/
TheStandardTests.cs
78 lines (64 loc) · 3.23 KB
/
TheStandardTests.cs
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
using System;
using MechJebLib.Functions;
using MechJebLib.Primitives;
using MechJebLib.PVG;
using MechJebLib.Utils;
using Xunit;
using Xunit.Abstractions;
using static MechJebLib.Utils.Statics;
namespace MechJebLibTest.PVGTests.AscentTests
{
public class TheStandardTests
{
private readonly ITestOutputHelper _testOutputHelper;
public TheStandardTests(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}
// This is fairly sensitive to initial bootstrapping and will often compute a negative coast instead of the optimal positive coast
[Fact]
public void OptimizedBoosterWithCoastElliptical()
{
Logger.Register(o => _testOutputHelper.WriteLine((string)o));
var r0 = new V3(-521765.111703417, -5568874.59934707, 3050608.87783524);
var v0 = new V3(406.088016257895, -38.0495807832894, 0.000701038889818476);
var u0 = new V3(-0.0820737379089317, -0.874094973679233, 0.478771328926086);
double t0 = 661803.431918959;
double mu = 3.986004418e+14;
double rbody = 6.371e+6;
double PeR = 6.371e+6 + 185e+3;
double ApR = 6.371e+6 + 10e+6;
double incT = Deg2Rad(28.608);
Ascent ascent = Ascent.Builder()
.Initial(r0, v0, u0, t0, mu, rbody)
.SetTarget(PeR, ApR, PeR, incT, 0, 0, false, false)
.AddStageUsingFinalMass(49119.7842689869, 7114.2513992454, 288.000034332275, 170.308460385726, 3, 3)
.AddStageUsingFinalMass(2848.62586760223, 1363.71123994759, 270.15767003304, 116.391834883409, 1, 1, true)
.AddOptimizedCoast(678.290157913434, 0, 450, 1, 1)
.AddStageUsingFinalMass(678.290157913434, 177.582604389742, 230.039271734103, 53.0805126571005, 0, 0, false, true)
.Build();
ascent.Run();
Optimizer pvg = ascent.GetOptimizer() ?? throw new Exception("null optimzer");
using Solution solution = pvg.GetSolution();
solution.Tgo(solution.T0, 0).ShouldBePositive();
solution.Tgo(solution.T0, 1).ShouldBePositive();
solution.Tgo(solution.T0, 2).ShouldBePositive();
solution.Tgo(solution.T0, 3).ShouldBePositive();
pvg.Znorm.ShouldBeZero(1e-9);
(V3 rf, V3 vf) = solution.TerminalStateVectors();
(double smaf, double eccf, double incf, double lanf, double argpf, double tanof, _) =
Astro.KeplerianFromStateVectors(mu, rf, vf);
solution.R(t0).ShouldEqual(r0);
solution.V(t0).ShouldEqual(v0);
solution.M(t0).ShouldEqual(49119.7842689869);
solution.Vgo(t0).ShouldEqual(9673.8952125677752, 1e-7);
solution.Pv(t0).normalized.ShouldEqual(new V3(0.76795016838086438, -0.57846262219206013, 0.27501551521775636), 1e-7);
smaf.ShouldEqual(11463499.98898875, 1e-7);
eccf.ShouldEqual(0.4280978753095433, 1e-7);
incf.ShouldEqual(incT, 1e-7);
lanf.ShouldEqual(3.0481683004886317, 1e-7);
argpf.ShouldEqual(1.9887149934489514, 1e-7);
tanof.ShouldEqual(0.091089077094440363, 1e-7);
}
}
}