use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.
the class FieldTransformGenerator method generate.
/**
* {@inheritDoc}
*/
public List<FieldTransform<T>> generate(final AbsoluteDate existingDate, final AbsoluteDate date) {
try {
final FieldAbsoluteDate<T> fieldDate = new FieldAbsoluteDate<>(field, date);
final List<FieldTransform<T>> generated = new ArrayList<>();
if (existingDate == null) {
// no prior existing transforms, just generate a first set
for (int i = 0; i < neighborsSize; ++i) {
generated.add(provider.getTransform(fieldDate.shiftedBy(i * step)));
}
} else {
// some transforms have already been generated
// add the missing ones up to specified date
FieldAbsoluteDate<T> t = new FieldAbsoluteDate<>(field, existingDate);
if (date.compareTo(t.toAbsoluteDate()) > 0) {
// forward generation
do {
t = t.shiftedBy(step);
generated.add(generated.size(), provider.getTransform(t));
} while (t.compareTo(fieldDate) <= 0);
} else {
// backward generation
do {
t = t.shiftedBy(-step);
generated.add(0, provider.getTransform(t));
} while (t.compareTo(fieldDate) >= 0);
}
}
// return the generated transforms
return generated;
} catch (OrekitException oe) {
throw new OrekitExceptionWrapper(oe);
}
}
use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.
the class GroundStationTest method doTestCartesianDerivatives.
private void doTestCartesianDerivatives(double latitude, double longitude, double altitude, double stepFactor, double relativeTolerancePositionValue, double relativeTolerancePositionDerivative, double relativeToleranceVelocityValue, double relativeToleranceVelocityDerivative, String... parameterPattern) throws OrekitException {
Utils.setDataRoot("regular-data");
final Frame eme2000 = FramesFactory.getEME2000();
final AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
final AbsoluteDate date0 = date.shiftedBy(50000);
final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
final GroundStation station = new GroundStation(new TopocentricFrame(earth, new GeodeticPoint(latitude, longitude, altitude), "dummy"));
final DSFactory factory = new DSFactory(parameterPattern.length, 1);
final FieldAbsoluteDate<DerivativeStructure> dateDS = new FieldAbsoluteDate<>(factory.getDerivativeField(), date);
ParameterDriver[] selectedDrivers = new ParameterDriver[parameterPattern.length];
UnivariateDifferentiableVectorFunction[] dFCartesian = new UnivariateDifferentiableVectorFunction[parameterPattern.length];
final ParameterDriver[] allDrivers = selectAllDrivers(station);
for (ParameterDriver driver : allDrivers) {
driver.setReferenceDate(date0);
}
Map<String, Integer> indices = new HashMap<>();
for (int k = 0; k < dFCartesian.length; ++k) {
for (int i = 0; i < allDrivers.length; ++i) {
if (allDrivers[i].getName().matches(parameterPattern[k])) {
selectedDrivers[k] = allDrivers[i];
dFCartesian[k] = differentiatedStationPV(station, eme2000, date, selectedDrivers[k], stepFactor);
indices.put(selectedDrivers[k].getName(), k);
}
}
}
;
DSFactory factory11 = new DSFactory(1, 1);
RandomGenerator generator = new Well19937a(0x084d58a19c498a54l);
double maxPositionValueRelativeError = 0;
double maxPositionDerivativeRelativeError = 0;
double maxVelocityValueRelativeError = 0;
double maxVelocityDerivativeRelativeError = 0;
for (int i = 0; i < 1000; ++i) {
// randomly change one parameter
ParameterDriver changed = allDrivers[generator.nextInt(allDrivers.length)];
changed.setNormalizedValue(2 * generator.nextDouble() - 1);
// transform to check
FieldTransform<DerivativeStructure> t = station.getOffsetToInertial(eme2000, dateDS, factory, indices);
FieldPVCoordinates<DerivativeStructure> pv = t.transformPVCoordinates(FieldPVCoordinates.getZero(factory.getDerivativeField()));
for (int k = 0; k < dFCartesian.length; ++k) {
// reference values and derivatives computed using finite differences
DerivativeStructure[] refCartesian = dFCartesian[k].value(factory11.variable(0, selectedDrivers[k].getValue()));
// position
final Vector3D refP = new Vector3D(refCartesian[0].getValue(), refCartesian[1].getValue(), refCartesian[2].getValue());
final Vector3D resP = new Vector3D(pv.getPosition().getX().getValue(), pv.getPosition().getY().getValue(), pv.getPosition().getZ().getValue());
maxPositionValueRelativeError = FastMath.max(maxPositionValueRelativeError, Vector3D.distance(refP, resP) / refP.getNorm());
final Vector3D refPD = new Vector3D(refCartesian[0].getPartialDerivative(1), refCartesian[1].getPartialDerivative(1), refCartesian[2].getPartialDerivative(1));
final Vector3D resPD = new Vector3D(pv.getPosition().getX().getAllDerivatives()[k + 1], pv.getPosition().getY().getAllDerivatives()[k + 1], pv.getPosition().getZ().getAllDerivatives()[k + 1]);
maxPositionDerivativeRelativeError = FastMath.max(maxPositionDerivativeRelativeError, Vector3D.distance(refPD, resPD) / refPD.getNorm());
// velocity
final Vector3D refV = new Vector3D(refCartesian[3].getValue(), refCartesian[4].getValue(), refCartesian[5].getValue());
final Vector3D resV = new Vector3D(pv.getVelocity().getX().getValue(), pv.getVelocity().getY().getValue(), pv.getVelocity().getZ().getValue());
maxVelocityValueRelativeError = FastMath.max(maxVelocityValueRelativeError, Vector3D.distance(refV, resV) / refV.getNorm());
final Vector3D refVD = new Vector3D(refCartesian[3].getPartialDerivative(1), refCartesian[4].getPartialDerivative(1), refCartesian[5].getPartialDerivative(1));
final Vector3D resVD = new Vector3D(pv.getVelocity().getX().getAllDerivatives()[k + 1], pv.getVelocity().getY().getAllDerivatives()[k + 1], pv.getVelocity().getZ().getAllDerivatives()[k + 1]);
maxVelocityDerivativeRelativeError = FastMath.max(maxVelocityDerivativeRelativeError, Vector3D.distance(refVD, resVD) / refVD.getNorm());
}
}
Assert.assertEquals(0.0, maxPositionValueRelativeError, relativeTolerancePositionValue);
Assert.assertEquals(0.0, maxPositionDerivativeRelativeError, relativeTolerancePositionDerivative);
Assert.assertEquals(0.0, maxVelocityValueRelativeError, relativeToleranceVelocityValue);
Assert.assertEquals(0.0, maxVelocityDerivativeRelativeError, relativeToleranceVelocityDerivative);
}
use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.
the class GroundStationTest method testNoReferenceDate.
@Test
public void testNoReferenceDate() throws OrekitException {
Utils.setDataRoot("regular-data");
final Frame eme2000 = FramesFactory.getEME2000();
final AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
final GroundStation station = new GroundStation(new TopocentricFrame(earth, new GeodeticPoint(0.1, 0.2, 100), "dummy"));
try {
station.getOffsetToInertial(eme2000, date);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.NO_REFERENCE_DATE_FOR_PARAMETER, oe.getSpecifier());
Assert.assertEquals("prime-meridian-offset", (String) oe.getParts()[0]);
}
try {
DSFactory factory = new DSFactory(9, 1);
Map<String, Integer> indices = new HashMap<>();
for (final ParameterDriver driver : Arrays.asList(station.getPrimeMeridianOffsetDriver(), station.getPrimeMeridianDriftDriver(), station.getPolarOffsetXDriver(), station.getPolarDriftXDriver(), station.getPolarOffsetYDriver(), station.getPolarDriftYDriver(), station.getEastOffsetDriver(), station.getNorthOffsetDriver(), station.getZenithOffsetDriver())) {
indices.put(driver.getName(), indices.size());
}
station.getOffsetToInertial(eme2000, new FieldAbsoluteDate<>(factory.getDerivativeField(), date), factory, indices);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.NO_REFERENCE_DATE_FOR_PARAMETER, oe.getSpecifier());
Assert.assertEquals("prime-meridian-offset", (String) oe.getParts()[0]);
}
}
use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.
the class GroundStationTest method doTestAngularDerivatives.
private void doTestAngularDerivatives(double latitude, double longitude, double altitude, double stepFactor, double toleranceRotationValue, double toleranceRotationDerivative, double toleranceRotationRateValue, double toleranceRotationRateDerivative, String... parameterPattern) throws OrekitException {
Utils.setDataRoot("regular-data");
final Frame eme2000 = FramesFactory.getEME2000();
final AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
final AbsoluteDate date0 = date.shiftedBy(50000);
final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
final GroundStation station = new GroundStation(new TopocentricFrame(earth, new GeodeticPoint(latitude, longitude, altitude), "dummy"));
final DSFactory factory = new DSFactory(parameterPattern.length, 1);
final FieldAbsoluteDate<DerivativeStructure> dateDS = new FieldAbsoluteDate<>(factory.getDerivativeField(), date);
ParameterDriver[] selectedDrivers = new ParameterDriver[parameterPattern.length];
UnivariateDifferentiableVectorFunction[] dFAngular = new UnivariateDifferentiableVectorFunction[parameterPattern.length];
final ParameterDriver[] allDrivers = selectAllDrivers(station);
for (ParameterDriver driver : allDrivers) {
driver.setReferenceDate(date0);
}
Map<String, Integer> indices = new HashMap<>();
for (int k = 0; k < dFAngular.length; ++k) {
for (int i = 0; i < allDrivers.length; ++i) {
if (allDrivers[i].getName().matches(parameterPattern[k])) {
selectedDrivers[k] = allDrivers[i];
dFAngular[k] = differentiatedTransformAngular(station, eme2000, date, selectedDrivers[k], stepFactor);
indices.put(selectedDrivers[k].getName(), k);
}
}
}
;
DSFactory factory11 = new DSFactory(1, 1);
RandomGenerator generator = new Well19937a(0xa01a1d8fe5d80af7l);
double maxRotationValueError = 0;
double maxRotationDerivativeError = 0;
double maxRotationRateValueError = 0;
double maxRotationRateDerivativeError = 0;
for (int i = 0; i < 1000; ++i) {
// randomly change one parameter
ParameterDriver changed = allDrivers[generator.nextInt(allDrivers.length)];
changed.setNormalizedValue(2 * generator.nextDouble() - 1);
// transform to check
FieldTransform<DerivativeStructure> t = station.getOffsetToInertial(eme2000, dateDS, factory, indices);
for (int k = 0; k < dFAngular.length; ++k) {
// reference values and derivatives computed using finite differences
DerivativeStructure[] refAngular = dFAngular[k].value(factory11.variable(0, selectedDrivers[k].getValue()));
// rotation
final Rotation refQ = new Rotation(refAngular[0].getValue(), refAngular[1].getValue(), refAngular[2].getValue(), refAngular[3].getValue(), true);
final Rotation resQ = t.getRotation().toRotation();
maxRotationValueError = FastMath.max(maxRotationValueError, Rotation.distance(refQ, resQ));
double sign = FastMath.copySign(1.0, refAngular[0].getValue() * t.getRotation().getQ0().getValue() + refAngular[1].getValue() * t.getRotation().getQ1().getValue() + refAngular[2].getValue() * t.getRotation().getQ2().getValue() + refAngular[3].getValue() * t.getRotation().getQ3().getValue());
maxRotationDerivativeError = FastMath.max(maxRotationDerivativeError, FastMath.abs(sign * refAngular[0].getPartialDerivative(1) - t.getRotation().getQ0().getAllDerivatives()[k + 1]));
maxRotationDerivativeError = FastMath.max(maxRotationDerivativeError, FastMath.abs(sign * refAngular[1].getPartialDerivative(1) - t.getRotation().getQ1().getAllDerivatives()[k + 1]));
maxRotationDerivativeError = FastMath.max(maxRotationDerivativeError, FastMath.abs(sign * refAngular[2].getPartialDerivative(1) - t.getRotation().getQ2().getAllDerivatives()[k + 1]));
maxRotationDerivativeError = FastMath.max(maxRotationDerivativeError, FastMath.abs(sign * refAngular[3].getPartialDerivative(1) - t.getRotation().getQ3().getAllDerivatives()[k + 1]));
// rotation rate
final Vector3D refRate = new Vector3D(refAngular[4].getValue(), refAngular[5].getValue(), refAngular[6].getValue());
final Vector3D resRate = t.getRotationRate().toVector3D();
final Vector3D refRateD = new Vector3D(refAngular[4].getPartialDerivative(1), refAngular[5].getPartialDerivative(1), refAngular[6].getPartialDerivative(1));
final Vector3D resRateD = new Vector3D(t.getRotationRate().getX().getAllDerivatives()[k + 1], t.getRotationRate().getY().getAllDerivatives()[k + 1], t.getRotationRate().getZ().getAllDerivatives()[k + 1]);
maxRotationRateValueError = FastMath.max(maxRotationRateValueError, Vector3D.distance(refRate, resRate));
maxRotationRateDerivativeError = FastMath.max(maxRotationRateDerivativeError, Vector3D.distance(refRateD, resRateD));
}
}
Assert.assertEquals(0.0, maxRotationValueError, toleranceRotationValue);
Assert.assertEquals(0.0, maxRotationDerivativeError, toleranceRotationDerivative);
Assert.assertEquals(0.0, maxRotationRateValueError, toleranceRotationRateValue);
Assert.assertEquals(0.0, maxRotationRateDerivativeError, toleranceRotationRateDerivative);
}
use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.
the class SolarRadiationPressureTest method testLightingInterplanetary.
@Test
public void testLightingInterplanetary() throws OrekitException, ParseException {
// Initialization
AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 3, 21), new TimeComponents(13, 59, 27.816), TimeScalesFactory.getUTC());
Orbit orbit = new KeplerianOrbit(1.0e11, 0.1, 0.2, 0.3, 0.4, 0.5, PositionAngle.TRUE, CelestialBodyFactory.getSolarSystemBarycenter().getInertiallyOrientedFrame(), date, Constants.JPL_SSD_SUN_GM);
PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
SolarRadiationPressure srp = new SolarRadiationPressure(sun, Constants.SUN_RADIUS, (RadiationSensitive) new IsotropicRadiationClassicalConvention(50.0, 0.5, 0.5));
Assert.assertFalse(srp.dependsOnPositionOnly());
Vector3D position = orbit.getPVCoordinates().getPosition();
Frame frame = orbit.getFrame();
Assert.assertEquals(1.0, srp.getLightingRatio(position, frame, date), 1.0e-15);
Assert.assertEquals(1.0, srp.getLightingRatio(new FieldVector3D<>(Decimal64Field.getInstance(), position), frame, new FieldAbsoluteDate<>(Decimal64Field.getInstance(), date)).getReal(), 1.0e-15);
}
Aggregations