ThirdBodyAttraction.java

  1. /* Copyright 2002-2013 CS Systèmes d'Information
  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 org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
  19. import org.apache.commons.math3.geometry.euclidean.threed.FieldRotation;
  20. import org.apache.commons.math3.geometry.euclidean.threed.FieldVector3D;
  21. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  22. import org.apache.commons.math3.ode.AbstractParameterizable;
  23. import org.apache.commons.math3.util.FastMath;
  24. import org.orekit.bodies.CelestialBody;
  25. import org.orekit.errors.OrekitException;
  26. import org.orekit.forces.ForceModel;
  27. import org.orekit.frames.Frame;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.propagation.events.EventDetector;
  30. import org.orekit.propagation.numerical.TimeDerivativesEquations;
  31. import org.orekit.time.AbsoluteDate;

  32. /** Third body attraction force model.
  33.  *
  34.  * @author Fabien Maussion
  35.  * @author Véronique Pommier-Maurussane
  36.  */
  37. public class ThirdBodyAttraction extends AbstractParameterizable implements ForceModel {

  38.     /** Suffix for parameter name for attraction coefficient enabling jacobian processing. */
  39.     public static final String ATTRACTION_COEFFICIENT_SUFFIX = " attraction coefficient";

  40.     /** The body to consider. */
  41.     private final CelestialBody body;

  42.     /** Local value for body attraction coefficient. */
  43.     private double gm;

  44.     /** Simple constructor.
  45.      * @param body the third body to consider
  46.      * (ex: {@link org.orekit.bodies.CelestialBodyFactory#getSun()} or
  47.      * {@link org.orekit.bodies.CelestialBodyFactory#getMoon()})
  48.      */
  49.     public ThirdBodyAttraction(final CelestialBody body) {
  50.         super(body.getName() + ATTRACTION_COEFFICIENT_SUFFIX);
  51.         this.body = body;
  52.         this.gm   = body.getGM();
  53.     }

  54.     /** {@inheritDoc} */
  55.     public void addContribution(final SpacecraftState s, final TimeDerivativesEquations adder)
  56.         throws OrekitException {

  57.         // compute bodies separation vectors and squared norm
  58.         final Vector3D centralToBody = body.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  59.         final double r2Central       = Vector3D.dotProduct(centralToBody, centralToBody);
  60.         final Vector3D satToBody     = centralToBody.subtract(s.getPVCoordinates().getPosition());
  61.         final double r2Sat           = Vector3D.dotProduct(satToBody, satToBody);

  62.         // compute relative acceleration
  63.         final Vector3D gamma =
  64.             new Vector3D(gm * FastMath.pow(r2Sat, -1.5), satToBody,
  65.                         -gm * FastMath.pow(r2Central, -1.5), centralToBody);

  66.         // add contribution to the ODE second member
  67.         adder.addXYZAcceleration(gamma.getX(), gamma.getY(), gamma.getZ());

  68.     }

  69.     /** {@inheritDoc} */
  70.     public FieldVector3D<DerivativeStructure> accelerationDerivatives(final AbsoluteDate date, final Frame frame,
  71.                                                                       final FieldVector3D<DerivativeStructure> position,
  72.                                                                       final FieldVector3D<DerivativeStructure> velocity,
  73.                                                                       final FieldRotation<DerivativeStructure> rotation,
  74.                                                                       final DerivativeStructure mass)
  75.         throws OrekitException {

  76.         // compute bodies separation vectors and squared norm
  77.         final Vector3D centralToBody    = body.getPVCoordinates(date, frame).getPosition();
  78.         final double r2Central          = Vector3D.dotProduct(centralToBody, centralToBody);
  79.         final FieldVector3D<DerivativeStructure> satToBody = position.subtract(centralToBody).negate();
  80.         final DerivativeStructure r2Sat = satToBody.getNormSq();

  81.         // compute relative acceleration
  82.         final FieldVector3D<DerivativeStructure> satAcc   = new FieldVector3D<DerivativeStructure>(r2Sat.pow(-1.5).multiply(gm), satToBody);
  83.         final Vector3D centralAcc = new Vector3D(gm * FastMath.pow(r2Central, -1.5), centralToBody);
  84.         return satAcc.subtract(centralAcc);

  85.     }

  86.     /** {@inheritDoc} */
  87.     public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s, final String paramName)
  88.         throws OrekitException {

  89.         complainIfNotSupported(paramName);

  90.         // compute bodies separation vectors and squared norm
  91.         final Vector3D centralToBody = body.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  92.         final double r2Central       = Vector3D.dotProduct(centralToBody, centralToBody);
  93.         final Vector3D satToBody     = centralToBody.subtract(s.getPVCoordinates().getPosition());
  94.         final double r2Sat           = Vector3D.dotProduct(satToBody, satToBody);

  95.         final DerivativeStructure gmds = new DerivativeStructure(1, 1, 0, gm);

  96.         // compute relative acceleration
  97.         return new FieldVector3D<DerivativeStructure>(gmds.multiply(FastMath.pow(r2Sat, -1.5)), satToBody,
  98.                               gmds.multiply(-FastMath.pow(r2Central, -1.5)), centralToBody);

  99.     }

  100.     /** {@inheritDoc} */
  101.     public EventDetector[] getEventsDetectors() {
  102.         return new EventDetector[0];
  103.     }

  104.     /** {@inheritDoc} */
  105.     public double getParameter(final String name)
  106.         throws IllegalArgumentException {
  107.         complainIfNotSupported(name);
  108.         return gm;
  109.     }

  110.     /** {@inheritDoc} */
  111.     public void setParameter(final String name, final double value)
  112.         throws IllegalArgumentException {
  113.         complainIfNotSupported(name);
  114.         gm = value;
  115.     }

  116. }