AdditionalEquationsAdapter.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.orekit.propagation.SpacecraftState;
  20. import org.orekit.time.AbsoluteDate;


  21. /** Temporary adapter from {@link AdditionalEquations} to {@link AdditionalDerivativesProvider}.
  22.  * @since 11.1
  23.  * @deprecated must be removed in 12.0 when {@link AdditionalEquations} is removed
  24.  */
  25. @Deprecated
  26. public class AdditionalEquationsAdapter implements AdditionalDerivativesProvider {

  27.     /** Wrapped equations. */
  28.     private final AdditionalEquations equations;

  29.     /** Supplier for reference state. */
  30.     private final Supplier<SpacecraftState> stateSupplier;

  31.     /** Dimension. */
  32.     private int dimension;

  33.     /** Simple constructor.
  34.      * @param equations wrapped equations
  35.      * @param stateSupplier supplier for reference state
  36.      */
  37.     public AdditionalEquationsAdapter(final AdditionalEquations equations, final Supplier<SpacecraftState> stateSupplier) {
  38.         this.equations     = equations;
  39.         this.stateSupplier = stateSupplier;
  40.         this.dimension     = -1;
  41.     }

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

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

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public boolean yield(final SpacecraftState state) {
  59.         return false;
  60.     }

  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public void init(final SpacecraftState initialState, final AbsoluteDate target) {
  64.         equations.init(initialState, target);
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     @Deprecated
  69.     public double[] derivatives(final SpacecraftState state) {
  70.         return combinedDerivatives(state).getAdditionalDerivatives();
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public CombinedDerivatives combinedDerivatives(final SpacecraftState state) {
  75.         final double[] pDot    = new double[getDimension()];
  76.         final double[] mainDot = equations.computeDerivatives(state, pDot);
  77.         return new CombinedDerivatives(pDot, mainDot);
  78.     }

  79. }