use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class TimeStampedAngularCoordinatesTest method testRoundTripNoOp.
@Test
public void testRoundTripNoOp() {
RandomGenerator random = new Well1024a(0x1e610cfe89306669l);
for (int i = 0; i < 100; ++i) {
Rotation r1 = randomRotation(random);
Vector3D o1 = randomVector(random, 1.0e-2);
Vector3D a1 = randomVector(random, 1.0e-2);
TimeStampedAngularCoordinates ac1 = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, r1, o1, a1);
Rotation r2 = randomRotation(random);
Vector3D o2 = randomVector(random, 1.0e-2);
Vector3D a2 = randomVector(random, 1.0e-2);
TimeStampedAngularCoordinates ac2 = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, r2, o2, a2);
TimeStampedAngularCoordinates roundTripSA = ac1.subtractOffset(ac2).addOffset(ac2);
Assert.assertEquals(0.0, Rotation.distance(ac1.getRotation(), roundTripSA.getRotation()), 4.0e-16);
Assert.assertEquals(0.0, Vector3D.distance(ac1.getRotationRate(), roundTripSA.getRotationRate()), 2.0e-17);
Assert.assertEquals(0.0, Vector3D.distance(ac1.getRotationAcceleration(), roundTripSA.getRotationAcceleration()), 1.0e-17);
TimeStampedAngularCoordinates roundTripAS = ac1.addOffset(ac2).subtractOffset(ac2);
Assert.assertEquals(0.0, Rotation.distance(ac1.getRotation(), roundTripAS.getRotation()), 6.0e-16);
Assert.assertEquals(0.0, Vector3D.distance(ac1.getRotationRate(), roundTripAS.getRotationRate()), 2.0e-17);
Assert.assertEquals(0.0, Vector3D.distance(ac1.getRotationAcceleration(), roundTripAS.getRotationAcceleration()), 2.0e-17);
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class FieldPropagation method main.
/**
* Program entry point.
* @param args program arguments (unused here)
* @throws IOException
* @throws OrekitException
*/
public static void main(String[] args) throws IOException, OrekitException {
// the goal of this example is to make a Montecarlo simulation giving an error on the semiaxis,
// the inclination and the RAAN. The interest of doing it with Orekit based on the
// DerivativeStructure is that instead of doing a large number of propagation around the initial
// point we will do a single propagation of the initial state, and thanks to the Taylor expansion
// we will see the evolution of the std deviation of the position, which is divided in the
// CrossTrack, the LongTrack and the Radial error.
// configure Orekit
File home = new File(System.getProperty("user.home"));
File orekitData = new File(home, "orekit-data");
if (!orekitData.exists()) {
System.err.format(Locale.US, "Failed to find %s folder%n", orekitData.getAbsolutePath());
System.err.format(Locale.US, "You need to download %s from the %s page and unzip it in %s for this tutorial to work%n", "orekit-data.zip", "https://www.orekit.org/forge/projects/orekit/files", home.getAbsolutePath());
System.exit(1);
}
DataProvidersManager manager = DataProvidersManager.getInstance();
manager.addProvider(new DirectoryCrawler(orekitData));
// output file in user's home directory
File workingDir = new File(System.getProperty("user.home"));
File errorFile = new File(workingDir, "error.txt");
System.out.println("Output file is in : " + errorFile.getAbsolutePath());
PrintWriter PW = new PrintWriter(errorFile, "UTF-8");
PW.printf("time \t\tCrossTrackErr \tLongTrackErr \tRadialErr \tTotalErr%n");
// setting the parameters of the simulation
// Order of derivation of the DerivativeStructures
int params = 3;
int order = 3;
DSFactory factory = new DSFactory(params, order);
// number of samples of the montecarlo simulation
int montecarlo_size = 100;
// nominal values of the Orbital parameters
double a_nominal = 7.278E6;
double e_nominal = 1e-3;
double i_nominal = FastMath.toRadians(98.3);
double pa_nominal = FastMath.PI / 2;
double raan_nominal = 0.0;
double ni_nominal = 0.0;
// mean of the gaussian curve for each of the errors around the nominal values
// {a, i, RAAN}
double[] mean = { 0, 0, 0 };
// standard deviation of the gaussian curve for each of the errors around the nominal values
// {dA, dI, dRaan}
double[] dAdIdRaan = { 5, FastMath.toRadians(1e-3), FastMath.toRadians(1e-3) };
// time of integration
double final_Dt = 1 * 60 * 60;
// number of steps per orbit
double num_step_orbit = 10;
DerivativeStructure a_0 = factory.variable(0, a_nominal);
DerivativeStructure e_0 = factory.constant(e_nominal);
DerivativeStructure i_0 = factory.variable(1, i_nominal);
DerivativeStructure pa_0 = factory.constant(pa_nominal);
DerivativeStructure raan_0 = factory.variable(2, raan_nominal);
DerivativeStructure ni_0 = factory.constant(ni_nominal);
// sometimes we will need the field of the DerivativeStructure to build new instances
Field<DerivativeStructure> field = a_0.getField();
// sometimes we will need the zero of the DerivativeStructure to build new instances
DerivativeStructure zero = field.getZero();
// initializing the FieldAbsoluteDate with only the field it will generate the day J2000
FieldAbsoluteDate<DerivativeStructure> date_0 = new FieldAbsoluteDate<>(field);
// initialize a basic frame
Frame frame = FramesFactory.getEME2000();
// initialize the orbit
double mu = 3.9860047e14;
FieldKeplerianOrbit<DerivativeStructure> KO = new FieldKeplerianOrbit<>(a_0, e_0, i_0, pa_0, raan_0, ni_0, PositionAngle.ECCENTRIC, frame, date_0, mu);
// step of integration (how many times per orbit we take the mesures)
double int_step = KO.getKeplerianPeriod().getReal() / num_step_orbit;
// random generator to conduct an
long number = 23091991;
RandomGenerator RG = new Well19937a(number);
GaussianRandomGenerator NGG = new GaussianRandomGenerator(RG);
UncorrelatedRandomVectorGenerator URVG = new UncorrelatedRandomVectorGenerator(mean, dAdIdRaan, NGG);
double[][] rand_gen = new double[montecarlo_size][3];
for (int jj = 0; jj < montecarlo_size; jj++) {
rand_gen[jj] = URVG.nextVector();
}
//
FieldSpacecraftState<DerivativeStructure> SS_0 = new FieldSpacecraftState<>(KO);
// adding force models
ForceModel fModel_Sun = new ThirdBodyAttraction(CelestialBodyFactory.getSun());
ForceModel fModel_Moon = new ThirdBodyAttraction(CelestialBodyFactory.getMoon());
ForceModel fModel_HFAM = new HolmesFeatherstoneAttractionModel(FramesFactory.getITRF(IERSConventions.IERS_2010, true), GravityFieldFactory.getNormalizedProvider(18, 18));
// setting an hipparchus field integrator
OrbitType type = OrbitType.CARTESIAN;
double[][] tolerance = NumericalPropagator.tolerances(0.001, KO.toOrbit(), type);
AdaptiveStepsizeFieldIntegrator<DerivativeStructure> integrator = new DormandPrince853FieldIntegrator<>(field, 0.001, 200, tolerance[0], tolerance[1]);
integrator.setInitialStepSize(zero.add(60));
// setting of the field propagator, we used the numerical one in order to add the third body attraction
// and the holmes featherstone force models
FieldNumericalPropagator<DerivativeStructure> numProp = new FieldNumericalPropagator<>(field, integrator);
numProp.setOrbitType(type);
numProp.setInitialState(SS_0);
numProp.addForceModel(fModel_Sun);
numProp.addForceModel(fModel_Moon);
numProp.addForceModel(fModel_HFAM);
// with the master mode we will calulcate and print the error on every fixed step on the file error.txt
// we defined the StepHandler to do that giving him the random number generator,
// the size of the montecarlo simulation and the initial date
numProp.setMasterMode(zero.add(int_step), new MyStepHandler<DerivativeStructure>(rand_gen, montecarlo_size, date_0, PW));
//
long START = System.nanoTime();
FieldSpacecraftState<DerivativeStructure> finalState = numProp.propagate(date_0.shiftedBy(final_Dt));
long STOP = System.nanoTime();
System.out.println((STOP - START) / 1E6 + " ms");
System.out.println(finalState.getDate());
PW.close();
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class AngularCoordinatesTest method testRodriguesSpecialCases.
@Test
public void testRodriguesSpecialCases() {
// identity
double[][] identity = new AngularCoordinates(Rotation.IDENTITY, Vector3D.ZERO, Vector3D.ZERO).getModifiedRodrigues(1.0);
for (double[] row : identity) {
for (double element : row) {
Assert.assertEquals(0.0, element, Precision.SAFE_MIN);
}
}
AngularCoordinates acId = AngularCoordinates.createFromModifiedRodrigues(identity);
Assert.assertEquals(0.0, acId.getRotation().getAngle(), Precision.SAFE_MIN);
Assert.assertEquals(0.0, acId.getRotationRate().getNorm(), Precision.SAFE_MIN);
// PI angle rotation (which is singular for non-modified Rodrigues vector)
RandomGenerator random = new Well1024a(0x2158523e6accb859l);
for (int i = 0; i < 100; ++i) {
Vector3D axis = randomVector(random, 1.0);
AngularCoordinates original = new AngularCoordinates(new Rotation(axis, FastMath.PI, RotationConvention.VECTOR_OPERATOR), Vector3D.ZERO, Vector3D.ZERO);
AngularCoordinates rebuilt = AngularCoordinates.createFromModifiedRodrigues(original.getModifiedRodrigues(1.0));
Assert.assertEquals(FastMath.PI, rebuilt.getRotation().getAngle(), 1.0e-15);
Assert.assertEquals(0.0, FastMath.sin(Vector3D.angle(axis, rebuilt.getRotation().getAxis(RotationConvention.VECTOR_OPERATOR))), 1.0e-15);
Assert.assertEquals(0.0, rebuilt.getRotationRate().getNorm(), 1.0e-16);
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class AngularCoordinatesTest method testRoundTripNoOp.
@Test
public void testRoundTripNoOp() {
RandomGenerator random = new Well1024a(0x1e610cfe89306669l);
for (int i = 0; i < 100; ++i) {
Rotation r1 = randomRotation(random);
Vector3D o1 = randomVector(random, 1.0e-2);
Vector3D oDot1 = randomVector(random, 1.0e-2);
AngularCoordinates ac1 = new AngularCoordinates(r1, o1, oDot1);
Rotation r2 = randomRotation(random);
Vector3D o2 = randomVector(random, 1.0e-2);
Vector3D oDot2 = randomVector(random, 1.0e-2);
AngularCoordinates ac2 = new AngularCoordinates(r2, o2, oDot2);
AngularCoordinates roundTripSA = ac1.subtractOffset(ac2).addOffset(ac2);
Assert.assertEquals(0.0, Rotation.distance(ac1.getRotation(), roundTripSA.getRotation()), 5.0e-16);
Assert.assertEquals(0.0, Vector3D.distance(ac1.getRotationRate(), roundTripSA.getRotationRate()), 2.0e-17);
Assert.assertEquals(0.0, Vector3D.distance(ac1.getRotationAcceleration(), roundTripSA.getRotationAcceleration()), 2.0e-17);
AngularCoordinates roundTripAS = ac1.addOffset(ac2).subtractOffset(ac2);
Assert.assertEquals(0.0, Rotation.distance(ac1.getRotation(), roundTripAS.getRotation()), 5.0e-16);
Assert.assertEquals(0.0, Vector3D.distance(ac1.getRotationRate(), roundTripAS.getRotationRate()), 2.0e-17);
Assert.assertEquals(0.0, Vector3D.distance(ac1.getRotationAcceleration(), roundTripAS.getRotationAcceleration()), 2.0e-17);
}
}
use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.
the class AngularCoordinatesTest method testRandomInverseCrossProducts.
@Test
public void testRandomInverseCrossProducts() throws OrekitException {
RandomGenerator generator = new Well1024a(0x52b29d8f6ac2d64bl);
for (int i = 0; i < 10000; ++i) {
Vector3D omega = randomVector(generator, 10 * generator.nextDouble() + 1.0);
Vector3D v1 = randomVector(generator, 10 * generator.nextDouble() + 1.0);
Vector3D v2 = randomVector(generator, 10 * generator.nextDouble() + 1.0);
checkInverse(omega, v1, v2);
}
}
Aggregations