Skip to content

Commit

Permalink
refactor: propulsion system to use Reals instead of Scalar (#353)
Browse files Browse the repository at this point in the history
* refactor: propulsion system to use Reals instead of Scalar

* fix: shift to string issue
  • Loading branch information
apaletta3 authored Feb 16, 2024
1 parent e462123 commit 419c50e
Show file tree
Hide file tree
Showing 25 changed files with 157 additions and 350 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/// Apache License 2.0

#include <OpenSpaceToolkit/Physics/Unit.hpp>

#include <OpenSpaceToolkit/Astrodynamics/Flight/System/PropulsionSystem.hpp>

inline void OpenSpaceToolkitAstrodynamicsPy_Flight_System_PropulsionSystem(pybind11::module& aModule)
Expand All @@ -10,10 +8,6 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Flight_System_PropulsionSystem(pybin

using ostk::core::type::Real;

using ostk::physics::Unit;
using ostk::physics::unit::Mass;
using ostk::physics::data::Scalar;

using ostk::astrodynamics::flight::system::PropulsionSystem;

{
Expand All @@ -26,20 +20,6 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Flight_System_PropulsionSystem(pybin
)doc"
)

// .def(
// init([](const Real& thrust, const Unit& thrustUnit, const Real& specificImpulse, const Unit&
// specificImpulseUnit)
// {
// return PropulsionSystem(Scalar(thrust, thrustUnit), Scalar(specificImpulse,
// specificImpulseUnit));
// }
// ),
// arg("thrust"),
// arg("thrust_unit"),
// arg("specific_impulse"),
// arg("specific_unit")
// )

.def(
init<const Real&, const Real&>(),
R"doc(
Expand All @@ -56,8 +36,8 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Flight_System_PropulsionSystem(pybin
.def(self == self)
.def(self != self)

// .def("__str__", &(shiftToString<PropulsionSystem>))
// .def("__repr__", &(shiftToString<PropulsionSystem>))
.def("__str__", &(shiftToString<PropulsionSystem>))
.def("__repr__", &(shiftToString<PropulsionSystem>))

.def(
"is_defined",
Expand All @@ -70,10 +50,50 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Flight_System_PropulsionSystem(pybin
)doc"
)

// .def("get_thrust", &PropulsionSystem::getThrust)
// .def("get_specific_impulse", &PropulsionSystem::getSpecificImpulse)
// .def("get_mass_flow_rate", &PropulsionSystem::getMassFlowRate) Scalar output
// .def("get_acceleration", &PropulsionSystem::getAcceleration, arg("mass"))
.def(
"get_thrust",
&PropulsionSystem::getThrust,
R"doc(
Return the thrust.
Returns:
float: The thrust in Newton.
)doc"
)
.def(
"get_specific_impulse",
&PropulsionSystem::getSpecificImpulse,
R"doc(
Return the specific impulse.
Returns:
float: The specific impulse in Seconds.
)doc"
)
.def(
"get_mass_flow_rate",
&PropulsionSystem::getMassFlowRate,
R"doc(
Return the mass flow rate.
Returns:
float: The mass flow rate in Kilograms per Second.
)doc"
)
.def(
"get_acceleration",
&PropulsionSystem::getAcceleration,
arg("mass"),
R"doc(
Return the acceleration.
Args:
mass (float): Mass in Kilograms.
Returns:
float: The acceleration in Meters per Second squared.
)doc"
)

.def_static(
"undefined",
Expand Down
27 changes: 27 additions & 0 deletions bindings/python/test/flight/system/test_propulsion_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def propulsion_system() -> PropulsionSystem:
)


@pytest.fixture
def mass() -> Mass:
return Mass(90.0, Mass.Unit.Kilogram)


