mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 20:54:28 +02:00
Added concentration
This commit is contained in:
@@ -134,6 +134,9 @@ struct dim_absorbed_dose : derived_dimension<Child, U, exp<E, 1>, exp<M, -1>> {}
|
||||
template<typename Child, Unit U, DimensionOf<dim_electric_current> I, DimensionOf<dim_length> L>
|
||||
struct dim_current_density : derived_dimension<Child, U, exp<I, 1>, exp<L, -2>> {};
|
||||
|
||||
template<typename Child, Unit U, DimensionOf<dim_substance> M, DimensionOf<dim_length> L>
|
||||
struct dim_concentration : derived_dimension<Child, U, exp<M, 1>, exp<L, -3>> {};
|
||||
|
||||
} // namespace physical
|
||||
|
||||
template<typename T>
|
||||
@@ -223,4 +226,7 @@ concept AbsorbedDose = physical::QuantityOf<T, physical::dim_absorbed_dose>;
|
||||
template<typename T>
|
||||
concept CurrentDensity = physical::QuantityOf<T, physical::dim_current_density>;
|
||||
|
||||
template<typename T>
|
||||
concept Concentration = physical::QuantityOf<T, physical::dim_concentration>;
|
||||
|
||||
} // namespace units
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include "si/area.h"
|
||||
#include "si/capacitance.h"
|
||||
#include "si/catalytic_activity.h"
|
||||
#include "si/concentration.h"
|
||||
#include "si/conductance.h"
|
||||
#include "si/constants.h"
|
||||
#include "si/current_density.h"
|
||||
|
47
src/include/units/physical/si/concentration.h
Normal file
47
src/include/units/physical/si/concentration.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2018 Mateusz Pusz
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <units/physical/dimensions.h>
|
||||
#include <units/physical/si/length.h>
|
||||
#include <units/physical/si/substance.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::si {
|
||||
|
||||
struct mol_per_metre_cub : unit<mol_per_metre_cub> {};
|
||||
struct dim_concentration : physical::dim_concentration<dim_concentration, mol_per_metre_cub, dim_substance, dim_length> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using concentration = quantity<dim_concentration, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// mol/m³
|
||||
constexpr auto operator"" q_mol_per_m3(unsigned long long l) { return concentration<mol_per_metre_cub, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_mol_per_m3(long double l) { return concentration<mol_per_metre_cub, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::si
|
||||
|
@@ -239,6 +239,12 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
|
||||
CHECK(fmt::format("{:%Q %Aq}", 1q_A_per_m2) == "1 A/m^2");
|
||||
}
|
||||
|
||||
SECTION("concentration")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1q_mol_per_m3) == "1 mol/m³");
|
||||
CHECK(fmt::format("{:%Q %Aq}", 1q_mol_per_m3) == "1 mol/m^3");
|
||||
}
|
||||
|
||||
SECTION("incoherent units with powers")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1q_mi * 1q_mi * 1q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³");
|
||||
|
@@ -297,8 +297,11 @@ static_assert(detail::unit_text<dim_surface_tension, newton_per_metre>() == "N/m
|
||||
static_assert(12q_A_per_m2 == 60q_A / 5q_m2);
|
||||
static_assert(1q_A_per_m2 == 1q_S * 1q_V / 1q_m2);
|
||||
|
||||
/* #warning FIX THIS */
|
||||
/* static_assert(detail::unit_text<dim_current_density, ampere_per_metre_sq>() == basic_symbol_text("A · m²", "A/m^2")); */
|
||||
static_assert(detail::unit_text<dim_current_density, ampere_per_metre_sq>() == basic_symbol_text("A/m²", "A/m^2"));
|
||||
|
||||
// concentration
|
||||
|
||||
static_assert(1q_mol_per_m3 == 1q_kg_per_m3 * 1q_mol / 1q_kg);
|
||||
static_assert(detail::unit_text<dim_concentration, ampere_per_metre_sq>() == basic_symbol_text("mol/m³", "mol/m^2"));
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user