Exemplo n.º 1
0
        public void MonteCarlo(double kt)
        {
            cellCounter = 0;
            for (int j = 0; j < gridWidth; j++)
            {
                for (int i = 0; i < gridHeight; i++)
                {
                    grid[j, i].isAvailableForMC = true;
                }
            }
            int          x = 0, y = 0;
            Random       rand      = new Random();
            int          newValue  = 0;;
            Neighborhood alterCell = new Neighborhood();

            Cell[,] singleIteration    = new Cell[3, 3];
            Cell[,] newSingleIteration = new Cell[3, 3];
            while (cellCounter < gridWidth * gridHeight)
            {
                x = rand.Next(gridWidth);
                y = rand.Next(gridHeight);
                while (!grid[x, y].isAvailableForMC)
                {
                    x++;
                    if (x == gridWidth)
                    {
                        x = 0;
                        y++;
                    }
                    if (y == gridHeight)
                    {
                        y = 0;
                    }
                }
                grid[x, y].isAvailableForMC = false;
                cellCounter++;
                int currentCellEnergy = 0;
                int newCellEnergy     = 0;
                switch (boundaryConditionType)
                {
                case 0:
                    singleIteration = absorbing(x, y, radius);
                    break;

                case 1:
                    singleIteration = periodical(x, y, radius);
                    break;
                }
                newSingleIteration = singleIteration;
                newValue           = alterCell.findRandomNeighbor(radius, cellSize, singleIteration, 1);
                if (newValue == 0)
                {
                    newValue = grid[x, y].value;
                }
                switch (neighborhoodType)
                {
                case 0:
                    currentCellEnergy = alterCell.vonNeumanMCEnergy(singleIteration);
                    newSingleIteration[radius, radius].value = newValue;
                    newCellEnergy = alterCell.vonNeumanMCEnergy(newSingleIteration);
                    break;

                case 1:
                    currentCellEnergy = alterCell.mooreMCEnergy(singleIteration);
                    newSingleIteration[radius, radius].value = newValue;
                    newCellEnergy = alterCell.mooreMCEnergy(newSingleIteration);
                    break;

                case 2:
                    currentCellEnergy = alterCell.pentagonalMCEnergy(singleIteration, rand.Next(4));
                    newSingleIteration[radius, radius].value = newValue;
                    newCellEnergy = alterCell.pentagonalMCEnergy(newSingleIteration, rand.Next(4));
                    break;

                case 3:
                    currentCellEnergy = alterCell.hexagonalMCEnergy(singleIteration, 0);
                    newSingleIteration[radius, radius].value = newValue;
                    newCellEnergy = alterCell.hexagonalMCEnergy(newSingleIteration, 0);
                    break;

                case 4:
                    currentCellEnergy = alterCell.hexagonalMCEnergy(singleIteration, 1);
                    newSingleIteration[radius, radius].value = newValue;
                    newCellEnergy = alterCell.hexagonalMCEnergy(newSingleIteration, 1);
                    break;

                case 5:
                    currentCellEnergy = alterCell.hexagonalMCEnergy(singleIteration, 2);
                    newSingleIteration[radius, radius].value = newValue;
                    newCellEnergy = alterCell.hexagonalMCEnergy(newSingleIteration, 2);
                    break;

                case 6:
                    currentCellEnergy = alterCell.radiusMCEnergy(radius, cellSize, singleIteration);
                    newSingleIteration[radius, radius].value = newValue;
                    newCellEnergy = alterCell.radiusMCEnergy(radius, cellSize, newSingleIteration);
                    break;
                }
                if (newCellEnergy <= currentCellEnergy)
                {
                    EnergyMap[x, y]  = newCellEnergy;
                    grid[x, y].value = newValue;
                }
                else
                {
                    double p           = rand.NextDouble();
                    double probability = (newCellEnergy - currentCellEnergy) / kt * (-1);
                    probability = Math.Exp(probability);
                    if (p <= probability)
                    {
                        EnergyMap[x, y]  = currentCellEnergy;
                        grid[x, y].value = newValue;
                    }
                }
            }
            energyMaxFind();
        }
