1   /* Copyright 2002-2015 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;
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.Rotation;
23  import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
24  import org.orekit.errors.OrekitException;
25  import org.orekit.errors.OrekitMessages;
26  import org.orekit.forces.drag.DragSensitive;
27  import org.orekit.forces.radiation.RadiationSensitive;
28  import org.orekit.frames.Frame;
29  import org.orekit.time.AbsoluteDate;
30  
31  /** This class represents the features of a simplified spacecraft.
32   * <p>The model of this spacecraft is a simple spherical model, this
33   * means that all coefficients are constant and do not depend of
34   * the direction.</p>
35   * <p>Instances of this class are guaranteed to be immutable.</p>
36   *
37   * @see BoxAndSolarArraySpacecraft
38   * @author &Eacute;douard Delente
39   * @author Fabien Maussion
40   * @author Pascal Parraud
41   */
42  public class SphericalSpacecraft implements RadiationSensitive, DragSensitive {
43  
44      /** Cross section (m²). */
45      private final double crossSection;
46  
47      /** Drag coefficient. */
48      private double dragCoeff;
49  
50      /** Absorption coefficient. */
51      private double absorptionCoeff;
52  
53      /** Specular reflection coefficient. */
54      private double specularReflectionCoeff;
55  
56      /** Simple constructor.
57       * @param crossSection Surface (m²)
58       * @param dragCoeff drag coefficient (used only for drag)
59       * @param absorptionCoeff absorption coefficient between 0.0 an 1.0
60       * (used only for radiation pressure)
61       * @param reflectionCoeff specular reflection coefficient between 0.0 an 1.0
62       * (used only for radiation pressure)
63       */
64      public SphericalSpacecraft(final double crossSection, final double dragCoeff,
65                                 final double absorptionCoeff, final double reflectionCoeff) {
66          this.crossSection            = crossSection;
67          this.dragCoeff               = dragCoeff;
68          this.absorptionCoeff         = absorptionCoeff;
69          this.specularReflectionCoeff = reflectionCoeff;
70      }
71  
72      /** {@inheritDoc} */
73      public Vector3D dragAcceleration(final AbsoluteDate date, final Frame frame, final Vector3D position,
74                                       final Rotation rotation, final double mass,
75                                       final double density, final Vector3D relativeVelocity) {
76          return new Vector3D(relativeVelocity.getNorm() * density * dragCoeff * crossSection / (2 * mass),
77                              relativeVelocity);
78      }
79  
80      /** {@inheritDoc} */
81      public FieldVector3D<DerivativeStructure> dragAcceleration(final AbsoluteDate date, final Frame frame, final FieldVector3D<DerivativeStructure> position,
82                                                                 final FieldRotation<DerivativeStructure> rotation, final DerivativeStructure mass,
83                                                                 final double density, final FieldVector3D<DerivativeStructure> relativeVelocity) {
84          return new FieldVector3D<DerivativeStructure>(relativeVelocity.getNorm().multiply(density * dragCoeff * crossSection / 2).divide(mass),
85                                relativeVelocity);
86      }
87  
88      /** {@inheritDoc} */
89      public FieldVector3D<DerivativeStructure> dragAcceleration(final AbsoluteDate date, final Frame frame, final Vector3D position,
90                                                                 final Rotation rotation, final double mass,
91                                                                 final  double density, final Vector3D relativeVelocity,
92                                                                 final String paramName)
93          throws OrekitException {
94  
95          if (!DRAG_COEFFICIENT.equals(paramName)) {
96              throw new OrekitException(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, paramName, DRAG_COEFFICIENT);
97          }
98  
99          final DerivativeStructure dragCoeffDS = new DerivativeStructure(1, 1, 0, dragCoeff);
100 
101         return new FieldVector3D<DerivativeStructure>(dragCoeffDS.multiply(relativeVelocity.getNorm() * density * crossSection / (2 * mass)),
102                               relativeVelocity);
103 
104     }
105 
106     /** {@inheritDoc} */
107     public Vector3D radiationPressureAcceleration(final AbsoluteDate date, final Frame frame, final Vector3D position,
108                                                   final Rotation rotation, final double mass, final Vector3D flux) {
109         final double kP = crossSection * (1 + 4 * (1.0 - absorptionCoeff) * (1.0 - specularReflectionCoeff) / 9.0);
110         return new Vector3D(kP / mass, flux);
111     }
112 
113     /** {@inheritDoc} */
114     public FieldVector3D<DerivativeStructure> radiationPressureAcceleration(final AbsoluteDate date, final Frame frame, final FieldVector3D<DerivativeStructure> position,
115                                                     final FieldRotation<DerivativeStructure> rotation, final DerivativeStructure mass,
116                                                     final FieldVector3D<DerivativeStructure> flux) {
117         final double kP = crossSection * (1 + 4 * (1.0 - absorptionCoeff) * (1.0 - specularReflectionCoeff) / 9.0);
118         return new FieldVector3D<DerivativeStructure>(mass.reciprocal().multiply(kP), flux);
119     }
120 
121     /** {@inheritDoc} */
122     public FieldVector3D<DerivativeStructure> radiationPressureAcceleration(final AbsoluteDate date, final Frame frame, final Vector3D position,
123                                                     final Rotation rotation, final double mass,
124                                                     final Vector3D flux, final String paramName)
125         throws OrekitException {
126 
127         final DerivativeStructure absorptionCoeffDS;
128         final DerivativeStructure specularReflectionCoeffDS;
129         if (ABSORPTION_COEFFICIENT.equals(paramName)) {
130             absorptionCoeffDS         = new DerivativeStructure(1, 1, 0, absorptionCoeff);
131             specularReflectionCoeffDS = new DerivativeStructure(1, 1,    specularReflectionCoeff);
132         } else if (REFLECTION_COEFFICIENT.equals(paramName)) {
133             absorptionCoeffDS         = new DerivativeStructure(1, 1,    absorptionCoeff);
134             specularReflectionCoeffDS = new DerivativeStructure(1, 1, 0, specularReflectionCoeff);
135         } else {
136             throw new OrekitException(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, paramName,
137                                       ABSORPTION_COEFFICIENT + ", " + REFLECTION_COEFFICIENT);
138         }
139 
140         final DerivativeStructure kP =
141                 absorptionCoeffDS.subtract(1).multiply(specularReflectionCoeffDS.subtract(1)).multiply(4.0 / 9.0).add(1).multiply(crossSection);
142         return new FieldVector3D<DerivativeStructure>(kP.divide(mass), flux);
143 
144     }
145 
146     /** {@inheritDoc} */
147     public void setDragCoefficient(final double value) {
148         dragCoeff = value;
149     }
150 
151     /** {@inheritDoc} */
152     public double getDragCoefficient() {
153         return dragCoeff;
154     }
155 
156     /** {@inheritDoc} */
157     public void setAbsorptionCoefficient(final double value) {
158         absorptionCoeff = value;
159     }
160 
161     /** {@inheritDoc} */
162     public double getAbsorptionCoefficient() {
163         return absorptionCoeff;
164     }
165 
166     /** {@inheritDoc} */
167     public void setReflectionCoefficient(final double value) {
168         specularReflectionCoeff = value;
169     }
170 
171     /** {@inheritDoc} */
172     public double getReflectionCoefficient() {
173         return specularReflectionCoeff;
174     }
175 
176 }