Ejemplo n.º 1
0
        /// <summary>
        /// Method that is called by the base class constructor. In this implicit euler scheme, it simply
        /// adds the diagonal entries to the operator matrix.
        /// Currently only working for fields that should be included in the time stepping.
        /// </summary>
        /// <param name="OperatorMatrix">The operator matrix that should be adjusted and passed onto the solver</param>
        /// <param name="dt">time step size</param>
        protected override void DefineMatrix(MsrMatrix OperatorMatrix, double dt)
        {
            int[]         cells            = m_Subgrid.SubgridIndex2LocalCellIndex;
            IList <Field> fields           = m_SubgridMapping.Fields;
            int           CoordinateOffset = 0;

            for (int g = 0; g < temporalOp.Length; g++)
            {
                if (temporalOp[g])
                {
                    Field gamma = fields[g];

                    for (int j = 0; j < cells.Length; j++)
                    {
                        int iglob = j * m_SubgridMapping.MaxTotalNoOfCoordinatesPerCell + CoordinateOffset + (int)OperatorMatrix.RowPartition.i0;
                        for (int n = 0; n < gamma.Basis.MaximalLength; n++)
                        {
                            double vadd = 1.0 / dt;
                            double v    = OperatorMatrix.GetDiagElement(iglob);
                            v += vadd;
                            OperatorMatrix.SetDiagElement(iglob, v);
                            iglob++;
                        }
                    }
                }
                CoordinateOffset += fields[g].Basis.MaximalLength;
            }
            m_Solver.DefineMatrix(OperatorMatrix);
            OperatorMatrix.SaveToTextFileSparse("Matrix.txt");
        }
