/// <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"); } }