Exemplo n.º 2
0
        public void DRX(double dt, double percentX)
        {
            Random       rand      = new Random();
            Neighborhood alterCell = new Neighborhood();

            Cell[,] singleIteration = new Cell[3, 3];

            deltaDislocationDensity = (A / B + (1 - A / B) * Math.Exp(-B * recrystalizationTimeStep)) - dislocationDensity;

            dislocationDensity         = ((A / B) + (1 - A / B) * Math.Exp(-1 * B * recrystalizationTimeStep));
            dislocationDensityCritical = (46842668.25 * 300 * 300) / (gridHeight * gridWidth);
            //writeToFile.SaveToFile(DislocationDensity);
            recrystalizationTimeStep = recrystalizationTimeStep + dt;

            double avaragePackage = (deltaDislocationDensity / (gridWidth * gridHeight)) * percentX;

            for (int i = 0; i < gridWidth; i++)
            {
                for (int j = 0; j < gridHeight; j++)
                {
                    grid[i, j].dislocationDensity += avaragePackage;
                    DensityMap[i, j]        += avaragePackage;
                    deltaDislocationDensity -= avaragePackage;
                }
            }
            double randomPackage;
            int    xx, yy;
            double proability;

            while (deltaDislocationDensity > 0)
            {
                xx = rand.Next(gridWidth);
                yy = rand.Next(gridHeight);

                switch (boundaryConditionType)
                {
                case 0:
                    singleIteration = absorbing(xx, yy, radius);
                    break;

                case 1:
                    singleIteration = periodical(xx, yy, radius);
                    break;
                }

                if (alterCell.isOnBorder(radius, cellSize, singleIteration, 1))
                {
                    proability    = rand.NextDouble();
                    randomPackage = deltaDislocationDensity * rand.NextDouble();
                    if (randomPackage <= deltaDislocationDensity && proability > 0.2)
                    {
                        grid[xx, yy].dislocationDensity += randomPackage;
                        DensityMap[xx, yy]      += randomPackage;
                        deltaDislocationDensity -= randomPackage;
                    }
                    if (deltaDislocationDensity < 0.00001)
                    {
                        deltaDislocationDensity = 0;
                    }
                }
                else
                {
                    proability    = rand.NextDouble();
                    randomPackage = deltaDislocationDensity * rand.NextDouble();
                    if (randomPackage <= deltaDislocationDensity && proability <= 0.2)
                    {
                        grid[xx, yy].dislocationDensity += randomPackage;
                        deltaDislocationDensity         -= randomPackage;
                    }
                    if (deltaDislocationDensity < 0.00001)
                    {
                        deltaDislocationDensity = 0;
                    }
                }

                List <Cell> latelyRecrystalized = new List <Cell>();
                for (int i = 0; i < gridWidth; i++)
                {
                    for (int j = 0; j < gridHeight; j++)
                    {
                        switch (boundaryConditionType)
                        {
                        case 0:
                            singleIteration = absorbing(i, j, radius);
                            break;

                        case 1:
                            singleIteration = periodical(i, j, radius);
                            break;
                        }
                        if ((alterCell.isOnBorder(radius, cellSize, singleIteration, 1)) & (grid[i, j].dislocationDensity > dislocationDensityCritical) & (!grid[i, i].isRecrystalised))
                        {
                            counter++;
                            int  c = 0, r = 0, g = 0, b = 0;
                            bool colorOK = true;
                            while (c < 1000)
                            {
                                r = rand.Next(256);
                                g = rand.Next(256);
                                b = rand.Next(256);
                                for (int k = 0; k < colorList.Count; k++)
                                {
                                    if (colorList[k].r == r & colorList[k].g == g & colorList[k].b == b)
                                    {
                                        colorOK = false;
                                    }
                                }
                                c++;
                                if (colorOK)
                                {
                                    c = 2000;
                                }
                            }
                            colorList.Add(new ColorRGB());
                            colorList[colorList.Count - 1].r = r;
                            colorList[colorList.Count - 1].g = g;
                            colorList[colorList.Count - 1].b = b;
                            grid[i, j].value = counter;
                            grid[i, j].dislocationDensity = 0;
                            DensityMap[i, j]           = 0;
                            grid[i, j].isRecrystalised = true;
                            latelyRecrystalized.Add(grid[i, j]);
                        }
                    }
                }

                /*for (int i = 0; i < gridWidth; i++)
                 * {
                 *  for (int j = 0; j < gridHeight; j++)
                 *  {
                 *      switch (boundaryConditionType)
                 *      {
                 *          case 0:
                 *              singleIteration = absorbing(i, j, radius);
                 *              break;
                 *          case 1:
                 *              singleIteration = periodical(i, j, radius);
                 *              break;
                 *      }
                 *
                 *      int tmp = alterCell.isNeighbourRecrystalized(radius, cellSize, singleIteration, 1, latelyRecrystalized);
                 *
                 *      if ((tmp != 0) & !(grid[i, j].isRecrystalised))
                 *      {
                 *          if (alterCell.checkNeighbourhoodDislocations(i, j, singleIteration, 1))
                 *          {
                 *              grid[i, j].value = tmp;
                 *              grid[i, j].dislocationDensity = 0;
                 *              DensityMap[i, j] = 0;
                 *              grid[i, j].isRecrystalised =  true;
                 *          }
                 *      }
                 *  }
                 * }*/
            }
            densityMaxFind();
        }