Ejemplo n.º 2
0
        public void Init(MultigridOperator op)
        {
            int D = op.GridData.SpatialDimension;

            CodName = new string[] { "momX", "momY", "div", "constitutiveXX", "constitutiveXY", "constitutiveYY" };
            Params  = new string[] { "VelocityX_GradientX", "VelocityX_GradientY", "VelocityY_GradientX", "VelocityY_GradientY" };
            DomName = new string[] { "VelocityX", "VelocityY", "Pressure", "StressXX", "StressXY", "StressYY" };

            LocalOp = new SpatialOperator(DomName, Params, CodName, (A, B, C) => 4);

            LocalOp.EquationComponents["constitutiveXX"].Add(new LocalJacobiFlux()
            {
                m_component = 0, We = m_We
            });
            LocalOp.EquationComponents["constitutiveXY"].Add(new LocalJacobiFlux()
            {
                m_component = 1, We = m_We
            });
            LocalOp.EquationComponents["constitutiveYY"].Add(new LocalJacobiFlux()
            {
                m_component = 2, We = m_We
            });

            LocalOp.Commit();

            var   U0      = ((BoSSS.Foundation.CoordinateMapping)op.Mapping.ProblemMapping).Fields.GetSubVector(0, 2);
            Basis U0Basis = new Basis(op.Mapping.GridData, 0);

            VectorField <SinglePhaseField> VelocityXGradient = new VectorField <SinglePhaseField>(D, U0Basis, "VelocityX_Gradient", SinglePhaseField.Factory);
            VectorField <SinglePhaseField> VelocityYGradient = new VectorField <SinglePhaseField>(D, U0Basis, "VelocityY_Gradient", SinglePhaseField.Factory);

            VelocityXGradient.Clear();
            VelocityXGradient.GradientByFlux(1.0, U0[0]);
            VelocityYGradient.Clear();
            VelocityYGradient.GradientByFlux(1.0, U0[1]);

            var Parameters = ArrayTools.Cat <DGField>(VelocityXGradient, VelocityYGradient);

            LocalMatrix = LocalOp.ComputeMatrix(op.BaseGridProblemMapping, Parameters, op.BaseGridProblemMapping);

            ConstEqIdx = op.Mapping.ProblemMapping.GetSubvectorIndices(true, 3, 4, 5);

            P = (BlockMsrMatrix)op.MassMatrix.Clone();

            for (int i = ConstEqIdx[0]; i <= ConstEqIdx.Length; i++)
            {
                for (int j = ConstEqIdx[0]; j <= ConstEqIdx.Length; j++)
                {
                    if (LocalMatrix[i, j] != 0)
                    {
                        P[i, j] = LocalMatrix[i, j];
                    }
                }
            }

            LocalMatrix.SaveToTextFileSparse("LocalMatrix");
            op.MassMatrix.SaveToTextFileSparse("MassMatrix");
            P.SaveToTextFileSparse("PrecondMatrix");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Test code for debugging.
        /// </summary>
        /// <param name="OperatorsFlowField"></param>
        /// <param name="VelocityMapping"></param>
        /// <param name="VelocityVectorMapping"></param>
        private void SaveMatricesToTextFile(OperatorFactoryFlowFieldVariableDensity OperatorsFlowField,
                                            UnsetteledCoordinateMapping VelocityMapping, UnsetteledCoordinateMapping VelocityVectorMapping)
        {
            OperatorsFlowField.Swip2[0].OperatorMatrix.SaveToTextFileSparse("C:\\tmp\\Swip20.txt");
            OperatorsFlowField.Swip2[1].OperatorMatrix.SaveToTextFileSparse("C:\\tmp\\Swip21.txt");
            OperatorsFlowField.Swip3[0].OperatorMatrix.SaveToTextFileSparse("C:\\tmp\\Swip30.txt");
            OperatorsFlowField.Swip3[1].OperatorMatrix.SaveToTextFileSparse("C:\\tmp\\Swip31.txt");

            ViscSplit[0, 0].AssemblyMatrix.SaveToTextFileSparse("C:\\tmp\\ViscSplit00.txt");
            ViscSplit[0, 1].AssemblyMatrix.SaveToTextFileSparse("C:\\tmp\\ViscSplit01.txt");
            ViscSplit[1, 0].AssemblyMatrix.SaveToTextFileSparse("C:\\tmp\\ViscSplit10.txt");
            ViscSplit[1, 1].AssemblyMatrix.SaveToTextFileSparse("C:\\tmp\\ViscSplit11.txt");

            int[] IndicesVelocity        = VelocityMapping.GetSubvectorIndices(true, 0);
            int[] IndicesVelocityVector0 = VelocityVectorMapping.GetSubvectorIndices(true, 0);
            int[] IndicesVelocityVector1 = VelocityVectorMapping.GetSubvectorIndices(true, 1);

            MsrMatrix Swip2Mtx = new MsrMatrix(VelocityVectorMapping);

            OperatorsFlowField.Swip2[0].OperatorMatrix.WriteSubMatrixTo <IList <int>, IList <int>, IList <int>, IList <int> >(Swip2Mtx,
                                                                                                                              IndicesVelocity,
                                                                                                                              IndicesVelocityVector0,
                                                                                                                              IndicesVelocityVector0,
                                                                                                                              IndicesVelocityVector0);
            OperatorsFlowField.Swip2[0].OperatorMatrix.AccSubMatrixTo <IList <int>, IList <int>, IList <int>, IList <int> >(1.0,
                                                                                                                            Swip2Mtx,
                                                                                                                            IndicesVelocity,
                                                                                                                            IndicesVelocityVector0,
                                                                                                                            IndicesVelocityVector1,
                                                                                                                            IndicesVelocityVector1);
            OperatorsFlowField.Swip2[1].OperatorMatrix.AccSubMatrixTo <IList <int>, IList <int>, IList <int>, IList <int> >(1.0,
                                                                                                                            Swip2Mtx,
                                                                                                                            IndicesVelocity,
                                                                                                                            IndicesVelocityVector1,
                                                                                                                            IndicesVelocityVector0,
                                                                                                                            IndicesVelocityVector0);
            OperatorsFlowField.Swip2[1].OperatorMatrix.AccSubMatrixTo <IList <int>, IList <int>, IList <int>, IList <int> >(1.0,
                                                                                                                            Swip2Mtx,
                                                                                                                            IndicesVelocity,
                                                                                                                            IndicesVelocityVector1,
                                                                                                                            IndicesVelocityVector1,
                                                                                                                            IndicesVelocityVector1);

            Swip2Mtx.SaveToTextFileSparse("C:\\tmp\\Swip2.txt");
        }
Ejemplo n.º 4
0
        public void Init(MultigridOperator op)
        {
            int D = op.GridData.SpatialDimension;

            CodName = (new string[] { "mom0", "mom1" });
            Params  = ArrayTools.Cat(
                VariableNames.Velocity0Vector(D));
            DomName = ArrayTools.Cat(VariableNames.VelocityVector(D));

            LocalOp = new SpatialOperator(DomName, Params, CodName, (A, B, C) => 4);

            for (int d = 0; d < D; d++)
            {
                LocalOp.EquationComponents["mom" + d].Add(new LocalDiffusiveFlux()
                {
                    m_component = d, dt = m_dt, muA = m_muA
                });
            }

            LocalOp.Commit();

            //LocalMatrix = op.MassMatrix.CloneAs().ToMsrMatrix();
            //LocalMatrix.Clear();

            //var U0 = new VectorField<SinglePhaseField>(op.BaseGridProblemMapping Take(D).Select(F => (SinglePhaseField)F).ToArray());

            UnsetteledCoordinateMapping test = new UnsetteledCoordinateMapping(op.BaseGridProblemMapping.BasisS.GetSubVector(0, D));

            var U0 = ((BoSSS.Foundation.CoordinateMapping)op.Mapping.ProblemMapping).Fields.GetSubVector(0, 2);

            var empty = new SinglePhaseField[D];

            LocalMatrix = LocalOp.ComputeMatrix(test, empty, test, time: m_dt);


            Uidx = op.Mapping.ProblemMapping.GetSubvectorIndices(true, D.ForLoop(i => i));
            Pidx = op.Mapping.ProblemMapping.GetSubvectorIndices(true, D);

            int Upart = Uidx.Length;
            int Ppart = Pidx.Length;

            ConvDiff = new MsrMatrix(Upart, Upart, 1, 1);
            pGrad    = new MsrMatrix(Upart, Ppart, 1, 1);
            divVel   = new MsrMatrix(Ppart, Upart, 1, 1);
            var VelocityMass        = new MsrMatrix(Upart, Upart, 1, 1);
            var leftChangeBasesVel  = new MsrMatrix(Upart, Upart, 1, 1);
            var rightChangeBasesVel = new MsrMatrix(Upart, Upart, 1, 1);

            op.MassMatrix.AccSubMatrixTo(1.0, VelocityMass, Uidx, default(int[]), Uidx, default(int[]), default(int[]), default(int[]));

            op.LeftChangeOfBasis.AccSubMatrixTo(1.0, leftChangeBasesVel, Uidx, default(int[]), Uidx, default(int[]), default(int[]), default(int[]));
            op.RightChangeOfBasis.AccSubMatrixTo(1.0, rightChangeBasesVel, Uidx, default(int[]), Uidx, default(int[]), default(int[]), default(int[]));

            var temp = MsrMatrix.Multiply(leftChangeBasesVel, LocalMatrix);

            LocalMatrix = MsrMatrix.Multiply(temp, rightChangeBasesVel);

            var M = op.OperatorMatrix;

            M.AccSubMatrixTo(1.0, ConvDiff, Uidx, default(int[]), Uidx, default(int[]), default(int[]), default(int[]));
            M.AccSubMatrixTo(1.0, pGrad, Uidx, default(int[]), Pidx, default(int[]), default(int[]), default(int[]));
            M.AccSubMatrixTo(1.0, divVel, Pidx, default(int[]), Uidx, default(int[]), default(int[]), default(int[]));

            LocalMatrix.SaveToTextFileSparse("LocalConvDiffMatrix");
            ConvDiff.SaveToTextFileSparse("ConvDiff");
            op.MassMatrix.SaveToTextFileSparse("MassMatrix");
            VelocityMass.SaveToTextFileSparse("VelocityMass");
        }
Ejemplo n.º 5
0
        public void Solve <U, V>(U X, V B)
            where U : IList <double>
            where V : IList <double>
        {
            var Bu = new double[Uidx.Length];
            var Xu = Bu.CloneAs();

            Bu = B.GetSubVector(Uidx, default(int[]));
            var Bp = new double[Pidx.Length];
            var Xp = Bp.CloneAs();

            Bp = B.GetSubVector(Pidx, default(int[]));

            Xu = X.GetSubVector(Uidx, default(int[]));
            Xp = X.GetSubVector(Pidx, default(int[]));

            P = new MsrMatrix(Pidx.Length, Pidx.Length);

            MultidimensionalArray Schur = MultidimensionalArray.Create(Pidx.Length, Pidx.Length);

            using (BatchmodeConnector bmc = new BatchmodeConnector())
            {
                bmc.PutSparseMatrix(LocalMatrix, "LocalMatrix");
                bmc.PutSparseMatrix(divVel, "divVel");
                bmc.PutSparseMatrix(pGrad, "pGrad");
                bmc.Cmd("invLocalMatrix = inv(full(LocalMatrix))");
                bmc.Cmd("Poisson = invLocalMatrix*pGrad");
                bmc.Cmd("Schur= divVel*Poisson");
                bmc.GetMatrix(Schur, "Schur");
                bmc.Execute(false);
            }

            P = Schur.ToMsrMatrix();

            P.SaveToTextFileSparse("LocalSchur");

            using (var solver = new ilPSP.LinSolvers.MUMPS.MUMPSSolver())
            {
                solver.DefineMatrix(P);
                solver.Solve(Xp, Bp);
            }

            //var temp2 = Xp.CloneAs();

            //LocalMatrix.SpMV(1, Xp, 0, temp2);

            //using (var solver = new ilPSP.LinSolvers.MUMPS.MUMPSSolver())
            //{
            //    solver.DefineMatrix(divVel);
            //    solver.Solve(Xp, temp2);
            //}


            // Solve ConvD           iff*w=v-q*pGrad
            pGrad.SpMVpara(-1, Xp, 1, Bu);

            using (var solver = new ilPSP.LinSolvers.MUMPS.MUMPSSolver())
            {
                solver.DefineMatrix(ConvDiff);
                solver.Solve(Xu, Bu);
            }

            var temp = new double[Uidx.Length + Pidx.Length];

            for (int i = 0; i < Uidx.Length; i++)
            {
                temp[Uidx[i]] = Xu[i];
            }

            for (int i = 0; i < Pidx.Length; i++)
            {
                temp[Pidx[i]] = Xp[i];
            }

            X.SetV(temp);
        }