/// <summary> /// Constructor /// </summary> /// <param name="gridData"></param> /// <param name="config"></param> public IBMFieldSet(IGridData gridData, IBMControl config) : base(gridData, config) { this.config = config; if (config.RestartInfo == null && !config.FieldOptions.ContainsKey(IBMVariables.LevelSet)) { throw new Exception( "Field 'levelSet' is required for IBM applications"); } LevelSet = new LevelSet( new Basis(gridData, config.FieldOptions[IBMVariables.LevelSet].Degree), IBMVariables.LevelSet); if (config.ContinuousLevelSet) { SpecFemBasis specFEMBasis = new SpecFemBasis((GridData)gridData, LevelSet.Basis.Degree); SpecFemField specFemField = new SpecFemField(specFEMBasis); specFemField.ProjectDGFieldMaximum(1.0, LevelSet); LevelSet.Clear(); specFemField.AccToDGField(1.0, LevelSet); } LevelSetGradient = new DGField[CompressibleEnvironment.NumberOfDimensions]; for (int d = 0; d < CompressibleEnvironment.NumberOfDimensions; d++) { LevelSetGradient[d] = DerivedFields[IBMVariables.LevelSetGradient[d]]; } }
private SinglePhaseField SpecFEMInterpolation(string fieldName, SpecFemBasis basis, MultidimensionalArray rho, MultidimensionalArray u, MultidimensionalArray v, MultidimensionalArray p, Func <double, double, double, double, double> func) { SpecFemField specFEMField = new SpecFemField(basis); int noOfNodesPerCell = noOfNodesPerEdge * noOfNodesPerEdge; int[,] cellNodeToNode = specFEMField.Basis.CellNode_To_Node; Debug.Assert(cellNodeToNode.GetLength(1) == noOfNodesPerCell); for (int i = 0; i < gridData.Grid.NoOfUpdateCells; i++) { for (int j = 0; j < noOfNodesPerCell; j++) { int matlabNodeIndex = GetLocalMatlabNodeIndex( basis.CellNodes[0][j, 0], basis.CellNodes[0][j, 1]); var indices = GetNodeIndices(i, matlabNodeIndex); specFEMField.Coordinates[cellNodeToNode[i, j]] = func( rho[indices.Item1, indices.Item2], u[indices.Item1, indices.Item2], v[indices.Item1, indices.Item2], p[indices.Item1, indices.Item2]); } } SinglePhaseField dgField = new SinglePhaseField(new Basis(gridData, dgDegree), fieldName); specFEMField.AccToDGField(1.0, dgField); return(dgField); }
/// <summary> /// Creates the LevelSet field for the Tracker based on the Option selected /// </summary> /// <param name="DGLevelSet">the unfiltered Level-set</param> /// <param name="gridData"></param> /// <param name="Option"></param> /// <returns>The filtered Level-Set Field </returns> public static LevelSet CreateField(SinglePhaseField DGLevelSet, Foundation.Grid.Classic.GridData gridData, ContinuityProjectionOption Option) { int k = DGLevelSet.Basis.Degree + 1; switch (Option) { case ContinuityProjectionOption.SpecFEM: { var ContinuousLevelSetBasis = new SpecFemBasis(gridData, k); return(new LevelSet(ContinuousLevelSetBasis.ContainingDGBasis, "Phi")); } case ContinuityProjectionOption.ConstrainedDG: { var ContinuousLevelSetDGBasis = new Basis(gridData, k); return(new LevelSet(ContinuousLevelSetDGBasis, "Phi")); } case ContinuityProjectionOption.None: { Console.WriteLine("WARNING: No additional enforcement of the level-set continuity!"); LevelSet SmoothedLevelSet = new LevelSet(DGLevelSet.Basis, "Phi"); DGLevelSet = SmoothedLevelSet; return(SmoothedLevelSet); } default: throw new ArgumentException(); } }
/// <summary> /// Selects algorithm variant based on the <paramref name="Option"/> /// </summary> /// <param name="ContBasis">DG basis for the continuous output data</param> /// <param name="DGBasis">DG basis for the discontinuous input data</param> /// <param name="gridData"></param> /// <param name="Option">Choice of algorithm</param> public ContinuityProjection(Basis ContBasis, Basis DGBasis, IGridData gridData, ContinuityProjectionOption Option) { myOption = Option; switch (Option) { case ContinuityProjectionOption.SpecFEM: { var ContinuousLevelSetBasis = new SpecFemBasis((BoSSS.Foundation.Grid.Classic.GridData)gridData, DGBasis.Degree + 1); MyProjection = new ContinuityProjectionSpecFem(ContinuousLevelSetBasis); break; } case ContinuityProjectionOption.ConstrainedDG: { MyProjection = new ContinuityProjectionCDG(ContBasis); break; } case ContinuityProjectionOption.None: { MyProjection = new NoProjection(); break; } default: throw new ArgumentException(); } }
/// <summary> /// Selects algorithm variant based on the <paramref name="Option"/> /// </summary> /// <param name="DGLevelSet">Discontinuous Field</param> /// <param name="gridData"></param> /// <param name="Option">Choice of algorithm</param> /// <param name="SmoothedLevelSet">The Continuous Field</param> public ContinuityProjection(SinglePhaseField DGLevelSet, Foundation.Grid.Classic.GridData gridData, ContinuityProjectionOption Option) { int k = DGLevelSet.Basis.Degree + 1; myOption = Option; switch (Option) { case ContinuityProjectionOption.SpecFEM: { var ContinuousLevelSetBasis = new SpecFemBasis(gridData, k); MyProjection = new ContinuityProjectionSpecFem(ContinuousLevelSetBasis); break; } case ContinuityProjectionOption.ContinuousDG: { var ContinuousLevelSetDGBasis = new Basis(gridData, k); MyProjection = new ContinuityProjectionCDG(ContinuousLevelSetDGBasis); break; } case ContinuityProjectionOption.None: { MyProjection = new NoProjection(); break; } default: throw new ArgumentException(); } }
public SinglePhaseField[] SpecFEMInterpolation(MultidimensionalArray rhoValues, MultidimensionalArray uValues, MultidimensionalArray vValues, MultidimensionalArray pValues) { SpecFemBasis basis = new SpecFemBasis(gridData, noOfNodesPerEdge); SinglePhaseField rhoField = SpecFEMInterpolation("rho", basis, rhoValues, uValues, vValues, pValues, (rho, u, v, p) => rho); SinglePhaseField u0Field = SpecFEMInterpolation("u0", basis, rhoValues, uValues, vValues, pValues, (rho, u, v, p) => u); SinglePhaseField u1Field = SpecFEMInterpolation("u1", basis, rhoValues, uValues, vValues, pValues, (rho, u, v, p) => v); SinglePhaseField m0Field = SpecFEMInterpolation("m0", basis, rhoValues, uValues, vValues, pValues, (rho, u, v, p) => rho * u); SinglePhaseField m1Field = SpecFEMInterpolation("m1", basis, rhoValues, uValues, vValues, pValues, (rho, u, v, p) => rho * v); SinglePhaseField pField = SpecFEMInterpolation("p", basis, rhoValues, uValues, vValues, pValues, (rho, u, v, p) => p); SinglePhaseField rhoEField = SpecFEMInterpolation("rhoE", basis, rhoValues, uValues, vValues, pValues, (rho, u, v, p) => p / 0.4 + 0.5 * rho * (u * u + v * v)); return(new SinglePhaseField[] { rhoField, u0Field, u1Field, pField, m0Field, m1Field, rhoEField }); }
protected override void CreateFields() { spec_basis = new SpecFemBasis((GridData)this.GridData, 4); var dg_basis = spec_basis.ContainingDGBasis; //var dg_basis = new Basis(this.GridData, 2); origin = new SinglePhaseField(dg_basis, "Origin"); specField = new SpecFemField(spec_basis); Result = new SinglePhaseField(dg_basis, "Result"); //this.GridData.Vertices.Coordinates.PlotCoordinateLabels("Coords_" + base.MPIRank + ".png"); }
private void UpdateArtificialViscosity() { // Determine piecewise constant viscosity this.ArtificialViscosityField.Clear(); // Cell masks CellMask cutCells = this.LevelSetTracker.Regions.GetCutCellMask(); CellMask speciesA_nonCut = this.LevelSetTracker.Regions.GetSpeciesMask("A").Except(cutCells); CellMask speciesB_nonCut = this.LevelSetTracker.Regions.GetSpeciesMask("B").Except(cutCells); // Calculate AV SetAVForSpecies(speciesA_nonCut, "A"); SetAVForSpecies(speciesB_nonCut, "B"); SetAVForCutCells(cutCells); // Set AV manually for testing //this.ArtificialViscosityField.Clear(); //this.ArtificialViscosityField.AccConstant(1.0); // Project visocsity onto continuous, multilinear space if (CompressibleEnvironment.NumberOfDimensions < 3) { // Standard version if (avSpecFEMBasis == null || !this.ArtificialViscosityField.Basis.Equals(avSpecFEMBasis.ContainingDGBasis)) { avSpecFEMBasis = new SpecFemBasis((GridData)this.GridData, 2); } SpecFemField specFemField = new SpecFemField(avSpecFEMBasis); specFemField.ProjectDGFieldMaximum(1.0, this.ArtificialViscosityField); this.ArtificialViscosityField.Clear(); specFemField.AccToDGField(1.0, this.ArtificialViscosityField); } else { throw new NotImplementedException("Artificial viscosity has only been tested for 2D"); } }
/// <summary> /// ctor; /// </summary> public SpecFemField(SpecFemBasis b) { m_Basis = b; m_Coordinates = MultidimensionalArray.Create(m_Basis.NoOfLocalNodes); }
/// <summary> /// Deprecated utility, writes matrices for spectral element method. /// </summary> public void WriteSEMMatrices() { int kSEM; // nodes per edge if (this.Grid.RefElements[0] is Triangle) { kSEM = this.T.Basis.Degree + 1; } else if (this.Grid.RefElements[0] is Square) { switch (this.T.Basis.Degree) { case 2: kSEM = 2; break; case 3: kSEM = 2; break; case 4: kSEM = 3; break; case 5: kSEM = 3; break; case 6: kSEM = 4; break; default: throw new NotSupportedException(); } } else { throw new NotImplementedException(); } SpecFemBasis SEM_basis = new SpecFemBasis((GridData)(this.GridData), kSEM); SEM_basis.CellNodes[0].SaveToTextFile("NODES_SEM" + kSEM + ".txt"); SEM_basis.MassMatrix.SaveToTextFileSparse("MASS_SEM" + kSEM + ".txt"); var Mod2Nod = SEM_basis.GetModal2NodalOperator(this.T.Basis); var Nod2Mod = SEM_basis.GetNodal2ModalOperator(this.T.Basis); Mod2Nod.SaveToTextFileSparse("MODAL" + this.T.Basis.Degree + "_TO_NODAL" + kSEM + ".txt"); Nod2Mod.SaveToTextFileSparse("NODAL" + kSEM + "_TO_MODAL" + this.T.Basis.Degree + ".txt"); this.LaplaceMtx.SaveToTextFileSparse("OPERATOR" + this.T.Basis.Degree + ".txt"); { var TEST = this.T.CloneAs(); TEST.Clear(); TEST.ProjectField((_2D)((x, y) => x * y)); int J = this.GridData.iGeomCells.Count; int N = SEM_basis.NodesPerCell[0]; MultidimensionalArray TEST_at_NODES = MultidimensionalArray.Create(J, N); TEST.Evaluate(0, J, SEM_basis.CellNodes[0], TEST_at_NODES); double[] CompareAtNodes = new double[J * N]; Mod2Nod.SpMVpara(1.0, TEST.CoordinateVector, 0.0, CompareAtNodes); double[] gretchen = TEST_at_NODES.ResizeShallow(J * N).To1DArray(); double fdist = GenericBlas.L2Dist(gretchen, CompareAtNodes); Debug.Assert(fdist < 1.0e-8); double[] bak = new double[TEST.Mapping.LocalLength]; Nod2Mod.SpMVpara(1.0, CompareAtNodes, 0.0, bak); double hdist = GenericBlas.L2Dist(bak, TEST.CoordinateVector); Debug.Assert(hdist < 1.0e-8); } var Scatter = SEM_basis.GetNodeScatterMatrix(); Scatter.SaveToTextFileSparse("SCATTER_SEM" + kSEM + ".txt"); { var SEMTEST = new SpecFemField(SEM_basis); var csem = SEMTEST.Coordinates; Random r = new Random(666); for (int i = 0; i < csem.GetLength(0); i++) { csem[i] = r.NextDouble(); } var DG_TEST0 = new SinglePhaseField(SEMTEST.Basis.ContainingDGBasis); var DG_TEST = this.T.CloneAs(); DG_TEST.Clear(); SEMTEST.AccToDGField(1.0, DG_TEST0); DG_TEST.AccLaidBack(1.0, DG_TEST0); double[] S2 = new double[Scatter.RowPartitioning.LocalLength]; double[] S3 = new double[DG_TEST.Mapping.LocalLength]; Scatter.SpMVpara(1.0, csem.To1DArray(), 0.0, S2); Nod2Mod.SpMVpara(1.0, S2, 0.0, S3); double gdist = GenericBlas.L2Dist(S3, DG_TEST.CoordinateVector); Debug.Assert(gdist < 1.0e-8); } }
public ContinuityProjectionSpecFem(SpecFemBasis myBasis) { FEMLevSet = new SpecFemField(myBasis); }