Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85662742
compute_gravity.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Sep 30, 22:10
Size
992 B
Mime Type
text/x-c
Expires
Wed, Oct 2, 22:10 (2 d)
Engine
blob
Format
Raw Data
Handle
21233266
Attached To
R7571 SP4E-TB-TL-FR
compute_gravity.cc
View Options
#include "compute_gravity.hh"
#include <cmath>
/* -------------------------------------------------------------------------- */
void ComputeGravity::compute(System& system) {
// define a lambda function for newtonian gravity
auto newton_gravity = [this](Particle& par1, Particle& par2) {
// compute the distance vector and the square of distance
auto v_r = par2.getPosition() - par1.getPosition();
auto r2 = v_r.squaredNorm();
if (r2 == 0.)
return;
// compute the distance
auto r = sqrt(r2);
v_r *= 1 / r;
// compute the pair force
auto force = par1.getMass() * par2.getMass() * G / r2 * v_r;
// add up the force for both concerned particles
par2.getForce() -= force;
par1.getForce() += force;
};
// apply newtonian gravity on all pairs of particles
applyOnPairs(newton_gravity, system);
}
/* -------------------------------------------------------------------------- */
void ComputeGravity::setG(Real G) { this->G = G; }
Event Timeline
Log In to Comment