Exemple #1
0
        /// <summary>
        /// Utility function to evaluate DG fields together with global nodes.
        /// </summary>
        /// <param name="f">DG field to evaluate.</param>
        /// <param name="NS">node set.</param>
        /// <param name="cm">optional cell mask.</param>
        /// <returns>
        /// Global nodes and function values at these nodes;
        /// 1st index: cell index;
        /// 2nd index: node index;
        /// 3rd index: spatial direction
        /// </returns>
        public static MultidimensionalArray Evaluate(this DGField f, NodeSet NS, CellMask cm = null)
        {
            IGridData g = f.GridDat;

            if (cm == null)
            {
                cm = CellMask.GetFullMask(g);
            }
            int D = g.SpatialDimension;

            MultidimensionalArray ret = MultidimensionalArray.Create(new int[] { cm.NoOfItemsLocally, NS.NoOfNodes, D + 1 });

            int jsub = 0;

            foreach (Chunk ck in cm)
            {
                var globNodes = ret.ExtractSubArrayShallow(new int[] { jsub, 0, 0 }, new int[] { jsub + ck.Len - 1, NS.NoOfNodes - 1, D - 1 });
                var fldValues = ret.ExtractSubArrayShallow(new int[] { jsub, 0, D }, new int[] { jsub + ck.Len - 1, NS.NoOfNodes - 1, D - 1 });

                g.TransformLocal2Global(NS, ck.i0, ck.Len, globNodes);
                f.Evaluate(ck.i0, ck.Len, NS, fldValues);
            }

            return(ret);
        }
Exemple #2
0
            protected override void Evaluate(int i0, int Length, QuadRule rule, MultidimensionalArray EvalResult)
            {
                NodeSet NodesUntransformed = rule.Nodes;
                int     M = NodesUntransformed.GetLength(0);
                //int D = NodesUntransformed.GetLength(1);

                MultidimensionalArray fieldvalsA = EvalResult.ResizeShallow(new int[] { Length, NodesUntransformed.GetLength(0) });

                fieldvalsA.Clear();
                m_FieldA.Evaluate(i0, Length, NodesUntransformed, fieldvalsA, 1.0);
                fieldvalsB.Clear();
                m_FieldB.Evaluate(i0, Length, NodesUntransformed, fieldvalsB, 1.0);

                for (int j = 0; j < Length; j++)
                {
                    for (int m = 0; m < M; m++)
                    {
                        EvalResult[j, m, 0] = fieldvalsA[j, m] * fieldvalsB[j, m];
                    }
                }
            }
Exemple #3
0
            /// <summary>
            /// Integrand evaluation.
            /// </summary>
            protected override void Evaluate(int i0, int Length, QuadRule rule, MultidimensionalArray EvalResult)
            {
                NodeSet NodesUntransformed = rule.Nodes;
                int     M = NodesUntransformed.GetLength(0);
                int     D = NodesUntransformed.GetLength(1);

                // evaluate scalar function ans store result in 'EvalResult'
                // =========================================================
                Debug.Assert(!((m_func != null) && (m_funcEx != null)));
                if (m_func != null || m_Map != null)
                {
                    GridDat.TransformLocal2Global(NodesUntransformed, i0, Length, m_NodesTransformed, 0);
                }

                if (m_func != null)
                {
                    MultidimensionalArray inp  = m_NodesTransformed.ResizeShallow(new int[] { Length *M, D });
                    MultidimensionalArray outp = EvalResult.ResizeShallow(new int[] { Length *M });
                    m_func(inp, outp);
                    Debug.Assert(m_funcEx == null);
                }
                if (m_funcEx != null)
                {
                    m_funcEx(i0, Length, NodesUntransformed, EvalResult.ExtractSubArrayShallow(-1, -1, 0));
                    Debug.Assert(m_func == null);
                }


                if (m_Map == null)
                {
                    // L2 error branch
                    // +++++++++++++++

                    MultidimensionalArray fieldvals = EvalResult.ResizeShallow(new int[] { Length, NodesUntransformed.GetLength(0) });
                    m_Owner.Evaluate(i0, Length, NodesUntransformed, fieldvals, -1.0);

                    for (int j = 0; j < Length; j++)
                    {
                        for (int m = 0; m < M; m++)
                        {
                            double e;
                            e = EvalResult[j, m, 0];
                            EvalResult[j, m, 0] = e * e;
                        }
                    }
                }
                else
                {
                    // arbitrary mapping branch
                    // ++++++++++++++++++++++++

                    MultidimensionalArray fieldvals = MultidimensionalArray.Create(new int[] { Length, NodesUntransformed.GetLength(0) });
                    m_Owner.Evaluate(i0, Length, NodesUntransformed, fieldvals, -1.0);

                    double[] X = new double[D];

                    for (int j = 0; j < Length; j++)
                    {
                        for (int m = 0; m < M; m++)
                        {
                            double e;
                            e = EvalResult[j, m, 0];

                            for (int d = 0; d < D; d++)
                            {
                                X[d] = m_NodesTransformed[j, m, d];
                            }

                            EvalResult[j, m, 0] = this.m_Map(X, fieldvals[j, m], e);
                        }
                    }
                }
            }