1 /* Copyright 2002-2020 CS GROUP 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.propagation.integration; 18 19 import org.orekit.attitudes.AttitudeProvider; 20 import org.orekit.frames.Frame; 21 import org.orekit.orbits.OrbitType; 22 import org.orekit.orbits.PositionAngle; 23 import org.orekit.propagation.PropagationType; 24 import org.orekit.propagation.SpacecraftState; 25 import org.orekit.time.AbsoluteDate; 26 27 /** This class maps between raw double elements and {@link SpacecraftState} instances. 28 * @author Luc Maisonobe 29 * @since 6.0 30 */ 31 public abstract class StateMapper { 32 33 /** Reference date. */ 34 private final AbsoluteDate referenceDate; 35 36 /** Propagation orbit type. */ 37 private final OrbitType orbitType; 38 39 /** Position angle type. */ 40 private final PositionAngle angleType; 41 42 /** Attitude provider. */ 43 private final AttitudeProvider attitudeProvider; 44 45 /** Central attraction coefficient. */ 46 private final double mu; 47 48 /** Inertial frame. */ 49 private final Frame frame; 50 51 /** Simple constructor. 52 * <p> 53 * The position parameter type is meaningful only if {@link 54 * #getOrbitType() propagation orbit type} 55 * support it. As an example, it is not meaningful for propagation 56 * in {@link OrbitType#CARTESIAN Cartesian} parameters. 57 * </p> 58 * @param referenceDate reference date 59 * @param mu central attraction coefficient (m³/s²) 60 * @param orbitType orbit type to use for mapping, null for 61 * propagating using {@link org.orekit.utils.AbsolutePVCoordinates AbsolutePVCoordinates} 62 * rather than {@link org.orekit.orbits Orbit} 63 * @param positionAngleType angle type to use for propagation 64 * @param attitudeProvider attitude provider 65 * @param frame inertial frame 66 */ 67 protected StateMapper(final AbsoluteDate referenceDate, final double mu, 68 final OrbitType orbitType, final PositionAngle positionAngleType, 69 final AttitudeProvider attitudeProvider, final Frame frame) { 70 this.referenceDate = referenceDate; 71 this.mu = mu; 72 this.orbitType = orbitType; 73 this.angleType = positionAngleType; 74 this.attitudeProvider = attitudeProvider; 75 this.frame = frame; 76 } 77 78 /** Get reference date. 79 * @return reference date 80 */ 81 public AbsoluteDate getReferenceDate() { 82 return referenceDate; 83 } 84 85 /** Get propagation parameter type. 86 * @return orbit type used for propagation 87 */ 88 public OrbitType getOrbitType() { 89 return orbitType; 90 } 91 92 /** Set position angle type. 93 */ 94 public void setPositionAngleType() { 95 } 96 97 /** Get propagation parameter type. 98 * @return angle type to use for propagation 99 */ 100 public PositionAngle getPositionAngleType() { 101 return angleType; 102 } 103 104 /** Get the central attraction coefficient μ. 105 * @return mu central attraction coefficient (m³/s²) 106 */ 107 public double getMu() { 108 return mu; 109 } 110 111 /** Get the inertial frame. 112 * @return inertial frame 113 */ 114 public Frame getFrame() { 115 return frame; 116 } 117 118 /** Get the attitude provider. 119 * @return attitude provider 120 */ 121 public AttitudeProvider getAttitudeProvider() { 122 return attitudeProvider; 123 } 124 125 /** Map the raw double time offset to a date. 126 * @param t date offset 127 * @return date 128 */ 129 public AbsoluteDate mapDoubleToDate(final double t) { 130 return referenceDate.shiftedBy(t); 131 } 132 133 /** 134 * Map the raw double time offset to a date. 135 * 136 * @param t date offset 137 * @param date The expected date. 138 * @return {@code date} if it is the same time as {@code t} to within the 139 * lower precision of the latter. Otherwise a new date is returned that 140 * corresponds to time {@code t}. 141 */ 142 public AbsoluteDate mapDoubleToDate(final double t, 143 final AbsoluteDate date) { 144 if (date.durationFrom(referenceDate) == t) { 145 return date; 146 } else { 147 return mapDoubleToDate(t); 148 } 149 } 150 151 /** Map a date to a raw double time offset. 152 * @param date date 153 * @return time offset 154 */ 155 public double mapDateToDouble(final AbsoluteDate date) { 156 return date.durationFrom(referenceDate); 157 } 158 159 /** Map the raw double components to a spacecraft state. 160 * @param t date offset 161 * @param y state components 162 * @param yDot time derivatives of the state components (null if unknown, in which case Keplerian motion is assumed) 163 * @param type type of the elements used to build the state (mean or osculating). 164 * @return spacecraft state 165 */ 166 public SpacecraftState mapArrayToState(final double t, final double[] y, final double[] yDot, final PropagationType type) { 167 return mapArrayToState(mapDoubleToDate(t), y, yDot, type); 168 } 169 170 /** Map the raw double components to a spacecraft state. 171 * @param date of the state components 172 * @param y state components 173 * @param yDot time derivatives of the state components (null if unknown, in which case Keplerian motion is assumed) 174 * @param type type of the elements used to build the state (mean or osculating). 175 * @return spacecraft state 176 */ 177 public abstract SpacecraftState mapArrayToState(AbsoluteDate date, double[] y, double[] yDot, PropagationType type); 178 179 /** Map a spacecraft state to raw double components. 180 * @param state state to map 181 * @param y placeholder where to put the components 182 * @param yDot placeholder where to put the components derivatives 183 */ 184 public abstract void mapStateToArray(SpacecraftState state, double[] y, double[] yDot); 185 186 }