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.gravity;
18
19 import org.hipparchus.CalculusFieldElement;
20 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21 import org.hipparchus.geometry.euclidean.threed.Vector3D;
22 import org.hipparchus.util.FastMath;
23 import org.orekit.bodies.CelestialBodies;
24 import org.orekit.bodies.CelestialBody;
25 import org.orekit.propagation.FieldSpacecraftState;
26 import org.orekit.propagation.SpacecraftState;
27 import org.orekit.utils.ExtendedPositionProvider;
28
29 /** Body attraction force model computed as absolute acceleration towards a body.
30 * <p>
31 * This force model represents the same physical principles as {@link NewtonianAttraction},
32 * but has several major differences:
33 * </p>
34 * <ul>
35 * <li>the attracting body can be <em>away</em> from the integration frame center,</li>
36 * <li>several instances of this force model can be added when several bodies are involved,</li>
37 * <li>this force model is <em>never</em> automatically added by the numerical propagator</li>
38 * </ul>
39 * <p>
40 * The possibility for the attracting body to be away from the frame center allows to use this force
41 * model when integrating for example an interplanetary trajectory propagated in an Earth centered
42 * frame (in which case an instance of {@link org.orekit.forces.inertia.InertialForces} must also be
43 * added to take into account the coupling effect of relative frames motion).
44 * </p>
45 * <p>
46 * The possibility to add several instances allows to use this in interplanetary trajectories or
47 * in trajectories about Lagrangian points
48 * </p>
49 * <p>
50 * The fact this force model is <em>never</em> automatically added by the numerical propagator differs
51 * from {@link NewtonianAttraction} as {@link NewtonianAttraction} may be added automatically when
52 * propagating a trajectory represented as an {@link org.orekit.orbits.Orbit}, which must always refer
53 * to a central body, if user did not add the {@link NewtonianAttraction} or set the central attraction
54 * coefficient by himself.
55 * </p>
56 * @see org.orekit.forces.inertia.InertialForces
57 * @author Luc Maisonobe
58 * @author Julio Hernanz
59 */
60 public class SingleBodyAbsoluteAttraction extends AbstractBodyAttraction {
61
62 /** Simple constructor.
63 * @param positionProvider extended position provider for the body to consider
64 * @param name name of the body
65 * @param mu body gravitational constant
66 * @since 13.0
67 */
68 public SingleBodyAbsoluteAttraction(final ExtendedPositionProvider positionProvider,
69 final String name, final double mu) {
70 super(positionProvider, name, mu);
71 }
72
73 /** Constructor.
74 * @param body the body to consider
75 * (ex: {@link CelestialBodies#getSun()} or
76 * {@link CelestialBodies#getMoon()})
77 */
78 public SingleBodyAbsoluteAttraction(final CelestialBody body) {
79 this(body, body.getName(), body.getGM());
80 }
81
82 /** {@inheritDoc} */
83 @Override
84 public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {
85
86 // compute bodies separation vectors and squared norm
87 final Vector3D bodyPosition = getBodyPosition(s.getDate(), s.getFrame());
88 final Vector3D satToBody = bodyPosition.subtract(s.getPosition());
89 final double r2Sat = satToBody.getNormSq();
90
91 // compute absolute acceleration
92 return new Vector3D(parameters[0] / (r2Sat * FastMath.sqrt(r2Sat)), satToBody);
93
94 }
95
96 /** {@inheritDoc} */
97 @Override
98 public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
99 final T[] parameters) {
100 // compute bodies separation vectors and squared norm
101 final FieldVector3D<T> centralToBody = getBodyPosition(s.getDate(), s.getFrame());
102 final FieldVector3D<T> satToBody = centralToBody.subtract(s.getPosition());
103 final T r2Sat = satToBody.getNormSq();
104
105 // compute absolute acceleration
106 return new FieldVector3D<>(parameters[0].divide(r2Sat.multiply(r2Sat.sqrt())), satToBody);
107
108 }
109
110 }