Skip to content

Commit

Permalink
feat: address remaining feedback and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwa2710 committed Oct 17, 2023
1 parent 27724b5 commit 8ce5c2f
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Sequence(pybind11::module
const Size&,
const NumericalSolver&,
const Array<Shared<Dynamics>>&,
const Duration&>(),
const Duration&,
const Size&>(),
arg("segments") = Array<Segment>::Empty(),
arg("repetition_count") = 1,
arg("numerical_solver") = NumericalSolver::DefaultConditional(),
arg("dynamics") = Array<Shared<Dynamics>>::Empty(),
arg("maximum_propagation_duration") = Duration::Days(30.0)
arg("maximum_propagation_duration") = Duration::Days(30.0),
arg("verbosity") = 1
)

.def("__str__", &(shiftToString<Sequence>))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ class Sequence
/// @param [in] aNumericalSolver A Numerical Solver. Defaults to Undefined.
/// @param [in] aDynamicsArray An array of shared dynamics. Defaults to empty.
/// @param [in] maximumPropagationDuration Maximum duration for propagation. Defaults to 7.0 days.
/// @param [in] verbose Verbosity level for the solver. Defaults to 5.
/// @param [in] verbosity Verbosity level for the solver [0 (low) - 5 (high)]. Defaults to 0.

Sequence(
const Array<Segment>& aSegmentArray = Array<Segment>::Empty(),
const Size& aRepetitionCount = 1,
const NumericalSolver& aNumericalSolver = NumericalSolver::Undefined(),
const Array<Shared<Dynamics>>& aDynamicsArray = Array<Shared<Dynamics>>::Empty(),
const Duration& maximumPropagationDuration = Duration::Days(7.0),
const Integer& verbose = 1
const Size& verbosity = 0
);

/// @brief Output stream operator.
Expand Down
21 changes: 13 additions & 8 deletions src/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,46 @@ Sequence::Sequence(
const NumericalSolver& aNumericalSolver,
const Array<Shared<Dynamics>>& aDynamicsArray,
const Duration& maximumPropagationDuration,
const Integer& verbose
const Size& verbosity
)
: segments_(aSegmentArray),
repetitionCount_(aRepetitionCount),
numericalSolver_(aNumericalSolver),
dynamics_(aDynamicsArray),
maximumPropagationDuration_(maximumPropagationDuration)
{
if (verbose == 0)
if (verbosity == 5)
{
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::trace);
}
else if (verbose == 1)
else if (verbosity == 4)
{
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::debug);
}
else if (verbose == 2)
else if (verbosity == 3)
{
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info);
}
else if (verbose == 3)
else if (verbosity == 2)
{
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::warning);
}
else if (verbose == 4)
else if (verbosity == 1)
{
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::error);
}
else if (verbose == 5)
else if (verbosity == 0)
{
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::fatal);
}
else
{
throw ostk::core::error::runtime::Wrong("Verbose level");
throw ostk::core::error::runtime::Wrong("verbosity level");
}

if (repetitionCount_ < 1)
{
throw ostk::core::error::runtime::Wrong("Repetition count");
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/OpenSpaceToolkit/Astrodynamics/Trajectory/Segment.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Segment, SegmentSolution_Print)
}
}

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Segment, SegmentSolution_StreamOperator)
{
{
testing::internal::CaptureStdout();

const Segment::Solution segmentSolution = Segment::Solution(
defaultName_, defaultDynamics_, {initialStateWithMass_, finalStateWithMass_}, true, Segment::Type::Maneuver
);

EXPECT_NO_THROW(std::cout << segmentSolution << std::endl);

EXPECT_FALSE(testing::internal::GetCapturedStdout().empty());
}
}

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Segment, Coast)
{
{
Expand Down
113 changes: 108 additions & 5 deletions test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, SequenceSolution_Prin
}
}

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, SequenceSolution_StreamOperator)
{
{
testing::internal::CaptureStdout();

const Segment::Solution segmentSolution = {
"A Segment", {}, {defaultState_, defaultState_}, true, Segment::Type::Coast
};

EXPECT_NO_THROW(std::cout << segmentSolution << std::endl);

EXPECT_FALSE(testing::internal::GetCapturedStdout().empty());
}
}

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Constructor)
{
{
Expand All @@ -154,7 +169,13 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Constructor)
}

