NewtonianAttraction.java

  1. /* Copyright 2010-2011 Centre National d'Études Spatiales
  2.  * Licensed to CS Systèmes d'Information (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.errors.OrekitException;
  25. import org.orekit.errors.OrekitInternalError;
  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.         try {
  54.             gmParameterDriver = new ParameterDriver(NewtonianAttraction.CENTRAL_ATTRACTION_COEFFICIENT,
  55.                                                     mu, MU_SCALE,
  56.                                                     0.0, Double.POSITIVE_INFINITY);
  57.         } catch (OrekitException oe) {
  58.             // this should never occur as valueChanged above never throws an exception
  59.             throw new OrekitInternalError(oe);
  60.         }

  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public boolean dependsOnPositionOnly() {
  65.         return true;
  66.     }

  67.     /** Get the central attraction coefficient μ.
  68.      * @return mu central attraction coefficient (m³/s²)
  69.      */
  70.     public double getMu() {
  71.         return gmParameterDriver.getValue();
  72.     }

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

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     public <T extends RealFieldElement<T>> void addContribution(final FieldSpacecraftState<T> s,
  82.                                                                 final FieldTimeDerivativesEquations<T> adder)
  83.         throws OrekitException {
  84.         adder.addKeplerContribution(getMu());
  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters)
  89.         throws OrekitException {
  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.         throws OrekitException {
  99.         final T mu = parameters[0];
  100.         final T r2 = s.getPVCoordinates().getPosition().getNormSq();
  101.         return new FieldVector3D<>(r2.sqrt().multiply(r2).reciprocal().multiply(mu).negate(), s.getPVCoordinates().getPosition());
  102.     }

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

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

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

  120. }