How to Implement Damping in Particle Simulation

In summary, the charged particles in the simulation move erratically and seem to spiral out of control if the dampening variable c is increased.
  • #1
TheDemx27
Gold Member
169
13
So I made this simulation of charged particles: https://github.com/TheDemx27/Charge-Simulator
My goal is to be able to put the charges on a line, as I've done, and see them tend toward a final state where there is more charge at the ends of the line and less towards the center. The problem is, the simulation runs like an elastically no matter what I try. At the moment, I've tried adding an acceleration in the opposing direction of motion, proportional to the velocity. This is the main loop for calculating the acceleration and setting the velocity:

Code:
            for (int i = 0; i < charges.Count; i++) {
                for (int j = i + 1; j < charges.Count; j++) {

                    distance = GetDistVec(charges[i], charges[j]);
                    f = charges[i].q * charges[j].q * k / (distance.Magnitude * distance.Magnitude);

                    acceleration1.Magnitude = Math.Abs(f / charges[i].m);
                    acceleration2.Magnitude = Math.Abs(f / charges[j].m);
                    acceleration1.Direction = distance.Direction;
                    acceleration2.Direction = distance.Direction += Math.PI;

                    // DAMPENING
                    double c = 10;

                    accel1 = PolarToComponent(acceleration1);
                    accel2 = PolarToComponent(acceleration2);

                    accel1.x -= c * charges[i].x;
                    accel1.y -= c * charges[i].y;
                    accel2.x -= c * charges[j].x;
                    accel2.y -= c * charges[j].y;
                    // DAMPENING

                    SetVelVec(charges[i], accel1);
                    SetVelVec(charges[j], accel2);
                }
            }

This doesn't seem to do anything. If I make c large enough, the oscillations get bigger, the sim eventually spirals out of control, and I get null values for the positions.
 
Technology news on Phys.org
  • #2
Hi,I'm not quite certain but it looks like you are adding a spring, not damping, variable charges.x is an x position, not velocity. Change this to charges.vx

Hope this helps.
 
  • Like
Likes TheDemx27
  • #3
Henryk said:
Hi,I'm not quite certain but it looks like you are adding a spring, not damping, variable charges.x is an x position, not velocity. Change this to charges.vx

Hope this helps.
Haha, yes that helped! Wow... ok then.
Thankyou!
 
  • #4
https://media.giphy.com/media/xThuWlHZT7zEPGyYP6/giphy.gif
~success~
 
  • Like
Likes Twigg, cpscdave, JorisL and 1 other person

Related to How to Implement Damping in Particle Simulation

1. What is damping in particle simulation?

Damping in particle simulation is a technique used to reduce or eliminate the excessive movement or oscillations of particles in a simulation. It is often used to stabilize a simulation and make it more realistic.

2. Why is damping important in particle simulation?

Damping is important because without it, particles in a simulation can continue to move or oscillate indefinitely, leading to unrealistic results. Damping helps to mimic real-world physics and make the simulation more accurate.

3. How is damping implemented in particle simulation?

Damping can be implemented in particle simulation by using equations that calculate the forces acting on each particle and applying a damping factor to those forces. This can be done in various ways, such as using a drag force or adding a velocity-dependent damping term to the equations of motion.

4. What factors affect the effectiveness of damping in particle simulation?

The effectiveness of damping in particle simulation can be affected by several factors, such as the damping coefficient, the type of damping used, the time step of the simulation, and the properties of the particles themselves (e.g. mass, shape, etc.). It is important to carefully choose these parameters to achieve the desired results.

5. Are there any limitations to implementing damping in particle simulation?

Yes, there are some limitations to implementing damping in particle simulation. For example, if the damping coefficient is too high, it can cause the particles to lose too much energy and come to a stop too quickly. Additionally, damping may not work effectively in certain types of simulations, such as those involving highly elastic materials or complex interactions between particles.

Similar threads

  • Programming and Computer Science
Replies
10
Views
3K
  • Programming and Computer Science
Replies
2
Views
3K
  • Introductory Physics Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
588
Replies
4
Views
710
  • Advanced Physics Homework Help
Replies
1
Views
814
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top