Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
        /// <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);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// two <see cref="UnsetteledCoordinateMapping"/>, if their <see cref="BasisS"/>-properties
        /// are equal (for every entry);
        /// </summary>
        /// <remarks>
        /// This is a non-virtual version of <see cref="Equals"/>;
        /// See <see cref="CoordinateMapping.Equals"/> for explanation.
        /// </remarks>
        public bool EqualsUnsetteled(UnsetteledCoordinateMapping obj)
        {
            UnsetteledCoordinateMapping othr = obj;

            // the following calls may be not necessary, but since they are very cheap ...
            if (!object.ReferenceEquals(this.m_Context, othr.m_Context))
            {
                return(false);
            }


            // the real test...
            if (this.m_BasisS.Length != othr.m_BasisS.Length)
            {
                return(false);
            }
            for (int i = 0; i < this.m_BasisS.Length; i++)
            {
                if (!this.m_BasisS[i].Equals(othr.m_BasisS[i]))
                {
                    return(false);
                }
            }

            // success
            return(true);
        }
Esempio n. 4
0
            internal InternalBla(ConstantTemporalOperator __Owner, UnsetteledCoordinateMapping DomainVarMap, IList <DGField> ParameterMap, UnsetteledCoordinateMapping CodomainVarMap)
            {
                this.DomainMapping   = DomainVarMap;
                this.Parameters      = ParameterMap;
                this.CodomainMapping = CodomainVarMap;
                m_Owner = __Owner;

                if (DomainMapping.NoOfVariables != Owner.DomainVar.Count)
                {
                    throw new ArgumentException("Mismatch in number of domain variables.");
                }
                if (CodomainMapping.NoOfVariables != Owner.CodomainVar.Count)
                {
                    throw new ArgumentException("Mismatch in number of codomain variables.");
                }

                if (ParameterMap.Count != Owner.ParameterVar.Count)
                {
                    throw new ArgumentException("Mismatch in number of parameter variables.");
                }

                if (!DomainVarMap.EqualsPartition(CodomainVarMap))
                {
                    throw new ArgumentException("Only supported for square matrices - domain and codomain map are not compatible (e.g. different number of rows and columns.");
                }
            }
Esempio n. 5
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));
 }
Esempio n. 6
0
        /// <summary>
        /// another legacy interface
        /// </summary>
        static public void ComputeAffine <V>(
            this SpatialOperator op,
            UnsetteledCoordinateMapping DomainMap,
            IList <DGField> Parameters,
            UnsetteledCoordinateMapping CodomainMap,
            V AffineOffset,
            bool OnlyBoundaryEdges      = true, double time = 0.0,
            EdgeQuadratureScheme edgeQr = null, CellQuadratureScheme volQr = null)
            where V : IList <double>
        {
            var GridDat = CodomainMap.GridDat;

            if (Parameters != null)
            {
                foreach (var prm in Parameters)
                {
                    if (!object.ReferenceEquals(prm.GridDat, GridDat))
                    {
                        throw new ArgumentException(string.Format("parameter field {0} is assigned to a different grid.", prm.Identification));
                    }
                }
            }

            //Using order zero for DomainMap will lead to inconsistent (and possibly insufficient) quadrature order!!!
            //UnsetteledCoordinateMapping DomainMap;
            //Basis b = new Basis(GridDat, 0);
            //Basis[] B = new Basis[this.DomainVar.Count];
            //B.SetAll(b);
            //DomainMap = new UnsetteledCoordinateMapping(B);


            if (OnlyBoundaryEdges)
            {
                if (edgeQr != null)
                {
                    throw new ArgumentException("If 'OnlyBoundaryEdges == true', 'edgeQr' must be null!", "edgeQr");
                }
                if (volQr != null)
                {
                    throw new ArgumentException("If 'OnlyBoundaryEdges == true', 'volQr' must be null!", "volQr");
                }

                volQr  = new CellQuadratureScheme(true, CellMask.GetEmptyMask(GridDat));
                edgeQr = new EdgeQuadratureScheme(true, GridDat.GetBoundaryEdgeMask());
            }

            op.ComputeMatrixEx(
                DomainMap, Parameters, CodomainMap,
                default(MsrMatrix), AffineOffset,
                OnlyAffine: true, time: time,
                volQuadScheme: volQr, edgeQuadScheme: edgeQr);
        }
