-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththree_body_problem.py
More file actions
1169 lines (938 loc) · 39.7 KB
/
three_body_problem.py
File metadata and controls
1169 lines (938 loc) · 39.7 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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Three-body problem implementation for mathematical analysis.
This module provides implementations of various aspects of the three-body problem,
including Hamiltonian formulation, equations of motion, and special solutions
like homothetic orbits and Lagrangian solutions.
"""
import numpy as np
from typing import Tuple, List, Callable, Dict, Optional, Union
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt
# Import local modules
from quaternion import Quaternion
class ThreeBodyProblem:
"""
Class implementing the three-body problem.
This class provides methods for simulating and analyzing the three-body problem
with various mass configurations and initial conditions.
"""
def __init__(self, masses: np.ndarray, G: float = 1.0):
"""
Initialize a three-body problem with specified masses.
Args:
masses: Array of three masses [m1, m2, m3]
G: Gravitational constant (default=1.0 for normalized units)
"""
if len(masses) != 3:
raise ValueError("Must provide exactly three masses")
self.masses = np.array(masses, dtype=float)
self.G = float(G)
self.dim = 3 # spatial dimension (3D)
# Compute mass parameter sigma
m1, m2, m3 = self.masses
self.sigma = (m1*m2 + m2*m3 + m3*m1) / (m1 + m2 + m3)**2
# Check if sigma is one of the exceptional values
self.exceptional_sigmas = {
"1/3": 1/3,
"2^3/3^3": 2**3/3**3,
"2/3^2": 2/3**2
}
# Identify which exceptional value is closest
min_diff = float('inf')
self.closest_exceptional = None
for name, value in self.exceptional_sigmas.items():
diff = abs(self.sigma - value)
if diff < min_diff:
min_diff = diff
self.closest_exceptional = name
self.is_exceptional = min_diff < 1e-10
def hamiltonian(self, state: np.ndarray) -> float:
"""
Compute the Hamiltonian (total energy) for a given state.
The Hamiltonian is H = T + V, where T is the kinetic energy and V is the potential energy.
Args:
state: State vector [r1, r2, r3, p1, p2, p3] where ri and pi are 3D vectors
Returns:
The value of the Hamiltonian (total energy)
"""
# Extract positions and momenta
# Each position and momentum is a 3D vector
r1 = state[0:3]
r2 = state[3:6]
r3 = state[6:9]
p1 = state[9:12]
p2 = state[12:15]
p3 = state[15:18]
# Compute kinetic energy
m1, m2, m3 = self.masses
T = np.sum(p1**2) / (2*m1) + np.sum(p2**2) / (2*m2) + np.sum(p3**2) / (2*m3)
# Compute potential energy
r12 = np.linalg.norm(r1 - r2)
r23 = np.linalg.norm(r2 - r3)
r31 = np.linalg.norm(r3 - r1)
V = -self.G * (m1*m2/r12 + m2*m3/r23 + m3*m1/r31)
return T + V
def equations_of_motion(self, t: float, state: np.ndarray) -> np.ndarray:
"""
Compute the time derivatives of the state vector.
This function implements the Hamiltonian equations of motion:
dr_i/dt = ∂H/∂p_i
dp_i/dt = -∂H/∂r_i
Args:
t: Time (not used explicitly as the system is autonomous)
state: State vector [r1, r2, r3, p1, p2, p3] where ri and pi are 3D vectors
Returns:
Time derivatives of the state vector [dr1/dt, dr2/dt, dr3/dt, dp1/dt, dp2/dt, dp3/dt]
"""
# Extract positions and momenta
r1 = state[0:3]
r2 = state[3:6]
r3 = state[6:9]
p1 = state[9:12]
p2 = state[12:15]
p3 = state[15:18]
m1, m2, m3 = self.masses
# Compute position derivatives (velocities)
dr1_dt = p1 / m1
dr2_dt = p2 / m2
dr3_dt = p3 / m3
# Compute momentum derivatives (forces)
# Calculate distances
r12 = r2 - r1
r23 = r3 - r2
r31 = r1 - r3
r12_norm = np.linalg.norm(r12)
r23_norm = np.linalg.norm(r23)
r31_norm = np.linalg.norm(r31)
# Calculate forces
dp1_dt = self.G * (m1*m2/r12_norm**3 * r12 - m3*m1/r31_norm**3 * r31)
dp2_dt = self.G * (m2*m3/r23_norm**3 * r23 - m1*m2/r12_norm**3 * r12)
dp3_dt = self.G * (m3*m1/r31_norm**3 * r31 - m2*m3/r23_norm**3 * r23)
# Assemble the derivatives
derivatives = np.concatenate([dr1_dt, dr2_dt, dr3_dt, dp1_dt, dp2_dt, dp3_dt])
return derivatives
def angular_momentum(self, state: np.ndarray) -> np.ndarray:
"""
Compute the total angular momentum for a given state.
Args:
state: State vector [r1, r2, r3, p1, p2, p3] where ri and pi are 3D vectors
Returns:
The total angular momentum vector
"""
r1 = state[0:3]
r2 = state[3:6]
r3 = state[6:9]
p1 = state[9:12]
p2 = state[12:15]
p3 = state[15:18]
# Compute individual angular momenta
L1 = np.cross(r1, p1)
L2 = np.cross(r2, p2)
L3 = np.cross(r3, p3)
# Total angular momentum
L_total = L1 + L2 + L3
return L_total
def linear_momentum(self, state: np.ndarray) -> np.ndarray:
"""
Compute the total linear momentum for a given state.
Args:
state: State vector [r1, r2, r3, p1, p2, p3] where ri and pi are 3D vectors
Returns:
The total linear momentum vector
"""
p1 = state[9:12]
p2 = state[12:15]
p3 = state[15:18]
# Total linear momentum
P_total = p1 + p2 + p3
return P_total
def center_of_mass(self, state: np.ndarray) -> np.ndarray:
"""
Compute the center of mass for a given state.
Args:
state: State vector [r1, r2, r3, p1, p2, p3] where ri and pi are 3D vectors
Returns:
The center of mass position vector
"""
r1 = state[0:3]
r2 = state[3:6]
r3 = state[6:9]
m1, m2, m3 = self.masses
M_total = m1 + m2 + m3
R_cm = (m1*r1 + m2*r2 + m3*r3) / M_total
return R_cm
def transform_to_center_of_mass_frame(self, state: np.ndarray) -> np.ndarray:
"""
Transform the state to the center of mass reference frame.
Args:
state: State vector [r1, r2, r3, p1, p2, p3] where ri and pi are 3D vectors
Returns:
The transformed state vector in the center of mass frame
"""
r1 = state[0:3]
r2 = state[3:6]
r3 = state[6:9]
p1 = state[9:12]
p2 = state[12:15]
p3 = state[15:18]
# Calculate center of mass
R_cm = self.center_of_mass(state)
# Calculate total momentum
P_total = self.linear_momentum(state)
m1, m2, m3 = self.masses
M_total = m1 + m2 + m3
# Transform positions (relative to center of mass)
r1_new = r1 - R_cm
r2_new = r2 - R_cm
r3_new = r3 - R_cm
# Transform momenta (subtract center of mass momentum)
p1_new = p1 - m1 * P_total / M_total
p2_new = p2 - m2 * P_total / M_total
p3_new = p3 - m3 * P_total / M_total
# Assemble the transformed state
transformed_state = np.concatenate([r1_new, r2_new, r3_new, p1_new, p2_new, p3_new])
return transformed_state
def integrate(self, initial_state: np.ndarray, t_span: Tuple[float, float],
t_eval: Optional[np.ndarray] = None,
**kwargs) -> Dict:
"""
Integrate the equations of motion.
Args:
initial_state: Initial state vector [r1, r2, r3, p1, p2, p3]
t_span: Tuple of (t_start, t_end)
t_eval: Optional array of time points to evaluate the solution at
**kwargs: Additional arguments to pass to solve_ivp
Returns:
Dictionary with integration results, including the time points and states
"""
# Use scipy's solve_ivp to integrate the equations of motion
result = solve_ivp(
self.equations_of_motion,
t_span,
initial_state,
t_eval=t_eval,
**kwargs
)
# Create a dictionary to store results
integration_results = {
"t": result.t,
"states": result.y.T, # Transpose to get shape (n_times, n_vars)
"success": result.success,
"message": result.message
}
return integration_results
def compute_conservation_errors(self, integration_results: Dict) -> Dict:
"""
Compute the conservation errors for energy, angular momentum, and linear momentum.
Args:
integration_results: Dictionary with integration results from the 'integrate' method
Returns:
Dictionary with arrays of conservation errors
"""
times = integration_results["t"]
states = integration_results["states"]
n_steps = len(times)
# Initial values (references)
initial_state = states[0]
initial_energy = self.hamiltonian(initial_state)
initial_angular_momentum = self.angular_momentum(initial_state)
initial_linear_momentum = self.linear_momentum(initial_state)
# Arrays to store errors
energy_error = np.zeros(n_steps)
angular_momentum_error = np.zeros(n_steps)
linear_momentum_error = np.zeros(n_steps)
# Compute errors at each time step
for i in range(n_steps):
current_state = states[i]
current_energy = self.hamiltonian(current_state)
current_angular_momentum = self.angular_momentum(current_state)
current_linear_momentum = self.linear_momentum(current_state)
# Relative energy error
if abs(initial_energy) > 1e-10:
energy_error[i] = abs((current_energy - initial_energy) / initial_energy)
else:
energy_error[i] = abs(current_energy - initial_energy)
# Angular momentum error (normalized)
if np.linalg.norm(initial_angular_momentum) > 1e-10:
angular_momentum_error[i] = np.linalg.norm(
current_angular_momentum - initial_angular_momentum
) / np.linalg.norm(initial_angular_momentum)
else:
angular_momentum_error[i] = np.linalg.norm(
current_angular_momentum - initial_angular_momentum
)
# Linear momentum error (normalized)
if np.linalg.norm(initial_linear_momentum) > 1e-10:
linear_momentum_error[i] = np.linalg.norm(
current_linear_momentum - initial_linear_momentum
) / np.linalg.norm(initial_linear_momentum)
else:
linear_momentum_error[i] = np.linalg.norm(
current_linear_momentum - initial_linear_momentum
)
conservation_errors = {
"energy": energy_error,
"angular_momentum": angular_momentum_error,
"linear_momentum": linear_momentum_error
}
return conservation_errors
def detect_collisions(self, integration_results: Dict, threshold: float = 1e-3) -> Dict:
"""
Detect collision events in the integration results.
Args:
integration_results: Dictionary with integration results
threshold: Distance threshold for detecting collisions
Returns:
Dictionary with collision information
"""
times = integration_results["t"]
states = integration_results["states"]
collisions = {
"times": [],
"types": [],
"indices": []
}
for i in range(len(times)):
state = states[i]
r1 = state[0:3]
r2 = state[3:6]
r3 = state[6:9]
r12 = np.linalg.norm(r1 - r2)
r23 = np.linalg.norm(r2 - r3)
r31 = np.linalg.norm(r3 - r1)
# Check for collisions
if r12 < threshold:
collisions["times"].append(times[i])
collisions["types"].append("1-2")
collisions["indices"].append(i)
if r23 < threshold:
collisions["times"].append(times[i])
collisions["types"].append("2-3")
collisions["indices"].append(i)
if r31 < threshold:
collisions["times"].append(times[i])
collisions["types"].append("3-1")
collisions["indices"].append(i)
return collisions
def plot_trajectories(self, integration_results: Dict, dim1: int = 0, dim2: int = 1,
figsize: Tuple[float, float] = (10, 8)) -> plt.Figure:
"""
Plot the trajectories of the three bodies.
Args:
integration_results: Dictionary with integration results
dim1: First dimension to plot (0=x, 1=y, 2=z)
dim2: Second dimension to plot (0=x, 1=y, 2=z)
figsize: Figure size (width, height) in inches
Returns:
The figure object
"""
states = integration_results["states"]
# Extract the coordinates for each body
r1 = states[:, 0:3]
r2 = states[:, 3:6]
r3 = states[:, 6:9]
# Create the figure
fig, ax = plt.subplots(figsize=figsize)
# Plot the trajectories
ax.plot(r1[:, dim1], r1[:, dim2], label=f"Body 1 (m={self.masses[0]:.2f})")
ax.plot(r2[:, dim1], r2[:, dim2], label=f"Body 2 (m={self.masses[1]:.2f})")
ax.plot(r3[:, dim1], r3[:, dim2], label=f"Body 3 (m={self.masses[2]:.2f})")
# Plot the initial positions
ax.scatter(r1[0, dim1], r1[0, dim2], marker='o', s=100, c='r', label='Initial positions')
ax.scatter(r2[0, dim1], r2[0, dim2], marker='o', s=100, c='r')
ax.scatter(r3[0, dim1], r3[0, dim2], marker='o', s=100, c='r')
# Set labels and title
dims = ['x', 'y', 'z']
ax.set_xlabel(f"{dims[dim1]}")
ax.set_ylabel(f"{dims[dim2]}")
ax.set_title(f"Three-Body Trajectories (σ={self.sigma:.6f})")
# Add a grid and legend
ax.grid(True)
ax.legend()
# Make the plot aspect ratio equal
ax.set_aspect('equal')
return fig
class HomotheticOrbits:
"""
Class for generating and analyzing homothetic orbits in the three-body problem.
Homothetic orbits are solutions where the configuration remains similar over time,
with only the scale changing.
"""
def __init__(self, three_body_problem: ThreeBodyProblem):
"""
Initialize the homothetic orbits analysis.
Args:
three_body_problem: ThreeBodyProblem instance
"""
self.tbp = three_body_problem
self.masses = three_body_problem.masses
self.sigma = three_body_problem.sigma
self.G = three_body_problem.G
def compute_central_configuration(self) -> np.ndarray:
"""
Compute a central configuration for the given masses.
A central configuration is an arrangement of bodies where the gravitational
forces are parallel to the position vectors from the center of mass.
Returns:
Array [a1, a2, a3] of position vectors defining the central configuration
"""
m1, m2, m3 = self.masses
# For equal masses, the equilateral triangle is a central configuration
if abs(m1 - m2) < 1e-10 and abs(m2 - m3) < 1e-10:
# Equilateral triangle with center of mass at origin
a1 = np.array([1.0, 0.0, 0.0]) # Explicitly use float values
a2 = np.array([-0.5, np.sqrt(3)/2, 0.0])
a3 = np.array([-0.5, -np.sqrt(3)/2, 0.0])
# Adjust to place center of mass at the origin
cm = (m1*a1 + m2*a2 + m3*a3) / (m1 + m2 + m3)
a1 -= cm
a2 -= cm
a3 -= cm
return np.concatenate([a1, a2, a3])
# For the collinear case, we need to solve for the positions
# We place the bodies on the x-axis
# Let's solve for the Lagrangian points L1, L2, L3
# Initialize positions with explicit float dtype
a1 = np.zeros(3, dtype=float)
a2 = np.zeros(3, dtype=float)
a3 = np.zeros(3, dtype=float)
# Set bodies along x-axis (will be adjusted to center of mass)
a1[0] = -1.0
a2[0] = 0.0
a3[0] = 1.0
# Iteratively adjust the positions to reach a central configuration
for _ in range(100):
# Compute center of mass
cm = (m1*a1 + m2*a2 + m3*a3) / (m1 + m2 + m3)
# Adjust to place center of mass at the origin
a1 -= cm
a2 -= cm
a3 -= cm
# Compute distances
r12 = np.linalg.norm(a1 - a2)
r23 = np.linalg.norm(a2 - a3)
r31 = np.linalg.norm(a3 - a1)
# Compute forces
f1 = m1 * (m2*(a2-a1)/r12**3 + m3*(a3-a1)/r31**3)
f2 = m2 * (m1*(a1-a2)/r12**3 + m3*(a3-a2)/r23**3)
f3 = m3 * (m1*(a1-a3)/r31**3 + m2*(a2-a3)/r23**3)
# Check if forces are parallel to positions (for central configuration)
# We use the fact that cross product should be zero
cross1 = np.cross(f1, a1)
cross2 = np.cross(f2, a2)
cross3 = np.cross(f3, a3)
error = np.linalg.norm(cross1) + np.linalg.norm(cross2) + np.linalg.norm(cross3)
if error < 1e-10:
break
# Adjust positions to reduce error (use a simple method)
scale = 0.01
a1 += scale * (np.dot(f1, a1) * a1 / np.linalg.norm(a1)**2 - f1)
a2 += scale * (np.dot(f2, a2) * a2 / np.linalg.norm(a2)**2 - f2)
a3 += scale * (np.dot(f3, a3) * a3 / np.linalg.norm(a3)**2 - f3)
return np.concatenate([a1, a2, a3])
def generate_initial_state(self, size: float = 1.0,
velocity_factor: float = 0.0) -> np.ndarray:
"""
Generate an initial state for a homothetic orbit.
Args:
size: Initial size of the configuration
velocity_factor: Factor for initial velocities (0 = free fall,
negative = expanding, positive = contracting)
Returns:
Initial state vector [r1, r2, r3, p1, p2, p3]
"""
# Compute central configuration
central_config = self.compute_central_configuration()
a1 = central_config[0:3]
a2 = central_config[3:6]
a3 = central_config[6:9]
# Scale the configuration
r1 = size * a1
r2 = size * a2
r3 = size * a3
# Compute the moment of inertia tensor for central configuration
m1, m2, m3 = self.masses
I = m1 * np.linalg.norm(a1)**2 + m2 * np.linalg.norm(a2)**2 + m3 * np.linalg.norm(a3)**2
# Compute the scale factor for homothetic velocities
# For a pure homothetic orbit, we need v_i = (velocity_factor) * r_i
# The equation of motion for the scale factor ρ is:
# ρ'' = -GM/ρ^2, where M is the total mass and λ is a constant
scale_factor = np.sqrt(self.G * sum(self.masses) / size)
velocity_scale = velocity_factor * scale_factor
# Compute velocities
v1 = velocity_scale * a1
v2 = velocity_scale * a2
v3 = velocity_scale * a3
# Compute momenta
p1 = self.masses[0] * v1
p2 = self.masses[1] * v2
p3 = self.masses[2] * v3
# Create initial state vector
initial_state = np.concatenate([r1, r2, r3, p1, p2, p3])
return initial_state
def normal_variational_equation_coefficients(self) -> Dict:
"""
Compute the coefficients for the normal variational equation.
The normal variational equation for homothetic orbits can be written in the form:
u'' = (λ(λ+1)/t^2 + μ(μ+1)/(t-1)^2 + ν(ν+1)/(t-a)^2) * u
Returns:
Dictionary with coefficients λ, μ, ν, and a
"""
# For the paper's specific cases, we compute the coefficients
# based on the mass parameter σ
sigma = self.sigma
# These coefficients are derived based on the specific case
# For the homothetic orbit NVE with three regular singular points:
lambda_val = 0.0
mu_val = 0.0
nu_val = 0.0
a_val = 2.0
# For specific values of sigma, use the known results from the paper
exceptional_sigmas = {
1/3: {"lambda": 0.5, "mu": -0.5, "nu": 1.0, "a": 2.0},
2**3/3**3: {"lambda": 0.5, "mu": -0.5, "nu": 1.5, "a": 2.0},
2/3**2: {"lambda": 1.0, "mu": 0.0, "nu": 1.0, "a": 1.5}
}
# Find the closest exceptional sigma value
min_diff = float('inf')
closest_sigma = None
for ex_sigma in exceptional_sigmas:
diff = abs(sigma - ex_sigma)
if diff < min_diff:
min_diff = diff
closest_sigma = ex_sigma
# If it's close to an exceptional value, use those coefficients
if min_diff < 1e-5:
lambda_val = exceptional_sigmas[closest_sigma]["lambda"]
mu_val = exceptional_sigmas[closest_sigma]["mu"]
nu_val = exceptional_sigmas[closest_sigma]["nu"]
a_val = exceptional_sigmas[closest_sigma]["a"]
else:
# For general case, derive the coefficients based on sigma
# This is a simplified approximation based on the full equations
lambda_val = 1.0
mu_val = (3*sigma - 1) / 2
nu_val = -mu_val
a_val = 2.0
return {
"lambda": lambda_val,
"mu": mu_val,
"nu": nu_val,
"a": a_val
}
def r_function(self, t: np.ndarray, coeffs: Dict) -> np.ndarray:
"""
Compute the r(t) function for the normal variational equation.
The function r(t) appears in the NVE in the form u'' = r(t) * u.
Args:
t: Array or scalar time values
coeffs: Dictionary with NVE coefficients
Returns:
The values of r(t) at the given time points
"""
lambda_val = coeffs["lambda"]
mu_val = coeffs["mu"]
nu_val = coeffs["nu"]
a_val = coeffs["a"]
# Compute r(t) = λ(λ+1)/t^2 + μ(μ+1)/(t-1)^2 + ν(ν+1)/(t-a)^2
t = np.asarray(t)
r_t = lambda_val * (lambda_val + 1) / t**2
r_t += mu_val * (mu_val + 1) / (t - 1)**2
r_t += nu_val * (nu_val + 1) / (t - a_val)**2
return r_t
def analyze_galois_group(self) -> str:
"""
Determine the differential Galois group for the NVE based on the mass parameter.
Returns:
String describing the Galois group and its properties
"""
sigma = self.sigma
# For exceptional mass ratios, we know the Galois group type
if abs(sigma - 1/3) < 1e-10:
return "Dihedral Galois group with abelian identity component"
elif abs(sigma - 2**3/3**3) < 1e-10:
return "Dihedral Galois group with abelian identity component"
elif abs(sigma - 2/3**2) < 1e-10:
return "Triangular Galois group with abelian identity component"
else:
return "SL(2,C) Galois group with non-abelian identity component"
def painleve_analysis(self) -> Dict:
"""
Perform Painlevé analysis for homothetic orbit with current mass parameter.
Returns:
Dictionary with Painlevé analysis results
"""
sigma = self.sigma
# For homothetic orbits, determine the order of pole p and resonances
p = 2/3 # Standard result for binary collisions
# Define results based on exceptional mass ratios
if abs(sigma - 1/3) < 1e-10:
resonances = [-1, 0, 4, 5]
compatibility_conditions = True
branch_point_type = "square root (Z_2)"
has_painleve_property = False
elif abs(sigma - 2**3/3**3) < 1e-10:
resonances = [-1, 0, 4, 5]
compatibility_conditions = True
branch_point_type = "square root (Z_2)"
has_painleve_property = False
elif abs(sigma - 2/3**2) < 1e-10:
resonances = [-1, 0, 4, 5]
compatibility_conditions = True
branch_point_type = "none (meromorphic)"
has_painleve_property = True
else:
resonances = [-1, 0, 4, 5]
compatibility_conditions = False
branch_point_type = "transcendental"
has_painleve_property = False
return {
"pole_order": p,
"resonances": resonances,
"compatibility_conditions_satisfied": compatibility_conditions,
"branch_point_type": branch_point_type,
"has_painleve_property": has_painleve_property
}
def quaternionic_monodromy(self) -> Dict:
"""
Determine the quaternionic monodromy for the current mass parameter.
Returns:
Dictionary with quaternionic monodromy information
"""
sigma = self.sigma
# Determine the quaternionic monodromy based on the mass parameter
if abs(sigma - 1/3) < 1e-10:
monodromy_type = "Z_2"
path_structure = "Z_2 symmetric"
is_trivial = False
elif abs(sigma - 2**3/3**3) < 1e-10:
monodromy_type = "Z_2"
path_structure = "Z_2 symmetric"
is_trivial = False
elif abs(sigma - 2/3**2) < 1e-10:
monodromy_type = "Trivial"
path_structure = "Trivial"
is_trivial = True
else:
monodromy_type = "Infinite"
path_structure = "Complex"
is_trivial = False
return {
"monodromy_type": monodromy_type,
"path_structure": path_structure,
"is_trivial": is_trivial
}
def isomorphic_structures_summary(self) -> Dict:
"""
Provide a summary of the isomorphic structures for the current mass parameter.
Returns:
Dictionary with summary of isomorphic structures
"""
sigma = self.sigma
galois_info = self.analyze_galois_group()
painleve_info = self.painleve_analysis()
quat_info = self.quaternionic_monodromy()
# Determine integrability
if (abs(sigma - 1/3) < 1e-10 or
abs(sigma - 2**3/3**3) < 1e-10 or
abs(sigma - 2/3**2) < 1e-10):
integrability = "Partially integrable"
else:
integrability = "Non-integrable"
return {
"mass_parameter": sigma,
"galois_group": galois_info,
"painleve_property": painleve_info["has_painleve_property"],
"branch_point_type": painleve_info["branch_point_type"],
"quaternionic_monodromy": quat_info["monodromy_type"],
"integrability": integrability
}
class LagrangianSolutions:
"""
Class for generating and analyzing Lagrangian equilateral solutions
in the three-body problem.
Lagrangian solutions are those where the three bodies form
an equilateral triangle at all times.
"""
def __init__(self, three_body_problem: ThreeBodyProblem):
"""
Initialize the Lagrangian solutions analysis.
Args:
three_body_problem: ThreeBodyProblem instance
"""
self.tbp = three_body_problem
self.masses = three_body_problem.masses
self.sigma = three_body_problem.sigma
self.G = three_body_problem.G
def generate_initial_state(self, size: float = 1.0,
rotation_rate: Optional[float] = None) -> np.ndarray:
"""
Generate an initial state for a Lagrangian solution.
Args:
size: Size of the equilateral triangle
rotation_rate: Angular velocity of rotation (if None, computed from equilibrium)
Returns:
Initial state vector [r1, r2, r3, p1, p2, p3]
"""
m1, m2, m3 = self.masses
M = m1 + m2 + m3
# Place the bodies at the vertices of an equilateral triangle
# with center of mass at the origin
a1 = np.array([size, 0, 0])
a2 = np.array([-0.5*size, 0.866*size, 0]) # cos(120°), sin(120°)
a3 = np.array([-0.5*size, -0.866*size, 0]) # cos(240°), sin(240°)
# Adjust to center of mass
cm = (m1*a1 + m2*a2 + m3*a3) / M
r1 = a1 - cm
r2 = a2 - cm
r3 = a3 - cm
# Compute the equilibrium rotation rate if not provided
if rotation_rate is None:
# For Lagrangian solutions, the rotation rate must balance gravity
# ω^2 = GM/L^3, where L is the side length of the triangle
L = size * np.sqrt(3) # Distance between any two bodies
omega_squared = self.G * M / L**3
rotation_rate = np.sqrt(omega_squared)
# Set initial velocities for circular motion
v1 = rotation_rate * np.array([-r1[1], r1[0], 0])
v2 = rotation_rate * np.array([-r2[1], r2[0], 0])
v3 = rotation_rate * np.array([-r3[1], r3[0], 0])
# Compute momenta
p1 = m1 * v1
p2 = m2 * v2
p3 = m3 * v3
# Create initial state vector
initial_state = np.concatenate([r1, r2, r3, p1, p2, p3])
return initial_state
def normal_variational_equation_coefficient(self) -> float:
"""
Compute the coefficient for the normal variational equation of Lagrangian solutions.
For circular Lagrangian orbits, the NVE reduces to: u'' = ((27/4)σ - 3/4) * u
Returns:
The coefficient ((27/4)σ - 3/4)
"""
return (27/4) * self.sigma - 3/4
def analyze_galois_group(self) -> str:
"""
Determine the differential Galois group for the NVE based on the mass parameter.
Returns:
String describing the Galois group and its properties
"""
sigma = self.sigma
coefficient = self.normal_variational_equation_coefficient()
# For exceptional mass ratios, we know the Galois group type
if abs(sigma - 1/3) < 1e-10:
return "Dihedral Galois group with abelian identity component"
elif abs(sigma - 2**3/3**3) < 1e-10:
return "Dihedral Galois group with abelian identity component"
elif abs(sigma - 2/3**2) < 1e-10:
return "Triangular Galois group with abelian identity component"
else:
return "SL(2,C) Galois group with non-abelian identity component"
def painleve_analysis(self) -> Dict:
"""
Perform Painlevé analysis for Lagrangian solutions with current mass parameter.
Returns:
Dictionary with Painlevé analysis results
"""
sigma = self.sigma
# Similar to homothetic orbits but with the specific NVE structure
# For exceptional mass ratios, we have specific results
if abs(sigma - 1/3) < 1e-10:
has_simpler_branching = True
branch_point_type = "square root (Z_2)"
has_painleve_property = False
elif abs(sigma - 2**3/3**3) < 1e-10:
has_simpler_branching = True
branch_point_type = "square root (Z_2)"
has_painleve_property = False
elif abs(sigma - 2/3**2) < 1e-10:
has_simpler_branching = True
branch_point_type = "none (meromorphic)"
has_painleve_property = True
else:
has_simpler_branching = False
branch_point_type = "transcendental"
has_painleve_property = False
return {
"has_simpler_branching": has_simpler_branching,
"branch_point_type": branch_point_type,
"has_painleve_property": has_painleve_property
}
def quaternionic_regularization_method(self) -> str:
"""
Determine the appropriate quaternionic regularization method based on the mass parameter.
Returns:
String indicating the appropriate regularization method
"""
sigma = self.sigma
if abs(sigma - 2/3**2) < 1e-10:
return "Levi-Civita"
else:
return "PathContinuation"
def quaternionic_monodromy(self) -> Dict:
"""
Determine the quaternionic monodromy for the current mass parameter.
Returns:
Dictionary with quaternionic monodromy information
"""
sigma = self.sigma
# Determine the quaternionic monodromy based on the mass parameter
if abs(sigma - 1/3) < 1e-10:
monodromy_type = "Z_2"
path_structure = "Z_2 symmetric"
is_trivial = False
elif abs(sigma - 2**3/3**3) < 1e-10:
monodromy_type = "Z_2"
path_structure = "Z_2 symmetric"
is_trivial = False
elif abs(sigma - 2/3**2) < 1e-10:
monodromy_type = "Trivial"
path_structure = "Trivial"
is_trivial = True
else:
monodromy_type = "Infinite"
path_structure = "Complex"
is_trivial = False
return {
"monodromy_type": monodromy_type,
"path_structure": path_structure,
"is_trivial": is_trivial
}
def isomorphic_structures_summary(self) -> Dict:
"""
Provide a summary of the isomorphic structures for the current mass parameter.