Пример #1
0
        private bool isAnyNeighbourRecrystlizatedPeriodicCondition(int i, int j, int neighbourhood, int numberOfBoard)
        {
            if (recrystalizationBoard[numberOfBoard, BoardGameOfLife.mod(i - 1, sizeM), j])
            {
                return(true);
            }
            if (recrystalizationBoard[numberOfBoard, BoardGameOfLife.mod(i + 1, sizeM), j])
            {
                return(true);
            }
            if (recrystalizationBoard[numberOfBoard, i, BoardGameOfLife.mod(j + 1, sizeN)])
            {
                return(true);
            }
            if (recrystalizationBoard[numberOfBoard, i, BoardGameOfLife.mod(j - 1, sizeN)])
            {
                return(true);
            }
            if (neighbourhood == 1 || neighbourhood == 2)
            {
                if (recrystalizationBoard[numberOfBoard, BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                          BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)])
                {
                    return(true);
                }
                if (recrystalizationBoard[numberOfBoard, BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                          BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)])
                {
                    return(true);
                }
            }

            if (neighbourhood == 1 || neighbourhood == 3)
            {
                if (recrystalizationBoard[numberOfBoard, BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                          BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)])
                {
                    return(true);
                }
                if (recrystalizationBoard[numberOfBoard, BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                          BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)])
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        public void computeMonteCarloPeriodicCondition(int numberOfBoard, double ktFactor)
        {
            bool[,] checkedArray = new bool[sizeM, sizeN];
            int i;
            int j;

            for (int k = 0; k < sizeN * sizeM; k++)
            {
                do
                {
                    i = rnd.Next(1, sizeM - 1);
                    j = rnd.Next(1, sizeN - 1);
                } while (checkedArray[i, j]);
                i = rnd.Next(sizeM);
                j = rnd.Next(sizeN);
                var arr = new List <int>();
                arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM), j));
                arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM), j));
                arr.Add(boards[numberOfBoard].getValue(i, BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                arr.Add(boards[numberOfBoard].getValue(i, BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                                       BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                                       BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                                       BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                                       BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));

                int    energy          = arr.Count(x => x != boards[numberOfBoard].getValue(i, j));
                int    temporaryValue  = arr[rnd.Next(0, arr.Count - 1)];
                int    temporaryEnergy = arr.Count(x => x != temporaryValue);
                int    deltaEnergy     = temporaryEnergy - energy;
                double p = rnd.NextDouble();
                if (deltaEnergy < 0)
                {
                    boards[numberOfBoard].setValue(i, j, temporaryValue);
                }
                else if (p < Math.Exp(-((deltaEnergy) / (ktFactor))))
                {
                    boards[numberOfBoard].setValue(i, j, temporaryValue);
                }
            }
        }
