Exemplo n.º 1
0
        /*
         * /// <summary>
         * /// base matrix assembly
         * /// </summary>
         * /// <typeparam name="T"></typeparam>
         * /// <param name="OpMatrix"></param>
         * /// <param name="OpAffine"></param>
         * /// <param name="RowMapping"></param>
         * /// <param name="ColMapping"></param>
         * /// <param name="CurrentState"></param>
         * /// <param name="ParamsMap"></param>
         * /// <param name="AgglomeratedCellLengthScales"></param>
         * /// <param name="time"></param>
         * public void AssembleMatrix<T>(BlockMsrMatrix OpMatrix, double[] OpAffine,
         *  UnsetteledCoordinateMapping RowMapping, UnsetteledCoordinateMapping ColMapping,
         *  IEnumerable<T> CurrentState, IList<DGField> ParamsMap, Dictionary<SpeciesId, MultidimensionalArray> AgglomeratedCellLengthScales,
         *  double time) where T : DGField {
         *
         *  // checks
         *  if(ColMapping.BasisS.Count != m_XOp.DomainVar.Count)
         *      throw new ArgumentException();
         *  if(RowMapping.BasisS.Count != m_XOp.CodomainVar.Count)
         *      throw new ArgumentException();
         *  if(OpMatrix == null && CurrentState == null)
         *      throw new ArgumentException();
         *
         *  SpeciesId[] SpcToCompute = AgglomeratedCellLengthScales.Keys.ToArray();
         *  if(!m_XOp.Species.SetEquals(SpcToCompute.Select(spcId => LsTrk.GetSpeciesName(spcId)))) {
         *      throw new ArgumentException("mismatch between species of operator and length scales.");
         *  }
         *
         *  if(OpMatrix != null) {
         *
         *      XSpatialOperatorMk2.XEvaluatorLinear mtxBuilder = m_XOp.GetMatrixBuilder(LsTrk, ColMapping, ParamsMap, RowMapping);
         *
         *      foreach(var kv in AgglomeratedCellLengthScales) {
         *          mtxBuilder.SpeciesOperatorCoefficients[kv.Key].CellLengthScales = kv.Value;
         *      }
         *
         *      mtxBuilder.time = time;
         *
         *      mtxBuilder.ComputeMatrix(OpMatrix, OpAffine);
         *
         *  } else {
         *      XSpatialOperatorMk2.XEvaluatorNonlin eval = m_XOp.GetEvaluatorEx(this.LsTrk,
         *          CurrentState.ToArray(), ParamsMap, RowMapping);
         *
         *      foreach(var kv in AgglomeratedCellLengthScales) {
         *          eval.SpeciesOperatorCoefficients[kv.Key].CellLengthScales = kv.Value;
         *      }
         *
         *      eval.time = time;
         *
         *      eval.Evaluate(1.0, 1.0, OpAffine);
         *
         *  }
         * }
         */

        public void AssembleMatrix <T>(BlockMsrMatrix OpMatrix, double[] OpAffine,
                                       UnsetteledCoordinateMapping RowMapping, UnsetteledCoordinateMapping ColMapping,
                                       IEnumerable <T> CurrentState, Dictionary <SpeciesId, MultidimensionalArray> AgglomeratedCellLengthScales,
                                       double time) where T : DGField
        {
            AssembleMatrix(OpMatrix, OpAffine, RowMapping, ColMapping, CurrentState, AgglomeratedCellLengthScales, time);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor for XDG solvers
        /// </summary>
        public OpAnalysisBase(LevelSetTracker LsTrk, BlockMsrMatrix Mtx, double[] RHS, UnsetteledCoordinateMapping Mapping, MultiphaseCellAgglomerator CurrentAgglomeration, BlockMsrMatrix _mass, IEnumerable <MultigridOperator.ChangeOfBasisConfig[]> OpConfig, ISpatialOperator abstractOperator)
        {
            int RHSlen = Mapping.TotalLength;

            m_map    = Mapping;                              // mapping
            VarGroup = Mapping.BasisS.Count.ForLoop(i => i); //default: all dependent variables are included in operator matrix

            m_LsTrk = LsTrk;

            m_OpMtx  = Mtx.CloneAs();
            localRHS = RHS.CloneAs();

            // create the Dummy XDG aggregation basis
            var baseGrid = Mapping.GridDat;
            var mgSeq    = Foundation.Grid.Aggregation.CoarseningAlgorithms.CreateSequence(baseGrid, 1);

            AggregationGridBasis[][] XAggB = AggregationGridBasis.CreateSequence(mgSeq, Mapping.BasisS);

            //
            XAggB.UpdateXdgAggregationBasis(CurrentAgglomeration);

            // create multigrid operator
            m_MultigridOp = new MultigridOperator(XAggB, Mapping,
                                                  m_OpMtx,
                                                  _mass,
                                                  OpConfig,
                                                  abstractOperator.DomainVar.Select(varName => abstractOperator.FreeMeanValue[varName]).ToArray());
        }
Exemplo n.º 3
0
 private static void CheckMatrix(BlockMsrMatrix M, UnsetteledCoordinateMapping RowMapping, UnsetteledCoordinateMapping ColMapping, int J)
 {
     if (M._RowPartitioning.LocalNoOfBlocks != J)
     {
         throw new ArgumentException("Number of column blocks must be equal to number of cells.");
     }
     if (M._ColPartitioning.LocalNoOfBlocks != J)
     {
         throw new ArgumentException("Number of column blocks must be equal to number of cells.");
     }
     if (!M._RowPartitioning.EqualsPartition(RowMapping))
     {
         throw new ArgumentException("Mapping must match partitioning.");
     }
     if (!M._ColPartitioning.EqualsPartition(ColMapping))
     {
         throw new ArgumentException("Mapping must match partitioning.");
     }
     if (!M._RowPartitioning.AllBlockSizesEqual)
     {
         throw new NotSupportedException("Only mappings with constant frame blocks are supported.");
     }
     if (!M._ColPartitioning.AllBlockSizesEqual)
     {
         throw new NotSupportedException("Only mappings with constant frame blocks are supported.");
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Reload of some operator after before grid-redistribution.
        /// </summary>
        /// <param name="Mtx_new">
        /// Output, matrix which should be restored.
        /// </param>
        /// <param name="Reference">
        /// Unique string reference under which data has been stored before grid-redistribution.
        /// </param>
        /// <param name="RowMapping">
        /// Coordinate mapping to correlate the matrix rows with cells of the computational grid.
        /// </param>
        /// <param name="ColMapping">
        ///  Coordinate mapping to correlate the matrix columns with cells of the computational grid.
        /// </param>
        public void RestoreMatrix(BlockMsrMatrix Mtx_new, string Reference, UnsetteledCoordinateMapping RowMapping, UnsetteledCoordinateMapping ColMapping)
        {
            int J = m_NewGrid.iLogicalCells.NoOfLocalUpdatedCells;

            CheckMatrix(Mtx_new, RowMapping, ColMapping, J);

            BlockMsrMatrix Mtx_old = m_Matrices[Reference].Item3;

            int[] RowHash = GetDGBasisHash(RowMapping.BasisS);
            int[] ColHash = GetDGBasisHash(ColMapping.BasisS);

            if (!ArrayTools.AreEqual(RowHash, m_Matrices[Reference].Item1))
            {
                throw new ApplicationException();
            }
            if (!ArrayTools.AreEqual(ColHash, m_Matrices[Reference].Item2))
            {
                throw new ApplicationException();
            }

            BlockMsrMatrix P_Row = GetRowPermutationMatrix(Mtx_new, Mtx_old, RowHash);
            BlockMsrMatrix P_Col = GetColPermutationMatrix(Mtx_new, Mtx_old, ColHash);

            Debug.Assert(Mtx_new._RowPartitioning.LocalNoOfBlocks == m_newJ);
            Debug.Assert(Mtx_new._ColPartitioning.LocalNoOfBlocks == m_newJ);
            Debug.Assert(Mtx_old._RowPartitioning.LocalNoOfBlocks == m_oldJ);
            Debug.Assert(Mtx_old._ColPartitioning.LocalNoOfBlocks == m_oldJ);

            Debug.Assert(P_Row._RowPartitioning.LocalNoOfBlocks == m_newJ);
            Debug.Assert(P_Row._ColPartitioning.LocalNoOfBlocks == m_oldJ);
            Debug.Assert(P_Col._RowPartitioning.LocalNoOfBlocks == m_oldJ);
            Debug.Assert(P_Col._ColPartitioning.LocalNoOfBlocks == m_newJ);

            BlockMsrMatrix.Multiply(Mtx_new, BlockMsrMatrix.Multiply(P_Row, Mtx_old), P_Col);
        }
Exemplo n.º 5
0
            public MiniMapping(UnsetteledCoordinateMapping Map, SpeciesId spId, LevelSetTracker.LevelSetRegions r)
            {
                m_Map = Map;
                m_spId = spId;
                m_LsRegion = r;

                Basis[] BS = Map.BasisS.ToArray();
                NS = new int[BS.Length];
                VarIsXdg = new bool[BS.Length];
                NoOfVars = BS.Length;

                for (int iVar = 0; iVar < BS.Length; iVar++) {
                    XDGBasis xBasis = BS[iVar] as XDGBasis;
                    if (xBasis != null) {
                        NS[iVar] = xBasis.NonX_Basis.Length;
                        //m_LsTrk = xBasis.Tracker;
                        VarIsXdg[iVar] = true;
                    } else {
                        NS[iVar] = BS[iVar].Length;
                        VarIsXdg[iVar] = false;
                    }

                    MaxDeg = Math.Max(MaxDeg, BS[iVar].Degree);
                }
            }
 /// <summary>
 /// Ctor for low Mach number flows.
 /// </summary>
 /// <param name="VelocityMapping"></param>
 /// <param name="Velocity0"></param>
 /// <param name="Velocity0Mean"></param>
 /// <param name="Phi0"></param>
 /// <param name="Phi0Mean"></param>
 /// <param name="SolverConf"></param>
 /// <param name="SpatialComponent">
 /// Spatial component index of velocity (i.e. u_i) for affine part of operator.
 /// The operator matrix is the same for all spatial directions.
 /// Therefore, if SpatialComponent!=0, only the affine part of the operator is calculated.
 /// </param>
 public MomentumConvectionVariableDensityOperator(UnsetteledCoordinateMapping VelocityMapping,
                                                  VectorField <SinglePhaseField> Velocity0, VectorField <SinglePhaseField> Velocity0Mean, SinglePhaseField Phi0, SinglePhaseField Phi0Mean, SolverConfiguration SolverConf, int SpatialComponent)
     : base(VelocityMapping, VelocityMapping, ArrayTools.Cat <SinglePhaseField>(Velocity0.ToArray(), Velocity0Mean.ToArray(), Phi0, Phi0Mean),
            SolverConf, false, SpatialComponent,
            OnlyAffine: (SpatialComponent != 0), OnlyBoundaryEdges: true, MaxUsePerIterMatrix: SolverConf.SpatialDimension)
 {
 }
Exemplo n.º 7
0
        public ExtVelSolver_PDEbased(Basis ExtPropertyBasis)
        {
            var map = new UnsetteledCoordinateMapping(ExtPropertyBasis);

            m_ExtvelMatrix = new MsrMatrix(map, map);
            m_ExtvelAffine = new double[m_ExtvelMatrix.RowPartitioning.LocalLength];
        }
Exemplo n.º 8
0
        /// <summary>
        /// computes a local unique coordinate index ("local" means local on this processor);
        /// this index is unique over all fields (in this mapping), over all cells, over all basis functions,
        /// but it's only locally (on this processor) valid.
        /// A local index in the update range (smaller than <see cref="NUpdate"/>) can be converted into
        /// a global index by adding <see cref="Partitioning.i0"/>.
        /// </summary>
        /// <param name="find">
        /// the field or basis index (see <see cref="BasisS"/>);
        /// </param>
        /// <param name="j">local cell index</param>
        /// <param name="n">DG mode index</param>
        /// <param name="lsTrk"></param>
        /// <param name="map"></param>
        /// <param name="spcIdx">species index</param>
        public static int LocalUniqueCoordinateIndex(this UnsetteledCoordinateMapping map, LevelSetTracker lsTrk, int find, int j, int spcIdx, int n)
        {
            //;

            int NoOfSpc = lsTrk.Regions.GetNoOfSpecies(j, out var rrc);

            if (spcIdx < 0 || spcIdx >= NoOfSpc)
            {
                throw new IndexOutOfRangeException($"Species index out of range (species index is {spcIdx}, Number of species is {NoOfSpc}, cell {j})");
            }

            Basis    b  = map.BasisS[find];
            XDGBasis xb = b as XDGBasis;

            if (xb == null)
            {
                return(map.LocalUniqueCoordinateIndex(find, j, n));
            }
            else
            {
                int i0 = map.LocalUniqueCoordinateIndex(find, j, 0);
                int Ns = xb.NonX_Basis.GetLength(j);
                if (n < 0 || n >= Ns)
                {
                    throw new IndexOutOfRangeException($"DG mode index (within species) of range (DG mode index is {n}, but non-XDG basis length is {Ns}, cell {j})");
                }

                return(i0 + Ns * spcIdx + n);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="SolverConf"></param>
        /// <param name="WorkingSet"></param>
        public SIMPLEStepIncompressible(SolverConfiguration SolverConf, VariableSet WorkingSet)
        {
            m_SolverConf = SolverConf;
            m_WorkingSet = WorkingSet;

            // Construct BDF scheme for unsteady solver
            if (SolverConf.Control.Algorithm == SolutionAlgorithms.Unsteady_SIMPLE)
            {
                m_BDF = new BDFScheme();
            }

            // Construct all SIMPLEOperators, which are needed for incompressible flows
            UnsetteledCoordinateMapping VelocityMapping = new UnsetteledCoordinateMapping(WorkingSet.VelBasis);
            UnsetteledCoordinateMapping PressureMapping = new UnsetteledCoordinateMapping(WorkingSet.PressureBasis);

            m_IncompressibleOperators = new OperatorFactoryFlowFieldIncompressible(VelocityMapping,
                                                                                   PressureMapping,
                                                                                   SolverConf,
                                                                                   WorkingSet.Velocity.Current,
                                                                                   WorkingSet.VelocityMean);

            // Construct matrix assemblies
            m_IncompressibleMatrixAssemblies = new MatrixFactoryIncompressibleFlows(
                SolverConf, m_IncompressibleOperators, PressureMapping, WorkingSet.Pressure, m_BDF);
        }
Exemplo n.º 10
0
        public static void Init()
        {
            bool dummy;

            ilPSP.Environment.Bootstrap(
                new string[0],
                BoSSS.Solution.Application.GetBoSSSInstallDir(),
                out dummy);

            //GridCommons grd = Grid2D.Cartesian2DGrid(RandomSpacing(), RandomSpacing());
            //grid = new GridData(Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-7, 7, 8), GenericBlas.Linspace(-1, 1, 2)));
            //grid = new GridData(Grid2D.Cartesian2DGrid(new double[] { -6, -4, -2, 2, 4, 6 }, GenericBlas.Linspace(-1, 1, 2)));
            grid  = new GridData(Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1.5, 1.5, 17), GenericBlas.Linspace(-1.5, 1.5, 17)));
            MgSeq = CoarseningAlgorithms.CreateSequence(grid);

            for (int p = 0; p <= 3; p++)   // loop over polynomial degrees...
            {
                var uMapping = new UnsetteledCoordinateMapping(new Basis(grid, p));

                var MgMapSeq = new MultigridMapping[MgSeq.Length];
                var BasisSeq = AggregationGridBasis.CreateSequence(MgSeq, uMapping.BasisS);
                for (int iLevel = 0; iLevel < MgSeq.Length; iLevel++)
                {
                    MgMapSeq[iLevel] = new MultigridMapping(uMapping, BasisSeq[iLevel], new int[] { p });
                }
                MultigrigMap.Add(p, MgMapSeq);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="TemperatureMapping"></param>
 /// <param name="Velocity0"></param>
 /// <param name="Velocity0Mean"></param>
 /// <param name="Temperature0"></param>
 /// <param name="Temperature0Mean"></param>
 /// <param name="SolverConf"></param>
 public OperatorFactoryTemperature(UnsetteledCoordinateMapping TemperatureMapping, UnsetteledCoordinateMapping PressureMapping,
                                   VectorField <SinglePhaseField> Velocity0, VectorField <SinglePhaseField> Velocity0Mean, SinglePhaseField Temperature0, SinglePhaseField Temperature0Mean,
                                   SolverConfiguration SolverConf)
 {
     this.TemperatureConvection = new TemperatureConvectionOperator(TemperatureMapping, Velocity0, Velocity0Mean, Temperature0, Temperature0Mean, SolverConf);
     this.HeatConduction        = new HeatConductionOperator(TemperatureMapping, Temperature0, SolverConf);
 }
Exemplo n.º 12
0
        public void Laplacian(OpenFOAMGrid grid, int DgDegree)
        {
            // grid, etc
            // =========

            GridData grd = grid.GridData;

            var b   = new Basis(grd, DgDegree);
            var map = new UnsetteledCoordinateMapping(b);

            var L  = new Laplace(1.3, grd.Cells.cj);
            var op = new SpatialOperator(1, 0, 1, QuadOrderFunc.Linear(), "T", "c1");

            op.EquationComponents["c1"].Add(L);
            op.Commit();

            // evaluate operator
            // =================

            var Mtx = new BlockMsrMatrix(map, map);

            double[] B = new double[map.LocalLength];

            var eval = op.GetMatrixBuilder(map, null, map);

            eval.ComputeMatrix(Mtx, B);

            // return data
            // ===========

            throw new NotImplementedException("todo");
        }
        /// <summary>
        /// Legacy interface, preserved as static function.
        /// </summary>
        public static void ComputeMatrixEx <M, V>(
            this XSpatialOperator xOp,
            LevelSetTracker lsTrk,
            UnsetteledCoordinateMapping DomainMap, IList <DGField> Parameters, UnsetteledCoordinateMapping CodomainMap,
            M Matrix, V AffineOffset, bool OnlyAffine, double time, bool ParameterMPIExchange,
            IDictionary <SpeciesId, MultidimensionalArray> CellLengthScales,
            IDictionary <SpeciesId, MultidimensionalArray> InterfaceLengthScales, MultidimensionalArray SlipLengths,
            SubGrid SubGrid, params SpeciesId[] whichSpc)
            where M : IMutableMatrixEx
            where V : IList <double> //
        {
            var SpeciesDictionary = new Dictionary <SpeciesId, XSpatialOperator.QrSchemPair>();

            foreach (var sp in whichSpc)
            {
                SpeciesDictionary.Add(sp, new XSpatialOperator.QrSchemPair());
            }

            ComputeMatrixEx <M, V>(
                xOp,
                lsTrk,
                DomainMap, Parameters, CodomainMap,
                Matrix, AffineOffset, OnlyAffine, time,
                ParameterMPIExchange, SpeciesDictionary, CellLengthScales,
                InterfaceLengthScales, SlipLengths,
                //agg, out mass,
                SubGrid);
        }
Exemplo n.º 14
0
        public static void Init()
        {
            //GridCommons grd = Grid2D.Cartesian2DGrid(RandomSpacing(), RandomSpacing());
            //grid = new GridData(Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-7, 7, 8), GenericBlas.Linspace(-1, 1, 2)));
            //grid = new GridData(Grid2D.Cartesian2DGrid(new double[] { -6, -4, -2, 2, 4, 6 }, GenericBlas.Linspace(-1, 1, 2)));
            //if (curved)
            //{
            //    grid = Grid2D.CurvedSquareGrid(GenericBlas.Linspace(1, 2, 5), GenericBlas.Linspace(0, 1, 17), CellType.Square_9, true).GridData;
            //}
            //else
            //{
            //    grid = (Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1.5, 1.5, 17), GenericBlas.Linspace(-1.5, 1.5, 17))).GridData;
            //}
            grid  = (Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1.5, 1.5, 17), GenericBlas.Linspace(-1.5, 1.5, 17))).GridData;
            MgSeq = CoarseningAlgorithms.CreateSequence(grid);

            for (int p = 0; p <= 3; p++)   // loop over polynomial degrees...
            {
                var uMapping = new UnsetteledCoordinateMapping(new Basis(grid, p));

                var MgMapSeq = new MultigridMapping[MgSeq.Length];
                var BasisSeq = AggregationGridBasis.CreateSequence(MgSeq, uMapping.BasisS);
                for (int iLevel = 0; iLevel < MgSeq.Length; iLevel++)
                {
                    MgMapSeq[iLevel] = new MultigridMapping(uMapping, BasisSeq[iLevel], new int[] { p });
                }
                MultigrigMap.Add(p, MgMapSeq);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="SolverConf"></param>
        /// <param name="WorkingSet"></param>
        /// <param name="WorkingSetMatrices"></param>
        public BaseSIMPLEStepVariableDensity(SolverConfiguration SolverConf, VariableSet WorkingSet, VariableMatrices WorkingSetMatrices)
        {
            this.SolverConf         = SolverConf;
            this.WorkingSet         = WorkingSet;
            this.WorkingSetMatrices = WorkingSetMatrices;

            // Construct BDF scheme for unsteady solver
            if (SolverConf.Control.Algorithm == SolutionAlgorithms.Unsteady_SIMPLE)
            {
                BDF = new BDFScheme();
            }

            // Construct SIMPLEOperators
            UnsetteledCoordinateMapping VelocityMapping = new UnsetteledCoordinateMapping(WorkingSet.VelBasis);
            UnsetteledCoordinateMapping PressureMapping = new UnsetteledCoordinateMapping(WorkingSet.PressureBasis);

            Basis[] VelBasisS = new Basis[SolverConf.SpatialDimension];
            for (int d = 0; d < SolverConf.SpatialDimension; d++)
            {
                VelBasisS[d] = WorkingSet.VelBasis;
            }
            UnsetteledCoordinateMapping VelocityVectorMapping = new UnsetteledCoordinateMapping(VelBasisS);

            OperatorsFlowField = GetOperatorsFlowField(VelocityMapping, VelocityVectorMapping, PressureMapping);

            // Construct matrix assemblies
            MatrixAssembliesFlowField = new MatrixFactoryVariableDensityFlowField(
                SolverConf,
                OperatorsFlowField,
                WorkingSetMatrices.Rho.Matrix,
                BDF,
                VelocityMapping,
                VelocityVectorMapping);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Replaces all <see cref="XDGBasis"/>-objects in the mapping <paramref name="full"/>
        /// with their non-cut counterparts (<see cref="XDGBasis.NonX_Basis"/>.
        /// </summary>
        static UnsetteledCoordinateMapping CreateMap(UnsetteledCoordinateMapping full)
        {
            var basisS = from b in full.BasisS
                         select((b is XDGBasis)?((XDGBasis)b).NonX_Basis : b);

            return(new UnsetteledCoordinateMapping(basisS.ToArray <Basis>()));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Recursive constructor, i.e. constructs operators on all multigrid levels which are provided by <paramref name="basisSeq"/>.
        /// </summary>
        /// <param name="basisSeq"></param>
        /// <param name="_ProblemMapping">
        /// DG coordinate mapping on the original grid, see <see cref="BaseGridProblemMapping"/>.
        /// </param>
        /// <param name="OperatorMatrix"></param>
        /// <param name="MassMatrix">
        /// Mass matrix on the original grid. If null, the identity matrix is assumed. It is only required if the
        /// </param>
        /// <param name="cobc">
        /// Configuration of the cell-wise, explicit block-preconditioning for each multigrid level.
        /// (Remark: this kind of preconditioning is mathematically equivalent to a change of the DG resp. XDG basis.)
        /// </param>
        public MultigridOperator(IEnumerable <AggregationGridBasis[]> basisSeq,
                                 UnsetteledCoordinateMapping _ProblemMapping, BlockMsrMatrix OperatorMatrix, BlockMsrMatrix MassMatrix,
                                 IEnumerable <ChangeOfBasisConfig[]> cobc)
            : this(null, basisSeq, _ProblemMapping, cobc) //
        {
            if (!OperatorMatrix.RowPartitioning.EqualsPartition(_ProblemMapping))
            {
                throw new ArgumentException("Row partitioning mismatch.");
            }
            if (!OperatorMatrix.ColPartition.EqualsPartition(_ProblemMapping))
            {
                throw new ArgumentException("Column partitioning mismatch.");
            }


            if (MassMatrix != null)
            {
                if (!MassMatrix.RowPartitioning.Equals(_ProblemMapping))
                {
                    throw new ArgumentException("Row partitioning mismatch.");
                }
                if (!MassMatrix.ColPartition.Equals(_ProblemMapping))
                {
                    throw new ArgumentException("Column partitioning mismatch.");
                }
            }

            if (this.LevelIndex == 0)
            {
                if (this.IndexIntoProblemMapping_Local == null)
                {
                    this.m_RawOperatorMatrix = OperatorMatrix;

                    if (MassMatrix != null)
                    {
                        this.m_RawMassMatrix = MassMatrix;  //is BlockMsrMatrix) ? ((BlockMsrMatrix)MassMatrix) : MassMatrix.ToMsrMatrix();
                    }
                    else
                    {
                        this.m_RawMassMatrix = null;
                    }
                }
                else
                {
                    this.m_RawOperatorMatrix = new BlockMsrMatrix(this.Mapping, this.Mapping);
                    OperatorMatrix.WriteSubMatrixTo(this.m_RawOperatorMatrix, this.IndexIntoProblemMapping_Global, default(int[]), this.IndexIntoProblemMapping_Global, default(int[]));

                    if (MassMatrix != null)
                    {
                        this.m_RawMassMatrix = new BlockMsrMatrix(this.Mapping, this.Mapping);
                        BlockMsrMatrix MMR = MassMatrix;
                        MMR.WriteSubMatrixTo(this.m_RawMassMatrix, this.IndexIntoProblemMapping_Global, default(int[]), this.IndexIntoProblemMapping_Global, default(int[]));
                    }
                    else
                    {
                        this.m_RawMassMatrix = null;
                    }
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="RowMapping"></param>
        /// <param name="ColMapping"></param>
        /// <param name="ParameterFields">
        /// Paramter fields for SpatialOperator - can be null.
        /// </param>
        /// <param name="SolverConf">
        /// Solver configuration.
        /// </param>
        /// <param name="IsConstant">
        /// If true, the operator is constant over time and SIMPLE iterations.
        /// That is the case for most operatores.
        /// Only operators like e.g. the <see cref="LinearizedConvection"/> are not constant.
        /// </param>
        /// <param name="ArgumentIndex">
        /// Argument index of dependent variable, e.g. spatial component u_i, for SpatialOperator
        /// - this parameter is optional.
        /// </param>
        /// <param name="SpatialDirection">
        /// Spatial direction index of independent variable, e.g. diff(p, x_i), for SpatialOperator
        /// - this parameter is optional.
        /// </param>
        /// <param name="OnlyAffine">
        /// If true, only the affine part of the operator is calculated.
        /// </param>
        /// <param name="OnlyBoundaryEdges">
        /// If true, the integration for calculating the affine part is carried out
        /// only on the boundary edges. Can be set to true for most operators.
        /// </param>
        /// <param name="MaxUsePerIterMatrix">
        /// For operators which are not constant the maximum number
        /// the matrix can be called via <see cref="OperatorMatrix"/> in one SIMPLE iteration.
        /// </param>
        /// <param name="MaxUsePerIterAffine">
        /// For operators which are not constant the maximum number
        /// the affine part can be called via <see cref="OperatorAffine"/> in one SIMPLE iteration.
        /// </param>
        protected SIMPLEOperator(UnsetteledCoordinateMapping RowMapping, UnsetteledCoordinateMapping ColMapping, SinglePhaseField[] ParameterFields,
                                 SolverConfiguration SolverConf, bool IsConstant, int ArgumentIndex = -1, int SpatialDirection = -1,
                                 bool OnlyAffine = false, bool OnlyBoundaryEdges = true, int MaxUsePerIterMatrix = 1, int MaxUsePerIterAffine = 1)
        {
            m_RowMapping = RowMapping;
            m_ColMapping = ColMapping;

            m_ParameterFields = ParameterFields;

            m_IsConstant        = IsConstant;
            m_OnlyAffine        = OnlyAffine;
            m_OnlyBoundaryEdges = OnlyBoundaryEdges;

            m_MaxUsePerIterMatrix = MaxUsePerIterMatrix;
            m_MaxUsePerIterAffine = MaxUsePerIterAffine;

            // Get SpatialOperator
            m_SpatialOperator = GetSpatialOperator(SolverConf, ArgumentIndex, SpatialDirection);

            // Initialize and compute matrix of this operator
            if (!m_OnlyAffine)
            {
                m_OperatorMatrix = new MsrMatrix(m_RowMapping, m_ColMapping);
                ComputeMatrix();
            }

            // Initialize and compute affine part of this operator
            m_OperatorAffine = new double[m_RowMapping.LocalLength];
            ComputeAffine();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="SolverConf"></param>
        /// <param name="WorkingSet"></param>
        /// <param name="WorkingSetMatrices"></param>
        public SIMPLEStepLowMach(SolverConfiguration SolverConf, VariableSet WorkingSet, VariableMatrices WorkingSetMatrices)
            : base(SolverConf, WorkingSet, WorkingSetMatrices)
        {
            this.LowMachControl = SolverConf.Control as LowMachSIMPLEControl;
            if (this.LowMachControl == null)
            {
                throw new ArgumentException("Invalid config", nameof(SolverConf));
            }

            // Construct SIMPLEOperators
            UnsetteledCoordinateMapping TemperatureMapping = new UnsetteledCoordinateMapping(WorkingSet.TemperatureBasis);
            UnsetteledCoordinateMapping PressureMapping    = new UnsetteledCoordinateMapping(WorkingSet.PressureBasis);

            OperatorsTemperature = new OperatorFactoryTemperature(
                TemperatureMapping,
                PressureMapping,
                base.WorkingSet.Velocity.Current,
                base.WorkingSet.VelocityMean,
                base.WorkingSet.Temperature.Current,
                base.WorkingSet.TemperatureMean,
                SolverConf);

            // Construct matrix assemblies
            MatrixAssembliesTemperature = new MatrixFactoryTemperature(
                OperatorsTemperature, TemperatureMapping.GridDat.iLogicalCells.NoOfLocalUpdatedCells, WorkingSetMatrices.Rho.Matrix, SolverConf, base.BDF);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Accumulates an identity matrix, but only for selected variabels
        /// </summary>
        /// <param name="M">matrix to be modified (input/output)</param>
        /// <param name="factor"></param>
        /// <param name="iVar"></param>
        static public void AccEyeSp(this ISparseMatrix M, UnsetteledCoordinateMapping map, int[] iVar, double factor = 1.0)
        {
            using (new FuncTrace()) {
                if (M.RowPartitioning.LocalLength != M.ColPartition.LocalLength)
                {
                    throw new ArgumentException("supported only for quadratic matrices");
                }
                if (map.LocalLength != M.RowPartitioning.LocalLength)
                {
                    throw new ArgumentException();
                }

                int J = map.GridDat.iLogicalCells.NoOfLocalUpdatedCells;

                for (int j = 0; j < J; j++)
                {
                    foreach (int f in iVar)
                    {
                        int Np = map.BasisS[f].GetLength(j);

                        for (int n = 0; n < Np; n++)
                        {
                            int idx = map.GlobalUniqueCoordinateIndex(f, j, n);

                            M.SetDiagonalElement(idx, M.GetDiagonalElement(idx) + factor);
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
            internal InternalBla(ConstantXTemporalOperator __Owner, UnsetteledCoordinateMapping DomainVarMap, IList <DGField> ParameterMap, UnsetteledCoordinateMapping CodomainVarMap)
            {
                this.DomainMapping   = DomainVarMap;
                this.Parameters      = ParameterMap;
                this.CodomainMapping = CodomainVarMap;
                m_Owner = __Owner;

                if (DomainMapping.NoOfVariables != Owner.DomainVar.Count)
                {
                    throw new ArgumentException("Mismatch in number of domain variables.");
                }
                if (CodomainMapping.NoOfVariables != Owner.CodomainVar.Count)
                {
                    throw new ArgumentException("Mismatch in number of codomain variables.");
                }

                if (ParameterMap.Count != Owner.ParameterVar.Count)
                {
                    throw new ArgumentException("Mismatch in number of parameter variables.");
                }

                if (!DomainVarMap.EqualsPartition(CodomainVarMap))
                {
                    throw new ArgumentException("Only supported for square matrices - domain and codomain map are not compatible (e.g. different number of rows and columns.");
                }
            }
 /// <summary>
 /// Ctor for incompressible flows.
 /// </summary>
 /// <param name="VelocityMapping"></param>
 /// <param name="Velocity"></param>
 /// <param name="VelocityMean"></param>
 /// <param name="SolverConf"></param>
 /// <param name="SpatialComponent">
 /// Spatial component index of velocity (i.e. u_i) for affine part of operator.
 /// The operator matrix is the same for all spatial directions.
 /// Therefore, if SpatialComponent!=0, only the affine part of the operator is calculated.
 /// </param>
 public MomentumConvectionOperator(UnsetteledCoordinateMapping VelocityMapping,
                                   VectorField <SinglePhaseField> Velocity, VectorField <SinglePhaseField> VelocityMean,
                                   SolverConfiguration SolverConf, int SpatialComponent)
     : base(VelocityMapping, VelocityMapping, ArrayTools.Cat <SinglePhaseField>(Velocity.ToArray(), VelocityMean.ToArray()),
            SolverConf, false, SpatialComponent, OnlyAffine: (SpatialComponent != 0))
 {
 }
Exemplo n.º 23
0
        static private void CompOffsets(int i0, int L, int[] offset, UnsetteledCoordinateMapping Map)
        {
            int DELTA = offset.Length;

            Debug.Assert(DELTA == Map.BasisS.Count);

            int _o0 = Map.LocalUniqueCoordinateIndex(0, i0, 0);

            for (int delta = 0; delta < offset.Length; delta++)
            {
                offset[delta] = Map.LocalUniqueCoordinateIndex(delta, i0, 0) - _o0;
            }

#if DEBUG
            int[] Ns = new int[DELTA];
            for (int delta = 0; delta < DELTA; delta++)
            {
                Ns[delta] = Map.BasisS[delta].GetLength(i0);
            }
            for (int i = 1; i < L; i++)
            {
                for (int delta = 0; delta < DELTA; delta++)
                {
                    Debug.Assert(Ns[delta] == Map.BasisS[delta].GetLength(i0 + i));
                }
            }
#endif
        }
Exemplo n.º 24
0
        void DelComputeOperatorMatrix(BlockMsrMatrix OpMtx, double[] OpAffine, UnsetteledCoordinateMapping Mapping, DGField[] CurrentState, Dictionary <SpeciesId, MultidimensionalArray> AgglomeratedCellLengthScales, double phystime)
        {
            DGField[] Params = null;
            if (this.Control.Eq == Equation.ScalarTransport)
            {
                Params = this.V.ToArray();
            }
            else if (this.Control.Eq == Equation.HeatEq)
            {
                Params = null;
            }
            else if (this.Control.Eq == Equation.Burgers)
            {
                Params = CurrentState;
            }
            else
            {
                throw new NotImplementedException();
            }

            // compute operator
            Debug.Assert(OpMtx.InfNorm() == 0.0);
            Debug.Assert(OpAffine.L2Norm() == 0.0);
            Operator.ComputeMatrixEx(this.LsTrk,
                                     Mapping, Params, Mapping,
                                     OpMtx, OpAffine, false, phystime, true,
                                     AgglomeratedCellLengthScales, null, null,
                                     AgglomeratedCellLengthScales.Keys.ToArray());
        }
Exemplo n.º 25
0
 /// <summary>
 /// ctor
 /// </summary>
 public LocalSolver_Iterative(Basis __LevelSetBasis, GradientModule __gm)
 {
     this.GridDat         = (GridData)(__LevelSetBasis.GridDat);
     this.LevelSetMapping = new UnsetteledCoordinateMapping(__LevelSetBasis);
     this.LevelSetBasis   = __LevelSetBasis;
     this.gm = __gm;
 }
Exemplo n.º 26
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="VelocityMapping"></param>
 /// <param name="VelocityVectorMapping"></param>
 /// <param name="PressureMapping"></param>
 /// <param name="SolverConf"></param>
 /// <param name="Velocity0"></param>
 /// <param name="Velocity0Mean"></param>
 /// <param name="Temperature0"></param>
 /// <param name="Temperature0Mean"></param>
 /// <param name="eta"></param>
 public OperatorFactoryFlowFieldLowMach(UnsetteledCoordinateMapping VelocityMapping, UnsetteledCoordinateMapping VelocityVectorMapping,
                                        UnsetteledCoordinateMapping PressureMapping,
                                        SolverConfiguration SolverConf,
                                        VectorField <SinglePhaseField> Velocity0, VectorField <SinglePhaseField> Velocity0Mean, SinglePhaseField Temperature0, SinglePhaseField Temperature0Mean,
                                        SinglePhaseField eta)
     : base(VelocityMapping, VelocityVectorMapping, PressureMapping, SolverConf, Velocity0, Velocity0Mean, Temperature0, Temperature0Mean, eta)
 {
 }
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="VelocityMapping"></param>
 /// <param name="VelocityVectorMapping"></param>
 /// <param name="PressureMapping"></param>
 /// <param name="SolverConf"></param>
 /// <param name="Velocity0"></param>
 /// <param name="Velocity0Mean"></param>
 /// <param name="Phi0"></param>
 /// <param name="Phi0Mean"></param>
 /// <param name="eta"></param>
 public OperatorFactoryFlowFieldMultiphase(UnsetteledCoordinateMapping VelocityMapping, UnsetteledCoordinateMapping VelocityVectorMapping,
                                           UnsetteledCoordinateMapping PressureMapping,
                                           SolverConfiguration SolverConf,
                                           VectorField <SinglePhaseField> Velocity0, VectorField <SinglePhaseField> Velocity0Mean, SinglePhaseField Phi0, SinglePhaseField Phi0Mean,
                                           SinglePhaseField eta)
     : base(VelocityMapping, VelocityVectorMapping, PressureMapping, SolverConf, Velocity0, Velocity0Mean, Phi0, Phi0Mean, eta)
 {
 }
Exemplo n.º 28
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="TemperatureMapping"></param>
 /// <param name="Velocity0"></param>
 /// <param name="Velocity0Mean"></param>
 /// <param name="Temperature0"></param>
 /// <param name="Temperature0Mean"></param>
 /// <param name="SolverConf"></param>
 public TemperatureConvectionOperator(UnsetteledCoordinateMapping TemperatureMapping,
                                      VectorField <SinglePhaseField> Velocity0, VectorField <SinglePhaseField> Velocity0Mean, SinglePhaseField Temperature0, SinglePhaseField Temperature0Mean,
                                      SolverConfiguration SolverConf)
     : base(TemperatureMapping, TemperatureMapping,
            ArrayTools.Cat <SinglePhaseField>(Velocity0.ToArray(), Velocity0Mean.ToArray(), Temperature0, Temperature0Mean),
            SolverConf, false)
 {
 }
Exemplo n.º 29
0
        /// <summary>
        /// Prolongates/injects a vector from the full grid (<see cref="BoSSS.Foundation.Grid.GridData"/>)
        /// to the aggregated grid (<see cref="AggGrid"/>).
        /// </summary>
        /// <param name="FullGridVector">output;</param>
        /// <param name="AggGridVector">input;</param>
        virtual public void ProlongateToFullGrid <T, V>(T FullGridVector, V AggGridVector)
            where T : IList <double>
            where V : IList <double> //
        {
            var fullMapping = new UnsetteledCoordinateMapping(this.DGBasis);

            if (FullGridVector.Count != fullMapping.LocalLength)
            {
                throw new ArgumentException("mismatch in vector length", "FullGridVector");
            }
            int L = this.LocalDim;

            if (AggGridVector.Count != L)
            {
                throw new ArgumentException("mismatch in vector length", "AggGridVector");
            }


            var ag    = this.AggGrid;
            var agCls = ag.iLogicalCells.AggregateCellToParts;
            int JAGG  = ag.iLogicalCells.NoOfLocalUpdatedCells;
            int N     = this.DGBasis.Length;

            var FulCoords = new double[N];
            var AggCoords = new double[N];

            //MultidimensionalArray Trf = MultidimensionalArray.Create(N, N);

            for (int jAgg = 0; jAgg < JAGG; jAgg++)
            {
                int[] agCl = agCls[jAgg];
                int   K    = agCl.Length;

                int i0 = jAgg * N;
                for (int n = 0; n < N; n++)
                {
                    AggCoords[n] = AggGridVector[n + i0];
                }

                for (int k = 0; k < K; k++)  // loop over the cells wich form the aggregated cell...
                {
                    int jCell = agCl[k];
                    int j0    = fullMapping.LocalUniqueCoordinateIndex(0, jCell, 0);

                    //Trf.Clear();
                    //Trf.Acc(1.0, this.CompositeBasis[jAgg].ExtractSubArrayShallow(k, -1, -1));
                    var Trf = this.CompositeBasis[jAgg].ExtractSubArrayShallow(k, -1, -1);

                    //Trf.Solve(FulCoords, AggCoords);
                    Trf.gemv(1.0, AggCoords, 0.0, FulCoords);

                    for (int n = 0; n < N; n++)
                    {
                        FullGridVector[j0 + n] = FulCoords[n];
                    }
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// ctor
        /// </summary>
        public LocalSolver_Elliptic(Basis __LevelSetBasis)
        {
            this.GridDat         = (GridData)(__LevelSetBasis.GridDat);
            this.LevelSetMapping = new UnsetteledCoordinateMapping(__LevelSetBasis);
            this.LevelSetBasis   = __LevelSetBasis;

            this.m_LaplaceMatrix = new MsrMatrix(this.LevelSetMapping, this.LevelSetMapping);
            this.m_LaplaceAffine = new double[this.LevelSetMapping.LocalLength];
        }