Пример #1
0
        /// <summary>
        /// Projects the given <paramref name="initialValues"/> onto the
        /// conservative variable fields <see cref="Density"/>,
        /// <see cref="Momentum"/> and <see cref="Energy"/>. Initial values
        /// may either be given in conservative (see
        /// <see cref="VariableTypes.ConservativeVariables"/>) or primitive
        /// (see <see cref="VariableTypes.PrimitiveVariables"/>) variables
        /// </summary>
        /// <param name="speciesMap"></param>
        /// <param name="initialValues">
        /// The given initial value functions, where the dictionary keys
        /// represent variable names.
        /// </param>
        public virtual void ProjectInitialValues(ISpeciesMap speciesMap, IDictionary <string, Func <double[], double> > initialValues)
        {
            int numberOfDimensions      = CNSEnvironment.NumberOfDimensions;
            CellQuadratureScheme scheme = new CellQuadratureScheme(true, speciesMap.SubGrid.VolumeMask);

            if (config.GetInitialValueVariables() == VariableTypes.ConservativeVariables)
            {
                Density.ProjectField(1.0, initialValues[Variables.Density], scheme);

                for (int d = 0; d < numberOfDimensions; d++)
                {
                    Momentum[d].ProjectField(1.0, initialValues[Variables.Momentum[d]], scheme);
                }

                Energy.ProjectField(1.0, initialValues[Variables.Energy], scheme);
            }
            else if (config.GetInitialValueVariables() == VariableTypes.PrimitiveVariables)
            {
                var densityFunction = initialValues[Variables.Density];
                Density.ProjectField(1.0, densityFunction, scheme);

                Func <double[], double>[] velocityFunctions = new Func <double[], double> [numberOfDimensions];
                for (int d = 0; d < numberOfDimensions; d++)
                {
                    velocityFunctions[d] = initialValues[Variables.Velocity[d]];
                    Momentum[d].ProjectField(1.0, X => densityFunction(X) * velocityFunctions[d](X), scheme);
                }

                var pressureFunction = initialValues[Variables.Pressure];
                Energy.ProjectField(
                    1.0,
                    delegate(double[] X) {
                    double rho = densityFunction(X);
                    double p   = pressureFunction(X);

                    Vector u = new Vector(numberOfDimensions);
                    for (int d = 0; d < numberOfDimensions; d++)
                    {
                        u[d] = velocityFunctions[d](X);
                    }

                    StateVector state = StateVector.FromPrimitiveQuantities(
                        speciesMap.GetMaterial(double.NaN), rho, u, p);
                    return(state.Energy);
                },
                    scheme);
            }
            else
            {
                throw new ArgumentException(
                          "Please specify initial values either in primitive or in conservative variables");
            }
        }
Пример #2
0
        protected override void SetInitial()
        {
            this.LsUpdate(0.0);

            u1.ProjectField((x, y) => x);
            u2.ProjectField((x, y) => x);
        }
Пример #3
0
        protected override void SetInitial()
        {
            u.ProjectField(Jump);
            double error = u.L2Error(Jump, 30);

            Console.WriteLine("L2Error:" + error);
        }
Пример #4
0
 /// <summary>
 /// Projection of a 3D-function <paramref name="f"/> onto a DG-Field
 /// </summary>
 public static void ProjectField(this DGField u, _3D f)
 {
     if (u.Basis.GridDat.SpatialDimension != 3)
     {
         throw new ArgumentException("mismatch in spatial dimension");
     }
     u.ProjectField(f.Vectorize());
 }
Пример #5
0
        /// <summary>
        /// sets some initial value for field <see cref="u"/>;
        /// </summary>
        protected override void SetInitial()
        {
            switch (GridData.SpatialDimension)
            {
            case 2:



                u.ProjectField((_2D)(delegate(double x, double y) {
                    double r = Math.Sqrt(x * x + y * y);


                    return(Math.Exp(-r * r));
                }));


                Velocity[0].ProjectField((_2D)((x, y) => 1.0));
                Velocity[1].ProjectField((_2D)((x, y) => 0.1));

                break;

            case 3:
                u.ProjectField((x, y, z) => ((Math.Abs(x) <= 3.0 && Math.Abs(y) <= 3.0 && Math.Abs(z) <= 3.0) ? 1 : 0));
                Velocity[0].ProjectField((_3D)((x, y, z) => 1));
                Velocity[1].ProjectField((_3D)((x, y, z) => 0));
                Velocity[2].ProjectField((_3D)((x, y, z) => 0));


                break;

            default:
                throw new NotImplementedException();
            }



            double rank = GridData.MpiRank;
            int    J    = GridData.Cells.NoOfLocalUpdatedCells;

            for (int j = 0; j < J; j++)
            {
                mpi_rank.SetMeanValue(j, rank);
            }
        }
Пример #6
0
        protected override void SetInitial()
        {
            c.ProjectField(delegate(double x, double y) {
                if (x <= pod)
                {
                    return(inflowDirichletValue);
                }
                else
                {
                    return(rightValue);
                }
            });

            Velocity[0].ProjectField((_2D)((x, y) => xVel));
            Velocity[1].ProjectField((_2D)((x, y) => yVel));

            double energyNormInit = c.L2Norm();

            Console.WriteLine("Energy norm = {0:0.000000000000000E-00}", energyNormInit);
        }
Пример #7
0
 public void Advect(double dt)
 {
     time += dt;
     LevelSet.ProjectField(MotionFunc.Vectorize(time));
 }
Пример #8
0
 /// <summary>
 /// Projection of a function <paramref name="f"/> onto a DG-Field
 /// </summary>
 public static void ProjectField(this DGField u, double alpha, Func <double[], double> f, CellQuadratureScheme scheme = null)
 {
     u.ProjectField(alpha, f.Vectorize(), scheme);
 }
Пример #9
0
 /// <summary>
 /// Projection of a function <paramref name="f"/> onto a DG-Field
 /// </summary>
 public static void ProjectField(this DGField u, Func <double[], double> f)
 {
     u.ProjectField(f.Vectorize());
 }