Пример #1
0
    public Grain[,] Simulation(Grain[,] grains, Graphics g)
    {
        bool[,] recrystalized = new bool[SIZE_Y, SIZE_X];

        for (int y = 0; y < SIZE_Y; y++)
        {
            for (int x = 0; x < SIZE_X; x++)
            {
                recrystalized[y, x] = false;
            }
        }

        for (int y = 0; y < SIZE_Y; y++)
        {
            for (int x = 0; x < SIZE_X; x++)
            {
                List <Grain> neighbours = NeighbourhoodFactory.GetNeighboursGrains(grains, x, y);

                foreach (Grain neighbour in neighbours)
                {
                    if (lastRecrystalized[neighbour.Y, neighbour.X])
                    {
                        bool rescrystallize = true;

                        foreach (Grain neighbour1 in neighbours)
                        {
                            if (!neighbour1.Recrystallized && neighbour1.Density >= grains[y, x].Density)
                            {
                                rescrystallize = false;
                                break;
                            }
                        }

                        if (rescrystallize && !grains[y, x].Recrystallized)
                        {
                            recrystalized[y, x]  = true;
                            grains[y, x].Density = 0;
                            // grains[y, x].Recrystallized = true;
                            grains[y, x].DisplayRecrystallized(g, Colors.GetRecrystallizationColor());
                        }

                        break;
                    }
                }
            }
        }

        for (int y = 0; y < SIZE_Y; y++)
        {
            for (int x = 0; x < SIZE_X; x++)
            {
                currentlyRecrystalized[y, x] = recrystalized[y, x] ? true: currentlyRecrystalized[y, x];
            }
        }

        return(grains);
    }
Пример #2
0
    public Recrystallization(Grain[,] grains)
    {
        for (int i = 0; i < SIZE_Y; i++)
        {
            for (int j = 0; j < SIZE_X; j++)
            {
                grains[i, j].Density        = 0;
                grains[i, j].Recrystallized = false;
            }
        }



        Colors.InitializeRecrystallizationColrs();

        ro                  = new List <double>();
        sigma               = new List <double>();
        checkedRo           = new List <double>();
        checkedRoFromGrians = new List <double>();

        currentlyRecrystalized = new bool[SIZE_Y, SIZE_X];
        lastRecrystalized      = new bool[SIZE_Y, SIZE_X];

        time = 0;

        double _ro    = (A / B) + (1 - (A / B)) * (Math.Exp(-B * time));
        double _sigma = sigma0 + value * A0 * B0 * Math.Sqrt(_ro);

        criticallRo = criticallRo / (SIZE_X * SIZE_Y);

        Console.WriteLine("Critical " + criticallRo);

        ro.Add(_ro);
        sigma.Add(_sigma);
        checkedRo.Add(0);
        checkedRoFromGrians.Add(_ro);


        for (int i = 0; i < SIZE_Y; i++)
        {
            for (int j = 0; j < SIZE_X; j++)
            {
                currentlyRecrystalized[i, j] = false;
                lastRecrystalized[i, j]      = false;

                List <int> neighbours = NeighbourhoodFactory.GetNeighboursMonteCarlo(grains, j, i);

                if (neighbours.Where(s => s != grains[i, j].State).ToList().Count > 0)
                {
                    grains[i, j].OnBorder = true;
                }
            }
        }
    }
Пример #3
0
    public void Simulate(Simulation grainGrowth, Graphics gB, Graphics g)
    {
        Grain[,] grains = grainGrowth.Tab;

        List <Grain> all = grains.OfType <Grain>().ToList();

        while (all.Count > 0)
        {
            if (BREAK_SIMULATION)
            {
                BREAK_SIMULATION = false;
                break;
            }



            int   index = random.Next(all.Count);
            Grain grain = all.ElementAt(index);
            all.RemoveAt(index);

            int stateBefore = grain.State;

            List <int> neighbours = NeighbourhoodFactory.GetNeighboursMonteCarlo(grains, grain.X, grain.Y);

            int energyBefore = CalculateEnergy(neighbours, stateBefore);

            grains[grain.Y, grain.X].Q = energyBefore;

            int stateAfter = (neighbours.ElementAt(random.Next(neighbours.Count)));

            int energyAfter = CalculateEnergy(neighbours, stateAfter);

            int deltaEnergy = energyAfter - energyBefore;
            if (deltaEnergy <= 0)
            {
                grains[grain.Y, grain.X].State = stateAfter;
                grain.Display(g, gB);
                grains[grain.Y, grain.X].Q = energyAfter;
            }
            else
            {
                float probability = (float)Math.Exp(-(deltaEnergy / this.KT)) * 100;
                float value       = (float)random.NextDouble() * 100;

                if (value <= probability)
                {
                    grains[grain.Y, grain.X].State = stateAfter;
                    grain.Display(g, gB);
                    grains[grain.Y, grain.X].Q = energyAfter;
                }
            }
        }
    }
Пример #4
0
    public void CalculateEnergy(Simulation grainGrowth)
    {
        for (int y = 0; y < SIZE_Y; y++)
        {
            for (int x = 0; x < SIZE_X; x++)
            {
                int stateBefore = grainGrowth.Tab[y, x].State;

                List <int> neighbours = NeighbourhoodFactory.GetNeighboursMonteCarlo(grainGrowth.Tab, x, y);


                int energyBefore = CalculateEnergy(neighbours, stateBefore);

                grainGrowth.Tab[y, x].Q = energyBefore;
            }
        }
    }
Пример #5
0
    private void ChangeStateRadial(Graphics g)
    {
        for (int i = 0; i < SIZE_Y; i++)
        {
            for (int j = 0; j < SIZE_X; j++)
            {
                if (this.tab[i, j].State == 0)
                {
                    continue;
                }

                foreach (Grain grain in NeighbourhoodFactory.GetRadialGrains(this.tab, j, i))
                {
                    previousGrains[grain.Y, grain.X].State = this.Tab[i, j].State;

                    previousGrains[grain.Y, grain.X].Display(g);
                }
            }
        }
    }
Пример #6
0
    private void ChangeState(Graphics g)
    {
        Parallel.For(0, SIZE_Y, i =>
        {
            for (int j = 0; j < SIZE_X; j++)
            {
                if (this.tab[i, j].State == 0)
                {
                    int cellBegin = this.tab[i, j].State;
                    int cellEnd   = this.tab[i, j].State;

                    cellEnd = NeighbourhoodFactory.GetNeighbours(this.tab, j, i);

                    if (cellEnd != cellBegin)
                    {
                        previousGrains[i, j].State = cellEnd;
                        previousGrains[i, j].Display(g);
                    }
                }
            }
            ;
        });
    }