Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F113373520
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
Sat, May 17, 14:06
Size
780 B
Mime Type
text/x-c
Expires
Mon, May 19, 14:06 (2 d)
Engine
blob
Format
Raw Data
Handle
26214777
Attached To
R7571 SP4E-TB-TL-FR
compute_gravity.cc
View Options
#include "compute_gravity.hh"
#include <cmath>
/* -------------------------------------------------------------------------- */
void ComputeGravity::computePairInteraction(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;
}
/* -------------------------------------------------------------------------- */
void ComputeGravity::setG(Real G) { this->G = G; }
Event Timeline
Log In to Comment