Exemple #1
0
        protected void TakeSingleStep()
        {
            var next = new FluidLayer(Size, Quantizations);

            foreach (var fluidCell in Layer.GetCells())
            {
                var position = fluidCell.Position;
                var grid     = new VelocityGrid(fluidCell.VelocityProbability);
                foreach (var distribution in grid.Distributions)
                {
                    var x = position.X + distribution.Velocity.X;
                    var y = position.Y + distribution.Velocity.Y;
                    if (x < 0)
                    {
                        x = 0;
                    }
                    if (x >= Width)
                    {
                        x = Width - 1;
                    }
                    if (y < 0)
                    {
                        y = 0;
                    }
                    if (y >= Height)
                    {
                        y = Height - 1;
                    }
                    var nextPos = new Point(x, y);
                    next[nextPos].NumberOfParticles = (int)Math.Round(fluidCell.NumberOfParticles * distribution.Probability);

                    var nextVelocity = new Velocity2dProbability(next[nextPos].VelocityProbability
                                                                 + distribution.VelocityProbability
                                                                 * distribution.Probability
                                                                 * fluidCell.NumberOfParticles);
                    next[nextPos].VelocityProbability = nextVelocity;
                }

                next[position].NumberOfParticles   = fluidCell.NumberOfParticles;
                next[position].VelocityProbability = fluidCell.VelocityProbability;
            }

            Layer = next;
        }
Exemple #2
0
 public FluidWorld(Size size, int quantizations)
 {
     Size          = size;
     Quantizations = quantizations;
     Layer         = new FluidLayer(size, quantizations);
 }