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

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

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

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

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

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

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

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

  62.     /** Get the central attraction coefficient μ.
  63.      * @return mu central attraction coefficient (m³/s²)
  64.      */
  65.     public double getMu() {
  66.         return gmParameterDriver.getValue();
  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.      * @return mu central attraction coefficient (m³/s²)
  72.      */
  73.     public <T extends CalculusFieldElement<T>> T getMu(final Field<T> field) {
  74.         final T zero = field.getZero();
  75.         return zero.add(gmParameterDriver.getValue());
  76.     }

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

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

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

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

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

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

  114.     /** {@inheritDoc} */
  115.     @Override
  116.     public List<ParameterDriver> getParametersDrivers() {
  117.         return Collections.singletonList(gmParameterDriver);
  118.     }

  119. }