Skip to content

Commit e397089

Browse files
committed
Added missing bracket
1 parent 77ec976 commit e397089

File tree

1 file changed

+123
-122
lines changed

1 file changed

+123
-122
lines changed

src/EIHPerturbation.cpp

Lines changed: 123 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ void EIHPerturbation::CalculateAccelerations(Model *model, int thread_id, int nu
3434
Real r_ab = sqrt(r_ab2); // PN1.0
3535
Real r_ab3 = r_ab * r_ab2; // PN1.0
3636
// Compute the normal vector, and mass to distance ratios
37-
Vec n_ab = x_ab / r_ab; // PN0.0
38-
Real m_a_over_r_ab = a.mass / r_ab; // PN1.0
39-
Real m_b_over_r_ab = b.mass / r_ab; // PN1.0
40-
Real m_b_over_r_ab3 = b.mass / r_ab3; // PN1.0
37+
Vec n_ab = x_ab / r_ab; // PN0.0
38+
Real m_a_over_r_ab = a.mass / r_ab; // PN1.0
39+
Real m_b_over_r_ab = b.mass / r_ab; // PN1.0
40+
// Real m_b_over_r_ab3 = b.mass / r_ab3; // PN1.0
4141
Real m_b_over_r_ab2 = b.mass / r_ab2; // PN1.0
4242

4343
// Compute the inner products used in the equations
44-
Real v_b_dot_n_ab = b.vel.Dot(n_ab); // PN1.0
45-
Real v_a_dot_v_b = a.vel.Dot(b.vel); // PN1.0
46-
Real v_a_dot_v_a = a.vel.SquaredNorm(); // PN1.0
47-
Real v_b_dot_v_b = b.vel.SquaredNorm(); // PN1.0
48-
Real square_v_a_dot_v_a = v_a_dot_v_a * v_a_dot_v_a; // PN1.0
44+
Real v_b_dot_n_ab = b.vel.Dot(n_ab); // PN1.0
45+
Real v_a_dot_v_b = a.vel.Dot(b.vel); // PN1.0
46+
Real v_a_dot_v_a = a.vel.SquaredNorm(); // PN1.0
47+
Real v_b_dot_v_b = b.vel.SquaredNorm(); // PN1.0
48+
// Real square_v_a_dot_v_a = v_a_dot_v_a * v_a_dot_v_a; // PN1.0
4949
Real square_v_b_dot_v_b = b.vel.SquaredNorm() * b.vel.SquaredNorm(); // PN1.0
5050
Real v_a_dot_n_ab = a.vel.Dot(n_ab); // PN2.0
5151
Real square_v_a_dot_v_b = a.vel.Dot(b.vel) * a.vel.Dot(b.vel); // PN2.0
@@ -77,7 +77,7 @@ void EIHPerturbation::CalculateAccelerations(Model *model, int thread_id, int nu
7777
Real r_bc = sqrt(r_bc2);
7878
Real r_bc3 = r_bc2 * r_bc;
7979
Real r_ac = x_ac.Norm();
80-
Real n_bc = x_bc / r_bc;
80+
Vec n_bc = x_bc / r_bc;
8181

8282
Real m_c_over_r_bc3 = c.mass / r_bc3;
8383
// Add the 3 cross terms
@@ -94,7 +94,7 @@ void EIHPerturbation::CalculateAccelerations(Model *model, int thread_id, int nu
9494

9595
// PN 2.0
9696
Real inv_r_ab2 = 1.0 / r_ab2; // computing inverse and reusing it
97-
Real temp = -14.25 * a.mass * a.mass * inv_r_ab2; // 57/4
97+
temp = -14.25 * a.mass * a.mass * inv_r_ab2; // 57/4
9898
temp -= 34.5 * a.mass * b.mass * inv_r_ab2; // 69/2
9999
temp -= 9.0 * b.mass * b.mass * inv_r_ab2; // 9
100100
temp -= 1.875 * quarted_v_b_dot_n_ab; // 16/8
@@ -113,7 +113,7 @@ void EIHPerturbation::CalculateAccelerations(Model *model, int thread_id, int nu
113113
temp2 += 1.25 * v_b_dot_v_b; // 5/4
114114
temp += a.mass / r_ab * temp2;
115115
// Next long term
116-
Real temp2 = 2.0 * square_v_a_dot_n_ab; // 2
116+
temp2 = 2.0 * square_v_a_dot_n_ab; // 2
117117
temp2 -= 4.0 * v_a_dot_n_ab * v_b_dot_n_ab; // 4
118118
temp2 -= 6.0 * square_v_b_dot_n_ab; // 6
119119
temp2 -= 8.0 * v_a_dot_v_b; // 8
@@ -122,7 +122,7 @@ void EIHPerturbation::CalculateAccelerations(Model *model, int thread_id, int nu
122122
// Add the 2.0 PN contributions in n_ab
123123
a.acc_pert += c4_recipr * n_ab * (m_b_over_r_ab2 * temp);
124124
// Compute the v_ab contributions
125-
Real temp = m_b_over_r_ab * (-2.0 * v_a_dot_n_ab - 2.0 * v_b_dot_n_ab); // 2, 2
125+
temp = m_b_over_r_ab * (-2.0 * v_a_dot_n_ab - 2.0 * v_b_dot_n_ab); // 2, 2
126126
temp += m_a_over_r_ab * (-15.75 * v_a_dot_n_ab + 13.75 * v_b_dot_n_ab); // -63/4, 55/4
127127
temp += 6.0 * v_a_dot_n_ab * square_v_b_dot_n_ab; // 6
128128
temp += 4.5 * cubed_v_b_dot_n_ab; // 9/2
@@ -138,131 +138,132 @@ void EIHPerturbation::CalculateAccelerations(Model *model, int thread_id, int nu
138138
Real v_ab_dot_n_ab = v_ab.Dot(n_ab);
139139
Real v_ab_dot_v_ab = v_ab.SquaredNorm();
140140
// Compute the n_ab terms for PN 2.5
141-
Real temp = 52.0 / 3.0 * b.mass / r_ab * v_ab_dot_n_ab; // 52/3
142-
temp -= 6.0 * a.mass / r_ab * v_ab_dot_n_ab; // 6
143-
temp += 3.0 * (v_ab_dot_n_ab)*v_ab_dot_v_ab; // 3
141+
temp = 52.0 / 3.0 * b.mass / r_ab * v_ab_dot_n_ab; // 52/3
142+
temp -= 6.0 * a.mass / r_ab * v_ab_dot_n_ab; // 6
143+
temp += 3.0 * (v_ab_dot_n_ab)*v_ab_dot_v_ab; // 3
144144
a.acc_pert += c5_recipr * n_ab * (0.8 * m_a_m_b_over_r_ab3 * temp);
145-
Real temp = 2.0 * a.mass / r_ab; // 2
146-
temp -= 8.0 * b.mass / r_ab; // 8
147-
temp -= v_ab_dot_v_ab; // 1
145+
temp = 2.0 * a.mass / r_ab; // 2
146+
temp -= 8.0 * b.mass / r_ab; // 8
147+
temp -= v_ab_dot_v_ab; // 1
148148
a.acc_pert += c5_recipr * v_ab * (0.8 * m_a_m_b_over_r_ab3 * temp);
149149
}
150150
}
151+
}
151152

152-
Real EIHPerturbation::GetEnergy(Model * model)
153-
{
154-
ParticleSetView &all = model->GetAllParticles();
155-
Real energy = 0;
156-
Real c2_recipr = 1 / (m_SpeedOfLight * m_SpeedOfLight);
157-
Real c4_recipr = c2_recipr * c2_recipr;
153+
Real EIHPerturbation::GetEnergy(Model *model)
154+
{
155+
ParticleSetView &all = model->GetAllParticles();
156+
Real energy = 0;
157+
Real c2_recipr = 1 / (m_SpeedOfLight * m_SpeedOfLight);
158+
Real c4_recipr = c2_recipr * c2_recipr;
158159

159-
for (Particle &a : all)
160+
for (Particle &a : all)
161+
{
162+
Vec v_a = a.vel;
163+
Real v_a_dot_v_a = v_a.SquaredNorm();
164+
Real square_v_a_dot_v_a = v_a_dot_v_a * v_a_dot_v_a; // PN1.0
165+
// 1PN kinetic term
166+
energy += c2_recipr * a.mass * 0 .375 * v_a_dot_v_a * v_a_dot_v_a;
167+
// 2PN kinetic term
168+
energy += c4_recipr * a.mass * 0.3125 * v_a_dot_v_a * v_a_dot_v_a * v_a_dot_v_a;
169+
for (Particle &b : all)
160170
{
161-
Vec v_a = a.vel;
162-
Real v_a_dot_v_a = v_a.SquaredNorm();
163-
Real square_v_a_dot_v_a = v_a_dot_v_a * v_a_dot_v_a; // PN1.0
164-
// 1PN kinetic term
165-
energy += c2_recipr * a.mass * 0 .375 * v_a_dot_v_a * v_a_dot_v_a;
166-
// 2PN kinetic term
167-
energy += c4_recipr * a.mass * 0.3125 * v_a_dot_v_a * v_a_dot_v_a * v_a_dot_v_a;
168-
for (Particle &b : all)
169-
{
170-
if (a == b)
171-
continue;
171+
if (a == b)
172+
continue;
172173

173-
// Compute the differences in position and velocity
174-
Vec x_ab = a.pos - b.pos;
175-
Vec v_ab = a.vel - b.vel;
176-
// compute the distances and its powers
177-
Real r_ab2 = x_ab.SquaredNorm(); // PN0.0
178-
Real r_ab = sqrt(r_ab2); // PN1.0
179-
Real r_ab3 = r_ab * r_ab2; // PN1.0
180-
// Compute the normal vector, and mass to distance ratios
181-
Vec n_ab = x_ab / r_ab; // PN0.0
182-
Real m_a_over_r_ab = a.mass / r_ab; // PN1.0
183-
Real ma_am_b_over_r_ab = a.mass * b.mass / r_ab; // PN1.0
184-
Real ma_m_b_over_r_ab3 = a.mass * b.mass / r_ab3; // PN1.0
185-
Real ma_m_b_over_r_ab2 = a.mass * b.mass / r_ab2; // PN1.0
186-
Real m_b_over_r_ab = b.mass / r_ab; // PN1.0
174+
// Compute the differences in position and velocity
175+
Vec x_ab = a.pos - b.pos;
176+
Vec v_ab = a.vel - b.vel;
177+
// compute the distances and its powers
178+
Real r_ab2 = x_ab.SquaredNorm(); // PN0.0
179+
Real r_ab = sqrt(r_ab2); // PN1.0
180+
Real r_ab3 = r_ab * r_ab2; // PN1.0
181+
// Compute the normal vector, and mass to distance ratios
182+
Vec n_ab = x_ab / r_ab; // PN0.0
183+
Real m_a_over_r_ab = a.mass / r_ab; // PN1.0
184+
Real ma_am_b_over_r_ab = a.mass * b.mass / r_ab; // PN1.0
185+
Real ma_m_b_over_r_ab3 = a.mass * b.mass / r_ab3; // PN1.0
186+
Real ma_m_b_over_r_ab2 = a.mass * b.mass / r_ab2; // PN1.0
187+
Real m_b_over_r_ab = b.mass / r_ab; // PN1.0
187188

188-
// Compute the inner products used in the equations
189-
Real v_b_dot_n_ab = b.vel.Dot(n_ab); // PN1.0
190-
Real v_a_dot_v_b = a.vel.Dot(b.vel); // PN1.0
191-
Real v_b_dot_v_b = b.vel.SquaredNorm(); // PN1.0
192-
Real square_v_b_dot_v_b = b.vel.SquaredNorm() * b.vel.SquaredNorm(); // PN1.0
193-
Real v_a_dot_n_ab = a.vel.Dot(n_ab); // PN2.0
194-
Real square_v_b_dot_n_ab = v_b_dot_n_ab * v_b_dot_n_ab; // PN2.0
195-
Real square_v_a_dot_n_ab = v_a_dot_n_ab * v_a_dot_n_ab; // PN2.0
196-
Real cubed_v_a_dot_n_ab = square_v_a_dot_n_ab * v_a_dot_n_ab; // PN2.0
197-
Real quarted_v_b_dot_n_ab = square_v_b_dot_n_ab * square_v_b_dot_n_ab; // PN2.0
189+
// Compute the inner products used in the equations
190+
Real v_b_dot_n_ab = b.vel.Dot(n_ab); // PN1.0
191+
Real v_a_dot_v_b = a.vel.Dot(b.vel); // PN1.0
192+
Real v_b_dot_v_b = b.vel.SquaredNorm(); // PN1.0
193+
Real square_v_b_dot_v_b = b.vel.SquaredNorm() * b.vel.SquaredNorm(); // PN1.0
194+
Real v_a_dot_n_ab = a.vel.Dot(n_ab); // PN2.0
195+
Real square_v_b_dot_n_ab = v_b_dot_n_ab * v_b_dot_n_ab; // PN2.0
196+
Real square_v_a_dot_n_ab = v_a_dot_n_ab * v_a_dot_n_ab; // PN2.0
197+
Real cubed_v_a_dot_n_ab = square_v_a_dot_n_ab * v_a_dot_n_ab; // PN2.0
198+
Real quarted_v_b_dot_n_ab = square_v_b_dot_n_ab * square_v_b_dot_n_ab; // PN2.0
198199

199-
// 1PN terms
200-
Real energypart = 1.5 * va_dot_va * m_b_over_r_ab;
201-
Real energytemp = 7.0 * a.vel.Dot(b.vel);
202-
energytemp += a.vel.Dot(n_ab) * b.vel.Dot(n_ab);
203-
energypart -= 0.25 * m_b_over_r_ab * energytemp;
204-
// 1PN cross terms
205-
for (Particle &c : all)
206-
{
207-
// Note: it could be b == c, which is not clear in Will (2014a)
208-
if (a == c)
209-
continue;
200+
// 1PN terms
201+
Real energypart = 1.5 * va_dot_va * m_b_over_r_ab;
202+
Real energytemp = 7.0 * a.vel.Dot(b.vel);
203+
energytemp += a.vel.Dot(n_ab) * b.vel.Dot(n_ab);
204+
energypart -= 0.25 * m_b_over_r_ab * energytemp;
205+
// 1PN cross terms
206+
for (Particle &c : all)
207+
{
208+
// Note: it could be b == c, which is not clear in Will (2014a)
209+
if (a == c)
210+
continue;
210211

211-
Real r_ac = (a.pos - c.pos).Norm();
212-
energypart += 0.5 * m_b_over_r_ab * c.mass / r_ac;
213-
}
214-
// ADD 1PN terms
215-
energy += c2_recipr * energypart * a.mass;
216-
// 2PN terms
217-
Real energypart = -0.5 * m_a_over_r_ab * m_a_over_r_ab;
218-
energypart -= 2.375 * m_a_over_r_ab * m_b_over_r_ab;
219-
energypart += 0.375 * cubed_v_a_dot_n_ab * v_b_dot_n_ab;
220-
energypart += 0.1875 * square_v_a_dot_n_ab * square_v_b_dot_n_ab;
221-
energypart -= 1.125 * v_a_dot_n_ab * v_b_dot_n_ab * v_a_dot_v_a;
222-
energypart -= 1.625 * square_v_b_dot_n_ab * v_a_dot_v_a;
223-
energypart += 2.625 * square_v_a_dot_v_a;
224-
energypart += 1.625 * square_v_a_dot_n_ab * v_a_dot_v_b;
225-
energypart += 0.75 * v_a_dot_n_ab * v_b_dot_n_ab * v_a_dot_v_b;
226-
energypart -= 6.875 * v_a_dot_v_a * v_a_dot_v_b;
227-
energypart += 2.125 * v_a_dot_v_b * v_a_dot_v_b;
228-
energypart += 1.9375 * v_a_dot_v_a * v_b_dot_v_b;
229-
Real energytemp = 7.25 * square_v_a_dot_n_ab;
230-
energytemp -= 3.25 * v_a_dot_n_ab * v_b_dot_n_ab;
231-
energytemp += 0.5 * square_v_b_dot_n_ab;
232-
energytemp += 1.5 * v_a_dot_v_a;
233-
energytemp += 1.75 * v_b_dot_v_b;
234-
energypart += energytemp * m_a_over_r_ab;
235-
energy += a.mass * c4_recipr * energypart * m_b_over_r_ab;
212+
Real r_ac = (a.pos - c.pos).Norm();
213+
energypart += 0.5 * m_b_over_r_ab * c.mass / r_ac;
236214
}
215+
// ADD 1PN terms
216+
energy += c2_recipr * energypart * a.mass;
217+
// 2PN terms
218+
Real energypart = -0.5 * m_a_over_r_ab * m_a_over_r_ab;
219+
energypart -= 2.375 * m_a_over_r_ab * m_b_over_r_ab;
220+
energypart += 0.375 * cubed_v_a_dot_n_ab * v_b_dot_n_ab;
221+
energypart += 0.1875 * square_v_a_dot_n_ab * square_v_b_dot_n_ab;
222+
energypart -= 1.125 * v_a_dot_n_ab * v_b_dot_n_ab * v_a_dot_v_a;
223+
energypart -= 1.625 * square_v_b_dot_n_ab * v_a_dot_v_a;
224+
energypart += 2.625 * square_v_a_dot_v_a;
225+
energypart += 1.625 * square_v_a_dot_n_ab * v_a_dot_v_b;
226+
energypart += 0.75 * v_a_dot_n_ab * v_b_dot_n_ab * v_a_dot_v_b;
227+
energypart -= 6.875 * v_a_dot_v_a * v_a_dot_v_b;
228+
energypart += 2.125 * v_a_dot_v_b * v_a_dot_v_b;
229+
energypart += 1.9375 * v_a_dot_v_a * v_b_dot_v_b;
230+
Real energytemp = 7.25 * square_v_a_dot_n_ab;
231+
energytemp -= 3.25 * v_a_dot_n_ab * v_b_dot_n_ab;
232+
energytemp += 0.5 * square_v_b_dot_n_ab;
233+
energytemp += 1.5 * v_a_dot_v_a;
234+
energytemp += 1.75 * v_b_dot_v_b;
235+
energypart += energytemp * m_a_over_r_ab;
236+
energy += a.mass * c4_recipr * energypart * m_b_over_r_ab;
237237
}
238-
return energy;
239238
}
239+
return energy;
240+
}
240241

241-
Vec EIHPerturbation::GetLinearMomentum(Model * model)
242-
{
243-
// This term is computed up to 1PN with cross terms
244-
ParticleSetView &all = model->GetAllParticles();
245-
Vec momentum = Vec::Zero();
246-
Real c2_recipr = 1 / (m_SpeedOfLight * m_SpeedOfLight);
242+
Vec EIHPerturbation::GetLinearMomentum(Model *model)
243+
{
244+
// This term is computed up to 1PN with cross terms
245+
ParticleSetView &all = model->GetAllParticles();
246+
Vec momentum = Vec::Zero();
247+
Real c2_recipr = 1 / (m_SpeedOfLight * m_SpeedOfLight);
247248

248-
for (Particle &a : all)
249+
for (Particle &a : all)
250+
{
251+
// 0PN
252+
momentum += a.mass * a.vel;
253+
// 1PN
254+
Real v_a_dot_v_a = v_a.SquaredNorm();
255+
Vec momentumpart = v_a_dot_v_a * a.vel;
256+
for (Particle &b : all)
249257
{
250-
// 0PN
251-
momentum += a.mass * a.vel;
252-
// 1PN
253-
Real v_a_dot_v_a = v_a.SquaredNorm();
254-
Vec momentumpart = v_a_dot_v_a * a.vel;
255-
for (Particle &b : all)
256-
{
257-
if (b == a)
258-
continue;
259-
Vec x_ab = a.pos - b.pos;
260-
Real r_ab = x_ab.Norm();
261-
Vec n_ab = x_ab / r_ab;
262-
momentumpart -= b.mass / r_ab * a.vel;
263-
momentumpart -= b.mass / r_ab * (a.vel.Dot(n_ab)) * n_ab
264-
}
265-
momentum += 0.5 * c2_recipr * a.mass * momentumpart
258+
if (b == a)
259+
continue;
260+
Vec x_ab = a.pos - b.pos;
261+
Real r_ab = x_ab.Norm();
262+
Vec n_ab = x_ab / r_ab;
263+
momentumpart -= b.mass / r_ab * a.vel;
264+
momentumpart -= b.mass / r_ab * (a.vel.Dot(n_ab)) * n_ab
266265
}
267-
return momentum;
266+
momentum += 0.5 * c2_recipr * a.mass * momentumpart
268267
}
268+
return momentum;
269+
}

0 commit comments

Comments
 (0)