Esempio n. 7
0
        /// <summary>
        /// two <see cref="UnsetteledCoordinateMapping"/>, if their <see cref="BasisS"/>-properties
        /// are equal (for every entry);
        /// </summary>
        public override bool Equals(object obj)
        {
            UnsetteledCoordinateMapping othr = obj as UnsetteledCoordinateMapping;

            if (obj == null)
            {
                return(false);
            }
            else
            {
                return(EqualsUnsetteled(othr));
            }
        }
Esempio n. 8
0
        /// <summary>
        /// simplified version of
        /// <see cref="ComputeMatrixEx{M,V}"/>;
        /// </summary>
        static public MsrMatrix ComputeMatrix(this SpatialOperator op,
                                              UnsetteledCoordinateMapping DomainMap, IList <DGField> Parameters, UnsetteledCoordinateMapping CodomainMap, double time = 0.0, SubGrid SubGrid = null)
        {
            int RowBlkSize = (CodomainMap.MaxTotalNoOfCoordinatesPerCell == CodomainMap.MinTotalNoOfCoordinatesPerCell) ? CodomainMap.MaxTotalNoOfCoordinatesPerCell : 1;
            int ColBlkSize = (DomainMap.MaxTotalNoOfCoordinatesPerCell == DomainMap.MinTotalNoOfCoordinatesPerCell) ? DomainMap.MaxTotalNoOfCoordinatesPerCell : 1;

            MsrMatrix Matrix = new MsrMatrix(CodomainMap.LocalLength, (int)DomainMap.GlobalCount, RowBlkSize, ColBlkSize);

            double[] dummyRHS = new double[Matrix.RowPartitioning.LocalLength];
            ComputeMatrix(op,
                          DomainMap, Parameters, CodomainMap,
                          Matrix, dummyRHS,
                          false, time, SubGrid);

            return(Matrix);
        }
Esempio n. 9
0
        private static IGridData CheckArguments(UnsetteledCoordinateMapping DomainMap, IList <DGField> Parameters, UnsetteledCoordinateMapping CodomainMap)
        {
            var GridDat = DomainMap.GridDat;

            if (!object.ReferenceEquals(GridDat, CodomainMap.GridDat))
            {
                throw new ArgumentException("Domain and codomain map must be assigend to the same grid.");
            }
            if (Parameters != null)
            {
                foreach (var prm in Parameters)
                {
                    if (prm != null && (!object.ReferenceEquals(prm.GridDat, GridDat)))
                    {
                        throw new ArgumentException(string.Format("parameter field {0} is assigned to a different grid.", prm.Identification));
                    }
                }
            }
            return(GridDat);
        }
Esempio n. 10
0
 /// <summary>
 /// Legacy interface
 /// </summary>
 static public IEvaluatorNonLin GetEvaluator(this SpatialOperator op, IList <DGField> DomainVarMap, UnsetteledCoordinateMapping CodomainVarMap)
 {
     return(op.GetEvaluatorEx(DomainVarMap, null, CodomainVarMap));
 }
Esempio n. 11
0
 /// <summary>
 /// Returns an matrix builder which always accumulates the same diagonal matrix.
 /// </summary>
 public IEvaluatorLinear GetMassMatrixBuilder(UnsetteledCoordinateMapping DomainVarMap, IList <DGField> ParameterMap, UnsetteledCoordinateMapping CodomainVarMap)
 {
     return(new InternalBla(this, DomainVarMap, ParameterMap, CodomainVarMap));
 }