How to Implement Damping in Particle Simulation

Click For Summary

Discussion Overview

The discussion revolves around implementing damping in a particle simulation of charged particles. Participants explore the challenges of achieving a stable final state where charges are distributed along a line, with more charge at the ends and less in the center. The focus is on the technical aspects of the simulation code and the effects of various damping strategies.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant shares a simulation code and describes the goal of achieving a stable charge distribution, noting that the simulation behaves elastically despite attempts to implement damping.
  • The participant mentions an approach of adding acceleration in the opposite direction of motion, proportional to velocity, but reports that this does not yield the desired results.
  • Another participant suggests that the issue may stem from incorrectly using position values instead of velocity values in the damping calculation, proposing a change from charges.x to charges.vx.
  • The original poster acknowledges the suggestion and expresses gratitude, indicating that the advice was helpful.

Areas of Agreement / Disagreement

There is no explicit consensus reached in the discussion, but one participant agrees with the suggestion provided. The initial problem regarding damping remains partially unresolved as the original poster has not confirmed the effectiveness of the proposed change.

Contextual Notes

The discussion highlights potential misunderstandings regarding the implementation of damping versus spring-like behavior in the simulation. The specific mathematical relationships and assumptions underlying the damping mechanism are not fully explored.

TheDemx27
Gold Member
Messages
169
Reaction score
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
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   Reactions: TheDemx27
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!
 
https://media.giphy.com/media/xThuWlHZT7zEPGyYP6/giphy.gif
~success~
 
  • Like
Likes   Reactions: Twigg, cpscdave, JorisL and 1 other person

Similar threads

Replies
10
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
4
Views
1K