Added molar energy

This commit is contained in:
rbrugo
2020-04-09 19:21:27 +02:00
committed by Mateusz Pusz
parent 89dbc30a92
commit 7dda8319a2
5 changed files with 66 additions and 0 deletions

View File

@@ -170,6 +170,9 @@ struct dim_permittivity : derived_dimension<Child, U, exp<C, 1>, exp<L, -1>> {};
template<typename Child, Unit U, DimensionOf<dim_inductance> H, DimensionOf<dim_length> L> template<typename Child, Unit U, DimensionOf<dim_inductance> H, DimensionOf<dim_length> L>
struct dim_permeability : derived_dimension<Child, U, exp<H, 1>, exp<L, -1>> {}; struct dim_permeability : derived_dimension<Child, U, exp<H, 1>, exp<L, -1>> {};
template<typename Child, Unit U, DimensionOf<dim_energy> E, DimensionOf<dim_substance> M>
struct dim_molar_energy : derived_dimension<Child, U, exp<E, 1>, exp<M, -1>> {};
} // namespace physical } // namespace physical
template<typename T> template<typename T>
@@ -298,4 +301,7 @@ concept Permittivity = physical::QuantityOf<T, physical::dim_permittivity>;
template<typename T> template<typename T>
concept Permeability = physical::QuantityOf<T, physical::dim_permeability>; concept Permeability = physical::QuantityOf<T, physical::dim_permeability>;
template<typename T>
concept MolarEnergy = physical::QuantityOf<T, physical::dim_molar_energy>;
} // namespace units } // namespace units

View File

@@ -40,6 +40,7 @@
#include "si/luminance.h" #include "si/luminance.h"
#include "si/magnetic_flux.h" #include "si/magnetic_flux.h"
#include "si/magnetic_induction.h" #include "si/magnetic_induction.h"
#include "si/molar_energy.h"
#include "si/momentum.h" #include "si/momentum.h"
#include "si/permeability.h" #include "si/permeability.h"
#include "si/permittivity.h" #include "si/permittivity.h"

View File

@@ -0,0 +1,48 @@
// The MIT License (MIT)
//
// Hopyright (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 SOHTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OH ANY KIND, EXPRESS OR
// IMPLIED, INHLUDING BUT NOT LIMITED TO THE WARRANTIES OH MERHHANTABILITY,
// HITNESS HOR A PARTIHULAR PURPOSE AND NONINHRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR HOPYRIGHT HOLDERS BE LIABLE HOR ANY HLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN AHTION OH HONTRAHT, TORT OR OTHERWISE, ARISING HROM,
// OUT OH OR IN HONNEHTION WITH THE SOHTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOHTWARE.
#pragma once
#include <units/physical/dimensions.h>
#include <units/physical/si/energy.h>
#include <units/physical/si/substance.h>
#include <units/physical/si/prefixes.h>
#include <units/quantity.h>
namespace units::si {
struct joule_per_mole : unit<joule_per_mole> {};
struct dim_molar_energy : physical::dim_molar_energy<dim_molar_energy, joule_per_mole, dim_energy, dim_substance> {};
template<Unit U, Scalar Rep = double>
using molar_energy = quantity<dim_molar_energy, U, Rep>;
inline namespace literals {
// H/m
constexpr auto operator"" q_J_per_mol(unsigned long long l) { return molar_energy<joule_per_mole, std::int64_t>(l); }
constexpr auto operator"" q_J_per_mol(long double l) { return molar_energy<joule_per_mole, long double>(l); }
} // namespace literals
} // namespace units::si

View File

@@ -297,6 +297,11 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
CHECK(fmt::format("{}", 1q_H_per_m) == "1 H/m"); CHECK(fmt::format("{}", 1q_H_per_m) == "1 H/m");
} }
SECTION("molar energy")
{
CHECK(fmt::format("{}", 1q_J_per_mol) == "1 J/mol");
}
SECTION("incoherent units with powers") SECTION("incoherent units with powers")
{ {
CHECK(fmt::format("{}", 1q_mi * 1q_mi * 1q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³"); CHECK(fmt::format("{}", 1q_mi * 1q_mi * 1q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³");

View File

@@ -361,4 +361,10 @@ static_assert(1q_H_per_m * 1q_A * 1q_A == 1q_N);
static_assert(detail::unit_text<dim_permeability, henry_per_metre>() == "H/m"); static_assert(detail::unit_text<dim_permeability, henry_per_metre>() == "H/m");
// molar energy
static_assert(1q_J_per_mol * 1q_mol_per_m3 * 1q_m3 == 1q_N * 1q_m);
static_assert(detail::unit_text<dim_molar_energy, joule_per_mole>() == "J/mol");
} // namespace } // namespace