Skip to content

Commit 98c3b8c

Browse files
committed
initial commit of CR3BP
1 parent 0b2bf99 commit 98c3b8c

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
classdef Canonical < otp.cr3bp.CR3BPProblem
2+
3+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
classdef NRHO < otp.cr3bp.CR3BPProblem
2+
%
3+
4+
methods
5+
function obj = NRHO
6+
% Create the NRHO CR3BP problem object.
7+
% $L_2$ Halo orbit family member
8+
9+
ic = [1.0192741002 -0.1801324242 -0.0971927950];
10+
mE = otp.utils.PhysicalConstants.EarthMass;
11+
mL = otp.utils.PhysicalConstants.MoonMass;
12+
G = otp.utils.PhysicalConstants.GravitationalConstant;
13+
14+
% derive mu
15+
muE = G*mE;
16+
muL = G*mL;
17+
mu = muL/(muE + muL);
18+
19+
y0 = [ic(1); 0; ic(2); 0; ic(3); 0];
20+
tspan = [0, 10];
21+
params = otp.cr3bp.CR3BPParameters('Mu', mu, 'SoftFactor', 0);
22+
obj = obj@otp.cr3bp.CR3BPProblem(tspan, y0, params);
23+
end
24+
end
25+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
classdef CR3BPParameters < otp.Parameters
2+
% Parameters for the CR3BP problem.
3+
4+
properties
5+
% Relative mass of the system.
6+
Mu %MATLAB ONLY: (1, 1) {otp.utils.validation.mustBeNumerical}
7+
8+
% A factor to avoid singularity
9+
SoftFactor %MATLAB ONLY: (1, 1) {otp.utils.validation.mustBeNumerical}
10+
end
11+
12+
methods
13+
function obj = CR3BPParameters(varargin)
14+
% Create a CR3BP parameters object.
15+
%
16+
% Parameters
17+
% ----------
18+
% varargin
19+
% A variable number of name-value pairs. A name can be any property of this class, and the subsequent
20+
% value initializes that property.
21+
22+
obj = obj@otp.Parameters(varargin{:});
23+
end
24+
end
25+
end

toolbox/+otp/+cr3bp/CR3BPProblem.m

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
classdef CR3BPProblem < otp.Problem
2+
% The circular restricted three body problem
3+
%
4+
% Notes
5+
% -----
6+
% +---------------------+-----------------------------------------------+
7+
% | Type | ODE |
8+
% +---------------------+-----------------------------------------------+
9+
% | Number of Variables | 6 |
10+
% +---------------------+-----------------------------------------------+
11+
% | Stiff | no |
12+
% +---------------------+-----------------------------------------------+
13+
%
14+
% Example
15+
% -------
16+
% >>> problem = otp.cr3bp.presets.Canonical;
17+
% >>> sol = model.solve('AbsTol', 1e-14, 'RelTol', 100*eps);
18+
% >>> problem.plotPhaseSpace(sol);
19+
%
20+
% See Also
21+
% --------
22+
% otp.nbody.NBodyProblem
23+
24+
methods
25+
function obj = CR3BPProblem(timeSpan, y0, parameters)
26+
% Create a CR3BP problem object.
27+
%
28+
% Parameters
29+
% ----------
30+
% timeSpan : numeric(1, 2)
31+
% The start and final time.
32+
% y0 : numeric(6, 1)
33+
% The initial conditions.
34+
% parameters : otp.cr3bp.CR3BPParameters
35+
% The parameters.
36+
37+
obj@otp.Problem('Circular Restricted 3 Body Problem', 6, timeSpan, y0, parameters);
38+
end
39+
end
40+
41+
methods (Access = protected)
42+
function onSettingsChanged(obj)
43+
mu = obj.Parameters.Mu;
44+
soft = obj.Parameters.SoftFactor;
45+
46+
obj.RHS = otp.RHS(@(t, y) otp.cr3bp.f(t, y, mu, soft), ...
47+
'Vectorized', 'on');
48+
end
49+
50+
function label = internalIndex2label(~, index)
51+
switch index
52+
case 1
53+
label = 'x';
54+
case 2
55+
label = 'y';
56+
case 3
57+
label = 'z';
58+
case 4
59+
label = 'dx';
60+
case 5
61+
label = 'dy';
62+
case 6
63+
label = 'dz';
64+
end
65+
end
66+
67+
function sol = internalSolve(obj, varargin)
68+
sol = internalSolve@otp.Problem(obj, 'Solver', otp.utils.Solver.Nonstiff, varargin{:});
69+
end
70+
71+
end
72+
end

toolbox/+otp/+cr3bp/f.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function dy = f(~, y, mu, soft)
2+
3+
x = y(1:3, :);
4+
v = y(4:6, :);
5+
6+
d = sqrt((x(1, :) + mu).^2 + x(2, :)^2 + x(3, :)^2 + soft^2);
7+
r = sqrt((x(1, :) - 1 + mu).^2 + x(2, :).^2 + x(3, :)^2 + soft^2);
8+
cd = (1 - mu)./d.^3;
9+
cr = mu./r.^3;
10+
11+
dx = v;
12+
dv = [...
13+
2*v(2, :) + (1 - cd - cr).*x(1, :) - (cd + cr).*mu + cr; ...
14+
-2*v(1, :) + (1 - cd - cr).*x(2, :); ...
15+
-(cd + cr).*x(3, :)];
16+
17+
dy = [dx; dv];
18+
19+
end

0 commit comments

Comments
 (0)