Пример #3
0
 public void calculateEnergyPeriodicCondition(int numberOfBoard)
 {
     for (int i = 0; i < sizeM; i++)
     {
         for (int j = 0; j < sizeN; j++)
         {
             var arr = new List <int>();
             arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM), j));
             arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM), j));
             arr.Add(boards[numberOfBoard].getValue(i, BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
             arr.Add(boards[numberOfBoard].getValue(i, BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
             arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                                    BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
             arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                                    BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
             arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                                    BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
             arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                                    BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
             boards[numberOfBoard].setEnergy(i, j, arr.Count(x => x != boards[numberOfBoard].getValue(i, j)));
         }
     }
 }
Пример #4
0
        public double computeRecrystalizationStepPeriodicCondition(int numberOfBoard, double A, double B, double timeStep, double xPercentage, double criticalRo, int neighbourhood)
        {
            bool[,] tmpRecrystalizationBoard = new bool[sizeM, sizeN];
            var    arr = new List <TemporaryCell>();
            var    arrRecrystalizated = new List <bool>();
            double ro        = calculateRo(A, B, timeStep);
            double deltaRo   = ro - previousRo;
            double averageRo = deltaRo / (sizeM * sizeN);

            scatterAverageRoToBoardPeriodicCondition(numberOfBoard, averageRo * xPercentage);
            scatterRoWithProbabilityPeriodicCondition(numberOfBoard, averageRo - averageRo * xPercentage);
            for (int i = 0; i < sizeM; i++)
            {
                for (int j = 0; j < sizeN; j++)
                {
                    if (boards[numberOfBoard].getDislocationDensity(i, j) > criticalRo)
                    {
                        boards[(numberOfBoard + 1) % 2].setDislocationDensity(i, j, 0);
                        boards[(numberOfBoard + 1) % 2].makeRecrystalizated(i, j);
                        tmpRecrystalizationBoard[i, j] = true;
                        continue;
                    }
                    if (isAnyNeighbourRecrystlizatedPeriodicCondition(i, j, 0, numberOfBoard))
                    {
                        if (neighbourhood == 0 || neighbourhood == 1 || neighbourhood == 2 || neighbourhood == 3)
                        {
                            arr.Add(boards[numberOfBoard].getDislocationDensityAndRecrystalizated(BoardGameOfLife.mod(i - 1, sizeM), j));
                            arr.Add(boards[numberOfBoard].getDislocationDensityAndRecrystalizated(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM), j));
                            arr.Add(boards[numberOfBoard].getDislocationDensityAndRecrystalizated(i, BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                            arr.Add(boards[numberOfBoard].getDislocationDensityAndRecrystalizated(i, BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                            if (neighbourhood == 1 || neighbourhood == 2)
                            {
                                arr.Add(boards[numberOfBoard].getDislocationDensityAndRecrystalizated(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                                                                                      BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                                arr.Add(boards[numberOfBoard].getDislocationDensityAndRecrystalizated(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                                                                                      BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                            }

                            if (neighbourhood == 1 || neighbourhood == 3)
                            {
                                arr.Add(boards[numberOfBoard].getDislocationDensityAndRecrystalizated(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                                                                                      BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                                arr.Add(boards[numberOfBoard].getDislocationDensityAndRecrystalizated(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                                                                                      BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                            }
                        }
                    }
                    boards[(numberOfBoard + 1) % 2].setDislocationDensity(i, j, boards[numberOfBoard].getDislocationDensity(i, j));
                }
            }

            //for (int i = 0; i < sizeM; i++)
            //{
            //    for (int j = 0; j < sizeN; j++)
            //    {
            //        recrystalizationBoard[i, j] = tmpRecrystalizationBoard[i, j];
            //    }
            //}
            //recrystalizationBoard = tmpRecrystalizationBoard;

            previousRo = deltaRo;
            return(ro);
        }
Пример #5
0
        public void computeStepPeriodicBoundaryCondition(int numberOfBoard, int radius = 0, int neighbourhood = 0)
        {
            int skippingCounter    = 0;
            int firstNeighbourhood = neighbourhood;

            for (int i = 0; i < boards[numberOfBoard].SizeM; i++)
            {
                for (int j = 0; j < boards[numberOfBoard].SizeN; j++)
                {
                    if (boards[numberOfBoard].getValue(i, j) != 0)
                    {
                        skippingCounter++;
                        boards[(numberOfBoard + 1) % 2].setValue(i, j, boards[numberOfBoard].getValue(i, j));
                        continue;
                    }

                    if (firstNeighbourhood == 10)
                    {
                        neighbourhood = rnd.Next() % 2 + 2;
                    }
                    else if (firstNeighbourhood == 12)
                    {
                        neighbourhood = rnd.Next() % 2 + 4;
                    }
                    var arr = new List <int>();


                    if (neighbourhood == 0 || neighbourhood == 1 || neighbourhood == 2 || neighbourhood == 3)
                    {
                        arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM), j));
                        arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM), j));
                        arr.Add(boards[numberOfBoard].getValue(i, BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                        arr.Add(boards[numberOfBoard].getValue(i, BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                        if (neighbourhood == 1 || neighbourhood == 2)
                        {
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                                                   BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                                                   BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                        }

                        if (neighbourhood == 1 || neighbourhood == 3)
                        {
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                                                   BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                                                   BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                        }
                    }
                    else if (neighbourhood == 4 || neighbourhood == 5)
                    {
                        int multiplier = (int)Math.Pow(-1, generateExponent());
                        if (neighbourhood == 4)
                        {
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM), j));
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM), j));
                            arr.Add(boards[numberOfBoard].getValue(i, BoardGameOfLife.mod(j + multiplier, boards[numberOfBoard].SizeN)));
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i - 1, boards[numberOfBoard].SizeM),
                                                                   BoardGameOfLife.mod(j + multiplier, boards[numberOfBoard].SizeN)));
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + 1, boards[numberOfBoard].SizeM),
                                                                   BoardGameOfLife.mod(j + multiplier, boards[numberOfBoard].SizeN)));
                        }
                        else
                        {
                            arr.Add(boards[numberOfBoard].getValue(i, BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                            arr.Add(boards[numberOfBoard].getValue(i, BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + multiplier, boards[numberOfBoard].SizeM), j));
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + multiplier, boards[numberOfBoard].SizeM),
                                                                   BoardGameOfLife.mod(j - 1, boards[numberOfBoard].SizeN)));
                            arr.Add(boards[numberOfBoard].getValue(BoardGameOfLife.mod(i + multiplier, boards[numberOfBoard].SizeM),
                                                                   BoardGameOfLife.mod(j + 1, boards[numberOfBoard].SizeN)));
                        }
                    }
                    else
                    {
                        double xLength, yLength, distance;
                        int    modK, modL;
                        for (int k = BoardGameOfLife.mod(i - radius, boards[numberOfBoard].SizeM), it = 0; it < 2 * radius; k = BoardGameOfLife.mod(k + 1, boards[numberOfBoard].SizeM), it++)
                        {
                            for (int l = BoardGameOfLife.mod(j - radius, boards[numberOfBoard].SizeN), it2 = 0; it2 < 2 * radius; l = BoardGameOfLife.mod(l + 1, boards[numberOfBoard].SizeN), it2++)
                            {
                                modK     = BoardGameOfLife.mod(k, boards[numberOfBoard].SizeM);
                                modL     = BoardGameOfLife.mod(l, boards[numberOfBoard].SizeN);
                                xLength  = calclulateDistanceBetweenCentres(i, modK, boards[numberOfBoard].getXValueCenter(i, j), boards[numberOfBoard].getXValueCenter(modK, modL));
                                yLength  = calclulateDistanceBetweenCentres(j, modL, boards[numberOfBoard].getYValueCenter(i, j), boards[numberOfBoard].getYValueCenter(modK, modL));
                                distance = Math.Sqrt(xLength * xLength + yLength * yLength);
                                if (distance < radius)
                                {
                                    arr.Add(boards[numberOfBoard].getValue(k, l));
                                }
                            }
                        }
                    }
                    var groups   = arr.GroupBy(v => v);
                    int maxCount = groups.Max(g => g.Count());
                    int mode     = groups.First(g => g.Count() == maxCount).Key;
                    var tmp      = arr.Max();
                    if (mode != 0 && (maxCount == arr.Count))
                    {
                        boards[(numberOfBoard + 1) % 2].setValue(i, j, mode);
                    }
                    else
                    {
                        boards[(numberOfBoard + 1) % 2].setValue(i, j, arr.Max());
                    }
                }
            }
            if (skippingCounter == sizeM * sizeN)
            {
                changesFlag = false;
            }
        }