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

Started refactoring of CR3BP for partial derivatives computation.

parent 65e649c0
......@@ -18,9 +18,9 @@ package org.orekit.propagation.numerical.cr3bp;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.integration.AdditionalDerivativesProvider;
import org.orekit.propagation.numerical.NumericalPropagator;
import org.orekit.utils.AbsolutePVCoordinates;
import org.orekit.utils.AbstractMultipleShooting;
......@@ -35,6 +35,11 @@ public class CR3BPMultipleShooter extends AbstractMultipleShooting {
/** Name of the derivatives. */
private static final String STM = "stmEquations";
/** Derivatives linked to the Propagators.
* @since 11.1
*/
private final List<STMEquations> stmEquations;
/** Number of patch points. */
private int npoints;
......@@ -52,7 +57,8 @@ public class CR3BPMultipleShooter extends AbstractMultipleShooting {
final List<org.orekit.propagation.integration.AdditionalEquations> additionalEquations,
final double arcDuration, final double tolerance) {
super(initialGuessList, propagatorList, additionalEquations, arcDuration, tolerance, STM);
this.npoints = initialGuessList.size();
stmEquations = additionalEquations.stream().map(ae -> (STMEquations) ae).collect(Collectors.toList());
npoints = initialGuessList.size();
}
/** Simple Constructor.
......@@ -60,20 +66,20 @@ public class CR3BPMultipleShooter extends AbstractMultipleShooting {
* @param initialGuessList initial patch points to be corrected.
* @param propagatorList list of propagators associated to each patch point.
* @param arcDuration initial guess of the duration of each arc.
* @param additionalDerivativesProviders list of additional derivatives providers linked to propagatorList.
* @param stmEquations list of additional derivatives providers linked to propagatorList.
* @param tolerance convergence tolerance on the constraint vector
*/
public CR3BPMultipleShooter(final List<SpacecraftState> initialGuessList, final List<NumericalPropagator> propagatorList,
final double arcDuration, final List<AdditionalDerivativesProvider> additionalDerivativesProviders,
final double arcDuration, final List<STMEquations> stmEquations,
final double tolerance) {
super(initialGuessList, propagatorList, arcDuration, additionalDerivativesProviders, tolerance, STM);
this.npoints = initialGuessList.size();
super(initialGuessList, propagatorList, arcDuration, tolerance, STM);
this.stmEquations = stmEquations;
this.npoints = initialGuessList.size();
}
/** {@inheritDoc} */
protected SpacecraftState getAugmentedInitialState(final SpacecraftState initialState,
final AdditionalDerivativesProvider additionalDerivativesProvider) {
return ((STMEquations) additionalDerivativesProvider).setInitialPhi(initialState);
protected SpacecraftState getAugmentedInitialState(final int i) {
return stmEquations.get(i).setInitialPhi(getPatchPoint(i));
}
/** {@inheritDoc} */
......
......@@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.hipparchus.linear.MatrixUtils;
......@@ -31,7 +30,6 @@ import org.orekit.attitudes.AttitudeProvider;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.integration.AdditionalDerivativesProvider;
import org.orekit.propagation.numerical.NumericalPropagator;
import org.orekit.time.AbsoluteDate;
......@@ -47,9 +45,10 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
private List<SpacecraftState> patchedSpacecraftStates;
/** Derivatives linked to the Propagators.
* @since 11.1
* @deprecated as of 11.1 not used anymore
*/
private final List<AdditionalDerivativesProvider> additionalDerivativesProviders;
@Deprecated
private List<org.orekit.propagation.integration.AdditionalEquations> additionalEquations;
/** List of Propagators. */
private final List<NumericalPropagator> propagatorList;
......@@ -92,39 +91,29 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
* @param arcDuration initial guess of the duration of each arc.
* @param tolerance convergence tolerance on the constraint vector.
* @param additionalName name of the additional equations
* @deprecated as of 11.1, replaced by {@link #AbstractMultipleShooting(List, List, double, List, double, String)}
* @deprecated as of 11.1, replaced by {@link #AbstractMultipleShooting(List, List, double, double, String)}
*/
@SuppressWarnings("deprecation")
@Deprecated
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,
additionalEquations.
stream().
map(ae -> ae instanceof AdditionalDerivativesProvider ?
(AdditionalDerivativesProvider) ae :
new org.orekit.propagation.integration.AdditionalEquationsAdapter(ae, () -> propagatorList.get(0).getInitialState())).
collect(Collectors.toList()),
tolerance, additionalName);
this(initialGuessList, propagatorList, arcDuration, tolerance, additionalName);
this.additionalEquations = additionalEquations;
}
/** Simple Constructor.
* <p> Standard constructor for multiple shooting </p>
* @param initialGuessList initial patch points to be corrected.
* @param propagatorList list of propagators associated to each patch point.
* @param additionalDerivativesProviders list of additional derivatives providers linked to propagatorList.
* @param arcDuration initial guess of the duration of each arc.
* @param tolerance convergence tolerance on the constraint vector.
* @param additionalName name of the additional equations
* @since 11.1
*/
protected AbstractMultipleShooting(final List<SpacecraftState> initialGuessList, final List<NumericalPropagator> propagatorList,
final double arcDuration, final List<AdditionalDerivativesProvider> additionalDerivativesProviders,
final double tolerance, final String additionalName) {
final double arcDuration, final double tolerance, final String additionalName) {
this.patchedSpacecraftStates = initialGuessList;
this.propagatorList = propagatorList;
this.additionalDerivativesProviders = additionalDerivativesProviders;
this.additionalName = additionalName;
// Should check if propagatorList.size() = initialGuessList.size() - 1
final int propagationNumber = initialGuessList.size() - 1;
......@@ -156,6 +145,15 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
this.mapConstraints = new HashMap<>();
}
/** Get a patch point.
* @param i index of the patch point
* @return state of the patch point
* @since 11.1
*/
protected SpacecraftState getPatchPoint(final int i) {
return patchedSpacecraftStates.get(i);
}
/** Set a component of a patch point to free or not.
* @param patchNumber Patch point with constraint
* @param componentIndex Component of the patch points which are constrained.
......@@ -503,9 +501,7 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
for (int i = 0; i < n; i++) {
// SpacecraftState initialization
final SpacecraftState initialState = patchedSpacecraftStates.get(i);
final SpacecraftState augmentedInitialState = getAugmentedInitialState(initialState, additionalDerivativesProviders.get(i));
final SpacecraftState augmentedInitialState = getAugmentedInitialState(i);
// Propagator initialization
propagatorList.get(i).setInitialState(augmentedInitialState);
......@@ -513,7 +509,7 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
final double integrationTime = propagationTime[i];
// Propagate trajectory
final SpacecraftState finalState = propagatorList.get(i).propagate(initialState.getDate().shiftedBy(integrationTime));
final SpacecraftState finalState = propagatorList.get(i).propagate(augmentedInitialState.getDate().shiftedBy(integrationTime));
propagatedSP.add(finalState);
}
......@@ -627,11 +623,24 @@ public abstract class AbstractMultipleShooting implements MultipleShooting {
* @param initialState SpacecraftState without the additional state
* @param additionalEquations2 Additional Equations.
* @return augmentedSP SpacecraftState with the additional state within.
* @deprecated as of 11.1, replaced by {@link #getAugmentedInitialState(int)}
*/
protected abstract SpacecraftState getAugmentedInitialState(SpacecraftState initialState,
AdditionalDerivativesProvider additionalEquations2);
@Deprecated
protected SpacecraftState getAugmentedInitialState(final SpacecraftState initialState,
final org.orekit.propagation.integration.AdditionalEquations additionalEquations2) {
throw new UnsupportedOperationException();
}
/** Compute the additional state from the additionalEquations.
* @param i index of the state
* @return augmentedSP SpacecraftState with the additional state within.
* @since 11.1
*/
protected SpacecraftState getAugmentedInitialState(final int i) {
// FIXME: this base implementation is only intended for version 11.1 to delegate to a deprecated method
// it should be removed in 12.0 when getAugmentedInitialState(SpacecraftState, AdditionalDerivativesProvider) is removed
return getAugmentedInitialState(patchedSpacecraftStates.get(i), additionalEquations.get(i));
}
/** Set the constraint of a closed orbit or not.
* @param isClosed true if orbit should be closed
......
......@@ -18,9 +18,9 @@ package org.orekit.utils;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.integration.AdditionalDerivativesProvider;
import org.orekit.propagation.numerical.EpochDerivativesEquations;
import org.orekit.propagation.numerical.NumericalPropagator;
......@@ -36,6 +36,11 @@ public class MultipleShooter extends AbstractMultipleShooting {
/** Name fo the additional derivatives. */
private static final String DERIVATIVES = "derivatives";
/** Derivatives linked to the Propagators.
* @since 11.1
*/
private final List<EpochDerivativesEquations> epochEquations;
/** Simple Constructor.
* <p> Standard constructor for multiple shooting which can be used with the CR3BP model.</p>
* @param initialGuessList initial patch points to be corrected.
......@@ -50,26 +55,27 @@ public class MultipleShooter extends AbstractMultipleShooting {
final List<org.orekit.propagation.integration.AdditionalEquations> additionalEquations,
final double arcDuration, final double tolerance) {
super(initialGuessList, propagatorList, additionalEquations, arcDuration, tolerance, DERIVATIVES);
epochEquations = additionalEquations.stream().map(ae -> (EpochDerivativesEquations) ae).collect(Collectors.toList());
}
/** Simple Constructor.
* <p> Standard constructor for multiple shooting which can be used with the CR3BP model.</p>
* @param initialGuessList initial patch points to be corrected.
* @param arcDuration initial guess of the duration of each arc.
* @param additionalDerivativesProviders list of additional derivatives providers linked to propagatorList.
* @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
*/
public MultipleShooter(final List<SpacecraftState> initialGuessList, final List<NumericalPropagator> propagatorList,
final double arcDuration,
final List<AdditionalDerivativesProvider> additionalDerivativesProviders, final double tolerance) {
super(initialGuessList, propagatorList, arcDuration, additionalDerivativesProviders, tolerance, DERIVATIVES);
final List<EpochDerivativesEquations> epochEquations, final double tolerance) {
super(initialGuessList, propagatorList, arcDuration, tolerance, DERIVATIVES);
this.epochEquations = epochEquations;
}
/** {@inheritDoc} */
protected SpacecraftState getAugmentedInitialState(final SpacecraftState initialState,
final AdditionalDerivativesProvider additionalDerivativesProvider) {
return ((EpochDerivativesEquations) additionalDerivativesProvider).setInitialJacobians(initialState);
protected SpacecraftState getAugmentedInitialState(final int i) {
return epochEquations.get(i).setInitialJacobians(getPatchPoint(i));
}
/** {@inheritDoc} */
......
......@@ -36,7 +36,6 @@ import org.orekit.orbits.LibrationOrbitFamily;
import org.orekit.orbits.LibrationOrbitType;
import org.orekit.orbits.RichardsonExpansion;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.integration.AdditionalDerivativesProvider;
import org.orekit.propagation.numerical.cr3bp.CR3BPForceModel;
import org.orekit.propagation.numerical.cr3bp.CR3BPMultipleShooter;
import org.orekit.propagation.numerical.cr3bp.STMEquations;
......@@ -73,7 +72,7 @@ public class CR3BPMultipleShooterTest {
vecAbsoluteTolerances,
vecRelativeTolerances);
final int narcs = 1;
final List<AdditionalDerivativesProvider> cr3bpAdditionalEquations = new ArrayList<>(narcs) ;
final List<STMEquations> cr3bpAdditionalEquations = new ArrayList<>(narcs) ;
cr3bpAdditionalEquations.add(new STMEquations(syst));
// Propagator definition for CR3BP
......
......@@ -40,7 +40,6 @@ import org.orekit.forces.gravity.ThirdBodyAttractionEpoch;
import org.orekit.frames.Frame;
import org.orekit.frames.FramesFactory;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.integration.AdditionalDerivativesProvider;
import org.orekit.propagation.numerical.EpochDerivativesEquations;
import org.orekit.propagation.numerical.NumericalPropagator;
import org.orekit.time.AbsoluteDate;
......@@ -128,7 +127,7 @@ public class MultipleShooterTest {
final AbsolutePVCoordinates firstGuessAPV = new AbsolutePVCoordinates(primaryFrame, initialDate, firstGuess);
List<SpacecraftState> firstGuessList2 = generatePatchPointsEphemeris(sun, earth, firstGuessAPV, arcDuration, narcs, integrator);
final List<NumericalPropagator> propagatorList = initializePropagators(sun, earth, integrator, narcs);
final List<AdditionalDerivativesProvider> additionalDerivativesProviders = addDerivativesProviders(propagatorList);
final List<EpochDerivativesEquations> epochEquations = addDerivativesProviders(propagatorList);
for (int i = 0; i < narcs + 1; i++) {
final SpacecraftState sp = firstGuessList2.get(i);
......@@ -157,7 +156,7 @@ public class MultipleShooterTest {
final double tolerance = 1.0;
MultipleShooter multipleShooting = new MultipleShooter(correctedList, propagatorList, arcDuration, additionalDerivativesProviders, tolerance);
MultipleShooter multipleShooting = new MultipleShooter(correctedList, propagatorList, arcDuration, epochEquations, tolerance);
multipleShooting.setPatchPointComponentFreedom(1, 0, false);
multipleShooting.setPatchPointComponentFreedom(1, 1, false);
multipleShooting.setPatchPointComponentFreedom(1, 2, false);
......@@ -231,7 +230,7 @@ public class MultipleShooterTest {
final AbsolutePVCoordinates firstGuessAPV = new AbsolutePVCoordinates(primaryFrame, initialDate, firstGuess);
List<SpacecraftState> firstGuessList2 = generatePatchPointsEphemeris(sun, earth, firstGuessAPV, arcDuration, narcs, integrator);
final List<NumericalPropagator> propagatorList = initializePropagatorsWithEstimated(sun, earth, integrator, narcs);
final List<AdditionalDerivativesProvider> additionalDerivativesProviders = addDerivativesProviders(propagatorList);
final List<EpochDerivativesEquations> epochEquations = addDerivativesProviders(propagatorList);
for (int i = 0; i < narcs + 1; i++) {
final SpacecraftState sp = firstGuessList2.get(i);
......@@ -260,7 +259,7 @@ public class MultipleShooterTest {
final double tolerance = 1.0;
MultipleShooter multipleShooting = new MultipleShooter(correctedList, propagatorList, arcDuration, additionalDerivativesProviders, tolerance);
MultipleShooter multipleShooting = new MultipleShooter(correctedList, propagatorList, arcDuration, epochEquations, tolerance);
multipleShooting.setPatchPointComponentFreedom(1, 0, false);
multipleShooting.setPatchPointComponentFreedom(1, 1, false);
multipleShooting.setPatchPointComponentFreedom(1, 2, false);
......@@ -376,9 +375,9 @@ public class MultipleShooterTest {
return propagatorList;
}
private static List<AdditionalDerivativesProvider> addDerivativesProviders(List<NumericalPropagator> propagatorList){
private static List<EpochDerivativesEquations> addDerivativesProviders(List<NumericalPropagator> propagatorList){
final int narcs = propagatorList.size();
final List<AdditionalDerivativesProvider> additionalEquations = new ArrayList<>(narcs) ;
final List<EpochDerivativesEquations> additionalEquations = new ArrayList<>(narcs) ;
for(int i = 0; i < narcs; i++) {
additionalEquations.add(new EpochDerivativesEquations("derivatives", propagatorList.get(i)));
}
......
Supports Markdown
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