예제 #1
0
        /// <summary>
        /// %
        /// </summary>
        public double VolumeForm(ref CommonParamsVol cpv, double[] U, double[,] GradU, double V, double[] GradV)
        {
            double ret   = 0.0;
            int    GAMMA = m_VolForm.ArgumentOrdering.Count;
            int    D     = cpv.D;

            Debug.Assert(D == m_SpatialDimension, "Spatial Dimension Mismatch.");

            double delta = GetTmpTrialVals(cpv.Parameters, out var Utmp, out var GradUtmp);

            CommonParamsVol clonedParams = cpv;

            Debug.Assert(object.ReferenceEquals(cpv, clonedParams) == false);
            GetOrgParams(cpv.Parameters, out clonedParams.Parameters);

            double f0 = m_VolForm.VolumeForm(ref clonedParams, Utmp, GradUtmp, V, GradV);

            ret += f0;                               // affine contribution - contains V and GradV contribution

            for (int iVar = 0; iVar < GAMMA; iVar++) // loop over trial variables

            {
                if (((m_VolForm.VolTerms & (TermActivationFlags.UxV | TermActivationFlags.UxGradV)) != 0)
                    )
                {
                    //&& (U[iVar] != 0.0)) { // perf. opt.
                    ret += Diff(ref Utmp[iVar], U[iVar], ref clonedParams, Utmp, GradUtmp, V, GradV, delta, f0, -1, iVar);
                }

                if (((m_VolForm.VolTerms & (TermActivationFlags.GradUxGradV | TermActivationFlags.GradUxV)) != 0)
                    //&& (GradU.GetRow(iVar).L2NormPow2() != 0.0)) {
                    )
                {
                    for (int d = 0; d < D; d++)
                    {
                        ret += Diff(ref GradUtmp[iVar, d], GradU[iVar, d], ref clonedParams, Utmp, GradUtmp, V, GradV, delta, f0, d, iVar);
                    }
                }
            }

            return(ret);
        }
예제 #2
0
        void INonlinVolumeForm_V.Form(ref VolumFormParams prm, MultidimensionalArray[] U, MultidimensionalArray[] GradU, MultidimensionalArray f)
        {
            int L = prm.Len;

            Debug.Assert(f.GetLength(0) == L);
            int K         = f.GetLength(1); // no of nodes per cell
            int D         = prm.GridDat.SpatialDimension;
            int _NOParams = this.ParameterOrdering == null ? 0 : this.ParameterOrdering.Count;

            Debug.Assert(_NOParams == prm.ParameterVars.Length);
            int _NOargs = this.ArgumentOrdering.Count;

            Debug.Assert(_NOargs == U.Length);
            Debug.Assert(_NOargs == GradU.Length);

            CommonParamsVol cpv;

            cpv.GridDat    = prm.GridDat;
            cpv.Parameters = new double[_NOParams];
            cpv.Xglobal    = new double[D];
            cpv.time       = prm.time;
            double[] _GradV = new double[D];
            double[,] _GradU = new double[_NOargs, D];
            double[] _U = new double[_NOargs];
            double   _V = 1.0;


            for (int l = 0; l < L; l++)  // loop over cells...
            {
                cpv.jCell = prm.j0 + l;

                for (int k = 0; k < K; k++)  // loop over nodes...


                {
                    for (int np = 0; np < _NOParams; np++)
                    {
                        cpv.Parameters[np] = prm.ParameterVars[np][l, k];
                    }
                    for (int d = 0; d < D; d++)
                    {
                        cpv.Xglobal[d] = prm.Xglobal[l, k, d];
                    }

                    for (int na = 0; na < _NOargs; na++)
                    {
                        if (U[na] != null)
                        {
                            _U[na] = U[na][l, k];
                        }
                        if (GradU[na] != null)
                        {
                            for (int d = 0; d < D; d++)
                            {
                                _GradU[na, d] = GradU[na][l, k, d];
                            }
                        }
                    }

                    f[l, k] += volForm.VolumeForm(ref cpv, _U, _GradU, _V, _GradV);
                }
            }
        }
예제 #3
0
        void INonlinVolumeForm_V.Form(ref VolumFormParams prm, MultidimensionalArray[] U, MultidimensionalArray[] GradU, MultidimensionalArray f)
        {
            int L = prm.Len;

            Debug.Assert(f.GetLength(0) == L);
            int K         = f.GetLength(1); // no of nodes per cell
            int D         = prm.GridDat.SpatialDimension;
            int _NOParams = this.ParameterOrdering == null ? 0 : this.ParameterOrdering.Count;

            Debug.Assert(_NOParams == prm.ParameterVars.Length);
            int _NOargs = this.ArgumentOrdering.Count;

            Debug.Assert(_NOargs == U.Length);
            Debug.Assert(_NOargs == GradU.Length);

            CommonParamsVol cpv;

            cpv.GridDat    = prm.GridDat;
            cpv.Parameters = new double[_NOParams];
            cpv.Xglobal    = new Vector(D);
            cpv.time       = prm.time;
            double[] _GradV = new double[D];
            double[,] _GradU = new double[_NOargs, D];
            double[] _U = new double[_NOargs];
            double   _V = 1.0;

#if DEBUG
            MultidimensionalArray f_check = null;

            if (volForm is INonlinVolumeForm_V volForm_)
            {
                f_check = f.CloneAs();
                volForm_.Form(ref prm, U, GradU, f);
                var f_tmp = f;
                f       = f_check;
                f_check = f_tmp;
            }
#endif

            for (int l = 0; l < L; l++)   // loop over cells...
            {
                cpv.jCell = prm.j0 + l;

                for (int k = 0; k < K; k++)   // loop over nodes...


                {
                    for (int np = 0; np < _NOParams; np++)
                    {
                        cpv.Parameters[np] = prm.ParameterVars[np][l, k];
                    }
                    for (int d = 0; d < D; d++)
                    {
                        cpv.Xglobal[d] = prm.Xglobal[l, k, d];
                    }

                    for (int na = 0; na < _NOargs; na++)
                    {
                        if (U[na] != null)
                        {
                            _U[na] = U[na][l, k];
                        }
                        if (GradU[na] != null)
                        {
                            for (int d = 0; d < D; d++)
                            {
                                _GradU[na, d] = GradU[na][l, k, d];
                            }
                        }
                    }

                    f[l, k] += volForm.VolumeForm(ref cpv, _U, _GradU, _V, _GradV);
                }
            }
#if DEBUG
            if (f_check != null)
            {
                double f_RelErr = f_check.L2Dist(f) / Math.Max(f.L2Norm(), 1);
                Debug.Assert(f_RelErr < 1e-14);
            }
#endif
        }