1   /* Copyright 2022-2024 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.forces.gravity;
18  
19  import org.hipparchus.util.FastMath;
20  import org.orekit.bodies.CelestialBody;
21  import org.orekit.forces.ForceModel;
22  import org.orekit.utils.ParameterDriver;
23  
24  import java.util.Collections;
25  import java.util.List;
26  
27  /** Abstract class for body attraction force model.
28   *
29   * @author Romain Serra
30   */
31  public abstract class AbstractBodyAttraction implements ForceModel {
32  
33      /** Suffix for parameter name for attraction coefficient enabling Jacobian processing. */
34      public static final String ATTRACTION_COEFFICIENT_SUFFIX = " attraction coefficient";
35  
36      /** Central attraction scaling factor.
37       * <p>
38       * We use a power of 2 to avoid numeric noise introduction
39       * in the multiplications/divisions sequences.
40       * </p>
41       */
42      private static final double MU_SCALE = FastMath.scalb(1.0, 32);
43  
44      /** The body to consider. */
45      private final CelestialBody body;
46  
47      /** Drivers for body attraction coefficient. */
48      private final ParameterDriver gmParameterDriver;
49  
50      /** Simple constructor.
51       * @param body the third body to consider
52       */
53      protected AbstractBodyAttraction(final CelestialBody body) {
54          this.body = body;
55          this.gmParameterDriver = new ParameterDriver(body.getName() + ATTRACTION_COEFFICIENT_SUFFIX,
56                  body.getGM(), MU_SCALE, 0.0, Double.POSITIVE_INFINITY);
57      }
58  
59      /** Getter for the body's name.
60       * @return the body's name
61       */
62      public String getBodyName() {
63          return body.getName();
64      }
65  
66      /** Protected getter for the body.
67       * @return the third body considered
68       */
69      protected CelestialBody getBody() {
70          return body;
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public boolean dependsOnPositionOnly() {
76          return true;
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public List<ParameterDriver> getParametersDrivers() {
82          return Collections.singletonList(gmParameterDriver);
83      }
84  }