Commit fdcf07ce authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Fixed number of iterations in multiple shooting.

parent bcfe9b8a
......@@ -68,11 +68,12 @@ public class CR3BPMultipleShooter extends AbstractMultipleShooting {
* @param arcDuration initial guess of the duration of each arc.
* @param stmEquations list of additional derivatives providers linked to propagatorList.
* @param tolerance convergence tolerance on the constraint vector
* @param maxIter maximum number of iterations
*/
public CR3BPMultipleShooter(final List<SpacecraftState> initialGuessList, final List<NumericalPropagator> propagatorList,
final double arcDuration, final List<STMEquations> stmEquations,
final double tolerance) {
super(initialGuessList, propagatorList, arcDuration, tolerance, STM);
final double tolerance, final int maxIter) {
super(initialGuessList, propagatorList, arcDuration, tolerance, maxIter, STM);
this.stmEquations = stmEquations;
this.npoints = initialGuessList.size();
}
......
......@@ -17,6 +17,7 @@
package org.orekit.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -54,13 +55,13 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
private final List<NumericalPropagator> propagatorList;
/** Duration of propagation along each arcs. */
private double[] propagationTime;
private final double[] propagationTime;
/** Free components of patch points. */
private boolean[] freePatchPointMap;
private final boolean[] freePatchPointMap;
/** Free epoch of patch points. */
private boolean[] freeEpochMap;
private final boolean[] freeEpochMap;
/** Number of free variables. */
private int nFree;
......@@ -72,13 +73,16 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
private int nConstraints;
/** Patch points components which are constrained. */
private Map<Integer, Double> mapConstraints;
private final Map<Integer, Double> mapConstraints;
/** True if orbit is closed. */
private boolean isClosedOrbit;
/** Tolerance on the constraint vector. */
private double tolerance;
private final double tolerance;
/** Maximum number of iterations. */
private final int maxIter;
/** Expected name of the additional equations. */
private final String additionalName;
......@@ -97,7 +101,7 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
protected AbstractMultipleShooting(final List<SpacecraftState> initialGuessList, final List<NumericalPropagator> propagatorList,
final List<org.orekit.propagation.integration.AdditionalEquations> additionalEquations,
final double arcDuration, final double tolerance, final String additionalName) {
this(initialGuessList, propagatorList, arcDuration, tolerance, additionalName);
this(initialGuessList, propagatorList, arcDuration, tolerance, 1, additionalName);
this.additionalEquations = additionalEquations;
}
......@@ -107,39 +111,35 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
* @param propagatorList list of propagators associated to each patch point.
* @param arcDuration initial guess of the duration of each arc.
* @param tolerance convergence tolerance on the constraint vector.
* @param maxIter maximum number of iterations
* @param additionalName name of the additional equations
* @since 11.1
*/
protected AbstractMultipleShooting(final List<SpacecraftState> initialGuessList, final List<NumericalPropagator> propagatorList,
final double arcDuration, final double tolerance, final String additionalName) {
final double arcDuration, final double tolerance, final int maxIter, final String additionalName) {
this.patchedSpacecraftStates = initialGuessList;
this.propagatorList = propagatorList;
this.additionalName = additionalName;
// Should check if propagatorList.size() = initialGuessList.size() - 1
final int propagationNumber = initialGuessList.size() - 1;
this.propagationTime = new double[propagationNumber];
for (int i = 0; i < propagationNumber; i++ ) {
this.propagationTime[i] = arcDuration;
}
propagationTime = new double[propagationNumber];
Arrays.fill(propagationTime, arcDuration);
// All the patch points are set initially as free variables
this.freePatchPointMap = new boolean[6 * initialGuessList.size()]; // epoch
for (int i = 0; i < freePatchPointMap.length; i++) {
freePatchPointMap[i] = true;
}
Arrays.fill(freePatchPointMap, true);
//Except the first one, the epochs of the patch points are set free.
this.freeEpochMap = new boolean[initialGuessList.size()];
Arrays.fill(freeEpochMap, true);
freeEpochMap[0] = false;
for (int i = 1; i < freeEpochMap.length; i++) {
freeEpochMap[i] = true;
}
this.nEpoch = initialGuessList.size() - 1;
this.nConstraints = 6 * propagationNumber;
this.nFree = 6 * initialGuessList.size() + 1;
this.tolerance = tolerance;
this.maxIter = maxIter;
// All the additional constraints must be set afterward
this.mapConstraints = new HashMap<>();
......@@ -160,9 +160,8 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
* @param isFree constraint value
*/
public void setPatchPointComponentFreedom(final int patchNumber, final int componentIndex, final boolean isFree) {
if (freePatchPointMap[6 * (patchNumber - 1) + componentIndex] != isFree ) {
final int eps = isFree ? 1 : -1;
nFree = nFree + eps;
if (freePatchPointMap[6 * (patchNumber - 1) + componentIndex] != isFree) {
nFree += isFree ? 1 : -1;
freePatchPointMap[6 * (patchNumber - 1) + componentIndex] = isFree;
}
}
......@@ -221,7 +220,7 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
iter++;
} while (fxNorm > tolerance && iter < 1); // Converge within tolerance and under 10 iterations
} while (fxNorm > tolerance && iter < maxIter); // Converge within tolerance and under 10 iterations
return patchedSpacecraftStates;
}
......
......@@ -65,11 +65,12 @@ public class MultipleShooter extends AbstractMultipleShooting {
* @param epochEquations list of additional derivatives providers linked to propagatorList.
* @param propagatorList list of propagators associated to each patch point.
* @param tolerance convergence tolerance on the constraint vector
* @param maxIter maximum number of iterations
*/
public MultipleShooter(final List<SpacecraftState> initialGuessList, final List<NumericalPropagator> propagatorList,
final double arcDuration,
final List<EpochDerivativesEquations> epochEquations, final double tolerance) {
super(initialGuessList, propagatorList, arcDuration, tolerance, DERIVATIVES);
final double arcDuration, final List<EpochDerivativesEquations> epochEquations,
final double tolerance, final int maxIter) {
super(initialGuessList, propagatorList, arcDuration, tolerance, maxIter, DERIVATIVES);
this.epochEquations = epochEquations;
}
......@@ -100,7 +101,7 @@ public class MultipleShooter extends AbstractMultipleShooting {
// The additional constraint vector has the following form :
// [ y1i - y1d ]---- other constraints (component of
// Fadd(X) = [ ... ] | a patch point eaquals to a
// Fadd(X) = [ ... ] | a patch point equals to a
// [vz2i - vz2d]---- desired value)
// Number of additional constraints
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.orekit.propagation.numerical;
package org.orekit.propagation.numerical.cr3bp;
import org.hipparchus.Field;
import org.hipparchus.analysis.differentiation.DSFactory;
......@@ -40,7 +40,8 @@ import org.orekit.frames.Frame;
import org.orekit.frames.FramesFactory;
import org.orekit.propagation.FieldSpacecraftState;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.numerical.cr3bp.CR3BPForceModel;
import org.orekit.propagation.numerical.FieldNumericalPropagator;
import org.orekit.propagation.numerical.NumericalPropagator;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.FieldAbsoluteDate;
import org.orekit.time.TimeScalesFactory;
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.orekit.propagation.numerical;
package org.orekit.propagation.numerical.cr3bp;
import java.util.ArrayList;
import java.util.List;
......@@ -36,9 +36,7 @@ import org.orekit.orbits.LibrationOrbitFamily;
import org.orekit.orbits.LibrationOrbitType;
import org.orekit.orbits.RichardsonExpansion;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.numerical.cr3bp.CR3BPForceModel;
import org.orekit.propagation.numerical.cr3bp.CR3BPMultipleShooter;
import org.orekit.propagation.numerical.cr3bp.STMEquations;
import org.orekit.propagation.numerical.NumericalPropagator;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.AbsolutePVCoordinates;
......@@ -103,7 +101,7 @@ public class CR3BPMultipleShooterTest {
firstGuess2)));
// Multiple Shooting definition
final CR3BPMultipleShooter multipleShooting = new CR3BPMultipleShooter(firstGuessList, propagatorList, arcDuration, cr3bpAdditionalEquations, 1E-8);
final CR3BPMultipleShooter multipleShooting = new CR3BPMultipleShooter(firstGuessList, propagatorList, arcDuration, cr3bpAdditionalEquations, 1E-8, 1);
multipleShooting.setPatchPointComponentFreedom(1, 1, false);
multipleShooting.setPatchPointComponentFreedom(1, 2, false);
multipleShooting.setPatchPointComponentFreedom(1, 3, false);
......
......@@ -137,7 +137,7 @@ public class MultipleShooterTest {
// Perturbation on a patch point
// -----------------------------
final int nP = 1; // Perturbated patch point
final int nP = 1; // Perturbed patch point
final Vector3D deltaP = new Vector3D(-50000,1000,0);
final Vector3D deltaV = new Vector3D(0.1,0,1.0);
final double deltaEpoch = 1000;
......@@ -152,11 +152,11 @@ public class MultipleShooterTest {
AbsolutePVCoordinates absPva = new AbsolutePVCoordinates(firstGuessSP.getFrame(), newDate, newPos, newVel);
final Attitude attitude = attPro.getAttitude(absPva, newDate, absPva.getFrame());
SpacecraftState newSP = new SpacecraftState(absPva , attitude);
correctedList.set(1, newSP);
correctedList.set(nP, newSP);
final double tolerance = 1.0;
MultipleShooter multipleShooting = new MultipleShooter(correctedList, propagatorList, arcDuration, epochEquations, tolerance);
MultipleShooter multipleShooting = new MultipleShooter(correctedList, propagatorList, arcDuration, epochEquations, tolerance, 10);
multipleShooting.setPatchPointComponentFreedom(1, 0, false);
multipleShooting.setPatchPointComponentFreedom(1, 1, false);
multipleShooting.setPatchPointComponentFreedom(1, 2, false);
......@@ -169,18 +169,18 @@ public class MultipleShooterTest {
multipleShooting.compute();
// Verify
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(0).getAbsPVA().getPosition(), correctedList.get(0).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.018029, Vector3D.distance(firstGuessList2.get(0).getAbsPVA().getVelocity(), correctedList.get(0).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(677.097822, Vector3D.distance(firstGuessList2.get(1).getAbsPVA().getPosition(), correctedList.get(1).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.017816, Vector3D.distance(firstGuessList2.get(1).getAbsPVA().getVelocity(), correctedList.get(1).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(863.676399, Vector3D.distance(firstGuessList2.get(2).getAbsPVA().getPosition(), correctedList.get(2).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.092103, Vector3D.distance(firstGuessList2.get(2).getAbsPVA().getVelocity(), correctedList.get(2).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(576.396708, Vector3D.distance(firstGuessList2.get(3).getAbsPVA().getPosition(), correctedList.get(3).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.092099, Vector3D.distance(firstGuessList2.get(3).getAbsPVA().getVelocity(), correctedList.get(3).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(288.575119, Vector3D.distance(firstGuessList2.get(4).getAbsPVA().getPosition(), correctedList.get(4).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.092113, Vector3D.distance(firstGuessList2.get(4).getAbsPVA().getVelocity(), correctedList.get(4).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.000000, Vector3D.distance(firstGuessList2.get(5).getAbsPVA().getPosition(), correctedList.get(5).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.092129, Vector3D.distance(firstGuessList2.get(5).getAbsPVA().getVelocity(), correctedList.get(5).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(0).getAbsPVA().getPosition(), correctedList.get(0).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(0).getAbsPVA().getVelocity(), correctedList.get(0).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.005230, Vector3D.distance(firstGuessList2.get(1).getAbsPVA().getPosition(), correctedList.get(1).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(1).getAbsPVA().getVelocity(), correctedList.get(1).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.009869, Vector3D.distance(firstGuessList2.get(2).getAbsPVA().getPosition(), correctedList.get(2).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(2).getAbsPVA().getVelocity(), correctedList.get(2).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.006641, Vector3D.distance(firstGuessList2.get(3).getAbsPVA().getPosition(), correctedList.get(3).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(3).getAbsPVA().getVelocity(), correctedList.get(3).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.003216, Vector3D.distance(firstGuessList2.get(4).getAbsPVA().getPosition(), correctedList.get(4).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(4).getAbsPVA().getVelocity(), correctedList.get(4).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(5).getAbsPVA().getPosition(), correctedList.get(5).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(5).getAbsPVA().getVelocity(), correctedList.get(5).getAbsPVA().getVelocity()), eps);
}
......@@ -259,7 +259,7 @@ public class MultipleShooterTest {
final double tolerance = 1.0;
MultipleShooter multipleShooting = new MultipleShooter(correctedList, propagatorList, arcDuration, epochEquations, tolerance);
MultipleShooter multipleShooting = new MultipleShooter(correctedList, propagatorList, arcDuration, epochEquations, tolerance, 10);
multipleShooting.setPatchPointComponentFreedom(1, 0, false);
multipleShooting.setPatchPointComponentFreedom(1, 1, false);
multipleShooting.setPatchPointComponentFreedom(1, 2, false);
......@@ -272,12 +272,12 @@ public class MultipleShooterTest {
multipleShooting.compute();
// Verify
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(0).getAbsPVA().getPosition(), correctedList.get(0).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.007568, Vector3D.distance(firstGuessList2.get(0).getAbsPVA().getVelocity(), correctedList.get(0).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(231.922890, Vector3D.distance(firstGuessList2.get(1).getAbsPVA().getPosition(), correctedList.get(1).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.007547, Vector3D.distance(firstGuessList2.get(1).getAbsPVA().getVelocity(), correctedList.get(1).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(233.233939, Vector3D.distance(firstGuessList2.get(2).getAbsPVA().getPosition(), correctedList.get(2).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.028078, Vector3D.distance(firstGuessList2.get(2).getAbsPVA().getVelocity(), correctedList.get(2).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(0).getAbsPVA().getPosition(), correctedList.get(0).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(0).getAbsPVA().getVelocity(), correctedList.get(0).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.000108, Vector3D.distance(firstGuessList2.get(1).getAbsPVA().getPosition(), correctedList.get(1).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(1).getAbsPVA().getVelocity(), correctedList.get(1).getAbsPVA().getVelocity()), eps);
Assert.assertEquals(0.000308, Vector3D.distance(firstGuessList2.get(2).getAbsPVA().getPosition(), correctedList.get(2).getAbsPVA().getPosition()), eps);
Assert.assertEquals(0.0, Vector3D.distance(firstGuessList2.get(2).getAbsPVA().getVelocity(), correctedList.get(2).getAbsPVA().getVelocity()), eps);
}
@Test(expected=OrekitException.class)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment