Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62483808
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, May 13, 12:52
Size
1 KB
Mime Type
text/x-c
Expires
Wed, May 15, 12:52 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17652369
Attached To
R7571 SP4E-TB-TL-FR
compute_gravity.cc
View Options
#include <cmath>
#include "compute_gravity.hh"
/* -------------------------------------------------------------------------- */
void
ComputeGravity
::
compute
(
System
&
system
)
{
// Get the total number of particles
int
nparticles
=
system
.
getNbParticles
();
//Initialize types
Vector
v_ij
;
Real
r2_ij
=
0.
;
Real
r_ij
=
0
;
Vector
force
;
Vector
nv_ij
;
// Loop over all the particles and gets each one's parameters
for
(
int
pi
=
0
;
pi
<
nparticles
;
++
pi
)
{
Particle
&
PI
=
system
.
getParticle
(
pi
);
//loop over all next interacting particles
for
(
int
pj
=
pi
+
1
;
pj
<
nparticles
;
++
pj
)
{
Particle
&
PJ
=
system
.
getParticle
(
pj
);
// Gets the vector between the two particles positions
v_ij
=
PJ
.
getPosition
()
-
PI
.
getPosition
();
// Squared distance (obtained via vector class)
r2_ij
=
v_ij
.
squaredNorm
();
// Obtained distance
r_ij
=
sqrt
(
r2_ij
);
//Obtained corresponding normed vector
nv_ij
=
v_ij
/
r_ij
;
// compute the gravity force vector interaction on i with j
force
=
nv_ij
*
PI
.
getMass
()
*
PJ
.
getMass
()
*
G
/
r2_ij
;
//F_ij=-F_ji Particles have opposite forces
PJ
.
getForce
()
-=
force
;
PI
.
getForce
()
+=
force
;
}
}
}
Event Timeline
Log In to Comment