LibrationOrbit.java

  1. /* Copyright 2002-2020 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.orbits;

  18. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.linear.EigenDecomposition;
  20. import org.hipparchus.linear.RealMatrix;
  21. import org.hipparchus.linear.RealVector;
  22. import org.orekit.annotation.DefaultDataContext;
  23. import org.orekit.attitudes.AttitudeProvider;
  24. import org.orekit.bodies.CR3BPSystem;
  25. import org.orekit.data.DataContext;
  26. import org.orekit.propagation.Propagator;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.propagation.numerical.cr3bp.STMEquations;
  29. import org.orekit.time.TimeScale;
  30. import org.orekit.utils.PVCoordinates;

  31. /**
  32.  * Base class for libration orbits.
  33.  * @see HaloOrbit
  34.  * @see LyapunovOrbit
  35.  * @author Vincent Mouraux
  36.  * @author Bryan Cazabonne
  37.  * @since 10.2
  38.  */
  39. public abstract class LibrationOrbit {

  40.     /** CR3BP System of the libration Orbit. */
  41.     private final CR3BPSystem syst;

  42.     /** Position-Velocity initial position on a libration Orbit. */
  43.     private PVCoordinates initialPV;

  44.     /** Orbital Period of the libration Orbit. */
  45.     private double orbitalPeriod;

  46.     /**
  47.      * Constructor.
  48.      * @param system CR3BP System considered
  49.      * @param initialPV initial position on a libration Orbit
  50.      * @param orbitalPeriod initial orbital period of the libration Orbit
  51.      */
  52.     protected LibrationOrbit(final CR3BPSystem system,
  53.                              final PVCoordinates initialPV,
  54.                              final double orbitalPeriod) {
  55.         this.syst = system;
  56.         this.initialPV = initialPV;
  57.         this.orbitalPeriod = orbitalPeriod;
  58.     }

  59.     /** Return the orbital period of the libration orbit.
  60.      * @return orbitalPeriod  orbital period of the libration orbit
  61.      */
  62.     public double getOrbitalPeriod() {
  63.         return orbitalPeriod;
  64.     }

  65.     /** Return the initialPV on the libration orbit.
  66.      * <p>
  67.      * This will return the exact initialPV only if you applied a prior
  68.      * differential correction. If you did not, you can use the method
  69.      * {@link #applyCorrectionOnPV(CR3BPDifferentialCorrection)}
  70.      * </p>
  71.      * @return initialPV initialPV on the libration orbit
  72.      */
  73.     public PVCoordinates getInitialPV() {
  74.         return initialPV;
  75.     }

  76.     /** Apply differential correction.
  77.      * <p>
  78.      * This will update {@link #initialPV} and
  79.      * {@link #orbitalPeriod} parameters.
  80.      * </p>
  81.      */
  82.     @DefaultDataContext
  83.     public void applyDifferentialCorrection() {
  84.         applyDifferentialCorrection(Propagator.getDefaultLaw(DataContext.getDefault().getFrames()),
  85.                                     DataContext.getDefault().getTimeScales().getUTC());
  86.     }

  87.     /** Apply differential correction.
  88.      * <p>
  89.      * This will update {@link #initialPV} and
  90.      * {@link #orbitalPeriod} parameters.
  91.      * </p>
  92.      * @param attitudeProvider the attitude law for the numerocal propagator
  93.      * @param utc UTC time scale
  94.      */
  95.     public void applyDifferentialCorrection(final AttitudeProvider attitudeProvider,
  96.                                             final TimeScale utc) {
  97.         final CR3BPDifferentialCorrection diff = new CR3BPDifferentialCorrection(initialPV, syst, orbitalPeriod, attitudeProvider, utc);
  98.         initialPV = applyCorrectionOnPV(diff);
  99.         orbitalPeriod = diff.getOrbitalPeriod();
  100.     }

  101.     /** Return a manifold direction from one position on a libration Orbit.
  102.      * @param s SpacecraftState with additional equations
  103.      * @param isStable true if the manifold is stable
  104.      * @return manifold first guess Position-Velocity of a point on the libration Orbit
  105.      */
  106.     public PVCoordinates getManifolds(final SpacecraftState s,
  107.                                       final boolean isStable) {
  108.         return isStable ? getStableManifolds(s) : getUnstableManifolds(s);
  109.     }

  110.     /** Return the stable manifold direction for several positions on a libration Orbit.
  111.      * @param s SpacecraftStates (with STM equations) to compute from
  112.      * @return Stable manifold first direction from a point on the libration Orbit
  113.      */
  114.     private PVCoordinates getStableManifolds(final SpacecraftState s) {

  115.         // Small delta, linked to the characteristic velocity of the CR3BP system
  116.         final double epsilon = syst.getVdim() * 1E2 / syst.getDdim();

  117.         // Get Normalize eigen vector linked to the stability of the manifold
  118.         final RealMatrix phi         = new STMEquations(syst).getStateTransitionMatrix(s);
  119.         final RealVector eigenVector = new EigenDecomposition(phi).getEigenvector(1).unitVector();

  120.         // New PVCoordinates following the manifold
  121.         return new PVCoordinates(s.getPVCoordinates().getPosition()
  122.                 .add(new Vector3D(eigenVector.getEntry(0), eigenVector
  123.                         .getEntry(1), eigenVector.getEntry(2))
  124.                             .scalarMultiply(epsilon)), s.getPVCoordinates()
  125.                                 .getVelocity()
  126.                                 .add(new Vector3D(eigenVector.getEntry(3),
  127.                                                   eigenVector.getEntry(4),
  128.                                                   eigenVector.getEntry(5))
  129.                                                       .scalarMultiply(epsilon)));
  130.     }

  131.     /** Get the Unstable manifold direction for several positions on a libration Orbit.
  132.      * @param s spacecraft state (with STM equations) to compute from
  133.      * @return pv coordinates representing the unstable manifold first direction
  134.      *         from a point on the libration Orbit
  135.      */
  136.     private PVCoordinates getUnstableManifolds(final SpacecraftState s) {

  137.         // Small delta, linked to the characteristic velocity of the CR3BP system
  138.         final double epsilon =
  139.             syst.getVdim() * 1E2 / syst.getDdim();

  140.         // Get Normalize eigen vector linked to the stability of the manifold
  141.         final RealMatrix phi         = new STMEquations(syst).getStateTransitionMatrix(s);
  142.         final RealVector eigenVector = new EigenDecomposition(phi).getEigenvector(0).unitVector();

  143.         // New PVCoordinates following the manifold
  144.         return new PVCoordinates(s.getPVCoordinates().getPosition()
  145.                     .add(new Vector3D(eigenVector.getEntry(0), eigenVector
  146.                         .getEntry(1), eigenVector.getEntry(2))
  147.                             .scalarMultiply(epsilon)), s.getPVCoordinates()
  148.                                 .getVelocity()
  149.                                 .add(new Vector3D(eigenVector.getEntry(3),
  150.                                                   eigenVector.getEntry(4),
  151.                                                   eigenVector.getEntry(5))
  152.                                                       .scalarMultiply(epsilon)));
  153.     }

  154.     /**
  155.      * Apply the differential correction to compute more accurate initial PV.
  156.      * @param diff cr3bp differential correction
  157.      * @return corrected PV coordinates
  158.      */
  159.     protected abstract PVCoordinates applyCorrectionOnPV(CR3BPDifferentialCorrection diff);

  160. }