NewtonianAttraction.java

  1. /* Copyright 2010-2011 Centre National d'Études Spatiales
  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. import java.util.Collections;
  19. import java.util.List;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.Field;
  22. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.hipparchus.util.FastMath;
  25. import org.orekit.forces.ForceModel;
  26. import org.orekit.propagation.FieldSpacecraftState;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.propagation.numerical.FieldTimeDerivativesEquations;
  29. import org.orekit.propagation.numerical.TimeDerivativesEquations;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.time.FieldAbsoluteDate;
  32. import org.orekit.utils.ParameterDriver;

  33. /** Force model for Newtonian central body attraction.
  34.  * @author Luc Maisonobe
  35.  */
  36. public class NewtonianAttraction implements ForceModel {

  37.     /** Name of the single parameter of this model: the central attraction coefficient. */
  38.     public static final String CENTRAL_ATTRACTION_COEFFICIENT = "central attraction coefficient";

  39.     /** Central attraction scaling factor.
  40.      * <p>
  41.      * We use a power of 2 to avoid numeric noise introduction
  42.      * in the multiplications/divisions sequences.
  43.      * </p>
  44.      */
  45.     private static final double MU_SCALE = FastMath.scalb(1.0, 32);

  46.     /** Driver for gravitational parameter. */
  47.     private final ParameterDriver gmParameterDriver;

  48.    /** Simple constructor.
  49.      * @param mu central attraction coefficient (m^3/s^2)
  50.      */
  51.     public NewtonianAttraction(final double mu) {
  52.         gmParameterDriver = new ParameterDriver(NewtonianAttraction.CENTRAL_ATTRACTION_COEFFICIENT,
  53.                                                 mu, MU_SCALE,
  54.                                                 0.0, Double.POSITIVE_INFINITY);
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public boolean dependsOnPositionOnly() {
  59.         return true;
  60.     }

  61.     /** Get the central attraction coefficient μ.
  62.      * @param date date at which the mu value wants to be known
  63.      * @return mu central attraction coefficient (m³/s²)
  64.      */
  65.     public double getMu(final AbsoluteDate date) {
  66.         return gmParameterDriver.getValue(date);
  67.     }

  68.     /** Get the central attraction coefficient μ.
  69.      * @param <T> the type of the field element
  70.      * @param field field to which the state belongs
  71.      * @param date date at which the mu value wants to be known
  72.      * @return mu central attraction coefficient (m³/s²)
  73.      */
  74.     public <T extends CalculusFieldElement<T>> T getMu(final Field<T> field, final FieldAbsoluteDate<T> date) {
  75.         final T zero = field.getZero();
  76.         return zero.newInstance(gmParameterDriver.getValue(date.toAbsoluteDate()));
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     public void addContribution(final SpacecraftState s, final TimeDerivativesEquations adder) {
  81.         adder.addKeplerContribution(getMu(s.getDate()));
  82.     }

  83.     /** {@inheritDoc} */
  84.     @Override
  85.     public <T extends CalculusFieldElement<T>> void addContribution(final FieldSpacecraftState<T> s,
  86.                                                                 final FieldTimeDerivativesEquations<T> adder) {
  87.         final Field<T> field = s.getDate().getField();
  88.         adder.addKeplerContribution(getMu(field, s.getDate()));
  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {
  93.         final double mu = parameters[0];
  94.         final double r2 = s.getPosition().getNormSq();
  95.         return new Vector3D(-mu / (FastMath.sqrt(r2) * r2), s.getPosition());
  96.     }

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  100.                                                                          final T[] parameters) {
  101.         final T mu = parameters[0];
  102.         final T r2 = s.getPosition().getNormSq();
  103.         return new FieldVector3D<>(r2.sqrt().multiply(r2).reciprocal().multiply(mu).negate(), s.getPosition());
  104.     }

  105.     /** {@inheritDoc} */
  106.     @Override
  107.     public List<ParameterDriver> getParametersDrivers() {
  108.         return Collections.singletonList(gmParameterDriver);
  109.     }

  110. }