/// <summary> /// performs some timesteps /// </summary> protected override double RunSolverOneStep(int TimestepNo, double phystime, double dt) { using (var ft = new FuncTrace()) { //PerformanceVsCachesize(); //SimplifiedPerformance(); //u.ProjectField((_2D)((x, y) => x+y)); //var f = new SinglePhaseField(u.Basis, "f"); //var sgrd = new SubGrid(new CellMask(this.GridDat, Chunk.GetSingleElementChunk(200))); //f.Clear(); //f.DerivativeByFlux(1.0, u, 0, sgrd, true); //Tecplot plt1 = new Tecplot(GridDat, true, false, 0); //plt1.PlotFields("ggg" , "Scalar Transport", phystime, u, f, mpi_rank); //base.TerminationKey = true; double dtCFL; if (this.GridData is GridData) { dtCFL = this.GridData.ComputeCFLTime(this.Velocity, 1.0e10); } else { Console.WriteLine("Nix CFL"); dtCFL = 1e-3; } if (dt <= 0) { // if dt <= 0, we're free to set the timestep on our own //base.NoOfTimesteps = -1; //dt = 1; base.NoOfTimesteps = 10; base.EndTime = 5.0; dtCFL *= 1.0 / (((double)u.Basis.Degree).Pow2()); } Console.Write("Timestp. #" + TimestepNo + " of " + base.NoOfTimesteps + " ... \t"); dt = dtCFL * 0.5; Timestepper.Perform(dt); // set mpi_rank int J = this.GridData.iLogicalCells.NoOfLocalUpdatedCells; double rank = GridData.MpiRank; for (int j = 0; j < J; j++) { mpi_rank.SetMeanValue(j, rank); } //dt = Timestepper.PerformAdaptive(1.0e2); Console.WriteLine("finished (dt = {0:0.###E-00}, CFL frac = {1:0.###E-00})!", dt, dt / dtCFL); return(dt); } }
/// <summary> /// assigns the cell index of the aggregated cell <em>j</em> to all (fine) grid cells that /// the aggregated cell <em>j</em> consists of. /// </summary> static public void ColorDGField(this AggregationGrid ag, DGField f) { if (!object.ReferenceEquals(f.GridDat, ag.AncestorGrid)) { throw new ArgumentException("mismatch in base grid."); } f.Clear(); int J = ag.iLogicalCells.NoOfLocalUpdatedCells; for (int j = 0; j < J; j++) // loog over logical/aggregate cells { int[] Neighs = ag.iLogicalCells.CellNeighbours[j]; var NeighColors = Neighs.Select(jNeigComp => (int)Math.Round(f.GetMeanValue(ag.iLogicalCells.AggregateCellToParts[jNeigComp][0]))); int iCol = 1; for (iCol = 1; iCol < 2 * J; iCol++) { if (!NeighColors.Contains(iCol)) { break; } } foreach (int jGeom in ag.iLogicalCells.AggregateCellToParts[j]) { f.SetMeanValue(jGeom, iCol); //f.SetMeanValue(jGeom, j); } } }
/// <summary> /// accumulates (to field <paramref name="f"/>), in every cell the /// distance form the cut cells times <paramref name="alpha"/>; /// Note: this is NOT the geometric distance, but the distance index /// that identifies the 'Near+1' , 'Near-1', 'Near+2', ..., - layers. /// </summary> public static void AccLevelSetDist(this DGField f, double alpha, LevelSetTracker LevSetTrk, int LevSetIdx) { int J = f.Basis.GridDat.iLogicalCells.NoOfLocalUpdatedCells; var r = LevSetTrk.Regions; for (int j = 0; j < J; j++) { int dist = LevelSetTracker.DecodeLevelSetDist(r.m_LevSetRegions[j], 0); f.SetMeanValue(j, f.GetMeanValue(j) + dist * alpha); } }
/// <summary> /// accumulates (to field <paramref name="f"/>), in every cell the /// number of species times <paramref name="alpha"/> /// </summary> public static void AccNoOfSpecies(this DGField f, double alpha, LevelSetTracker LevSetTrk, int LevSetIdx) { int J = f.Basis.GridDat.iLogicalCells.NoOfLocalUpdatedCells; var r = LevSetTrk.Regions; for (int j = 0; j < J; j++) { ReducedRegionCode rrc; int NoOfSpec = r.GetNoOfSpecies(j, out rrc); f.SetMeanValue(j, f.GetMeanValue(j) + NoOfSpec * alpha); } }
/// <summary> /// assigns the cell index of the aggregated cell <em>j</em> to all (fine) grid cells that /// the aggregated cell <em>j</em> consists of. /// </summary> static public void ColorDGField(this AggregationGridData ag, DGField f) { IGridData Anc = f.GridDat; if (!IsAnc(Anc, ag)) { throw new ArgumentException("Field 'f' must be defined on an ancestor grid of 'ag'."); } f.Clear(); int Jag = ag.iLogicalCells.NoOfLocalUpdatedCells; int Janc = Anc.iLogicalCells.NoOfLocalUpdatedCells; Debug.Assert(Anc.iGeomCells.Count == ag.iGeomCells.Count); int[] jG2jL = Anc.iGeomCells.GeomCell2LogicalCell; int[] Colors = new int[Jag]; BitArray Marked = new BitArray(Janc); for (int j = 0; j < Jag; j++) // loop over logical/aggregate cells // determine colors of neighbor cells { int[] Neighs = ag.iLogicalCells.CellNeighbours[j]; var NeighColors = Neighs.Select(jN => Colors[jN]); // select color for cell 'j' int iCol = 1; for (iCol = 1; iCol < 2 * Jag; iCol++) { if (!NeighColors.Contains(iCol)) { break; } } Colors[j] = iCol; // color all logical cells in ancestor grid // idea: convert to geometrical and back to logical // in this way we can e.g. skip multiple grid levels foreach (int jGeom in ag.iLogicalCells.AggregateCellToParts[j]) { int jLogAnc; if (jG2jL != null) { jLogAnc = jG2jL[jGeom]; } else { jLogAnc = jGeom; } if (!Marked[jLogAnc]) { f.SetMeanValue(jLogAnc, iCol); Marked[jLogAnc] = true; } else { // nop } } } }