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