class TestPropulsionSystem:
def test_constructors(
self,
Expand All @@ -44,3 +49,25 @@ def test_is_defined(
propulsion_system: PropulsionSystem,
):
assert propulsion_system.is_defined()

def test_getters(
self,
propulsion_system: PropulsionSystem,
mass: Mass,
):
assert propulsion_system.get_thrust() == 1.0
assert propulsion_system.get_specific_impulse() == 150.0
assert propulsion_system.get_mass_flow_rate() is not None
assert propulsion_system.get_acceleration(mass) is not None

def test_static_methods(
self,
mass: Mass,
):
assert PropulsionSystem.undefined().is_defined() is False

assert PropulsionSystem.default().is_defined() is True
assert PropulsionSystem.default().get_thrust() is not None
assert PropulsionSystem.default().get_specific_impulse() is not None
assert PropulsionSystem.default().get_mass_flow_rate() is not None
assert PropulsionSystem.default().get_acceleration(mass) is not None
1 change: 0 additions & 1 deletion bindings/python/test/guidance_law/test_qlaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from ostk.physics.coordinate import Frame
from ostk.physics.unit import Length
from ostk.physics.unit import Angle
from ostk.physics.unit import Derived


from ostk.astrodynamics.trajectory.orbit.model.kepler import COE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

#include <OpenSpaceToolkit/Core/Type/Real.hpp>

#include <OpenSpaceToolkit/Physics/Data/Direction.hpp>
#include <OpenSpaceToolkit/Physics/Data/Scalar.hpp>
#include <OpenSpaceToolkit/Physics/Unit.hpp>
#include <OpenSpaceToolkit/Physics/Unit/Derived.hpp>
#include <OpenSpaceToolkit/Physics/Unit/Time.hpp>
#include <OpenSpaceToolkit/Physics/Unit/Mass.hpp>

namespace ostk
{
Expand All @@ -22,34 +18,12 @@ namespace system

using ostk::core::type::Real;

using ostk::physics::data::Direction;
using ostk::physics::data::Scalar;
using ostk::physics::unit::Length;
using ostk::physics::unit::Mass;
using ostk::physics::unit::Time;
using ostk::physics::unit::ElectricCurrent;
using ostk::physics::unit::Angle;
using ostk::physics::unit::Derived;
using ostk::physics::Unit;

/// @brief Define a propulsion system (constant thrust, constant Isp for now)
class PropulsionSystem
{
public:
static Unit thrustSIUnit;
static Unit specificImpulseSIUnit;
static Unit massFlowRateSIUnit; // TBI: Define in ostk physics as proper units

/// @brief Constructor
///
/// @code{.cpp}
/// PropulsionSystem propulsion = { ... };
/// @endcode
///
/// @param aThrust Thrust (scalar)
/// @param aSpecificImpulse Specific impulse (scalar)
PropulsionSystem(const Scalar& aThrust, const Scalar& aSpecificImpulse);

/// @brief Constructor
///
/// @code{.cpp}
Expand Down Expand Up @@ -93,39 +67,39 @@ class PropulsionSystem
/// @brief Get propulsion system's thrust
///
/// @code{.cpp}
/// Scalar thrust = propulsionSystem.getThrust();
/// Real thrust = propulsionSystem.getThrust();
/// @endcode
///
/// @return Scalar
Scalar getThrust() const;
/// @return Real
Real getThrust() const;

/// @brief Get propulsion system's specific impulse
/// https://en.wikipedia.org/wiki/Specific_impulse
///
/// @code{.cpp}
/// Scalar specificImpulse = propulsionSystem.getSpecificImpulse();
/// Real specificImpulse = propulsionSystem.getSpecificImpulse();
/// @endcode
///
/// @return Scalar
Scalar getSpecificImpulse() const;
/// @return Real
Real getSpecificImpulse() const;

/// @brief Get propulsion system's mass flow rate
///
/// @code{.cpp}
/// Scalar massFlowRate = propulsionSystem.getMassFlowRate();
/// Real massFlowRate = propulsionSystem.getMassFlowRate();
/// @endcode
///
/// @return Scalar
Scalar getMassFlowRate() const;
/// @return Real
Real getMassFlowRate() const;

/// @brief Get propulsion system's acceleration
///
/// @code{.cpp}
/// Scalar acceleration = propulsionSystem.getAcceleration();
/// Real acceleration = propulsionSystem.getAcceleration();
/// @endcode
///
/// @return Scalar
Scalar getAcceleration(const Mass& aMass) const;
/// @return Real
Real getAcceleration(const Mass& aMass) const;

/// @brief Undefined propulsion system
///
Expand All @@ -146,9 +120,9 @@ class PropulsionSystem
static PropulsionSystem Default();

private:
Scalar thrust_ = Scalar::Undefined(); /// Thrust [N]
Scalar specificImpulse_ = Scalar::Undefined(); /// Specific impulse [s]
Scalar massFlowRate_ = Scalar::Undefined(); /// Mass flow rate [kg/s]
Real thrust_; /// Thrust [N]
Real specificImpulse_; /// Specific impulse [s]
Real massFlowRate_; /// Mass flow rate [kg/s]
};

} // namespace system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <OpenSpaceToolkit/Mathematics/Object/Vector.hpp>

#include <OpenSpaceToolkit/Physics/Data/Direction.hpp>
#include <OpenSpaceToolkit/Physics/Time/Instant.hpp>

#include <OpenSpaceToolkit/Astrodynamics/Dynamics/Thruster.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ using ostk::astrodynamics::trajectory::state::CoordinateSubset;
using ostk::astrodynamics::trajectory::state::coordinatesubset::CartesianPosition;
using ostk::astrodynamics::trajectory::state::coordinatesubset::CartesianVelocity;

static const Derived::Unit GravitationalParameterSIUnit =
Derived::Unit::GravitationalParameter(Length::Unit::Meter, Time::Unit::Second);

AtmosphericDrag::AtmosphericDrag(const Shared<const Celestial>& aCelestialSPtr)
: AtmosphericDrag(aCelestialSPtr, String::Format("Atmospheric Drag [{}]", aCelestialSPtr->getName()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@ namespace dynamics
using ostk::mathematics::object::Vector3d;

using ostk::physics::coordinate::Position;
using ostk::physics::data::Vector;
using ostk::physics::unit::Derived;
using ostk::physics::unit::Length;
using ostk::physics::unit::Time;

using ostk::astrodynamics::trajectory::state::coordinatesubset::CartesianPosition;
using ostk::astrodynamics::trajectory::state::coordinatesubset::CartesianVelocity;

static const Derived::Unit GravitationalParameterSIUnit =
Derived::Unit::GravitationalParameter(Length::Unit::Meter, Time::Unit::Second);

CentralBodyGravity::CentralBodyGravity(const Shared<const Celestial>& aCelestialObjectSPtr)
: CentralBodyGravity(
aCelestialObjectSPtr, String::Format("Central Body Gravity [{}]", aCelestialObjectSPtr->getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <OpenSpaceToolkit/Core/Error.hpp>
#include <OpenSpaceToolkit/Core/Utility.hpp>

#include <OpenSpaceToolkit/Physics/Data/Scalar.hpp>

#include <OpenSpaceToolkit/Astrodynamics/Dynamics/PositionDerivative.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/CartesianPosition.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/CartesianVelocity.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@ using ostk::core::type::String;
using ostk::mathematics::object::Vector3d;

using ostk::physics::coordinate::Position;
using ostk::physics::data::Vector;
using ostk::physics::unit::Derived;
using ostk::physics::unit::Length;
using ostk::physics::unit::Time;

using ostk::astrodynamics::trajectory::state::coordinatesubset::CartesianPosition;
using ostk::astrodynamics::trajectory::state::coordinatesubset::CartesianVelocity;

static const Derived::Unit GravitationalParameterSIUnit =
Derived::Unit::GravitationalParameter(Length::Unit::Meter, Time::Unit::Second);

ThirdBodyGravity::ThirdBodyGravity(const Shared<const Celestial>& aCelestialObjectSPtr)
: ThirdBodyGravity(aCelestialObjectSPtr, String::Format("Third Body Gravity [{}]", aCelestialObjectSPtr->getName()))
{
Expand Down
5 changes: 2 additions & 3 deletions src/OpenSpaceToolkit/Astrodynamics/Dynamics/Thruster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ Thruster::Thruster(
satelliteSystem_(aSatelliteSystem),
guidanceLaw_(aGuidanceLaw),
massFlowRateCache_(
aSatelliteSystem.isDefined() ? aSatelliteSystem.accessPropulsionSystem().getMassFlowRate().getValue()
: Real::Undefined()
aSatelliteSystem.isDefined() ? aSatelliteSystem.accessPropulsionSystem().getMassFlowRate() : Real::Undefined()
)
{
}
Expand Down Expand Up @@ -93,7 +92,7 @@ VectorXd Thruster::computeContribution(
}

const Real maximumThrustAccelerationMagnitude =
satelliteSystem_.accessPropulsionSystem().getAcceleration(Mass::Kilograms(x[6])).getValue();
satelliteSystem_.accessPropulsionSystem().getAcceleration(Mass::Kilograms(x[6]));

const Vector3d acceleration = guidanceLaw_->calculateThrustAccelerationAt(
anInstant, positionCoordinates, velocityCoordinates, maximumThrustAccelerationMagnitude, aFrameSPtr
Expand Down
Loading

0 comments on commit 419c50e

Please sign in to comment.