internal string[] GetInCodeIdentifications(FieldInfo fi, int D) { if (m_FieldIdentifications != null) { if (m_CapDimension) { if (m_FieldIdentifications.Length < D) { throw new ApplicationException("Length of field identification vector is to small; (Field '" + fi.Name + "')"); } return(ArrayTools.GetSubVector(m_FieldIdentifications, 0, D)); } else { if (m_FieldIdentifications.Length != D) { throw new ApplicationException("Mismatch in Length of field identification vector; (Field '" + fi.Name + "')"); } return(m_FieldIdentifications); } } else { throw new ApplicationException("For vector fields, the in-code identification is mandatory; (Field '" + fi.Name + "')"); } }
internal string[] GetControlFileNames(FieldInfo fi, int D) { if (m_ControlFileNames != null) { if (m_CapDimension) { if (m_ControlFileNames.Length < D) { throw new ApplicationException("error initializing vector field '" + fi.Name + "': mismatch in spatial dimension."); } return(ArrayTools.GetSubVector(m_ControlFileNames, 0, D)); } else { if (m_ControlFileNames.Length != D) { throw new ApplicationException("error initializing vector field '" + fi.Name + "': mismatch in spatial dimension."); } return(m_ControlFileNames); } } else { return(GetInCodeIdentifications(fi, D)); } }
private double[] GetAuxAccVec(BlockMaskBase mask, IList <double> fullVector, int iCell) { int nCell = mask.GetType() == typeof(BlockMaskExt)? iCell - BMLoc.m_StructuredNi0.Length:iCell; double[] subVector = new double[mask.GetLengthOfCell(nCell)]; var Cidx = mask.GetLocalidcOfCell(nCell); Debug.Assert(subVector.Length == Cidx.Length); ArrayTools.GetSubVector <int[], int[], double>(fullVector, subVector, Cidx); return(subVector); }
public int[] GetSubblk_i0(int blockType) { if (m_j0Subblk_i0 == null) { m_j0Subblk_i0 = ArrayTools.GetSubVector(this.m_j0CoordinateIndex, 0, this.m_BasisS.Length); } #if DEBUG if (m_j0Subblk_i0_Backup == null) { m_j0Subblk_i0_Backup = m_j0Subblk_i0.CloneAs(); } else { Debug.Assert(ArrayTools.ListEquals <int>(m_j0Subblk_i0, m_j0Subblk_i0_Backup), "Some moron messed with the start indices."); } #endif return(m_j0Subblk_i0); }
/// <summary> /// flux at the boundary /// </summary> double BorderEdgeFlux(ref Foundation.CommonParamsBnd inp, double[] Uin) { IncompressibleBcType edgeType = m_bcmap.EdgeTag2Type[inp.EdgeTag]; switch (edgeType) { case IncompressibleBcType.Wall: { if ((edgeType == IncompressibleBcType.Wall) && (m_bcmap.PhysMode == PhysicsMode.Multiphase)) { throw new ApplicationException("Use NoSlipNeumann boundary condition for multiphase flows instead of Wall."); } double r = 0.0; // Setup params // ============ Foundation.CommonParams inp2; inp2.GridDat = inp.GridDat; inp2.Normal = inp.Normal; inp2.iEdge = inp.iEdge; inp2.Parameters_IN = inp.Parameters_IN; inp2.X = inp.X; inp2.time = inp.time; inp2.jCellIn = inp.jCellIn; inp2.jCellOut = int.MinValue; // Boundary values for Parameters // ============================== inp2.Parameters_OUT = new double[inp.Parameters_IN.Length]; // Dirichlet values for scalars and Velocities // ========================== double[] Uout = new double[Uin.Length]; //Velocity for (int i = 0; i < m_SpatialDimension; i++) { Uout[i] = m_bcmap.bndFunction[VariableNames.Velocity_d(i)][inp.EdgeTag](inp.X, inp.time); } switch (m_bcmap.PhysMode) { case PhysicsMode.MixtureFraction: // opt1: //inp2.Parameters_OUT = inp.Parameters_IN; Uout[m_SpatialDimension] = m_bcmap.bndFunction[VariableNames.MixtureFraction][inp.EdgeTag](inp.X, inp.time); break; case PhysicsMode.LowMach: { Uout[m_SpatialDimension] = m_bcmap.bndFunction[VariableNames.Temperature][inp.EdgeTag](inp.X, inp.time); break; } case PhysicsMode.Combustion: { // opt1: (using Dirichlet values) Uout[m_SpatialDimension] = m_bcmap.bndFunction[VariableNames.Temperature][inp.EdgeTag](inp.X, inp.time); for (int n = 1; n < NumberOfReactants - 1 + 1; n++) { //Using inner values for species Uout[m_SpatialDimension + n] = Uin[m_SpatialDimension + n]; } break; } case PhysicsMode.Multiphase: break; default: throw new NotImplementedException(); } // Calculate BorderEdgeFlux as InnerEdgeFlux // ========================================= r = InnerEdgeFlux(ref inp2, Uin, Uout); if (double.IsNaN(r)) { throw new NotFiniteNumberException(); } return(r); } case IncompressibleBcType.Velocity_Inlet: { if ((edgeType == IncompressibleBcType.Wall) && (m_bcmap.PhysMode == PhysicsMode.Multiphase)) { throw new ApplicationException("Use NoSlipNeumann boundary condition for multiphase flows instead of Wall."); } double r = 0.0; // Setup params // ============ Foundation.CommonParams inp2; inp2.GridDat = inp.GridDat; inp2.Normal = inp.Normal; inp2.iEdge = inp.iEdge; inp2.Parameters_IN = inp.Parameters_IN; inp2.X = inp.X; inp2.time = inp.time; inp2.jCellIn = inp.jCellIn; inp2.jCellOut = int.MinValue; // Boundary values for Parameters // ============================== inp2.Parameters_OUT = new double[inp.Parameters_IN.Length]; double[] Uout = new double[Uin.Length]; // Velocity for (int j = 0; j < m_SpatialDimension; j++) { // opt1: Uout[j] = m_bcmap.bndFunction[VariableNames.Velocity_d(j)][inp.EdgeTag](inp.X, inp.time); } // Skalar (e.g. temperature or MassFraction) switch (m_bcmap.PhysMode) { case PhysicsMode.MixtureFraction: { // opt1: Uout[m_SpatialDimension] = m_bcmap.bndFunction[VariableNames.MixtureFraction][inp.EdgeTag](inp.X, inp.time); break; } case PhysicsMode.LowMach: { // opt1: Uout[m_SpatialDimension] = m_bcmap.bndFunction[VariableNames.Temperature][inp.EdgeTag](inp.X, inp.time); // opt2: inner values //inp2.Parameters_OUT[2 * m_SpatialDimension] = inp2.Parameters_IN[2 * m_SpatialDimension]; break; } case PhysicsMode.Combustion: { // opt1: (using Dirichlet values) Uout[m_SpatialDimension] = m_bcmap.bndFunction[VariableNames.Temperature][inp.EdgeTag](inp.X, inp.time); for (int n = 1; n < NumberOfReactants; n++) { // opt1: (using Dirichlet values) Uout[m_SpatialDimension + n] = m_bcmap.bndFunction[VariableNames.MassFraction_n(n - 1)][inp.EdgeTag](inp.X, inp.time); } break; } case PhysicsMode.Multiphase: break; default: throw new NotImplementedException(); } // Calculate BorderEdgeFlux as InnerEdgeFlux // ========================================= r = InnerEdgeFlux(ref inp2, Uin, Uout); if (double.IsNaN(r)) { throw new NotFiniteNumberException(); } return(r); } case IncompressibleBcType.Pressure_Dirichlet: case IncompressibleBcType.Outflow: case IncompressibleBcType.Pressure_Outlet: case IncompressibleBcType.NoSlipNeumann: { double r = 0.0; double u1, u2, u3 = 0; u1 = Uin[0]; u2 = Uin[1]; r += Uin[argumentIndex] * (u1 * inp.Normal[0] + u2 * inp.Normal[1]); if (m_SpatialDimension == 3) { u3 = Uin[2]; r += Uin[argumentIndex] * u3 * inp.Normal[2]; } double rho = 1.0; switch (m_bcmap.PhysMode) { case PhysicsMode.Incompressible: break; case PhysicsMode.MixtureFraction: rho = EoS.getDensityFromZ(Uin[inp.D]); break; case PhysicsMode.LowMach: rho = EoS.GetDensity(Uin[argumentIndex]); break; case PhysicsMode.Combustion: double[] args = ArrayTools.GetSubVector(Uin, m_SpatialDimension, NumberOfReactants - 1 + 1); rho = EoS.GetDensity(args); break; default: throw new NotImplementedException("not implemented physmode"); } r *= rho; if (double.IsNaN(r)) { throw new NotFiniteNumberException(); } return(r); } default: throw new NotImplementedException("Boundary condition not implemented!"); } }
/// <summary> /// Converts C# to 'LaTeX-escaped C#' /// </summary> public static string Bws2Tex(string Command) { if (Command == null) { Command = ""; } // split Command into multiple lines. string[] CommandLines = Command.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None); // remove trailing empty lines while (CommandLines.Length > 0) { if (CommandLines[CommandLines.Length - 1].IsEmptyOrWhite()) { CommandLines = ArrayTools.GetSubVector(CommandLines, 0, CommandLines.Length - 1); } else { break; } } // write command using (var stw = new StringWriter()) { for (int k = 0; k < CommandLines.Length; k++) { string ln = CommandLines[k]; string lineWoW = ln.TrimStart(' ', '\t'); if (lineWoW.StartsWith("///")) { // ++++++++++++++++ // LaTeX - verbatim // ++++++++++++++++ // write line if (k < CommandLines.Length - 1) { stw.WriteLine(ln); } else { stw.Write(ln); } } else { // global operations // ================= ln = ln.Replace("\\", "\\textbackslash "); ln = ln.Replace("{", "\\{"); ln = ln.Replace("}", "\\}"); ln = ln.Replace("\t", "\btab "); ln = ln.Replace("\r", ""); //ln = ln.Replace("\n", "\\newline "); ln = ln.Replace("_", "\\_"); ln = ln.Replace("%", "\\%"); // per-line operations // =================== // leading tabs/white-spaces: replace with "\btab" //for (int i = 0; i < CommandLines.Length; i++) { if (ln.IsEmptyOrWhite()) { ln = " "; } int NoOfIntendTabs = 0; while (ln.StartsWith(" ")) { ln = ln.Substring(4); NoOfIntendTabs++; } for (int j = 0; j < NoOfIntendTabs; j++) { ln = "\\btab " + ln; } //} // write line if (k < CommandLines.Length - 1) { stw.WriteLine(ln + "\\newline "); } else { stw.Write(ln); } } } // return // ====== string ret = stw.ToString(); if (ret.IsEmptyOrWhite()) { // completly empty commands return(" % "); } else { return(ret); } } }
/// <summary> /// ~ /// </summary> public void Solve <U, V>(U X, V B) where U : IList <double> where V : IList <double> // { int Lf = m_op.Mapping.LocalLength; int Lc = m_LsubIdx.Length; if (Res_f == null || Res_f.Length != Lf) { Res_f = new double[Lf]; } if (Res_c == null || Res_c.Length != Lc) { Res_c = new double[Lc]; } else { Res_c.ClearEntries(); } if (Cor_c == null || Cor_c.Length != Lc) { Cor_c = new double[Lc]; } var Mtx = m_op.OperatorMatrix; // compute fine residual Res_f.SetV(B); Mtx.SpMV(-1.0, X, 1.0, Res_f); // project to low-p/coarse Res_c.AccV(1.0, Res_f, default(int[]), m_LsubIdx); // low-p solve intSolver.Solve(Cor_c, Res_c); // accumulate low-p correction X.AccV(1.0, Cor_c, m_LsubIdx, default(int[])); double[] Xbkup = X.ToArray(); // solver high-order // compute residual of low-order solution Res_f.SetV(B); Mtx.SpMV(-1.0, X, 1.0, Res_f); var Map = m_op.Mapping; int NoVars = Map.AggBasis.Length; int j0 = Map.FirstBlock; int J = Map.LocalNoOfBlocks; int[] degs = m_op.Degrees; var BS = Map.AggBasis; int Mapi0 = Map.i0; double[] b_f = null, x_hi = null; for (int j = 0; j < J; j++) { if (HighOrderBlocks_LU[j] != null) { int NpTotHi = HighOrderBlocks_LU[j].NoOfRows; if (b_f == null || b_f.Length != NpTotHi) { b_f = new double[NpTotHi]; x_hi = new double[NpTotHi]; } ArrayTools.GetSubVector <int[], int[], double>(Res_f, b_f, HighOrderBlocks_indices[j]); HighOrderBlocks_LU[j].BacksubsLU(HighOrderBlocks_LUpivots[j], x_hi, b_f); X.AccV(1.0, x_hi, HighOrderBlocks_indices[j], default(int[])); } } //compute residual for Callback Res_f.SetV(B); Mtx.SpMV(-1.0, X, 1.0, Res_f); if (IterationCallback != null) { IterationCallback(0, X.ToArray(), Res_f, m_op); } }