Skip to content

Commit

Permalink
ReturnFromMoon: improve final accuracy + allow larger stepsize
Browse files Browse the repository at this point in the history
Doesn't seem to have much of an effect on total runtime or
convergence.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Aug 26, 2023
1 parent d78272a commit f03a1f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions MechJeb2/MechJebLib/Maneuvers/ReturnFromMoon.cs
Expand Up @@ -364,7 +364,7 @@ private static double[] GenerateInitialGuess(Args args)
}

private const double DIFFSTEP = 1e-9;
private const double EPSX = 1e-4;
private const double EPSX = 1e-8;
private const int MAXITS = 1000;

private const int NVARIABLES = 20;
Expand Down Expand Up @@ -397,7 +397,7 @@ private static (V3 V, double dt) ManeuverScaled(Args args, double dtmin = double
alglib.minnlccreate(NVARIABLES, x, out alglib.minnlcstate state);

alglib.minnlcsetbc(state, bndl, bndu);
alglib.minnlcsetstpmax(state, 1e-8);
alglib.minnlcsetstpmax(state, 1e-4);
//double rho = 1000.0;
//int outerits = 5;
//alglib.minnlcsetalgoaul(state, rho, outerits);
Expand Down
3 changes: 3 additions & 0 deletions MechJebLibTest/Maneuvers/ReturnFromMoonTests.cs
Expand Up @@ -61,6 +61,7 @@ private void NextManeuverToReturnFromMoonTest()
r0 = new V3(1105140.06213014, -8431008.05414815, -4729658.84487529);
v0 = new V3(-293.374690393787, -1173.3597686151, -411.755491683683);
*/
_testOutputHelper.WriteLine($"iteration: {i}");

(V3 dv, double dt, double newPeR) =
ReturnFromMoon.NextManeuver(398600435436096, 4902800066163.8, moonR0, moonV0, 66167158.6569544, r0, v0, peR, 0, 0);
Expand All @@ -72,6 +73,8 @@ private void NextManeuverToReturnFromMoonTest()
V3 r3 = moonR2 + r2;
V3 v3 = moonV2 + v2;

_testOutputHelper.WriteLine($"periapsis: {MechJebLib.Core.Maths.PeriapsisFromStateVectors(centralMu, r3, v3)}");

MechJebLib.Core.Maths.PeriapsisFromStateVectors(centralMu, r3, v3).ShouldEqual(peR, 1e-3);
newPeR.ShouldEqual(peR, 1e-3);
}
Expand Down

0 comments on commit f03a1f6

Please sign in to comment.