Exemplo n.º 3
0
        public void checkGrid(int cellSize)
        {
            Cell[,] temp            = new Cell[gridWidth, gridHeight];
            Cell[,] singleIteration = new Cell[3, 3];
            Neighborhood alterCell = new Neighborhood();

            for (int j = 0; j < gridHeight; j++)
            {
                for (int i = 0; i < gridWidth; i++)
                {
                    temp[i, j]                    = new Cell(0, 0);
                    temp[i, j].gravityX           = grid[i, j].gravityX;
                    temp[i, j].gravityY           = grid[i, j].gravityY;
                    temp[i, j].isRecrystalised    = grid[i, j].isRecrystalised;
                    temp[i, j].dislocationDensity = grid[i, j].dislocationDensity;
                    temp[i, j].id                 = grid[i, j].id;
                }
            }
            for (int j = 0; j < gridHeight; j++)
            {
                for (int i = 0; i < gridWidth; i++)
                {
                    switch (boundaryConditionType)
                    {
                    case 0:
                        singleIteration = absorbing(i, j, radius);
                        break;

                    case 1:
                        singleIteration = periodical(i, j, radius);
                        break;
                    }
                    int tempValue = 0;
                    switch (neighborhoodType)
                    {
                    case 0:
                        tempValue = alterCell.vonNeumanType(singleIteration);
                        if (tempValue != temp[i, j].value)
                        {
                            cellCounter++;
                        }
                        temp[i, j].value = tempValue;
                        break;

                    case 1:
                        tempValue = alterCell.mooreType(singleIteration);
                        if (tempValue != temp[i, j].value)
                        {
                            cellCounter++;
                        }
                        temp[i, j].value = tempValue;
                        break;

                    case 2:
                        Random rand = new Random();
                        tempValue = alterCell.pentagonalType(singleIteration, rand.Next(4));
                        if (tempValue != temp[i, j].value)
                        {
                            cellCounter++;
                        }
                        temp[i, j].value = tempValue;
                        break;

                    case 3:
                        tempValue = alterCell.hexagonalType(singleIteration, 0);
                        if (tempValue != temp[i, j].value)
                        {
                            cellCounter++;
                        }
                        temp[i, j].value = tempValue;
                        break;

                    case 4:
                        tempValue = alterCell.hexagonalType(singleIteration, 1);
                        if (tempValue != temp[i, j].value)
                        {
                            cellCounter++;
                        }
                        temp[i, j].value = tempValue;
                        break;

                    case 5:
                        tempValue = alterCell.hexagonalType(singleIteration, 2);
                        if (tempValue != temp[i, j].value)
                        {
                            cellCounter++;
                        }
                        temp[i, j].value = tempValue;
                        break;

                    case 6:
                        tempValue = alterCell.radiusType(radius, cellSize, singleIteration);
                        if (tempValue != temp[i, j].value)
                        {
                            cellCounter++;
                        }
                        temp[i, j].value = tempValue;
                        break;
                    }
                }
            }
            grid = temp;
        }