public void MoveParticles(SimulationStructure structure, float step, int simStep)
 {
     foreach (var allSection in structure.GetAllSections())
     {
         allSection.ApplyToAllParticles(
             particle =>
         {
             var randomAcceleration = step * acceleration *
                                      (
                 new Vector3((float)(randomizer.NextDouble() - 0.5d),
                             (float)(randomizer.NextDouble() - 0.5d),
                             (float)(randomizer.NextDouble() - 0.5d)) +
                 accelerationBias);
             particle.Velocity += randomAcceleration;
             if (particle.Velocity.LengthSquared() > maxSpeedSquared)
             {
                 particle.Velocity.Normalize();
                 particle.Velocity = particle.Velocity * (float)Math.Sqrt(maxSpeedSquared);
             }
             particle.Position += particle.Velocity * step;
             bouncer.BounceParticle(ref particle);
             return(particle);
         });
     }
     costCalculator.CalculateTotalCost(structure, simStep);
 }
        public void MoveParticles(SimulationStructure structure, float step, int simStep)
        {
            var dampingF = (float)(1 / Math.Exp(step));

            foreach (var particleSection in structure.GetAllSections())
            {
                particleSection.ApplyToAllParticles(particle =>
                {
                    particle.Position += particle.Velocity * step;
                    particle.Velocity += step * (gravityPoint - particle.Position);
                    bouncer.BounceParticle(ref particle);
                    if (particle.Velocity.LengthSquared() > maxSpeedSquared)
                    {
                        particle.Velocity *= 0.9f;
                    }
                    return(particle);
                });
            }
            centerRemainTime -= step;
            if (centerRemainTime < 0)
            {
                UpdateGravityPoint(structure);
            }
            costCalculator.CalculateTotalCost(structure, simStep);
        }
        private void VisualizeMatrixStep(SimulationStructure structure, int step)
        {
            foreach (var particleSection in structure.GetAllSections())
            {
                if (!(particleSection is MatrixSortParticleSection))
                {
                    return;
                }
                var msec = particleSection as MatrixSortParticleSection;
            }
            var particleSections = structure.GetAllSections().ToList();
            var toPrintBuffer    = new StringBuilder();

            for (int i = 0; i < particleSections.Count(); i++)
            {
                var lowerBound = particleSections[i].LowerBound;
                toPrintBuffer.AppendLine();
                toPrintBuffer.AppendLine("Section: " + lowerBound.X + "," + lowerBound.Y + "," + lowerBound.Z);
                toPrintBuffer.AppendLine();

                var mySec = particleSections[i] as MatrixSortParticleSection;
                var pDim  = mySec.ParticlesMatrix.GetLength(0);
                for (int j = 0; j < 8; j++)
                {
                    var Xd       = j % 2 == 0 ? 0: pDim - 1;
                    var Yd       = j % 4 < 2 ? 0: pDim - 1;
                    var Zd       = j < 4 ? 0: pDim - 1;
                    var particle = mySec.ParticlesMatrix[Xd, Yd, Zd];
                    toPrintBuffer.AppendLine("  Index: " + Xd + "," + Yd + "," + Zd);
                    var position = particle.Position;
                    toPrintBuffer.AppendLine("  Position: " + position.X + "," + position.Y + "," + position.Z);
                }
            }
            var path = outputPath + "cornerPartics" + step;

            File.WriteAllText(path, toPrintBuffer.ToString());
        }
        public void Sort(SimulationStructure simulationStructure, int step)
        {
            bool shown = false;

            foreach (IParticleSection particleSection in simulationStructure.GetAllSections())
            {
                SingleSectionSort((ParticleSection)particleSection);
                if (!shown)
                {
                    foreach (var s in ((ParticleSection)particleSection).elementsPerSide)
                    {
                        Console.Out.WriteLine(s);
                    }
                    shown = true;
                }
            }
            sideSorterTransmitter.TransmitParticles(simulationStructure, step);
        }
Beispiel #5
0
        public void MoveParticles(SimulationStructure structure, float step, int simStep)
        {
            var f = ((float)Math.Sin((float)simStep / 400));


            foreach (var allSection in structure.GetAllSections())
            {
                allSection.ApplyToAllParticles(particle =>
                {
                    particle.Velocity = new Vector3((particle.Velocity.X + f / 5) * 0.5f, 0,
                                                    0);
                    particle.Position += particle.Velocity * step;
                    bouncer.BounceParticle(ref particle);
                    return(particle);
                });
            }

            costCalculator.CalculateTotalCost(structure, simStep);
        }