parent
b4113effa7
commit
7b655129e8
@ -102,7 +102,7 @@ fn offset_Momentum(bodies: &mut [body; BODIES_COUNT]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Output the total energy of the system.
|
// Output the total energy of the system.
|
||||||
fn output_Energy(bodies: &mut [body; BODIES_COUNT]) {
|
unsafe fn output_Energy(bodies: &mut [body; BODIES_COUNT]) {
|
||||||
let mut energy = 0.;
|
let mut energy = 0.;
|
||||||
for i in 0..BODIES_COUNT {
|
for i in 0..BODIES_COUNT {
|
||||||
// Add the kinetic energy for each body.
|
// Add the kinetic energy for each body.
|
||||||
@ -115,18 +115,21 @@ fn output_Energy(bodies: &mut [body; BODIES_COUNT]) {
|
|||||||
// Add the potential energy between this body and
|
// Add the potential energy between this body and
|
||||||
// every other body
|
// every other body
|
||||||
for j in i + 1..BODIES_COUNT {
|
for j in i + 1..BODIES_COUNT {
|
||||||
let mut position_Delta = [0.; 3];
|
let mut position_Delta = [mem::MaybeUninit::<f64>::uninit(); 3];
|
||||||
|
|
||||||
for m in 0..3 {
|
for m in 0..3 {
|
||||||
position_Delta[m] =
|
position_Delta[m]
|
||||||
bodies[i].position[m] - bodies[j].position[m];
|
.as_mut_ptr()
|
||||||
|
.write(bodies[i].position[m] - bodies[j].position[m]);
|
||||||
}
|
}
|
||||||
let position_Delta: [f64; 3] = mem::transmute(position_Delta);
|
let position_Delta: [f64; 3] = mem::transmute(position_Delta);
|
||||||
|
|
||||||
energy -= bodies[i].mass * bodies[j].mass / f64::sqrt(
|
energy -= bodies[i].mass * bodies[j].mass
|
||||||
|
/ f64::sqrt(
|
||||||
position_Delta[0] * position_Delta[0]
|
position_Delta[0] * position_Delta[0]
|
||||||
+ position_Delta[1] * position_Delta[1]
|
+ position_Delta[1] * position_Delta[1]
|
||||||
+ position_Delta[2] * position_Delta[2]);
|
+ position_Delta[2] * position_Delta[2],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user