use of org.hipparchus.util.Pair in project Orekit by CS-SI.
the class JacobianPropagatorConverter method getModel.
/**
* {@inheritDoc}
*/
protected MultivariateJacobianFunction getModel() {
return new MultivariateJacobianFunction() {
/**
* {@inheritDoc}
*/
public Pair<RealVector, RealMatrix> value(final RealVector point) throws IllegalArgumentException, OrekitExceptionWrapper {
try {
final RealVector value = new ArrayRealVector(getTargetSize());
final RealMatrix jacobian = MatrixUtils.createRealMatrix(getTargetSize(), point.getDimension());
final NumericalPropagator prop = builder.buildPropagator(point.toArray());
final int stateSize = isOnlyPosition() ? 3 : 6;
final ParameterDriversList orbitalParameters = builder.getOrbitalParametersDrivers();
final PartialDerivativesEquations pde = new PartialDerivativesEquations("pde", prop);
final ParameterDriversList propagationParameters = pde.getSelectedParameters();
prop.setInitialState(pde.setInitialJacobians(prop.getInitialState()));
final JacobiansMapper mapper = pde.getMapper();
final List<SpacecraftState> sample = getSample();
for (int i = 0; i < sample.size(); ++i) {
final int row = i * stateSize;
if (prop.getInitialState().getDate().equals(sample.get(i).getDate())) {
// use initial state and Jacobians
fillRows(value, jacobian, row, prop.getInitialState(), stateSize, orbitalParameters, propagationParameters, mapper);
} else {
// use a date detector to pick up state and Jacobians
prop.addEventDetector(new DateDetector(sample.get(i).getDate()).withHandler(new EventHandler<DateDetector>() {
/**
* {@inheritDoc}
*/
@Override
public Action eventOccurred(final SpacecraftState state, final DateDetector detector, final boolean increasing) throws OrekitException {
fillRows(value, jacobian, row, state, stateSize, orbitalParameters, propagationParameters, mapper);
return row + stateSize >= getTargetSize() ? Action.STOP : Action.CONTINUE;
}
}));
}
}
prop.propagate(sample.get(sample.size() - 1).getDate().shiftedBy(10.0));
return new Pair<RealVector, RealMatrix>(value, jacobian);
} catch (OrekitException ex) {
throw new OrekitExceptionWrapper(ex);
}
}
};
}
use of org.hipparchus.util.Pair in project Orekit by CS-SI.
the class Model method value.
/**
* {@inheritDoc}
*/
@Override
public Pair<RealVector, RealMatrix> value(final RealVector point) throws OrekitExceptionWrapper {
try {
// Set up the propagators parallelizer
final NumericalPropagator[] propagators = createPropagators(point);
final Orbit[] orbits = new Orbit[propagators.length];
for (int i = 0; i < propagators.length; ++i) {
mappers[i] = configureDerivatives(propagators[i]);
orbits[i] = propagators[i].getInitialState().getOrbit();
}
final PropagatorsParallelizer parallelizer = new PropagatorsParallelizer(Arrays.asList(propagators), configureMeasurements(point));
// Reset value and Jacobian
evaluations.clear();
value.set(0.0);
for (int i = 0; i < jacobian.getRowDimension(); ++i) {
for (int j = 0; j < jacobian.getColumnDimension(); ++j) {
jacobian.setEntry(i, j, 0.0);
}
}
// Run the propagation, gathering residuals on the fly
if (forwardPropagation) {
// Propagate forward from firstDate
parallelizer.propagate(firstDate.shiftedBy(-1.0), lastDate.shiftedBy(+1.0));
} else {
// Propagate backward from lastDate
parallelizer.propagate(lastDate.shiftedBy(+1.0), firstDate.shiftedBy(-1.0));
}
observer.modelCalled(orbits, evaluations);
return new Pair<RealVector, RealMatrix>(value, jacobian);
} catch (OrekitException oe) {
throw new OrekitExceptionWrapper(oe);
}
}
use of org.hipparchus.util.Pair in project Orekit by CS-SI.
the class YUMAParser method loadData.
@Override
public void loadData(final InputStream input, final String name) throws IOException, ParseException, OrekitException {
// Clears the lists
almanacs.clear();
prnList.clear();
// Creates the reader
final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
try {
// Gathers data to create one GPSAlmanac from 13 consecutive lines
final List<Pair<String, String>> entries = new ArrayList<Pair<String, String>>(KEY.length);
// Reads the data one line at a time
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
// Try to split the line into 2 tokens as key:value
final String[] token = line.trim().split(":");
// If the line is made of 2 tokens
if (token.length == 2) {
// Adds these tokens as an entry to the entries
entries.add(new Pair<String, String>(token[0].trim(), token[1].trim()));
}
// If the number of entries equals the expected number
if (entries.size() == KEY.length) {
// Gets a GPSAlmanac from the entries
final GPSAlmanac almanac = getAlmanac(entries, name);
// Adds the GPSAlmanac to the list
almanacs.add(almanac);
// Adds the PRN number of the GPSAlmanac to the list
prnList.add(almanac.getPRN());
// Clears the entries
entries.clear();
}
}
} catch (IOException ioe) {
throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_YUMA_ALMANAC_FILE, name);
}
}
use of org.hipparchus.util.Pair in project Orekit by CS-SI.
the class OEMParserTest method testITRFFrames.
/**
* Check the parser can parse several ITRF frames. Test case for #361.
*
* @throws OrekitException on error.
*/
@Test
public void testITRFFrames() throws OrekitException {
// setup
Charset utf8 = StandardCharsets.UTF_8;
IERSConventions conventions = IERSConventions.IERS_2010;
boolean simpleEop = true;
Frame itrf2008 = FramesFactory.getITRF(conventions, simpleEop);
OEMParser parser = new OEMParser().withSimpleEOP(simpleEop).withConventions(conventions);
// frames to check
List<Pair<String, Frame>> frames = new ArrayList<>();
frames.add(new Pair<>("ITRF-93", Predefined.ITRF_2008_TO_ITRF_93.createTransformedITRF(itrf2008, "ITRF93")));
frames.add(new Pair<>("ITRF-97", Predefined.ITRF_2008_TO_ITRF_97.createTransformedITRF(itrf2008, "ITRF97")));
frames.add(new Pair<>("ITRF2000", Predefined.ITRF_2008_TO_ITRF_2000.createTransformedITRF(itrf2008, "ITRF2000")));
frames.add(new Pair<>("ITRF2005", Predefined.ITRF_2008_TO_ITRF_2005.createTransformedITRF(itrf2008, "ITRF2005")));
frames.add(new Pair<>("ITRF2008", itrf2008));
for (Pair<String, Frame> frame : frames) {
final String frameName = frame.getFirst();
InputStream pre = OEMParserTest.class.getResourceAsStream("/ccsds/OEMExample7.txt.pre");
InputStream middle = new ByteArrayInputStream(("REF_FRAME = " + frameName).getBytes(utf8));
InputStream post = OEMParserTest.class.getResourceAsStream("/ccsds/OEMExample7.txt.post");
InputStream input = new SequenceInputStream(pre, new SequenceInputStream(middle, post));
// action
OEMFile actual = parser.parse(input);
// verify
EphemeridesBlock actualBlock = actual.getEphemeridesBlocks().get(0);
Assert.assertEquals(actualBlock.getFrameString(), frameName);
// check expected frame
Frame actualFrame = actualBlock.getFrame();
Frame expectedFrame = frame.getSecond();
Assert.assertEquals(actualFrame.getName(), expectedFrame.getName());
Assert.assertEquals(actualFrame.getTransformProvider(), expectedFrame.getTransformProvider());
}
}
Aggregations