Beispiel #1
0
        /// <summary>
        /// Returns the acceleration CHANGES to a particular particle based on gravitational interaction.
        /// </summary>
        /// <returns></returns>
        public static List<double?> CalculateAcceleration_BasicGravity(Particle InputParticle, Particle ModParticle, int MassIndex, double Precision, double GRAVCONSTANT)
        {
            List<double?> ReturnAcceleration = new List<double?>(InputParticle.Acceleration.Capacity);

            int i;
            for (i = 0; i < InputParticle.Acceleration.Capacity; i++) // For each component of the input acceleration
            {
                if (InputParticle.Position[i] == null || InputParticle.Velocity[i] == null || InputParticle.Acceleration[i] == null)
                    {
                        //If any of these are null, then we don't need to worry about it
                    }
                    else
                    {
                        double? Distance = ModParticle.Position[i] - InputParticle.Position[i];
                        if (Distance > -Precision && Distance < Precision)
                        {
                            //If they are at the same point in space (or really close), then the acceleration change is zero
                            ReturnAcceleration.Add(0);
                        }
                        else
                        {
                            if (Distance > 0)
                            {
                                ReturnAcceleration.Add((GRAVCONSTANT * ModParticle.Properties[MassIndex]) / (Distance * Distance));
                            }
                            else
                            {
                                ReturnAcceleration.Add((GRAVCONSTANT * ModParticle.Properties[MassIndex]) / -(Distance * Distance));
                            }
                        }
                    }
            }

            return ReturnAcceleration;
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new particle modeled after a neutron.
        /// </summary>
        /// <returns>A neutron.</returns>
        public static Particle CreateNeutron(int ID, List<double?> Position)
        {
            Particle ReturnParticle = new Particle(ID, 2, 2);

            ReturnParticle.Position[0] = Position[0];
            ReturnParticle.Position[1] = Position[1];
            ReturnParticle.Properties[0] = 1.675e-27;
            ReturnParticle.Properties[1] = null;
            ReturnParticle.Acceleration[0] = 0;
            ReturnParticle.Acceleration[1] = 0;
            ReturnParticle.Velocity[0] = 0;
            ReturnParticle.Velocity[1] = 0;

            return ReturnParticle;
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new particle modeled after an electron.
        /// </summary>
        /// <returns>An electron.</returns>
        public static Particle CreateElectron(int ID, List<double?> Position)
        {
            Particle ReturnParticle = new Particle(ID, 2, 2);

            ReturnParticle.Position[0] = Position[0];
            ReturnParticle.Position[1] = Position[1];
            ReturnParticle.Properties[0] = 9.109e-28;
            ReturnParticle.Properties[1] = -1.602e-19;
            ReturnParticle.Acceleration[0] = 0;
            ReturnParticle.Acceleration[1] = 0;
            ReturnParticle.Velocity[0] = 0;
            ReturnParticle.Velocity[1] = 0;

            return ReturnParticle;
        }
Beispiel #4
0
        private void basicParticleInitializationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TB.Clear();
            TB.Text += "Running Basic Particle Initialization Test:" + Environment.NewLine;
            TB.Text += "-------------------------------------------" + Environment.NewLine;
            TB.Text += "Creating a basic particle with ID 1234, NDimensions 2, and NProperties 3..." + Environment.NewLine;

            Particle test = new Particle(1234, 2, 3);

            TB.Text += Environment.NewLine;
            TB.Text += test.ParticleToString();
            TB.Text += Environment.NewLine;
            TB.Text += "Testing changing the value of Properties[0] to 5678..." + Environment.NewLine;
            test.Properties[0] = 5678;
            TB.Text += "Properties[0] Value = " + test.Properties[0].ToString() + Environment.NewLine;
            TB.Text += Environment.NewLine;
            TB.Text += "Basic particle initialization test complete...";
        }
Beispiel #5
0
        private void zeroRandomWalkTestToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TB.Clear();
            TB.Text += "Running Random Walk Test:" + Environment.NewLine;
            TB.Text += "-------------------------" + Environment.NewLine;
            TB.Text += "Plotting 10000 2D simple mass particles at position 0 with random walk (5, 10)..." + Environment.NewLine;

            ModelParticle = Generic2D.CreateSimpleMassParticle(-1, ModelParticle.Position);
            ParticleList = Simulation.GetRandomParticleSet(0, 10000, 2, Generic2D.CreateBasicSizeList(0), ModelParticle.Properties, false);
            GenerationCount = 0;
            RandomWalkTest.Start();
        }
