mpusz / mp-units

The quantities and units library for C++
https://mpusz.github.io/mp-units/
MIT License
1.1k stars 89 forks source link

Parameterized quantities #475

Open JohelEGP opened 1 year ago

JohelEGP commented 1 year ago

Parameterized quantities

I have identified 2 kinds of parameterized quantities.

Same quantity name for different quantities

This kind of quantity shares its name between different quantities in the parts of ISO 80000. For example:

https://github.com/mpusz/mp-units/blob/60a564a86700804e306f0d73a1521ea6e4abe377/src/systems/isq/include/mp-units/systems/isq/mechanics.h#L89 https://github.com/mpusz/mp-units/blob/60a564a86700804e306f0d73a1521ea6e4abe377/src/systems/isq/include/mp-units/systems/isq/electromagnetism.h#L111

Same quantity, actually parameterized

Some quantities from ISO 80000-7:2019 (light and radiation) are parameterized on a photometric condition.

Amount of substance is parameterized on “elementary entity” (ISO 80000-9:2019 9.2). And thus many quantities in part 9 are equally parameterized. The standard has some remarks on the structure of an “elementary entity”. Like https://github.com/mpusz/mp-units/issues/35#issuecomment-1655365069,

It would also help to have the input from people familiar with the domain.

Previous work

I had previously started a code specification for the quantities, and this is how I did it.

struct context { };
inline constexpr context mechanics;
inline constexpr context thermodynamics;
inline constexpr context electromagnetism;
inline constexpr context light_and_optical_radiation;
inline constexpr context radiometry;
inline constexpr context acoustics;
inline constexpr context in_a_mixture;
inline constexpr context in_a_solution;
inline constexpr context pressure_basis;
inline constexpr context concentration_basis;
inline constexpr context atomic_physics;
inline constexpr context ionizing_radiation;

struct photometric_condition { };
inline constexpr photometric_condition photopic_vision = {};
inline constexpr photometric_condition scotopic_vision = {};
inline constexpr photometric_condition mesopic_vision  = {};

template<const context&> extern const quantity efficiency;
template<const context&> extern const quantity power;
template<const photometric_condition&> extern const quantity luminous_efficacy_of_radiation;
template<const photometric_condition&> extern const quantity maximum_luminous_efficacy;
template<const context& = light_and_optical_radiation> extern const quantity reflectance;
template<const context& = light_and_optical_radiation> extern const quantity transmittance;
template<const context&> extern const quantity linear_attenuation_coefficient;
template<const context&> extern const quantity mass_attenuation_coefficient;
template<const context&> extern const quantity standard_absolute_activity;
template<const context&> extern const quantity equilibrium_constant;
template<const context&> extern const quantity magnetic_dipole_moment;
template<const context&> extern const quantity radiant_energy;

// ### ISO 80000-4:2019, Part 4: Mechanics.
template<> inline constexpr auto power<mechanics> = defn<"𝘗", "𝘗 = 𝙁 ⋅ 𝙫", force("𝙁"), velocity("𝙫")>();

// ### IEC 80000-6:2008, Part 6: Electromagnetism.
inline constexpr auto power<electromagnetism> = defn<"𝘱", "𝘱 = 𝘶𝘪", voltage("𝘶"), electric_current("𝘪")>();

// ### ISO 80000-9:2019, Part 9: Physical chemistry and molecular physics.
inline constexpr auto number_of_entities   = defn<"𝘕(X)", "dim 𝘕(X) = 1">();
inline constexpr auto amount_of_substance  = defn<"𝘯(X)", "𝘯(X) = 𝘕(X)/𝘕_A", number_of_entities("𝘕(X)"), Avogadro_constant("𝘕_A")>();

template<> inline constexpr auto standard_absolute_activity<in_a_mixture> = defn<"𝜆_X^⊝", "𝜆_X^⊝ = 𝜆 ⃰_X(𝘱^⊝)", "𝘱^⊝ = 10⁵ Pa", absolute_activity("𝜆_X"), pressure("𝘱")>();

template<> inline constexpr auto standard_absolute_activity<in_a_solution> = defn<"𝜆_B^⊝", "𝜆_B^⊝ = lim_{∑𝘣_B→0}[𝜆_B((𝘱^⊝)𝘣^⊝/𝘣_B)]", "𝘱^⊝ = 10⁵ Pa", molality("𝘣"), absolute_activity("𝜆_B"), pressure("𝘱")>();

template<> inline constexpr auto equilibrium_constant<pressure_basis>      = defn<"𝘒_𝘱", "𝘒_𝘱 = ∏_B(𝘱_B)^{𝘷_B}", partial_pressure("𝘱"), stoichiometric_number_of_substance("𝘷_B")>();
template<> inline constexpr auto equilibrium_constant<concentration_basis> = defn<"𝘒_𝘤", "𝘒_𝘤 = ∏_B(𝘤_B)^{𝘷_B}", particle_concentration("𝘤"), stoichiometric_number_of_substance("𝘷_B")>();
mpusz commented 1 year ago

Yes, similar issues to power also exist for energy and efficiency.

mpusz commented 1 year ago

And yes, I also planned to make quantity_spec templated on photometric condition for light and radiation. I didn't realize it is the same case for power, energy, and efficiency though. Thanks for raising this issue!