AbstractParametricAcceleration.java

  1. /* Copyright 2022-2025 Romain Serra
  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.empirical;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Rotation;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.orekit.attitudes.AttitudeProvider;
  25. import org.orekit.forces.ForceModel;
  26. import org.orekit.propagation.FieldSpacecraftState;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.propagation.events.EventDetector;
  29. import org.orekit.propagation.events.FieldEventDetector;

  30. import java.util.stream.Stream;

  31. /**
  32.  * Abstract class for parametric acceleration.
  33.  *
  34.  * @since 13.0
  35.  * @author Romain Serra
  36.  */
  37. public abstract class AbstractParametricAcceleration implements ForceModel {

  38.     /** Direction of the acceleration in defining frame. */
  39.     private final Vector3D direction;

  40.     /** Flag for inertial acceleration direction. */
  41.     private final boolean isInertial;

  42.     /** The attitude to override, if set. */
  43.     private final AttitudeProvider attitudeOverride;

  44.     protected AbstractParametricAcceleration(final Vector3D direction, final boolean isInertial,
  45.                                              final AttitudeProvider attitudeOverride) {
  46.         this.direction = direction;
  47.         this.isInertial = isInertial;
  48.         this.attitudeOverride = attitudeOverride;
  49.     }

  50.     /**
  51.      * Getter for attitude override.
  52.      * @return attitude override
  53.      */
  54.     public AttitudeProvider getAttitudeOverride() {
  55.         return attitudeOverride;
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public boolean dependsOnPositionOnly() {
  60.         return isInertial;
  61.     }

  62.     /**
  63.      * Computes the acceleration's direction in the propagation frame.
  64.      * @param state state
  65.      * @return direction
  66.      */
  67.     protected Vector3D getAccelerationDirection(final SpacecraftState state) {
  68.         if (isInertial) {
  69.             // the acceleration direction is already defined in the inertial frame
  70.             return direction;
  71.         } else {
  72.             final Rotation rotation;
  73.             if (attitudeOverride == null) {
  74.                 // the acceleration direction is defined in spacecraft frame as set by the propagator
  75.                 rotation = state.getAttitude().getRotation();
  76.             } else {
  77.                 // the acceleration direction is defined in a dedicated frame
  78.                 rotation = attitudeOverride.getAttitudeRotation(state.isOrbitDefined() ? state.getOrbit() : state.getAbsPVA(),
  79.                         state.getDate(), state.getFrame());
  80.             }
  81.             return rotation.applyInverseTo(direction);
  82.         }
  83.     }

  84.     /**
  85.      * Computes the acceleration's direction in the propagation frame.
  86.      * @param state state
  87.      * @param <T> field type
  88.      * @return direction
  89.      */
  90.     protected <T extends CalculusFieldElement<T>> FieldVector3D<T> getAccelerationDirection(final FieldSpacecraftState<T> state) {
  91.         if (isInertial) {
  92.             // the acceleration direction is already defined in the inertial frame
  93.             return new FieldVector3D<>(state.getDate().getField(), direction);
  94.         } else {
  95.             final FieldRotation<T> rotation;
  96.             if (attitudeOverride == null) {
  97.                 // the acceleration direction is defined in spacecraft frame as set by the propagator
  98.                 rotation = state.getAttitude().getRotation();
  99.             } else {
  100.                 // the acceleration direction is defined in a dedicated frame
  101.                 rotation = attitudeOverride.getAttitudeRotation(state.getOrbit(), state.getDate(), state.getFrame());
  102.             }
  103.             return rotation.applyInverseTo(direction);
  104.         }
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     public Stream<EventDetector> getEventDetectors() {
  109.         return attitudeOverride == null ? Stream.of() : attitudeOverride.getEventDetectors();
  110.     }

  111.     /** {@inheritDoc} */
  112.     @Override
  113.     public <T extends CalculusFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventDetectors(final Field<T> field) {
  114.         return attitudeOverride == null ? Stream.of() : attitudeOverride.getFieldEventDetectors(field);
  115.     }
  116. }