forked from EmelineBolmont/mercury-90
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforces.f90
More file actions
501 lines (409 loc) · 16.1 KB
/
forces.f90
File metadata and controls
501 lines (409 loc) · 16.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
!******************************************************************************
! MODULE: forces
!******************************************************************************
!
! DESCRIPTION:
!> @brief Modules that contains all common forces
!
!******************************************************************************
module forces
use types_numeriques
use mercury_globals
implicit none
private
public :: mfo_all
public :: mfo_ngf ! Needed by HYBRID and MVS
public :: mfo_obl ! Needed by HYBRID and MVS on respectively mfo_hy and mfo_mvs
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author John E. Chambers
!>
!
!> @date 2 March 2001
!
! DESCRIPTION:
!> @brief Calculates accelerations on a set of NBOD bodies (of which NBIG are Big)
!! due to Newtonian gravitational perturbations, post-Newtonian
!! corrections (if required), cometary non-gravitational forces (if required)
!! and user-defined forces (if required).
!
!> @note Input/output must be in coordinates with respect to the central body.
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine mfo_all (time,jcen,nbod,nbig,m,x,v,s,rcrit,a,stat,ngf,ngflag,nce,ice,jce)
use physical_constant
use mercury_constant
use user_module
implicit none
! Input
integer, intent(in) :: nbod !< [in] current number of bodies (1: star; 2-nbig: big bodies; nbig+1-nbod: small bodies)
integer, intent(in) :: nbig !< [in] current number of big bodies (ones that perturb everything else)
integer, intent(in) :: ngflag !< [in] do any bodies experience non-grav. forces?
!!\n ( 0 = no non-grav forces)
!!\n 1 = cometary jets only
!!\n 2 = radiation pressure/P-R drag only
!!\n 3 = both
integer, intent(in) :: stat(nbod) !< [in] status (0 => alive, <>0 => to be removed)
integer, intent(in) :: nce
integer, intent(in) :: ice(nce)
integer, intent(in) :: jce(nce)
real(double_precision), intent(in) :: time !< [in] current epoch (days)
real(double_precision), intent(in) :: jcen(3) !< [in] J2,J4,J6 for central body (units of RCEN^i for Ji)
real(double_precision), intent(in) :: m(nbod) !< [in] mass (in solar masses * K2)
real(double_precision), intent(in) :: x(3,nbod)
real(double_precision), intent(in) :: v(3,nbod)
real(double_precision), intent(in) :: s(3,nbod) !< [in] spin angular momentum (solar masses AU^2/day)
real(double_precision), intent(in) :: ngf(4,nbod) !< [in] non gravitational forces parameters
!! \n(1-3) cometary non-gravitational (jet) force parameters
!! \n(4) beta parameter for radiation pressure and P-R drag
real(double_precision), intent(in) :: rcrit(nbod)
! Output
real(double_precision), intent(out) :: a(3,nbod)
! Local
integer :: j
real(double_precision) :: acor(3,nb_bodies_initial),acen(3)
!------------------------------------------------------------------------------
! Newtonian gravitational forces
call mfo_grav (nbod,nbig,m,x,v,a,stat)
! Correct for oblateness of the central body
if (jcen(1).ne.0.or.jcen(2).ne.0.or.jcen(3).ne.0) then
call mfo_obl (jcen,nbod,m,x,acor,acen)
do j = 2, nbod
a(1,j) = a(1,j) + (acor(1,j) - acen(1))
a(2,j) = a(2,j) + (acor(2,j) - acen(2))
a(3,j) = a(3,j) + (acor(3,j) - acen(3))
end do
end if
! Include non-gravitational (cometary jet) accelerations if necessary
if ((ngflag.eq.1).or.(ngflag.eq.3)) then
call mfo_ngf (nbod,x,v,acor,ngf)
do j = 2, nbod
a(1,j) = a(1,j) + acor(1,j)
a(2,j) = a(2,j) + acor(2,j)
a(3,j) = a(3,j) + acor(3,j)
end do
end if
! Include radiation pressure/Poynting-Robertson drag if necessary
if (ngflag.eq.2.or.ngflag.eq.3) then
call mfo_pr (nbod,nbig,m,x,v,acor,ngf)
do j = 2, nbod
a(1,j) = a(1,j) + acor(1,j)
a(2,j) = a(2,j) + acor(2,j)
a(3,j) = a(3,j) + acor(3,j)
end do
end if
! Include post-Newtonian corrections if required
if (opt(7).eq.1) then
call mfo_pn (nbod,nbig,m,x,v,acor)
do j = 2, nbod
a(1,j) = a(1,j) + acor(1,j)
a(2,j) = a(2,j) + acor(2,j)
a(3,j) = a(3,j) + acor(3,j)
end do
end if
! Include user-defined accelerations if required
if (opt(8).eq.1) then
call mfo_user (time,jcen,nbod,nbig,m,x,v,acor)
do j = 2, nbod
a(1,j) = a(1,j) + acor(1,j)
a(2,j) = a(2,j) + acor(2,j)
a(3,j) = a(3,j) + acor(3,j)
end do
end if
!------------------------------------------------------------------------------
return
end subroutine mfo_all
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author John E. Chambers
!>
!
!> @date 3 October 2000
!
! DESCRIPTION:
!> @brief Calculates accelerations on a set of NBOD bodies (NBIG of which are Big)
!! due to gravitational perturbations by all the other bodies, except that
!! Small bodies do not interact with one another.\n\n
!!
!! The positions and velocities are stored in arrays X, V with the format
!! (x,y,z) and (vx,vy,vz) for each object in succession. The accelerations
!! are stored in the array A (ax,ay,az).
!
!> @note All coordinates and velocities must be with respect to central body!!!
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine mfo_grav (nbod,nbig,m,x,v,a,stat)
use physical_constant
use mercury_constant
implicit none
! Input
integer, intent(in) :: nbod !< [in] current number of bodies (1: star; 2-nbig: big bodies; nbig+1-nbod: small bodies)
integer, intent(in) :: nbig !< [in] current number of big bodies (ones that perturb everything else)
integer, intent(in) :: stat(nbod) !< [in] status (0 => alive, <>0 => to be removed)
real(double_precision), intent(in) :: m(nbod) !< [in] mass (in solar masses * K2)
real(double_precision), intent(in) :: x(3,nbod)
real(double_precision), intent(in) :: v(3,nbod)
! Output
real(double_precision), intent(out) :: a(3,nbod)
! Local
integer :: i, j
real(double_precision) :: sx, sy, sz, dx, dy, dz, tmp1, tmp2, s_1, s2, s_3, r3(nb_bodies_initial)
!------------------------------------------------------------------------------
sx = 0.d0
sy = 0.d0
sz = 0.d0
do i = 2, nbod
a(1,i) = 0.d0
a(2,i) = 0.d0
a(3,i) = 0.d0
s2 = x(1,i)*x(1,i) + x(2,i)*x(2,i) + x(3,i)*x(3,i)
s_1 = 1.d0 / sqrt(s2)
r3(i) = s_1 * s_1 * s_1
end do
do i = 2, nbod
tmp1 = m(i) * r3(i)
sx = sx - tmp1 * x(1,i)
sy = sy - tmp1 * x(2,i)
sz = sz - tmp1 * x(3,i)
end do
! Direct terms
do i = 2, nbig
do j = i + 1, nbod
dx = x(1,j) - x(1,i)
dy = x(2,j) - x(2,i)
dz = x(3,j) - x(3,i)
s2 = dx*dx + dy*dy + dz*dz
s_1 = 1.d0 / sqrt(s2)
s_3 = s_1 * s_1 * s_1
tmp1 = s_3 * m(i)
tmp2 = s_3 * m(j)
a(1,j) = a(1,j) - tmp1 * dx
a(2,j) = a(2,j) - tmp1 * dy
a(3,j) = a(3,j) - tmp1 * dz
a(1,i) = a(1,i) + tmp2 * dx
a(2,i) = a(2,i) + tmp2 * dy
a(3,i) = a(3,i) + tmp2 * dz
end do
end do
! Indirect terms (add these on last to reduce roundoff error)
do i = 2, nbod
tmp1 = m(1) * r3(i)
a(1,i) = a(1,i) + sx - tmp1 * x(1,i)
a(2,i) = a(2,i) + sy - tmp1 * x(2,i)
a(3,i) = a(3,i) + sz - tmp1 * x(3,i)
end do
!------------------------------------------------------------------------------
return
end subroutine mfo_grav
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author John E. Chambers
!>
!
!> @date 29 November 1999
!
! DESCRIPTION:
!> @brief Calculates accelerations on a set of NBOD bodies due to cometary
!! non-gravitational jet forces. The positions and velocities are stored in
!! arrays X, V with the format (x,y,z) and (vx,vy,vz) for each object in
!! succession. The accelerations are stored in the array A (ax,ay,az). The
!! non-gravitational accelerations follow a force law described by Marsden
!! et al. (1973) Astron. J. 211-225, with magnitude determined by the
!! parameters NGF(1,2,3) for each object.
!
!> @note All coordinates and velocities must be with respect to central body!!!
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine mfo_ngf (nbod,x,v,a,ngf)
use physical_constant
use mercury_constant
implicit none
! Input
integer, intent(in) :: nbod !< [in] current number of bodies (1: star; 2-nbig: big bodies; nbig+1-nbod: small bodies)
real(double_precision), intent(in) :: x(3,nbod)
real(double_precision), intent(in) :: v(3,nbod)
real(double_precision), intent(in) :: ngf(4,nbod) !< [in] non gravitational forces parameters
!! \n(1-3) cometary non-gravitational (jet) force parameters
!! \n(4) beta parameter for radiation pressure and P-R drag
! Output
real(double_precision), intent(out) :: a(3,nbod)
! Local
integer :: j
real(double_precision) :: r2,r,rv,q,g,tx,ty,tz,nx,ny,nz,a1,a2,a3
!------------------------------------------------------------------------------
do j = 2, nbod
r2 = x(1,j)*x(1,j) + x(2,j)*x(2,j) +x(3,j)*x(3,j)
! Only calculate accelerations if body is close to the Sun (R < 9.36 AU),
! or if the non-gravitational force parameters are exceptionally large.
if (r2.lt.88.d0.or.abs(ngf(1,j)).gt.1d-7.or.abs(ngf(2,j)).gt.1d-7.or.abs(ngf(3,j)).gt.1d-7) then
r = sqrt(r2)
rv = x(1,j)*v(1,j) + x(2,j)*v(2,j) + x(3,j)*v(3,j)
! Calculate Q = R / R0, where R0 = 2.808 AU
q = r * .3561253561253561d0
g = .111262d0 * q**(-2.15d0) * (1.d0+q**5.093d0)**(-4.6142d0)
! Within-orbital-plane transverse vector components
tx = r2*v(1,j) - rv*x(1,j)
ty = r2*v(2,j) - rv*x(2,j)
tz = r2*v(3,j) - rv*x(3,j)
! Orbit-normal vector components
nx = x(2,j)*v(3,j) - x(3,j)*v(2,j)
ny = x(3,j)*v(1,j) - x(1,j)*v(3,j)
nz = x(1,j)*v(2,j) - x(2,j)*v(1,j)
! Multiplication factors
a1 = ngf(1,j) * g / r
a2 = ngf(2,j) * g / sqrt(tx*tx + ty*ty + tz*tz)
a3 = ngf(3,j) * g / sqrt(nx*nx + ny*ny + nz*nz)
! X,Y and Z components of non-gravitational acceleration
a(1,j) = a1*x(1,j) + a2*tx + a3*nx
a(2,j) = a1*x(2,j) + a2*ty + a3*ny
a(3,j) = a1*x(3,j) + a2*tz + a3*nz
else
a(1,j) = 0.d0
a(2,j) = 0.d0
a(3,j) = 0.d0
end if
end do
!------------------------------------------------------------------------------
return
end subroutine mfo_ngf
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> John E. Chambers
!
!> @date 3 October 2000
!
! DESCRIPTION:
!> @brief Calculates post-Newtonian relativistic corrective accelerations for a set
!! of NBOD bodies (NBIG of which are Big).\n\n
!!
!! This routine should not be called from the symplectic algorithm MAL_MVS
!! or the conservative Bulirsch-Stoer algorithm MAL_BS2.
!
!> @note All coordinates and velocities must be with respect to central body!!!
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine mfo_pn (nbod,nbig,m,x,v,a)
use physical_constant
use mercury_constant
implicit none
! Input
integer, intent(in) :: nbod !< [in] current number of bodies (1: star; 2-nbig: big bodies; nbig+1-nbod: small bodies)
integer, intent(in) :: nbig !< [in] current number of big bodies (ones that perturb everything else)
real(double_precision), intent(in) :: m(nbod) !< [in] mass (in solar masses * K2)
real(double_precision), intent(in) :: x(3,nbod)
real(double_precision), intent(in) :: v(3,nbod)
! Output
real(double_precision), intent(out) :: a(3,nbod)
! Local
integer :: j
!------------------------------------------------------------------------------
do j = 1, nbod
a(1,j) = 0.d0
a(2,j) = 0.d0
a(3,j) = 0.d0
end do
!------------------------------------------------------------------------------
return
end subroutine mfo_pn
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> John E. Chambers
!
!> @date 3 October 2000
!
! DESCRIPTION:
!> @brief Calculates radiation pressure and Poynting-Robertson drag for a set
!! of NBOD bodies (NBIG of which are Big).\n\n
!!
!! This routine should not be called from the symplectic algorithm MAL_MVS
!! or the conservative Bulirsch-Stoer algorithm MAL_BS2.
!
!> @note All coordinates and velocities must be with respect to central body!!!
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine mfo_pr (nbod,nbig,m,x,v,a,ngf)
use physical_constant
use mercury_constant
implicit none
! Input
integer, intent(in) :: nbod !< [in] current number of bodies (1: star; 2-nbig: big bodies; nbig+1-nbod: small bodies)
integer, intent(in) :: nbig !< [in] current number of big bodies (ones that perturb everything else)
real(double_precision), intent(in) :: m(nbod) !< [in] mass (in solar masses * K2)
real(double_precision), intent(in) :: x(3,nbod)
real(double_precision), intent(in) :: v(3,nbod)
real(double_precision), intent(in) :: ngf(4,nbod) !< [in] non gravitational forces parameters
!! \n(1-3) cometary non-gravitational (jet) force parameters
!! \n(4) beta parameter for radiation pressure and P-R drag
! Output
real(double_precision), intent(out) :: a(3,nbod)
! Local
integer :: j
!------------------------------------------------------------------------------
do j = 1, nbod
a(1,j) = 0.d0
a(2,j) = 0.d0
a(3,j) = 0.d0
end do
!------------------------------------------------------------------------------
return
end subroutine mfo_pr
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author John E. Chambers
!>
!
!> @date 2 October 2000
!
! DESCRIPTION:
!> @brief Calculates barycentric accelerations of NBOD bodies due to oblateness of
!! the central body. Also returns the corresponding barycentric acceleration
!! of the central body.
!
!> @note All coordinates must be with respect to the central body!!!
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine mfo_obl (jcen,nbod,m,x,a,acen)
use physical_constant
use mercury_constant
implicit none
! Input
integer, intent(in) :: nbod !< [in] current number of bodies (1: star; 2-nbig: big bodies; nbig+1-nbod: small bodies)
real(double_precision), intent(in) :: jcen(3) !< [in] J2,J4,J6 for central body (units of RCEN^i for Ji)
real(double_precision), intent(in) :: m(nbod) !< [in] mass (in solar masses * K2)
real(double_precision), intent(in) :: x(3,nbod)
! Output
real(double_precision), intent(out) :: acen(3)
real(double_precision), intent(out) :: a(3,nbod)
! Local
integer :: i
real(double_precision) :: jr2,jr4,jr6,r2,r_1,r_2,r_3,u2,u4,u6,tmp1,tmp2,tmp3,tmp4
!------------------------------------------------------------------------------
acen(1) = 0.d0
acen(2) = 0.d0
acen(3) = 0.d0
do i = 2, nbod
! Calculate barycentric accelerations on the objects
r2 = x(1,i)*x(1,i) + x(2,i)*x(2,i) + x(3,i)*x(3,i)
r_1 = 1.d0 / sqrt(r2)
r_2 = r_1 * r_1
r_3 = r_2 * r_1
jr2 = jcen(1) * r_2
jr4 = jcen(2) * r_2 * r_2
jr6 = jcen(3) * r_2 * r_2 * r_2
u2 = x(3,i) * x(3,i) * r_2
u4 = u2 * u2
u6 = u4 * u2
tmp1 = m(1) * r_3
tmp2 = jr2*(7.5d0*u2 - 1.5d0) + jr4*(39.375d0*u4 - 26.25d0*u2 + 1.875d0) + &
jr6*(187.6875d0*u6 -216.5625d0*u4 +59.0625d0*u2 -2.1875d0)
tmp3 = jr2*3.d0 + jr4*(17.5d0*u2 - 7.5d0) + jr6*(86.625d0*u4 - 78.75d0*u2 + 13.125d0)
a(1,i) = x(1,i) * tmp1 * tmp2
a(2,i) = x(2,i) * tmp1 * tmp2
a(3,i) = x(3,i) * tmp1 * (tmp2 - tmp3)
! Calculate barycentric accelerations on the central body
tmp4 = m(i) / m(1)
acen(1) = acen(1) - tmp4 * a(1,i)
acen(2) = acen(2) - tmp4 * a(2,i)
acen(3) = acen(3) - tmp4 * a(3,i)
end do
!------------------------------------------------------------------------------
return
end subroutine mfo_obl
end module forces