From 6c2058e09d09f804fc7a59361f795142b81d87da Mon Sep 17 00:00:00 2001 From: Vishwa Shah Date: Wed, 18 Oct 2023 09:39:29 -0700 Subject: [PATCH] fix: fix extra state being observed in integrating with conditions (#256) * fix: fix extra state logging in integrating with conditions * chore: add test --- .../Trajectory/Segment.cpp | 3 +++ .../Trajectory/Sequence.cpp | 3 +++ .../Astrodynamics/Trajectory/State/NumericalSolver.cpp | 1 - .../Astrodynamics/Trajectory/Sequence.test.cpp | 10 ++++++++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Segment.cpp b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Segment.cpp index 65a880c21..cc066d580 100644 --- a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Segment.cpp +++ b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Segment.cpp @@ -18,6 +18,9 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Segment(pybind11::module& class_(aModule, "SegmentSolution") + .def("__str__", &(shiftToString)) + .def("__repr__", &(shiftToString)) + .def_readonly("name", &Segment::Solution::name) .def_readonly("dynamics", &Segment::Solution::dynamics) .def_readonly("states", &Segment::Solution::states) diff --git a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Sequence.cpp b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Sequence.cpp index 2762fdc4e..2c13cfb85 100644 --- a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Sequence.cpp +++ b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Sequence.cpp @@ -21,6 +21,9 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Sequence(pybind11::module class_(aModule, "SequenceSolution") + .def("__str__", &(shiftToString)) + .def("__repr__", &(shiftToString)) + .def_readonly("segment_solutions", &Sequence::Solution::segmentSolutions) .def_readonly("execution_is_complete", &Sequence::Solution::executionIsComplete) diff --git a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/NumericalSolver.cpp b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/NumericalSolver.cpp index 55a11a3ab..8c005aede 100644 --- a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/NumericalSolver.cpp +++ b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/NumericalSolver.cpp @@ -164,7 +164,6 @@ NumericalSolver::ConditionSolution NumericalSolver::integrateTime( // initialize stepper double currentTime = 0.0; stepper.initialize(aState.accessCoordinates(), currentTime, signedTimeStep); - observeState(aState); // do first step double previousTime; diff --git a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp index 5fe97e3d0..b7dfda046 100644 --- a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp +++ b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp @@ -25,6 +25,7 @@ using ostk::core::ctnr::Array; using ostk::core::types::Shared; using ostk::core::types::Size; +using ostk::core::types::Index; using ostk::core::types::Real; using ostk::math::geom::d3::objects::Composite; @@ -430,11 +431,18 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Solve_2) EXPECT_EQ(solution.accessStartInstant(), Instant::J2000()); EXPECT_EQ(solution.accessEndInstant(), solution.segmentSolutions.accessLast().states.accessLast().accessInstant()); + const Array solutionStates = solution.getStates(); + + for (Index i = 1; i < solutionStates.getSize(); ++i) + { + EXPECT_TRUE(solutionStates[i].accessInstant() > solutionStates[i - 1].accessInstant()); + } EXPECT_DOUBLE_EQ(solution.getInitialMass().inKilograms(), mass + 100.0); EXPECT_DOUBLE_EQ( solution.getFinalMass().inKilograms(), solution.segmentSolutions.accessLast().states.accessLast().accessCoordinates()[6] ); + EXPECT_EQ(solution.getPropagationDuration(), solution.accessEndInstant() - solution.accessStartInstant()); EXPECT_DOUBLE_EQ( solution.computeDeltaMass().inKilograms(), @@ -446,8 +454,6 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Solve_2) std::log(solution.getInitialMass().inKilograms() / solution.getFinalMass().inKilograms()), 1e-3 ); - - EXPECT_EQ(solution.getPropagationDuration(), solution.accessEndInstant() - solution.accessStartInstant()); } TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Print)