Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion mojito/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ target_sources(
FILE_SET HEADERS
BASE_DIRS include
FILES
include/mojito/ab_bc_ca.hpp
include/mojito/abc.hpp
include/mojito/alphabeta.hpp
include/mojito/angle_wrapped.hpp
include/mojito/constants.hpp
include/mojito/divisor.hpp
include/mojito/reference_frame.hpp
include/mojito/dq.hpp
include/mojito/math.hpp
include/mojito/mojito.hpp
include/mojito/pu_conversion.hpp
include/mojito/quantity_cast.hpp
include/mojito/transform.hpp
include/mojito/type_traits.hpp
include/mojito/types.hpp
include/mojito/units.hpp)
Expand Down
2 changes: 0 additions & 2 deletions mojito/include/mojito/alphabeta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ class alphabeta {
return rotate_counter_clockwise(angle_wrapped(-theta.get_radians()));
}

constexpr alphabeta<T> rotate(const angle_wrapped& theta) const { return rotate_counter_clockwise(theta); }

constexpr alphabeta<T> operator+(const alphabeta<T>& other) const
{
return alphabeta<T>{_values[0] + other._values[0], _values[1] + other._values[1]};
Expand Down
2 changes: 0 additions & 2 deletions mojito/include/mojito/dq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class dq {
return rotate_counter_clockwise(angle_wrapped(-theta.get_radians()));
}

constexpr dq<T> rotate(const angle_wrapped& theta) const { return rotate_counter_clockwise(theta); }

constexpr dq<T> operator+(const dq<T>& other) const
{
return dq<T>{_values[0] + other._values[0], _values[1] + other._values[1]};
Expand Down
72 changes: 72 additions & 0 deletions mojito/include/mojito/math.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#ifndef MOJITO_MATH_HPP
#define MOJITO_MATH_HPP

#include <algorithm>
#include <type_traits>

#include "abc.hpp"
#include "alphabeta.hpp"
#include "dq.hpp"

namespace mojito {

template <typename Frame, typename T = typename Frame::value_type>
constexpr T cross_product(const Frame& a, const Frame& b)
{
if constexpr (std::is_same_v<Frame, alphabeta<T>>) {
return a.alpha() * b.beta() - a.beta() * b.alpha();
}
else if constexpr (std::is_same_v<Frame, dq<T>>) {
return a.d() * b.q() - a.q() * b.d();
}
else {
static_assert(std::is_same_v<Frame, alphabeta<T>> || std::is_same_v<Frame, dq<T>>,
"cross_product only supports alphabeta and dq frames");
}
}

template <typename T>
T sum(abc<T> const& value)
{
return value.a() + value.b() + value.c();
}

template <typename T>
T max(abc<T> const& value)
{
return std::max({value.a(), value.b(), value.c()});
}

template <typename T>
T max(alphabeta<T> const& value)
{
return std::max({value.alpha(), value.beta()});
}

template <typename T>
T max(dq<T> const& value)
{
return std::max({value.d(), value.q()});
}

template <typename T>
T min(abc<T> const& value)
{
return std::min({value.a(), value.b(), value.c()});
}

template <typename T>
T min(alphabeta<T> const& value)
{
return std::min({value.alpha(), value.beta()});
}

template <typename T>
T min(dq<T> const& value)
{
return std::min({value.d(), value.q()});
}

} // namespace mojito

#endif // MOJITO_MATH_HPP
3 changes: 3 additions & 0 deletions mojito/include/mojito/mojito.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
#include "dq.hpp"
#include "ab_bc_ca.hpp"
#include "transform.hpp"
#include "math.hpp"
#include "pu_conversion.hpp"
#include "quantity_cast.hpp"

#endif // MOJITO_HPP
80 changes: 80 additions & 0 deletions mojito/include/mojito/pu_conversion.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef MOJITO_PU_CONVERSION_HPP
#define MOJITO_PU_CONVERSION_HPP

#include "abc.hpp"
#include "alphabeta.hpp"
#include "dq.hpp"
#include "divisor.hpp"
#include "units.hpp"

namespace mojito {

template <typename Dim>
constexpr auto to_si(const abc<quantity<Dim, per_unit>>& pu_frame, const quantity<Dim, si>& base_quantity)
{
using result_quantity_t = decltype(to_si(pu_frame.a(), base_quantity));
return abc<result_quantity_t>(to_si(pu_frame.a(), base_quantity), to_si(pu_frame.b(), base_quantity),
to_si(pu_frame.c(), base_quantity));
}

template <typename Dim>
constexpr auto to_pu(const abc<quantity<Dim, si>>& si_frame, const quantity<Dim, si>& base_quantity)
{
using result_quantity_t = decltype(to_pu(si_frame.a(), base_quantity));
return abc<result_quantity_t>(to_pu(si_frame.a(), base_quantity), to_pu(si_frame.b(), base_quantity),
to_pu(si_frame.c(), base_quantity));
}

template <typename Dim>
constexpr auto to_si(const alphabeta<quantity<Dim, per_unit>>& pu_frame, const quantity<Dim, si>& base_quantity)
{
using result_quantity_t = decltype(to_si(pu_frame.alpha(), base_quantity));
return alphabeta<result_quantity_t>(to_si(pu_frame.alpha(), base_quantity), to_si(pu_frame.beta(), base_quantity));
}

template <typename Dim>
constexpr auto to_pu(const alphabeta<quantity<Dim, si>>& si_frame, const quantity<Dim, si>& base_quantity)
{
using result_quantity_t = decltype(to_pu(si_frame.alpha(), base_quantity));
return alphabeta<result_quantity_t>(to_pu(si_frame.alpha(), base_quantity), to_pu(si_frame.beta(), base_quantity));
}

template <typename Dim>
constexpr auto to_si(const dq<quantity<Dim, per_unit>>& pu_frame, const quantity<Dim, si>& base_quantity)
{
using result_quantity_t = decltype(to_si(pu_frame.d(), base_quantity));
return dq<result_quantity_t>(to_si(pu_frame.d(), base_quantity), to_si(pu_frame.q(), base_quantity));
}

template <typename Dim>
constexpr auto to_pu(const dq<quantity<Dim, si>>& si_frame, const quantity<Dim, si>& base_quantity)
{
using result_quantity_t = decltype(to_pu(si_frame.d(), base_quantity));
return dq<result_quantity_t>(to_pu(si_frame.d(), base_quantity), to_pu(si_frame.q(), base_quantity));
}

template <typename Dim>
constexpr auto to_pu(const abc<quantity<Dim, si>>& si_frame, const divisor<quantity<Dim, si>>& divisor)
{
using result_quantity_t = decltype(to_pu(si_frame.a(), divisor));
return abc<result_quantity_t>(to_pu(si_frame.a(), divisor), to_pu(si_frame.b(), divisor),
to_pu(si_frame.c(), divisor));
}

template <typename Dim>
constexpr auto to_pu(const alphabeta<quantity<Dim, si>>& si_frame, const divisor<quantity<Dim, si>>& divisor)
{
using result_quantity_t = decltype(to_pu(si_frame.alpha(), divisor));
return alphabeta<result_quantity_t>(to_pu(si_frame.alpha(), divisor), to_pu(si_frame.beta(), divisor));
}

template <typename Dim>
constexpr auto to_pu(const dq<quantity<Dim, si>>& si_frame, const divisor<quantity<Dim, si>>& divisor)
{
using result_quantity_t = decltype(to_pu(si_frame.d(), divisor));
return dq<result_quantity_t>(to_pu(si_frame.d(), divisor), to_pu(si_frame.q(), divisor));
}

} // namespace mojito

#endif // MOJITO_PU_CONVERSION_HPP
69 changes: 69 additions & 0 deletions mojito/include/mojito/quantity_cast.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef MOJITO_QUANTITY_CAST_HPP
#define MOJITO_QUANTITY_CAST_HPP

#include <algorithm>

#include "abc.hpp"
#include "alphabeta.hpp"
#include "dq.hpp"
#include "types.hpp"

namespace mojito {

template <typename QuantityType>
abc<QuantityType> to_dimension_abc(const abc<real_t>& scalar_abc)
{
abc<QuantityType> quantity_abc{};
std::transform(scalar_abc.begin(), scalar_abc.end(), quantity_abc.begin(),
[](real_t val) { return QuantityType{val}; });
return quantity_abc;
}

template <typename QuantityType>
alphabeta<QuantityType> to_dimension_alphabeta(const alphabeta<real_t>& scalar_alphabeta)
{
alphabeta<QuantityType> quantity_alphabeta{};
std::transform(scalar_alphabeta.begin(), scalar_alphabeta.end(), quantity_alphabeta.begin(),
[](real_t val) { return QuantityType{val}; });
return quantity_alphabeta;
}

template <typename QuantityType>
dq<QuantityType> to_dimension_dq(const dq<real_t>& scalar_dq)
{
dq<QuantityType> quantity_dq{};
std::transform(scalar_dq.begin(), scalar_dq.end(), quantity_dq.begin(),
[](real_t val) { return QuantityType{val}; });
return quantity_dq;
}

template <typename QuantityType>
abc<real_t> to_dimensionless_abc(const abc<QuantityType>& quantity_abc)
{
abc<real_t> scalar_abc{};
std::transform(quantity_abc.begin(), quantity_abc.end(), scalar_abc.begin(),
[](const QuantityType& val) { return val.value(); });
return scalar_abc;
}

template <typename QuantityType>
alphabeta<real_t> to_dimensionless_alphabeta(const alphabeta<QuantityType>& quantity_alphabeta)
{
alphabeta<real_t> scalar_alphabeta{};
std::transform(quantity_alphabeta.begin(), quantity_alphabeta.end(), scalar_alphabeta.begin(),
[](const QuantityType& val) { return val.value(); });
return scalar_alphabeta;
}

template <typename QuantityType>
dq<real_t> to_dimensionless_dq(const dq<QuantityType>& quantity_dq)
{
dq<real_t> scalar_dq{};
std::transform(quantity_dq.begin(), quantity_dq.end(), scalar_dq.begin(),
[](const QuantityType& val) { return val.value(); });
return scalar_dq;
}

} // namespace mojito

#endif // MOJITO_QUANTITY_CAST_HPP
Loading
Loading