コード例 #1
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");
        }
コード例 #2
0
        /// <summary>
        /// Calculating the level set gradient using the specified scheme in a narrow band around the zero level set, therein the calculions are performed
        /// </summary>
        /// <param name="LS"> The level set function </param>
        /// <param name="LSG"> Gradient of the level set function </param>
        /// <param name="f"> Specifying the method of flux calculation </param>
        /// <param name="Restriction"> The narrow band around the zero level set wherein the calculations are performed </param>
        void CalculateLevelSetGradient(LevelSet LS, VectorField <SinglePhaseField> LSG, string f, SubGrid Restriction)
        {
            SpatialOperator   SO;
            CoordinateMapping CoDom;

            if (m_ctx.SpatialDimension == 2)
            {
                SO = new SpatialOperator(1, 2, QuadOrderFunc.Linear(), new string[] { "LS", "LSG[0]", "LSG[1]" });
                SO.EquationComponents["LSG[0]"].Add(CreateFlux(m_ctx, f, 0));
                SO.EquationComponents["LSG[1]"].Add(CreateFlux(m_ctx, f, 1));
                SO.Commit();
                CoDom = new CoordinateMapping(LSG[0], LSG[1]);
            }
            else if (m_ctx.SpatialDimension == 3)
            {
                SO = new SpatialOperator(1, 3, QuadOrderFunc.Linear(), new string[] { "LS", "LSG[0]", "LSG[1]", "LSG[2]" });
                SO.EquationComponents["LSG[0]"].Add(CreateFlux(m_ctx, f, 0));
                SO.EquationComponents["LSG[1]"].Add(CreateFlux(m_ctx, f, 1));
                SO.EquationComponents["LSG[2]"].Add(CreateFlux(m_ctx, f, 2));
                SO.Commit();
                CoDom = new CoordinateMapping(LSG[0], LSG[1], LSG[2]);
            }
            else
            {
                throw new NotSupportedException();
            }

            SO.Evaluate(1.0, 0.0, LS.Mapping, null, CoDom, sgrd: Restriction, bndMode: SubGridBoundaryModes.OpenBoundary);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        protected override void CreateEquationsAndSolvers(GridUpdateDataVaultBase L)
        {
            diffOp = new SpatialOperator(new string[] { "u" },
                                         Solution.NSECommon.VariableNames.VelocityVector(this.GridData.SpatialDimension),
                                         new string[] { "codom1" },
                                         QuadOrderFunc.Linear());


            switch (this.GridData.SpatialDimension)
            {
            case 2:
                diffOp.EquationComponents["codom1"].Add(new ScalarTransportFlux());
                break;

            case 3:
                diffOp.EquationComponents["codom1"].Add(new ScalarTransportFlux3D());
                break;

            default:
                throw new NotImplementedException("spatial dim. not supported.");
            }
            diffOp.Commit();

            Timestepper = new RungeKutta(RungeKuttaScheme.TVD3,
                                         diffOp,
                                         new CoordinateMapping(u), Velocity.Mapping);

            //Timestepper = new ROCK4(diffOp, u.CoordinateVector, Velocity.Mapping);
        }
コード例 #4
0
        /// <summary>
        /// Update of level-set gradient in 'upwind'-direction, i.e. at boundaries towards accepted cells,
        /// the outer value is taken.
        /// </summary>
        /// <param name="jCell">Cell index to update.</param>
        /// <param name="AcceptedMask"></param>
        /// <param name="Phi">Input: the level-set</param>
        /// <param name="gradPhi">Output: gradient of <paramref name="Phi"/> in cell <paramref name="jCell"/>.</param>
        public void GradientUpdate(int jCell, BitArray AcceptedMask, SinglePhaseField Phi, VectorField <SinglePhaseField> gradPhi)
        {
            var GridDat = Phi.GridDat;

            if (m_gradEvo == null || jCell != m_gradEvo_jCell)
            {
                var Sgrd = new SubGrid(new CellMask(GridDat, Chunk.GetSingleElementChunk(jCell)));



                SpatialOperator op = new SpatialOperator(1, 2, QuadOrderFunc.Linear(), "Phi", "g0", "g1");
                op.EquationComponents["g0"].Add(new Gradient(0, jCell, AcceptedMask));
                op.EquationComponents["g1"].Add(new Gradient(1, jCell, AcceptedMask));
                op.EdgeQuadraturSchemeProvider   = g => new EdgeQuadratureScheme(domain: Sgrd.AllEdgesMask);
                op.VolumeQuadraturSchemeProvider = g => new CellQuadratureScheme(domain: Sgrd.VolumeMask);
                op.Commit();

                m_gradEvo = op.GetEvaluatorEx(
                    Phi.Mapping, null, gradPhi.Mapping);
                m_gradEvo.ActivateSubgridBoundary(subGridBoundaryTreatment: SubGridBoundaryModes.BoundaryEdge, sgrd: Sgrd.VolumeMask);

                m_gradEvo_jCell = jCell;
            }

            foreach (var f in gradPhi)
            {
                f.Coordinates.ClearRow(jCell);
            }
            m_gradEvo.MPITtransceive = false;
            m_gradEvo.Evaluate(1.0, 1.0, gradPhi.CoordinateVector);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        public void GradientUpdate(SubGrid Sgrd, double[] PhiMean, SinglePhaseField Phi, VectorField <SinglePhaseField> gradPhi)
        {
            var GridDat = Phi.GridDat;


            gradPhi.Clear(Sgrd.VolumeMask);

            SpatialOperator op = new SpatialOperator(1, 2, QuadOrderFunc.Linear(), "Phi", "g0", "g1");

            op.EquationComponents["g0"].Add(new Gradient2(0, PhiMean));
            op.EquationComponents["g1"].Add(new Gradient2(1, PhiMean));
            op.EdgeQuadraturSchemeProvider   = g => (new EdgeQuadratureScheme(domain: Sgrd.AllEdgesMask));
            op.VolumeQuadraturSchemeProvider = g => (new CellQuadratureScheme(domain: Sgrd.VolumeMask));
            op.Commit();

            var gradEvo = op.GetEvaluatorEx(Phi.Mapping, null, gradPhi.Mapping);

            gradEvo.ActivateSubgridBoundary(Sgrd.VolumeMask, SubGridBoundaryModes.BoundaryEdge);

            //Sgrd.VolumeMask.ToTxtFile("nar.csv", false);


            gradPhi.Clear(Sgrd.VolumeMask);
            gradEvo.time           = 0.0;
            gradEvo.MPITtransceive = false;
            gradEvo.Evaluate(1.0, 0.0, gradPhi.CoordinateVector);
            //gradPhi.GradientByFlux(1.0, Phi, optionalSubGrid:Sgrd , bndMode: SubGridBoundaryModes.BoundaryEdge);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        public void GradientUpdate(SubGrid Sgrd, double[] PhiMean, SinglePhaseField Phi, VectorField <SinglePhaseField> gradPhi)
        {
            var GridDat = Phi.GridDat;


            gradPhi.Clear(Sgrd.VolumeMask);

            SpatialOperator op = new SpatialOperator(1, 2, QuadOrderFunc.Linear(), "Phi", "g0", "g1");

            op.EquationComponents["g0"].Add(new Gradient2(0, PhiMean));
            op.EquationComponents["g1"].Add(new Gradient2(1, PhiMean));
            op.Commit();

            var gradEvo = op.GetEvaluatorEx(
                Phi.Mapping, null, gradPhi.Mapping,
                edgeQrCtx: (new EdgeQuadratureScheme(domain: Sgrd.AllEdgesMask)),
                volQrCtx: (new CellQuadratureScheme(domain: Sgrd.VolumeMask)),
                subGridBoundaryTreatment: SpatialOperator.SubGridBoundaryModes.BoundaryEdge, sgrd: Sgrd);

            //Sgrd.VolumeMask.ToTxtFile("nar.csv", false);


            gradPhi.Clear(Sgrd.VolumeMask);
            gradEvo.Evaluate(1.0, 0.0, gradPhi.CoordinateVector, 0.0, MPIexchange: false);
            //gradPhi.GradientByFlux(1.0, Phi, optionalSubGrid:Sgrd , bndMode: SpatialOperator.SubGridBoundaryModes.BoundaryEdge);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: xyuan/BoSSS
        protected override void CreateEquationsAndSolvers(GridUpdateDataVaultBase L)
        {
            diffOp = new SpatialOperator(
                new string[] { "c" },
                new string[] { "viscosity", "VelocityX", "VelocityY" },
                new string[] { "codom1" },
                QuadOrderFunc.Linear());
            diffOp.EquationComponents["codom1"].Add(new ScalarTransportFlux2D(inflowDirichletValue));
            diffOp.Commit();

            CoordinateMapping coordMap;

            coordMap = new CoordinateMapping(viscosity, Velocity[0], Velocity[1]);

            // 3 sub-grids
            MultidimensionalArray metricOne = MultidimensionalArray.Create(numOfCellsX);
            MultidimensionalArray metricTwo = MultidimensionalArray.Create(numOfCellsX);

            // 3 cells
            //metricOne[0] = 2;
            //metricOne[1] = 1;
            //metricOne[2] = 0.5;

            //metricTwo[0] = 1;
            //metricTwo[1] = 0.5;
            //metricTwo[2] = 2;

            // 4 cells
            metricOne[0] = 2;
            metricOne[1] = 1;
            metricOne[2] = 0.5;
            metricOne[3] = 0.25;

            metricTwo[0] = 0.5;
            metricTwo[1] = 2;
            metricTwo[2] = 0.25;
            metricTwo[3] = 1;

            CustomTimestepConstraint = new SurrogateConstraint(GridData, dtFixed, dtFixed, double.MaxValue, endTime, metricOne, metricTwo);

            timeStepper = new AdamsBashforthLTS(
                diffOp,
                new CoordinateMapping(c),
                coordMap,
                order: ABOrder,
                numOfClusters: this.numOfSubgrids,
                timeStepConstraints: new List <TimeStepConstraint>()
            {
                CustomTimestepConstraint
            },
                fluxCorrection: false,
                reclusteringInterval: 1);

            // Sub-grid visualization
            //AdamsBashforthLTS timeStepper2 = timeStepper as AdamsBashforthLTS;
            //timeStepper2.SubGridField.Identification = "clusterLTS";
            //m_IOFields.Add(timeStepper2.SubGridField);
            //timeStepper = timeStepper2;
        }
コード例 #8
0
        private MsrMatrix PenaltyMatrix(EdgeMask em, Basis LevSetBasis, Basis JumpBasis)
        {
            var OpA = new SpatialOperator(1, 0, 1, QuadOrderFunc.Linear(), "Phi", "c1");

            OpA.EquationComponents["c1"].Add(new JumpForm());
            //OpA.EquationComponents["c1"].Add(new GradientJumpForm() { ATerm = true, BTerm = true });
            OpA.EquationComponents["c1"].Add(new GradientJumpForm2());
            OpA.Commit();

            //var OpB = new SpatialOperator(1, 0, 1, "Phi", "c1");
            //Op.EquationComponents["c1"].Add(new JumpForm());
            //OpB.EquationComponents["c1"].Add(new GradientJumpForm() { BTerm = true });
            //Op.EquationComponents["c1"].Add(new GradientJumpForm2());
            //OpB.Commit();

            var inp_LevSet_Mapping  = new UnsetteledCoordinateMapping(LevSetBasis);
            var outp_Result_Mapping = new UnsetteledCoordinateMapping(JumpBasis);

            MsrMatrix MatrixA;

            MatrixA = new MsrMatrix(outp_Result_Mapping, inp_LevSet_Mapping);
            double[] AffineA = new double[inp_LevSet_Mapping.LocalLength];
            OpA.ComputeMatrixEx(inp_LevSet_Mapping, null, outp_Result_Mapping,
                                MatrixA, AffineA, OnlyAffine: false,
                                edgeQuadScheme: new EdgeQuadratureScheme(true, em),
                                volQuadScheme: new CellQuadratureScheme(true, CellMask.GetEmptyMask(em.GridData)));
            MatrixA.CheckForNanOrInfM();

            //MsrMatrix MatrixB;
            //MatrixB = new MsrMatrix(outp_Result_Mapping, inp_LevSet_Mapping);
            //double[] AffineB = new double[inp_LevSet_Mapping.LocalLength];
            //OpB.ComputeMatrixEx(inp_LevSet_Mapping, null, outp_Result_Mapping,
            //    MatrixB, AffineB, OnlyAffine: false
            //    );//,
            //    //edgeQrCtx: new EdgeQuadratureScheme(true, em),
            //    //volQrCtx: new CellQuadratureScheme(true, CellMask.GetEmptyMask(em.GridData)));

            //Debug.Assert(AffineB.L2Norm() == 0);

            //var Err = MatrixA.Transpose();
            //Err.Acc(-1.0, MatrixB);

            //double errnorm = Err.InfNorm();
            //Debug.Assert(errnorm < 1.0e-10);
            ////Console.WriteLine("Errnorm:" + errnorm);


            return(MatrixA);
        }
コード例 #9
0
        public void Evaluate2(SubGrid S, SinglePhaseField inp_LevSet, SinglePhaseField outp_Result)
        {
            var Op = new SpatialOperator(1, 0, 1, QuadOrderFunc.Linear(), "Phi", "c1");

            Op.EquationComponents["c1"].Add(new JumpForm());
            //Op.EquationComponents["c1"].Add(new GradientJumpForm() { BTerm = true });
            Op.EquationComponents["c1"].Add(new GradientJumpForm2());
            Op.Commit();


            var inp_LevSet_Mapping  = inp_LevSet.Mapping;
            var outp_Result_Mapping = outp_Result.Mapping;


            Op.Evaluate(1.0, 1.0,
                        inp_LevSet_Mapping, new DGField[0], outp_Result_Mapping);//,
            //qInsEdge: new EdgeQuadratureScheme(true, S.InnerEdgesMask),
            //qInsVol: new CellQuadratureScheme(true, CellMask.GetEmptyMask(S._GridData)),
            //bndMode: SpatialOperator.SubGridBoundaryModes.InnerEdge,
            //sgrd: S);
        }
コード例 #10
0
        /// <summary>
        /// Creating the time integrated DG-FEM discretization of the level set advection equation
        /// </summary>
        /// <param name="LevelSet"></param>
        /// <param name="ExtensionVelocity"></param>
        /// <param name="e"></param>
        void CreateAdvectionSpatialOperator(SinglePhaseField LevelSet, SinglePhaseField ExtensionVelocity, ExplicitEuler.ChangeRateCallback e, SubGrid subGrid)
        {
            SpatialOperator SO;
            Func <int[], int[], int[], int> QuadOrderFunction = QuadOrderFunc.Linear();
            int D = LevelSet.GridDat.SpatialDimension;

            //FieldFactory<SinglePhaseField> fac = new FieldFactory<SinglePhaseField>(SinglePhaseField.Factory);
            //VectorField<SinglePhaseField> LevelSetGradient = new VectorField<SinglePhaseField>(D,
            //    LevelSet.Basis,fac);

            SO = new SpatialOperator(1, 1, 1, QuadOrderFunction, new string[] { "LS", "S", "Result" });
            double PenaltyBase = ((double)((LevelSet.Basis.Degree + 1) * (LevelSet.Basis.Degree + D))) / ((double)D);

            SO.EquationComponents["Result"].Add(new ScalarVelocityAdvectionFlux(GridDat, PenaltyBase));
            SO.Commit();
            this.TimeIntegrator = new RungeKutta(RungeKuttaScheme.ExplicitEuler, SO, new CoordinateMapping(LevelSet), new CoordinateMapping(ExtensionVelocity), subGrid);

            // Performing the task e
            if (e != null)
            {
                this.TimeIntegrator.OnBeforeComputeChangeRate += e;
            }
        }
コード例 #11
0
        unsafe public static void Laplacian(ref int GridRef,
                                            ref int DgDegree,

                                            out int ierr)
        {
            try {
                // grid, etc
                // =========

                GridData grd = null;// (GridData)(Infrastructure.GetObject(GridRef));

                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");
            } catch (Exception e) {
                ierr = Infrastructure.ErrorHandler(e);
            }
            ierr = 0;
        }
コード例 #12
0
ファイル: ipViscosityMain.cs プロジェクト: shanxiangjun/BoSSS
        protected override void CreateEquationsAndSolvers(GridUpdateDataVaultBase L)
        {
            using (FuncTrace tr = new FuncTrace()) {
                this.BcMap = new IncompressibleBoundaryCondMap(this.GridData, grid.GetBoundaryConfig(), PhysicsMode.Incompressible);


                // assemble system, create matrix
                // ------------------------------



                int D = GridData.SpatialDimension;
                //double penalty_base = ((double)((U[0].Basis.Degree + 1) * (U[0].Basis.Degree + D))) / ((double)D);
                double penalty_base   = 1.0;
                double penalty_factor = 1.2;



                // equation assembly
                // -----------------
                string[] CodNames = D.ForLoop(i => "C" + i);
                Operator = new SpatialOperator(VariableNames.VelocityVector(D), new string[] { VariableNames.ViscosityMolecular }, CodNames, QuadOrderFunc.Linear());

                for (int d = 0; d < D; d++)
                {
                    if ((this.whichTerms & Terms.T1) != 0)
                    {
                        var flx1 = new swipViscosity_Term1(penalty_base * penalty_factor, d, D, BcMap, ViscosityOption.VariableViscosity);

                        flx1.g_Diri_Override = this.solution.U;
                        flx1.g_Neu_Override  = this.solution.dU;
                        Operator.EquationComponents[CodNames[d]].Add(flx1);
                    }
                    if ((this.whichTerms & Terms.T2) != 0)
                    {
                        var flx2 = new swipViscosity_Term2(penalty_base * penalty_factor, d, D, BcMap, ViscosityOption.VariableViscosity);

                        flx2.g_Diri_Override = this.solution.U;
                        flx2.g_Neu_Override  = this.solution.dU;
                        Operator.EquationComponents[CodNames[d]].Add(flx2);
                    }
                    if ((this.whichTerms & Terms.T3) != 0)
                    {
                        var flx3 = new swipViscosity_Term3(penalty_base * penalty_factor, d, D, BcMap, ViscosityOption.VariableViscosity);

                        flx3.g_Diri_Override = this.solution.U;
                        flx3.g_Neu_Override  = this.solution.dU;
                        Operator.EquationComponents[CodNames[d]].Add(flx3);
                    }
                } // */
                Operator.Commit();


                var map = this.U.Mapping;
                OperatorMtx = new MsrMatrix(map, map);
                Operator.ComputeMatrixEx(map, new DGField[] { this.mu }, map,
                                         OperatorMtx, this.bnd.CoordinateVector,
                                         volQuadScheme: null, edgeQuadScheme: null);

                // test for matrix symmetry
                // ========================

                if (base.MPISize == 1)
                {
                    double MatrixAssymmetry = OperatorMtx.SymmetryDeviation();
                    Console.WriteLine("Matrix asymmetry: " + MatrixAssymmetry);
                    Assert.LessOrEqual(Math.Abs(MatrixAssymmetry), 1.0e-10);
                }
            }
        }
コード例 #13
0
        protected override SpatialOperator GetSpatialOperator(SolverConfiguration SolverConf, int SpatialComponent, int SpatialDirection)
        {
            SpatialOperator DivergenceOp = new SpatialOperator(new string[] { VariableNames.Velocity_d(SpatialComponent) }, new string[] { "div_d" }, QuadOrderFunc.Linear());

            DivergenceOp.EquationComponents["div_d"].Add(new Divergence_DerivativeSource(SpatialComponent, SolverConf.SpatialDimension));
            DivergenceOp.EquationComponents["div_d"].Add(new Divergence_DerivativeSource_Flux(SpatialComponent, SolverConf.BcMap));
            DivergenceOp.Commit();
            return(DivergenceOp);
        }
コード例 #14
0
        protected override SpatialOperator GetSpatialOperator(SolverConfiguration SolverConf, int SpatialComponent, int SpatialDirection)
        {
            SpatialOperator PressureOp = new SpatialOperator(new string[] { VariableNames.Pressure }, new string[] { "p1" }, QuadOrderFunc.Linear());

            PressureOp.EquationComponents["p1"].Add(new PressureGradientLin_d(SpatialDirection, SolverConf.BcMap));

            if (SolverConf.Control.PressureGradientSource != null)
            {
                PressureOp.EquationComponents["p1"].Add(
                    new SrcPressureGradientLin_d(SolverConf.Control.PressureGradientSource[SpatialDirection]));
            }

            PressureOp.Commit();
            return(PressureOp);
        }