예제 #1
0
        /// <summary>
        /// Two <see cref="CoordinateMapping"/> are equal if all entries of their <see cref="Fields"/>-properties are
        /// equal in reference. Note that this is a very strict condition; if the mappings should be compared just on
        /// <see cref="UnsetteledCoordinateMapping"/>-level, the <see cref="UnsetteledCoordinateMapping.EqualsUnsetteled"/>-comparison
        /// should be used.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (!base.Equals(obj))
            {
                return(false);
            }

            CoordinateMapping othr = obj as CoordinateMapping;

            if (othr == null)
            {
                return(false);
            }


            if (othr.m_Fields.Length != this.m_Fields.Length)
            {
                return(false);
            }
            for (int i = 0; i < othr.m_Fields.Length; i++)
            {
                if (!object.ReferenceEquals(this.m_Fields[i], othr.m_Fields[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
 /// <summary>
 /// Constructs a new vector, based on the mapping <paramref name="mapping"/>;
 /// </summary>
 /// <param name="mapping">
 /// The mapping to transform indices; This parameter is
 /// used to initialize <see cref="Mapping"/>.
 /// </param>
 /// <param name="presentExternal">
 /// value for the <see cref="PresentExternal"/>-property;
 /// </param>
 public CoordinateVector(CoordinateMapping mapping, bool presentExternal)
 {
     m_mapping         = mapping;
     m_PresentExternal = presentExternal;
     if (m_PresentExternal)
     {
         m_Count = m_mapping.Ntotal;
     }
     else
     {
         m_Count = m_mapping.LocalLength;
     }
 }
예제 #3
0
        /// <summary>
        /// And another wrapper.
        /// </summary>
        static public void Evaluate(this SpatialOperator op, double time, SubGrid subGrid = null, SubGridBoundaryModes subGridBoundaryMode = SubGridBoundaryModes.OpenBoundary, params DGField[] f)
        {
            if (op.DomainVar.Count + op.ParameterVar.Count + op.CodomainVar.Count != f.Length)
            {
                throw new ArgumentException("wrong number of domain/parameter/codomain fields", "f");
            }

            CoordinateMapping inp = new CoordinateMapping(f.GetSubVector(0, op.DomainVar.Count));

            DGField[]         Parameters = f.GetSubVector(op.DomainVar.Count, op.ParameterVar.Count);
            CoordinateMapping outp       = new CoordinateMapping(f.GetSubVector(op.DomainVar.Count + op.ParameterVar.Count, op.CodomainVar.Count));

            Evaluate(op, 1.0, 0.0, inp, Parameters, outp, subGrid, null, null, subGridBoundaryMode, time);
        }
예제 #4
0
        /// <summary>
        /// Another wrapper for
        /// <see cref="Evaluate(SpatialOperator,double,double,CoordinateMapping,IList{DGField},CoordinateMapping,SubGrid,EdgeQuadratureScheme,CellQuadratureScheme,SpatialOperator.SubGridBoundaryModes)"/>
        /// </summary>
        /// <param name="DomainFields">
        /// the domain variables; the number of elements
        /// must be equal to the number of elements in the <see cref="DomainVar"/>-list;
        /// </param>
        /// <param name="CodomainFields">
        /// the codomain variables; the number of elements
        /// must be equal to the number of elements in the <see cref="CodomainVar"/>-list;
        /// </param>
        /// <remarks>
        /// If some of the input field, i.e. some element of <paramref name="DomainFields"/>, is contained in the
        /// output fields, i.e. in the list <paramref name="CodomainFields"/>, these DG fields will be cloned to ensure
        /// correct operation of the operator evaluation.<br/>
        /// It is not a good choice to use this
        /// function if this operator should be evaluated multiple times
        /// and
        /// contains linear components (i.e. <see cref="ContainsLinear"/> returns true);
        /// If the later one is the case, the matrix which represents
        /// the linear components of the operator must be computed first, which is computational- and
        /// memory - intensive;
        /// After execution of this method, the matrix will be lost;
        /// If multiple evaluation is desired, the <see cref="Evaluator"/>-class should be used,
        /// in which the matrix of the operator will persist;
        /// However, if no linear components are present, the performance of this function should
        /// be almost comparable to the use of the <see cref="Evaluator"/>-class;
        /// </remarks>
        /// <param name="op"></param>
        /// <param name="time"></param>
        static public void Evaluate(this SpatialOperator op, IList <DGField> DomainFields, IList <DGField> CodomainFields, double time = double.NaN)
        {
            if (DomainFields.Count != op.DomainVar.Count)
            {
                throw new ArgumentException("wrong number of domain fields", "DomainFields");
            }
            if (CodomainFields.Count != op.CodomainVar.Count)
            {
                throw new ArgumentException("wrong number of domain fields", "CodomainFields");
            }

            CoordinateMapping inp  = new CoordinateMapping(DomainFields);
            CoordinateMapping outp = new CoordinateMapping(CodomainFields);

            Evaluate(op, 1.0, 0.0, inp, null, outp, null, null, null, SubGridBoundaryModes.OpenBoundary, time);
        }
예제 #5
0
 /// <summary>
 /// Constructs a new vector, based on the mapping <paramref name="mapping"/>;
 /// </summary>
 /// <param name="mapping">
 /// The mapping to transform indices; This parameter is
 /// used to initialize <see cref="Mapping"/>.
 /// </param>
 /// <remarks>
 /// <see cref="PresentExternal"/> is initialized to false.
 /// </remarks>
 public CoordinateVector(CoordinateMapping mapping) :
     this(mapping, false)
 {
 }
예제 #6
0
        /// <summary>
        /// Evaluates this operator for given DG fields;
        /// </summary>
        /// <param name="DomainMapping">
        /// the domain variables, or "input data" for the operator; the number
        /// of elements must be equal to the number of elements in the
        /// <see cref="DomainVar"/>-list;
        /// </param>
        /// <param name="Params">
        /// List of parameter fields; May be null
        /// </param>
        /// <param name="CodomainMapping">
        /// the co-domain variables, or "output" for the evaluation of the
        /// operator; the number of elements must be equal to the number of
        /// elements in the <see cref="CodomainVar"/>-list;
        /// </param>
        /// <param name="alpha">
        /// scaling of the operator
        /// </param>
        /// <param name="beta">
        /// scaling of the accumulator (<paramref name="CodomainMapping"/>);
        /// </param>
        /// <param name="sgrd">
        /// subgrid, for restricted evaluation; null indicates evaluation on
        /// the full grid.
        /// </param>
        /// <param name="bndMode">
        /// Treatment of subgrid boundaries, if <paramref name="sgrd"/> is not
        /// null. See <see cref="Evaluator"/>
        /// </param>
        /// <param name="qInsEdge">
        /// Optional definition of the edge quadrature scheme. Since this
        /// already implies a domain of integration, must be null if
        /// <paramref name="sgrd"/> is not null.
        /// </param>
        /// <param name="qInsVol">
        /// Optional definition of the volume quadrature scheme. Since this
        /// already implies a domain of integration, must be null if
        /// <paramref name="sgrd"/> is not null.
        /// </param>
        /// <remarks>
        /// If some of the input data, <paramref name="DomainMapping"/>, is
        /// contained in the  output data, <paramref name="CodomainMapping"/>,
        /// these DG fields will be cloned to ensure correct operation of the
        /// operator evaluation.<br/>
        /// It is not a good choice to use this function if this operator
        /// should be evaluated multiple times and  contains linear components
        /// (i.e. <see cref="ContainsLinear"/> returns true); If the latter is
        /// the case, the matrix which represents the linear components of the
        /// operator must be computed first, which is computational- and
        /// memory-intensive; After execution of this method, the matrix will
        /// be lost; If multiple evaluation is desired, the
        /// <see cref="Evaluator"/>-class should be used, in which the matrix
        /// of the operator will persist; However, if no linear components are
        /// present, the performance of this function should be almost
        /// comparable to the use of the <see cref="Evaluator"/>-class;
        /// </remarks>
        static public void Evaluate(
            this SpatialOperator op,
            double alpha, double beta,
            CoordinateMapping DomainMapping, IList <DGField> Params, CoordinateMapping CodomainMapping,
            SubGrid sgrd = null,
            EdgeQuadratureScheme qInsEdge = null,
            CellQuadratureScheme qInsVol  = null,
            SpatialOperator.SubGridBoundaryModes bndMode = SubGridBoundaryModes.OpenBoundary,
            double time = double.NaN)                  //
        {
            using (new FuncTrace()) {
                if (sgrd != null && (qInsEdge != null || qInsVol != null))
                {
                    throw new ArgumentException("Specification of Subgrid and quadrature schemes is exclusive: not allowed to specify both at the same time.", "sgrd");
                }
#if DEBUG
                op.Verify(); //this has already been done during this.Commit()
#endif

                IList <DGField> _DomainFields          = DomainMapping.Fields;
                IList <DGField> _CodomainFields        = CodomainMapping.Fields;
                DGField[]       _DomainFieldsRevisited = new DGField[_DomainFields.Count];

                bool a = false;
                for (int i = 0; i < _DomainFields.Count; i++)
                {
                    DGField f = _DomainFields[i];

                    if (_CodomainFields.Contains(f))
                    {
                        // some of the domain variables (input data)
                        // is also a member of the codomain variables (output);
                        // the data need to be cloned to provide correct results
                        a = true;
                        _DomainFieldsRevisited[i] = (DGField)f.Clone();
                    }
                    else
                    {
                        _DomainFieldsRevisited[i] = f;
                    }
                }

                CoordinateMapping domainMappingRevisited;
                if (a)
                {
                    domainMappingRevisited = new CoordinateMapping(_DomainFieldsRevisited);
                }
                else
                {
                    domainMappingRevisited = DomainMapping;
                }

                if (sgrd != null)
                {
                    CellMask cm = (sgrd == null) ? null : sgrd.VolumeMask;
                    EdgeMask em = (sgrd == null) ? null : sgrd.AllEdgesMask;

                    qInsEdge = new EdgeQuadratureScheme(true, em);
                    qInsVol  = new CellQuadratureScheme(true, cm);
                }

                var ev = op.GetEvaluatorEx(
                    domainMappingRevisited, Params, CodomainMapping,
                    qInsEdge,
                    qInsVol);

                if (sgrd != null)
                {
                    ev.ActivateSubgridBoundary(sgrd.VolumeMask, bndMode);
                }
                CoordinateVector outp = new CoordinateVector(CodomainMapping);
                ev.time = time;
                ev.Evaluate <CoordinateVector>(alpha, beta, outp);
            }
        }
예제 #7
0
 /// <summary>
 /// Constructs a mapping from associated with a given <see cref="SubGrid"/> on the basis of the original mapping
 /// </summary>
 /// <param name="context">the context object</param>
 /// <param name="cm">The original mapping</param>
 /// <param name="subgrid">The subgrid</param>
 public SubgridCoordinateMappingExt(Context context, CoordinateMapping cm, SubGrid subgrid) : base(context, subgrid, cm.Fields)
 {
 }