Ejemplo n.º 1
0
        /// <summary>
        /// Dispatcher to determine the correct sub-class of
        /// <see cref="BoundaryConditionSource"/> when creating a source term
        /// for a specific equation component.
        /// </summary>
        public static BoundaryConditionSource CreateBoundaryConditionSource(
            this IEquationComponent equationComponent, CNSControl control, ISpeciesMap speciesMap, BoundaryCondition boundaryCondition)
        {
            BoundaryConditionSource result;

            if (equationComponent is INonlinearFlux)
            {
                result = new BoundaryConditionSourceFromINonlinearFlux(
                    control, speciesMap, boundaryCondition, (INonlinearFlux)equationComponent);
            }
            else if (equationComponent is SIPGFlux)
            {
                result = new BoundaryConditionSourceFromSIPGFlux(
                    control, speciesMap, boundaryCondition, (SIPGFlux)equationComponent);
            }
            else if (equationComponent is INonlinear2ndOrderForm)
            {
                result = new BoundaryConditionSourceFromINonlinear2ndOrderForm(
                    control, speciesMap, boundaryCondition, (INonlinear2ndOrderForm)equationComponent);
            }
            else
            {
                throw new NotImplementedException("To do");
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// %
        /// </summary>
        protected FormDifferentiatorCommon(IEquationComponent vf, TermActivationFlags __Terms, int SpatialDimension)
        {
            m_OrgForm          = vf;
            m_eps              = Math.Sqrt(BLAS.MachineEps);
            m_SpatialDimension = SpatialDimension;

            Terms = __Terms;
            if ((Terms & (TermActivationFlags.GradUxV | TermActivationFlags.UxV)) != 0)
            {
                Terms |= TermActivationFlags.V;
            }
            if ((Terms & (TermActivationFlags.GradUxGradV | TermActivationFlags.UxGradV)) != 0)
            {
                Terms |= TermActivationFlags.GradV;
            }

            // Parameters for form derivative
            // ==============================

            ParamUreq     = (Terms & (TermActivationFlags.UxGradV | TermActivationFlags.UxV)) != 0;
            ParamGradUreq = (Terms & (TermActivationFlags.GradUxGradV | TermActivationFlags.GradUxV)) != 0;

            m_ParameterOrdering = new string[0];

            // original parameters
            OffsetOrgParams = m_ParameterOrdering.Length;
            if (vf.ParameterOrdering != null && vf.ParameterOrdering.Count > 0)
            {
                m_ParameterOrdering = m_ParameterOrdering.Cat(vf.ParameterOrdering);
                NoOfOrgParams       = vf.ParameterOrdering.Count;
            }
            else
            {
                NoOfOrgParams = 0;
            }

            // U in linearization point
            OffsetUparams = m_ParameterOrdering.Length;
            if (ParamUreq && vf.ArgumentOrdering != null && vf.ArgumentOrdering.Count > 0)
            {
                m_ParameterOrdering = m_ParameterOrdering.Cat(vf.ArgumentOrdering.Select(fn => fn + "_lin"));
            }

            // derivatives in linearization point
            OffsetGradUparams = m_ParameterOrdering.Length;
            if (ParamGradUreq && vf.ArgumentOrdering != null && vf.ArgumentOrdering.Count > 0)
            {
                foreach (string arg in vf.ArgumentOrdering)
                {
                    m_ParameterOrdering = m_ParameterOrdering.Cat(SpatialDimension.ForLoop(d => arg + "_lin_d[" + d + "]"));
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// creates the spatial operator that consists only of component <paramref name="c"/>
        /// </summary>
        public static SpatialOperator Operator(this IEquationComponent c, Func <int[], int[], int[], int> quadOrderFunc)
        {
            string[] Codomain = new string[] { "v1" };
            string[] Domain   = c.ArgumentOrdering.ToArray();
            string[] Param    = (c.ParameterOrdering != null) ? c.ParameterOrdering.ToArray() : new string[0];

            SpatialOperator ret = new SpatialOperator(Domain, Param, Codomain, quadOrderFunc);

            ret.EquationComponents[Codomain[0]].Add(c);
            ret.Commit();

            return(ret);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// creates the spatial operator that consists only of component <paramref name="c"/>
        /// </summary>
        public static XSpatialOperatorMk2 XOperator(this IEquationComponent c, IEnumerable <string> species, Func <int[], int[], int[], int> quadOrderFunc)
        {
            string[] Codomain = new string[] { "v1" };
            string[] Domain   = c.ArgumentOrdering.ToArray();
            string[] Param    = (c.ParameterOrdering != null) ? c.ParameterOrdering.ToArray() : new string[0];

            XSpatialOperatorMk2 ret = new XSpatialOperatorMk2(Domain, Param, Codomain, quadOrderFunc, species);

            ret.EquationComponents[Codomain[0]].Add(c);
            ret.Commit();

            return(ret);
        }
Ejemplo n.º 5
0
        private bool Compfilter(IEquationComponent c)
        {
            ILevelSetComponent b = (ILevelSetComponent)c;

            if (this.m_LevSetIdx != b.LevelSetIndex)
            {
                // component is not relevant for this level-set
                return(false);
            }

            if (!(this.m_SpeciesPair.Contains(b.PositiveSpecies) && this.m_SpeciesPair.Contains(b.NegativeSpecies)))
            {
                // component is not relevant for this level-set
                return(false);
            }

            // filter passed
            return(true);
        }
Ejemplo n.º 6
0
        private bool Compfilter(IEquationComponent c)
        {
            ILevelSetForm b = (ILevelSetForm)c;

            if (this.m_LevSetIdx != b.LevelSetIndex)
            {
                // component is not relevant for this level-set
                return(false);
            }

            if (!(this.SpeciesA == b.NegativeSpecies && this.SpeciesB == b.PositiveSpecies))
            {
                // component is not relevant for this level-set
                return(false);
            }

            // filter passed
            return(true);
        }
        /// <summary>
        /// creates the spatial operator that consists only of component <paramref name="c"/>
        /// </summary>
        public static SpatialOperator Operator(this IEquationComponent c, Func <int[], int[], int[], int> quadOrderFunc, Func <IGridData, EdgeQuadratureScheme> edgeSchemeProvider = null, Func <IGridData, CellQuadratureScheme> cellSchemeProvider = null)
        {
            string[] Codomain = new string[] { "v1" };
            string[] Domain   = c.ArgumentOrdering.ToArray();
            string[] Param    = (c.ParameterOrdering != null) ? c.ParameterOrdering.ToArray() : new string[0];

            SpatialOperator ret = new SpatialOperator(Domain, Param, Codomain, quadOrderFunc);

            if (edgeSchemeProvider != null)
            {
                ret.EdgeQuadraturSchemeProvider = edgeSchemeProvider;
            }
            if (cellSchemeProvider != null)
            {
                ret.VolumeQuadraturSchemeProvider = cellSchemeProvider;
            }

            ret.EquationComponents[Codomain[0]].Add(c);
            ret.Commit();

            return(ret);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="DiffOp"></param>
        /// <param name="CoDomVarName">
        /// the name of the variable in the codomain (<see cref="SpatialOperator.CodomainVar"/>-member
        /// of <paramref name="DiffOp"/>, for which this object should be defined;
        /// </param>
        /// <param name="_fieldList">
        /// list of domain variable names
        /// </param>
        /// <param name="_fieldList2">
        /// optional (i.e. can be null)
        /// list of parameter variable names;
        /// will be concatenated with <paramref name="_fieldList"/>
        /// </param>
        /// <param name="F">optional filter, can be null.</param>
        /// <param name="vectorizer">
        /// Function for the vectorization of the evaluation of <paramref name="F"/>
        /// </param>
        internal EquationComponentArgMapping(SpatialOperator DiffOp, string CoDomVarName,
                                             IList <string> _fieldList, IList <string> _fieldList2, Func <T, bool> F, Func <IEquationComponent, IEquationComponent> vectorizer)
        {
            m_CoDomVarName = CoDomVarName;
            //m_DomainFields = DomainMapping.Fields;


            // =================
            // concat field list
            // =================
            IList <string> fieldList;

            if (_fieldList2 != null)
            {
                fieldList = Enumerable.Concat(_fieldList, _fieldList2).ToList();
            }
            else
            {
                fieldList = _fieldList;
            }

            // =========================================
            // collect all equation components of type T
            // =========================================

            ICollection <IEquationComponent> eqCompS = DiffOp.EquationComponents[CoDomVarName];

            List <T> AllComponentsofMyType = new List <T>();

            foreach (IEquationComponent eqComp in eqCompS)
            {
                if (eqComp is T)
                {
                    T _eqComp = (T)eqComp;

                    if (F == null || F(_eqComp))
                    {
                        AllComponentsofMyType.Add(_eqComp);
                    }
                }
                else if (vectorizer != null)
                {
                    IEquationComponent VeqComp = vectorizer(eqComp);

                    if (VeqComp != null && VeqComp is T)
                    {
                        T _VeqComp = (T)VeqComp;

                        if (F == null || F(_VeqComp))
                        {
                            AllComponentsofMyType.Add(_VeqComp);
                        }
                    }
                }
            }

            m_AllComponentsOfMyType = AllComponentsofMyType.ToArray();

            // ======================
            // build argument mapping
            // ======================

            int argMapMaxCount = 0;

            foreach (var w in m_AllComponentsOfMyType)
            {
                int c = w.ArgumentOrdering.Count;
                if (w.ParameterOrdering != null)
                {
                    c += w.ParameterOrdering.Count;
                }
                argMapMaxCount = Math.Max(argMapMaxCount, c);
            }
            AllToSub       = new int[m_AllComponentsOfMyType.Length, argMapMaxCount];
            NoOfArguments  = new int[m_AllComponentsOfMyType.Length];
            NoOfParameters = new int[m_AllComponentsOfMyType.Length];
            //ArrayTools.SetAll(AllToSub, int.MinValue);
            AllToSub.SetAll(int.MinValue);

            //IList<string> fieldList = DiffOp.DomainVar;
            for (int i = 0; i < AllToSub.GetLength(0); i++)
            {
                // arguments...
                IList <string> argMap = m_AllComponentsOfMyType[i].ArgumentOrdering;
                NoOfArguments[i] = argMap.Count;
                for (int j = 0; j < NoOfArguments[i]; j++)
                {
                    int ifound = fieldList.IndexOf(argMap[j]);
                    AllToSub[i, j] = ifound;
                    Debug.Assert(AllToSub[i, j] >= 0);
                }

                // parameters...
                IList <string> paramMap = m_AllComponentsOfMyType[i].ParameterOrdering;
                if (paramMap != null)
                {
                    NoOfParameters[i] = paramMap.Count;

                    for (int j = 0; j < NoOfParameters[i]; j++)
                    {
                        AllToSub[i, j + NoOfArguments[i]] = fieldList.IndexOf(paramMap[j]);
                        Debug.Assert(AllToSub[i, j + NoOfArguments[i]] >= 0);
                    }
                }
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// creates the spatial operator that consists only of component <paramref name="c"/>
 /// </summary>
 public static SpatialOperator Operator(this IEquationComponent c, int DegreeOfNonlinearity = 1)
 {
     return(Operator(c, QuadOrderFunc.NonLinear(DegreeOfNonlinearity)));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// creates the spatial operator that consists only of component <paramref name="c"/>
 /// </summary>
 public static XSpatialOperatorMk2 XOperator(this IEquationComponent c, IEnumerable <string> species, int DegreeOfNonlinearity = 1)
 {
     return(XOperator(c, species, QuadOrderFunc.NonLinear(DegreeOfNonlinearity)));
 }
 /// <summary>
 /// creates the spatial operator that consists only of component <paramref name="c"/>
 /// </summary>
 public static SpatialOperator Operator(this IEquationComponent c, int DegreeOfNonlinearity = 1, Func <IGridData, EdgeQuadratureScheme> edgeSchemeProvider = null, Func <IGridData, CellQuadratureScheme> cellSchemeProvider = null)
 {
     return(Operator(c, QuadOrderFunc.NonLinear(DegreeOfNonlinearity), edgeSchemeProvider, cellSchemeProvider));
 }