示例#1
0
        private void Distribute()
        {
            double equalDistributionPercentage = 0.2;
            double deltaRo                   = ro - previousRo;
            double roPerCell                 = deltaRo / (matrix.GetLength(0) * matrix.GetLength(1));
            double equalDistribution         = roPerCell * equalDistributionPercentage;
            double randomDistributionPackage = roPerCell * (1 - equalDistributionPercentage);
            double chance;

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    matrix[i, j].density += equalDistribution;
                    deltaRo -= equalDistribution;
                }
            }

            var         rand = new Random();
            List <Cell> neighbours = new List <Cell>();
            int         temp1, temp2, temp3, temp4;

            while (deltaRo > 0)
            {
                int i = rand.Next(matrix.GetLength(0));
                int j = rand.Next(matrix.GetLength(1));

                temp1 = i == 0 ? matrix.GetLength(0) - 1 : i - 1;      //i-1
                temp2 = j == 0 ? matrix.GetLength(1) - 1 : j - 1;      //j-1
                temp3 = i == matrix.GetLength(0) - 1 ? 0 : i + 1;      //i+1
                temp4 = j == matrix.GetLength(1) - 1 ? 0 : j + 1;      //j+1

                neighbours.Add(matrix[temp1, j]);
                neighbours.Add(matrix[temp3, j]);
                neighbours.Add(matrix[i, temp2]);
                neighbours.Add(matrix[i, temp4]);

                chance = 0.2;
                if (Addons.IsLimit(matrix[i, j], neighbours))
                {
                    chance = 0.8;
                }


                if (rand.NextDouble() <= chance)
                {
                    matrix[i, j].density += randomDistributionPackage;
                    deltaRo -= randomDistributionPackage;
                }
            }
        }
示例#2
0
        private void Recrystalize()
        {
            int         temp1, temp2, temp3, temp4;
            List <Cell> neighbours;
            List <Cell> temp = new List <Cell>();

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    neighbours = new List <Cell>();
                    temp1      = i == 0 ? matrix.GetLength(0) - 1 : i - 1; //i-1
                    temp2      = j == 0 ? matrix.GetLength(1) - 1 : j - 1; //j-1
                    temp3      = i == matrix.GetLength(0) - 1 ? 0 : i + 1; //i+1
                    temp4      = j == matrix.GetLength(1) - 1 ? 0 : j + 1; //j+1

                    neighbours.Add(matrix[temp1, j]);
                    neighbours.Add(matrix[temp3, j]);
                    neighbours.Add(matrix[i, temp2]);
                    neighbours.Add(matrix[i, temp4]);

                    if (matrixPreviousIteration.Any(_ => neighbours.Select(x => x.id).Contains(_.id)) &&
                        matrix[i, j].density > neighbours.Max(x => x.density))
                    {
                        matrix[i, j].isRecrystal = true;
                        matrix[i, j].density     = 0;
                        temp.Add(matrix[i, j]);
                    }

                    if (matrix[i, j].density > criticalRo && Addons.IsLimit(matrix[i, j], neighbours))
                    {
                        matrix[i, j].isRecrystal = true;
                        matrix[i, j].density     = 0;
                        temp.Add(matrix[i, j]);
                    }
                }
            }
            matrixPreviousIteration = temp;
        }