{
EXPECT_NO_THROW(Sequence sequence(defaultSegments_, defaultRepetitionCount_));
{
EXPECT_NO_THROW(Sequence sequence(defaultSegments_, defaultRepetitionCount_));
}

{
EXPECT_THROW(Sequence sequence(defaultSegments_, 0), ostk::core::error::runtime::Wrong);
}
}

{
Expand All @@ -176,6 +197,36 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Constructor)
defaultMaximumPropagationDuration_
));
}

{
{
for (Size verbosity = 0; verbosity <= 5; ++verbosity)
{
EXPECT_NO_THROW(Sequence sequence(
defaultSegments_,
defaultRepetitionCount_,
defaultNumericalSolver_,
defaultDynamics_,
defaultMaximumPropagationDuration_,
verbosity
));
}
}

{
EXPECT_THROW(
Sequence sequence(
defaultSegments_,
defaultRepetitionCount_,
defaultNumericalSolver_,
defaultDynamics_,
defaultMaximumPropagationDuration_,
6
),
ostk::core::error::runtime::Wrong
);
}
}
}

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, StreamOperator)
Expand Down Expand Up @@ -401,9 +452,61 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Solve_2)

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Print)
{
testing::internal::CaptureStdout();
{
testing::internal::CaptureStdout();

EXPECT_NO_THROW(defaultSequence_.print(std::cout, true));
EXPECT_NO_THROW(defaultSequence_.print(std::cout, false));
EXPECT_FALSE(testing::internal::GetCapturedStdout().empty());
}

{
const Composite satelliteGeometry(Cuboid(
{0.0, 0.0, 0.0},
{Vector3d {1.0, 0.0, 0.0}, Vector3d {0.0, 1.0, 0.0}, Vector3d {0.0, 0.0, 1.0}},
{1.0, 2.0, 3.0}
));

const PropulsionSystem propulsionSystem = PropulsionSystem(1.0, 1500.0);

const SatelliteSystem satelliteSystem = {
Mass::Kilograms(100.0),
satelliteGeometry,
Matrix3d::Identity(),
500.0,
2.1,
propulsionSystem,
};

Sequence sequence = {
Array<Segment>::Empty(),
defaultRepetitionCount_,
defaultNumericalSolver_,
defaultDynamics_,
defaultMaximumPropagationDuration_,
};

sequence.addCoastSegment(std::make_shared<RealCondition>(COECondition::SemiMajorAxis(
RealCondition::Criterion::AnyCrossing,
Frame::GCRF(),
Length::Kilometers(6999.5),
EarthGravitationalModel::EGM2008.gravitationalParameter_
)));

EXPECT_NO_THROW(defaultSequence_.print(std::cout, true));
EXPECT_NO_THROW(defaultSequence_.print(std::cout, false));
EXPECT_FALSE(testing::internal::GetCapturedStdout().empty());
sequence.addManeuverSegment(
std::make_shared<RealCondition>(COECondition::SemiMajorAxis(
RealCondition::Criterion::AnyCrossing,
Frame::GCRF(),
Length::Kilometers(7000.0),
EarthGravitationalModel::EGM2008.gravitationalParameter_
)),
std::make_shared<ConstantThrust>(ConstantThrust::Intrack(satelliteSystem))
);

testing::internal::CaptureStdout();

EXPECT_NO_THROW(sequence.print(std::cout, true));
EXPECT_NO_THROW(sequence.print(std::cout, false));
EXPECT_FALSE(testing::internal::GetCapturedStdout().empty());
}
}

0 comments on commit 8ce5c2f

Please sign in to comment.