Beispiel #6
0
 private void sTARTToolStripMenuItem2_Click(object sender, EventArgs e)
 {
     TB.Clear();
     TB.Text += "Running Simple Electromagnetism Test:" + Environment.NewLine;
     TB.Text += "-------------------------------------" + Environment.NewLine;
     TB.Text += "Plotting 200 2D random proton and electron particles at a random position on a size 100 grid with gravity and electromagnetism active..." + Environment.NewLine;
     ParticleList = new List<Particle>(200);
     int i;
     for (i = 0; i < 200; i++)
     {
         if (i < gen.Next(1, 200)) //Create Protons
         {
             ModelParticle = Generic2D.CreateProton(i, Simulation.GetRandomCoordinates(2, Generic2D.CreateBasicSizeList(100), false));
             ModelParticle.Properties[0] = 10;
             ParticleList.Add(ModelParticle);
         }
         else //Create Electrons
         {
             ModelParticle = Generic2D.CreateElectron(i, Simulation.GetRandomCoordinates(2, Generic2D.CreateBasicSizeList(100), false));
             ModelParticle.Properties[0] = 1;
             ParticleList.Add(ModelParticle);
         }
     }
     GenerationCount = 0;
     SimpleElecMagTest.Start();
 }
Beispiel #7
0
        private void randomPositionPlotSpeedTestToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TB.Clear();
            TB.Text += "Running Random Position Plot Speed Test:" + Environment.NewLine;
            TB.Text += "----------------------------------------" + Environment.NewLine;
            TB.Text += "Plotting 10000 2D simple mass particles at a random position (without nulls) on a size 1500 grid every 50 msecs..." + Environment.NewLine;

            ModelParticle = Generic2D.CreateSimpleMassParticle(-1, ModelParticle.Position);
            ParticleList = Simulation.GetRandomParticleSet(0, 10000, 2, Generic2D.CreateBasicSizeList(1500), ModelParticle.Properties, false);
            GenerationCount = 0;
            RandomPositionPlotTest.Start();
        }
Beispiel #8
0
        private void multiple2DParticlePlotTestToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TB.Clear();
            TB.Text += "Running Multiple 2D Particle Plot Test:" + Environment.NewLine;
            TB.Text += "---------------------------------------" + Environment.NewLine;
            TB.Text += "Plotting 100 2D simple mass particles at a random position (without nulls) on a size 100 grid..." + Environment.NewLine;

            Particle ModelParticle = new Particle(-1, 2, 2);
            ModelParticle = Generic2D.CreateSimpleMassParticle(-1, ModelParticle.Position);
            List<Particle> ParticleList = Simulation.GetRandomParticleSet(0, 100, 2, Generic2D.CreateBasicSizeList(100), ModelParticle.Properties, false);

            TB.Text += "Plotting particles..." + Environment.NewLine;
            SimGrid.Series[0].Points.Clear();
            foreach (Particle test in ParticleList)
            {
                SimGrid.Series[0].Points.AddXY(test.Position[0], test.Position[1]);
            }

            TB.Text += "2D multiple particle plot test complete (check grid)...";
        }
Beispiel #9
0
        private void getRandomParticleSetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TB.Clear();
            TB.Text += "Running Get Random Particle Set Test:" + Environment.NewLine;
            TB.Text += "-------------------------------------" + Environment.NewLine;
            TB.Text += "Creating a list of 5 2D simple mass particles with indexes starting at 1000 on a size 50 grid..." + Environment.NewLine;
            TB.Text += Environment.NewLine;
            TB.Text += Environment.NewLine;
            Particle ModelParticle = new Particle(-1, 2, 2);
            ModelParticle = Generic2D.CreateSimpleMassParticle(-1, ModelParticle.Position);

            List<Particle> ParticleList = Simulation.GetRandomParticleSet(1000, 5, 2, Generic2D.CreateBasicSizeList(50), ModelParticle.Properties, true);

            foreach (Particle x in ParticleList)
            {
                TB.Text += "-------------------------" + Environment.NewLine;
                TB.Text += x.ParticleToString();
                TB.Text += "-------------------------" + Environment.NewLine;
            }
            TB.Text += Environment.NewLine;
            TB.Text += "2D simple mass particle initialization test complete...";
        }
