FieldImpulseManeuver.java

  1. /* Copyright 2002-2025 Exotrail
  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.forces.maneuvers;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.ode.events.Action;
  22. import org.hipparchus.util.FastMath;
  23. import org.orekit.attitudes.AttitudeProvider;
  24. import org.orekit.orbits.FieldCartesianOrbit;
  25. import org.orekit.orbits.FieldOrbit;
  26. import org.orekit.propagation.FieldSpacecraftState;
  27. import org.orekit.propagation.events.FieldDetectorModifier;
  28. import org.orekit.propagation.events.FieldEventDetectionSettings;
  29. import org.orekit.propagation.events.FieldEventDetector;
  30. import org.orekit.propagation.events.handlers.FieldEventHandler;
  31. import org.orekit.time.FieldAbsoluteDate;
  32. import org.orekit.utils.Constants;
  33. import org.orekit.utils.FieldAbsolutePVCoordinates;
  34. import org.orekit.utils.FieldPVCoordinates;

  35. /** Impulse maneuver model for propagators working with Fields.
  36.  * <p>This class implements an impulse maneuver as a discrete event
  37.  * that can be provided to any {@link org.orekit.propagation.FieldPropagator
  38.  * Propagator} and mirrors the standard version
  39.  * {@link org.orekit.forces.maneuvers.ImpulseManeuver}.</p>
  40.  * <p>The maneuver is executed when an underlying is triggered, in which case this class will generate a {@link
  41.  * Action#RESET_STATE RESET_STATE} event. By default, the detection settings are those of the trigger.
  42.  * In the simple cases, the underlying event detector may be a basic
  43.  * {@link org.orekit.propagation.events.FieldDateDetector date event}, but it
  44.  * can also be a more elaborate {@link
  45.  * org.orekit.propagation.events.FieldApsideDetector apside event} for apogee
  46.  * maneuvers for example.</p>
  47.  * <p>The maneuver velocity increment is defined via {@link FieldImpulseProvider}.
  48.  * If no AttitudeProvider is given, the current attitude of the spacecraft,
  49.  * defined by the current spacecraft state, will be used as the
  50.  * {@link AttitudeProvider} so the velocity increment should be given in
  51.  * the same pseudoinertial frame as the {@link FieldSpacecraftState} used to
  52.  * construct the propagator that will handle the maneuver.
  53.  * If an AttitudeProvider is given, the velocity increment given should be
  54.  * defined appropriately in consideration of that provider. So, a typical
  55.  * case for tangential maneuvers is to provide a {@link org.orekit.attitudes.LofOffset LOF aligned}
  56.  * attitude provider along with a velocity increment defined in accordance with
  57.  * that LOF aligned attitude provider; e.g. if the LOF aligned attitude provider
  58.  * was constructed using LOFType.VNC the velocity increment should be
  59.  * provided in VNC coordinates.</p>
  60.  * <p>The norm through which the delta-V maps to the mass consumption is chosen via the
  61.  * enum {@link Control3DVectorCostType}. Default is Euclidean. </p>
  62.  * <p>Beware that the triggering event detector must behave properly both
  63.  * before and after maneuver. If for example a node detector is used to trigger
  64.  * an inclination maneuver and the maneuver change the orbit to an equatorial one,
  65.  * the node detector will fail just after the maneuver, being unable to find a
  66.  * node on an equatorial orbit! This is a real case that has been encountered
  67.  * during validation ...</p>
  68.  * @see org.orekit.propagation.FieldPropagator#addEventDetector(FieldEventDetector)
  69.  * @see org.orekit.forces.maneuvers.ImpulseManeuver
  70.  * @author Romain Serra
  71.  * @since 12.0
  72.  * @param <T> type of the field elements
  73.  */
  74. public class FieldImpulseManeuver<T extends CalculusFieldElement<T>> extends AbstractImpulseManeuver
  75.         implements FieldDetectorModifier<T> {

  76.     /** Triggering event. */
  77.     private final FieldEventDetector<T> trigger;

  78.     /** Specific impulse. */
  79.     private final T isp;

  80.     /** Engine exhaust velocity. */
  81.     private final T vExhaust;

  82.     /** Trigger's detection settings. */
  83.     private final FieldEventDetectionSettings<T> detectionSettings;

  84.     /** Specific event handler. */
  85.     private final Handler<T> handler;

  86.     /** Field impulse provider. */
  87.     private final FieldImpulseProvider<T> fieldImpulseProvider;

  88.     /** Indicator for forward propagation. */
  89.     private boolean forward;

  90.     /** Build a new instance.
  91.      * @param trigger triggering event
  92.      * @param deltaVSat velocity increment in satellite frame
  93.      * @param isp engine specific impulse (s)
  94.      */
  95.     public FieldImpulseManeuver(final FieldEventDetector<T> trigger, final FieldVector3D<T> deltaVSat, final T isp) {
  96.         this(trigger, null, deltaVSat, isp);
  97.     }

  98.     /** Build a new instance.
  99.      * @param trigger triggering event
  100.      * @param attitudeOverride the attitude provider to use for the maneuver
  101.      * @param deltaVSat velocity increment in satellite frame
  102.      * @param isp engine specific impulse (s)
  103.      */
  104.     public FieldImpulseManeuver(final FieldEventDetector<T> trigger, final AttitudeProvider attitudeOverride,
  105.                                 final FieldVector3D<T> deltaVSat, final T isp) {
  106.         this(trigger, attitudeOverride, FieldImpulseProvider.of(deltaVSat), isp, Control3DVectorCostType.TWO_NORM);
  107.     }

  108.     /** Build a new instance.
  109.      * @param trigger triggering event
  110.      * @param attitudeOverride the attitude provider to use for the maneuver
  111.      * @param deltaVSat velocity increment in satellite frame
  112.      * @param isp engine specific impulse (s)
  113.      * @param control3DVectorCostType increment's norm for mass consumption
  114.      * @deprecated since 13.0
  115.      */
  116.     @Deprecated
  117.     public FieldImpulseManeuver(final FieldEventDetector<T> trigger, final AttitudeProvider attitudeOverride,
  118.                                 final FieldVector3D<T> deltaVSat, final T isp,
  119.                                 final Control3DVectorCostType control3DVectorCostType) {
  120.         this(trigger, trigger.getDetectionSettings(), attitudeOverride,
  121.                 FieldImpulseProvider.of(deltaVSat), isp, control3DVectorCostType);
  122.     }

  123.     /** Build a new instance.
  124.      * @param trigger triggering event
  125.      * @param attitudeOverride the attitude provider to use for the maneuver
  126.      * @param fieldImpulseProvider impulse provider
  127.      * @param isp engine specific impulse (s)
  128.      * @param control3DVectorCostType increment's norm for mass consumption
  129.      */
  130.     public FieldImpulseManeuver(final FieldEventDetector<T> trigger, final AttitudeProvider attitudeOverride,
  131.                                 final FieldImpulseProvider<T> fieldImpulseProvider, final T isp,
  132.                                 final Control3DVectorCostType control3DVectorCostType) {
  133.         this(trigger, trigger.getDetectionSettings(), attitudeOverride, fieldImpulseProvider, isp, control3DVectorCostType);
  134.     }

  135.     /** Private constructor.
  136.      * @param trigger triggering event
  137.      * @param detectionSettings event detection settings
  138.      * @param attitudeOverride the attitude provider to use for the maneuver
  139.      * @param fieldImpulseProvider impulse provider
  140.      * @param isp engine specific impulse (s)
  141.      * @param control3DVectorCostType increment's norm for mass consumption
  142.      */
  143.     private FieldImpulseManeuver(final FieldEventDetector<T> trigger,
  144.                                  final FieldEventDetectionSettings<T> detectionSettings,
  145.                                  final AttitudeProvider attitudeOverride, final FieldImpulseProvider<T> fieldImpulseProvider,
  146.                                  final T isp, final Control3DVectorCostType control3DVectorCostType) {
  147.         super(attitudeOverride, control3DVectorCostType);
  148.         this.trigger = trigger;
  149.         this.detectionSettings = detectionSettings;
  150.         this.fieldImpulseProvider = fieldImpulseProvider;
  151.         this.isp = isp;
  152.         this.vExhaust = this.isp.multiply(Constants.G0_STANDARD_GRAVITY);
  153.         this.handler = new Handler<>();
  154.     }

  155.     /**
  156.      * Creates a copy with different event detection settings.
  157.      * @param eventDetectionSettings new detection settings
  158.      * @return a new detector with same properties except for the detection settings
  159.      */
  160.     public FieldImpulseManeuver<T> withDetectionSettings(final FieldEventDetectionSettings<T> eventDetectionSettings) {
  161.         return new FieldImpulseManeuver<>(trigger, eventDetectionSettings, getAttitudeOverride(), fieldImpulseProvider, isp,
  162.                 getControl3DVectorCostType());
  163.     }

  164.     /** {@inheritDoc} */
  165.     @Override
  166.     public void init(final FieldSpacecraftState<T> s0, final FieldAbsoluteDate<T> t) {
  167.         FieldDetectorModifier.super.init(s0, t);
  168.         forward = t.durationFrom(s0.getDate()).getReal() >= 0;
  169.         fieldImpulseProvider.init(s0, t);
  170.     }

  171.     /** {@inheritDoc} */
  172.     @Override
  173.     public void finish(final FieldSpacecraftState<T> state) {
  174.         FieldDetectorModifier.super.finish(state);
  175.         fieldImpulseProvider.finish(state);
  176.     }

  177.     /** {@inheritDoc} */
  178.     @Override
  179.     public FieldEventDetectionSettings<T> getDetectionSettings() {
  180.         return detectionSettings;
  181.     }

  182.     /** {@inheritDoc} */
  183.     @Override
  184.     public FieldEventDetector<T> getDetector() {
  185.         return trigger;
  186.     }

  187.     /** Get the triggering event.
  188.      * @return triggering event
  189.      */
  190.     public FieldEventDetector<T> getTrigger() {
  191.         return getDetector();
  192.     }

  193.     /**
  194.      * Getter for the impulse provider.
  195.      * @return impulse provider
  196.      * @since 13.0
  197.      */
  198.     public FieldImpulseProvider<T> getFieldImpulseProvider() {
  199.         return fieldImpulseProvider;
  200.     }

  201.     /** Get the specific impulse.
  202.      * @return specific impulse
  203.      */
  204.     public T getIsp() {
  205.         return isp;
  206.     }

  207.     @Override
  208.     public FieldEventHandler<T> getHandler() {
  209.         return handler;
  210.     }

  211.     /** Local handler. */
  212.     private static class Handler<T extends CalculusFieldElement<T>> implements FieldEventHandler<T> {

  213.         /** {@inheritDoc} */
  214.         @Override
  215.         public Action eventOccurred(final FieldSpacecraftState<T> s,
  216.                                     final FieldEventDetector<T> detector,
  217.                                     final boolean increasing) {
  218.             final FieldImpulseManeuver<T> im = (FieldImpulseManeuver<T>) detector;
  219.             im.trigger.getHandler().eventOccurred(s, im.trigger, increasing); // Action ignored but method still called
  220.             return Action.RESET_STATE;
  221.         }

  222.         /** {@inheritDoc} */
  223.         @Override
  224.         public FieldSpacecraftState<T> resetState(final FieldEventDetector<T> detector,
  225.                                                   final FieldSpacecraftState<T> oldState) {

  226.             final FieldImpulseManeuver<T> im = (FieldImpulseManeuver<T>) detector;
  227.             final FieldAbsoluteDate<T> date = oldState.getDate();
  228.             final boolean isStateOrbitDefined = oldState.isOrbitDefined();

  229.             final FieldRotation<T> rotation;
  230.             if (im.getAttitudeOverride() == null) {
  231.                 rotation = oldState.getAttitude().getRotation();
  232.             } else {
  233.                 rotation = im.getAttitudeOverride().getAttitudeRotation(isStateOrbitDefined ? oldState.getOrbit() : oldState.getAbsPVA(),
  234.                         date, oldState.getFrame());
  235.             }

  236.             // convert velocity increment in inertial frame
  237.             final FieldVector3D<T> deltaVSat = im.fieldImpulseProvider.getImpulse(oldState, im.forward);
  238.             final FieldVector3D<T> deltaV = rotation.applyInverseTo(deltaVSat);
  239.             final T one = oldState.getMass().getField().getOne();
  240.             final T sign = (im.forward) ? one : one.negate();

  241.             // apply increment to position/velocity
  242.             final FieldPVCoordinates<T> oldPV = oldState.getPVCoordinates();
  243.             final FieldVector3D<T> newVelocity = oldPV.getVelocity().add(deltaV);
  244.             final FieldPVCoordinates<T> newPV = new FieldPVCoordinates<>(oldPV.getPosition(), newVelocity);

  245.             // compute new mass
  246.             final T normDeltaV = im.getControl3DVectorCostType().evaluate(deltaVSat);
  247.             final T newMass = oldState.getMass().multiply(FastMath.exp(normDeltaV.multiply(sign.negate()).divide(im.vExhaust)));

  248.             // pack everything in a new state
  249.             if (oldState.isOrbitDefined()) {
  250.                 final FieldOrbit<T> newOrbit = new FieldCartesianOrbit<>(newPV, oldState.getFrame(), oldState.getDate(),
  251.                         oldState.getOrbit().getMu());
  252.                 return new FieldSpacecraftState<>(oldState.getOrbit().getType().normalize(newOrbit, oldState.getOrbit()),
  253.                         oldState.getAttitude(), newMass, oldState.getAdditionalDataValues(),
  254.                         oldState.getAdditionalStatesDerivatives());
  255.             } else {
  256.                 final FieldAbsolutePVCoordinates<T> newAbsPVA = new FieldAbsolutePVCoordinates<>(oldState.getFrame(),
  257.                         oldState.getDate(), newPV);
  258.                 return new FieldSpacecraftState<>(newAbsPVA, oldState.getAttitude(), newMass,
  259.                         oldState.getAdditionalDataValues(), oldState.getAdditionalStatesDerivatives());
  260.             }
  261.         }

  262.     }
  263. }