Ejemplo n.º 1
0
        /// <summary>
        /// Creates an array with an tanh spaced distribution of the mean
        /// values between maximum and minimum value of a given cell metric,
        /// e.g., minimal distance between two nodes in a cell <see cref="GridData.CellData.h_min"/>
        /// </summary>
        /// <param name="cellMetric">Given cell metric</param>
        /// <returns>Double[] with the length of the number of given sub-grids></returns>
        private MultidimensionalArray CreateInitialMeans(MultidimensionalArray cellMetric, int numOfClusters)
        {
            System.Diagnostics.Debug.Assert(
                cellMetric.Storage.All(d => double.IsNaN(d) == false),
                "Cell metrics contains f****d up entries");

            double h_min = cellMetric.Min();
            double h_max = cellMetric.Max();

            //Console.WriteLine("Clustering: Create tanh spaced means");

            // Getting global h_min and h_max
            ilPSP.MPICollectiveWatchDog.Watch();
            h_min = h_min.MPIMin();
            h_max = h_max.MPIMax();

            if (h_min == h_max)
            {
                h_max += 0.1 * h_max; // Dirty hack for IBM cases with equidistant grids
            }
            // Tanh Spacing, which yields to more cell cluster for smaller cells
            var means = Grid1D.TanhSpacing(h_min, h_max, numOfClusters, 4.0, true).Reverse().ToArray();

            // Equidistant spacing, in general not the best choice
            //means = GenericBlas.Linspace(h_min, h_max, NumOfSgrd).Reverse().ToArray();

            return(MultidimensionalArray.CreateWrapper(means, numOfClusters));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Test using subsonicInlet at the inlet and
        /// supersonicInlet (Dirichlet) at the outlet
        /// </summary>
        /// <returns></returns>
        public static CNSControl[] EulerSubsonicInlet1D()
        {
            CNSControl[] templates = GetTemplates();

            foreach (CNSControl c in templates)
            {
                int divisions = (int)c.Paramstudy_CaseIdentification.Single(t => t.Item1 == "divisions").Item2;

                int noOfCells = (2 << divisions) * 8;
                c.GridFunc = delegate {
                    GridCommons grid = Grid1D.LineGrid(
                        GenericBlas.Linspace(0.0, Math.PI / 2.0 + 0.0, noOfCells + 1));
                    grid.EdgeTagNames.Add(1, "supersonicInlet");
                    grid.EdgeTagNames.Add(2, "subsonicInlet");
                    grid.DefineEdgeTags((Vector x) => Math.Abs(x[0]) < 1e-14 ? (byte)2 : (byte)1);
                    return(grid);
                };
                c.ProjectName += "_subsonicInlet2";

                c.AddBoundaryValue("subsonicInlet", CompressibleVariables.Density, exactDensity);
                c.AddBoundaryValue("subsonicInlet", CNSVariables.Velocity[0], exactVelocity);

                c.AddBoundaryValue("supersonicInlet", CompressibleVariables.Density, exactDensity);
                c.AddBoundaryValue("supersonicInlet", CNSVariables.Velocity[0], exactVelocity);
                c.AddBoundaryValue("supersonicInlet", CNSVariables.Pressure, exactPressure);
            }

            return(templates);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Исследование характеристик работы решателя одномерных задач
        /// </summary>
        private static void SolverTask1DTests()
        {
            // Задаём дифференциальный оператор
            var op = new DerivativeOperator1D3P();

            op.Kim1 = -1m / (2m * 0.5m);
            op.Ki   = 2m;
            op.Kip1 = 1m / (2m * 0.5m);

            // Создаём одномерную расчетную область
            var raschOblast1D = new Grid1D(1.5m, 11, AxisEnum.X);
            // Создаём исследуемый объект
            var lineSegment = new GeometryPrimitive1DLineSegment(new Coordinate1D(0m), 0.5m);

            var raschObjectGeometry1D = new Geometry1D();
            var geometryElement       = new GeometryElement1D(new Coordinate1D(0.5m));

            geometryElement.AddGeometryPrimitive(lineSegment);
            raschObjectGeometry1D.AddGeometryElement(geometryElement);

            var gridWithGeometryPrecalculated1D = new GridWithGeometryPreCalculated1D(raschOblast1D, raschObjectGeometry1D);

            var nodeSet1D = gridWithGeometryPrecalculated1D.NodeSet1D;

            // Создаём задачу
            var task = new SolverTask1D();

            task.NodeSet1D = nodeSet1D;

            SolverResult result = Solver.Calculate(task);
        }
Ejemplo n.º 4
0
        public void Init()
        {
            Func <double, double, double> rightPart = (r, t) => 0;
            Grid1D grid = Grid1D.Build(0, 1, 100);

            double[] ut0 = new double[grid.N];
            for (int i = 0; i < grid.N; i++)
            {
                ut0[i] = 0;
            }
            TimeLimitCondition timeLimitCondition = new TimeLimitCondition(2 * Math.PI);
            var boundaryConditions = new[]
            {
                new BoundaryCondition(t => 0, BoundaryConditionLocation.Left,
                                      BoundaryConditionType.Dirichlet),
                new BoundaryCondition(t => Math.Cos(t), BoundaryConditionLocation.Right,
                                      BoundaryConditionType.Dirichlet)
            };
            var scheme   = new CrankNicolsonCylindricScheme1D(boundaryConditions, (r, t) => - (Math.Cos(t) / r) - r * Math.Sin(t), 1);
            var solution = scheme.Solve(timeLimitCondition, grid, ut0, 1E-3);

            Func <double, double, double> uExact = (r, t) => r * t;
            int n = 0;

            foreach (var layer in solution.Layers)
            {
                double[] g = new double[grid.N];
                grid.CopyTo(g, 0);
                Shape2D shape = new Curve2D(g, layer);
                shape.Color   = Color.Black;
                shape.Visible = true;
                shapes.Add(shape);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Test using SubsonicPressureInlet at the inlet and
        /// SubsonicOutlet at the outlet. That is, this test case
        /// uses physically correct boundary conditions
        /// </summary>
        /// <returns></returns>
        public static CNSControl[] EulerSubsonicPressureInletAndOutletTest1D()
        {
            CNSControl[] templates = GetTemplates();

            foreach (CNSControl c in templates)
            {
                int divisions = (int)c.Paramstudy_CaseIdentification.Single(t => t.Item1 == "divisions").Item2;

                int noOfCells = (2 << divisions) * 8;
                c.GridFunc = delegate {
                    GridCommons grid = Grid1D.LineGrid(
                        GenericBlas.Linspace(0.0, Math.PI / 2.0 + 0.0, noOfCells + 1));
                    grid.EdgeTagNames.Add(1, "subsonicPressureInlet");
                    grid.EdgeTagNames.Add(2, "subsonicOutlet");
                    grid.DefineEdgeTags((Vector x) => Math.Abs(x[0]) < 1e-14 ? (byte)1 : (byte)2);
                    return(grid);
                };

                c.AddBoundaryValue("subsonicPressureInlet", "p0", totalPressure);
                c.AddBoundaryValue("subsonicPressureInlet", "T0", totalTemperature);

                c.AddBoundaryValue("subsonicOutlet", CNSVariables.Pressure, exactPressure);
            }

            return(templates);
        }
Ejemplo n.º 6
0
    public V2DataOnGrid(string a, double b, Grid1D x, Grid1D y) : base(a, b)
    {
        Elem = new Grid1D[2];

        Elem[0] = x;
        Elem[1] = y;
    }
Ejemplo n.º 7
0
            /// <summary>
            /// Cartesian grid, nothing fancy.
            /// </summary>
            public void CreateGrid(Context _Context, out GridCommons grd, out IncompressibleBoundaryCondMap bcMap)
            {
                grd = new Cartesian2DGrid(_Context.CommMaster, Grid1D.Linspace(-2, 2, 10), Grid1D.Linspace(-2, 2, 10));
                grd.EdgeTagsNames.Add(1, "Pressure_Outlet");
                grd.DefineEdgeTags(x => 1);

                bcMap = null;
            }
Ejemplo n.º 8
0
        protected override void CreateOrLoadGrid() {
            Debug.Assert(Res % 2 == 0);

            double[] xNodes = Grid1D.Linspace(-1, 1, Res + 1);
            double[] yNodes = Grid1D.Linspace(-1, 1, Res + 1);
            GridCommons grd = new Cartesian2DGrid(m_Context.CommMaster, xNodes, yNodes, null, null, false, false);
            _Context.SetGrid(grd);
        }
Ejemplo n.º 9
0
    static void Main(string[] args)

    {
        Grid1D temp1 = new Grid1D(0.5f, 5);

        Grid1D temp2 = new Grid1D(0.4f, 4);

        DateTime date1 = new DateTime(2020, 10, 21);

        V3DataOnGrid obj1 = new V3DataOnGrid("1111", date1, temp1, temp2);

        obj1.array = new double[2, 3];

        obj1.InitRandom(4.5, 6.1);

        Console.WriteLine(obj1.ToLongString());

        Console.WriteLine();

        V3DataCollection obj2 = (V3DataCollection)obj1;

        Console.WriteLine(obj2.ToLongString());

        Console.WriteLine();

        V3MainCollection obj3 = new V3MainCollection();

        obj3.AddDefaults();

        Console.WriteLine(obj3.ToString());

        int number = 1;

        Vector2 v = new Vector2(1, 2);

        foreach (V3Data data in obj3)

        {
            Console.WriteLine();

            Console.WriteLine($"Nearest for an element №{number} in V3MainCollection");

            Vector2[] res = data.Nearest(v);

            for (int i = 0; i < res.Length; i++)

            {
                Console.WriteLine(res[i]);
            }

            number++;
        }

        Console.ReadKey();
    }
Ejemplo n.º 10
0
    static void Main()
    {
        Grid1D G_1 = new Grid1D(3, 3);
        Grid1D G_2 = new Grid1D(5, 3);

        V2DataOnGrid V2_1 = new V2DataOnGrid("new_1", 5, G_1, G_2);

        V2_1.InitRandom(5, 10);
        //V2_1.NearAverage(0.9f);

        Console.WriteLine('\n' + V2_1.ToLongString());

        V2DataCollection V2C = (V2DataOnGrid)V2_1;

        Console.WriteLine('\n' + V2C.ToLongString());
        //V2C.NearAverage(0.9f);

        V2MainCollection VM_1 = new V2MainCollection();

        VM_1.AddDefaults();
        VM_1.ToString();

        Vector2 vect = new Vector2((float)101010, (float)111);

        foreach (var item in VM_1)
        {
            item.NearAverage(0.5f);
        }


        //Console.WriteLine(V2C.ToLongString());
        //Console.WriteLine(V2_1.NearAverage(0.5f));
        //Console.WriteLine(V2_1.ToString());
        //Console.WriteLine(V2_1.ToLongString());

        V2DataCollection V2C_1 = new V2DataCollection("newC_1", 6);
        V2DataCollection V2C_2 = new V2DataCollection("newC_2", 7);

        //V2C_1.InitRandom(10,10,10,-20,30);
        //Console.WriteLine(V2C_1.ToLongString());
        //V2C_1.NearAverage(0.9f);
        //Console.WriteLine(V2C_1.ToString());
        //Console.WriteLine(V2C_1.ToLongString());

        VM_1.Add(V2_1);
        VM_1.Add(V2C_1);
        VM_1.Add(V2C_2);
        //Console.WriteLine(VM_1.Count);
        VM_1.Remove("new_1", 5);
        //Console.WriteLine(VM_1.Count);
        //VM_1.AddDefaults();
        //Console.WriteLine(VM_1.Count);
    }
Ejemplo n.º 11
0
        void PlotCell0()
        {
            BoundingBox BB = new BoundingBox(2);

            GridDat.Cells.GetCellBoundingBox(0, BB);

            int Nx     = 50;
            int Ny     = 55;
            var xNodes = Grid1D.Linspace(BB.Min[0], BB.Max[0], Nx);
            var yNodes = Grid1D.Linspace(BB.Min[1], BB.Max[1], Ny);

            var GlobalNodes = MultidimensionalArray.Create(Nx, Ny, 2);

            for (int i = 0; i < Nx; i++)
            {
                for (int j = 0; j < Ny; j++)
                {
                    GlobalNodes[i, j, 0] = xNodes[i];
                    GlobalNodes[i, j, 1] = yNodes[j];
                }
            }

            var GlobalNodes_C = GlobalNodes.ResizeShallow(Nx * Ny, 2);
            var LocalNodes    = MultidimensionalArray.Create(1, Nx * Ny, 2);

            GridDat.TransformGlobal2Local(GlobalNodes_C, LocalNodes, 0, 1, 0);

            var Values  = MultidimensionalArray.Create(1, Nx, Ny);
            var Values_ = Values.ResizeShallow(1, Nx * Ny);

            var Gradients  = MultidimensionalArray.Create(1, Nx, Ny, 2);
            var Gradients_ = Gradients.ResizeShallow(1, Nx * Ny, 2);


            var NodeSet = GridDat.NSC.CreateContainer(LocalNodes.ExtractSubArrayShallow(0, -1, -1), 0);
            var lh      = GridDat.NSC.LockNodeSetFamily(NodeSet);

            f1.Evaluate(0, 1, 0, Values_);
            f1.EvaluateGradient(0, 1, 0, Gradients_);
            GridDat.NSC.UnlockNodeSetFamily(lh);


            xNodes.SaveToTextFile("C:\\tmp\\xNodes.txt");
            yNodes.SaveToTextFile("C:\\tmp\\yNodes.txt");

            FullMatrix output1 = new FullMatrix(Values.ExtractSubArrayShallow(0, -1, -1));

            output1.ToTxtFile("C:\\tmp\\f.txt");

            FullMatrix output2 = new FullMatrix(Gradients.ExtractSubArrayShallow(0, -1, -1, 0));

            output2.ToTxtFile("C:\\tmp\\df.txt");
        }
Ejemplo n.º 12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            labelDateTime.Text = System.DateTime.Now.ToString();
            var price = 1234567.32m;

            labelMoney.Text = price.ToString("C", CultureInfo.CurrentCulture);

            var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures)
                           .Except(CultureInfo.GetCultures(CultureTypes.SpecificCultures));

            Grid1D.DataSource = cultures;
            Grid1D.DataBind();
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates Nodes, yes it really does!
 /// </summary>
 /// <param name="res"></param>
 /// <param name="stetch">
 /// Factor which determines how much the intervals in the output grow; 1.0 is no stretching.
 /// </param>
 /// <param name="min"></param>
 /// <param name="max"></param>
 /// <returns></returns>
 static double[] CreateNodes(int res, double stetch, double min, double max)
 {
     if (stetch == 1.0)
     {
         return(GenericBlas.Linspace(min, max, res + 1));
     }
     else
     {
         return(Grid1D.ExponentialSpaceing(min, max, res + 1, stetch)); // without proper preconditioning,
     }
     // a stretched grid is much more expensive than
     // an equidistant grid !!!
 }
Ejemplo n.º 14
0
        /// <summary>
        /// creates a simple 2d/3d bilinear grid;
        /// </summary>


        protected override GridCommons CreateOrLoadGrid()
        {
            // 2d Grid
            // =======
            var xNodes = Grid1D.Linspace(-1, 1, 3);
            var yNodes = Grid1D.Linspace(-1, 1, 3);
            var grd    = Grid2D.Cartesian2DGrid(xNodes, yNodes, CellType.Square_8, false, false);

            //var grd = Grid2D.BilinearSquareGrid(Grid1D.Linspace(-100, 100, 8), Grid1D.Linspace(-100, 100, 8), 0.8, 0, 0, null);
            //var grd = Grid2D.CurvedSquareGrid(Grid1D.Linspace(1, 2, 7), Grid1D.Linspace(0, 1, 16), 9);
            // var grd = Grid2D.CurvedSquareGrid(Grid1D.Linspace(1, 2, 3), Grid1D.Linspace(0, 1, 101), CellType.Square_9, true);
            //var grd = Grid3D.Cartesian3DGrid(Grid1D.Linspace(0, 1, 3), Grid1D.Linspace(0, 1, 3), Grid1D.Linspace(0, 1, 3),false, false, false,CellType.Cube_8);
            //var grd = Grid3D.Cartesian3DGrid(Grid1D.Linspace(-1, 1, 4), Grid1D.Linspace(-1, 1, 4), Grid1D.Linspace(-1, 1, 4),true, true, true, CellType.Cube_Linear);
            //var grd = Grid3D.CylinderGrid(Grid1D.Linspace(1, 2, 4), Grid1D.Linspace(0, 0.25, 4), Grid1D.Linspace(0, 2, 4), CellType.Cube_27, true, true);
            return(grd);
        }
        public void AddDefaults()
        {
            Random rnd   = new Random();
            int    n_new = rnd.Next(3, 5);

            for (int i = 0; i < n_new; i++)
            {
                Grid1D           d1       = new Grid1D(3, 4);
                V2DataOnGrid     New_Grid = new V2DataOnGrid("a", 4, d1, d1);
                V2DataCollection New_Coll = new V2DataCollection("b", 5);
                New_Grid.InitRandom(12, 20);
                New_Coll.InitRandom(5, 1, 10, 12, 20);
                Main_Data.Add(New_Grid);
                Main_Data.Add(New_Coll);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes the Solver. Creates the objects that are used in the solver-method.
        /// Outlines the QuadNodesGlobal which are used as nodes for the geometric approach.
        /// Creates the edges on which the values will be defined in the solver-method.
        /// Creates a Cell which holds all the information of the parameters in the inside of the cell
        /// </summary>
        /// <param name="ExtPropertyBasis"></param>
        public ExtVelSolver_FastMarching(Basis ExtPropertyBasis)
        {
            this.SolverBasis = ExtPropertyBasis;
            this.GridDat     = ExtPropertyBasis.GridDat;

            //Build Edges.
            double[] NodeGrid         = Grid1D.Linspace(-1, 1, Math.Max(20, (this.SolverBasis.Degree + 1) * 2));
            int      maxNumberOfEdges = 4;

            edgesOfCell = new Edge[maxNumberOfEdges];
            for (int i = 0; i < maxNumberOfEdges; i++)
            {
                edgesOfCell[i] = new Edge(NodeGrid, GridDat);
            }

            DaRuleS         = this.GridDat.Grid.RefElements.Select(Kref => Kref.GetQuadratureRule(this.SolverBasis.Degree * 2)).ToArray();
            QuadNodesGlobal = DaRuleS.Select(rule => MultidimensionalArray.Create(rule.NoOfNodes, GridDat.SpatialDimension)).ToArray();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Uses <see cref="SubsonicPressureInlet"/> at the inlet and
        /// <see cref="SupersonicInlet"/> (Dirichlet) at the outlet
        /// </summary>
        /// <returns></returns>
        public static CNSControl[] EulerSubsonicPressureInletTest1D()
        {
            CNSControl[] templates = GetTemplates();

            foreach (CNSControl c in templates)
            {
                int divisions = (int)c.Paramstudy_CaseIdentification.Single(t => t.Item1 == "divisions").Item2;

                int noOfCells = (2 << divisions) * 8;
                c.GridFunc = delegate {
                    GridCommons grid = Grid1D.LineGrid(
                        GenericBlas.Linspace(0.0, Math.PI / 2.0 + 0.0, noOfCells + 1));
                    grid.EdgeTagNames.Add(1, "supersonicInlet");
                    grid.EdgeTagNames.Add(2, "subsonicPressureInlet");
                    grid.DefineEdgeTags(x => Math.Abs(x[0]) < 1e-14 ? (byte)2 : (byte)1);
                    return(grid);
                };
            }

            return(templates);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Test using <see cref="SupersonicInlet"/> (Dirichlet) everywhere
        /// </summary>
        /// <returns></returns>
        public static CNSControl[] EulerSupersonicInlet1D()
        {
            CNSControl[] templates = GetTemplates();

            foreach (CNSControl c in templates)
            {
                int divisions = (int)c.Paramstudy_CaseIdentification.Single(t => t.Item1 == "divisions").Item2;

                int noOfCells = (2 << divisions) * 8;
                c.GridFunc = delegate {
                    GridCommons grid = Grid1D.LineGrid(
                        GenericBlas.Linspace(0.0, Math.PI / 2.0 + 0.0, noOfCells + 1));
                    grid.EdgeTagNames.Add(1, "supersonicInlet");
                    grid.DefineEdgeTags(x => 1);
                    return(grid);
                };
                c.ProjectName += "_supersonicAll";
            }

            return(templates.ToArray());
        }
Ejemplo n.º 19
0
        public void AddDefaults()
        {
            Random rnd = new Random();

            Grid1D       d1         = new Grid1D(1, 2);
            Grid1D       d2         = new Grid1D(2, 2);
            V2DataOnGrid New_Grid   = new V2DataOnGrid("A", 3, d1, d1);
            V2DataOnGrid New_Grid_1 = new V2DataOnGrid("A", 3, d2, d2);

            New_Grid.InitRandom(3, 7);
            New_Grid_1.InitRandom(4, 8);

            V2DataCollection New_Coll = new V2DataCollection("B", 5);

            New_Coll.InitRandom(4, 4, 6, 4, 6);



            Main_Data.Add(New_Grid);
            Main_Data.Add(New_Grid_1);
            Main_Data.Add(New_Grid_1);
            Main_Data.Add(New_Coll);
        }
Ejemplo n.º 20
0
        private static CNSControl ShockTube_PartTest_Dynamic(int numOfCellsX, int numOfCellsY, int NoOfTimesteps, int NumberOfSubGrids, bool Repart, int RecInt)
        {
            CNSControl c = new CNSControl();

            int    dgDegree    = 0;
            double sensorLimit = 1e-4;
            bool   true1D      = false;
            bool   saveToDb    = false;

            //string dbPath = @"D:\Weber\BoSSS\test_db";
            string dbPath = null;

            c.DbPath   = dbPath;
            c.savetodb = dbPath != null && saveToDb;

            c.GridPartType = GridPartType.Hilbert;

            bool AV = false;

            double xMin = 0;
            double xMax = 1;
            double yMin = 0;
            double yMax = 1;

            c.ExplicitScheme = ExplicitSchemes.LTS;
            c.ExplicitOrder  = 1;

            c.NumberOfSubGrids     = NumberOfSubGrids;
            c.ReclusteringInterval = RecInt;
            c.FluxCorrection       = false;

            if (Repart)
            {
                // Add one balance constraint for each subgrid
                c.DynamicLoadBalancing_On             = true;
                c.DynamicLoadBalancing_CellClassifier = new LTSCellClassifier();
                c.DynamicLoadBalancing_CellCostEstimatorFactories.AddRange(LTSCellCostEstimator.Factory(c.NumberOfSubGrids));
                c.DynamicLoadBalancing_ImbalanceThreshold = 0.0;
                c.DynamicLoadBalancing_Period             = c.ReclusteringInterval;
            }

            c.GridFunc = delegate {
                double[] xNodes = GenericBlas.Linspace(xMin, xMax, numOfCellsX + 1);

                if (true1D)
                {
                    var grid = Grid1D.LineGrid(xNodes, periodic: false);
                    // Boundary conditions
                    grid.EdgeTagNames.Add(1, "AdiabaticSlipWall");

                    grid.DefineEdgeTags(delegate(double[] _X) {
                        return(1);
                    });
                    return(grid);
                }
                else
                {
                    double[] yNodes = GenericBlas.Linspace(yMin, yMax, numOfCellsY + 1);
                    var      grid   = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: false, periodicY: false);
                    // Boundary conditions
                    grid.EdgeTagNames.Add(1, "AdiabaticSlipWall");

                    grid.DefineEdgeTags(delegate(double[] _X) {
                        return(1);
                    });

                    return(grid);
                }
            };

            c.AddBoundaryValue("AdiabaticSlipWall");

            // Initial conditions
            c.InitialValues_Evaluators.Add(CompressibleVariables.Density, delegate(double[] X) {
                double x = X[0];

                if (true1D == false)
                {
                    double y = X[1];
                }

                if (x <= 0.5)
                {
                    return(1.0);
                }
                else
                {
                    return(0.125);
                }
            });
            c.InitialValues_Evaluators.Add(CNSVariables.Pressure, delegate(double[] X) {
                double x = X[0];

                if (true1D == false)
                {
                    double y = X[1];
                }

                if (x <= 0.5)
                {
                    return(1.0);
                }
                else
                {
                    return(0.1);
                }
            });
            c.InitialValues_Evaluators.Add(CNSVariables.Velocity.xComponent, X => 0.0);
            if (true1D == false)
            {
                c.InitialValues_Evaluators.Add(CNSVariables.Velocity.yComponent, X => 0.0);
            }


            if (AV)
            {
                c.ActiveOperators = Operators.Convection | Operators.ArtificialViscosity;
            }
            else
            {
                c.ActiveOperators = Operators.Convection;
            }
            c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC;

            // Shock-capturing
            double epsilon0 = 1.0;
            double kappa    = 0.5;

            if (AV)
            {
                Variable sensorVariable = CompressibleVariables.Density;
                c.CNSShockSensor         = new PerssonSensor(sensorVariable, sensorLimit);
                c.ArtificialViscosityLaw = new SmoothedHeavisideArtificialViscosityLaw(c.CNSShockSensor, dgDegree, sensorLimit, epsilon0, kappa);
            }

            c.EquationOfState = IdealGas.Air;

            c.MachNumber     = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio);
            c.ReynoldsNumber = 1.0;
            c.PrandtlNumber  = 0.71;

            c.AddVariable(CompressibleVariables.Density, dgDegree);
            c.AddVariable(CompressibleVariables.Momentum.xComponent, dgDegree);
            c.AddVariable(CompressibleVariables.Energy, dgDegree);
            if (true1D == false)
            {
                c.AddVariable(CompressibleVariables.Momentum.yComponent, dgDegree);
                c.AddVariable(CNSVariables.Velocity.yComponent, dgDegree);
                if (AV)
                {
                    c.AddVariable(CNSVariables.ArtificialViscosity, 2);
                }
            }
            else
            {
                if (AV)
                {
                    c.AddVariable(CNSVariables.ArtificialViscosity, 1);
                }
            }
            c.AddVariable(CNSVariables.Velocity.xComponent, dgDegree);
            c.AddVariable(CNSVariables.Pressure, dgDegree);
            c.AddVariable(CNSVariables.Entropy, dgDegree);
            c.AddVariable(CNSVariables.LocalMachNumber, dgDegree);
            c.AddVariable(CNSVariables.Rank, 0);

            c.AddVariable(CNSVariables.CFL, 0);
            c.AddVariable(CNSVariables.CFLConvective, 0);
            if (AV)
            {
                c.AddVariable(CNSVariables.CFLArtificialViscosity, 0);
            }
            if (c.ExplicitScheme.Equals(ExplicitSchemes.LTS))
            {
                c.AddVariable(CNSVariables.LTSClusters, 0);
            }


            // Time config
            c.dtMin       = 0.0;
            c.dtMax       = 1.0;
            c.CFLFraction = 0.3;
            c.Endtime     = 0.25;
            //c.dtFixed = 1.5e-3;
            c.NoOfTimesteps = NoOfTimesteps;


            c.ProjectName = String.Format("Shock tube {0} Repartitioning", (Repart ? "with" : "without"));
            if (true1D)
            {
                c.SessionName = String.Format("{3}, 1D, dgDegree = {0}, noOfCellsX = {1}, sensorLimit = {2:0.00E-00}", dgDegree, numOfCellsX, sensorLimit, c.ProjectName);
            }
            else
            {
                c.SessionName = String.Format("{9}, 2D, dgDegree = {0}, noOfCellsX = {1}, noOfCellsX = {2}, sensorLimit = {3:0.00E-00}, CFLFraction = {4:0.00E-00}, ALTS {5}/{6}, GridPartType {7}, NoOfCores {8}", dgDegree, numOfCellsX, numOfCellsY, sensorLimit, c.CFLFraction, c.ExplicitOrder, c.NumberOfSubGrids, c.GridPartType, ilPSP.Environment.MPIEnv.MPI_Size, c.ProjectName);
            }
            return(c);
        }
Ejemplo n.º 21
0
        public static IBM_Control IBMCylinderFlow(string _DbPath = null, int k = 2, bool xPeriodic = false, double VelXBase = 0.0)
        {
            IBM_Control C = new IBM_Control();

            const double BaseSize = 1.0;

            // basic database options
            // ====================

            C.savetodb           = false;
            C.ProjectDescription = "Cylinder";
            C.Tags.Add("with immersed boundary method");

            // DG degrees
            // ==========

            C.FieldOptions.Add("VelocityX", new FieldOpts()
            {
                Degree   = k,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("VelocityY", new FieldOpts()
            {
                Degree   = k,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("Pressure", new FieldOpts()
            {
                Degree   = k - 1,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("PhiDG", new FieldOpts()
            {
                Degree   = 2,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("Phi", new FieldOpts()
            {
                Degree   = 2,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });

            // grid and boundary conditions
            // ============================

            C.GridFunc = delegate {
                var _xNodes1 = Grid1D.TanhSpacing(0, 1, 5, 1, false);
                _xNodes1 = _xNodes1.GetSubVector(0, (_xNodes1.Length - 1));
                var _xNodes2 = GenericBlas.Linspace(1, 5.5, 35);
                _xNodes2 = _xNodes2.GetSubVector(0, (_xNodes2.Length - 1));
                var _xNodes3 = Grid1D.TanhSpacing(5.5, 22, 20, 1.3, true);

                var xNodes = ArrayTools.Cat(_xNodes1, _xNodes2, _xNodes3);


                var _yNodes1 = Grid1D.TanhSpacing(0, 1, 5, 1.2, false);
                _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1));
                var _yNodes2 = GenericBlas.Linspace(1, 3, 20);
                _yNodes2 = _yNodes2.GetSubVector(0, (_yNodes2.Length - 1));
                var _yNodes3 = Grid1D.TanhSpacing(3, 4.1, 5, 1.2, true);

                var yNodes = ArrayTools.Cat(_yNodes1, _yNodes2, _yNodes3);

                var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: xPeriodic);
                grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
                grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
                if (!xPeriodic)
                {
                    grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
                    grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
                }

                grd.DefineEdgeTags(delegate(double[] X) {
                    byte et = 0;
                    if (Math.Abs(X[1] - (0 * BaseSize)) <= 1.0e-8)
                    {
                        et = 1;
                    }
                    if (Math.Abs(X[1] + (-4.1 * BaseSize)) <= 1.0e-8)
                    {
                        et = 2;
                    }
                    if (!xPeriodic && Math.Abs(X[0] - (0 * BaseSize)) <= 1.0e-8)
                    {
                        et = 3;
                    }
                    if (!xPeriodic && Math.Abs(X[0] + (-22 * BaseSize)) <= 1.0e-8)
                    {
                        et = 4;
                    }


                    Debug.Assert(et != 0);
                    return(et);
                });

                return(grd);
            };

            C.AddBoundaryCondition("Velocity_Inlet_upper", "VelocityX", X => 0);
            C.AddBoundaryCondition("Velocity_Inlet_lower", "VelocityX", X => 0);
            if (!xPeriodic)
            {
                C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX", X => (4 * 1.5 * X[1] * (4.1 - X[1]) / (4.1 * 4.1)));
            }
            C.AddBoundaryCondition("Pressure_Outlet_right");

            // Initial Values
            // ==============

            C.particleRadius = 0.5;

            C.InitialValues_Evaluators.Add("Phi", X => - (X[0] - 2).Pow2() + -(X[1] - 2).Pow2() + C.particleRadius.Pow2());


            C.InitialValues_Evaluators.Add("VelocityX", X => 0);


            // Physical Parameters
            // ===================

            C.PhysicalParameters.mu_A  = 0.05;
            C.PhysicalParameters.rho_A = 1;

            C.PhysicalParameters.IncludeConvection = true;
            C.PhysicalParameters.Material          = true;

            // misc. solver options
            // ====================

            C.AdvancedDiscretizationOptions.PenaltySafety = 1;
            C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.1;
            C.LevelSetSmoothing        = false;
            C.MaxKrylovDim             = 20;
            C.MaxSolverIterations      = 100;
            C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;
            C.NoOfMultigridLevels      = 1;

            // Timestepping
            // ============

            C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.BDF2;
            double dt = 1E20;

            C.dtFixed       = dt;
            C.dtMax         = dt;
            C.dtMin         = dt;
            C.Endtime       = 200;
            C.NoOfTimesteps = 1;

            // haben fertig...
            // ===============

            return(C);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// See also <see cref="GRID_CASE"/> and <see cref="GRID_FILE"/>.
        /// </summary>
        protected override GridCommons CreateOrLoadGrid()
        {
            GridCommons grd;

            switch (GRID_CASE)
            {
            case 1:
                grd = Grid1D.LineGrid(GenericBlas.Linspace(-4, 4, 5));
                break;


            case 2: {
                grd = Grid1D.LineGrid(GenericBlas.Linspace(-4, 4, 20));
                break;
            }

            case 3: {
                double[] xnodes = new double[] { -2, 0, 2 };
                double[] ynodes = new double[] { -2, 0, 2 };
                double   dx     = xnodes[1] - xnodes[0];
                double   dy     = ynodes[1] - ynodes[0];
                //this.CellVolume = dx * dy;
                //if(Math.Abs(dx - dy) <= 1.0e-12)
                //    EdgeArea = dx;
                grd = Grid2D.Cartesian2DGrid(xnodes, ynodes, periodicX: false, periodicY: false, type: CellType.Square_4);
                break;
            }

            case 4: {
                double[] xnodes = GenericBlas.Linspace(-1, 5, 9);
                double[] ynodes = GenericBlas.Linspace(-1, 5, 13);
                double   dx     = xnodes[1] - xnodes[0];
                double   dy     = ynodes[1] - ynodes[0];
                this.CellVolume = dx * dy;
                if (Math.Abs(dx - dy) <= 1.0e-12)
                {
                    EdgeArea = dx;
                }
                grd = Grid2D.Cartesian2DGrid(xnodes, ynodes, periodicX: false, periodicY: false, type: CellType.Square_4);
                break;
            }

            case 5: {
                double[] xnodes = GenericBlas.Linspace(-1, 1, 8);
                double[] ynodes = GenericBlas.Linspace(-1, 1, 13);
                grd = Grid2D.UnstructuredTriangleGrid(xnodes, ynodes, JitterScale: 0.5);
                break;
            }

            case 6: {
                grd = Circle();
                break;
            }

            case 7: {
                // test periodicity

                grd       = Grid2D.CurvedSquareGrid(GenericBlas.Linspace(1, 2, 4), GenericBlas.Linspace(0, 0.25, 10), CellType.Square_9, PeriodicS: true);
                AltRefSol = true;
                break;
            }

            case 8: {
                double[] rNodes = GenericBlas.Linspace(1, 4, 8);
                double[] sNodes = GenericBlas.Linspace(0, 0.5, 15);
                grd = Grid2D.CurvedSquareGrid(rNodes, sNodes, CellType.Square_4, PeriodicS: false);
                break;
            }

            case 9: {
                double[] xNodes1 = GenericBlas.Linspace(-1, 0.3, 7);
                double[] yNodes1 = GenericBlas.Linspace(-1, 1, 13);
                double[] xNodes2 = GenericBlas.Linspace(0.3, 1, 5);
                double[] yNodes2 = GenericBlas.Linspace(-1, 1, 25);
                double[] xNodes3 = GenericBlas.Linspace(-1, 1, 8);
                double[] yNodes3 = GenericBlas.Linspace(-2, -1, 5);

                var grd1 = Grid2D.Cartesian2DGrid(xNodes1, yNodes1, type: CellType.Square_Linear);
                var grd2 = Grid2D.Cartesian2DGrid(xNodes2, yNodes2, type: CellType.Square_Linear);
                var grd3 = Grid2D.Cartesian2DGrid(xNodes3, yNodes3, type: CellType.Square_Linear);
                var grdJ = GridCommons.MergeLogically(grd1, GridCommons.MergeLogically(grd2, grd3));
                grd = GridCommons.Seal(grdJ, 4);

                break;
            }

            case 10: {
                double[] xNodes1 = GenericBlas.Linspace(-1, 0.3, 4);
                double[] xNodes2 = GenericBlas.Linspace(0.3, 1, 5);

                double[] yNodes1 = GenericBlas.Linspace(-1, 1, 9);
                double[] yNodes2 = GenericBlas.Linspace(-1, 1, 5);

                double[] zNodes1 = GenericBlas.Linspace(-1, 1, 5);
                double[] zNodes2 = GenericBlas.Linspace(-1, 1, 3);

                var grd1 = Grid3D.Cartesian3DGrid(xNodes1, yNodes1, zNodes1);
                var grd2 = Grid3D.Cartesian3DGrid(xNodes2, yNodes2, zNodes2);
                var grdJ = GridCommons.MergeLogically(grd1, grd2);
                grd = GridCommons.Seal(grdJ, 4);


                break;
            }

            case 11: {
                grd = Grid2D.Trapezoidal2dGrid(4, 2, 2, GenericBlas.Linspace(0, 1, 2));
                break;
            }

            case 12: {
                var grid1 = Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-3, 5, 5), GenericBlas.Linspace(-1, 1, 2));
                //grd = base_grid;
                //grid1.Plot2DGrid();


                var gdat1 = new GridData(grid1);
                var grid2 = gdat1.Adapt(new int[] { 1, 2 }, null, out GridCorrelation o2c_1);
                //grid2.Plot2DGrid();

                var gdat2 = new GridData(grid2);
                var grid3 = gdat2.Adapt(new int[] { 2, 4 }, null, out GridCorrelation o2c_2);
                //grid3.Plot2DGrid();

                var gdat3 = new GridData(grid3);
                var grid4 = gdat3.Adapt(new int[] { 11, 14, 15 }, null, out GridCorrelation o2c_3);
                //grid4.Plot2DGrid();

                var gdat4 = new GridData(grid4);
                var grid5 = gdat4.Adapt(new[] { 4, 21, 22, 10 }, new[] { new[] { 13, 14, 15, 16 } }, out GridCorrelation o2c_4);

                //grid5.Plot2DGrid();

                grd = grid5;

                break;
            }

            case 13: {
                double[] rNodes = GenericBlas.Linspace(1, 4, 8);
                double[] sNodes = GenericBlas.Linspace(0, 0.5, 15);
                grd = Grid2D.CurvedSquareGrid(rNodes, sNodes, CellType.Square_9, PeriodicS: false);
                break;
            }

            case 14: {
                double[] rNodes = GenericBlas.Linspace(1, 4, 13);
                double[] sNodes = GenericBlas.Linspace(0, 0.5, 25);
                grd = Grid2D.CurvedSquareGrid(rNodes, sNodes, CellType.Square_16, PeriodicS: false);
                break;
            }

            case 15: {
                double[] rNodes = GenericBlas.Linspace(1, 2, 4);
                double[] sNodes = GenericBlas.Linspace(0, 0.5, 4);
                double[] zNodes = GenericBlas.Linspace(-1, 1, 5);
                grd = Grid3D.CylinderGrid(rNodes, sNodes, zNodes, CellType.Cube_27, PeriodicS: false, PeriodicZ: false);
                break;
            }

            case 16: {
                grd = Grid2D.Ogrid(0.5, 1, 5, 3, CellType.Square_4);
                break;
            }

            case 17: {
                grd = Grid3D.Ogrid(0.5, 1, 3, 3, GenericBlas.Linspace(0, 4, 3));
                break;
            }

            case 18: {
                // aggregation grid
                double[] xNodes = GenericBlas.Linspace(-1, 1, 5);
                double[] yNodes = GenericBlas.Linspace(-1, 1, 5);

                var baseGrid = Grid2D.UnstructuredTriangleGrid(xNodes, yNodes);
                var baseGdat = new GridData(baseGrid);
                var aggGrid  = CoarseningAlgorithms.Coarsen(baseGdat, 2);
                base.AggGrid = aggGrid;
                grd          = null;

                double dx = xNodes[1] - xNodes[0];
                double dy = yNodes[1] - yNodes[0];
                this.CellVolume = dx * dy;
                if (Math.Abs(dx - dy) <= 1.0e-12)
                {
                    EdgeArea = dx;
                }


                break;
            }

            // ++++++++++++++++++++++++++++++++++++++++++++++++++++
            // more expensive grids (not tested in DEBUG MODE)
            // ++++++++++++++++++++++++++++++++++++++++++++++++++++

            case 30: {
                double[] xnodes = GenericBlas.Linspace(-1, 1, 7);
                double[] ynodes = GenericBlas.Linspace(-1, 1, 9);
                double[] znodes = GenericBlas.Linspace(-1, 1, 8);
                grd = Grid3D.Cartesian3DGrid(xnodes, ynodes, znodes, periodicX: false, periodicY: false, periodicZ: false);
                break;
            }



            // +++++++++++++++++++++++++++++++++
            // grids imported from GMSH/CGNS
            // +++++++++++++++++++++++++++++++++

            case 50: {
                // gmsh grid import test

                Console.WriteLine("Loading file: '" + GRID_FILE + "'...");
                grd = GridImporter.Import(GRID_FILE);
                //Console.WriteLine("done. " + grd.NoOfUpdateCells.MPISum() + " cells loaded.");

                //Plot2dGridGnuplot(grd);

                HashSet <CellType> cellTypes = new HashSet <CellType>();
                foreach (var cell in grd.Cells)
                {
                    if (!cellTypes.Contains(cell.Type))
                    {
                        cellTypes.Add(cell.Type);
                    }
                }
                Console.Write("Cell types: ");
                foreach (var ct in cellTypes)
                {
                    Console.Write(ct);
                    Console.Write(" ");
                }
                Console.WriteLine();


                break;
            }

            default:
                throw new NotSupportedException();
            }
            return(grd);
        }
Ejemplo n.º 23
0
        static public IBM_Control IBMCylinderFlow(string _DbPath = null, int k = 2, bool only_channel = true, bool pardiso = true, int no_p = 1, int no_it = 1, bool load_Grid = false, string _GridGuid = null)
        {
            // int cells_x, int cells_yz
            IBM_Control  C         = new IBM_Control();
            bool         xPeriodic = false;
            int          i         = 2;
            const double BaseSize  = 1.0;

            // basic database options
            // ======================

            //C.DbPath = _DbPath;

            C.DbPath   = @"\\dc1\userspace\stange\HiWi_database\PerformanceTests";
            C.savetodb = true;

            bool   restart            = false;
            string restartSession     = "67a29dcc-ade9-4704-b198-b3380e774f5a";
            string restartGrid        = "42e1ede0-40fc-4267-9d48-94c0397ac9a5";
            bool   startFromGivenGrid = true;
            string startGrid          = "42e1ede0-40fc-4267-9d48-94c0397ac9a5";

            switch (i)
            {
            case 1:
                C.MeshFactor = 1.258;     // was 1.33
                break;

            case 2:
                C.MeshFactor = 3.0;     //1.77; //0.92;
                break;

            case 3:
                C.MeshFactor = 0.7;     // was 07
                break;

            default:

                throw new ApplicationException();
            }

            if (pardiso)
            {
                if (only_channel)
                {
                    C.SessionName = "2DChannel_Pardiso_k" + k + "_MeshFactor" + C.MeshFactor + "_no_p" + no_p + "_run" + no_it;
                }
                else
                {
                    C.SessionName = "Cylinder_Pardiso_k" + k + "_MeshFactor" + C.MeshFactor + "_no_p" + no_p + "_run" + no_it;
                }
            }
            else
            {
                if (only_channel)
                {
                    C.SessionName = "2DChannel_Mumps_k" + k + "_MeshFactor" + C.MeshFactor + "_no_p" + no_p + "_run" + no_it;
                }
                else
                {
                    C.SessionName = "Cylinder_Mumps_k" + k + "_MeshFactor" + C.MeshFactor + "_no_p" + no_p + "_run" + no_it;
                }
            }
            C.saveperiod = 1;
            //C.SessionName = "Sphere_k" + k + "_h" + h+"Re100";


            C.Tags.Add("Pardiso " + pardiso);
            C.Tags.Add("only channel " + only_channel);
            C.Tags.Add("k " + k);
            C.Tags.Add("no_p" + no_p);
            C.Tags.Add("run " + no_it);
            C.Tags.Add("MeshFactor " + C.MeshFactor);

            C.ProjectName = "FixedCylinderRe100_k" + i + "_CellAgglo02_penalty4_newMesh2";

            C.ProjectDescription = "Cylinder";

            // DG degrees
            // ==========

            C.FieldOptions.Add("VelocityX", new FieldOpts()
            {
                Degree   = k,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("VelocityY", new FieldOpts()
            {
                Degree   = k,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            //Console.WriteLine("Achtung: equal order!!!!");
            C.FieldOptions.Add("Pressure", new FieldOpts()
            {
                Degree = k - 1,

                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("PhiDG", new FieldOpts()
            {
                Degree   = 2,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("Phi", new FieldOpts()
            {
                Degree   = 2,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });

            // restart options
            // ===============
            if (restart)
            {
                C.RestartInfo = new Tuple <Guid, TimestepNumber>(new Guid(restartSession), -1);
                C.GridGuid    = new Guid(restartGrid);
            }
            //grid and boundary conditions
            // ============================

            // Initial Values
            // ==============

            double radius = 0.5;

            C.PhysicalParameters.rho_A = 1.0;
            C.PhysicalParameters.mu_A  = 1.0 / 100.0;

            if (!restart)
            {
                if (!startFromGivenGrid)
                {
                    C.GridFunc = delegate
                    {
                        var _xNodes1 = Grid1D.TanhSpacing(-2.0, -1.0, Convert.ToInt32(10.0 * C.MeshFactor), 0.5, false); //10
                        _xNodes1 = _xNodes1.GetSubVector(0, (_xNodes1.Length - 1));
                        var _xNodes2 = GenericBlas.Linspace(-1.0, 2.0, Convert.ToInt32(35.0 * C.MeshFactor));            //35
                        _xNodes2 = _xNodes2.GetSubVector(0, (_xNodes2.Length - 1));
                        var _xNodes3 = Grid1D.TanhSpacing(2.0, 20.0, Convert.ToInt32(60.0 * C.MeshFactor), 1.5, true);   //60

                        var xNodes = ArrayTools.Cat(_xNodes1, _xNodes2, _xNodes3);


                        var _yNodes1 = Grid1D.TanhSpacing(-2.0, -1.0, Convert.ToInt32(7.0 * C.MeshFactor), 0.9, false); //7
                        _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1));
                        var _yNodes2 = GenericBlas.Linspace(-1.0, 1.0, Convert.ToInt32(25.0 * C.MeshFactor));           //25
                        _yNodes2 = _yNodes2.GetSubVector(0, (_yNodes2.Length - 1));
                        var _yNodes3 = Grid1D.TanhSpacing(1.0, 2.1, Convert.ToInt32(7.0 * C.MeshFactor), 1.1, true);    //7
                        var yNodes   = ArrayTools.Cat(_yNodes1, _yNodes2, _yNodes3);



                        //double[] xNodes = GenericBlas.Linspace(0 * BaseSize, 22 * BaseSize, 25);
                        //double[] yNodes = GenericBlas.Linspace(0 * BaseSize, 4.1 * BaseSize, 25);
                        var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: xPeriodic);
                        grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
                        grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
                        if (!xPeriodic)
                        {
                            grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
                            grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
                        }

                        grd.DefineEdgeTags(delegate(double[] X)
                        {
                            byte et = 0;
                            if (Math.Abs(X[1] - (-2.0 * BaseSize)) <= 1.0e-8)
                            {
                                et = 1;
                            }
                            if (Math.Abs(X[1] - (+2.1 * BaseSize)) <= 1.0e-8)
                            {
                                et = 2;
                            }
                            if (!xPeriodic && Math.Abs(X[0] - (-2.0 * BaseSize)) <= 1.0e-8)
                            {
                                et = 3;
                            }
                            if (!xPeriodic && Math.Abs(X[0] - (+20.0 * BaseSize)) <= 1.0e-8)
                            {
                                et = 4;
                            }


                            Debug.Assert(et != 0);
                            return(et);
                        });

                        Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

                        return(grd);
                    };
                }
                else
                {
                    C.GridGuid = new Guid(startGrid);
                }
                if (only_channel)
                {
                    C.InitialValues_Evaluators.Add("Phi", X => - 1);
                }
                else
                {
                    C.InitialValues_Evaluators.Add("Phi", X => - (X[0]).Pow2() + -(X[1]).Pow2() + radius.Pow2());
                }


                //C.InitialValues.Add("Phi", X => -1);

                C.InitialValues_Evaluators.Add("VelocityX", X => 4.0 * 1.5 * (X[1] + 2.0) * (4.1 - (X[1] + 2.0)) / (4.1 * 4.1));
            }

            //C.GridFunc = delegate {

            //    // Box1
            //    var box1_p1 = new double[2] { -2, -2 };
            //    var box1_p2 = new double[2] { 20, 2.1 };
            //    var box1 = new GridBox(box1_p1, box1_p2, 46, 20); //k1: 70,25 ; k2: 46,20 ; k3: 35,15

            //    // Box2
            //    var box2_p1 = new double[2] { -2, -2 };
            //    var box2_p2 = new double[2] { 3, 2.1 };
            //    var box2 = new GridBox(box2_p1, box2_p2, 26, 40); //k1: 40,50 ; k2: 26,40; k3: 20, 30

            //    // Box3
            //    var box3_p1 = new double[2] { -2, -1 };
            //    var box3_p2 = new double[2] { 1, 1 };
            //    var box3 = new GridBox(box3_p1, box3_p2, 32, 38); //k1: 48,58  ; k2: 32,38; k3: 24, 30

            //    // Box4
            //    var box4_p1 = new double[2] { -0.7, -0.72 };
            //    var box4_p2 = new double[2] { 0.7, 0.7 };
            //    var box4 = new GridBox(box4_p1, box4_p2, 30, 56); //k1: 44,84  ; k2: 30,56; k3: 22, 42

            //    var grd = Grid2D.HangingNodes2D(box1, box2, box3,box4);

            //    grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
            //    grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
            //    if (!xPeriodic) {
            //        grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
            //        grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
            //    }

            //    grd.DefineEdgeTags(delegate (double[] X) {
            //        byte et = 0;
            //        if (Math.Abs(X[1] - (-2 * BaseSize)) <= 1.0e-8)
            //            et = 1;
            //        if (Math.Abs(X[1] - (+2.1 * BaseSize)) <= 1.0e-8)
            //            et = 2;
            //        if (!xPeriodic && Math.Abs(X[0] - (-2 * BaseSize)) <= 1.0e-8)
            //            et = 3;
            //        if (!xPeriodic && Math.Abs(X[0] - (+20.0 * BaseSize)) <= 1.0e-8)
            //            et = 4;


            //        Debug.Assert(et != 0);
            //        return et;
            //    });

            //    Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

            //    return grd;
            //};

            C.AddBoundaryCondition("Velocity_Inlet_upper", "VelocityX", X => 0.0);
            C.AddBoundaryCondition("Velocity_Inlet_lower", "VelocityX", X => 0.0); //-(4 * 1.5 * X[1] * (4.1 - X[1]) / (4.1 * 4.1))
            if (!xPeriodic)
            {
                C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX", X => (4.0 * 1.5 * (X[1] + 2.0) * (4.1 - (X[1] + 2.0)) / (4.1 * 4.1)));
                //C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX#A", X => 1);
            }
            C.AddBoundaryCondition("Pressure_Outlet_right");



            //C.InitialValues.Add("Phi", X => phi(X, 0));

            //C.InitialValues.Add("Phi", X => ((X[0] / (radius * BaseSize)) - mPx) * (X[0] / (radius * BaseSize)) - mPx) + ((X[1]) / (radius * BaseSize)) - 2.)Pow2() - radius.Pow2()));  // quadratic form
            //    );


            //C.InitialValues.Add("VelocityX", delegate (double[] X)
            //{
            //    double x = X[0];
            //    double y = X[1];

            //    double R = Math.Sqrt((x + 1).Pow2() + y.Pow2());

            //    double xVel = 0;

            //    if (R < 0.75)
            //    {
            //        xVel = 1;
            //    }
            //    return xVel;
            //});

            //C.InitialValues.Add("VelocityY", delegate (double[] X) {
            //    double x = X[0];
            //    double y = X[1];

            //    double R = Math.Sqrt((x + 1).Pow2() + (y).Pow2());

            //    double yVel = 0;

            //    if (R < 0.75) {
            //        yVel = 1;
            //    }
            //    return yVel;
            //});

            // For restart
            //C.RestartInfo = new Tuple<Guid, TimestepNumber>(new Guid("8f5cfed9-31c7-4be8-aa56-e92e5348e08b"), 95);
            //C.GridGuid = new Guid("71ffc0c4-66aa-4762-b07e-45385f34b03f");

            // Physical Parameters
            // ===================


            C.PhysicalParameters.IncludeConvection = true;


            // misc. solver options
            // ====================

            C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2;
            C.AdvancedDiscretizationOptions.PenaltySafety = 4;
            C.LevelSetSmoothing = false;
            //C.option_solver = "direct";
            C.MaxKrylovDim             = 20;
            C.MaxSolverIterations      = 50;
            C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;
            //C.NoOfMultigridLevels = 0;

            if (pardiso)
            {
                C.whichSolver = DirectSolver._whichSolver.PARDISO;
            }
            else
            {
                C.whichSolver = DirectSolver._whichSolver.MUMPS;
            }
            // Timestepping
            // ============

            C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.BDF2;
            double dt = 0.1;

            C.dtMax         = dt;
            C.dtMin         = dt;
            C.Endtime       = 70;
            C.NoOfTimesteps = 10;

            // haben fertig...
            // ===============
            return(C);
        }
Ejemplo n.º 24
0
        public static IBMControl IBMNACA0012(int MeshPara, int dgDegree, double CFL, double agglomeration, double alpha)
        {
            IBMControl c = new IBMControl();

            // Solver Settings
            c.dtMin         = 0.0;
            c.dtMax         = 1.0;
            c.Endtime       = 1000.0;
            c.CFLFraction   = CFL;
            c.NoOfTimesteps = 200000;

            c.PrintInterval = 10;
            //c.ResidualInterval = 100;
            //c.ResidualLoggerType = ResidualLoggerTypes.ChangeRate | ResidualLoggerTypes.Query;
            //c.ResidualBasedTerminationCriteria.Add("changeRate_L2_abs_rhoE", 1E-8);

            //IBM Settings
            c.LevelSetBoundaryTag     = "AdiabaticSlipWall";
            c.LevelSetQuadratureOrder = 2 * dgDegree + 2;
            c.AgglomerationThreshold  = agglomeration;

            // NEXT STEP: SET THIS BOOL TO FALSE AND JUST USE IN POSITIVE SUB_VOLUME;
            // THEN TRY BOUNDING BOX APPROACH?
            // WHY THE HELL DOES THIS CONFIGURATION FAIL!??!?!?!?
            c.CutCellQuadratureType             = XQuadFactoryHelper.MomentFittingVariants.Classic;
            c.SurfaceHMF_ProjectNodesToLevelSet = false;
            c.SurfaceHMF_RestrictNodes          = true;
            c.SurfaceHMF_UseGaussNodes          = false;
            c.VolumeHMF_NodeCountSafetyFactor   = 3.0;
            c.VolumeHMF_RestrictNodes           = true;
            c.VolumeHMF_UseGaussNodes           = false;

            //Guid restart = new Guid("cd061fe3-3215-483a-8790-f6fd686d6676");
            //c.RestartInfo = new Tuple<Guid, BoSSS.Foundation.IO.TimestepNumber>(restart, -1);

            // Session Settings
            //c.DbPath = @"\\fdyprime\userspace\kraemer-eis\FDY-Cluster\dbe_NACA\";
            c.savetodb           = false;
            c.saveperiod         = 10000;
            c.ProjectName        = "MeshPara:" + MeshPara + "_CFL=" + c.CFLFraction + "_p=" + dgDegree + "_agg=" + c.AgglomerationThreshold + "_alpha=" + alpha + "_HMF=" + c.CutCellQuadratureType;
            c.ProjectDescription = "NACA0012 Steady Test with Ma=0.5";
            c.Tags.Add("NACA0012");
            c.Tags.Add("IBM Test");
            c.Tags.Add("steady");

            // Solver Type
            c.DomainType         = DomainTypes.StaticImmersedBoundary;
            c.ActiveOperators    = Operators.Convection;
            c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC;

            // Time-Stepping Settings
            c.ExplicitScheme = ExplicitSchemes.RungeKutta;
            c.ExplicitOrder  = 1;

            //Material Settings
            c.EquationOfState = IdealGas.Air;
            c.MachNumber      = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio);

            // Primary CNSVariables
            c.AddVariable(CompressibleVariables.Density, dgDegree);
            c.AddVariable(CompressibleVariables.Momentum.xComponent, dgDegree);
            c.AddVariable(CompressibleVariables.Momentum.yComponent, dgDegree);
            c.AddVariable(CompressibleVariables.Energy, dgDegree);

            c.AddVariable(IBMVariables.LevelSet, 8);

            // Refined Region
            double xBegin = -0.012;
            double xEnd   = 1.01;

            c.GridFunc = delegate {
                int chords = 100;

                int xleft   = -chords;
                int xRight  = chords;
                int yBottom = -chords;
                int yTop    = chords;

                double spacingFactor = 3.95;

                double[] xnodes1 = Grid1D.TanhSpacing(xleft, xBegin, MeshPara + 1, spacingFactor, false);
                double[] xnodes2 = Grid1D.TanhSpacing_DoubleSided(xBegin, xEnd, MeshPara + 1, 2.0);
                double[] xnodes3 = Grid1D.TanhSpacing(xEnd, xRight, MeshPara + 1, spacingFactor, true);

                double[] xComplete = new double[xnodes1.Length + xnodes2.Length + xnodes3.Length - 2];
                for (int i = 0; i < xnodes1.Length; i++)
                {
                    xComplete[i] = xnodes1[i];
                }
                for (int i = 1; i < xnodes2.Length; i++)
                {
                    xComplete[i + xnodes1.Length - 1] = xnodes2[i];
                }
                for (int i = 1; i < xnodes3.Length; i++)
                {
                    xComplete[i + xnodes1.Length + xnodes2.Length - 2] = xnodes3[i];
                }

                double yrefinedTop    = 0.2;
                double yrefinedBottom = -0.2;

                double[] ynodes1 = Grid1D.TanhSpacing(yBottom, yrefinedBottom, MeshPara + 1, spacingFactor, false);
                double[] ynodes2 = GenericBlas.Linspace(yrefinedBottom, yrefinedTop, (int)(0.75 * MeshPara) + 1);
                double[] ynodes3 = Grid1D.TanhSpacing(yrefinedTop, yTop, MeshPara + 1, spacingFactor, true);

                double[] yComplete = new double[ynodes1.Length + ynodes2.Length + ynodes3.Length - 2];
                for (int i = 0; i < ynodes1.Length; i++)
                {
                    yComplete[i] = ynodes1[i];
                }
                for (int i = 1; i < ynodes2.Length; i++)
                {
                    yComplete[i + ynodes1.Length - 1] = ynodes2[i];
                }
                for (int i = 1; i < ynodes3.Length; i++)
                {
                    yComplete[i + ynodes1.Length + ynodes2.Length - 2] = ynodes3[i];
                }

                int numOfCellsX = (xRight - xleft) * MeshPara;
                int numOfCellsY = (yTop - yBottom) * MeshPara;

                GridCommons grid = Grid2D.Cartesian2DGrid(xComplete, yComplete);

                grid.EdgeTagNames.Add(1, "supersonicinlet");
                grid.EdgeTagNames.Add(2, "AdiabaticSlipWall");
                grid.DefineEdgeTags((Vector X) => 1);
                grid.Name = "[" + xleft + "," + xRight + "]x[" + yBottom + "," + yTop + "]_Cells:(" + (xComplete.Length - 1) + "x" + (yComplete.Length - 1) + ")";

                return(grid);
            };

            // Functions
            Func <double[], double, double> rho      = (X, t) => 1.0;
            Func <double[], double, double> u0       = (X, t) => 1.0;
            Func <double[], double, double> u1       = (X, t) => 0.0;
            Func <double[], double, double> pressure = (X, t) => 2.8571428571428;

            Func <double[], double> test = X => 1 - 0.05 * 0.4 / 1.4 * Math.Pow(Math.Exp(1 - X[0] * X[0] - X[1] * X[1]), (1 / 0.4));

            Func <double[], double, double> levelSet = delegate(double[] X, double t) {
                double value = 0.0;

                double radian = alpha * Math.PI / 180;

                double xRotated = 1 + Math.Cos(radian) * (X[0] - 1) - Math.Sin(radian) * (X[1]);
                double yRotated = Math.Sin(radian) * (X[0] - 1) + Math.Cos(radian) * (X[1]);

                double a = 0.6;
                //double b = 0.2969;
                double c1 = 0.126;
                double d  = 0.3516;
                double e  = 0.2843;
                double f  = 0.1036;


                if (yRotated >= 0.0 || (X[0] > 0.562875 && X[1] > 0))
                {
                    //if (yRotated >= 0.0 ){
                    value = Math.Pow((yRotated + a * (c1 * xRotated + d * Math.Pow(xRotated, 2) - e * Math.Pow(xRotated, 3) + f * Math.Pow(xRotated, 4))), 2) - 0.0317338596 * xRotated;
                }
                else
                {
                    value = Math.Pow((-yRotated + a * (c1 * xRotated + d * Math.Pow(xRotated, 2) - e * Math.Pow(xRotated, 3) + f * Math.Pow(xRotated, 4))), 2) - 0.0317338596 * xRotated;
                }

                //value = yRotated - Math.Tan(radian)*xRotated;

                return(value);
            };

            c.LevelSetFunction = levelSet;

            //Initial Values
            c.InitialValues_Evaluators.Add(CompressibleVariables.Density, X => rho(X, 0.0));
            c.InitialValues_Evaluators.Add(CNSVariables.Velocity.xComponent, X => u0(X, 0.0));
            c.InitialValues_Evaluators.Add(CNSVariables.Velocity.yComponent, X => u1(X, 0.0));
            c.InitialValues_Evaluators.Add(CNSVariables.Pressure, X => pressure(X, 0.0));

            //BoundaryConditions
            c.AddBoundaryValue("AdiabaticSlipWall");
            c.AddBoundaryValue("supersonicInlet", CompressibleVariables.Density, rho);
            c.AddBoundaryValue("supersonicInlet", CNSVariables.Velocity.xComponent, u0);
            c.AddBoundaryValue("supersonicInlet", CNSVariables.Velocity.yComponent, u1);
            c.AddBoundaryValue("supersonicInlet", CNSVariables.Pressure, pressure);

            // Queries
            //c.Queries.Add("L2ErrorEntropy", IBMQueries.L2Error(state => state.Entropy, (X, t) => 2.8571428571428));
            //c.Queries.Add("IBMDragForce", IBMQueries.IBMDragForce());
            //c.Queries.Add("IBMLiftForce", IBMQueries.IBMLiftForce());
            return(c);
        }
        private static CNSControl ShockTubeToro1Template(int dgDegree, ExplicitSchemes explicitScheme, int explicitOrder, int noOfCells = 50, double gridStretching = 0.0, bool twoD = false)
        {
            double densityLeft           = 1.0;
            double velocityLeft          = 0.0;
            double pressureLeft          = 1.0;
            double densityRight          = 0.125;
            double velocityRight         = 0.0;
            double pressureRight         = 0.1;
            double discontinuityPosition = 0.5;

            CNSControl c = new CNSControl();

            c.DbPath = null;
            //c.DbPath = @"c:\bosss_db\";
            c.savetodb = false;

            c.ActiveOperators    = Operators.Convection;
            c.ConvectiveFluxType = ConvectiveFluxTypes.OptimizedHLLC;

            c.EquationOfState = IdealGas.Air;
            c.MachNumber      = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio);
            c.ReynoldsNumber  = 1.0;
            c.PrandtlNumber   = 0.71;

            c.ExplicitScheme = explicitScheme;
            c.ExplicitOrder  = explicitOrder;

            c.AddVariable(CompressibleVariables.Density, dgDegree);
            c.AddVariable(CompressibleVariables.Momentum.xComponent, dgDegree);
            c.AddVariable(CompressibleVariables.Energy, dgDegree);
            c.AddVariable(CNSVariables.Velocity.xComponent, dgDegree);
            c.AddVariable(CNSVariables.Pressure, dgDegree);
            c.AddVariable(CNSVariables.Rank, 0);

            c.GridFunc = delegate {
                double xMin = 0.0;
                double xMax = 1.0;
                double yMin = 0.0;
                double yMax = 1.0;

                double[] xNodes;
                double[] yNodes;
                if (gridStretching > 0.0)
                {
                    xNodes = Grid1D.TanhSpacing(xMin, xMax, noOfCells + 1, gridStretching, true);
                    yNodes = Grid1D.TanhSpacing(yMin, yMax, 1 + 1, gridStretching, true);
                }
                else
                {
                    xNodes = GenericBlas.Linspace(xMin, xMax, noOfCells + 1);
                    yNodes = GenericBlas.Linspace(yMin, yMax, 1 + 1);
                }

                GridCommons grid;
                if (twoD)
                {
                    grid = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: false, periodicY: false);
                }
                else
                {
                    grid = Grid1D.LineGrid(xNodes, periodic: false);
                }

                // Boundary conditions
                grid.EdgeTagNames.Add(1, "AdiabaticSlipWall");
                grid.DefineEdgeTags(delegate(double[] _X) {
                    return(1);
                });
                return(grid);
            };
            c.AddBoundaryValue("AdiabaticSlipWall");

            Material    material  = c.GetMaterial();
            StateVector stateLeft = StateVector.FromPrimitiveQuantities(
                material, densityLeft, new Vector(velocityLeft, 0.0, 0.0), pressureLeft);
            StateVector stateRight = StateVector.FromPrimitiveQuantities(
                material, densityRight, new Vector(velocityRight, 0.0, 0.0), pressureRight);

            c.InitialValues_Evaluators.Add(
                CompressibleVariables.Density,
                X => stateLeft.Density + (stateRight.Density - stateLeft.Density) * (X[0] - discontinuityPosition).Heaviside());
            c.InitialValues_Evaluators.Add(
                CNSVariables.Velocity.xComponent,
                X => stateLeft.Velocity.x + (stateRight.Velocity.x - stateLeft.Velocity.x) * (X[0] - discontinuityPosition).Heaviside());
            c.InitialValues_Evaluators.Add(
                CNSVariables.Pressure,
                X => stateLeft.Pressure + (stateRight.Pressure - stateLeft.Pressure) * (X[0] - discontinuityPosition).Heaviside());
            if (twoD)
            {
                c.InitialValues_Evaluators.Add(CNSVariables.Velocity.yComponent, X => 0);
            }

            if (!twoD)
            {
                var riemannSolver = new ExactRiemannSolver(stateLeft, stateRight, new Vector(1.0, 0.0, 0.0));
                riemannSolver.GetStarRegionValues(out double pStar, out double uStar);

                c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error(
                                  CompressibleVariables.Density,
                                  (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Density));
                c.Queries.Add("L2ErrorVelocity", QueryLibrary.L2Error(
                                  CNSVariables.Velocity.xComponent,
                                  (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Velocity.x));
                c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error(
                                  CNSVariables.Pressure,
                                  (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Pressure));
            }

            c.dtMin = 0.0;
            c.dtMax = 1.0;
            //c.dtFixed = 1.0e-6;
            c.CFLFraction   = 0.1;
            c.Endtime       = 0.2;
            c.NoOfTimesteps = int.MaxValue;

            // Use METIS since ParMETIS is not installed on build server
            c.GridPartType = GridPartType.METIS;

            return(c);
        }
Ejemplo n.º 26
0
        public static IBM_Control[] IBMCylinderFlow(string _DbPath = null, int k = 2, bool xPeriodic = false, double VelXBase = 0.0)
        {
            List <IBM_Control> R = new List <IBM_Control>();

            foreach (int i in new int[] { 3 })
            {
                IBM_Control C = new IBM_Control();

                C.Paramstudy_CaseIdentification = new Tuple <string, object>[] {
                    new Tuple <string, object>("k", i),
                };

                k = i;

                const double BaseSize = 1.0;

                // basic database options
                // ======================

                C.DbPath      = @"\\fdyprime\userspace\krause\BoSSS_DBs\Paper_CellAgglo01_Penalty4";
                C.savetodb    = false;
                C.ProjectName = "FixedCylinderRe100_k" + i + "_CellAgglo02_penalty4_newMesh2";

                switch (i)
                {
                case 1:
                    C.MeshFactor = 1.33; // was 1.33
                    break;

                case 2:
                    C.MeshFactor = 0.92;
                    break;

                case 3:
                    C.MeshFactor = 0.7; // was 07
                    break;

                default:

                    throw new ApplicationException();
                }

                C.ProjectDescription = "Cylinder";
                C.Tags.Add("with immersed boundary method");

                // DG degrees
                // ==========

                C.FieldOptions.Add("VelocityX", new FieldOpts()
                {
                    Degree   = k,
                    SaveToDB = FieldOpts.SaveToDBOpt.TRUE
                });
                C.FieldOptions.Add("VelocityY", new FieldOpts()
                {
                    Degree   = k,
                    SaveToDB = FieldOpts.SaveToDBOpt.TRUE
                });
                //Console.WriteLine("Achtung: equal order!!!!");
                C.FieldOptions.Add("Pressure", new FieldOpts()
                {
                    Degree = k - 1,

                    SaveToDB = FieldOpts.SaveToDBOpt.TRUE
                });
                C.FieldOptions.Add("PhiDG", new FieldOpts()
                {
                    Degree   = 2,
                    SaveToDB = FieldOpts.SaveToDBOpt.TRUE
                });
                C.FieldOptions.Add("Phi", new FieldOpts()
                {
                    Degree   = 2,
                    SaveToDB = FieldOpts.SaveToDBOpt.TRUE
                });

                //grid and boundary conditions
                // ============================

                C.GridFunc = delegate {
                    var _xNodes1 = Grid1D.TanhSpacing(-2, -1, Convert.ToInt32(10 * C.MeshFactor), 0.5, false); //10
                    _xNodes1 = _xNodes1.GetSubVector(0, (_xNodes1.Length - 1));
                    var _xNodes2 = GenericBlas.Linspace(-1, 2, Convert.ToInt32(35 * C.MeshFactor));            //35
                    _xNodes2 = _xNodes2.GetSubVector(0, (_xNodes2.Length - 1));
                    var _xNodes3 = Grid1D.TanhSpacing(2, 20, Convert.ToInt32(60 * C.MeshFactor), 1.5, true);   //60

                    var xNodes = ArrayTools.Cat(_xNodes1, _xNodes2, _xNodes3);


                    var _yNodes1 = Grid1D.TanhSpacing(-2, -1, Convert.ToInt32(7 * C.MeshFactor), 0.9, false); //7
                    _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1));
                    var _yNodes2 = GenericBlas.Linspace(-1, 1, Convert.ToInt32(25 * C.MeshFactor));           //25
                    _yNodes2 = _yNodes2.GetSubVector(0, (_yNodes2.Length - 1));
                    var _yNodes3 = Grid1D.TanhSpacing(1, 2.1, Convert.ToInt32(7 * C.MeshFactor), 1.1, true);  //7
                    var yNodes   = ArrayTools.Cat(_yNodes1, _yNodes2, _yNodes3);



                    //double[] xNodes = GenericBlas.Linspace(0 * BaseSize, 22 * BaseSize, 25);
                    //double[] yNodes = GenericBlas.Linspace(0 * BaseSize, 4.1 * BaseSize, 25);
                    var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: xPeriodic);
                    grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
                    grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
                    if (!xPeriodic)
                    {
                        grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
                        grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
                    }

                    grd.DefineEdgeTags(delegate(double[] X) {
                        byte et = 0;
                        if (Math.Abs(X[1] - (-2 * BaseSize)) <= 1.0e-8)
                        {
                            et = 1;
                        }
                        if (Math.Abs(X[1] - (+2.1 * BaseSize)) <= 1.0e-8)
                        {
                            et = 2;
                        }
                        if (!xPeriodic && Math.Abs(X[0] - (-2 * BaseSize)) <= 1.0e-8)
                        {
                            et = 3;
                        }
                        if (!xPeriodic && Math.Abs(X[0] - (+20.0 * BaseSize)) <= 1.0e-8)
                        {
                            et = 4;
                        }


                        Debug.Assert(et != 0);
                        return(et);
                    });

                    Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

                    return(grd);
                };

                //C.GridFunc = delegate {

                //    // Box1
                //    var box1_p1 = new double[2] { -2, -2 };
                //    var box1_p2 = new double[2] { 20, 2.1 };
                //    var box1 = new GridBox(box1_p1, box1_p2, 46, 20); //k1: 70,25 ; k2: 46,20 ; k3: 35,15

                //    // Box2
                //    var box2_p1 = new double[2] { -2, -2 };
                //    var box2_p2 = new double[2] { 3, 2.1 };
                //    var box2 = new GridBox(box2_p1, box2_p2, 26, 40); //k1: 40,50 ; k2: 26,40; k3: 20, 30

                //    // Box3
                //    var box3_p1 = new double[2] { -2, -1 };
                //    var box3_p2 = new double[2] { 1, 1 };
                //    var box3 = new GridBox(box3_p1, box3_p2, 32, 38); //k1: 48,58  ; k2: 32,38; k3: 24, 30

                //    // Box4
                //    var box4_p1 = new double[2] { -0.7, -0.72 };
                //    var box4_p2 = new double[2] { 0.7, 0.7 };
                //    var box4 = new GridBox(box4_p1, box4_p2, 30, 56); //k1: 44,84  ; k2: 30,56; k3: 22, 42

                //    var grd = Grid2D.HangingNodes2D(box1, box2, box3,box4);

                //    grd.EdgeTagNames.Add(1, "Velocity_Inlet_upper");
                //    grd.EdgeTagNames.Add(2, "Velocity_Inlet_lower");
                //    if (!xPeriodic) {
                //        grd.EdgeTagNames.Add(3, "Velocity_Inlet_left");
                //        grd.EdgeTagNames.Add(4, "Pressure_Outlet_right");
                //    }

                //    grd.DefineEdgeTags(delegate (double[] X) {
                //        byte et = 0;
                //        if (Math.Abs(X[1] - (-2 * BaseSize)) <= 1.0e-8)
                //            et = 1;
                //        if (Math.Abs(X[1] - (+2.1 * BaseSize)) <= 1.0e-8)
                //            et = 2;
                //        if (!xPeriodic && Math.Abs(X[0] - (-2 * BaseSize)) <= 1.0e-8)
                //            et = 3;
                //        if (!xPeriodic && Math.Abs(X[0] - (+20.0 * BaseSize)) <= 1.0e-8)
                //            et = 4;


                //        Debug.Assert(et != 0);
                //        return et;
                //    });

                //    Console.WriteLine("Cells:    {0}", grd.NumberOfCells);

                //    return grd;
                //};

                C.AddBoundaryCondition("Velocity_Inlet_upper", "VelocityX", X => 0);
                C.AddBoundaryCondition("Velocity_Inlet_lower", "VelocityX", X => 0); //-(4 * 1.5 * X[1] * (4.1 - X[1]) / (4.1 * 4.1))
                if (!xPeriodic)
                {
                    C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX", X => (4 * 1.5 * (X[1] + 2) * (4.1 - (X[1] + 2)) / (4.1 * 4.1)));
                    //C.AddBoundaryCondition("Velocity_Inlet_left", "VelocityX#A", X => 1);
                }
                C.AddBoundaryCondition("Pressure_Outlet_right");


                // Initial Values
                // ==============

                double radius = 0.5;
                C.PhysicalParameters.rho_A = 1;
                C.PhysicalParameters.mu_A  = 1.0 / 20;

                //C.InitialValues.Add("Phi", X => phi(X, 0));

                //C.InitialValues.Add("Phi", X => ((X[0] / (radius * BaseSize)) - mPx) * (X[0] / (radius * BaseSize)) - mPx) + ((X[1]) / (radius * BaseSize)) - 2.)Pow2() - radius.Pow2()));  // quadratic form
                //    );
                C.InitialValues_Evaluators.Add("Phi", X => - (X[0]).Pow2() + -(X[1]).Pow2() + radius.Pow2());
                //C.InitialValues.Add("Phi", X => -1);

                C.InitialValues_Evaluators.Add("VelocityX", X => 4 * 1.5 * (X[1] + 2) * (4.1 - (X[1] + 2)) / (4.1 * 4.1));
                //C.InitialValues.Add("VelocityX", delegate (double[] X)
                //{
                //    double x = X[0];
                //    double y = X[1];

                //    double R = Math.Sqrt((x + 1).Pow2() + y.Pow2());

                //    double xVel = 0;

                //    if (R < 0.75)
                //    {
                //        xVel = 1;
                //    }
                //    return xVel;
                //});

                //C.InitialValues.Add("VelocityY", delegate (double[] X) {
                //    double x = X[0];
                //    double y = X[1];

                //    double R = Math.Sqrt((x + 1).Pow2() + (y).Pow2());

                //    double yVel = 0;

                //    if (R < 0.75) {
                //        yVel = 1;
                //    }
                //    return yVel;
                //});

                // For restart
                //C.RestartInfo = new Tuple<Guid, TimestepNumber>(new Guid("8f5cfed9-31c7-4be8-aa56-e92e5348e08b"), 95);
                //C.GridGuid = new Guid("71ffc0c4-66aa-4762-b07e-45385f34b03f");

                // Physical Parameters
                // ===================


                C.PhysicalParameters.IncludeConvection = true;


                // misc. solver options
                // ====================

                C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2;

                C.LevelSetSmoothing = false;
                //C.option_solver = "direct";
                C.MaxKrylovDim             = 20;
                C.MaxSolverIterations      = 50;
                C.VelocityBlockPrecondMode = MultigridOperator.Mode.SymPart_DiagBlockEquilib_DropIndefinite;
                C.NoOfMultigridLevels      = 0;

                // Timestepping
                // ============

                C.Timestepper_Scheme = IBM_Control.TimesteppingScheme.ImplicitEuler;
                double dt = 0.05;
                C.dtMax         = dt;
                C.dtMin         = dt;
                C.Endtime       = 70;
                C.NoOfTimesteps = 1000000;

                // haben fertig...
                // ===============

                R.Add(C);
            }

            return(R.ToArray());
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Control for the testcase according to Smolianksi
        /// </summary>
        /// <param name="p"></param>
        /// <param name="kelem"></param>
        /// <param name="_DbPath"></param>
        /// <returns></returns>
        public static XNSE_Control RT_Smolianski(int p = 2, int kelem = 32, string _DbPath = null)
        {
            XNSE_Control C = new XNSE_Control();

            // basic database options
            // ======================
            #region db

            //_DbPath = @"D:\local\local_Testcase_databases\Testcase_RTinstability";
            _DbPath = @"\\fdyprime\userspace\smuda\cluster\cluster_db";

            C.DbPath      = _DbPath;
            C.savetodb    = C.DbPath != null;
            C.ProjectName = "XNSE/RT-Instability";
            C.Tags.Add("unstable");
            //C.Tags.Add("smolianski");

            #endregion

            //C.LogValues = XNSE_Control.LoggingValues.Wavelike;
            //C.WriteInterfaceP = true;


            // DG degrees
            // ==========
            #region degrees

            C.FieldOptions.Add("VelocityX", new FieldOpts()
            {
                Degree   = p,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("VelocityY", new FieldOpts()
            {
                Degree   = p,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("Pressure", new FieldOpts()
            {
                Degree   = p - 1,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("PhiDG", new FieldOpts()
            {
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("Phi", new FieldOpts()
            {
                Degree   = 4,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("Curvature", new FieldOpts()
            {
                Degree   = 8,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });

            #endregion


            // grid genration
            // ==============
            #region grid

            double L = 1;
            double H = 4.0 * L;

            C.GridFunc = delegate() {
                // Smolianski
                //double[] Xnodes = GenericBlas.Linspace(0, L, kelem + 1);
                //double[] Ynodes = GenericBlas.Linspace(0, H, (4 * kelem) + 1);
                //var grd = Grid2D.Cartesian2DGrid(Xnodes, Ynodes, periodicX: false);

                double[] xNodes = GenericBlas.Linspace(0, L, kelem + 1);

                double[] _yNodes1 = GenericBlas.Linspace(0, 2.2, (int)(2.2 * kelem) + 1);
                _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1));
                var _yNodes2 = Grid1D.TanhSpacing(2.2, 4.0, (kelem / 2) + 1, 1.5, true);

                var yNodes = ArrayTools.Cat(_yNodes1, _yNodes2);


                var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: false);

                grd.EdgeTagNames.Add(1, "wall_lower");
                grd.EdgeTagNames.Add(2, "wall_upper");
                grd.EdgeTagNames.Add(3, "freeslip_left");
                grd.EdgeTagNames.Add(4, "freeslip_right");


                grd.DefineEdgeTags(delegate(double[] X) {
                    byte et = 0;
                    if (Math.Abs(X[1]) <= 1.0e-8)
                    {
                        et = 1;
                    }
                    if (Math.Abs(X[1] - H) <= 1.0e-8)
                    {
                        et = 2;
                    }
                    if (Math.Abs(X[0]) <= 1.0e-8)
                    {
                        et = 3;
                    }
                    if (Math.Abs(X[0] - L) <= 1.0e-8)
                    {
                        et = 4;
                    }

                    return(et);
                });

                return(grd);
            };


            //double L = 1; //lambda_instable;
            //double H = 1.0 * L;
            //double H_interf = L / 4.0;

            ////int xkelem = 20;
            //int ykelem_Interface = 1 * kelem / 2;
            //int ykelem_outer = kelem / 2;

            //C.GridFunc = delegate () {
            //    double[] xNodes = GenericBlas.Linspace(0, L, kelem + 1);
            //    //double[] Ynodes_Interface = GenericBlas.Linspace(-(H_interf) / 2.0, (H_interf) / 2.0, ykelem_Interface);
            //    //Ynodes_Interface = Ynodes_Interface.GetSubVector(1, Ynodes_Interface.GetLength(0) - 2);
            //    //double[] Ynodes_lower = GenericBlas.Linspace(-(H + (H_interf / 2.0)), -(H_interf / 2.0), ykelem_outer + 1);
            //    //double[] Ynodes_upper = GenericBlas.Linspace((H_interf / 2.0), H + (H_interf / 2.0), ykelem_outer + 1);
            //    //double[] Ynodes = Ynodes_lower.Concat(Ynodes_Interface).ToArray().Concat(Ynodes_upper).ToArray();
            //    var _yNodes1 = Grid1D.TanhSpacing(-(H + (H_interf / 2.0)), -(H_interf / 2.0), ykelem_outer + 1, 1.5, false);
            //    _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1));
            //    var _yNodes2 = GenericBlas.Linspace(-H_interf / 2.0, H_interf / 2.0, ykelem_Interface);
            //    _yNodes2 = _yNodes2.GetSubVector(0, (_yNodes2.Length - 1));
            //    var _yNodes3 = Grid1D.TanhSpacing((H_interf / 2.0), H + (H_interf / 2.0), ykelem_outer + 1, 1.5, true);
            //    var yNodes = ArrayTools.Cat(_yNodes1, _yNodes2, _yNodes3);

            //    var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: true);

            //    grd.EdgeTagNames.Add(1, "wall_lower");
            //    grd.EdgeTagNames.Add(2, "wall_upper");


            //    grd.DefineEdgeTags(delegate (double[] X) {
            //        byte et = 0;
            //        if (Math.Abs(X[1] + ((H_interf / 2.0) + H)) <= 1.0e-8)
            //            et = 1;
            //        if (Math.Abs(X[1] - ((H_interf / 2.0) + H)) <= 1.0e-8)
            //            et = 2;
            //        if (Math.Abs(X[0]) <= 1.0e-8)
            //            et = 3;
            //        if (Math.Abs(X[0] - L) <= 1.0e-8)
            //            et = 4;

            //        return et;
            //    });

            //    return grd;
            //};

            #endregion


            // boundary conditions
            // ===================
            #region BC

            C.AddBoundaryCondition("wall_lower");
            C.AddBoundaryCondition("wall_upper");
            C.AddBoundaryCondition("freeslip_left");
            C.AddBoundaryCondition("freeslip_right");

            #endregion


            // Initial Values
            // ==============
            #region init

            int    k  = 1;
            double A0 = 0.05;
            C.InitialValues_Evaluators.Add("Phi", (X => X[1] - (2.0 + A0 * Math.Cos(2.0 * Math.PI * X[0]))));

            C.InitialValues_Evaluators.Add("VelocityY#A", X => 0.0);
            C.InitialValues_Evaluators.Add("VelocityY#B", X => 0.0);

            double g = 1.0;
            C.InitialValues_Evaluators.Add("GravityY#A", X => - g);
            C.InitialValues_Evaluators.Add("GravityY#B", X => - g);

            //var database = new DatabaseInfo(_DbPath);
            //Guid restartID = new Guid("12b8c9f7-504c-40c4-a548-304a2e2aa14f");
            //C.RestartInfo = new Tuple<Guid, Foundation.IO.TimestepNumber>(restartID, 3420);

            #endregion


            // Physical Parameters
            // ===================
            #region physics

            //C.PhysicalParameters.rho_A = 0.17;
            //C.PhysicalParameters.rho_B = 1.2;
            //C.PhysicalParameters.mu_A = 0.17e-2;
            //C.PhysicalParameters.mu_B = 1.2e-2;
            //C.PhysicalParameters.Sigma = 0.0;

            C.PhysicalParameters.rho_A = 0.17;
            C.PhysicalParameters.rho_B = 1.2;
            C.PhysicalParameters.mu_A  = 0.003;
            C.PhysicalParameters.mu_B  = 0.003;
            C.PhysicalParameters.Sigma = 0.0;   // corresponding dt = 1e-3;
            //C.PhysicalParameters.Sigma = 0.015;   // corresponding dt = 4e-3;

            C.PhysicalParameters.IncludeConvection = true;
            C.PhysicalParameters.Material          = true;

            #endregion



            // additional parameters
            // =====================

            //double[] param = new double[4];
            //param[0] = k;   // wavenumber
            //param[1] = L;  // wavelength
            //param[2] = A0;      // initial disturbance
            //param[3] = g;      // y-gravity
            //C.AdditionalParameters = param;


            // misc. solver options
            // ====================
            #region solver


            //C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2;
            //C.AdvancedDiscretizationOptions.PenaltySafety = 40;
            //C.AdvancedDiscretizationOptions.UseGhostPenalties = true;

            C.LSContiProjectionMethod       = ContinuityProjectionOption.SpecFEM;
            C.VelocityBlockPrecondMode      = MultigridOperator.Mode.SymPart_DiagBlockEquilib;
            C.Solver_MaxIterations          = 50;
            C.Solver_ConvergenceCriterion   = 1e-8;
            C.LevelSet_ConvergenceCriterion = 1e-6;

            C.LinearSolver = new DirectSolver()
            {
                WhichSolver = DirectSolver._whichSolver.MUMPS
            };

            C.AdvancedDiscretizationOptions.FilterConfiguration = CurvatureAlgorithms.FilterConfiguration.Default;
            C.AdvancedDiscretizationOptions.SST_isotropicMode   = Solution.XNSECommon.SurfaceStressTensor_IsotropicMode.Curvature_Projected;
            C.AdvancedDiscretizationOptions.FilterConfiguration.FilterCurvatureCycles = 1;

            #endregion


            // Timestepping
            // ============
            #region time

            C.CompMode = AppControl._CompMode.Transient;

            C.Timestepper_Scheme  = XNSE_Control.TimesteppingScheme.ImplicitEuler;
            C.Timestepper_BDFinit = TimeStepperInit.SingleInit;
            //C.dt_increment = 20;
            C.Timestepper_LevelSetHandling = LevelSetHandling.LieSplitting;

            double dt = 1e-3;
            C.dtMax         = dt;
            C.dtMin         = dt;
            C.Endtime       = 1000;
            C.NoOfTimesteps = 4000;

            C.saveperiod = 4;

            #endregion

            return(C);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Template for all shock tube tests
        /// </summary>
        /// <param name="convectiveFlux"></param>
        /// <param name="densityLeft"></param>
        /// <param name="velocityLeft"></param>
        /// <param name="pressureLeft"></param>
        /// <param name="densityRight"></param>
        /// <param name="velocityRight"></param>
        /// <param name="pressureRight"></param>
        /// <param name="discontinuityPosition"></param>
        /// <returns></returns>
        private static CNSControl GetShockTubeControlTemplate(ConvectiveFluxTypes convectiveFlux, double densityLeft, double velocityLeft, double pressureLeft, double densityRight, double velocityRight, double pressureRight, double discontinuityPosition)
        {
            CNSControl c = new CNSControl();

            c.DbPath   = null;
            c.savetodb = false;

            c.ActiveOperators    = Operators.Convection;
            c.ConvectiveFluxType = convectiveFlux;
            c.EquationOfState    = IdealGas.Air;
            c.MachNumber         = 1.0 / Math.Sqrt(c.EquationOfState.HeatCapacityRatio);

            c.ExplicitScheme = ExplicitSchemes.RungeKutta;
            c.ExplicitOrder  = 1;

            int dgDegree = 0;

            c.AddVariable(Variables.Density, dgDegree);
            c.AddVariable(Variables.Momentum.xComponent, dgDegree);
            c.AddVariable(Variables.Energy, dgDegree);

            c.AddVariable(Variables.Pressure, dgDegree);
            c.AddVariable(Variables.Velocity.xComponent, dgDegree);

            c.GridFunc = delegate {
                double[] xNodes = GenericBlas.Linspace(0.0, 1.0, 201);
                var      grid   = Grid1D.LineGrid(xNodes, false);
                grid.EdgeTagNames.Add(1, "supersonicOutlet");
                grid.DefineEdgeTags(X => 1);
                return(grid);
            };

            // Take inner values everywhere
            c.AddBoundaryCondition("supersonicOutlet");

            Material    material  = new Material(c);
            StateVector stateLeft = StateVector.FromPrimitiveQuantities(
                material, densityLeft, new Vector3D(velocityLeft, 0.0, 0.0), pressureLeft);
            StateVector stateRight = StateVector.FromPrimitiveQuantities(
                material, densityRight, new Vector3D(velocityRight, 0.0, 0.0), pressureRight);

            c.InitialValues_Evaluators.Add(
                Variables.Density,
                X => stateLeft.Density + (stateRight.Density - stateLeft.Density) * (X[0] - discontinuityPosition).Heaviside());
            c.InitialValues_Evaluators.Add(
                Variables.Velocity.xComponent,
                X => stateLeft.Velocity.x + (stateRight.Velocity.x - stateLeft.Velocity.x) * (X[0] - discontinuityPosition).Heaviside());
            c.InitialValues_Evaluators.Add(
                Variables.Pressure,
                X => stateLeft.Pressure + (stateRight.Pressure - stateLeft.Pressure) * (X[0] - discontinuityPosition).Heaviside());

            var    riemannSolver = new ExactRiemannSolver(stateLeft, stateRight, new Vector3D(1.0, 0.0, 0.0));
            double pStar, uStar;

            riemannSolver.GetStarRegionValues(out pStar, out uStar);

            c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error(
                              Variables.Density,
                              (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Density));
            c.Queries.Add("L2ErrorVelocity", QueryLibrary.L2Error(
                              Variables.Velocity.xComponent,
                              (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Velocity.x));
            c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error(
                              Variables.Pressure,
                              (X, t) => riemannSolver.GetState(pStar, uStar, X[0] - discontinuityPosition, t).Pressure));

            c.dtMin         = 0.0;
            c.dtMax         = 1.0;
            c.CFLFraction   = 0.5;
            c.NoOfTimesteps = int.MaxValue;

            c.PrintInterval = 50;

            return(c);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Control for various testing
        /// </summary>
        /// <param name="p"></param>
        /// <param name="xkelem"></param>
        /// <param name="dt"></param>
        /// <param name="t_end"></param>
        /// <param name="_DbPath"></param>
        /// <returns></returns>
        public static XNSE_Control RT(int p = 2, int xkelem = 16, string _DbPath = null)
        {
            XNSE_Control C = new XNSE_Control();

            // basic database options
            // ======================
            #region db

            _DbPath = @"D:\local\local_Testcase_databases\Testcase_RTinstability";
            //_DbPath = @"\\fdyprime\userspace\smuda\cluster\cluster_db";

            C.DbPath      = _DbPath;
            C.savetodb    = C.DbPath != null;
            C.ProjectName = "XNSE/RT-Instability";

            C.LogValues       = XNSE_Control.LoggingValues.Wavelike;
            C.WriteInterfaceP = true;

            #endregion

            // DG degrees
            // ==========
            #region degrees

            C.FieldOptions.Add("VelocityX", new FieldOpts()
            {
                Degree   = p,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("VelocityY", new FieldOpts()
            {
                Degree   = p,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("Pressure", new FieldOpts()
            {
                Degree   = p - 1,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("GravityY", new FieldOpts()
            {
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("PhiDG", new FieldOpts()
            {
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("Phi", new FieldOpts()
            {
                Degree   = p,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
            C.FieldOptions.Add("Curvature", new FieldOpts()
            {
                Degree   = p,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });

            #endregion


            // Physical Parameters
            // ===================
            #region physics


            // Capillary wave: Laplace number La = 3e5:
            //C.Tags.Add("La=3e5");
            //double rho_l = 1e-3;
            //double rho_h = 1e-3;
            //double mu_l = 1e-5;
            //double mu_h = 1e-5;
            //double sigma = 3e-2;

            // Capillary wave: Laplace number La = 3000:
            //C.Tags.Add("La3000");
            //double rho_l = 1e-3;
            //double rho_h = 1e-3;
            //double mu_l = 1e-4;
            //double mu_h = 1e-4;
            //double sigma = 3e-2;

            // Capillary wave: Laplace number La = 120:
            //double rho_l = 1e-3;
            //double rho_h = 1e-3;
            //double mu_l = 5e-4;
            //double mu_h = 5e-4;
            //double sigma = 3e-2;

            //double rho_l = 1e-3;
            //double rho_h = 1e-3;
            //double mu_l = 1e-6;
            //double mu_h = 1e-4;
            //double sigma = 3e-2;

            //double rho_l = 1;
            //double rho_h = 1;
            //double mu_l = 1e-3;
            //double mu_h = 1e-3;
            //double sigma = 1;

            // Air(light)-Water(heavy)
            //double rho_h = 1e-3;          // kg / cm^3
            //double rho_l = 1.2e-6;        // kg / cm^3
            //double mu_h = 1e-5;           // kg / cm * s
            //double mu_l = 17.1e-8;        // kg / cm * s
            //double sigma = 72.75e-3;      // kg / s^2         // lambda_crit = 1.7121 ; lambda < lambda_c: stable

            // same kinematic viscosities
            //double rho_l = 1e-5;          // kg / cm^3
            //double mu_l = 1e-8;           // kg / cm * s
            //double rho_h = 1e-3;        // kg / cm^3
            //double mu_h = 1e-6;        // kg / cm * s         // Atwood number = 0.98

            //double rho_l = 7e-4;          // kg / cm^3
            //double mu_l = 7e-5;           // kg / cm * s
            //double rho_h = 1e-3;        // kg / cm^3
            //double mu_h = 1e-4;        // kg / cm * s           // Atwood number = 0.1765

            //double sigma = 72.75e-3;      // kg / s^2


            //double rho_l = 1e-3;
            //double mu_l = 1e-4;
            //double rho_h = 1;
            //double mu_h = 1e-1;

            //double sigma = 100;      // kg / s^2

            double rho_l = 1e-1;
            double mu_l  = 1e-2;
            double rho_h = 10;
            double mu_h  = 1;

            double sigma = 50;      // kg / s^2

            // Water-Oil
            //double rho_ = 8.63e-4;
            //double rho_B = 1.2e-6;
            //double mu_A = 2e-4;
            //double mu_B = 17.1e-8;


            // stable configuration
            //C.PhysicalParameters.rho_A = rho_h;
            //C.PhysicalParameters.rho_B = rho_l;
            //C.PhysicalParameters.mu_A = mu_h;
            //C.PhysicalParameters.mu_B = mu_l;
            //C.PhysicalParameters.Sigma = sigma;


            // unstable configuration
            C.PhysicalParameters.rho_A = rho_l;
            C.PhysicalParameters.rho_B = rho_h;
            C.PhysicalParameters.mu_A  = mu_l;
            C.PhysicalParameters.mu_B  = mu_h;
            C.PhysicalParameters.Sigma = sigma;

            //C.PhysicalParameters.Sigma = 0.0;   // free surface boundary condition

            C.PhysicalParameters.IncludeConvection = true;
            C.PhysicalParameters.Material          = true;

            #endregion


            // Initial displacement
            // ===================

            int    kmode = 1;
            double H0    = 0.01;

            //double lambda_stable = 1;
            //double lambda_instable = 4;
            //Func<double, double> displacement = x => ((lambda_stable / 100) * Math.Sin(x * 2 * Math.PI / lambda_stable )) + ((lambda_instable / 100) * Math.Sin(x * 2 * Math.PI / lambda_instable));
            Func <double, double> displacement = x => (H0 * Math.Sin(x * 2 * Math.PI * (double)kmode));


            // grid genration
            // ==============
            #region grid

            double L        = 1; //lambda_instable;
            double H        = 1.0 * L;
            double H_interf = L / 4.0;

            //int xkelem = 20;
            int ykelem_Interface = 1 * xkelem;      // /2
            int ykelem_outer     = xkelem / 2;      // /2

            C.GridFunc = delegate() {
                double[] xNodes = GenericBlas.Linspace(0, L, xkelem + 1);
                //double[] Ynodes_Interface = GenericBlas.Linspace(-(H_interf) / 2.0, (H_interf) / 2.0, ykelem_Interface);
                //Ynodes_Interface = Ynodes_Interface.GetSubVector(1, Ynodes_Interface.GetLength(0) - 2);
                //double[] Ynodes_lower = GenericBlas.Linspace(-(H + (H_interf / 2.0)), -(H_interf / 2.0), ykelem_outer + 1);
                //double[] Ynodes_upper = GenericBlas.Linspace((H_interf / 2.0), H + (H_interf / 2.0), ykelem_outer + 1);
                //double[] Ynodes = Ynodes_lower.Concat(Ynodes_Interface).ToArray().Concat(Ynodes_upper).ToArray();
                var _yNodes1 = Grid1D.TanhSpacing(-(H + (H_interf / 2.0)), -(H_interf / 2.0), ykelem_outer + 1, 1.5, false);
                _yNodes1 = _yNodes1.GetSubVector(0, (_yNodes1.Length - 1));
                var _yNodes2 = GenericBlas.Linspace(-H_interf / 2.0, H_interf / 2.0, ykelem_Interface);
                _yNodes2 = _yNodes2.GetSubVector(0, (_yNodes2.Length - 1));
                var _yNodes3 = Grid1D.TanhSpacing((H_interf / 2.0), H + (H_interf / 2.0), ykelem_outer + 1, 1.5, true);
                var yNodes   = ArrayTools.Cat(_yNodes1, _yNodes2, _yNodes3);

                var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes, periodicX: true);

                grd.EdgeTagNames.Add(1, "wall_lower");
                grd.EdgeTagNames.Add(2, "wall_upper");


                grd.DefineEdgeTags(delegate(double[] X) {
                    byte et = 0;
                    if (Math.Abs(X[1] + ((H_interf / 2.0) + H)) <= 1.0e-8)
                    {
                        et = 1;
                    }
                    if (Math.Abs(X[1] - ((H_interf / 2.0) + H)) <= 1.0e-8)
                    {
                        et = 2;
                    }
                    if (Math.Abs(X[0]) <= 1.0e-8)
                    {
                        et = 3;
                    }
                    if (Math.Abs(X[0] - L) <= 1.0e-8)
                    {
                        et = 4;
                    }

                    return(et);
                });

                return(grd);
            };

            // nach Popinet
            //C.GridFunc = delegate () {
            //    double[] Xnodes = GenericBlas.Linspace(0, L, xkelem + 1);
            //    double[] Ynodes = GenericBlas.Linspace(-3.0 * L / 2.0, 3.0 * L / 2.0, (3 * xkelem) + 1);
            //    var grd = Grid2D.Cartesian2DGrid(Xnodes, Ynodes, periodicX: true);

            //    grd.EdgeTagNames.Add(1, "wall_lower");
            //    grd.EdgeTagNames.Add(2, "wall_upper");


            //    grd.DefineEdgeTags(delegate (double[] X) {
            //        byte et = 0;
            //        if (Math.Abs(X[1] + (3.0 * L / 2.0)) <= 1.0e-8)
            //            et = 1;
            //        if (Math.Abs(X[1] - (3.0 * L / 2.0)) <= 1.0e-8)
            //            et = 2;
            //        if (Math.Abs(X[0]) <= 1.0e-8)
            //            et = 3;
            //        if (Math.Abs(X[0] - L) <= 1.0e-8)
            //            et = 4;

            //        return et;
            //    });

            //    return grd;
            //};


            #endregion


            // boundary conditions
            // ===================
            #region BC

            C.AddBoundaryCondition("wall_lower");
            C.AddBoundaryCondition("wall_upper");

            #endregion


            // Initial Values
            // ==============
            #region init

            Func <double, double> PeriodicFunc = x => displacement(x);

            //superposed higher frequent disturbance
            //double lambda_dist = lambda / (double)(xkelem / 2);
            //if (lambda_dist > 0.0) {
            //    double A0_dist = A0 / 5.0;
            //    Func<double, double> disturbance = x => A0_dist * Math.Sin(x * 2 * Math.PI / lambda_dist);
            //    PeriodicFunc = x => (displacement(x) + disturbance(x));
            //}


            C.InitialValues_Evaluators.Add("Phi", (X => X[1] - (PeriodicFunc(X[0]))));

            C.InitialValues_Evaluators.Add("VelocityX#A", X => 0.0);
            C.InitialValues_Evaluators.Add("VelocityX#B", X => 0.0);

            double g = 9.81; // e2;
            C.InitialValues_Evaluators.Add("GravityY#A", X => - g);
            C.InitialValues_Evaluators.Add("GravityY#B", X => - g);

            //var database = new DatabaseInfo(_DbPath);
            //Guid restartID = new Guid("0141eba2-8d7b-4593-8595-bfff12dbfc40");
            //C.RestartInfo = new Tuple<Guid, Foundation.IO.TimestepNumber>(restartID, null);

            #endregion


            // misc. solver options
            // ====================
            #region solver


            //C.AdvancedDiscretizationOptions.CellAgglomerationThreshold = 0.2;
            //C.AdvancedDiscretizationOptions.PenaltySafety = 40;
            //C.AdvancedDiscretizationOptions.UseGhostPenalties = true;

            C.LSContiProjectionMethod       = ContinuityProjectionOption.SpecFEM;
            C.VelocityBlockPrecondMode      = MultigridOperator.Mode.SymPart_DiagBlockEquilib;
            C.NoOfMultigridLevels           = 1;
            C.Solver_MaxIterations          = 50;
            C.Solver_ConvergenceCriterion   = 1e-8;
            C.LevelSet_ConvergenceCriterion = 1e-6;

            C.LinearSolver = new DirectSolver()
            {
                WhichSolver = DirectSolver._whichSolver.MUMPS
            };

            //C.Option_LevelSetEvolution = LevelSetEvolution.Fourier;
            //C.AdvancedDiscretizationOptions.surfTensionMode = SurfaceTensionMode.Curvature_Fourier;

            C.AdvancedDiscretizationOptions.FilterConfiguration = CurvatureAlgorithms.FilterConfiguration.Default;
            C.AdvancedDiscretizationOptions.SST_isotropicMode   = Solution.XNSECommon.SurfaceStressTensor_IsotropicMode.Curvature_Projected;
            C.AdvancedDiscretizationOptions.FilterConfiguration.FilterCurvatureCycles = 1;

            #endregion


            // additional parameters
            // =====================

            double[] param = new double[4];
            param[0] = kmode; // wavenumber
            param[1] = L;     // wavelength
            param[2] = H0;    // initial disturbance
            param[3] = g;     // y-gravity
            C.AdditionalParameters = param;

            // specialized Fourier Level-Set
            // =============================

            int numSp = 640;
            //C.FourierLevSetControl = new FourierLevSetControl(FourierType.Planar, numSp, L, PeriodicFunc, 1.0 / (double)xkelem) {
            //    FourierEvolve = Fourier_Evolution.MaterialPoints,
            //    Timestepper = FourierLevelSet_Timestepper.RungeKutta1901,
            //    InterpolationType = Interpolationtype.CubicSplineInterpolation
            //};


            // Timestepping
            // ============
            #region time

            C.CompMode = AppControl._CompMode.Transient;

            C.Timestepper_Scheme  = XNSE_Control.TimesteppingScheme.ImplicitEuler;
            C.Timestepper_BDFinit = TimeStepperInit.SingleInit;
            //C.dt_increment = 20;
            C.Timestepper_LevelSetHandling = LevelSetHandling.LieSplitting;

            double dt = 1e-4;
            C.dtMax         = dt;
            C.dtMin         = dt;
            C.Endtime       = 1000;
            C.NoOfTimesteps = 4000;

            C.saveperiod = 4;

            #endregion


            return(C);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 1D Manufactured solution for the Euler equations with variable Mach number
        /// </summary>
        /// <param name="dgDegree"></param>
        /// <param name="noOfCellsPerDirection"></param>
        /// <returns></returns>
        public static CNSControl Euler1D(int dgDegree, int noOfCellsPerDirection)
        {
            CNSControl c = new CNSControl();

            c.PrintInterval    = 1;
            c.ResidualInterval = 1;
            c.saveperiod       = 1;

            c.DbPath   = @"";
            c.savetodb = false;
            c.Tags.Add("MMS");

            c.ActiveOperators    = Operators.Convection | Operators.CustomSource;
            c.ConvectiveFluxType = ConvectiveFluxTypes.Rusanov;
            c.ExplicitScheme     = ExplicitSchemes.RungeKutta;
            c.ExplicitOrder      = 1;
            c.EquationOfState    = IdealGas.Air;

            c.AddVariable(Variables.Density, dgDegree);
            c.AddVariable(Variables.Momentum.xComponent, dgDegree);
            c.AddVariable(Variables.Energy, dgDegree);
            c.AddVariable(Variables.Velocity.xComponent, dgDegree);
            c.AddVariable(Variables.Pressure, dgDegree);
            c.AddVariable(Variables.LocalMachNumber, dgDegree);

            c.GridFunc = delegate {
                double[] nodes = GenericBlas.Linspace(0.0, 1.0, noOfCellsPerDirection + 1);
                var      grid  = Grid1D.LineGrid(nodes);
                grid.EdgeTagNames.Add(1, "supersonicinlet");
                grid.DefineEdgeTags(X => 1);
                return(grid);
            };

            double gamma = c.EquationOfState.HeatCapacityRatio;

            c.MachNumber = 1 / Math.Sqrt(gamma);

            double a           = 2.0 * Math.PI;
            double b           = 0.25;
            double c1          = 2.0;
            double MachScaling = (gamma * c.MachNumber * c.MachNumber);

            Func <double[], double, double> rho  = (X, t) => c1 + b * Math.Sin(a * X[0]);
            Func <double[], double, double> m0   = (X, t) => c1 + b * Math.Sin(a * X[0]);
            Func <double[], double, double> rhoE = (X, t) => (c1 + b * Math.Sin(a * X[0])) * (c1 + b * Math.Sin(a * X[0]));
            Func <double[], double, double> u0   = (X, t) => 1;
            Func <double[], double, double> p    = (X, t) => (gamma - 1) * (rhoE(X, t) - 0.5 * MachScaling * rho(X, t) * u0(X, t) * u0(X, t));

            c.InitialValues_Evaluators.Add(Variables.Density, X => rho(X, 0.0));
            c.InitialValues_Evaluators.Add(Variables.Momentum.xComponent, X => m0(X, 0.0));
            c.InitialValues_Evaluators.Add(Variables.Energy, X => rhoE(X, 0.0));

            c.AddBoundaryCondition("supersonicInlet", Variables.Density, rho);
            c.AddBoundaryCondition("supersonicInlet", Variables.Velocity.xComponent, u0);
            c.AddBoundaryCondition("supersonicInlet", Variables.Pressure, p);

            // MMS Sources
            c.CustomContinuitySources.Add(map => new AdHocSourceTerm(map,
                                                                     (X, t, state) => - (a * b * Math.Cos(a * X[0]))
                                                                     ));
            c.CustomMomentumSources[0].Add(map => new AdHocSourceTerm(map,
                                                                      (X, t, state) => - ((a * b * Math.Cos(a * X[0])) * (1 + (gamma - 1) / MachScaling * (2 * rho(X, t) - 0.5 * MachScaling)))
                                                                      ));
            c.CustomEnergySources.Add(map => new AdHocSourceTerm(map,
                                                                 (X, t, state) => - ((a * b * Math.Cos(a * X[0])) * (2 * rho(X, t) + (gamma - 1) * (2 * rho(X, t) - 0.5 * MachScaling)))
                                                                 ));

            c.Queries.Add("L2ErrorDensity", QueryLibrary.L2Error(Variables.Density, rho));
            c.Queries.Add("L2ErrorPressure", QueryLibrary.L2Error(Variables.Pressure, p));
            c.Queries.Add("L2ErrorVelocity", QueryLibrary.L2Error(Variables.Velocity.xComponent, u0));

            c.dtMin              = 0.0;
            c.dtMax              = 1.0;
            c.CFLFraction        = 0.4;
            c.Endtime            = 10000.0;
            c.NoOfTimesteps      = int.MaxValue;
            c.ResidualLoggerType = ResidualLoggerTypes.ChangeRate | ResidualLoggerTypes.Query;
            c.ResidualBasedTerminationCriteria.Add("changeRate_abs_rhoE", 1E-14);

            c.ProjectName = "MMS_Euler1D_Flux=" + c.ConvectiveFluxType + "dg=" + dgDegree + "_cells=" + noOfCellsPerDirection;

            return(c);
        }