public static bool isPointOnGrainBorder(Tuple <int, int> point, Grain[,] grain_structure) { HashSet <int> neighbors_IDs = new HashSet <int>(); for (int i = point.Item1 - 1; i <= point.Item1 + 1; ++i) { if (i < 0 || i > grain_structure.GetLength(0) - 1) { continue; } for (int j = point.Item2 - 1; j <= point.Item2 + 1; ++j) { if (j < 0 || j > grain_structure.GetLength(0) - 1) { continue; } neighbors_IDs.Add(grain_structure[i, j].ID); } } if (neighbors_IDs.Count > 1) { return(true); } return(false); }
private void mc_proceedSingleCellMonteCarlo(Tuple <int, int> cell, Grain[,] space, bool recrystalization = false) { int x = cell.Item1; int y = cell.Item2; int dim = space.GetLength(0); double initial_energy = mc_getCellEnergy(x, y, space); var previous_ID = space[x, y].ID; mc_changeID(x, y, dim, space, recrystalization); double post_change_energy = mc_getCellEnergy(x, y, space); double energy_difference = post_change_energy - initial_energy; //Console.WriteLine("Energy difference = {0}", energy_difference); if (energy_difference < 0) { // Keep new state, update color space[x, y].color = grain_ID_Color_dict[space[x, y].ID]; var t = true; } else { // Revert change space[x, y].ID = previous_ID; } }
private double mc_getCellEnergy(int x, int y, Grain[,] space, double Jgb = 1.0) { int dim = space.GetLength(0); int number_of_neighbors_with_different_ID = mc_getNumberOfNeighborsWithDifferentID(x, y, dim, space); double energy = Jgb * number_of_neighbors_with_different_ID; return(energy); }
public static List <Tuple <int, int> > findGrainBoundaries(Grain[,] grain_structure) { List <Tuple <int, int> > border = new List <Tuple <int, int> >(); for (var x = 0; x < grain_structure.GetLength(0); ++x) { for (var y = 0; y < grain_structure.GetLength(0); ++y) { Tuple <int, int> point = new Tuple <int, int>(x, y); if (isPointOnGrainBorder(point, grain_structure)) { border.Add(point); } } } return(border); }
public static bool haveNeighborhood(Grain [,] grains, int i, int j) { List <Grain> GrainNeighbour = new List <Grain>(); int iprev = 0; int inext = 0; int jprev = 0; int jnext = 0; nonPeriodic(ref iprev, ref jprev, ref inext, ref jnext, i, j, grains.GetLength(1), grains.GetLength(0)); if (grains[iprev, j].ID > 0) { return(true); } else { return(false); } }