-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
1284 lines (1000 loc) · 43.9 KB
/
test.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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""UnitTest classes for testing orbital_elements classes."""
import unittest
import numpy as np
import math
import mcpyi
import orbital_elements.utilities as utl
import orbital_elements.pose as pose
import orbital_elements.convert as convert
import orbital_elements.rv as rv
import orbital_elements.coe as coe
import orbital_elements.mee as mee
import orbital_elements.meeMl0 as meeMl0
__author__ = "Nathan I. Budd"
__email__ = "[email protected]"
__copyright__ = "Copyright 2017, LASR Lab"
__license__ = "MIT"
__version__ = "0.1"
__status__ = "Production"
__date__ = "02 Mar 2017"
DU = 1/6378.137 # DU/km (Earth Radius)
TU = 1/806.811 # TU/s
m = 1000
tol = 1e-14
# INITIAL CONDITIONS
mu = 1.0
a_0 = 8000. * DU
e_0 = 0.1
i_0 = 10.*np.pi/180.
W_0 = 10.*np.pi/180.
w_0 = 10.*np.pi/180.
f_0 = 10.*np.pi/180.
period = 2.*np.pi*(a_0**3 / mu)**.5
coe_0 = np.array([[a_0, e_0, i_0, W_0, w_0, f_0]])
rv_0 = convert.rv_coe(coe_0)
mee_0 = convert.mee_coe(coe_0)
T = np.linspace(0, 10, num=m).reshape((m, 1))
meeMl0_0 = convert.meeMl0_mee(T[0:1], mee_0)
coe_sltn = coe.KeplerianSolution(coe_0)(T)
orbits = math.ceil(T[-1]/period)
segs_per_orbit = 3
order_mcpi = 60
class TestRV(unittest.TestCase):
def test_hamiltonian_constant(self):
X0 = rv_0
X = np.tile(X0, (m, 1))
T = np.zeros((m, 1))
order = 6
H = rv.Hamiltonian(order=order)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_hamiltonian_solution(self):
X0 = rv_0
X = rv.KeplerianSolution(X0)(T)
order = 1
H = rv.Hamiltonian(order=order)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_compare_dynamics_to_solution(self):
X0 = rv_0
Xsol = rv.KeplerianSolution(X0)(T)
kep_dyn = rv.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(kep_dyn, domains, N, 'warm', X0, tol)
Xdyn = mcpi.solve_serial()(T)
np.testing.assert_allclose(Xsol, Xdyn, rtol=0, atol=tol*10)
def test_hamiltonian_dynamics(self):
X0 = rv_0
kep_dyn = rv.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(kep_dyn, domains, N, 'warm', X0, tol)
X = mcpi.solve_serial()(T)
order_H = 1
H = rv.Hamiltonian(order=order_H)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_zonal_gravity(self):
X0 = rv_0
order_H = 6
kep_dyn = rv.KeplerianDynamics()
zon_grav = rv.ZonalGravity(order=order_H)
system = utl.SystemDynamics(kep_dyn, zon_grav)
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(system, domains, N, 'warm', X0, tol)
X = mcpi.solve_serial()(T)
H = rv.Hamiltonian(order=order_H)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_zonal_round_trip(self):
X0_forward = rv_0
order_H = 6
kep_dyn_forward = rv.KeplerianDynamics()
zon_grav = rv.ZonalGravity(order=order_H)
sysfor = utl.SystemDynamics(kep_dyn_forward, zon_grav)
segments = orbits * segs_per_orbit
domains_for = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains_for) - 1
N = (order_mcpi,) * seg_number
mcpi_forward = mcpyi.MCPI(sysfor, domains_for, N, 'warm', X0_forward,
tol)
T_for = T
X_for = mcpi_forward.solve_serial()(T_for)
X0_bckward = X_for[-1:]
kep_dyn_bckward = rv.KeplerianDynamics()
sysbck = utl.SystemDynamics(kep_dyn_bckward, zon_grav)
domains_bck = [-x for x in domains_for]
mcpi_bckward = mcpyi.MCPI(sysbck, domains_bck, N, 'warm', X0_bckward,
tol)
T_bck = np.linspace(0, -10, num=m).reshape((m, 1))
X_bck = mcpi_bckward.solve_serial()(T_bck)
np.testing.assert_allclose(X0_forward, X_bck[-1:], rtol=0, atol=tol*10)
class TestCOE(unittest.TestCase):
def test_hamiltonian_constant(self):
X0 = coe_0
X = np.tile(X0, (m, 1))
T = np.zeros((m, 1))
order = 6
H = coe.Hamiltonian(order=order)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_hamiltonian_solution(self):
X0 = coe_0
X = coe.KeplerianSolution(X0)(T)
order = 1
H = coe.Hamiltonian(order=order)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_compare_keplerian_to_rv(self):
X0_coe = coe_0
X0_rv = rv_0
X_coe = coe.KeplerianSolution(X0_coe)(T)
kep_dyn = rv.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(kep_dyn, domains, N, 'warm', X0_rv, tol)
X_rv = mcpi.solve_serial()(T)
np.testing.assert_allclose(X_rv, convert.rv_coe(X_coe), rtol=0,
atol=tol*10)
def test_compare_dynamics_to_solution(self):
X0 = rv_0
Xsol = rv.KeplerianSolution(X0)(T)
kep_dyn = rv.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(kep_dyn, domains, N, 'warm', X0, tol)
Xdyn = mcpi.solve_serial()(T)
np.testing.assert_allclose(Xsol, Xdyn, rtol=0, atol=tol*10)
def test_hamiltonian_dynamics(self):
X0 = coe_0
kep_dyn = coe.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(kep_dyn, domains, N, 'warm', X0, tol)
X = mcpi.solve_serial()(T)
order_H = 1
H = coe.Hamiltonian(order=order_H)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_compare_dynamics_to_rv(self):
X0_coe = coe_0
X0_rv = rv_0
coe_dyn = coe.KeplerianDynamics()
rv_dyn = rv.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_coe = mcpyi.MCPI(coe_dyn, domains, N, 'warm', X0_coe, tol)
mcpi_rv = mcpyi.MCPI(rv_dyn, domains, N, 'warm', X0_rv, tol)
X_coe = mcpi_coe.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(X_rv, convert.rv_coe(X_coe), rtol=0,
atol=1e-13)
def test_zonal_gravity(self):
X0 = coe_0
order_H = 6
kep_dyn = coe.KeplerianDynamics()
zon_grav = coe.ZonalGravity(order=order_H)
system = utl.SystemDynamics(kep_dyn, perturbations=zon_grav)
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(system, domains, N, 'warm', X0, tol)
X = mcpi.solve_serial()(T)
H = coe.Hamiltonian(order=order_H)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_compare_zonal_to_rv(self):
X0_coe = coe_0
X0_rv = rv_0
order_H = 6
kep_dyn_coe = coe.KeplerianDynamics()
zon_grav_coe = coe.ZonalGravity(order=order_H)
syscoe = utl.SystemDynamics(kep_dyn_coe, zon_grav_coe)
kep_dyn_rv = rv.KeplerianDynamics()
zon_grav_rv = rv.ZonalGravity(order=order_H)
sysrv = utl.SystemDynamics(kep_dyn_rv, zon_grav_rv)
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_coe = mcpyi.MCPI(syscoe, domains, N, 'warm', X0_coe, tol)
mcpi_rv = mcpyi.MCPI(sysrv, domains, N, 'warm', X0_rv, tol)
X_coe = mcpi_coe.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(X_rv, convert.rv_coe(X_coe), rtol=0,
atol=tol*10)
def test_compare_a_eci_to_rv(self):
X0_coe = coe_0
X0_rv = rv_0
order_H = 6
kep_dyn_coe = coe.KeplerianDynamics()
zon_grav_coe = coe.ZonalGravity(order=order_H)
syscoe = utl.SystemDynamics(kep_dyn_coe, zon_grav_coe)
kep_dyn_rv = rv.KeplerianDynamics()
zon_grav_rv = rv.ZonalGravity(order=order_H)
sysrv = utl.SystemDynamics(kep_dyn_rv, zon_grav_rv)
segs_per_orbit = 6
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_coe = mcpyi.MCPI(syscoe, domains, N, 'warm', X0_coe, tol)
mcpi_rv = mcpyi.MCPI(sysrv, domains, N, 'warm', X0_rv, tol)
mcpi_coe.solve_serial()(T)
mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(zon_grav_coe.a_eci, zon_grav_rv.a_eci,
rtol=0, atol=tol)
def test_compare_constant_thrust_to_rv(self):
X0_coe = coe_0
X0_rv = rv_0
u = np.array([[0., 1e-6, 0.]])
kep_dyn_coe = coe.KeplerianDynamics()
conthrust_coe = coe.ConstantThrust(u)
syscoe = utl.SystemDynamics(kep_dyn_coe, conthrust_coe)
kep_dyn_rv = rv.KeplerianDynamics()
conthrust_rv = rv.ConstantThrust(u)
sysrv = utl.SystemDynamics(kep_dyn_rv, conthrust_rv)
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_coe = mcpyi.MCPI(syscoe, domains, N, 'warm', X0_coe, tol)
mcpi_rv = mcpyi.MCPI(sysrv, domains, N, 'warm', X0_rv, tol)
X_coe = mcpi_coe.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(X_rv, convert.rv_coe(X_coe), rtol=0,
atol=tol*10)
class TestMEE(unittest.TestCase):
def test_hamiltonian_constant(self):
X0 = mee_0
X = np.tile(X0, (m, 1))
T = np.zeros((m, 1))
order = 6
H = mee.Hamiltonian(order=order)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_hamiltonian_solution(self):
X0 = mee_0
X = mee.KeplerianSolution(X0)(T)
order = 1
H = mee.Hamiltonian(order=order)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_compare_keplerian_to_rv(self):
X0_mee = mee_0
X0_rv = rv_0
X_mee = mee.KeplerianSolution(X0_mee)(T)
X_rv = rv.KeplerianSolution(X0_rv)(T)
np.testing.assert_allclose(X_mee, convert.mee_rv(X_rv), rtol=0,
atol=tol*10)
def test_hamiltonian_dynamics(self):
X0 = mee_0
kep_dyn = mee.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(kep_dyn, domains, N, 'warm', X0, tol)
X = mcpi.solve_serial()(T)
order_H = 1
H = mee.Hamiltonian(order=order_H)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_compare_dynamics_to_rv(self):
X0_mee = mee_0
X0_rv = rv_0
mee_dyn = mee.KeplerianDynamics()
rv_dyn = rv.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_mee = mcpyi.MCPI(mee_dyn, domains, N, 'warm', X0_mee, tol)
mcpi_rv = mcpyi.MCPI(rv_dyn, domains, N, 'warm', X0_rv, tol)
X_mee = mcpi_mee.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(X_rv, convert.rv_mee(X_mee), rtol=0,
atol=tol*10)
def test_zonal_gravity(self):
X0 = mee_0
order_H = 6
kep_dyn = mee.KeplerianDynamics()
zon_grav = mee.ZonalGravity(order=order_H)
system = utl.SystemDynamics(kep_dyn, perturbations=zon_grav)
segs_per_orbit = 6
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(system, domains, N, 'warm', X0, tol)
X = mcpi.solve_serial()(T)
H = mee.Hamiltonian(order=order_H)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=0, atol=tol*10)
def test_compare_zonal_to_rv(self):
X0_mee = mee_0
X0_rv = rv_0
order_H = 6
kep_dyn_mee = mee.KeplerianDynamics()
zon_grav_mee = mee.ZonalGravity(order=order_H)
sysmee = utl.SystemDynamics(kep_dyn_mee, zon_grav_mee)
kep_dyn_rv = rv.KeplerianDynamics()
zon_grav_rv = rv.ZonalGravity(order=order_H)
sysrv = utl.SystemDynamics(kep_dyn_rv, zon_grav_rv)
segs_per_orbit = 6
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_mee = mcpyi.MCPI(sysmee, domains, N, 'warm', X0_mee, tol)
mcpi_rv = mcpyi.MCPI(sysrv, domains, N, 'warm', X0_rv, tol)
X_mee = mcpi_mee.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(X_rv, convert.rv_mee(X_mee), rtol=0,
atol=tol*10)
def test_compare_a_eci_to_rv(self):
X0_mee = mee_0
X0_rv = rv_0
order_H = 6
kep_dyn_mee = mee.KeplerianDynamics()
zon_grav_mee = mee.ZonalGravity(order=order_H)
kep_dyn_rv = rv.KeplerianDynamics()
zon_grav_rv = rv.ZonalGravity(order=order_H)
segs_per_orbit = 6
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_mee = mcpyi.MCPI(kep_dyn_mee, domains, N, 'warm', X0_mee, tol)
mcpi_rv = mcpyi.MCPI(kep_dyn_rv, domains, N, 'warm', X0_rv, tol)
X_mee = mcpi_mee.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
zon_grav_mee.eci_acceleration(T, convert.rv_mee(X_mee))
zon_grav_rv.eci_acceleration(T, X_rv)
np.testing.assert_allclose(zon_grav_mee.a_eci, zon_grav_rv.a_eci,
rtol=0, atol=tol)
def test_compare_zonal_to_coe(self):
X0_mee = mee_0
X0_coe = coe_0
order_H = 6
kep_dyn_mee = mee.KeplerianDynamics()
zon_grav_mee = mee.ZonalGravity(order=order_H)
sysmee = utl.SystemDynamics(kep_dyn_mee, zon_grav_mee)
kep_dyn_coe = coe.KeplerianDynamics()
zon_grav_coe = coe.ZonalGravity(order=order_H)
syscoe = utl.SystemDynamics(kep_dyn_coe, zon_grav_coe)
segs_per_orbit = 6
orbits = 1
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_mee = mcpyi.MCPI(sysmee, domains, N, 'warm', X0_mee, tol)
mcpi_coe = mcpyi.MCPI(syscoe, domains, N, 'warm', X0_coe, tol)
X_mee = mcpi_mee.solve_serial()(T)
X_coe = mcpi_coe.solve_serial()(T)
diff = convert.mod_angles(np.abs(X_coe-convert.coe_mee(X_mee)))
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_compare_constant_thrust_to_rv(self):
X0_mee = mee_0
X0_rv = rv_0
u = np.array([[1e-6, 1e-6, 1e-6]])
kep_dyn_mee = mee.KeplerianDynamics()
conthrust_mee = mee.ConstantThrust(u)
sysmee = utl.SystemDynamics(kep_dyn_mee, conthrust_mee)
kep_dyn_rv = rv.KeplerianDynamics()
conthrust_rv = rv.ConstantThrust(u)
sysrv = utl.SystemDynamics(kep_dyn_rv, conthrust_rv)
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_mee = mcpyi.MCPI(sysmee, domains, N, 'warm', X0_mee, tol)
mcpi_rv = mcpyi.MCPI(sysrv, domains, N, 'warm', X0_rv, tol)
X_mee = mcpi_mee.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(X_rv, convert.rv_mee(X_mee), rtol=0,
atol=tol*10)
class TestMEEMl0(unittest.TestCase):
def test_hamiltonian_constant(self):
X0 = meeMl0_0
X = np.tile(X0, (m, 1))
T = np.zeros((m, 1))
order = 6
H = meeMl0.Hamiltonian(order=order)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_hamiltonian_solution(self):
X0 = meeMl0_0
X = meeMl0.KeplerianSolution(X0)(T)
order = 1
H = meeMl0.Hamiltonian(order=order)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_compare_keplerian_to_rv(self):
X0_meeMl0 = meeMl0_0
X0_rv = rv_0
X_meeMl0 = meeMl0.KeplerianSolution(X0_meeMl0)(T)
X_rv = rv.KeplerianSolution(X0_rv)(T)
np.testing.assert_allclose(
convert.rv_mee(convert.mee_meeMl0(T, X_meeMl0)),
X_rv, rtol=0, atol=tol*10
)
def test_hamiltonian_dynamics(self):
X0 = meeMl0_0
kep_dyn = meeMl0.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(kep_dyn, domains, N, 'warm', X0, tol)
X = mcpi.solve_serial()(T)
order_H = 1
H = meeMl0.Hamiltonian(order=order_H)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=tol)
def test_compare_dynamics_to_rv(self):
X0_meeMl0 = meeMl0_0
X0_rv = rv_0
meeMl0_dyn = meeMl0.KeplerianDynamics()
rv_dyn = rv.KeplerianDynamics()
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_meeMl0 = mcpyi.MCPI(meeMl0_dyn, domains, N, 'warm', X0_meeMl0,
tol)
mcpi_rv = mcpyi.MCPI(rv_dyn, domains, N, 'warm', X0_rv, tol)
X_meeMl0 = mcpi_meeMl0.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(
X_rv,
convert.rv_mee(convert.mee_meeMl0(T, X_meeMl0)),
rtol=0, atol=tol*10)
def test_compare_a_eci_to_rv(self):
X0_meeMl0 = meeMl0_0
X0_rv = rv_0
order_H = 6
kep_dyn_meeMl0 = meeMl0.KeplerianDynamics()
zon_grav_meeMl0 = meeMl0.ZonalGravity(order=order_H)
kep_dyn_rv = rv.KeplerianDynamics()
zon_grav_rv = rv.ZonalGravity(order=order_H)
segs_per_orbit = 6
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_meeMl0 = mcpyi.MCPI(kep_dyn_meeMl0, domains, N, 'warm', X0_meeMl0,
tol)
mcpi_rv = mcpyi.MCPI(kep_dyn_rv, domains, N, 'warm', X0_rv, tol)
X_meeMl0 = mcpi_meeMl0.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
zon_grav_meeMl0.eci_acceleration(
T, convert.rv_mee(convert.mee_meeMl0(T, X_meeMl0))
)
zon_grav_rv.eci_acceleration(T, X_rv)
np.testing.assert_allclose(zon_grav_meeMl0.a_eci, zon_grav_rv.a_eci,
rtol=0, atol=tol)
def test_compare_constant_h_thrust_to_rv(self):
X0_meeMl0 = meeMl0_0
X0_rv = rv_0
u = np.array([[0., 0., 1e-6]])
kep_dyn_meeMl0 = meeMl0.KeplerianDynamics()
conthrust_meeMl0 = meeMl0.ConstantThrust(u)
sysmeeMl0 = utl.SystemDynamics(kep_dyn_meeMl0, conthrust_meeMl0)
kep_dyn_rv = rv.KeplerianDynamics()
conthrust_rv = rv.ConstantThrust(u)
sysrv = utl.SystemDynamics(kep_dyn_rv, conthrust_rv)
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_meeMl0 = mcpyi.MCPI(sysmeeMl0, domains, N, 'warm', X0_meeMl0, tol)
mcpi_rv = mcpyi.MCPI(sysrv, domains, N, 'warm', X0_rv, tol)
X_meeMl0 = mcpi_meeMl0.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
diff = convert.mod_angles(X_meeMl0 -
convert.meeMl0_mee(T, convert.mee_rv(X_rv)))
np.testing.assert_allclose(diff, 0.0, rtol=0, atol=tol*10)
def test_compare_constant_r_thrust_to_rv(self):
X0_meeMl0 = meeMl0_0
X0_rv = rv_0
u = np.array([[1e-6, 0., 0.]])
kep_dyn_meeMl0 = meeMl0.KeplerianDynamics()
conthrust_meeMl0 = meeMl0.ConstantThrust(u)
sysmeeMl0 = utl.SystemDynamics(kep_dyn_meeMl0, conthrust_meeMl0)
kep_dyn_rv = rv.KeplerianDynamics()
conthrust_rv = rv.ConstantThrust(u)
sysrv = utl.SystemDynamics(kep_dyn_rv, conthrust_rv)
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_meeMl0 = mcpyi.MCPI(sysmeeMl0, domains, N, 'warm', X0_meeMl0, tol)
mcpi_rv = mcpyi.MCPI(sysrv, domains, N, 'warm', X0_rv, tol)
X_meeMl0 = mcpi_meeMl0.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(
X_rv,
convert.rv_mee(convert.mee_meeMl0(T, X_meeMl0)),
rtol=0, atol=tol)
def test_compare_constant_theta_thrust_to_rv(self):
X0_meeMl0 = meeMl0_0
X0_rv = rv_0
u = np.array([[0., 1e-6, 0.]])
kep_dyn_meeMl0 = meeMl0.KeplerianDynamics()
conthrust_meeMl0 = meeMl0.ConstantThrust(u)
sysmeeMl0 = utl.SystemDynamics(kep_dyn_meeMl0, conthrust_meeMl0)
kep_dyn_rv = rv.KeplerianDynamics()
conthrust_rv = rv.ConstantThrust(u)
sysrv = utl.SystemDynamics(kep_dyn_rv, conthrust_rv)
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_meeMl0 = mcpyi.MCPI(sysmeeMl0, domains, N, 'warm', X0_meeMl0, tol)
mcpi_rv = mcpyi.MCPI(sysrv, domains, N, 'warm', X0_rv, tol)
X_meeMl0 = mcpi_meeMl0.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(
X_rv,
convert.rv_mee(convert.mee_meeMl0(T, X_meeMl0)),
rtol=0, atol=tol*10)
def test_compare_zonal_to_mee(self):
X0_meeMl0 = meeMl0_0
X0_mee = mee_0
order_H = 6
kep_dyn_meeMl0 = meeMl0.KeplerianDynamics()
zon_grav_meeMl0 = meeMl0.ZonalGravity(order=order_H)
sysmeeMl0 = utl.SystemDynamics(kep_dyn_meeMl0, zon_grav_meeMl0)
kep_dyn_mee = mee.KeplerianDynamics()
zon_grav_mee = mee.ZonalGravity(order=order_H)
sysmee = utl.SystemDynamics(kep_dyn_mee, zon_grav_mee)
segs_per_orbit = 6
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_meeMl0 = mcpyi.MCPI(sysmeeMl0, domains, N, 'warm', X0_meeMl0, tol)
mcpi_mee = mcpyi.MCPI(sysmee, domains, N, 'warm', X0_mee, tol)
X_meeMl0 = mcpi_meeMl0.solve_serial()(T)
X_mee = mcpi_mee.solve_serial()(T)
diff = convert.mod_angles(X_mee - convert.mee_meeMl0(T, X_meeMl0))
np.testing.assert_allclose(diff, 0.0, rtol=0, atol=tol*10)
def test_zonal_gravity(self):
X0 = meeMl0_0
order_H = 6
kep_dyn = meeMl0.KeplerianDynamics()
zon_grav = meeMl0.ZonalGravity(order=order_H)
system = utl.SystemDynamics(kep_dyn, perturbations=zon_grav)
segs_per_orbit = 6
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi = mcpyi.MCPI(system, domains, N, 'warm', X0, tol)
X = mcpi.solve_serial()(T)
H = meeMl0.Hamiltonian(order=order_H)(T, X)
np.testing.assert_allclose(H[0, 0], H, rtol=0, atol=tol*10)
def test_compare_zonal_to_rv(self):
X0_meeMl0 = meeMl0_0
X0_rv = rv_0
order_H = 6
kep_dyn_meeMl0 = meeMl0.KeplerianDynamics()
zon_grav_meeMl0 = meeMl0.ZonalGravity(order=order_H)
sysmeeMl0 = utl.SystemDynamics(kep_dyn_meeMl0, zon_grav_meeMl0)
kep_dyn_rv = rv.KeplerianDynamics()
zon_grav_rv = rv.ZonalGravity(order=order_H)
sysrv = utl.SystemDynamics(kep_dyn_rv, zon_grav_rv)
segs_per_orbit = 6
segments = orbits * segs_per_orbit
domains = [k*period/segs_per_orbit for k in range(segments+1)]
seg_number = len(domains) - 1
N = (order_mcpi,) * seg_number
mcpi_meeMl0 = mcpyi.MCPI(sysmeeMl0, domains, N, 'warm', X0_meeMl0, tol)
mcpi_rv = mcpyi.MCPI(sysrv, domains, N, 'warm', X0_rv, tol)
X_meeMl0 = mcpi_meeMl0.solve_serial()(T)
X_rv = mcpi_rv.solve_serial()(T)
np.testing.assert_allclose(
X_rv,
convert.rv_mee(convert.mee_meeMl0(T, X_meeMl0)),
rtol=0, atol=tol*10)
def test_dgve_dlmnts_dpdot_dp(self):
X0_meeMl0 = meeMl0_0
T0 = T[0:1]
a_d = np.array([[0, 1, 0]])
dG_dX = meeMl0.dGVE_dLMNTS(h=1e-7)(T0, X0_meeMl0, a_d)
p = mee_0[0, 0]
f = mee_0[0, 1]
g = mee_0[0, 2]
L = mee_0[0, 5]
dpdot_dp = (3 * p**.5 / mu**.5 / (1 + f*np.cos(L) + g*np.sin(L)) *
a_d[0, 1])
np.testing.assert_allclose(dG_dX[0, 0, 0], dpdot_dp,
rtol=0, atol=1e-5)
class TestPose(unittest.TestCase):
def test_single_dcm(self):
axes = [1]
angles = np.array([[1]])
dcm = pose.euler_angles(axes, angles)
self.assertEqual(dcm.shape, (1, 3, 3))
def test_313_rotation(self):
axes = [3, 1, 3]
angles = np.array([[1, 1.5, 2]])
dcm = pose.euler_angles(axes, angles)
self.assertEqual(dcm.shape, (1, 3, 3))
class TestConvert(unittest.TestCase):
def test_coef_coeE_coef(self):
coef = convert.mod_angles(coe_sltn)
coeE = convert.coeE_coef(coef)
coef2 = convert.mod_angles(convert.coef_coeE(coeE))
diff = convert.mod_angles(np.abs(coef-coef2), angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_coeE_coef_coeE(self):
coeE = convert.mod_angles(convert.coeE_coef(coe_sltn))
coef = convert.coef_coeE(coeE)
coeE2 = convert.mod_angles(convert.coeE_coef(coef))
diff = convert.mod_angles(np.abs(coeE-coeE2), angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_coeE_coeM_coeE(self):
coeE = convert.mod_angles(convert.coeE_coef(coe_sltn))
coeM = convert.coeM_coeE(coeE)
coeE2 = convert.mod_angles(convert.coeE_coeM(coeM))
diff = convert.mod_angles(np.abs(coeE-coeE2), angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_coeM_coeE_coeM(self):
coeE = convert.coeE_coef(coe_sltn)
coeM = convert.mod_angles(convert.coeM_coeE(coeE))
coeE = convert.coeE_coeM(coeM)
coeM2 = convert.mod_angles(convert.coeM_coeE(coeE))
diff = convert.mod_angles(np.abs(coeM-coeM2), angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_coef_coeM_coef(self):
coef = convert.mod_angles(coe_sltn)
coeM = convert.coeM_coef(coef)
coef2 = convert.mod_angles(convert.coef_coeM(coeM))
diff = convert.mod_angles(np.abs(coef-coef2), angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_coeM_coef_coeM(self):
coeM = convert.mod_angles(convert.coeM_coef(coe_sltn))
coef = convert.coef_coeM(coeM)
coeM2 = convert.mod_angles(convert.coeM_coef(coef))
diff = convert.mod_angles(np.abs(coeM-coeM2), angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_coe_mee_coe(self):
coe = convert.mod_angles(coe_sltn)
mee = convert.mee_coe(coe)
coe2 = convert.mod_angles(convert.coe_mee(mee))
diff = convert.mod_angles(np.abs(coe-coe2), angle_indices=[2, 3, 4, 5])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_mee_coe_mee(self):
mee = convert.mod_angles(convert.mee_coe(coe_sltn))
coe = convert.coe_mee(mee)
mee2 = convert.mod_angles(convert.mee_coe(coe))
diff = convert.mod_angles(np.abs(mee-mee2), angle_indices=[5])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_mee_rv_mee(self):
mee = convert.mod_angles(convert.mee_coe(coe_sltn))
rv = convert.rv_mee(mee)
mee2 = convert.mod_angles(convert.mee_rv(rv))
np.testing.assert_allclose(mee, mee2, rtol=0, atol=tol)
def test_rv_mee_rv(self):
mee = convert.mod_angles(convert.mee_coe(coe_sltn))
rv = convert.rv_mee(mee)
mee = convert.mee_rv(rv)
rv2 = convert.rv_mee(mee)
np.testing.assert_allclose(rv, rv2, rtol=0, atol=tol)
def test_coe_rv_coe(self):
coe = coe_sltn
rv = convert.rv_coe(coe)
coe2 = convert.coe_rv(rv)
diff = convert.mod_angles(np.abs(coe-coe2), angle_indices=[2, 3, 4, 5])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol*10)
def test_rv_coe_rv(self):
rv = convert.rv_coe(coe_sltn)
coe = convert.coe_rv(rv)
rv2 = convert.rv_coe(coe)
np.testing.assert_allclose(rv, rv2, rtol=0, atol=tol)
def test_meeEl_meeMl_meeEl(self):
meeEl = convert.mod_angles(convert.mee_coe(coe_sltn))
meeMl = convert.meeMl_meeEl(meeEl)
meeEl2 = convert.mod_angles(convert.meeEl_meeMl(meeMl))
diff = convert.mod_angles(np.abs(meeEl-meeEl2),
angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_meeMl_meeEl_meeMl(self):
meeEl = convert.mod_angles(convert.mee_coe(coe_sltn))
meeMl = convert.mod_angles(convert.meeMl_meeEl(meeEl))
meeEl = convert.meeEl_meeMl(meeMl)
meeMl2 = convert.mod_angles(convert.meeMl_meeEl(meeEl))
diff = convert.mod_angles(np.abs(meeMl-meeMl2), angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_meeEl_meefl_meeEl(self):
meeEl = convert.mod_angles(convert.mee_coe(coe_sltn))
meefl = convert.meefl_meeEl(meeEl)
meeEl2 = convert.mod_angles(convert.meeEl_meefl(meefl))
diff = convert.mod_angles(np.abs(meeEl-meeEl2),
angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_meefl_meeEl_meefl(self):
meeEl = convert.mod_angles(convert.mee_coe(coe_sltn))
meefl = convert.mod_angles(convert.meefl_meeEl(meeEl))
meeEl = convert.meeEl_meefl(meefl)
meefl2 = convert.mod_angles(convert.meefl_meeEl(meeEl))
diff = convert.mod_angles(np.abs(meefl-meefl2), angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_meefl_meeMl_meefl(self):
meefl = convert.mod_angles(convert.mee_coe(coe_sltn))
meeMl = convert.meeMl_meefl(meefl)
meefl2 = convert.mod_angles(convert.meefl_meeMl(meeMl))
diff = convert.mod_angles(np.abs(meefl-meefl2),
angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_meeMl_meefl_meeMl(self):
meefl = convert.mod_angles(convert.mee_coe(coe_sltn))
meeMl = convert.mod_angles(convert.meeMl_meefl(meefl))
meefl = convert.meefl_meeMl(meeMl)
meeMl2 = convert.mod_angles(convert.meeMl_meefl(meefl))
diff = convert.mod_angles(np.abs(meeMl-meeMl2), angle_indices=[0])
indices_2pi = np.where(2*np.pi-tol < diff)
diff[indices_2pi] -= 2*np.pi
np.testing.assert_allclose(diff, 0., rtol=0, atol=tol)
def test_compare_meeMl_meeEl_to_coeM_coeE(self):
coeE = convert.mod_angles(coe_sltn)