-
Notifications
You must be signed in to change notification settings - Fork 9
/
solver.py
570 lines (457 loc) · 22.5 KB
/
solver.py
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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
import copy
from vector3 import *
def SymplecticEuler(bodies, vessels, surface_points, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t):
for rp in radiation_pressures:
rp.update_occultation(bodies)
rp.update_mass(maneuvers, sim_time, delta_t)
accel = rp.calc_accel()
rp.vessel.update_vel(accel, delta_t)
# do not update vessel position in this 'for' loop, we did not apply all accelerations!
for ad in atmospheric_drags:
ad.update_mass(maneuvers, sim_time, delta_t)
accel = ad.calc_accel()
ad.vessel.update_vel(accel, delta_t)
# do not update vessel position in this 'for' loop, we did not apply all accelerations!
# GR
for sch in schwarzschilds:
accel = sch.compute_Schwarzschild()
sch.vessel.update_vel(accel, delta_t)
for lt in lensethirrings:
accel = lt.compute_LenseThirring()
lt.vessel.update_vel(accel, delta_t)
for m in maneuvers:
m.perform_maneuver(sim_time, delta_t)
for v in vessels:
accel = vec3(0, 0, 0)
for b in bodies:
accel = accel + v.get_gravity_by(b)
v.update_vel(accel, delta_t)
for x in bodies:
accel = vec3(0, 0, 0)
for y in bodies:
if not x == y: # don't attempt to apply gravity to self
accel = accel + x.get_gravity_by(y)
x.update_vel(accel, delta_t)
# update positions after all accelerations are calculated
for v in vessels:
v.update_pos(delta_t)
v.update_traj_history()
v.update_draw_traj_history()
for x in bodies:
x.update_pos(delta_t)
# planets rotate!
x.update_orient(delta_t)
x.update_traj_history()
# update surface point positions
for sp in surface_points:
sp.update_state_vectors(delta_t)
def VelocityVerlet(bodies, vessels, surface_points, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t):
# update masses and occultation calculations
for ad in atmospheric_drags:
ad.update_mass(maneuvers, sim_time, delta_t)
for rp in radiation_pressures:
rp.update_occultation(bodies)
rp.update_mass(maneuvers, sim_time, delta_t)
# - - - FIRST ACCELERATIONS - - -
vessel_accels_1 = [vec3(0, 0, 0)] * len(vessels)
body_accels_1 = [vec3(0, 0, 0)] * len(bodies)
# calculate celestial body accelerations due to gravity
for x in bodies:
for y in bodies:
if not x == y:
b_idx = bodies.index(x)
body_accels_1[b_idx] = body_accels_1[b_idx] + x.get_gravity_by(y)
# calculate vessel accelerations due to gravity
for v in vessels:
v_idx = vessels.index(v)
for b in bodies:
vessel_accels_1[v_idx] = vessel_accels_1[v_idx] + v.get_gravity_by(b)
# calculate vessel accelerations due to maneuvers
for m in maneuvers:
if m.vessel in vessels:
v_idx = vessels.index(m.vessel)
accel_vec = m.get_accel(sim_time, delta_t)
vessel_accels_1[v_idx] = vessel_accels_1[v_idx] + accel_vec
# calculate vessel accelerations due to atmospheric drag
for ad in atmospheric_drags:
if ad.vessel in vessels:
v_idx = vessels.index(ad.vessel)
accel_vec = ad.calc_accel()
vessel_accels_1[v_idx] = vessel_accels_1[v_idx] + accel_vec
# calculate vessel accelerations due to radiation pressure
for rp in radiation_pressures:
if rp.vessel in vessels:
v_idx = vessels.index(rp.vessel)
accel_vec = rp.calc_accel()
vessel_accels_1[v_idx] = vessel_accels_1[v_idx] + accel_vec
# calculate vessel accelerations due to relativistic effects
for sch in schwarzschilds:
if sch.vessel in vessels:
v_idx = vessels.index(sch.vessel)
accel_vec = sch.compute_Schwarzschild()
vessel_accels_1[v_idx] = vessel_accels_1[v_idx] + accel_vec
for lt in lensethirrings:
if lt.vessel in vessels:
v_idx = vessels.index(lt.vessel)
accel_vec = lt.compute_LenseThirring()
vessel_accels_1[v_idx] = vessel_accels_1[v_idx] + accel_vec
# - - - POSITION UPDATE - - -
for b in bodies:
b_idx = bodies.index(b)
b.set_pos(b.pos + b.vel * delta_t + body_accels_1[b_idx] * 0.5 * delta_t**2)
for v in vessels:
v_idx = vessels.index(v)
v.set_pos(v.pos + v.vel * delta_t + vessel_accels_1[v_idx] * 0.5 * delta_t**2)
# - - - SECOND ACCELERATIONS - - -
vessel_accels_2 = [vec3(0, 0, 0)] * len(vessels)
body_accels_2 = [vec3(0, 0, 0)] * len(bodies)
# calculate celestial body accelerations due to gravity
for x in bodies:
for y in bodies:
if not x == y:
b_idx = bodies.index(x)
body_accels_2[b_idx] = body_accels_2[b_idx] + x.get_gravity_by(y)
# calculate vessel accelerations due to gravity
for v in vessels:
v_idx = vessels.index(v)
for b in bodies:
vessel_accels_2[v_idx] = vessel_accels_2[v_idx] + v.get_gravity_by(b)
# calculate vessel accelerations due to maneuvers
for m in maneuvers:
if m.vessel in vessels:
v_idx = vessels.index(m.vessel)
accel_vec = m.get_accel((sim_time + delta_t), delta_t)
vessel_accels_2[v_idx] = vessel_accels_2[v_idx] + accel_vec
# calculate vessel accelerations due to atmospheric drag
for ad in atmospheric_drags:
if ad.vessel in vessels:
v_idx = vessels.index(ad.vessel)
accel_vec = ad.calc_accel()
vessel_accels_2[v_idx] = vessel_accels_2[v_idx] + accel_vec
# calculate vessel accelerations due to radiation pressure
for rp in radiation_pressures:
if rp.vessel in vessels:
v_idx = vessels.index(rp.vessel)
accel_vec = rp.calc_accel()
vessel_accels_2[v_idx] = vessel_accels_2[v_idx] + accel_vec
# calculate vessel accelerations due to relativistic effects
for sch in schwarzschilds:
if sch.vessel in vessels:
v_idx = vessels.index(sch.vessel)
accel_vec = sch.compute_Schwarzschild()
vessel_accels_2[v_idx] = vessel_accels_2[v_idx] + accel_vec
for lt in lensethirrings:
if lt.vessel in vessels:
v_idx = vessels.index(lt.vessel)
accel_vec = lt.compute_LenseThirring()
vessel_accels_2[v_idx] = vessel_accels_2[v_idx] + accel_vec
# - - - VELOCITY UPDATE - - -
for b in bodies:
b_idx = bodies.index(b)
b.set_vel(b.vel + (body_accels_1[b_idx] + body_accels_2[b_idx]) * 0.5 * delta_t)
for v in vessels:
v_idx = vessels.index(v)
v.set_vel(v.vel + (vessel_accels_1[v_idx] + vessel_accels_2[v_idx]) * 0.5 * delta_t)
for m in maneuvers:
m.update_mass(sim_time, delta_t)
# planet orientation update
for b in bodies:
b.update_orient(delta_t)
b.update_traj_history()
for sp in surface_points:
sp.update_state_vectors(delta_t)
# update graphics related things
for v in vessels:
v.update_traj_history()
v.update_draw_traj_history()
def Yoshida4(bodies, vessels, surface_points, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t):
# update masses and occultation calculations
for ad in atmospheric_drags:
ad.update_mass(maneuvers, sim_time, delta_t)
for rp in radiation_pressures:
rp.update_occultation(bodies)
rp.update_mass(maneuvers, sim_time, delta_t)
def compute_accels_at_state(vessels, bodies, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t):
vessel_accels = [vec3(0, 0, 0)] * len(vessels)
body_accels = [vec3(0, 0, 0)] * len(bodies)
# calculate celestial body accelerations due to gravity
for x in bodies:
for y in bodies:
if not x == y:
b_idx = bodies.index(x)
body_accels[b_idx] = body_accels[b_idx] + x.get_gravity_by(y)
# calculate vessel accelerations due to gravity
for v in vessels:
v_idx = vessels.index(v)
for b in bodies:
vessel_accels[v_idx] = vessel_accels[v_idx] + v.get_gravity_by(b)
# calculate vessel accelerations due to maneuvers
for m in maneuvers:
if m.vessel in vessels:
v_idx = vessels.index(m.vessel)
accel_vec = m.get_accel(sim_time, delta_t)
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
# calculate vessel accelerations due to atmospheric drag
for ad in atmospheric_drags:
if ad.vessel in vessels:
v_idx = vessels.index(ad.vessel)
accel_vec = ad.calc_accel()
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
# calculate vessel accelerations due to radiation pressure
for rp in radiation_pressures:
if rp.vessel in vessels:
v_idx = vessels.index(rp.vessel)
accel_vec = rp.calc_accel()
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
# calculate vessel accelerations due to relativistic effects
for sch in schwarzschilds:
if sch.vessel in vessels:
v_idx = vessels.index(sch.vessel)
accel_vec = sch.compute_Schwarzschild()
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
for lt in lensethirrings:
if lt.vessel in vessels:
v_idx = vessels.index(lt.vessel)
accel_vec = lt.compute_LenseThirring()
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
return vessel_accels, body_accels
def update_objs_pos(vessels, bodies, const, dt):
for v in vessels:
v.pos = v.pos + v.vel * const * dt
for b in bodies:
b.pos = b.pos + b.vel * const * dt
def update_objs_vel(vessels, bodies, const, vacc, bacc, dt):
for idx_v, v in enumerate(vessels):
v.vel = v.vel + vacc[idx_v] * const * dt
for idx_b, b in enumerate(bodies):
b.vel = b.vel + bacc[idx_b] * const * dt
# - - - CONSTANTS - - -
# w0 = -1.7024143839193153
# w1 = 1.3512071919596578
c1 = 0.6756035959798289
c2 = -0.17560359597982877
c3 = -0.17560359597982877
c4 = 0.6756035959798289
d1 = 1.3512071919596578
d2 = -1.7024143839193153
d3 = 1.3512071919596578
update_objs_pos(vessels, bodies, c1, delta_t)
vacc, bacc = compute_accels_at_state(vessels, bodies, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t)
update_objs_vel(vessels, bodies, d1, vacc, bacc, delta_t)
update_objs_pos(vessels, bodies, c2, delta_t)
vacc, bacc = compute_accels_at_state(vessels, bodies, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t)
update_objs_vel(vessels, bodies, d2, vacc, bacc, delta_t)
update_objs_pos(vessels, bodies, c3, delta_t)
vacc, bacc = compute_accels_at_state(vessels, bodies, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t)
update_objs_vel(vessels, bodies, d3, vacc, bacc, delta_t)
update_objs_pos(vessels, bodies, c4, delta_t)
# this has to be done separately
for m in maneuvers:
m.update_mass(sim_time, delta_t)
# planet orientation update
for b in bodies:
b.update_orient(delta_t)
b.update_traj_history()
for sp in surface_points:
sp.update_state_vectors(delta_t)
# update graphics related things
for v in vessels:
v.update_traj_history()
v.update_draw_traj_history()
def Yoshida8(bodies, vessels, surface_points, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t):
# update masses and occultation calculations
for ad in atmospheric_drags:
ad.update_mass(maneuvers, sim_time, delta_t)
for rp in radiation_pressures:
rp.update_occultation(bodies)
rp.update_mass(maneuvers, sim_time, delta_t)
def compute_accels_at_state(vessels, bodies, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t):
vessel_accels = [vec3(0, 0, 0)] * len(vessels)
body_accels = [vec3(0, 0, 0)] * len(bodies)
# calculate celestial body accelerations due to gravity
for x in bodies:
for y in bodies:
if not x == y:
b_idx = bodies.index(x)
body_accels[b_idx] = body_accels[b_idx] + x.get_gravity_by(y)
# calculate vessel accelerations due to gravity
for v in vessels:
v_idx = vessels.index(v)
for b in bodies:
vessel_accels[v_idx] = vessel_accels[v_idx] + v.get_gravity_by(b)
# calculate vessel accelerations due to maneuvers
for m in maneuvers:
if m.vessel in vessels:
v_idx = vessels.index(m.vessel)
accel_vec = m.get_accel(sim_time, delta_t)
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
# calculate vessel accelerations due to atmospheric drag
for ad in atmospheric_drags:
if ad.vessel in vessels:
v_idx = vessels.index(ad.vessel)
accel_vec = ad.calc_accel()
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
# calculate vessel accelerations due to radiation pressure
for rp in radiation_pressures:
if rp.vessel in vessels:
v_idx = vessels.index(rp.vessel)
accel_vec = rp.calc_accel()
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
# calculate vessel accelerations due to relativistic effects
for sch in schwarzschilds:
if sch.vessel in vessels:
v_idx = vessels.index(sch.vessel)
accel_vec = sch.compute_Schwarzschild()
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
for lt in lensethirrings:
if lt.vessel in vessels:
v_idx = vessels.index(lt.vessel)
accel_vec = lt.compute_LenseThirring()
vessel_accels[v_idx] = vessel_accels[v_idx] + accel_vec
return vessel_accels, body_accels
def update_objs_pos(vessels, bodies, const, dt):
for v in vessels:
v.pos = v.pos + v.vel * const * dt
for b in bodies:
b.pos = b.pos + b.vel * const * dt
def update_objs_vel(vessels, bodies, const, vacc, bacc, dt):
for idx_v, v in enumerate(vessels):
v.vel = v.vel + vacc[idx_v] * const * dt
for idx_b, b in enumerate(bodies):
b.vel = b.vel + bacc[idx_b] * const * dt
# - - - CONSTANTS - - -
w1 = 0.311790812418427e0
w2 = -0.155946803821447e1
w3 = -0.167896928259640e1
w4 = 0.166335809963315e1
w5 = -0.106458714789183e1
w6 = 0.136934946416871e1
w7 = 0.629030650210433e0
w0 = 1.65899088454396 # (1 - 2 * (w1 + w2 + w3 + w4 + w5 + w6 + w7))
ds = [w7, w6, w5, w4, w3, w2, w1, w0, w1, w2, w3, w4, w5, w6, w7]
# cs = [w7 / 2, (w7 + w6) / 2, (w6 + w5) / 2, (w5 + w4) / 2,
# (w4 + w3) / 2, (w3 + w2) / 2, (w2 + w1) / 2, (w1 + w0) / 2,
# (w1 + w0) / 2, (w2 + w1) / 2, (w3 + w2) / 2, (w4 + w3) / 2,
# (w5 + w4) / 2, (w6 + w5) / 2, (w7 + w6) / 2, w7 / 2]
cs = [0.3145153251052165, 0.9991900571895715, 0.15238115813844, 0.29938547587066, -0.007805591481624963,
-1.619218660405435, -0.6238386128980216, 0.9853908484811935, 0.9853908484811935, -0.6238386128980216,
-1.619218660405435, -0.007805591481624963, 0.29938547587066, 0.15238115813844, 0.9991900571895715,
0.3145153251052165]
for i in range(15):
update_objs_pos(vessels, bodies, cs[i], delta_t)
vacc, bacc = compute_accels_at_state(vessels, bodies, maneuvers, atmospheric_drags, radiation_pressures,
schwarzschilds, lensethirrings, sim_time, delta_t)
update_objs_vel(vessels, bodies, ds[i], vacc, bacc, delta_t)
update_objs_pos(vessels, bodies, cs[15], delta_t)
# this has to be done separately
for m in maneuvers:
m.update_mass(sim_time, delta_t)
# planet orientation update
for b in bodies:
b.update_orient(delta_t)
b.update_traj_history()
for sp in surface_points:
sp.update_state_vectors(delta_t)
# update graphics related things
for v in vessels:
v.update_traj_history()
v.update_draw_traj_history()
def adaptive(bodies, vessels, surface_points, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t,
solver_type=0, tolerance=1e-8):
c_delta_t = delta_t
z_delta_t = delta_t * 0.5
original_delta_t = delta_t
def copylist(inlist):
outlist = []
for obj in inlist:
outlist.append(copy.copy(obj))
return outlist
warn = False
good_step = False
increase_delta_t = False
max_attempts = 100
attempts = 0
while (not good_step) and (attempts < max_attempts):
attempts += 1
# safekeep original states, use copies for computations
c_bodies = copylist(bodies)
c_vessels = copylist(vessels)
c_surface_points = copylist(surface_points)
c_maneuvers = copylist(maneuvers)
c_atmospheric_drags = copylist(atmospheric_drags)
c_radiation_pressures = copylist(radiation_pressures)
c_schwarzschilds = copylist(schwarzschilds)
c_lensethirrings = copylist(lensethirrings)
c_sim_time = sim_time
# solve the step using delta_t
if solver_type == 0:
SymplecticEuler(c_bodies, c_vessels, c_surface_points, c_maneuvers, c_atmospheric_drags, c_radiation_pressures, c_schwarzschilds, c_lensethirrings, c_sim_time, c_delta_t)
elif solver_type == 1:
VelocityVerlet(c_bodies, c_vessels, c_surface_points, c_maneuvers, c_atmospheric_drags, c_radiation_pressures, c_schwarzschilds, c_lensethirrings, c_sim_time, c_delta_t)
elif solver_type == 2:
Yoshida4(c_bodies, c_vessels, c_surface_points, c_maneuvers, c_atmospheric_drags, c_radiation_pressures, c_schwarzschilds, c_lensethirrings, c_sim_time, c_delta_t)
else:
Yoshida8(c_bodies, c_vessels, c_surface_points, c_maneuvers, c_atmospheric_drags, c_radiation_pressures, c_schwarzschilds, c_lensethirrings, c_sim_time, c_delta_t)
# save results
d1_positions = []
for obj in c_bodies:
d1_positions.append(obj.pos)
for obj in c_vessels:
d1_positions.append(obj.pos)
# solve the step using using delta_t / 2
z_bodies = copylist(bodies)
z_vessels = copylist(vessels)
z_surface_points = copylist(surface_points)
z_maneuvers = copylist(maneuvers)
z_atmospheric_drags = copylist(atmospheric_drags)
z_radiation_pressures = copylist(radiation_pressures)
z_schwarzschilds = copylist(schwarzschilds)
z_lensethirrings = copylist(lensethirrings)
z_sim_time = sim_time
if solver_type == 0:
SymplecticEuler(z_bodies, z_vessels, z_surface_points, z_maneuvers, z_atmospheric_drags, z_radiation_pressures, z_schwarzschilds, z_lensethirrings, z_sim_time, z_delta_t)
SymplecticEuler(z_bodies, z_vessels, z_surface_points, z_maneuvers, z_atmospheric_drags, z_radiation_pressures, z_schwarzschilds, z_lensethirrings, z_sim_time, z_delta_t)
elif solver_type == 1:
VelocityVerlet(z_bodies, z_vessels, z_surface_points, z_maneuvers, z_atmospheric_drags, z_radiation_pressures, z_schwarzschilds, z_lensethirrings, z_sim_time, z_delta_t)
VelocityVerlet(z_bodies, z_vessels, z_surface_points, z_maneuvers, z_atmospheric_drags, z_radiation_pressures, z_schwarzschilds, z_lensethirrings, z_sim_time, z_delta_t)
elif solver_type == 2:
Yoshida4(z_bodies, z_vessels, z_surface_points, z_maneuvers, z_atmospheric_drags, z_radiation_pressures, z_schwarzschilds, z_lensethirrings, z_sim_time, z_delta_t)
Yoshida4(z_bodies, z_vessels, z_surface_points, z_maneuvers, z_atmospheric_drags, z_radiation_pressures, z_schwarzschilds, z_lensethirrings, z_sim_time, z_delta_t)
else:
Yoshida8(z_bodies, z_vessels, z_surface_points, z_maneuvers, z_atmospheric_drags, z_radiation_pressures, z_schwarzschilds, z_lensethirrings, z_sim_time, z_delta_t)
Yoshida8(z_bodies, z_vessels, z_surface_points, z_maneuvers, z_atmospheric_drags, z_radiation_pressures, z_schwarzschilds, z_lensethirrings, z_sim_time, z_delta_t)
# save results
d2_positions = []
for obj in z_bodies:
d2_positions.append(obj.pos)
for obj in z_vessels:
d2_positions.append(obj.pos)
# compare all
if len(d1_positions) == len(d2_positions):
errors = []
for i in range(len(d1_positions)):
errors.append((d1_positions[i] - d2_positions[i]).mag())
for e in errors:
if e > tolerance:
delta_t = 0.5 * delta_t
else:
good_step = True
if e < tolerance * 0.3:
increase_delta_t = True
else:
good_step = True # something changed during this step - can't compare
if attempts == max_attempts:
delta_t = original_delta_t
increase_delta_t = False
warn = True
if solver_type == 0:
SymplecticEuler(bodies, vessels, surface_points, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t)
elif solver_type == 1:
VelocityVerlet(bodies, vessels, surface_points, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t)
elif solver_type == 2:
Yoshida4(bodies, vessels, surface_points, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t)
elif solver_type == 3:
Yoshida8(bodies, vessels, surface_points, maneuvers, atmospheric_drags, radiation_pressures, schwarzschilds, lensethirrings, sim_time, delta_t)
return delta_t, increase_delta_t, warn
# def RK89() ?
# Maybe with a not-energy-conserving warning.