/// <summary> /// Diagnostic output. /// </summary> /// <param name="cout"></param> /// <param name="time"></param> public static void PrintCellSpecisTable(LevelSetTracker LsTrk, TextWriter cout, double time) { int J = LsTrk.GridDat.Cells.NoOfLocalUpdatedCells; cout.WriteLine("Species at time {0}: ==============", time); Console.WriteLine("j\tDist\t#Spc\t"); for (int j = 0; j < J; j++) { // cell index cout.Write(j); cout.Write("\t"); // level-set distance int dist = LevelSetTracker.DecodeLevelSetDist(LsTrk.Regions.RegionsCode[j], 0); cout.Write(dist); cout.Write("\t"); // number of species in cell ReducedRegionCode rrc; int NoOfSpc = LsTrk.Regions.GetNoOfSpecies(j, out rrc); cout.Write(NoOfSpc); cout.Write("\t"); // species sequence for (int iSpc = 0; iSpc < NoOfSpc; iSpc++) { var SpId = LsTrk.GetSpeciesIdFromIndex(rrc, iSpc); var SpNm = LsTrk.GetSpeciesName(SpId); cout.Write(SpNm); if (iSpc < (NoOfSpc - 1)) { cout.Write(","); } } cout.Write("\t"); // new 2 old int[] N2O = TimeSteppingUtils.SpeciesUpdate(LsTrk, j, true); cout.Write("new2old: "); if (N2O != null) { for (int i = 0; i < N2O.Length; i++) { cout.Write(N2O[i]); if (i < (N2O.Length - 1)) { cout.Write(","); } } } else { cout.Write("-"); } cout.Write("\t"); // old 2 new int[] O2N = TimeSteppingUtils.SpeciesUpdate(LsTrk, j, false); cout.Write("old2new: "); if (O2N != null) { for (int i = 0; i < O2N.Length; i++) { cout.Write(O2N[i]); if (i < (O2N.Length - 1)) { cout.Write(","); } } } else { cout.Write("-"); } cout.Write("\t"); // end-of-line cout.WriteLine(); } cout.WriteLine("---------------------"); }
/// <summary> /// Computes a mapping from the new species index to the old species index, or vice-versa. /// </summary> /// <param name="jCell"> /// Local cell index. /// </param> /// <param name="New2Old"> /// If true, a mapping from new species index to previous/old species index is returned, /// if false the other way around. /// </param> /// <param name="LsTrk"> /// </param> /// <returns> /// Null, if there is no change in species ordering in cell <paramref name="jCell"/> /// from the previous level-set tracker state to the actual. /// /// Otherwise, if <paramref name="New2Old"/> is true, an array of the same length /// as the number of species currently in cell <paramref name="jCell"/>. /// - index: current species index in cell <paramref name="jCell"/>. /// - content: index of this species with respect to the previous level-set-tracker state. /// If <paramref name="New2Old"/> false, the other way around. /// </returns> public static int[] SpeciesUpdate(LevelSetTracker LsTrk, int jCell, bool New2Old) { ushort[] OldCode = LsTrk.RegionsHistory[0].RegionsCode; ushort[] NewCode = LsTrk.RegionsHistory[1].RegionsCode; // Only if the return value of this function is positive, a mapping from current species index to previous species index // - index: current species index in cell <paramref name="jCell"/>. // - content: index of this species with respect to the previous level-set-tracker state. int[] UpdateMap = null; bool AnyUpdate = false; ushort oc = OldCode[jCell]; ushort nc = NewCode[jCell]; if (!New2Old) { // swap old and new ushort b = oc; oc = nc; nc = b; } ReducedRegionCode oldRRC, newRRC; int OldNoOfSpc = LsTrk.GetNoOfSpeciesByRegionCode(oc, out oldRRC); int NewNoOfSpc = LsTrk.GetNoOfSpeciesByRegionCode(nc, out newRRC); for (int new_iSpc = 0; new_iSpc < NewNoOfSpc; new_iSpc++) { SpeciesId spId = LsTrk.GetSpeciesIdFromIndex(newRRC, new_iSpc); int old_iSpc = LsTrk.GetSpeciesIndex(oldRRC, spId); // if the species was not present in the previous state, this should be negative if (old_iSpc != new_iSpc) { if (AnyUpdate == false) { // init the update map: no change up to index 'new_iSpc' AnyUpdate = true; UpdateMap = new int[NewNoOfSpc]; for (int i = 0; i < new_iSpc; i++) { UpdateMap[i] = i; } } // index 'new_iSpc' maps to old species index UpdateMap[new_iSpc] = old_iSpc; } } if (NewNoOfSpc < OldNoOfSpc) { // the number of species is reduced - this also counts as change if (AnyUpdate == false) { // init the update map: no change up to index 'new_iSpc' AnyUpdate = true; UpdateMap = new int[NewNoOfSpc]; for (int i = 0; i < NewNoOfSpc; i++) { UpdateMap[i] = i; } } } // return return(UpdateMap); }