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.stream.Stream;

  19. import org.hipparchus.Field;
  20. import org.hipparchus.RealFieldElement;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.hipparchus.util.FastMath;
  24. import org.orekit.forces.AbstractForceModel;
  25. import org.orekit.propagation.FieldSpacecraftState;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.propagation.events.EventDetector;
  28. import org.orekit.propagation.events.FieldEventDetector;
  29. import org.orekit.propagation.numerical.FieldTimeDerivativesEquations;
  30. import org.orekit.propagation.numerical.TimeDerivativesEquations;
  31. import org.orekit.utils.ParameterDriver;

  32. /** Force model for Newtonian central body attraction.
  33.  * @author Luc Maisonobe
  34.  */
  35. public class NewtonianAttraction extends AbstractForceModel {

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

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

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

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

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

  60.     /** Get the central attraction coefficient μ.
  61.      * @return mu central attraction coefficient (m³/s²)
  62.      */
  63.     public double getMu() {
  64.         return gmParameterDriver.getValue();
  65.     }

  66.     /** Get the central attraction coefficient μ.
  67.      * @param <T> the type of the field element
  68.      * @param field field to which the state belongs
  69.      * @return mu central attraction coefficient (m³/s²)
  70.      */
  71.     public <T extends RealFieldElement<T>> T getMu(final Field<T> field) {
  72.         final T zero = field.getZero();
  73.         return zero.add(gmParameterDriver.getValue());
  74.     }

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     public void addContribution(final SpacecraftState s, final TimeDerivativesEquations adder) {
  78.         adder.addKeplerContribution(getMu());
  79.     }

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

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

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

  102.     /** {@inheritDoc} */
  103.     @Override
  104.     public Stream<EventDetector> getEventsDetectors() {
  105.         return Stream.empty();
  106.     }

  107.     /** {@inheritDoc} */
  108.     @Override
  109.     public <T extends RealFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(final Field<T> field) {
  110.         return Stream.empty();
  111.     }

  112.     /** {@inheritDoc} */
  113.     @Override
  114.     public ParameterDriver[] getParametersDrivers() {
  115.         return new ParameterDriver[] {
  116.             gmParameterDriver
  117.         };
  118.     }

  119. }