/// <summary>
        /// simplified version of
        /// <see cref="ComputeMatrixEx{M,V}"/>;
        /// </summary>
        static public void ComputeMatrix <M, V>(this SpatialOperator op,
                                                UnsetteledCoordinateMapping DomainMap, IList <DGField> Parameters, UnsetteledCoordinateMapping CodomainMap,
                                                M Matrix, V AffineOffset, bool OnlyAffine, double time = 0.0,
                                                SubGrid sgrd = null)
            where M : IMutableMatrixEx
            where V : IList <double>
        {
            var GridDat = CheckArguments(DomainMap, Parameters, CodomainMap);


            var ev = op.GetMatrixBuilder(DomainMap, Parameters, CodomainMap,
                                         new EdgeQuadratureScheme(true, sgrd == null ? null : sgrd.AllEdgesMask),
                                         new CellQuadratureScheme(true, sgrd == null ? null : sgrd.VolumeMask));

            ev.time = time;

            if (OnlyAffine)
            {
                ev.ComputeAffine(AffineOffset);
            }
            else
            {
                ev.ComputeMatrix(Matrix, AffineOffset);
            }
        }
Example #2
0
        public void Laplacian(OpenFOAMGrid grid, int DgDegree)
        {
            // grid, etc
            // =========

            GridData grd = grid.GridData;

            var b   = new Basis(grd, DgDegree);
            var map = new UnsetteledCoordinateMapping(b);

            var L  = new Laplace(1.3, grd.Cells.cj);
            var op = new SpatialOperator(1, 0, 1, QuadOrderFunc.Linear(), "T", "c1");

            op.EquationComponents["c1"].Add(L);
            op.Commit();

            // evaluate operator
            // =================

            var Mtx = new BlockMsrMatrix(map, map);

            double[] B = new double[map.LocalLength];

            var eval = op.GetMatrixBuilder(map, null, map);

            eval.ComputeMatrix(Mtx, B);

            // return data
            // ===========

            throw new NotImplementedException("todo");
        }
        /// <summary>
        /// computes the affine offset and/or matrix of the operator, expert
        /// version;
        /// </summary>
        /// <param name="DomainMap">
        /// the mapping which is used to compute column indices into
        /// <paramref name="Matrix"/>;
        /// </param>
        /// <param name="Parameters">
        /// The parameter variables (of this differential operator);
        /// The number of elements in the list must match the parameter count
        /// of the differential operator (see
        /// <see cref="SpatialOperator.ParameterVar"/>);  It is allowed to set
        /// an entry to 'null', in this case the values of the parameter field
        /// are assumed to be 0.0; If the differential operator contains no
        /// parameters, this argument can be null;
        /// </param>
        /// <param name="CodomainMap">
        /// the mapping which is used to compute row indices into
        /// <paramref name="Matrix"/> and <paramref name="AffineOffset"/>.
        /// </param>
        /// <param name="Matrix">
        /// Acc output: the matrix which represents the linear part of this
        /// operator, according to the mapping given by
        /// <paramref name="DomainMap"/> and <paramref name="CodomainMap"/>,
        /// is <b>ACCUMULATED</b> here; <br/>
        /// Setting all matrix entries to 0.0 is left to the user;
        /// </param>
        /// <param name="AffineOffset">
        /// Acc output: the vector which represents the affine part of this
        /// operator, according to the mapping given by
        /// <paramref name="DomainMap"/> and <paramref name="CodomainMap"/>,
        /// is <b>ACCUMULATED</b> here; <br/>
        /// Setting all vector entries to 0.0 is left to the user;
        /// </param>
        /// <param name="OnlyAffine">
        /// If true, only the <paramref name="AffineOffset"/> is computed, and
        /// the <paramref name="Matrix"/> is not touched (can be null);
        /// </param>
        /// <remarks>
        /// The operator assembly must be finalized before by calling
        /// <see cref="Commit"/> before this method can be called.
        /// </remarks>
        /// <param name="edgeRule">
        /// Quadrature rule and domain for edge integration; specifying this is exclusive with <paramref name="edgeQuadScheme"/>, i.e. both cannot be unequal null at the same time.
        /// </param>
        /// <param name="edgeQuadScheme">
        /// Quadrature scheme for edge integration; specifying this is exclusive with <paramref name="edgeRule"/>, i.e. both cannot be unequal null at the same time.
        /// </param>
        /// <param name="volRule">
        /// Quadrature rule and domain for volume integration; specifying this is exclusive with <paramref name="volQuadScheme"/>, i.e. both cannot be unequal null at the same time.
        /// </param>
        /// <param name="volQuadScheme">
        /// Quadrature scheme for volume integration; specifying this is exclusive with <paramref name="volRule"/>, i.e. both cannot be unequal null at the same time.
        /// </param>
        /// <param name="SubGridBoundaryMask">
        /// </param>
        /// <param name="ParameterMPIExchange">
        /// Determines whether parameter fields have to exchange ghost cell
        /// data before the assembly of the operator.
        /// </param>
        /// <param name="time"></param>
        /// <param name="op"></param>
        static public void ComputeMatrixEx <M, V>(this SpatialOperator op,
                                                  UnsetteledCoordinateMapping DomainMap, IList <DGField> Parameters, UnsetteledCoordinateMapping CodomainMap,
                                                  M Matrix, V AffineOffset, bool OnlyAffine = false,
                                                  double time = 0.0,
                                                  EdgeQuadratureScheme edgeQuadScheme = null, CellQuadratureScheme volQuadScheme = null,
                                                  //ICompositeQuadRule<QuadRule> edgeRule = null, ICompositeQuadRule<QuadRule> volRule = null,
                                                  BitArray SubGridBoundaryMask = null,
                                                  bool ParameterMPIExchange    = true)
            where M : IMutableMatrixEx
            where V : IList <double> //
        {
            var ev = op.GetMatrixBuilder(DomainMap, Parameters, CodomainMap, edgeQuadScheme, volQuadScheme);

            ev.time           = time;
            ev.MPITtransceive = ParameterMPIExchange;
            if (SubGridBoundaryMask != null)
            {
                throw new NotSupportedException();
                //ev.ActivateSubgridBoundary(new Grid.CellMask(ev.GridData, SubGridBoundaryMask));
            }

            if (OnlyAffine)
            {
                ev.ComputeAffine(AffineOffset);
            }
            else
            {
                ev.ComputeMatrix(Matrix, AffineOffset);
            }
        }