Beispiel #10
0
        /// <summary>
        /// Outputs useful debug information about a Generic 2D particle as a string.
        /// </summary>
        /// <returns>A string containing information about a 2D particle.</returns>
        public static string ParticleToString(Particle InputParticle)
        {
            string output = "";
            output += "Particle ID =                   " + InputParticle.ID.ToString() + Environment.NewLine;
            output += "Properties Capacity =           " + InputParticle.Properties.Capacity.ToString() + Environment.NewLine;
            output += "Position Capacity =             " + InputParticle.Position.Capacity.ToString() + Environment.NewLine;
            output += "Velocity Capacity =             " + InputParticle.Velocity.Capacity.ToString() + Environment.NewLine;
            output += "Acceleration Capacity =         " + InputParticle.Acceleration.Capacity.ToString() + Environment.NewLine;
            output += "Properties Count =              " + InputParticle.Properties.Count.ToString() + Environment.NewLine;
            output += "Position Count =                " + InputParticle.Position.Count.ToString() + Environment.NewLine;
            output += "Velocity Count =                " + InputParticle.Velocity.Count.ToString() + Environment.NewLine;
            output += "Acceleration Count =            " + InputParticle.Acceleration.Count.ToString() + Environment.NewLine;
            output += "Properties[0] (Mass) Value =    " + InputParticle.Properties[0].ToString() + Environment.NewLine;
            output += "Properties[1] (Charge) Value =  " + InputParticle.Properties[1].ToString() + Environment.NewLine;
            output += "Position[0] (X) Value =         " + InputParticle.Position[0].ToString() + Environment.NewLine;
            output += "Position[1] (Y) Value =         " + InputParticle.Position[1].ToString() + Environment.NewLine;
            output += "Velocity[0] (X) Value =         " + InputParticle.Velocity[0].ToString() + Environment.NewLine;
            output += "Velocity[1] (Y) Value =         " + InputParticle.Velocity[1].ToString() + Environment.NewLine;
            output += "Acceleration[0] (X) Value =     " + InputParticle.Acceleration[0].ToString() + Environment.NewLine;
            output += "Acceleration[1] (Y) Value =     " + InputParticle.Acceleration[1].ToString() + Environment.NewLine;

            return output;
        }
Beispiel #11
0
        public static Particle UpdateParticle_BasicGravity(Particle Input, List<Particle> ParticleList, int MassIndex, double Precision, double GRAVCONSTANT, double VelocityLimit)
        {
            if (Input.Properties[MassIndex] == null) return Input;

            Particle ReturnParticle = Input;

            foreach (Particle P in ParticleList)
            {
                if (P.ID == Input.ID || P.Properties[MassIndex] == null) continue;
                ReturnParticle.Acceleration = AddLists(ReturnParticle.Acceleration, CalculateAcceleration_BasicGravity(Input, P, MassIndex, Precision, GRAVCONSTANT));
            }

            ReturnParticle.Velocity = AddLists(ReturnParticle.Velocity, ReturnParticle.Acceleration);

            int i;
            for (i = 0; i < ReturnParticle.Velocity.Capacity; i++)
            {
                if (ReturnParticle.Velocity[i] == null) continue;
                if (ReturnParticle.Velocity[i] > 0 && ReturnParticle.Velocity[i] > VelocityLimit) ReturnParticle.Velocity[i] = VelocityLimit;
                if (ReturnParticle.Velocity[i] < 0 && ReturnParticle.Velocity[i] < -VelocityLimit) ReturnParticle.Velocity[i] = -VelocityLimit;
            }

            ReturnParticle.Position = AddLists(ReturnParticle.Position, ReturnParticle.Velocity);
            return ReturnParticle;
        }
Beispiel #12
0
        /// <summary>
        /// Creates a set of randomly positioned particles with a particular set of properties. Velocities and Accelerations are initialized to zero.
        /// </summary>
        /// <returns>A list of randomly positioned particles.</returns>
        public static List<Particle> GetRandomParticleSet(int IndexStart, int NParticles, int NDimensions, List<int> Sizes, List<double?> Properties, bool IsNullPositionAllowed)
        {
            List<Particle> OutList = new List<Particle>(NParticles);

            int i;
            for (i = 0; i < NParticles; i++)
            {
                Particle NewParticle = new Particle(IndexStart + i, NDimensions, Properties.Capacity);
                NewParticle.Properties = Properties;
                NewParticle.InitializeToZero();
                NewParticle.Position = GetRandomCoordinates(NDimensions, Sizes, IsNullPositionAllowed);
                OutList.Add(NewParticle);
            }

            return OutList;
        }