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  
19  import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
20  import org.apache.commons.math3.geometry.euclidean.threed.FieldRotation;
21  import org.apache.commons.math3.geometry.euclidean.threed.FieldVector3D;
22  import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
23  import org.apache.commons.math3.ode.AbstractParameterizable;
24  import org.apache.commons.math3.util.FastMath;
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  
33  /** Force model for Newtonian central body attraction.
34   * @author Luc Maisonobe
35   */
36  public class NewtonianAttraction extends AbstractParameterizable implements ForceModel {
37  
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  
41      /** Central attraction coefficient (m^3/s^2). */
42      private double mu;
43  
44     /** Simple constructor.
45       * @param mu central attraction coefficient (m^3/s^2)
46       */
47      public NewtonianAttraction(final double mu) {
48          super(CENTRAL_ATTRACTION_COEFFICIENT);
49          this.mu = mu;
50      }
51  
52      /** {@inheritDoc} */
53      public FieldVector3D<DerivativeStructure> accelerationDerivatives(final AbsoluteDate date, final Frame frame,
54                                                                        final FieldVector3D<DerivativeStructure> position, final FieldVector3D<DerivativeStructure> velocity,
55                                                                        final FieldRotation<DerivativeStructure> rotation, final DerivativeStructure mass)
56          throws OrekitException {
57  
58          final DerivativeStructure r2 = position.getNormSq();
59          return new FieldVector3D<DerivativeStructure>(r2.sqrt().multiply(r2).reciprocal().multiply(-mu), position);
60  
61      }
62  
63      /** {@inheritDoc} */
64      public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s, final String paramName)
65          throws OrekitException {
66  
67          complainIfNotSupported(paramName);
68  
69          final Vector3D            position = s.getPVCoordinates().getPosition();
70          final double              r2       = position.getNormSq();
71          final DerivativeStructure muds     = new DerivativeStructure(1, 1, 0, mu);
72          return new FieldVector3D<DerivativeStructure>(muds.divide(-r2 * FastMath.sqrt(r2)), position);
73  
74      }
75  
76      /** Get the central attraction coefficient &mu;.
77       * @return mu central attraction coefficient (m<sup>3</sup>/s<sup>2</sup>)
78       */
79      public double getMu() {
80          return mu;
81      }
82  
83      /** {@inheritDoc} */
84      public double getParameter(final String name)
85          throws IllegalArgumentException {
86          complainIfNotSupported(name);
87          return mu;
88      }
89  
90      /** {@inheritDoc} */
91      public void setParameter(final String name, final double value)
92          throws IllegalArgumentException {
93          complainIfNotSupported(name);
94          this.mu = value;
95      }
96  
97      /** {@inheritDoc} */
98      public void addContribution(final SpacecraftState s, final TimeDerivativesEquations adder)
99          throws OrekitException {
100         adder.addKeplerContribution(mu);
101     }
102 
103     /** {@inheritDoc} */
104     public EventDetector[] getEventsDetectors() {
105         return new EventDetector[0];
106     }
107 
108 }
109