Example #4
0
 /// <summary>
 /// as defined by interface
 /// </summary>
 public IEvaluatorLinear GetMassMatrixBuilder(UnsetteledCoordinateMapping DomainVarMap, IList <DGField> ParameterMap, UnsetteledCoordinateMapping CodomainVarMap)
 {
     InternalRepresentation.EdgeQuadraturSchemeProvider   = owner.EdgeQuadraturSchemeProvider;
     InternalRepresentation.VolumeQuadraturSchemeProvider = owner.VolumeQuadraturSchemeProvider;
     InternalRepresentation.m_UserDefinedValues           = owner.m_UserDefinedValues;
     InternalRepresentation.CurrentHomotopyValue          = owner.CurrentHomotopyValue;
     return(InternalRepresentation.GetMatrixBuilder(DomainVarMap, ParameterMap, CodomainVarMap));
 }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="spatialOp"></param>
        /// <param name="fields"></param>
        /// <param name="matrix"></param>
        /// <param name="affineOffset"></param>
        /// <param name="OnlyAffine">
        /// if true, only the <paramref name="affineOffset"/>
        /// is computed and <paramref name="matrix"/> is null on exit.
        /// </param>
        public static void ComputeMatrix(SpatialOperator spatialOp, CoordinateMapping fields, bool OnlyAffine, out MsrMatrix matrix, out double[] affineOffset)
        {
            // Check operator and arguments
            if (!spatialOp.IsCommited)
            {
                throw new ArgumentException("operator must be committed first.", "spatialOp");
            }
            if (spatialOp.ContainsNonlinear)
            {
                throw new ArgumentException("spatial differential operator cannot contain nonlinear components for implicit euler.", "spatialOp");
            }
            if (!spatialOp.ContainsLinear())
            {
                throw new ArgumentException("spatial differential operator seems to contain no components.", "spatialOp");
            }
            if (spatialOp.DomainVar.Count != spatialOp.CodomainVar.Count)
            {
                throw new ArgumentException("spatial differential operator must have the same number of domain and codomain variables.", "spatialOp");
            }
            if (fields.Fields.Count != spatialOp.CodomainVar.Count)
            {
                throw new ArgumentException("the number of fields in the coordinate mapping must be equal to the number of domain/codomain variables of the spatial differential operator", "fields");
            }

            // Assemble matrix and affine offset
            IPartitioning matrixPartition = fields;


            if (!OnlyAffine)
            {
                matrix = new MsrMatrix(matrixPartition);
            }
            else
            {
                matrix = null;
            }
            affineOffset = new double[fields.LocalLength];

            var b = spatialOp.GetMatrixBuilder(fields, null, fields);

            if (OnlyAffine)
            {
                b.ComputeAffine(affineOffset);
            }
            else
            {
                b.ComputeMatrix(matrix, affineOffset);
            }
        }
