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 fieldImpulseProvider impulse provider
  112.      * @param isp engine specific impulse (s)
  113.      * @param control3DVectorCostType increment's norm for mass consumption
  114.      */
  115.     public FieldImpulseManeuver(final FieldEventDetector<T> trigger, final AttitudeProvider attitudeOverride,
  116.                                 final FieldImpulseProvider<T> fieldImpulseProvider, final T isp,
  117.                                 final Control3DVectorCostType control3DVectorCostType) {
  118.         this(trigger, trigger.getDetectionSettings(), attitudeOverride, fieldImpulseProvider, isp, control3DVectorCostType);
  119.     }

  120.     /** Private constructor.
  121.      * @param trigger triggering event
  122.      * @param detectionSettings event detection settings
  123.      * @param attitudeOverride the attitude provider to use for the maneuver
  124.      * @param fieldImpulseProvider impulse provider
  125.      * @param isp engine specific impulse (s)
  126.      * @param control3DVectorCostType increment's norm for mass consumption
  127.      */
  128.     private FieldImpulseManeuver(final FieldEventDetector<T> trigger,
  129.                                  final FieldEventDetectionSettings<T> detectionSettings,
  130.                                  final AttitudeProvider attitudeOverride, final FieldImpulseProvider<T> fieldImpulseProvider,
  131.                                  final T isp, final Control3DVectorCostType control3DVectorCostType) {
  132.         super(attitudeOverride, control3DVectorCostType);
  133.         this.trigger = trigger;
  134.         this.detectionSettings = detectionSettings;
  135.         this.fieldImpulseProvider = fieldImpulseProvider;
  136.         this.isp = isp;
  137.         this.vExhaust = this.isp.multiply(Constants.G0_STANDARD_GRAVITY);
  138.         this.handler = new Handler<>();
  139.     }

  140.     /**
  141.      * Creates a copy with different event detection settings.
  142.      * @param eventDetectionSettings new detection settings
  143.      * @return a new detector with same properties except for the detection settings
  144.      */
  145.     public FieldImpulseManeuver<T> withDetectionSettings(final FieldEventDetectionSettings<T> eventDetectionSettings) {
  146.         return new FieldImpulseManeuver<>(trigger, eventDetectionSettings, getAttitudeOverride(), fieldImpulseProvider, isp,
  147.                 getControl3DVectorCostType());
  148.     }

  149.     /** {@inheritDoc} */
  150.     @Override
  151.     public void init(final FieldSpacecraftState<T> s0, final FieldAbsoluteDate<T> t) {
  152.         FieldDetectorModifier.super.init(s0, t);
  153.         forward = t.durationFrom(s0.getDate()).getReal() >= 0;
  154.         fieldImpulseProvider.init(s0, t);
  155.     }

  156.     /** {@inheritDoc} */
  157.     @Override
  158.     public void finish(final FieldSpacecraftState<T> state) {
  159.         FieldDetectorModifier.super.finish(state);
  160.         fieldImpulseProvider.finish(state);
  161.     }

  162.     /** {@inheritDoc} */
  163.     @Override
  164.     public FieldEventDetectionSettings<T> getDetectionSettings() {
  165.         return detectionSettings;
  166.     }

  167.     /** {@inheritDoc} */
  168.     @Override
  169.     public FieldEventDetector<T> getDetector() {
  170.         return trigger;
  171.     }

  172.     /** Get the triggering event.
  173.      * @return triggering event
  174.      */
  175.     public FieldEventDetector<T> getTrigger() {
  176.         return getDetector();
  177.     }

  178.     /**
  179.      * Getter for the impulse provider.
  180.      * @return impulse provider
  181.      * @since 13.0
  182.      */
  183.     public FieldImpulseProvider<T> getFieldImpulseProvider() {
  184.         return fieldImpulseProvider;
  185.     }

  186.     /** Get the specific impulse.
  187.      * @return specific impulse
  188.      */
  189.     public T getIsp() {
  190.         return isp;
  191.     }

  192.     @Override
  193.     public FieldEventHandler<T> getHandler() {
  194.         return handler;
  195.     }

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

  198.         /** {@inheritDoc} */
  199.         @Override
  200.         public Action eventOccurred(final FieldSpacecraftState<T> s,
  201.                                     final FieldEventDetector<T> detector,
  202.                                     final boolean increasing) {
  203.             final FieldImpulseManeuver<T> im = (FieldImpulseManeuver<T>) detector;
  204.             im.trigger.getHandler().eventOccurred(s, im.trigger, increasing); // Action ignored but method still called
  205.             return Action.RESET_STATE;
  206.         }

  207.         /** {@inheritDoc} */
  208.         @Override
  209.         public FieldSpacecraftState<T> resetState(final FieldEventDetector<T> detector,
  210.                                                   final FieldSpacecraftState<T> oldState) {

  211.             final FieldImpulseManeuver<T> im = (FieldImpulseManeuver<T>) detector;
  212.             final FieldAbsoluteDate<T> date = oldState.getDate();
  213.             final boolean isStateOrbitDefined = oldState.isOrbitDefined();

  214.             final FieldRotation<T> rotation;
  215.             if (im.getAttitudeOverride() == null) {
  216.                 rotation = oldState.getAttitude().getRotation();
  217.             } else {
  218.                 rotation = im.getAttitudeOverride().getAttitudeRotation(isStateOrbitDefined ? oldState.getOrbit() : oldState.getAbsPVA(),
  219.                         date, oldState.getFrame());
  220.             }

  221.             // convert velocity increment in inertial frame
  222.             final FieldVector3D<T> deltaVSat = im.fieldImpulseProvider.getImpulse(oldState, im.forward);
  223.             final FieldVector3D<T> deltaV = rotation.applyInverseTo(deltaVSat);
  224.             final T one = oldState.getMass().getField().getOne();
  225.             final T sign = (im.forward) ? one : one.negate();

  226.             // apply increment to position/velocity
  227.             final FieldPVCoordinates<T> oldPV = oldState.getPVCoordinates();
  228.             final FieldVector3D<T> newVelocity = oldPV.getVelocity().add(deltaV);
  229.             final FieldPVCoordinates<T> newPV = new FieldPVCoordinates<>(oldPV.getPosition(), newVelocity);

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

  233.             // pack everything in a new state
  234.             if (oldState.isOrbitDefined()) {
  235.                 final FieldOrbit<T> newOrbit = new FieldCartesianOrbit<>(newPV, oldState.getFrame(), oldState.getDate(),
  236.                         oldState.getOrbit().getMu());
  237.                 return new FieldSpacecraftState<>(oldState.getOrbit().getType().normalize(newOrbit, oldState.getOrbit()),
  238.                         oldState.getAttitude(), newMass, oldState.getAdditionalDataValues(),
  239.                         oldState.getAdditionalStatesDerivatives());
  240.             } else {
  241.                 final FieldAbsolutePVCoordinates<T> newAbsPVA = new FieldAbsolutePVCoordinates<>(oldState.getFrame(),
  242.                         oldState.getDate(), newPV);
  243.                 return new FieldSpacecraftState<>(newAbsPVA, oldState.getAttitude(), newMass,
  244.                         oldState.getAdditionalDataValues(), oldState.getAdditionalStatesDerivatives());
  245.             }
  246.         }

  247.     }
  248. }