Exemplo n.º 1
0
        /// <summary>
        /// Saves the location and weight associated with each node in
        /// <paramref name="compositeRule"/> into a text file
        /// </summary>
        public static void ToTextFileVolume(this ICompositeQuadRule <QuadRule> compositeRule, Grid.Classic.GridData gridData, string filename)
        {
            int D = gridData.SpatialDimension;

            string[] dimensions = new string[] { "x", "y", "z" };

            using (var file = new StreamWriter(filename)) {
                file.WriteLine(String.Format(
                                   "Cell\t{0}\tWeight",
                                   dimensions.Take(D).Aggregate((s, t) => s + "\t" + t)));

                foreach (IChunkRulePair <QuadRule> pair in compositeRule)
                {
                    MultidimensionalArray globalNodes = gridData.GlobalNodes.GetValue_Cell(pair.Rule.Nodes, pair.Chunk.i0, pair.Chunk.Len);

                    foreach (var cell in pair.Chunk.Elements.AsSmartEnumerable())
                    {
                        for (int n = 0; n < pair.Rule.NoOfNodes; n++)
                        {
                            file.Write(cell.Value);

                            for (int d = 0; d < D; d++)
                            {
                                file.Write("\t{0}", globalNodes[cell.Index, n, d].ToString("E", NumberFormatInfo.InvariantInfo));
                            }

                            file.WriteLine("\t{0}", pair.Rule.Weights[n].ToString("E", NumberFormatInfo.InvariantInfo));
                        }
                    }

                    file.Flush();
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs a surface integrator.
 /// </summary>
 /// <param name="owner">
 /// Creator of this object.
 /// </param>
 /// <param name="rule">
 /// The quadrature rule to be used
 /// </param>
 public SurfaceIntegrator(LevelSetIntegrator owner, ICompositeQuadRule <CellBoundaryQuadRule> rule)
     : base(new int[] { owner.m_NoOfIntegrands }, owner.m_LevSetTrk.GridDat, rule)
 {
     m_Owner        = owner;
     m_WeightBuffer = new MultidimensionalArray(2);
     m_ResultBuffer = new MultidimensionalArray(4);
 }
        private MultidimensionalArray EdgeQuadrature2CellBoundary(ICompositeQuadRule <QuadRule> surfRule)
        {
            int J   = this.GridData.iLogicalCells.NoOfLocalUpdatedCells;
            var ret = MultidimensionalArray.Create(J);
            var E2C = this.GridData.iLogicalEdges.CellIndices;

            BoSSS.Foundation.Quadrature.EdgeQuadrature.GetQuadrature(
                new int[] { 1 }, this.GridData,
                surfRule,
                delegate(int i0, int Length, QuadRule Qr, MultidimensionalArray EvalResult) { // Evaluate
                EvalResult.SetAll(1.0);
            },
                delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration) { // SaveIntegrationResults
                for (int i = 0; i < Length; i++)
                {
                    int iEdge  = i0 + i;
                    int jCell0 = E2C[iEdge, 0];
                    int jCell1 = E2C[iEdge, 1];

                    ret[jCell0] += ResultsOfIntegration[i, 0];
                    if (jCell1 >= 0)
                    {
                        ret[jCell1] += ResultsOfIntegration[i, 0];
                    }
                }
            }).Execute();

            return(ret);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Standard constructor
        /// </summary>
        /// <param name="noOfIntegralsPerCell">
        /// The number of integrals to be computed
        /// </param>
        /// <param name="context">
        /// see <see cref="gridData"/>.
        /// </param>
        /// <param name="rule">
        /// quadrature domain and rules.
        /// </param>
        /// <param name="cs">integrate in physical or reference coordinates?</param>
        protected Quadrature(int[] noOfIntegralsPerCell, IGridData context, ICompositeQuadRule <TQuadRule> rule, CoordinateSystem cs)
        {
            m_TotalNoOfIntegralsPerItem = 1;
            foreach (var no in noOfIntegralsPerCell)
            {
                m_TotalNoOfIntegralsPerItem *= no;
            }
            m_IntegralsComponent = noOfIntegralsPerCell;

#if DEBUG
            if (rule.Count() > 0)
            {
                int J = rule.Max(crp => crp.Chunk.JE);
                System.Collections.BitArray ChunkTest = new System.Collections.BitArray(J);
                foreach (var chunk in rule)
                {
                    int IE = chunk.Chunk.JE;
                    for (int i = chunk.Chunk.i0; i < IE; i++)
                    {
                        if (ChunkTest[i])
                        {
                            throw new ArgumentException("More than one quadrature rule defined for integration item " + i + ".");
                        }
                        ChunkTest[i] = true;
                    }
                }
            }
#endif


            gridData         = context;
            m_compositeRule  = rule;
            CoordinateSystem = cs;
        }
Exemplo n.º 5
0
 public EdgeQuadratureImpl(int[] noOfIntegralsPerCell,
                           IGridData context,
                           ICompositeQuadRule <QuadRule> domNrule,
                           CoordinateSystem cs)
     : base(noOfIntegralsPerCell, context, domNrule, cs)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="noOfIntegralsPerCell"></param>
 /// <param name="context"></param>
 /// <param name="rule"></param>
 /// <param name="cs">integrate in physical or reference coordinates?</param>
 public EdgeQuadrature(int[] noOfIntegralsPerCell, IGridData context, ICompositeQuadRule <QuadRule> rule, CoordinateSystem cs = Quadrature.CoordinateSystem.Physical)
     : base(noOfIntegralsPerCell, context, rule, cs) //
 {
     foreach (IChunkRulePair <QuadRule> crp in rule)
     {
         NodeCoordinateSystem ncs = crp.Rule.Nodes.GetNodeCoordinateSystem(context);
         if (ncs != NodeCoordinateSystem.EdgeCoord)
         {
             throw new ArgumentException("Illegal node set for edge quadrature. Found some node set defined for: " + ncs.ToString() + ".");
         }
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Constructs an integrator for the given field
 /// <paramref name="field"/>.
 /// </summary>
 /// <param name="trk">
 /// The tracker containing the level set to be integrated over
 /// </param>
 /// <param name="field">
 /// The field to be integrated
 /// </param>
 /// <param name="volumeFactory">
 /// <see cref="LevelSetIntegrator.LevelSetIntegrator"/>
 /// </param>
 /// <param name="boundaryFactory">
 /// <see cref="LevelSetIntegrator.LevelSetIntegrator"/>
 /// </param>
 /// <param name="quadOrder">
 /// <see cref="LevelSetIntegrator.LevelSetIntegrator"/>
 /// </param>
 /// <param name="sgrd"></param>
 /// <param name="LevSetIdx"></param>
 public ScalarFieldLevelSetIntegrator(
     LevelSetTracker trk,
     SinglePhaseField field,
     ICompositeQuadRule <QuadRule> volumeFactory,
     ICompositeQuadRule <CellBoundaryQuadRule> boundaryFactory,
     int quadOrder,
     SubGrid sgrd,
     int LevSetIdx)
     : base(trk, 1, volumeFactory, boundaryFactory, quadOrder, sgrd, LevSetIdx)
 {
     m_levSet = trk.LevelSets[0];
     m_Field  = field;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Constructs an integrator.
        /// </summary>
        /// <param name="lsTrk">
        /// The level set tracker tracking the level set to be integrated over
        /// </param>
        /// <param name="NoOfIntegrands">
        /// The number of integrals to perform simultaneously
        /// </param>
        /// <param name="volumeFactory">
        /// The quadrature rule factory for the volume integrals. Note that the
        /// integrand is discontinuous and that special quadrature rules should
        /// be used for this case.
        /// </param>
        /// <param name="boundaryFactory">
        /// The quadrature rule factory for the surface integrals. Note that the
        /// integrand is discontinuous and that special quadrature rules should
        /// be used for this case.
        /// </param>
        /// <param name="quadOrder">
        /// The desired quadrature rule (for surface and volume integrals)
        /// </param>
        /// <param name="LevSetIdx">
        /// The id of the level set to be integrated over.
        /// </param>
        /// <param name="sgrd">
        /// the subgrid which is used for the mapping the results
        /// (see <see cref="Execute"/>).
        /// </param>
        public LevelSetIntegrator(
            LevelSetTracker lsTrk, int NoOfIntegrands,
            ICompositeQuadRule <QuadRule> volumeFactory,
            ICompositeQuadRule <CellBoundaryQuadRule> boundaryFactory,
            int quadOrder,
            SubGrid sgrd,
            int LevSetIdx)
        {
            m_LevSetTrk      = lsTrk;
            m_NoOfIntegrands = NoOfIntegrands;
            m_SubGrid        = sgrd;
            m_LevSetIdx      = LevSetIdx;

            m_SurfaceIntegrator = new SurfaceIntegrator(this, boundaryFactory);
            m_VoumeIntegrator   = new VolumeIntegrator(this, volumeFactory);
        }
        /// <summary>
        /// Calculate Forces acting from fluid onto the particle
        /// </summary>
        internal double[] Forces(out List <double[]>[] stressToPrintOut, CellMask cutCells)
        {
            double[]          tempForces        = new double[m_SpatialDim];
            double[]          IntegrationForces = tempForces.CloneAs();
            List <double[]>[] stressToPrint     = new List <double[]> [m_SpatialDim];
            stressToPrint[0] = new List <double[]>();
            stressToPrint[1] = new List <double[]>();
            for (int d = 0; d < m_SpatialDim; d++)
            {
                void ErrFunc(int CurrentCellID, int Length, NodeSet Ns, MultidimensionalArray result)
                {
                    int K = result.GetLength(1);
                    MultidimensionalArray Grad_UARes = MultidimensionalArray.Create(Length, K, m_SpatialDim, m_SpatialDim);
                    MultidimensionalArray pARes      = MultidimensionalArray.Create(Length, K);
                    MultidimensionalArray Normals    = m_LevelSetTracker.DataHistories[0].Current.GetLevelSetNormals(Ns, CurrentCellID, Length);

                    for (int i = 0; i < m_SpatialDim; i++)
                    {
                        m_U[i].EvaluateGradient(CurrentCellID, Length, Ns, Grad_UARes.ExtractSubArrayShallow(-1, -1, i, -1), 0, 1);
                    }
                    m_P.Evaluate(CurrentCellID, Length, Ns, pARes);
                    for (int j = 0; j < Length; j++)
                    {
                        for (int k = 0; k < K; k++)
                        {
                            result[j, k] = StressTensor(Grad_UARes, pARes, Normals, m_FluidViscosity, k, j, m_SpatialDim, d);
                            double t = Math.PI * (1 - Math.Sign(Normals[j, k, 1])) / 2 + Math.Acos(Normals[j, k, 0]);
                            stressToPrint[d].Add(new double[] { t, result[j, k] });
                        }
                    }
                }

                int[]                         noOfIntegrals = new int[] { 1 };
                XQuadSchemeHelper             SchemeHelper  = m_LevelSetTracker.GetXDGSpaceMetrics(new[] { m_LevelSetTracker.GetSpeciesId("A") }, m_RequiredOrder, 1).XQuadSchemeHelper;
                CellQuadratureScheme          cqs           = SchemeHelper.GetLevelSetquadScheme(0, cutCells);
                ICompositeQuadRule <QuadRule> surfaceRule   = cqs.Compile(m_LevelSetTracker.GridDat, m_RequiredOrder);

                CellQuadrature.GetQuadrature(noOfIntegrals, m_GridData, surfaceRule,
                                             delegate(int i0, int Length, QuadRule QR, MultidimensionalArray EvalResult) { ErrFunc(i0, Length, QR.Nodes, EvalResult.ExtractSubArrayShallow(-1, -1, 0)); },
                                             delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration) { IntegrationForces[d] = ForceTorqueSummationWithNeumaierArray(IntegrationForces[d], ResultsOfIntegration, Length); }
                                             ).Execute();
            }
            stressToPrintOut = stressToPrint.CloneAs();
            return(tempForces = IntegrationForces.CloneAs());
        }
        private MultidimensionalArray EdgeQuadrature(ICompositeQuadRule <QuadRule> surfRule)
        {
            int E   = this.GridData.iLogicalEdges.Count;
            var ret = MultidimensionalArray.Create(E);

            BoSSS.Foundation.Quadrature.EdgeQuadrature.GetQuadrature(
                new int[] { 1 }, this.GridData,
                surfRule,
                delegate(int i0, int Length, QuadRule QR, MultidimensionalArray EvalResult) { // Evaluate
                EvalResult.SetAll(1.0);
            },
                delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration) { // SaveIntegrationResults
                ret.ExtractSubArrayShallow(new int[] { i0 }, new int[] { i0 + Length - 1 })
                .Set(ResultsOfIntegration.ExtractSubArrayShallow(-1, 0));
            }).Execute();

            return(ret);
        }
        void PlotEdgeRule(ICompositeQuadRule <QuadRule> edgeRule)
        {
            var E2C = this.GridData.iLogicalEdges.CellIndices;
            //var Trafos = this.GridData.Edges.Edge2CellTrafos;
            var trfIdx = this.GridData.iGeomEdges.Edge2CellTrafoIndex;

            using (TextWriter tw = new StreamWriter("edges.csv")) {
                foreach (var ChunkRule in edgeRule)
                {
                    var Nodes   = ChunkRule.Rule.Nodes;
                    var Weights = ChunkRule.Rule.Weights;

                    for (int iEdge = ChunkRule.Chunk.i0; iEdge < ChunkRule.Chunk.JE; iEdge++)
                    {
                        int jCell = E2C[iEdge, 0];
                        int iTrf  = trfIdx[iEdge, 0];

                        //var NodesCell = Trafos[iTrf].Transform(Nodes);
                        NodeSet NodesCell = Nodes.GetVolumeNodeSet(this.GridData, iTrf);
                        var     NodesGlob = MultidimensionalArray.Create(NodesCell.Lengths);

                        this.GridData.TransformLocal2Global(NodesCell, NodesGlob, jCell);

                        int K = NodesGlob.GetLength(0);
                        int D = NodesGlob.GetLength(1);

                        for (int k = 0; k < K; k++)
                        {
                            tw.Write(iEdge);
                            tw.Write("\t");

                            for (int d = 0; d < D; d++)
                            {
                                tw.Write(NodesGlob[k, d]);
                                tw.Write("\t");
                            }

                            tw.WriteLine(Weights[k]);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Saves the sum of weights of each volume rule in the given
        /// <paramref name="compositeRule"/> together with the coordinates of
        /// the corresponding cell center into a text file.
        /// </summary>
        public static void SumOfWeightsToTextFileVolume(this ICompositeQuadRule <QuadRule> compositeRule, IGridData g, string filename)
        {
            int J     = g.iLogicalCells.Count;
            var bMask = new System.Collections.BitArray(J);

            double[] wSum = new double[J];
            foreach (IChunkRulePair <QuadRule> crp in compositeRule)
            {
                for (int iCell = crp.Chunk.i0; iCell < crp.Chunk.JE; iCell++)
                {
                    bMask[iCell] = true;
                    wSum[iCell]  = crp.Rule.Weights.Sum();
                }
            }

            var mask = new CellMask(g, bMask);

            mask.SaveToTextFile(filename, false, (X, i, ii) => wSum[i]);
        }
Exemplo n.º 13
0
        /// <summary>
        /// creates an edge quadrature, where integrand evaluation (<paramref name="_Evaluate"/>) and other methods
        /// can be passed as delegates. Use this, if you do not want to derive from <see cref="EdgeQuadrature"/>.
        /// </summary>
        static public EdgeQuadrature GetQuadrature(int[] noOfIntegralsPerCell,
                                                   Grid.Classic.GridData context,
                                                   ICompositeQuadRule <QuadRule> domNrule,
                                                   Del_Evaluate _Evaluate,
                                                   Del_SaveIntegrationResults _SaveIntegrationResults,
                                                   Del_AllocateBuffers _AllocateBuffers = null,
                                                   Del_QuadNodesChanged _PostLockNodes  = null,
                                                   CoordinateSystem cs = CoordinateSystem.Physical)
        {
            var ret = new EdgeQuadratureImpl(noOfIntegralsPerCell, context, domNrule, cs)
            {
                m_Evaluate = _Evaluate,
                m_SaveIntegrationResults = _SaveIntegrationResults,
                m_AllocateBuffers        = _AllocateBuffers,
                m_quadNodesChanged       = _PostLockNodes,
            };

            return(ret);
        }
        private MultidimensionalArray CellQuadrature(ICompositeQuadRule <QuadRule> surfRule)
        {
            int J   = this.GridData.iLogicalCells.NoOfLocalUpdatedCells;
            var ret = MultidimensionalArray.Create(J);

            BoSSS.Foundation.Quadrature.CellQuadrature.GetQuadrature(
                new int[] { 1 }, this.GridData,
                surfRule,
                delegate(int i0, int Length, QuadRule QR, MultidimensionalArray EvalResult) { // Evaluate
                //Integrand.Evaluate(i0, Length, 0, EvalResult.ExtractSubArrayShallow(-1, -1, 0));
                EvalResult.SetAll(1.0);
            },
                delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration) { // SaveIntegrationResults
                var A = ret.ExtractSubArrayShallow(new int[] { i0 }, new int[] { i0 + Length - 1 });
                var B = ResultsOfIntegration.ExtractSubArrayShallow(-1, 0);
                A.Set(B);
            }).Execute();

            return(ret);
        }
Exemplo n.º 15
0
 /// <summary>
 /// ctor.
 /// </summary>
 public LxNormQuadrature(DGField owner, ScalarFunctionEx func, Func <double[], double, double, double> Map, ICompositeQuadRule <QuadRule> rule)
     : base(new int[] { 1 }, owner.Basis.GridDat, rule) //
 {
     m_funcEx = func;
     m_Owner  = owner;
     m_Map    = Map;
 }
Exemplo n.º 16
0
        /// <summary>
        /// ctor.
        /// </summary>
        internal NECQuadratureLevelSet(IGridData context,
                                       XSpatialOperatorMk2 DiffOp,
                                       V __ResultVector,
                                       IList <DGField> __DomainFields,
                                       IList <DGField> __Parameters,
                                       UnsetteledCoordinateMapping CodomainMap,
                                       LevelSetTracker lsTrk, int _iLevSet, Tuple <SpeciesId, SpeciesId> SpeciesPair,
                                       ICompositeQuadRule <QuadRule> domAndRule) //
            : base(new int[] { CodomainMap.GetNonXBasisLengths(0).Sum() * 2 },   // we always integrate over species in pairs (neg + pos), so we need to alloc mem only 2 species
                   context,
                   domAndRule)                                                   //
        {
            MPICollectiveWatchDog.Watch();

            // -----------------------------------
            // set members / check ctor parameters
            // -----------------------------------
            m_lsTrk            = lsTrk;
            this.m_LevSetIdx   = _iLevSet;
            this.m_SpeciesPair = SpeciesPair;
            this.ResultVector  = __ResultVector;
            m_CodomainMap      = CodomainMap;
            var _Parameters = (__Parameters != null) ? __Parameters.ToArray() : new DGField[0];

            if (__DomainFields.Count != DiffOp.DomainVar.Count)
            {
                throw new ArgumentException("mismatch between number of domain variables in spatial operator and given domain variables");
            }
            if (_Parameters.Length != DiffOp.ParameterVar.Count)
            {
                throw new ArgumentException("mismatch between number of parameter variables in spatial operator and given parameters");
            }
            if (m_CodomainMap.NoOfVariables != DiffOp.CodomainVar.Count)
            {
                throw new ArgumentException("mismatch between number of codomain variables in spatial operator and given codomain mapping");
            }

            var _DomainAndParamFields = ArrayTools.Cat(__DomainFields, _Parameters);

            this.DELTA = __DomainFields.Count;

            m_DomainAndParamFieldsA = new ConventionalDGField[_DomainAndParamFields.Length];
            m_DomainAndParamFieldsB = new ConventionalDGField[_DomainAndParamFields.Length];
            for (int i = 0; i < m_DomainAndParamFieldsA.Length; i++)
            {
                var f = _DomainAndParamFields[i];
                if (f == null)
                {
                    m_DomainAndParamFieldsA[i] = null;
                    m_DomainAndParamFieldsB[i] = null;
                }
                else if (f is XDGField xf)
                {
                    m_DomainAndParamFieldsA[i] = xf.GetSpeciesShadowField(this.SpeciesA);
                    m_DomainAndParamFieldsB[i] = xf.GetSpeciesShadowField(this.SpeciesB);
                }
                else if (f is ConventionalDGField cf)
                {
                    m_DomainAndParamFieldsA[i] = cf;
                    m_DomainAndParamFieldsB[i] = null;
                }
                else
                {
                    throw new NotImplementedException("missing implementation for " + f.GetType().Name);
                }
            }

            LECQuadratureLevelSet <IMutableMatrix, double[]> .TestNegativeAndPositiveSpecies(domAndRule, m_lsTrk, SpeciesA, SpeciesB, m_LevSetIdx);

            // ------------------------
            // sort equation components
            // ------------------------

            int Gamma = m_CodomainMap.NoOfVariables;

            m_NonlinLsForm_V = EquationComponentArgMapping <INonlinLevelSetForm_V> .GetArgMapping(DiffOp, true,
                                                                                                  eq => ((eq.LevelSetTerms & (TermActivationFlags.V | TermActivationFlags.UxV | TermActivationFlags.GradUxV)) != 0) && Compfilter(eq),
                                                                                                  eq => (eq is ILevelSetForm)?new NonlinearLevelSetFormVectorizer((ILevelSetForm)eq, lsTrk) : null);

            m_NonlinLsForm_GradV = EquationComponentArgMapping <INonlinLevelSetForm_GradV> .GetArgMapping(DiffOp, true,
                                                                                                          eq => ((eq.LevelSetTerms & (TermActivationFlags.GradV | TermActivationFlags.UxGradV | TermActivationFlags.GradUxGradV)) != 0) && Compfilter(eq),
                                                                                                          eq => (eq is ILevelSetForm)?new NonlinearLevelSetFormVectorizer((ILevelSetForm)eq, lsTrk) : null);


            m_ValueRequired    = new bool[m_DomainAndParamFieldsA.Length];
            m_GradientRequired = new bool[m_DomainAndParamFieldsA.Length];

            m_NonlinLsForm_V.DetermineReqFields(m_GradientRequired,
                                                comp => ((comp.LevelSetTerms & (TermActivationFlags.GradUxGradV | TermActivationFlags.GradUxV)) != 0));
            m_NonlinLsForm_GradV.DetermineReqFields(m_GradientRequired,
                                                    comp => ((comp.LevelSetTerms & (TermActivationFlags.GradUxGradV | TermActivationFlags.GradUxV)) != 0));
            m_NonlinLsForm_V.DetermineReqFields(m_ValueRequired,
                                                comp => ((comp.LevelSetTerms & (TermActivationFlags.UxGradV | TermActivationFlags.UxV)) != 0));
            m_NonlinLsForm_GradV.DetermineReqFields(m_ValueRequired,
                                                    comp => ((comp.LevelSetTerms & (TermActivationFlags.UxGradV | TermActivationFlags.UxV)) != 0));

            for (int i = __DomainFields.Count; i < m_DomainAndParamFieldsA.Length; i++)
            {
                m_ValueRequired[i] = true; // parameters are always required!
            }


            // -----
            // alloc
            // -----

            Koeff_V     = new MultidimensionalArray[Gamma];
            Koeff_GradV = new MultidimensionalArray[Gamma];
            for (int gamma = 0; gamma < Gamma; gamma++)
            {
                Koeff_V[gamma]     = new MultidimensionalArray(3);
                Koeff_GradV[gamma] = new MultidimensionalArray(4);
            }

            Debug.Assert(m_DomainAndParamFieldsA.Length == m_DomainAndParamFieldsB.Length);
            int L = m_DomainAndParamFieldsA.Length;

            m_FieldValuesPos         = new MultidimensionalArray[L];
            m_FieldValuesNeg         = new MultidimensionalArray[L];
            m_FieldGradientValuesPos = new MultidimensionalArray[L];
            m_FieldGradientValuesNeg = new MultidimensionalArray[L];

            for (int l = 0; l < L; l++)
            {
                if (m_ValueRequired[l])
                {
                    m_FieldValuesPos[l] = new MultidimensionalArray(2);
                    m_FieldValuesNeg[l] = new MultidimensionalArray(2);
                }

                if (m_GradientRequired[l])
                {
                    m_FieldGradientValuesPos[l] = new MultidimensionalArray(3);
                    m_FieldGradientValuesNeg[l] = new MultidimensionalArray(3);
                }
            }


            // ------------------
            // init custom timers
            // ------------------

            base.CustomTimers             = new Stopwatch[] { new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch() };
            base.CustomTimers_Names       = new string[] { "Flux-Eval", "Basis-Eval", "Loops", "ParametersAndNormals", "Field-Eval" };
            base.CustomTimers_RootPointer = new int[5];
            ArrayTools.SetAll(base.CustomTimers_RootPointer, -1);

            this.m_NonlinLsForm_V_Watches     = this.m_NonlinLsForm_V.InitStopWatches(0, this);
            this.m_NonlinLsForm_GradV_Watches = this.m_NonlinLsForm_GradV.InitStopWatches(0, this);

            Flux_Eval            = base.CustomTimers[0];
            Basis_Eval           = base.CustomTimers[1];
            Loops                = base.CustomTimers[2];
            ParametersAndNormals = base.CustomTimers[3];
            Field_Eval           = base.CustomTimers[4];
        }
Exemplo n.º 17
0
        /// <summary>
        /// ctor.
        /// </summary>
        internal NECQuadratureLevelSet(IGridData context,
                                       XSpatialOperatorMk2 DiffOp,
                                       V __ResultVector,
                                       IList <DGField> __DomainFields,
                                       IList <DGField> __Parameters,
                                       UnsetteledCoordinateMapping CodomainMap,
                                       LevelSetTracker lsTrk, int _iLevSet, Tuple <SpeciesId, SpeciesId> SpeciesPair,
                                       ICompositeQuadRule <QuadRule> domAndRule) //
            : base(new int[] { CodomainMap.MaxTotalNoOfCoordinatesPerCell },
                   context,
                   domAndRule) //
        {
            // -----------------------------------
            // set members / check ctor parameters
            // -----------------------------------
            m_lsTrk            = lsTrk;
            this.m_LevSetIdx   = _iLevSet;
            this.m_SpeciesPair = SpeciesPair;
            this.ResultVector  = __ResultVector;
            m_CodomainMap      = CodomainMap;
            var _Parameters = (__Parameters != null) ? __Parameters.ToArray() : new DGField[0];

            if (__DomainFields.Count != DiffOp.DomainVar.Count)
            {
                throw new ArgumentException("mismatch between number of domain variables in spatial operator and given domain variables");
            }
            if (_Parameters.Length != DiffOp.ParameterVar.Count)
            {
                throw new ArgumentException("mismatch between number of parameter variables in spatial operator and given parameters");
            }
            if (m_CodomainMap.NoOfVariables != DiffOp.CodomainVar.Count)
            {
                throw new ArgumentException("mismatch between number of codomain variables in spatial operator and given codomain mapping");
            }

            m_DomainAndParamFields = ArrayTools.Cat(__DomainFields, _Parameters);
            this.DELTA             = __DomainFields.Count;

            // ------------------------
            // sort equation components
            // ------------------------

            int Gamma = m_CodomainMap.NoOfVariables;

            m_NonlinLsForm_V = DiffOp.GetArgMapping <INonlinLevelSetForm_V>(true,
                                                                            eq => ((eq.LevelSetTerms & (TermActivationFlags.V | TermActivationFlags.UxV | TermActivationFlags.GradUxV)) != 0) && Compfilter(eq),
                                                                            eq => (eq is ILevelSetForm) ? new NonlinearLevelSetFormVectorizer((ILevelSetForm)eq) : null);
            m_NonlinLsForm_GradV = DiffOp.GetArgMapping <INonlinLevelSetForm_GradV>(true,
                                                                                    eq => ((eq.LevelSetTerms & (TermActivationFlags.GradV | TermActivationFlags.UxGradV | TermActivationFlags.GradUxGradV)) != 0) && Compfilter(eq),
                                                                                    eq => (eq is ILevelSetForm) ? new NonlinearLevelSetFormVectorizer((ILevelSetForm)eq) : null);


            m_ValueRequired    = new bool[m_DomainAndParamFields.Length];
            m_GradientRequired = new bool[m_DomainAndParamFields.Length];

            m_NonlinLsForm_V.DetermineReqFields(m_GradientRequired,
                                                comp => ((comp.LevelSetTerms & (TermActivationFlags.GradUxGradV | TermActivationFlags.GradUxV)) != 0));
            m_NonlinLsForm_GradV.DetermineReqFields(m_GradientRequired,
                                                    comp => ((comp.LevelSetTerms & (TermActivationFlags.GradUxGradV | TermActivationFlags.GradUxV)) != 0));
            m_NonlinLsForm_V.DetermineReqFields(m_ValueRequired,
                                                comp => ((comp.LevelSetTerms & (TermActivationFlags.UxGradV | TermActivationFlags.UxV)) != 0));
            m_NonlinLsForm_GradV.DetermineReqFields(m_ValueRequired,
                                                    comp => ((comp.LevelSetTerms & (TermActivationFlags.UxGradV | TermActivationFlags.UxV)) != 0));

            for (int i = __DomainFields.Count; i < m_DomainAndParamFields.Length; i++)
            {
                m_ValueRequired[i] = true; // parameters are always required!
            }


            // -----
            // alloc
            // -----

            Koeff_V     = new MultidimensionalArray[Gamma];
            Koeff_GradV = new MultidimensionalArray[Gamma];
            for (int gamma = 0; gamma < Gamma; gamma++)
            {
                Koeff_V[gamma]     = new MultidimensionalArray(3);
                Koeff_GradV[gamma] = new MultidimensionalArray(4);
            }

            int L = m_DomainAndParamFields.Length;

            m_FieldValuesPos         = new MultidimensionalArray[L];
            m_FieldValuesNeg         = new MultidimensionalArray[L];
            m_FieldGradientValuesPos = new MultidimensionalArray[L];
            m_FieldGradientValuesNeg = new MultidimensionalArray[L];

            for (int l = 0; l < L; l++)
            {
                if (m_ValueRequired[l])
                {
                    m_FieldValuesPos[l] = new MultidimensionalArray(2);
                    m_FieldValuesNeg[l] = new MultidimensionalArray(2);
                }

                if (m_GradientRequired[l])
                {
                    m_FieldGradientValuesPos[l] = new MultidimensionalArray(3);
                    m_FieldGradientValuesNeg[l] = new MultidimensionalArray(3);
                }
            }


            // ------------------
            // init custom timers
            // ------------------

            base.CustomTimers             = new Stopwatch[] { new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch() };
            base.CustomTimers_Names       = new string[] { "Flux-Eval", "Basis-Eval", "Loops", "ParametersAndNormals", "Field-Eval" };
            base.CustomTimers_RootPointer = new int[5];
            ArrayTools.SetAll(base.CustomTimers_RootPointer, -1);

            this.m_NonlinLsForm_V_Watches     = this.m_NonlinLsForm_V.InitStopWatches(0, this);
            this.m_NonlinLsForm_GradV_Watches = this.m_NonlinLsForm_GradV.InitStopWatches(0, this);

            Flux_Eval            = base.CustomTimers[0];
            Basis_Eval           = base.CustomTimers[1];
            Loops                = base.CustomTimers[2];
            ParametersAndNormals = base.CustomTimers[3];
            Field_Eval           = base.CustomTimers[4];
        }
Exemplo n.º 18
0
        /// <summary>
        /// ctor.
        /// </summary>
        public NECQuadratureVolume(IGridData context,
                                   SpatialOperator DiffOp,
                                   IList <DGField> _DomainFields,
                                   IList <DGField> _ParameterFields,
                                   UnsetteledCoordinateMapping CodomainMapping,
                                   ICompositeQuadRule <QuadRule> domNrule)
            : base(context, DiffOp, _DomainFields, _ParameterFields, CodomainMapping)
        {
            // -----------------
            // quadrature object
            // -----------------

            m_Quad = CellQuadrature.GetQuadrature2(new int[] { CodomainMapping.NoOfCoordinatesPerCell }, context, domNrule,
                                                   this.EvaluateEx,
                                                   this.SaveIntegrationResults,
                                                   this.AllocateBuffers);

            int Gamma = _DomainFields.Count;

            // ------------------------
            // sort equation components
            // ------------------------

            m_NonlinSources = EquationComponentArgMapping <INonlinearSource> .GetArgMapping(DiffOp, true);

            m_NonlinFormV = EquationComponentArgMapping <INonlinVolumeForm_V> .GetArgMapping(DiffOp, true,
                                                                                             eq => ((eq.VolTerms & (TermActivationFlags.V | TermActivationFlags.UxV | TermActivationFlags.GradUxV)) != 0),
                                                                                             eq => (eq is IVolumeForm ? new NonlinVolumeFormVectorizer((IVolumeForm)eq) : null));

            m_NonlinFormGradV = EquationComponentArgMapping <INonlinVolumeForm_GradV> .GetArgMapping(DiffOp, true,
                                                                                                     eq => ((eq.VolTerms & (TermActivationFlags.UxGradV | TermActivationFlags.GradV | TermActivationFlags.GradUxGradV)) != 0),
                                                                                                     eq => (eq is IVolumeForm ? new NonlinVolumeFormVectorizer((IVolumeForm)eq) : null));

            Debug.Assert(base.m_DomainFields.Length >= Gamma);
            m_ValueRequired    = new bool[base.m_DomainFields.Length];
            m_GradientRequired = new bool[Gamma];

            // base.m_DomainFields may also contain parameter fields:
            for (int i = Gamma; i < base.m_DomainFields.Length; i++)
            {
                m_ValueRequired[i] = true;
            }

            this.m_NonlinFormV.DetermineReqFields(m_GradientRequired,
                                                  comp => ((comp.VolTerms & (TermActivationFlags.GradUxGradV | TermActivationFlags.GradUxV)) != 0));
            this.m_NonlinFormGradV.DetermineReqFields(m_GradientRequired,
                                                      comp => ((comp.VolTerms & (TermActivationFlags.GradUxGradV | TermActivationFlags.GradUxV)) != 0));
            this.m_NonlinFormV.DetermineReqFields(m_ValueRequired,
                                                  comp => ((comp.VolTerms & (TermActivationFlags.UxGradV | TermActivationFlags.UxV)) != 0));
            this.m_NonlinFormGradV.DetermineReqFields(m_ValueRequired,
                                                      comp => ((comp.VolTerms & (TermActivationFlags.UxGradV | TermActivationFlags.UxV)) != 0));
            this.m_NonlinSources.DetermineReqFields(m_ValueRequired, comp => true);
            base.m_NonlinFluxes.DetermineReqFields(m_ValueRequired, comp => true);
            base.m_NonlinFluxesEx.DetermineReqFields(m_ValueRequired, comp => true);

            // ---------
            // profiling
            // ---------

            var _CustomTimers       = new Stopwatch[] { new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch() };
            var _CustomTimers_Names = new string[] { "Flux-Eval", "Basis-Eval", "Field-Eval", "Loops", "ParametersAndNormals", "Flux-Trafo" };

            Flux_Eval                       = _CustomTimers[0];
            Flux_Trafo                      = _CustomTimers[5];
            Field_Eval                      = _CustomTimers[2];
            Basis_Eval                      = _CustomTimers[1];
            Loops                           = _CustomTimers[3];
            ParametersAndNormals            = _CustomTimers[4];
            m_Quad.CustomTimers             = m_Quad.CustomTimers.Cat(_CustomTimers);
            m_Quad.CustomTimers_Names       = m_Quad.CustomTimers_Names.Cat(_CustomTimers_Names);
            m_Quad.CustomTimers_RootPointer = new int[_CustomTimers_Names.Length];
            ArrayTools.SetAll(m_Quad.CustomTimers_RootPointer, -1);

            this.m_NonlinSources_watch   = this.m_NonlinSources.InitStopWatches(0, m_Quad);
            this.m_NonlinFormV_watch     = this.m_NonlinFormV.InitStopWatches(0, m_Quad);
            this.m_NonlinFormGradV_watch = this.m_NonlinFormGradV.InitStopWatches(0, m_Quad);
            base.m_NonlinFluxesWatches   = base.m_NonlinFluxes.InitStopWatches(0, m_Quad);
            base.m_NonlinFluxesExWatches = base.m_NonlinFluxesEx.InitStopWatches(0, m_Quad);

            // ---------------------
            // alloc multidim arrays
            // ---------------------

            m_FluxValues    = new MultidimensionalArray[m_CodomainBasisS.Length];
            m_FluxValuesTrf = new MultidimensionalArray[m_CodomainBasisS.Length];
            for (int i = 0; i < m_FluxValues.Length; i++)
            {
                if (m_NonlinFluxes[i].m_AllComponentsOfMyType.Length > 0 || m_NonlinFluxesEx[i].m_AllComponentsOfMyType.Length > 0 || m_NonlinFormGradV[i].m_AllComponentsOfMyType.Length > 0)
                {
                    m_FluxValues[i]    = new MultidimensionalArray(3);
                    m_FluxValuesTrf[i] = new MultidimensionalArray(3);

                    Basis GradBasis = base.m_CodomainBasisS[i];
                    if (m_MaxCodBasis_Gradient == null || m_MaxCodBasis_Gradient.Degree < GradBasis.Degree)
                    {
                        m_MaxCodBasis_Gradient = GradBasis;
                    }
                }
            }

            m_SourceValues = new MultidimensionalArray[m_CodomainBasisS.Length];
            for (int i = 0; i < m_SourceValues.Length; i++)
            {
                if (m_NonlinSources[i].m_AllComponentsOfMyType.Length > 0 || m_NonlinFormV[i].m_AllComponentsOfMyType.Length > 0)
                {
                    m_SourceValues[i] = new MultidimensionalArray(2);

                    Basis ValBasis = base.m_CodomainBasisS[i];
                    if (m_MaxCodBasis == null || m_MaxCodBasis.Degree < ValBasis.Degree)
                    {
                        m_MaxCodBasis = ValBasis;
                    }
                }
            }


            m_FieldValues    = new MultidimensionalArray[m_DomainFields.Length];
            m_FieldGradients = new MultidimensionalArray[Gamma];
            for (int i = 0; i < m_DomainFields.Length; i++)
            {
                if (m_ValueRequired[i])
                {
                    m_FieldValues[i] = new MultidimensionalArray(2);
                }
                if (i < Gamma && m_GradientRequired[i])
                {
                    m_FieldGradients[i] = new MultidimensionalArray(3);
                }
            }


            m_TestFuncWeighted     = new MultidimensionalArray(2);
            m_TestFuncGradWeighted = new MultidimensionalArray(3);
        }
Exemplo n.º 19
0
 public CellBoundaryQuadratureImpl(
     int[] noOfIntegralsPerCell, Grid.Classic.GridData context, ICompositeQuadRule <TQuadRule> domNrule, CoordinateSystem cs)
     : base(noOfIntegralsPerCell, context, domNrule, cs)
 {
 }
Exemplo n.º 20
0
 /// <summary>
 /// Constructs a volume integrator.
 /// </summary>
 /// <param name="owner">
 /// Creator of this object.
 /// </param>
 /// <param name="volumeRule">
 /// quadrature rules and domain
 /// </param>
 public VolumeIntegrator(LevelSetIntegrator owner, ICompositeQuadRule <QuadRule> volumeRule)
     : base(new int[] { owner.m_NoOfIntegrands }, owner.m_LevSetTrk.GridDat, volumeRule)
 {
     m_Owner        = owner;
     m_WeightBuffer = new MultidimensionalArray(2);
 }
Exemplo n.º 21
0
        void SpecialProjection(LevelSetTracker LsTrk, int order, DGField[] Uin, VectorField <SinglePhaseField> Uout)
        {
            var CC   = LsTrk.Regions.GetCutCellMask();
            var gDat = LsTrk.GridDat;

            // get quadrature rules
            // ====================

            //XQuadSchemeHelper H = new XQuadSchemeHelper(LsTrk, MomentFittingVariant);
            var H = LsTrk.GetXDGSpaceMetrics(new[] { LsTrk.GetSpeciesId("A") }, order, 1).XQuadSchemeHelper;
            CellQuadratureScheme                      cqs      = H.GetLevelSetquadScheme(0, CC);
            ICompositeQuadRule <QuadRule>             surfRule = cqs.Compile(gDat, order);
            ICompositeQuadRule <CellBoundaryQuadRule> bndyRule = (new CellBoundaryQuadratureScheme(true, CC)).Compile(gDat, order);



            // Compute Mass matrix and RHS for the 'strange' projection
            // ========================================================
            int L = CC.NoOfItemsLocally;
            var Q = new QuadratureKernels(Uin, L);

            Q.BlockCnt = 0;
            CellQuadrature.GetQuadrature(
                new int[] { Q.Nnx + Q.D, Q.Nnx },
                gDat,
                surfRule,
                Q.Evaluate, Q.SaveIntegrationResults_surf).Execute();
            Debug.Assert(Q.BlockCnt == L);

            Q.BlockCnt = 0;
            CellBoundaryQuadrature <CellBoundaryQuadRule> .GetQuadrature(
                new int[] { Q.Nnx + Q.D, Q.Nnx },
                gDat,
                bndyRule,
                Q.Evaluate, Q.SaveIntegrationResults_bndy).Execute();

            Debug.Assert(Q.BlockCnt == L);

            // solve the non-diagonal mass matrix systems
            // ==========================================

            int BlkCnt = 0;

            foreach (int jCell in CC.ItemEnum)
            {
                var MassMatrix = Q.MassMatrix.ExtractSubArrayShallow(BlkCnt, -1, -1);
                var RHS        = Q.RHS.ExtractSubArrayShallow(BlkCnt, -1, -1);

                // Die "Massenmatrix" muss nicht unbedingt invbar sein, daher: Least-Squares solve
                MassMatrix.LeastSquareSolve(RHS);

                for (int d = 0; d < Q.D; d++)
                {
                    for (int n = 0; n < Q.Nnx; n++)
                    {
                        Uout[d].Coordinates[jCell, n] = RHS[n, d];
                    }
                }

                BlkCnt++;
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// ctor.
        /// </summary>
        internal LECQuadratureLevelSet(IGridData context,
                                       XSpatialOperator DiffOp,
                                       M Matrix, V OffsetVec,
                                       UnsetteledCoordinateMapping RowMap, IList <DGField> ParamsMap, UnsetteledCoordinateMapping ColMap,
                                       LevelSetTracker lsTrk, int _iLevSet, ICollection <SpeciesId> SpeciesPair,
                                       ICompositeQuadRule <QuadRule> domAndRule,
                                       IDictionary <SpeciesId, MultidimensionalArray> __LenScales) //
            : base(new int[] { RowMap.MaxTotalNoOfCoordinatesPerCell, 1 + ((Matrix == null) ? 0 : ColMap.MaxTotalNoOfCoordinatesPerCell) },
                   context,
                   domAndRule) //
        {
            // ------------------
            // init custom timers
            // ------------------

            base.CustomTimers             = new Stopwatch[] { new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch() };
            base.CustomTimers_Names       = new string[] { "Flux-Eval", "Basis-Eval", "Loops", "ParametersAndNormals" };
            base.CustomTimers_RootPointer = new int[4];
            ArrayTools.SetAll(base.CustomTimers_RootPointer, -1);

            // -----------------------------------
            // set members / check ctor parameters
            // -----------------------------------

            m_RowMap     = RowMap;
            m_ColMap     = ColMap;
            m_Parameters = (ParamsMap != null) ? ParamsMap.ToArray() : new DGField[0];
            m_LenScales  = __LenScales;


            if (m_RowMap.BasisS.Count != DiffOp.CodomainVar.Count)
            {
                throw new ArgumentException("mismatch between number of codomain variables in spatial operator and row mapping");
            }
            if (m_ColMap.BasisS.Count != DiffOp.DomainVar.Count)
            {
                throw new ArgumentException("mismatch between number of domain variables in spatial operator and column mapping");
            }
            if (m_Parameters.Length != DiffOp.ParameterVar.Count)
            {
                throw new ArgumentException("mismatch between number of parameter variables in spatial operator and given parameters");
            }

            int Gamma = m_RowMap.BasisS.Count;

            m_lsTrk = lsTrk;

            if (Matrix != null && (Matrix.RowPartitioning.LocalLength != RowMap.LocalLength))
            {
                throw new ArgumentException("mismatch between matrix number of rows and row mapping.");
            }
            if (Matrix != null && (Matrix.ColPartition.LocalLength != ColMap.LocalLength))
            {
                throw new ArgumentException("mismatch between matrix number of columns and column mapping.");
            }

            this.m_LevSetIdx = _iLevSet;

            this.OperatorMatrix = Matrix;
            this.OperatorAffine = OffsetVec;
            this.m_SpeciesPair  = SpeciesPair;

            // ------------------------
            // sort equation components
            // ------------------------

            //m_BiLinForms = DiffOp.GetArgMapping<IBilinearForm>(true, Compfilter<IBilinearForm>);
            //m_2ndDerivFlux = DiffOp.GetArgMapping<ILinear2ndDerivativeCouplingFlux>(true, Compfilter<ILinear2ndDerivativeCouplingFlux>);

            m_LsForm_UxV = DiffOp.GetArgMapping <ILinearLevelSetComponent_UxV>(true,
                                                                               eq => ((eq.LevelSetTerms & TermActivationFlags.UxV) != 0) && Compfilter(eq),
                                                                               eq => (eq is ILevelSetComponent) ? new LinearLevelSetComponentVectorizer(lsTrk, (ILevelSetComponent)eq) : null);
            m_LsForm_GradUxV = DiffOp.GetArgMapping <ILinearLevelSetComponent_GradUxV>(true,
                                                                                       eq => ((eq.LevelSetTerms & TermActivationFlags.GradUxV) != 0) && Compfilter(eq),
                                                                                       eq => (eq is ILevelSetComponent) ? new LinearLevelSetComponentVectorizer(lsTrk, (ILevelSetComponent)eq) : null);
            m_LsForm_UxGradV = DiffOp.GetArgMapping <ILinearLevelSetComponent_UxGradV>(true,
                                                                                       eq => ((eq.LevelSetTerms & TermActivationFlags.UxGradV) != 0) && Compfilter(eq),
                                                                                       eq => (eq is ILevelSetComponent) ? new LinearLevelSetComponentVectorizer(lsTrk, (ILevelSetComponent)eq) : null);
            m_LsForm_GradUxGradV = DiffOp.GetArgMapping <ILinearLevelSetComponent_GradUxGradV>(true,
                                                                                               eq => ((eq.LevelSetTerms & TermActivationFlags.GradUxGradV) != 0) && Compfilter(eq),
                                                                                               eq => (eq is ILevelSetComponent) ? new LinearLevelSetComponentVectorizer(lsTrk, (ILevelSetComponent)eq) : null);
            m_LsForm_V = DiffOp.GetArgMapping <ILinearLevelSetComponent_V>(true,
                                                                           eq => ((eq.LevelSetTerms & TermActivationFlags.V) != 0 && Compfilter(eq)),
                                                                           eq => (eq is ILevelSetComponent) ? new LinearLevelSetComponentVectorizer(lsTrk, (ILevelSetComponent)eq) : null);
            m_LsForm_GradV = DiffOp.GetArgMapping <ILinearLevelSetComponent_GradV>(true,
                                                                                   eq => ((eq.LevelSetTerms & TermActivationFlags.GradV) != 0) && Compfilter(eq),
                                                                                   eq => (eq is ILevelSetComponent) ? new LinearLevelSetComponentVectorizer(lsTrk, (ILevelSetComponent)eq) : null);

            // -----
            // alloc
            // -----

            AllocEmpty(m_LsForm_UxV, out Koeff_UxV, out Sum_Koeff_UxV, 5, false);
            AllocEmpty(m_LsForm_GradUxV, out Koeff_NablaUxV, out Sum_Koeff_NablaUxV, 6, false);
            AllocEmpty(m_LsForm_UxGradV, out Koeff_UxNablaV, out Sum_Koeff_UxNablaV, 6, false);
            AllocEmpty(m_LsForm_GradUxGradV, out Koeff_NablaUxNablaV, out Sum_Koeff_NablaUxNablaV, 7, false);

            AllocEmpty(m_LsForm_V, out Koeff_V, out Sum_Koeff_V, 3, true);
            AllocEmpty(m_LsForm_GradV, out Koeff_NablaV, out Sum_Koeff_NablaV, 4, true);
        }
Exemplo n.º 23
0
        /// <summary>
        /// This call computes an integral measure which may depend on
        /// this <see cref="DGField"/> an the given <paramref name="function"/>;
        /// This is a collective call, it must be invoked by all
        /// MPI processes within the communicator; internally, it invokes MPI_Allreduce;
        /// </summary>
        /// <param name="function"></param>
        /// <param name="rule">
        /// composite quadrature rule.
        /// </param>
        /// <param name="Map">
        /// Arbiter mapping applied to the values of this field and
        /// <paramref name="function"/> at some point, which is finally integrated.
        /// E.g., the mapping for an L2-error would be \f$ (\vec{x},a,b) => (a - b)^2 \f$,
        /// where \f$ a \f$ is the value of this field at some point \f$ \vec{x} \f$ and
        /// \f$ b \f$ is the value of <paramref name="function"/> at \f$ \vec{x} \f$.
        /// </param>
        /// <returns>
        /// on all invoking MPI processes, the L2 norm of
        /// this field minus <paramref name="function"/>
        /// </returns>
        public double LxError(ScalarFunctionEx function, Func <double[], double, double, double> Map, ICompositeQuadRule <QuadRule> rule)
        {
            MPICollectiveWatchDog.Watch(csMPI.Raw._COMM.WORLD);

            using (new FuncTrace()) {
                LxNormQuadrature l2nq = new LxNormQuadrature(this, function, Map, rule);
                l2nq.Execute();

                double nrmtot = l2nq.LxNorm.MPISum();
                return(nrmtot);
            }
        }
Exemplo n.º 24
0
 internal IntegralOverExQuadrature(IGridData dat, DGField[] fields, ICompositeQuadRule <QuadRule> qr, Func f)
     : base(new int[] { 1 }, dat, qr)
 {
     m_fields = fields;
     m_f      = f;
 }
Exemplo n.º 25
0
        /// <summary>
        /// Variant of
        /// <see cref="LxError(ScalarFunction, Func{double, double, double}, ICompositeQuadRule{QuadRule})"/>
        /// that computes the cell-local Lx norm (and does thus not include MPI
        /// communication)
        /// </summary>
        /// <param name="function">
        /// Optional: Reference function for error computation. If null, zero
        /// is taken as the reference function
        /// </param>
        /// <param name="quadRule">
        /// composite quadrature rule.
        /// </param>
        /// <param name="Map">
        /// Arbitrary mapping applied to the values of this field and
        /// <paramref name="function"/> at some point, which is finally
        /// integrated. E.g., the mapping for an L2-error would be
        /// \f$ (a,b) => (a - b)^2 \f$, where \f$ a \f$ is the value of this
        /// field at some point \f$ \vec{x} \f$ and \f$ b \f$ is the value of
        /// <paramref name="function"/> at \f$ \vec{x} \f$.
        /// </param>
        /// <returns>
        /// The cell-local Lx norm of this field minus
        /// <paramref name="function"/>, approximated by the quadrature rule
        /// <paramref name="quadRule"/>
        /// </returns>
        public double[] LocalLxError(ScalarFunction function, Func <double[], double, double, double> Map, ICompositeQuadRule <QuadRule> quadRule)
        {
            using (new FuncTrace()) {
                LocalLxNormQuadrature quacdrature = new LocalLxNormQuadrature(this, function, Map, quadRule);
                quacdrature.Execute();

                return(quacdrature.LocalLxNorms);
            }
        }
Exemplo n.º 26
0
        protected override double RunSolverOneStep(int TimestepNo, double phystime, double dt)
        {
            //if (base.Control.timeDependent) {
            //    dt = base.GetFixedTimestep();
            //    Console.WriteLine("Timestep {0}, dt = {1} ...", TimestepNo, dt);
            //} else {
            base.TerminationKey = true;
            dt = 1.0;
            Console.WriteLine("Steady solve ...");
            //}

            double mintime, maxtime;
            bool   converged;
            int    NoOfIterations, DOFs;


            // direct solver
            this.ReferenceSolve();
            //this.ConsistencyTest();


            // new solver framework: multigrid, blablablah ...

            ExperimentalSolver(out mintime, out maxtime, out converged, out NoOfIterations, out DOFs);
            this.Op_Agglomeration.Extrapolate(this.u.Mapping);

            //Stats:
            {
                int BlkSize_min   = u.Mapping.MinTotalNoOfCoordinatesPerCell;
                int BlkSize_max   = u.Mapping.MaxTotalNoOfCoordinatesPerCell;
                int NoOfMtxBlocks = 0;
                foreach (int[] Neigs in this.GridData.iLogicalCells.CellNeighbours)
                {
                    NoOfMtxBlocks++;               //               diagonal block
                    NoOfMtxBlocks += Neigs.Length; // off-diagonal block
                }
                NoOfMtxBlocks = NoOfMtxBlocks.MPISum();

                int MtxBlockSize = BlkSize_max * BlkSize_max;
                int MtxSize      = MtxBlockSize * NoOfMtxBlocks;

                double MtxStorage = MtxSize * (8.0 + 4.0) / (1024 * 1024); // 12 bytes (double+int) per entry

                Console.WriteLine("   System size:                 {0}", u.Mapping.TotalLength);
                Console.WriteLine("   No of blocks:                {0}", u.Mapping.TotalNoOfBlocks);
                Console.WriteLine("   No of blocks in matrix:      {0}", NoOfMtxBlocks);
                Console.WriteLine("   DG coordinates per cell:     {0}", BlkSize_max);
                Console.WriteLine("   Non-zeros per matrix block:  {0}", MtxBlockSize);
                Console.WriteLine("   Total non-zeros in matrix:   {0}", MtxSize);
                Console.WriteLine("   maximal matrix storage (MB): {0}", MtxStorage);

                Console.WriteLine("DOF: {0}", DOFs);
                Console.WriteLine("min Blocksize: {0}", u.Mapping.MinTotalNoOfCoordinatesPerCell);
                Console.WriteLine("max Blocksize: {0}", u.Mapping.MaxTotalNoOfCoordinatesPerCell);

                base.QueryHandler.ValueQuery("maxBlkSize", u.Mapping.MaxTotalNoOfCoordinatesPerCell, true);
                base.QueryHandler.ValueQuery("minBlkSize", u.Mapping.MinTotalNoOfCoordinatesPerCell, true);
                base.QueryHandler.ValueQuery("NumberOfMatrixBlox", NoOfMtxBlocks, true);
                base.QueryHandler.ValueQuery("DOFs", DOFs, true);
            }

            base.QueryHandler.ValueQuery("minSolRunT", mintime, true);
            base.QueryHandler.ValueQuery("maxSolRunT", maxtime, true);
            base.QueryHandler.ValueQuery("Conv", converged ? 1.0 : 0.0, true);
            base.QueryHandler.ValueQuery("NoIter", NoOfIterations, true);

            Console.WriteLine("maximal Multigridlevel: {0}", MaxMlevel);
            base.QueryHandler.ValueQuery("maxMultigridlvl", MaxMlevel, true);

            Console.WriteLine("done.");

            if (this.Control.ExcactSolSupported)
            {
                this.uErr.Clear();
                this.uErr.Acc(+1.0, u);
                this.uErr.Acc(-1.0, uEx);

                double L2_ERR = this.uErr.L2Norm();

                base.QueryHandler.ValueQuery("L2_ERR", L2_ERR, true);

                this.LsTrk.UpdateTracker();
                int order = Math.Max(u.Basis.Degree, Math.Max(uErr.Basis.Degree, uEx.Basis.Degree)) * 2 + 1;
                //var scheme = new XQuadSchemeHelper(this.LsTrk, this.Control.HMFversion, this.LsTrk.SpeciesIdS.ToArray());
                var scheme = this.LsTrk.GetXDGSpaceMetrics(this.LsTrk.SpeciesIdS.ToArray(), order, 1).XQuadSchemeHelper;


                var A_scheme = scheme.GetVolumeQuadScheme(this.LsTrk.GetSpeciesId("A"));
                var B_scheme = scheme.GetVolumeQuadScheme(this.LsTrk.GetSpeciesId("B"));

                ICompositeQuadRule <QuadRule> A_rule = A_scheme.Compile(this.GridData, order);
                ICompositeQuadRule <QuadRule> B_rule = B_scheme.Compile(this.GridData, order);

                foreach (var _rule in new ICompositeQuadRule <QuadRule>[] { A_rule, B_rule })
                {
                    foreach (var ckR in _rule)
                    {
                        ckR.Rule.Weights.CheckForNanOrInf(true, true, true);
                        ckR.Rule.Nodes.CheckForNanOrInf(true, true, true);
                    }
                }

                double L2_ERR_HMF_A = this.u.GetSpeciesShadowField("A").LxError(this.Control.InitialValues_Evaluators["uEx#A"].Vectorize(), null, A_rule).Sqrt();
                double L2_ERR_HMF_B = this.u.GetSpeciesShadowField("B").LxError(this.Control.InitialValues_Evaluators["uEx#B"].Vectorize(), null, B_rule).Sqrt();
                double L2_ERR_HMF   = (L2_ERR_HMF_A.Pow2() + L2_ERR_HMF_B.Pow2()).Sqrt();
                base.QueryHandler.ValueQuery("L2_ERR_HMF_A", L2_ERR_HMF_A, true);
                base.QueryHandler.ValueQuery("L2_ERR_HMF_B", L2_ERR_HMF_B, true);
                base.QueryHandler.ValueQuery("L2_ERR_HMF", L2_ERR_HMF, true);


                Console.WriteLine("Error norm (standard):       " + L2_ERR);
                Console.WriteLine("Error norm (HMF, Species A): " + L2_ERR_HMF_A);
                Console.WriteLine("Error norm (HMF, Species B): " + L2_ERR_HMF_B);
                Console.WriteLine("Error norm (HMF):            " + L2_ERR_HMF);
            }

            return(dt);
        }
Exemplo n.º 27
0
 /// <summary>
 /// ctor
 /// </summary>
 public SignedDistanceErrorQuad(LevelSet phi, ICompositeQuadRule <QuadRule> daRule)
     : base(new int[] { 1 }, phi.GridDat, daRule)
 {
     m_phi     = phi;
     m_gradPhi = new MultidimensionalArray(3);
 }
Exemplo n.º 28
0
 public LocalLxNormQuadrature(DGField owner, ScalarFunction func, Func <double[], double, double, double> Map, ICompositeQuadRule <QuadRule> rule)
     : base(owner, func, Map, rule)
 {
     m_localLxNorms = new double[rule.NumberOfItems];
 }