diff options
-rw-r--r-- | c++/converter.hpp | 28 | ||||
-rw-r--r-- | c++/lbm_unit.hpp | 44 | ||||
-rw-r--r-- | tests/converter.cpp | 18 |
3 files changed, 82 insertions, 8 deletions
diff --git a/c++/converter.hpp b/c++/converter.hpp index e07847f..f3c3518 100644 --- a/c++/converter.hpp +++ b/c++/converter.hpp @@ -4,10 +4,38 @@ namespace kel { namespace lbm { + +template<typename T> class converter { private: + saw::data<saw::unit_division<T, LbmMeter<T>, SiMeter<T> >> meter_conv_; + saw::data<saw::unit_division<T, LbmSecond<T>, SiSecond<T> >> second_conv_; public: converter() = delete; + converter( + saw::data<saw::unit_division<T, LbmMeter<T>, SiMeter<T> >> meter_conv__, + saw::data<saw::unit_division<T, LbmSecond<T>, SiSecond<T> >> second_conv__ + ): + meter_conv_{meter_conv__}, + second_conv_{second_conv__} + {} + + saw::data<sch::LbmMeter<T>> meter_si_to_lbm(const saw::data<sch::SiMeter<T>>& m_si){ + return m_si * meter_conv_; + } + + saw::data<sch::LbmSecond<T>> second_si_to_lbm(const saw::data<sch::SiSecond<T>>& s_si){ + return s_si * second_conv_; + } + + saw::data<sch::LbmVelocity<T>> velocity_si_to_lbm(const saw::data<sch::SiVelocity<T>>& vel_si){ + return vel_si * meter_conv_ / second_conv_; + } + + saw::data<sch::LbmAcceleration<T>> acceleration_si_to_lbm(const saw::data<sch::SiAcceleration<T>>& acc_si){ + return acc_si * meter_conv_ / (second_conv_ * second_conv_); + } + }; } } diff --git a/c++/lbm_unit.hpp b/c++/lbm_unit.hpp index dc1f8e9..4cb9b52 100644 --- a/c++/lbm_unit.hpp +++ b/c++/lbm_unit.hpp @@ -8,26 +8,54 @@ namespace kel { namespace lbm { namespace lbm_type { struct meter { - static constexpr std::string_view name = "meter_l"; - static constexpr std::string_view short_name = "m_l"; + static constexpr std::string_view name = "meter_lbm"; + static constexpr std::string_view short_name = "m_lbm"; }; struct second { - static constexpr std::string_view name = "second_l"; - static constexpr std::string_view short_name = "s_l"; + static constexpr std::string_view name = "second_lbm"; + static constexpr std::string_view short_name = "s_lbm"; }; } +namespace si_type { +struct meter { + static constexpr std::string_view name = "meter_si"; + static constexpr std::string_view short_name = "m_si"; +}; + +struct second { + static constexpr std::string_view name = "second_si"; + static constexpr std::string_view short_name = "s_si"; +}; +} + +namesapce sch { + +template<typename S> +using SiMeter = schema::Unit<S, schema::UnitElement<si_type::meter, 1>>; + +template<typename S> +using LbmMeter = schema::Unit<S, schema::UnitElement<lbm_type::meter, 1>>; + +template<typename S> +using SiSecond = schema::Unit<S, schema::UnitElement<si_type::meter, 1>>; + template<typename S> -using lbm_meter = unit<S, unit_component<lbm_type::meter, 1>>; +using LbmSecond = schema::Unit<S, schema::UnitElement<lbm_type::second, 1>>; template<typename S> -using lbm_second = unit<S, unit_component<lbm_type::second, 1>>; +using SiVelocity = schema::Unit<S, schema::UnitElement<si_type::meter, 1>, schema::UnitElement<si_type::second, -1>>; template<typename S> -using lbm_velocity = unit<S, unit_component<lbm_type::meter, 1>, unit_component<lbm_type::second, -1>>; +using LbmVelocity = schema::Unit<S, schema::UnitElement<lbm_type::meter, 1>, schema::UnitElement<lbm_type::second, -1>>; template<typename S> -using lbm_acceleration = unit<S, unit_component<lbm_type::meter, 1>, unit_component<lbm_type::second, -2>>; +using SiAcceleration = schema::Unit<S, schema::UnitElement<si_type::meter, 1>, schema::UnitElement<si_type::second, -2>>; + +template<typename S> +using LbmAcceleration = schema::Unit<S, schema::UnitElement<lbm_type::meter, 1>, schema::UnitElement<lbm_type::second, -2>>; + +} } } diff --git a/tests/converter.cpp b/tests/converter.cpp new file mode 100644 index 0000000..3c66348 --- /dev/null +++ b/tests/converter.cpp @@ -0,0 +1,18 @@ +#include <forstio/test/suite.hpp> + +#include "../c++/converter.hpp" + + +namespace { +namespace sch { +using namespace kel::lbm::sch; + +using T = Float64; +} + +SAW_TEST("Meter"){ + using namespace kel; + + lbm::converter<sch::T> converter; +} +} |