protected override void AdaptMesh(int TimestepNo, out GridCommons newGrid, out GridCorrelation old2NewGrid) { if (TimestepNo > 3 && TimestepNo % 3 != 0) { //{ newGrid = null; old2NewGrid = null; return; } // Check grid changes // ================== bool AnyChange; List <int> CellsToRefineList; List <int[]> Coarsening; GridRefinementController gridRefinementController = new GridRefinementController((GridData)this.GridData, LsTrk.Regions.GetCutCellMask()); if (MPISize > 1) { List <Tuple <int, BitArray> > cellMaskRefinementLevel = GetCellMaskWithRefinementLevels(); AnyChange = gridRefinementController.ComputeGridChange(cellMaskRefinementLevel, out CellsToRefineList, out Coarsening); } else { AnyChange = gridRefinementController.ComputeGridChange(LevelIndicator, out CellsToRefineList, out Coarsening); } int NoOfCellsToRefine = 0; int NoOfCellsToCoarsen = 0; if (AnyChange) { int[] glb = (new int[] { CellsToRefineList.Count, Coarsening.Sum(L => L.Length), }).MPISum(); NoOfCellsToRefine = glb[0]; NoOfCellsToCoarsen = glb[1]; } int oldJ = this.GridData.CellPartitioning.TotalLength; // Update Grid // =========== if (AnyChange) { Console.WriteLine(" Refining " + NoOfCellsToRefine + " of " + oldJ + " cells"); Console.WriteLine(" Coarsening " + NoOfCellsToCoarsen + " of " + oldJ + " cells"); newGrid = ((GridData)this.GridData).Adapt(CellsToRefineList, Coarsening, out old2NewGrid); } else { newGrid = null; old2NewGrid = null; } }
/// <summary> /// control of mesh adaptation /// </summary> protected override void AdaptMesh(int TimestepNo, out GridCommons newGrid, out GridCorrelation old2NewGrid) { if (this.Control.AdaptiveMeshRefinement && TimestepNo > 1) { int oldJ = this.GridData.CellPartitioning.TotalLength; double LocNormPow2 = this.ResiualKP1.CoordinateVector.L2NormPow2(); // norm of residual on this processor double TotNormPow2 = LocNormPow2.MPISum(); // norm of residual over all processors double MeanNormPow2PerCell = TotNormPow2 / oldJ; // mean norm per cell double maxSoFar = 0; int jMax = -1; for (int j = 0; j < oldJ; j++) { double CellNorm = Error.Coordinates.GetRow(j).L2NormPow2(); if (CellNorm > maxSoFar) { jMax = j; maxSoFar = CellNorm; } } int LevelIndicator(int j, int CurrentLevel) { double CellNorm = this.ResiualKP1.Coordinates.GetRow(j).L2NormPow2(); if (j == jMax) { return(CurrentLevel + 1); } else { return(CurrentLevel); } } bool AnyChange = GridRefinementController.ComputeGridChange((GridData)(this.GridData), null, LevelIndicator, out List <int> CellsToRefineList, out List <int[]> Coarsening); int NoOfCellsToRefine = 0; int NoOfCellsToCoarsen = 0; if (AnyChange) { int[] glb = (new int[] { CellsToRefineList.Count, Coarsening.Sum(L => L.Length), }).MPISum(); NoOfCellsToRefine = glb[0]; NoOfCellsToCoarsen = glb[1]; } // Update Grid // =========== if (AnyChange) { Console.WriteLine(" Refining " + NoOfCellsToRefine + " of " + oldJ + " cells"); Console.WriteLine(" Coarsening " + NoOfCellsToCoarsen + " of " + oldJ + " cells"); newGrid = ((GridData)(this.GridData)).Adapt(CellsToRefineList, Coarsening, out old2NewGrid); } else { newGrid = null; old2NewGrid = null; } } else { newGrid = null; old2NewGrid = null; } }