1   /* Copyright 2002-2025 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.forces.drag;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.hipparchus.CalculusFieldElement;
24  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
25  import org.hipparchus.geometry.euclidean.threed.Vector3D;
26  import org.hipparchus.util.FastMath;
27  import org.orekit.propagation.FieldSpacecraftState;
28  import org.orekit.propagation.SpacecraftState;
29  import org.orekit.utils.ParameterDriver;
30  
31  /** This class models isotropic drag effects.
32   * <p>The model of this spacecraft is a simple spherical model, this
33   * means that all coefficients are constant and do not depend on
34   * the direction.</p>
35   *
36   * @see org.orekit.forces.BoxAndSolarArraySpacecraft
37   * @see org.orekit.forces.radiation.IsotropicRadiationCNES95Convention
38   * @author Luc Maisonobe
39   * @since 7.1
40   */
41  public class IsotropicDrag implements DragSensitive {
42  
43      /** Parameters scaling factor.
44       * <p>
45       * We use a power of 2 to avoid numeric noise introduction
46       * in the multiplications/divisions sequences.
47       * </p>
48       */
49      private final double SCALE = FastMath.scalb(1.0, -3);
50  
51      /** Drivers for drag coefficient parameter. */
52      private final List<ParameterDriver> dragParametersDrivers;
53  
54      /** Cross section (m²). */
55      private final double crossSection;
56  
57      /** Constructor with drag coefficient min/max set to ±∞.
58       * @param crossSection Surface (m²)
59       * @param dragCoeff drag coefficient
60       */
61      public IsotropicDrag(final double crossSection, final double dragCoeff) {
62          this(crossSection, dragCoeff, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
63      }
64  
65      /** Constructor with drag coefficient min/max set by user.
66       * @param crossSection Surface (m²)
67       * @param dragCoeff drag coefficient
68       * @param dragCoeffMin Minimum value of drag coefficient
69       * @param dragCoeffMax Maximum value of drag coefficient
70       */
71      public IsotropicDrag(final double crossSection, final double dragCoeff,
72                           final double dragCoeffMin, final double dragCoeffMax) {
73          // in some corner cases (unknown spacecraft, fuel leaks, active piloting ...)
74          // the single coefficient may be arbitrary, and even negative
75          // the DRAG_COEFFICIENT parameter should be sufficient, but GLOBAL_DRAG_FACTOR
76          // was added as of 12.0 for consistency with BoxAndSolarArraySpacecraft
77          // that only has a global multiplication factor, hence allowing this name
78          // to be used for both models
79          this.dragParametersDrivers = new ArrayList<>(2);
80          dragParametersDrivers.add(new ParameterDriver(DragSensitive.GLOBAL_DRAG_FACTOR,
81                                                        1.0, SCALE,
82                                                        0.0, Double.POSITIVE_INFINITY));
83          dragParametersDrivers.add(new ParameterDriver(DragSensitive.DRAG_COEFFICIENT,
84                                                        dragCoeff, SCALE,
85                                                        dragCoeffMin, dragCoeffMax));
86          this.crossSection = crossSection;
87      }
88  
89      /** {@inheritDoc} */
90      @Override
91      public List<ParameterDriver> getDragParametersDrivers() {
92          return Collections.unmodifiableList(dragParametersDrivers);
93      }
94  
95      /** {@inheritDoc} */
96      @Override
97      public Vector3D dragAcceleration(final SpacecraftState state,
98                                       final double density, final Vector3D relativeVelocity,
99                                       final double[] parameters) {
100         final double dragCoeff = parameters[0] * parameters[1];
101         return new Vector3D(relativeVelocity.getNorm() * density * dragCoeff * crossSection / (2 * state.getMass()),
102                             relativeVelocity);
103     }
104 
105     /** {@inheritDoc} */
106     @Override
107     public <T extends CalculusFieldElement<T>> FieldVector3D<T>
108         dragAcceleration(final FieldSpacecraftState<T> state, final T density,
109                          final FieldVector3D<T> relativeVelocity,
110                          final T[] parameters) {
111         final T dragCoeff = parameters[0].multiply(parameters[1]);
112         return new FieldVector3D<>(relativeVelocity.getNorm().
113                                    multiply(density.multiply(dragCoeff).multiply(crossSection / 2)).
114                                    divide(state.getMass()),
115                                    relativeVelocity);
116     }
117 }