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  
19  import org.hipparchus.ode.nonstiff.AdaptiveStepsizeIntegrator;
20  import org.orekit.orbits.Orbit;
21  import org.orekit.orbits.OrbitType;
22  import org.orekit.orbits.PositionAngleType;
23  import org.orekit.propagation.ToleranceProvider;
24  import org.orekit.utils.AbsolutePVCoordinates;
25  
26  /**
27   * Abstract class for integrator builder using variable step size.
28   *
29   * @author Romain Serra
30   * @since 12.2
31   */
32  public abstract class AbstractVariableStepIntegratorBuilder<T extends AdaptiveStepsizeIntegrator> extends AbstractIntegratorBuilder<T> {
33  
34      /** Minimum step size (s). */
35      private final double minStep;
36  
37      /** Maximum step size (s). */
38      private final double maxStep;
39  
40      /** Integration tolerance provider. */
41      private final ToleranceProvider toleranceProvider;
42  
43      /**
44       * Constructor.
45       *
46       * @param minStep minimum step size (s)
47       * @param maxStep maximum step size (s)
48       * @param toleranceProvider integration tolerance provider
49       * @since 13.0
50       */
51      protected AbstractVariableStepIntegratorBuilder(final double minStep, final double maxStep,
52                                                      final ToleranceProvider toleranceProvider) {
53          this.minStep = minStep;
54          this.maxStep = maxStep;
55          this.toleranceProvider = toleranceProvider;
56      }
57  
58      /**
59       * Getter for the maximum step.
60       * @return max stepsize
61       * @since 13.0
62       */
63      public double getMaxStep() {
64          return maxStep;
65      }
66  
67      /**
68       * Getter for the minimum step.
69       * @return min stepsize
70       * @since 13.0
71       */
72      public double getMinStep() {
73          return minStep;
74      }
75  
76      /**
77       * Computes tolerances.
78       * @param orbit initial orbit
79       * @param orbitType orbit type for integration
80       * @return integrator tolerances
81       */
82      protected double[][] getTolerances(final Orbit orbit, final OrbitType orbitType) {
83          return toleranceProvider.getTolerances(orbit, orbitType, PositionAngleType.MEAN);
84      }
85  
86      /**
87       * Computes tolerances.
88       * @param absolutePVCoordinates position-velocity vector
89       * @return integrator tolerances
90       * @since 13.0
91       */
92      protected double[][] getTolerances(final AbsolutePVCoordinates absolutePVCoordinates) {
93          return toleranceProvider.getTolerances(absolutePVCoordinates);
94      }
95  
96      /** {@inheritDoc} */
97      @Override
98      public T buildIntegrator(final Orbit orbit, final OrbitType orbitType,
99                                                final PositionAngleType angleType) {
100         return buildIntegrator(getTolerances(orbit, orbitType));
101     }
102 
103     /** {@inheritDoc} */
104     @Override
105     public T buildIntegrator(final AbsolutePVCoordinates absolutePVCoordinates) {
106         return buildIntegrator(getTolerances(absolutePVCoordinates));
107     }
108 
109     /**
110      * Builds an integrator from input absolute and relative tolerances.
111      * @param tolerances tolerance array
112      * @return integrator
113      * @since 13.0
114      */
115     protected abstract T buildIntegrator(double[][] tolerances);
116 
117     /**
118      * Get a default tolerance provider.
119      * @param dP expected position error (m)
120      * @return tolerance provider
121      * @since 13.0
122      */
123     protected static ToleranceProvider getDefaultToleranceProvider(final double dP) {
124         return ToleranceProvider.getDefaultToleranceProvider(dP);
125     }
126 }