FieldAdditionalEquationsAdapter.java

  1. /* Copyright 2002-2022 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.propagation.integration;

  18. import java.util.function.Supplier;

  19. import org.hipparchus.CalculusFieldElement;
  20. import org.hipparchus.util.MathArrays;
  21. import org.orekit.propagation.FieldSpacecraftState;
  22. import org.orekit.time.FieldAbsoluteDate;

  23. /** Temporary adapter from {@link FieldAdditionalEquations} to {@link FieldAdditionalDerivativesProvider}.
  24.  * @since 11.1
  25.  * @deprecated must be removed in 12.0 when {@link AdditionalEquations} is removed
  26.  */
  27. @Deprecated
  28. public class FieldAdditionalEquationsAdapter<T extends CalculusFieldElement<T>> implements FieldAdditionalDerivativesProvider<T> {

  29.     /** Wrapped equations. */
  30.     private final FieldAdditionalEquations<T> equations;

  31.     /** Supplier for reference state. */
  32.     private final Supplier<FieldSpacecraftState<T>> stateSupplier;

  33.     /** Dimension. */
  34.     private int dimension;

  35.     /** Simple constructor.
  36.      * @param equations wrapped equations
  37.      * @param stateSupplier supplier for reference state
  38.      */
  39.     public FieldAdditionalEquationsAdapter(final FieldAdditionalEquations<T> equations, final Supplier<FieldSpacecraftState<T>> stateSupplier) {
  40.         this.equations     = equations;
  41.         this.stateSupplier = stateSupplier;
  42.         this.dimension     = -1;
  43.     }

  44.     /** {@inheritDoc} */
  45.     @Override
  46.     public String getName() {
  47.         return equations.getName();
  48.     }

  49.     /** {@inheritDoc} */
  50.     @Override
  51.     public int getDimension() {
  52.         if (dimension < 0) {
  53.             // retrieve the dimension the first time we need it
  54.             dimension = stateSupplier.get().getAdditionalState(getName()).length;
  55.         }
  56.         return dimension;
  57.     }

  58.     /** {@inheritDoc} */
  59.     @Override
  60.     public boolean yield(final FieldSpacecraftState<T> state) {
  61.         return false;
  62.     }

  63.     /** {@inheritDoc} */
  64.     @Override
  65.     public void init(final FieldSpacecraftState<T> initialState, final FieldAbsoluteDate<T> target) {
  66.         equations.init(initialState, target);
  67.     }

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public T[] derivatives(final FieldSpacecraftState<T> state) {
  71.         final T[] pDot = MathArrays.buildArray(state.getDate().getField(), getDimension());
  72.         equations.computeDerivatives(state, pDot);
  73.         return pDot;
  74.     }

  75. }