use of org.orekit.attitudes.FieldAttitude in project Orekit by CS-SI.
the class DSConverter method getState.
/**
* Get the state with the number of parameters consistent with force model.
* @param forceModel force model
* @return state with the number of parameters consistent with force model
*/
public FieldSpacecraftState<DerivativeStructure> getState(final ForceModel forceModel) {
// count the required number of parameters
int nbParams = 0;
for (final ParameterDriver driver : forceModel.getParametersDrivers()) {
if (driver.isSelected()) {
++nbParams;
}
}
// fill in intermediate slots
while (dsStates.size() < nbParams + 1) {
dsStates.add(null);
}
if (dsStates.get(nbParams) == null) {
// it is the first time we need this number of parameters
// we need to create the state
final DSFactory factory = new DSFactory(freeStateParameters + nbParams, 1);
final FieldSpacecraftState<DerivativeStructure> s0 = dsStates.get(0);
// orbit
final FieldPVCoordinates<DerivativeStructure> pv0 = s0.getPVCoordinates();
final FieldOrbit<DerivativeStructure> dsOrbit = new FieldCartesianOrbit<>(new TimeStampedFieldPVCoordinates<>(s0.getDate().toAbsoluteDate(), extend(pv0.getPosition(), factory), extend(pv0.getVelocity(), factory), extend(pv0.getAcceleration(), factory)), s0.getFrame(), s0.getMu());
// attitude
final FieldAngularCoordinates<DerivativeStructure> ac0 = s0.getAttitude().getOrientation();
final FieldAttitude<DerivativeStructure> dsAttitude = new FieldAttitude<>(s0.getAttitude().getReferenceFrame(), new TimeStampedFieldAngularCoordinates<>(dsOrbit.getDate(), extend(ac0.getRotation(), factory), extend(ac0.getRotationRate(), factory), extend(ac0.getRotationAcceleration(), factory)));
// mass
final DerivativeStructure dsM = extend(s0.getMass(), factory);
dsStates.set(nbParams, new FieldSpacecraftState<>(dsOrbit, dsAttitude, dsM));
}
return dsStates.get(nbParams);
}
use of org.orekit.attitudes.FieldAttitude in project Orekit by CS-SI.
the class FieldKeplerianPropagatorTest method doTestWrappedAttitudeException.
private <T extends RealFieldElement<T>> void doTestWrappedAttitudeException(Field<T> field) throws OrekitException {
T zero = field.getZero();
final FieldKeplerianOrbit<T> orbit = new FieldKeplerianOrbit<>(zero.add(7.8e6), zero.add(0.032), zero.add(0.4), zero.add(0.1), zero.add(0.2), zero.add(0.3), PositionAngle.TRUE, FramesFactory.getEME2000(), new FieldAbsoluteDate<>(field), 3.986004415e14);
FieldKeplerianPropagator<T> propagator = new FieldKeplerianPropagator<>(orbit, new AttitudeProvider() {
private static final long serialVersionUID = 1L;
public Attitude getAttitude(PVCoordinatesProvider pvProv, AbsoluteDate date, Frame frame) throws OrekitException {
throw new OrekitException((Throwable) null, new DummyLocalizable("dummy error"));
}
public <Q extends RealFieldElement<Q>> FieldAttitude<Q> getAttitude(FieldPVCoordinatesProvider<Q> pvProv, FieldAbsoluteDate<Q> date, Frame frame) throws OrekitException {
throw new OrekitException((Throwable) null, new DummyLocalizable("dummy error"));
}
});
propagator.propagate(orbit.getDate().shiftedBy(10.09));
}
use of org.orekit.attitudes.FieldAttitude in project Orekit by CS-SI.
the class AbstractForceModelTest method checkStateJacobianVsFiniteDifferences.
protected void checkStateJacobianVsFiniteDifferences(final SpacecraftState state0, final ForceModel forceModel, final AttitudeProvider provider, final double dP, final double checkTolerance, final boolean print) throws OrekitException {
double[][] finiteDifferencesJacobian = Differentiation.differentiate(state -> forceModel.acceleration(state, forceModel.getParameters()).toArray(), 3, provider, OrbitType.CARTESIAN, PositionAngle.MEAN, dP, 5).value(state0);
DSFactory factory = new DSFactory(6, 1);
Field<DerivativeStructure> field = factory.getDerivativeField();
final FieldAbsoluteDate<DerivativeStructure> fDate = new FieldAbsoluteDate<>(field, state0.getDate());
final Vector3D p = state0.getPVCoordinates().getPosition();
final Vector3D v = state0.getPVCoordinates().getVelocity();
final Vector3D a = state0.getPVCoordinates().getAcceleration();
final TimeStampedFieldPVCoordinates<DerivativeStructure> fPVA = new TimeStampedFieldPVCoordinates<>(fDate, new FieldVector3D<>(factory.variable(0, p.getX()), factory.variable(1, p.getY()), factory.variable(2, p.getZ())), new FieldVector3D<>(factory.variable(3, v.getX()), factory.variable(4, v.getY()), factory.variable(5, v.getZ())), new FieldVector3D<>(factory.constant(a.getX()), factory.constant(a.getY()), factory.constant(a.getZ())));
final TimeStampedFieldAngularCoordinates<DerivativeStructure> fAC = new TimeStampedFieldAngularCoordinates<>(fDate, new FieldRotation<>(field, state0.getAttitude().getRotation()), new FieldVector3D<>(field, state0.getAttitude().getSpin()), new FieldVector3D<>(field, state0.getAttitude().getRotationAcceleration()));
final FieldSpacecraftState<DerivativeStructure> fState = new FieldSpacecraftState<>(new FieldCartesianOrbit<>(fPVA, state0.getFrame(), state0.getMu()), new FieldAttitude<>(state0.getFrame(), fAC), field.getZero().add(state0.getMass()));
FieldVector3D<DerivativeStructure> dsJacobian = forceModel.acceleration(fState, forceModel.getParameters(fState.getDate().getField()));
Vector3D dFdPXRef = new Vector3D(finiteDifferencesJacobian[0][0], finiteDifferencesJacobian[1][0], finiteDifferencesJacobian[2][0]);
Vector3D dFdPXRes = new Vector3D(dsJacobian.getX().getPartialDerivative(1, 0, 0, 0, 0, 0), dsJacobian.getY().getPartialDerivative(1, 0, 0, 0, 0, 0), dsJacobian.getZ().getPartialDerivative(1, 0, 0, 0, 0, 0));
Vector3D dFdPYRef = new Vector3D(finiteDifferencesJacobian[0][1], finiteDifferencesJacobian[1][1], finiteDifferencesJacobian[2][1]);
Vector3D dFdPYRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 1, 0, 0, 0, 0), dsJacobian.getY().getPartialDerivative(0, 1, 0, 0, 0, 0), dsJacobian.getZ().getPartialDerivative(0, 1, 0, 0, 0, 0));
Vector3D dFdPZRef = new Vector3D(finiteDifferencesJacobian[0][2], finiteDifferencesJacobian[1][2], finiteDifferencesJacobian[2][2]);
Vector3D dFdPZRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 0, 1, 0, 0, 0), dsJacobian.getY().getPartialDerivative(0, 0, 1, 0, 0, 0), dsJacobian.getZ().getPartialDerivative(0, 0, 1, 0, 0, 0));
Vector3D dFdVXRef = new Vector3D(finiteDifferencesJacobian[0][3], finiteDifferencesJacobian[1][3], finiteDifferencesJacobian[2][3]);
Vector3D dFdVXRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 0, 0, 1, 0, 0), dsJacobian.getY().getPartialDerivative(0, 0, 0, 1, 0, 0), dsJacobian.getZ().getPartialDerivative(0, 0, 0, 1, 0, 0));
Vector3D dFdVYRef = new Vector3D(finiteDifferencesJacobian[0][4], finiteDifferencesJacobian[1][4], finiteDifferencesJacobian[2][4]);
Vector3D dFdVYRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 0, 0, 0, 1, 0), dsJacobian.getY().getPartialDerivative(0, 0, 0, 0, 1, 0), dsJacobian.getZ().getPartialDerivative(0, 0, 0, 0, 1, 0));
Vector3D dFdVZRef = new Vector3D(finiteDifferencesJacobian[0][5], finiteDifferencesJacobian[1][5], finiteDifferencesJacobian[2][5]);
Vector3D dFdVZRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 0, 0, 0, 0, 1), dsJacobian.getY().getPartialDerivative(0, 0, 0, 0, 0, 1), dsJacobian.getZ().getPartialDerivative(0, 0, 0, 0, 0, 1));
if (print) {
System.out.println("dF/dPX ref: " + dFdPXRef.getX() + " " + dFdPXRef.getY() + " " + dFdPXRef.getZ());
System.out.println("dF/dPX res: " + dFdPXRes.getX() + " " + dFdPXRes.getY() + " " + dFdPXRes.getZ());
System.out.println("dF/dPY ref: " + dFdPYRef.getX() + " " + dFdPYRef.getY() + " " + dFdPYRef.getZ());
System.out.println("dF/dPY res: " + dFdPYRes.getX() + " " + dFdPYRes.getY() + " " + dFdPYRes.getZ());
System.out.println("dF/dPZ ref: " + dFdPZRef.getX() + " " + dFdPZRef.getY() + " " + dFdPZRef.getZ());
System.out.println("dF/dPZ res: " + dFdPZRes.getX() + " " + dFdPZRes.getY() + " " + dFdPZRes.getZ());
System.out.println("dF/dPX ref norm: " + dFdPXRef.getNorm() + ", abs error: " + Vector3D.distance(dFdPXRef, dFdPXRes) + ", rel error: " + (Vector3D.distance(dFdPXRef, dFdPXRes) / dFdPXRef.getNorm()));
System.out.println("dF/dPY ref norm: " + dFdPYRef.getNorm() + ", abs error: " + Vector3D.distance(dFdPYRef, dFdPYRes) + ", rel error: " + (Vector3D.distance(dFdPYRef, dFdPYRes) / dFdPYRef.getNorm()));
System.out.println("dF/dPZ ref norm: " + dFdPZRef.getNorm() + ", abs error: " + Vector3D.distance(dFdPZRef, dFdPZRes) + ", rel error: " + (Vector3D.distance(dFdPZRef, dFdPZRes) / dFdPZRef.getNorm()));
System.out.println("dF/dVX ref norm: " + dFdVXRef.getNorm() + ", abs error: " + Vector3D.distance(dFdVXRef, dFdVXRes) + ", rel error: " + (Vector3D.distance(dFdVXRef, dFdVXRes) / dFdVXRef.getNorm()));
System.out.println("dF/dVY ref norm: " + dFdVYRef.getNorm() + ", abs error: " + Vector3D.distance(dFdVYRef, dFdVYRes) + ", rel error: " + (Vector3D.distance(dFdVYRef, dFdVYRes) / dFdVYRef.getNorm()));
System.out.println("dF/dVZ ref norm: " + dFdVZRef.getNorm() + ", abs error: " + Vector3D.distance(dFdVZRef, dFdVZRes) + ", rel error: " + (Vector3D.distance(dFdVZRef, dFdVZRes) / dFdVZRef.getNorm()));
}
checkdFdP(dFdPXRef, dFdPXRes, checkTolerance);
checkdFdP(dFdPYRef, dFdPYRes, checkTolerance);
checkdFdP(dFdPZRef, dFdPZRes, checkTolerance);
checkdFdP(dFdVXRef, dFdVXRes, checkTolerance);
checkdFdP(dFdVYRef, dFdVYRes, checkTolerance);
checkdFdP(dFdVZRef, dFdVZRes, checkTolerance);
}
use of org.orekit.attitudes.FieldAttitude in project Orekit by CS-SI.
the class KeplerianPropagatorTest method tesWrapedAttitudeException.
@Test(expected = OrekitException.class)
public void tesWrapedAttitudeException() throws OrekitException {
final KeplerianOrbit orbit = new KeplerianOrbit(7.8e6, 0.032, 0.4, 0.1, 0.2, 0.3, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, 3.986004415e14);
KeplerianPropagator propagator = new KeplerianPropagator(orbit, new AttitudeProvider() {
private static final long serialVersionUID = 1L;
public Attitude getAttitude(PVCoordinatesProvider pvProv, AbsoluteDate date, Frame frame) throws OrekitException {
throw new OrekitException((Throwable) null, new DummyLocalizable("dummy error"));
}
public <T extends RealFieldElement<T>> FieldAttitude<T> getAttitude(FieldPVCoordinatesProvider<T> pvProv, FieldAbsoluteDate<T> date, Frame frame) throws OrekitException {
throw new OrekitException((Throwable) null, new DummyLocalizable("dummy error"));
}
});
propagator.propagate(orbit.getDate().shiftedBy(10.09));
}
use of org.orekit.attitudes.FieldAttitude in project Orekit by CS-SI.
the class FieldSpacecraftState method interpolate.
/**
* Get an interpolated instance.
* <p>
* The additional states that are interpolated are the ones already present
* in the instance. The sample instances must therefore have at least the same
* additional states has the instance. They may have more additional states,
* but the extra ones will be ignored.
* </p>
* <p>
* As this implementation of interpolation is polynomial, it should be used only
* with small samples (about 10-20 points) in order to avoid <a
* href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's phenomenon</a>
* and numerical problems (including NaN appearing).
* </p>
* @param date interpolation date
* @param sample sample points on which interpolation should be done
* @return a new instance, interpolated at specified date
* @exception OrekitException if the number of point is too small for interpolating
*/
public FieldSpacecraftState<T> interpolate(final FieldAbsoluteDate<T> date, final Stream<FieldSpacecraftState<T>> sample) throws OrekitException {
// prepare interpolators
final List<FieldOrbit<T>> orbits = new ArrayList<>();
final List<FieldAttitude<T>> attitudes = new ArrayList<>();
final FieldHermiteInterpolator<T> massInterpolator = new FieldHermiteInterpolator<>();
final Map<String, FieldHermiteInterpolator<T>> additionalInterpolators = new HashMap<String, FieldHermiteInterpolator<T>>(additional.size());
for (final String name : additional.keySet()) {
additionalInterpolators.put(name, new FieldHermiteInterpolator<>());
}
// extract sample data
try {
sample.forEach(state -> {
try {
final T deltaT = state.getDate().durationFrom(date);
orbits.add(state.getOrbit());
attitudes.add(state.getAttitude());
final T[] mm = MathArrays.buildArray(orbit.getA().getField(), 1);
mm[0] = state.getMass();
massInterpolator.addSamplePoint(deltaT, mm);
for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
entry.getValue().addSamplePoint(deltaT, state.getAdditionalState(entry.getKey()));
}
} catch (OrekitException oe) {
throw new OrekitExceptionWrapper(oe);
}
});
} catch (OrekitExceptionWrapper oew) {
throw oew.getException();
}
// perform interpolations
final FieldOrbit<T> interpolatedOrbit = orbit.interpolate(date, orbits);
final FieldAttitude<T> interpolatedAttitude = attitude.interpolate(date, attitudes);
final T interpolatedMass = massInterpolator.value(orbit.getA().getField().getZero())[0];
final Map<String, T[]> interpolatedAdditional;
if (additional.isEmpty()) {
interpolatedAdditional = null;
} else {
interpolatedAdditional = new HashMap<String, T[]>(additional.size());
for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
interpolatedAdditional.put(entry.getKey(), entry.getValue().value(orbit.getA().getField().getZero()));
}
}
// create the complete interpolated state
return new FieldSpacecraftState<>(interpolatedOrbit, interpolatedAttitude, interpolatedMass, interpolatedAdditional);
}
Aggregations