Example #6
0
        /// <summary>
        /// ctor.
        /// </summary>
        public LinearSolver(ISparseSolver solver, SpatialOperator spatialOp, CoordinateMapping UnknownsMap)
        {
            // verify input
            // ------------
            if (!spatialOp.IsCommited)
            {
                throw new ArgumentException("operator must be committed first.", "spatialOp");
            }
            if (spatialOp.ContainsNonlinear)
            {
                throw new ArgumentException("spatial differential operator cannot contain nonlinear components for linear solver.", "spatialOp");
            }
            if (!spatialOp.ContainsLinear())
            {
                throw new ArgumentException("spatial differential operator seems to contain no components.", "spatialOp");
            }
            if (spatialOp.DomainVar.Count != spatialOp.CodomainVar.Count)
            {
                throw new ArgumentException("spatial differential operator must have the same number of domain and codomain variables.", "spatialOp");
            }

            if (UnknownsMap.Fields.Count != spatialOp.CodomainVar.Count)
            {
                throw new ArgumentException("the number of fields in the coordinate mapping must be equal to the number of domain/codomain variables of the spatial differential operator", "fields");
            }

            m_Mapping = UnknownsMap;
            m_Solver  = solver;

            // matrix assembly
            // ---------------
            MsrMatrix eM;

            {
                eM             = new MsrMatrix(m_Mapping);
                m_AffineOffset = new double[m_Mapping.LocalLength];

                //spatialOp.ComputeMatrixEx(m_Mapping, null, m_Mapping, eM, m_AffineOffset);
                spatialOp.GetMatrixBuilder(m_Mapping, null, m_Mapping).ComputeMatrix(eM, m_AffineOffset);
            }

            ConstructorCommon(eM);
        }
Example #7
0
        unsafe public static void Laplacian(ref int GridRef,
                                            ref int DgDegree,

                                            out int ierr)
        {
            try {
                // grid, etc
                // =========

                GridData grd = null;// (GridData)(Infrastructure.GetObject(GridRef));

                var b   = new Basis(grd, DgDegree);
                var map = new UnsetteledCoordinateMapping(b);

                var L  = new Laplace(1.3, grd.Cells.cj);
                var op = new SpatialOperator(1, 0, 1, QuadOrderFunc.Linear(), "T", "c1");
                op.EquationComponents["c1"].Add(L);
                op.Commit();

                // evaluate operator
                // =================

                var      Mtx = new BlockMsrMatrix(map, map);
                double[] B   = new double[map.LocalLength];

                var eval = op.GetMatrixBuilder(map, null, map);
                eval.ComputeMatrix(Mtx, B);

                // return data
                // ===========

                throw new NotImplementedException("todo");
            } catch (Exception e) {
                ierr = Infrastructure.ErrorHandler(e);
            }
            ierr = 0;
        }