AbstractVariableStepIntegratorBuilder.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.propagation.conversion;

  18. import org.hipparchus.ode.nonstiff.AdaptiveStepsizeIntegrator;
  19. import org.orekit.orbits.Orbit;
  20. import org.orekit.orbits.OrbitType;
  21. import org.orekit.orbits.PositionAngleType;
  22. import org.orekit.propagation.ToleranceProvider;
  23. import org.orekit.utils.AbsolutePVCoordinates;

  24. /**
  25.  * Abstract class for integrator builder using variable step size.
  26.  *
  27.  * @author Romain Serra
  28.  * @since 12.2
  29.  */
  30. public abstract class AbstractVariableStepIntegratorBuilder<T extends AdaptiveStepsizeIntegrator> extends AbstractIntegratorBuilder<T> {

  31.     /** Minimum step size (s). */
  32.     private final double minStep;

  33.     /** Maximum step size (s). */
  34.     private final double maxStep;

  35.     /** Integration tolerance provider. */
  36.     private final ToleranceProvider toleranceProvider;

  37.     /**
  38.      * Constructor.
  39.      *
  40.      * @param minStep minimum step size (s)
  41.      * @param maxStep maximum step size (s)
  42.      * @param toleranceProvider integration tolerance provider
  43.      * @since 13.0
  44.      */
  45.     protected AbstractVariableStepIntegratorBuilder(final double minStep, final double maxStep,
  46.                                                     final ToleranceProvider toleranceProvider) {
  47.         this.minStep = minStep;
  48.         this.maxStep = maxStep;
  49.         this.toleranceProvider = toleranceProvider;
  50.     }

  51.     /**
  52.      * Getter for the maximum step.
  53.      * @return max stepsize
  54.      * @since 13.0
  55.      */
  56.     public double getMaxStep() {
  57.         return maxStep;
  58.     }

  59.     /**
  60.      * Getter for the minimum step.
  61.      * @return min stepsize
  62.      * @since 13.0
  63.      */
  64.     public double getMinStep() {
  65.         return minStep;
  66.     }

  67.     /**
  68.      * Computes tolerances.
  69.      * @param orbit initial orbit
  70.      * @param orbitType orbit type for integration
  71.      * @return integrator tolerances
  72.      */
  73.     protected double[][] getTolerances(final Orbit orbit, final OrbitType orbitType) {
  74.         return toleranceProvider.getTolerances(orbit, orbitType, PositionAngleType.MEAN);
  75.     }

  76.     /**
  77.      * Computes tolerances.
  78.      * @param absolutePVCoordinates position-velocity vector
  79.      * @return integrator tolerances
  80.      * @since 13.0
  81.      */
  82.     protected double[][] getTolerances(final AbsolutePVCoordinates absolutePVCoordinates) {
  83.         return toleranceProvider.getTolerances(absolutePVCoordinates);
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     public T buildIntegrator(final Orbit orbit, final OrbitType orbitType,
  88.                                               final PositionAngleType angleType) {
  89.         return buildIntegrator(getTolerances(orbit, orbitType));
  90.     }

  91.     /** {@inheritDoc} */
  92.     @Override
  93.     public T buildIntegrator(final AbsolutePVCoordinates absolutePVCoordinates) {
  94.         return buildIntegrator(getTolerances(absolutePVCoordinates));
  95.     }

  96.     /**
  97.      * Builds an integrator from input absolute and relative tolerances.
  98.      * @param tolerances tolerance array
  99.      * @return integrator
  100.      * @since 13.0
  101.      */
  102.     protected abstract T buildIntegrator(double[][] tolerances);

  103.     /**
  104.      * Get a default tolerance provider.
  105.      * @param dP expected position error (m)
  106.      * @return tolerance provider
  107.      * @since 13.0
  108.      */
  109.     protected static ToleranceProvider getDefaultToleranceProvider(final double dP) {
  110.         return ToleranceProvider.getDefaultToleranceProvider(dP);
  111.     }
  112. }