diff --git a/BUILD.bazel b/BUILD.bazel index 79b63051..ae3a73aa 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -864,7 +864,7 @@ phq_library( ":DimensionalScalar", ":ScalarStrain", ":TemperatureDifference", - ":Unit/ThermalExpansion", + ":Unit/ReciprocalTemperature", ], ) @@ -2736,6 +2736,33 @@ phq_test( ], ) +phq_library( + name = "Unit/ReciprocalTemperature", + hdrs = ["include/PhQ/Unit/ReciprocalTemperature.hpp"], + deps = [ + ":Base", + ":Dimension/ElectricCurrent", + ":Dimension/Length", + ":Dimension/LuminousIntensity", + ":Dimension/Mass", + ":Dimension/SubstanceAmount", + ":Dimension/Temperature", + ":Dimension/Time", + ":Dimensions", + ":Unit", + ":UnitSystem", + ], +) + +phq_test( + name = "test/Unit/ReciprocalTemperature", + srcs = ["test/Unit/ReciprocalTemperature.cpp"], + deps = [ + ":Unit/ReciprocalTemperature", + ":test/Unit", + ], +) + phq_library( name = "Unit/SolidAngle", hdrs = ["include/PhQ/Unit/SolidAngle.hpp"], @@ -3006,33 +3033,6 @@ phq_test( ], ) -phq_library( - name = "Unit/ThermalExpansion", - hdrs = ["include/PhQ/Unit/ThermalExpansion.hpp"], - deps = [ - ":Base", - ":Dimension/ElectricCurrent", - ":Dimension/Length", - ":Dimension/LuminousIntensity", - ":Dimension/Mass", - ":Dimension/SubstanceAmount", - ":Dimension/Temperature", - ":Dimension/Time", - ":Dimensions", - ":Unit", - ":UnitSystem", - ], -) - -phq_test( - name = "test/Unit/ThermalExpansion", - srcs = ["test/Unit/ThermalExpansion.cpp"], - deps = [ - ":Unit/ThermalExpansion", - ":test/Unit", - ], -) - phq_library( name = "Unit/Time", hdrs = ["include/PhQ/Unit/Time.hpp"], @@ -3288,7 +3288,7 @@ phq_library( ":DimensionalScalar", ":Strain", ":TemperatureDifference", - ":Unit/ThermalExpansion", + ":Unit/ReciprocalTemperature", ], ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 397f1852..361edab5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -626,9 +626,9 @@ if(PHYSICAL_QUANTITIES_PHQ_TEST) target_link_libraries(unit_thermal_conductivity GTest::gtest_main) gtest_discover_tests(unit_thermal_conductivity) - add_executable(unit_thermal_expansion ${PROJECT_SOURCE_DIR}/test/Unit/ThermalExpansion.cpp) - target_link_libraries(unit_thermal_expansion GTest::gtest_main) - gtest_discover_tests(unit_thermal_expansion) + add_executable(unit_reciprocal_temperature ${PROJECT_SOURCE_DIR}/test/Unit/ReciprocalTemperature.cpp) + target_link_libraries(unit_reciprocal_temperature GTest::gtest_main) + gtest_discover_tests(unit_reciprocal_temperature) add_executable(unit_time ${PROJECT_SOURCE_DIR}/test/Unit/Time.cpp) target_link_libraries(unit_time GTest::gtest_main) diff --git a/README.md b/README.md index bf0c0cb4..320787bd 100644 --- a/README.md +++ b/README.md @@ -707,6 +707,7 @@ The Physical Quantities library features the following units of measure: - [PhQ::Unit::MemoryRate](include/PhQ/Unit/MemoryRate.hpp) - [PhQ::Unit::Power](include/PhQ/Unit/Power.hpp) - [PhQ::Unit::Pressure](include/PhQ/Unit/Pressure.hpp) +- [PhQ::Unit::ReciprocalTemperature](include/PhQ/Unit/ReciprocalTemperature.hpp) - [PhQ::Unit::SolidAngle](include/PhQ/Unit/SolidAngle.hpp) - [PhQ::Unit::SpecificEnergy](include/PhQ/Unit/SpecificEnergy.hpp) - [PhQ::Unit::SpecificHeatCapacity](include/PhQ/Unit/SpecificHeatCapacity.hpp) @@ -717,7 +718,6 @@ The Physical Quantities library features the following units of measure: - [PhQ::Unit::TemperatureDifference](include/PhQ/Unit/TemperatureDifference.hpp) - [PhQ::Unit::TemperatureGradient](include/PhQ/Unit/TemperatureGradient.hpp) - [PhQ::Unit::ThermalConductivity](include/PhQ/Unit/ThermalConductivity.hpp) -- [PhQ::Unit::ThermalExpansion](include/PhQ/Unit/ThermalExpansion.hpp) - [PhQ::Unit::Time](include/PhQ/Unit/Time.hpp) - [PhQ::Unit::TransportEnergyConsumption](include/PhQ/Unit/TransportEnergyConsumption.hpp) - [PhQ::Unit::Volume](include/PhQ/Unit/Volume.hpp) diff --git a/docs/main.txt b/docs/main.txt index c8399564..c87a4856 100644 --- a/docs/main.txt +++ b/docs/main.txt @@ -709,6 +709,7 @@ /// - PhQ::Unit::MemoryRate /// - PhQ::Unit::Power /// - PhQ::Unit::Pressure +/// - PhQ::Unit::ReciprocalTemperature /// - PhQ::Unit::SolidAngle /// - PhQ::Unit::SpecificEnergy /// - PhQ::Unit::SpecificHeatCapacity @@ -719,7 +720,6 @@ /// - PhQ::Unit::TemperatureDifference /// - PhQ::Unit::TemperatureGradient /// - PhQ::Unit::ThermalConductivity -/// - PhQ::Unit::ThermalExpansion /// - PhQ::Unit::Time /// - PhQ::Unit::TransportEnergyConsumption /// - PhQ::Unit::Volume diff --git a/include/PhQ/LinearThermalExpansionCoefficient.hpp b/include/PhQ/LinearThermalExpansionCoefficient.hpp index c1b0d7fe..8fab7849 100644 --- a/include/PhQ/LinearThermalExpansionCoefficient.hpp +++ b/include/PhQ/LinearThermalExpansionCoefficient.hpp @@ -32,7 +32,7 @@ #include "DimensionalScalar.hpp" #include "ScalarStrain.hpp" #include "TemperatureDifference.hpp" -#include "Unit/ThermalExpansion.hpp" +#include "Unit/ReciprocalTemperature.hpp" namespace PhQ { @@ -42,16 +42,16 @@ namespace PhQ { /// coefficient. template class LinearThermalExpansionCoefficient - : public DimensionalScalar { + : public DimensionalScalar { public: /// \brief Default constructor. Constructs a linear thermal expansion coefficient with an /// uninitialized value. LinearThermalExpansionCoefficient() = default; /// \brief Constructor. Constructs a linear thermal expansion coefficient with a given value - /// expressed in a given thermal expansion unit. - LinearThermalExpansionCoefficient(const NumericType value, const Unit::ThermalExpansion unit) - : DimensionalScalar(value, unit) {} + /// expressed in a given reciprocal temperature unit. + LinearThermalExpansionCoefficient(const NumericType value, const Unit::ReciprocalTemperature unit) + : DimensionalScalar(value, unit) {} /// \brief Destructor. Destroys this linear thermal expansion coefficient. ~LinearThermalExpansionCoefficient() noexcept = default; @@ -98,12 +98,13 @@ class LinearThermalExpansionCoefficient } /// \brief Statically creates a linear thermal expansion coefficient with a given value expressed - /// in a given thermal expansion unit. - template + /// in a given reciprocal temperature unit. + template [[nodiscard]] static constexpr LinearThermalExpansionCoefficient Create( const NumericType value) { return LinearThermalExpansionCoefficient{ - ConvertStatically>(value)}; + ConvertStatically>( + value)}; } constexpr LinearThermalExpansionCoefficient operator+( @@ -161,9 +162,9 @@ class LinearThermalExpansionCoefficient private: /// \brief Constructor. Constructs a linear thermal expansion coefficient with a given value - /// expressed in the standard thermal expansion unit. + /// expressed in the standard reciprocal temperature unit. explicit constexpr LinearThermalExpansionCoefficient(const NumericType value) - : DimensionalScalar(value) {} + : DimensionalScalar(value) {} }; template diff --git a/include/PhQ/Unit/ReciprocalTemperature.hpp b/include/PhQ/Unit/ReciprocalTemperature.hpp new file mode 100644 index 00000000..c4e0ef57 --- /dev/null +++ b/include/PhQ/Unit/ReciprocalTemperature.hpp @@ -0,0 +1,240 @@ +// Copyright © 2020-2024 Alexandre Coderre-Chabot +// +// This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical +// models, and units of measure for scientific computing. +// +// Physical Quantities is hosted at: +// https://github.com/acodcha/phq +// +// Physical Quantities is licensed under the MIT License: +// https://mit-license.org +// +// 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. + +#ifndef PHQ_UNIT_RECIPROCAL_TEMPERATURE_HPP +#define PHQ_UNIT_RECIPROCAL_TEMPERATURE_HPP + +#include +#include +#include +#include +#include +#include +#include + +#include "../Base.hpp" +#include "../Dimension/ElectricCurrent.hpp" +#include "../Dimension/Length.hpp" +#include "../Dimension/LuminousIntensity.hpp" +#include "../Dimension/Mass.hpp" +#include "../Dimension/SubstanceAmount.hpp" +#include "../Dimension/Temperature.hpp" +#include "../Dimension/Time.hpp" +#include "../Dimensions.hpp" +#include "../Unit.hpp" +#include "../UnitSystem.hpp" + +namespace PhQ { + +namespace Unit { + +/// \brief Reciprocal temperature units. Reciprocal temperature is the inverse of temperature. +enum class ReciprocalTemperature : int8_t { + /// \brief Per kelvin (/K) reciprocal temperature unit. + PerKelvin, + + /// \brief Per degree Celsius (/°C) reciprocal temperature unit. + PerCelsius, + + /// \brief Per degree Rankine (/°R) reciprocal temperature unit. + PerRankine, + + /// \brief Per degree Fahrenheit (/°F) reciprocal temperature unit. + PerFahrenheit +}; + +} // namespace Unit + +/// \brief Standard reciprocal temperature unit: per kelvin (/K). +template <> +inline constexpr const Unit::ReciprocalTemperature Standard{ + Unit::ReciprocalTemperature::PerKelvin}; + +/// \brief Physical dimension set of reciprocal temperature units. +template <> +inline constexpr const Dimensions RelatedDimensions{ + Dimensions{Dimension::Time{0}, Dimension::Length{0}, Dimension::Mass{0}, + Dimension::ElectricCurrent{0}, Dimension::Temperature{-1}, + Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}} +}; + +inline std::ostream& operator<<(std::ostream& stream, const Unit::ReciprocalTemperature unit) { + stream << Abbreviation(unit); + return stream; +} + +namespace Internal { + +template <> +inline const std::map + ConsistentUnits{ + {UnitSystem::MetreKilogramSecondKelvin, Unit::ReciprocalTemperature::PerKelvin }, + {UnitSystem::MillimetreGramSecondKelvin, Unit::ReciprocalTemperature::PerKelvin }, + {UnitSystem::FootPoundSecondRankine, Unit::ReciprocalTemperature::PerRankine}, + {UnitSystem::InchPoundSecondRankine, Unit::ReciprocalTemperature::PerRankine}, +}; + +template <> +inline const std::map + RelatedUnitSystems{}; + +// clang-format off + +template <> +inline const std::map + Abbreviations{ + {Unit::ReciprocalTemperature::PerKelvin, "/K" }, + {Unit::ReciprocalTemperature::PerCelsius, "/°C"}, + {Unit::ReciprocalTemperature::PerRankine, "/°R"}, + {Unit::ReciprocalTemperature::PerFahrenheit, "/°F"}, +}; + +template <> +inline const std::unordered_map + Spellings{ + {"1/K", Unit::ReciprocalTemperature::PerKelvin }, + {"1/°K", Unit::ReciprocalTemperature::PerKelvin }, + {"1/degK", Unit::ReciprocalTemperature::PerKelvin }, + {"/K", Unit::ReciprocalTemperature::PerKelvin }, + {"/°K", Unit::ReciprocalTemperature::PerKelvin }, + {"/degK", Unit::ReciprocalTemperature::PerKelvin }, + {"1/°C", Unit::ReciprocalTemperature::PerCelsius }, + {"1/C", Unit::ReciprocalTemperature::PerCelsius }, + {"1/degC", Unit::ReciprocalTemperature::PerCelsius }, + {"/°C", Unit::ReciprocalTemperature::PerCelsius }, + {"/C", Unit::ReciprocalTemperature::PerCelsius }, + {"/degC", Unit::ReciprocalTemperature::PerCelsius }, + {"1/°R", Unit::ReciprocalTemperature::PerRankine }, + {"1/R", Unit::ReciprocalTemperature::PerRankine }, + {"1/degR", Unit::ReciprocalTemperature::PerRankine }, + {"/°R", Unit::ReciprocalTemperature::PerRankine }, + {"/R", Unit::ReciprocalTemperature::PerRankine }, + {"/degR", Unit::ReciprocalTemperature::PerRankine }, + {"1/°F", Unit::ReciprocalTemperature::PerFahrenheit}, + {"1/F", Unit::ReciprocalTemperature::PerFahrenheit}, + {"1/degF", Unit::ReciprocalTemperature::PerFahrenheit}, + {"/°F", Unit::ReciprocalTemperature::PerFahrenheit}, + {"/F", Unit::ReciprocalTemperature::PerFahrenheit}, + {"/degF", Unit::ReciprocalTemperature::PerFahrenheit}, +}; + +// clang-format on + +template <> +template +inline constexpr void +Conversion::FromStandard( + NumericType& /*value*/) noexcept {} + +template <> +template +inline constexpr void +Conversion::ToStandard( + NumericType& /*value*/) noexcept {} + +template <> +template +inline constexpr void +Conversion::FromStandard( + NumericType& /*value*/) noexcept {} + +template <> +template +inline constexpr void +Conversion::ToStandard( + NumericType& /*value*/) noexcept {} + +template <> +template +inline constexpr void +Conversion::FromStandard( + NumericType& value) noexcept { + value /= static_cast(1.8L); +} + +template <> +template +inline constexpr void +Conversion::ToStandard( + NumericType& value) noexcept { + value *= static_cast(1.8L); +} + +template <> +template +inline constexpr void +Conversion::FromStandard( + NumericType& value) noexcept { + value /= static_cast(1.8L); +} + +template <> +template +inline constexpr void +Conversion::ToStandard( + NumericType& value) noexcept { + value *= static_cast(1.8L); +} + +template +inline const std::map> + MapOfConversionsFromStandard{ + {Unit::ReciprocalTemperature::PerKelvin, + Conversions::FromStandard }, + {Unit::ReciprocalTemperature::PerCelsius, + Conversions::FromStandard }, + {Unit::ReciprocalTemperature::PerRankine, + Conversions::FromStandard }, + {Unit::ReciprocalTemperature::PerFahrenheit, + Conversions::FromStandard}, +}; + +template +inline const std::map> + MapOfConversionsToStandard{ + {Unit::ReciprocalTemperature::PerKelvin, + Conversions::ToStandard }, + {Unit::ReciprocalTemperature::PerCelsius, + Conversions::ToStandard }, + {Unit::ReciprocalTemperature::PerRankine, + Conversions::ToStandard }, + {Unit::ReciprocalTemperature::PerFahrenheit, + Conversions::ToStandard}, +}; + +} // namespace Internal + +} // namespace PhQ + +#endif // PHQ_UNIT_RECIPROCAL_TEMPERATURE_HPP diff --git a/include/PhQ/Unit/ThermalExpansion.hpp b/include/PhQ/Unit/ThermalExpansion.hpp deleted file mode 100644 index ff9ac1eb..00000000 --- a/include/PhQ/Unit/ThermalExpansion.hpp +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright © 2020-2024 Alexandre Coderre-Chabot -// -// This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical -// models, and units of measure for scientific computing. -// -// Physical Quantities is hosted at: -// https://github.com/acodcha/phq -// -// Physical Quantities is licensed under the MIT License: -// https://mit-license.org -// -// 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. - -#ifndef PHQ_UNIT_THERMAL_EXPANSION_HPP -#define PHQ_UNIT_THERMAL_EXPANSION_HPP - -#include -#include -#include -#include -#include -#include -#include - -#include "../Base.hpp" -#include "../Dimension/ElectricCurrent.hpp" -#include "../Dimension/Length.hpp" -#include "../Dimension/LuminousIntensity.hpp" -#include "../Dimension/Mass.hpp" -#include "../Dimension/SubstanceAmount.hpp" -#include "../Dimension/Temperature.hpp" -#include "../Dimension/Time.hpp" -#include "../Dimensions.hpp" -#include "../Unit.hpp" -#include "../UnitSystem.hpp" - -namespace PhQ { - -namespace Unit { - -/// \brief Thermal expansion units. -enum class ThermalExpansion : int8_t { - /// \brief Per kelvin (/K) thermal expansion unit. - PerKelvin, - - /// \brief Per degree Celsius (/°C) thermal expansion unit. - PerCelsius, - - /// \brief Per degree Rankine (/°R) thermal expansion unit. - PerRankine, - - /// \brief Per degree Fahrenheit (/°F) thermal expansion unit. - PerFahrenheit -}; - -} // namespace Unit - -/// \brief Standard thermal expansion unit: per kelvin (/K). -template <> -inline constexpr const Unit::ThermalExpansion Standard{ - Unit::ThermalExpansion::PerKelvin}; - -/// \brief Physical dimension set of thermal expansion units. -template <> -inline constexpr const Dimensions RelatedDimensions{ - Dimensions{Dimension::Time{0}, Dimension::Length{0}, Dimension::Mass{0}, - Dimension::ElectricCurrent{0}, Dimension::Temperature{-1}, - Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}} -}; - -inline std::ostream& operator<<(std::ostream& stream, const Unit::ThermalExpansion unit) { - stream << Abbreviation(unit); - return stream; -} - -namespace Internal { - -template <> -inline const std::map ConsistentUnits{ - {UnitSystem::MetreKilogramSecondKelvin, Unit::ThermalExpansion::PerKelvin }, - {UnitSystem::MillimetreGramSecondKelvin, Unit::ThermalExpansion::PerKelvin }, - {UnitSystem::FootPoundSecondRankine, Unit::ThermalExpansion::PerRankine}, - {UnitSystem::InchPoundSecondRankine, Unit::ThermalExpansion::PerRankine}, -}; - -template <> -inline const std::map - RelatedUnitSystems{}; - -// clang-format off - -template <> -inline const std::map - Abbreviations{ - {Unit::ThermalExpansion::PerKelvin, "/K" }, - {Unit::ThermalExpansion::PerCelsius, "/°C"}, - {Unit::ThermalExpansion::PerRankine, "/°R"}, - {Unit::ThermalExpansion::PerFahrenheit, "/°F"}, -}; - -template <> -inline const std::unordered_map - Spellings{ - {"1/K", Unit::ThermalExpansion::PerKelvin }, - {"1/°K", Unit::ThermalExpansion::PerKelvin }, - {"1/degK", Unit::ThermalExpansion::PerKelvin }, - {"/K", Unit::ThermalExpansion::PerKelvin }, - {"/°K", Unit::ThermalExpansion::PerKelvin }, - {"/degK", Unit::ThermalExpansion::PerKelvin }, - {"1/°C", Unit::ThermalExpansion::PerCelsius }, - {"1/C", Unit::ThermalExpansion::PerCelsius }, - {"1/degC", Unit::ThermalExpansion::PerCelsius }, - {"/°C", Unit::ThermalExpansion::PerCelsius }, - {"/C", Unit::ThermalExpansion::PerCelsius }, - {"/degC", Unit::ThermalExpansion::PerCelsius }, - {"1/°R", Unit::ThermalExpansion::PerRankine }, - {"1/R", Unit::ThermalExpansion::PerRankine }, - {"1/degR", Unit::ThermalExpansion::PerRankine }, - {"/°R", Unit::ThermalExpansion::PerRankine }, - {"/R", Unit::ThermalExpansion::PerRankine }, - {"/degR", Unit::ThermalExpansion::PerRankine }, - {"1/°F", Unit::ThermalExpansion::PerFahrenheit}, - {"1/F", Unit::ThermalExpansion::PerFahrenheit}, - {"1/degF", Unit::ThermalExpansion::PerFahrenheit}, - {"/°F", Unit::ThermalExpansion::PerFahrenheit}, - {"/F", Unit::ThermalExpansion::PerFahrenheit}, - {"/degF", Unit::ThermalExpansion::PerFahrenheit}, -}; - -// clang-format on - -template <> -template -inline constexpr void -Conversion::FromStandard( - NumericType& /*value*/) noexcept {} - -template <> -template -inline constexpr void -Conversion::ToStandard( - NumericType& /*value*/) noexcept {} - -template <> -template -inline constexpr void -Conversion::FromStandard( - NumericType& /*value*/) noexcept {} - -template <> -template -inline constexpr void -Conversion::ToStandard( - NumericType& /*value*/) noexcept {} - -template <> -template -inline constexpr void -Conversion::FromStandard( - NumericType& value) noexcept { - value /= static_cast(1.8L); -} - -template <> -template -inline constexpr void -Conversion::ToStandard( - NumericType& value) noexcept { - value *= static_cast(1.8L); -} - -template <> -template -inline constexpr void -Conversion::FromStandard( - NumericType& value) noexcept { - value /= static_cast(1.8L); -} - -template <> -template -inline constexpr void -Conversion::ToStandard( - NumericType& value) noexcept { - value *= static_cast(1.8L); -} - -template -inline const std::map> - MapOfConversionsFromStandard{ - {Unit::ThermalExpansion::PerKelvin, - Conversions::FromStandard }, - {Unit::ThermalExpansion::PerCelsius, - Conversions::FromStandard }, - {Unit::ThermalExpansion::PerRankine, - Conversions::FromStandard }, - {Unit::ThermalExpansion::PerFahrenheit, - Conversions::FromStandard}, -}; - -template -inline const std::map> - MapOfConversionsToStandard{ - {Unit::ThermalExpansion::PerKelvin, - Conversions::ToStandard }, - {Unit::ThermalExpansion::PerCelsius, - Conversions::ToStandard }, - {Unit::ThermalExpansion::PerRankine, - Conversions::ToStandard }, - {Unit::ThermalExpansion::PerFahrenheit, - Conversions::ToStandard}, -}; - -} // namespace Internal - -} // namespace PhQ - -#endif // PHQ_UNIT_THERMAL_EXPANSION_HPP diff --git a/include/PhQ/VolumetricThermalExpansionCoefficient.hpp b/include/PhQ/VolumetricThermalExpansionCoefficient.hpp index d50bf4e4..aeee1369 100644 --- a/include/PhQ/VolumetricThermalExpansionCoefficient.hpp +++ b/include/PhQ/VolumetricThermalExpansionCoefficient.hpp @@ -32,7 +32,7 @@ #include "DimensionalScalar.hpp" #include "Strain.hpp" #include "TemperatureDifference.hpp" -#include "Unit/ThermalExpansion.hpp" +#include "Unit/ReciprocalTemperature.hpp" namespace PhQ { @@ -42,16 +42,17 @@ namespace PhQ { /// coefficient. template class VolumetricThermalExpansionCoefficient - : public DimensionalScalar { + : public DimensionalScalar { public: /// \brief Default constructor. Constructs a volumetric thermal expansion coefficient with an /// uninitialized value. VolumetricThermalExpansionCoefficient() = default; /// \brief Constructor. Constructs a volumetric thermal expansion coefficient with a given value - /// expressed in a given thermal expansion unit. - VolumetricThermalExpansionCoefficient(const NumericType value, const Unit::ThermalExpansion unit) - : DimensionalScalar(value, unit) {} + /// expressed in a given reciprocal temperature unit. + VolumetricThermalExpansionCoefficient( + const NumericType value, const Unit::ReciprocalTemperature unit) + : DimensionalScalar(value, unit) {} /// \brief Destructor. Destroys this volumetric thermal expansion coefficient. ~VolumetricThermalExpansionCoefficient() noexcept = default; @@ -98,12 +99,13 @@ class VolumetricThermalExpansionCoefficient } /// \brief Statically creates a volumetric thermal expansion coefficient with a given value - /// expressed in a given thermal expansion unit. - template + /// expressed in a given reciprocal temperature unit. + template [[nodiscard]] static constexpr VolumetricThermalExpansionCoefficient Create( const NumericType value) { return VolumetricThermalExpansionCoefficient{ - ConvertStatically>(value)}; + ConvertStatically>( + value)}; } constexpr VolumetricThermalExpansionCoefficient operator+( @@ -160,9 +162,9 @@ class VolumetricThermalExpansionCoefficient private: /// \brief Constructor. Constructs a volumetric thermal expansion coefficient with a given value - /// expressed in the standard thermal expansion unit. + /// expressed in the standard reciprocal temperature unit. explicit constexpr VolumetricThermalExpansionCoefficient(const NumericType value) - : DimensionalScalar(value) {} + : DimensionalScalar(value) {} }; template diff --git a/test/LinearThermalExpansionCoefficient.cpp b/test/LinearThermalExpansionCoefficient.cpp index 6feb8a1d..6bcd6ad8 100644 --- a/test/LinearThermalExpansionCoefficient.cpp +++ b/test/LinearThermalExpansionCoefficient.cpp @@ -31,8 +31,8 @@ #include "../include/PhQ/ScalarStrain.hpp" #include "../include/PhQ/TemperatureDifference.hpp" +#include "../include/PhQ/Unit/ReciprocalTemperature.hpp" #include "../include/PhQ/Unit/TemperatureDifference.hpp" -#include "../include/PhQ/Unit/ThermalExpansion.hpp" #include "Performance.hpp" namespace PhQ { @@ -40,75 +40,75 @@ namespace PhQ { namespace { TEST(LinearThermalExpansionCoefficient, ArithmeticOperatorAddition) { - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin) - + LinearThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin), - LinearThermalExpansionCoefficient(3.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin) + + LinearThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin), + LinearThermalExpansionCoefficient(3.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(LinearThermalExpansionCoefficient, ArithmeticOperatorDivision) { - EXPECT_EQ(LinearThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin) / 2.0, - LinearThermalExpansionCoefficient(4.0, Unit::ThermalExpansion::PerKelvin)); - EXPECT_EQ(LinearThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin) - / LinearThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin), + EXPECT_EQ(LinearThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin) / 2.0, + LinearThermalExpansionCoefficient(4.0, Unit::ReciprocalTemperature::PerKelvin)); + EXPECT_EQ(LinearThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin) + / LinearThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin), 4.0); } TEST(LinearThermalExpansionCoefficient, ArithmeticOperatorMultiplication) { - EXPECT_EQ(LinearThermalExpansionCoefficient(4.0, Unit::ThermalExpansion::PerKelvin) * 2.0, - LinearThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin)); - EXPECT_EQ(2.0 * LinearThermalExpansionCoefficient(4.0, Unit::ThermalExpansion::PerKelvin), - LinearThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin)); - EXPECT_EQ(LinearThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin) + EXPECT_EQ(LinearThermalExpansionCoefficient(4.0, Unit::ReciprocalTemperature::PerKelvin) * 2.0, + LinearThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin)); + EXPECT_EQ(2.0 * LinearThermalExpansionCoefficient(4.0, Unit::ReciprocalTemperature::PerKelvin), + LinearThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin)); + EXPECT_EQ(LinearThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin) * TemperatureDifference(4.0, Unit::TemperatureDifference::Kelvin), ScalarStrain(8.0)); EXPECT_EQ(TemperatureDifference(4.0, Unit::TemperatureDifference::Kelvin) - * LinearThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin), + * LinearThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin), ScalarStrain(8.0)); } TEST(LinearThermalExpansionCoefficient, ArithmeticOperatorSubtraction) { - EXPECT_EQ(LinearThermalExpansionCoefficient(3.0, Unit::ThermalExpansion::PerKelvin) - - LinearThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin), - LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(LinearThermalExpansionCoefficient(3.0, Unit::ReciprocalTemperature::PerKelvin) + - LinearThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin), + LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(LinearThermalExpansionCoefficient, AssignmentOperatorAddition) { LinearThermalExpansionCoefficient linear_thermal_expansion_coefficient{ - 1.0, Unit::ThermalExpansion::PerKelvin}; + 1.0, Unit::ReciprocalTemperature::PerKelvin}; linear_thermal_expansion_coefficient += - LinearThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin); + LinearThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin); EXPECT_EQ(linear_thermal_expansion_coefficient, - LinearThermalExpansionCoefficient(3.0, Unit::ThermalExpansion::PerKelvin)); + LinearThermalExpansionCoefficient(3.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(LinearThermalExpansionCoefficient, AssignmentOperatorDivision) { LinearThermalExpansionCoefficient linear_thermal_expansion_coefficient{ - 8.0, Unit::ThermalExpansion::PerKelvin}; + 8.0, Unit::ReciprocalTemperature::PerKelvin}; linear_thermal_expansion_coefficient /= 2.0; EXPECT_EQ(linear_thermal_expansion_coefficient, - LinearThermalExpansionCoefficient(4.0, Unit::ThermalExpansion::PerKelvin)); + LinearThermalExpansionCoefficient(4.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(LinearThermalExpansionCoefficient, AssignmentOperatorMultiplication) { LinearThermalExpansionCoefficient linear_thermal_expansion_coefficient{ - 4.0, Unit::ThermalExpansion::PerKelvin}; + 4.0, Unit::ReciprocalTemperature::PerKelvin}; linear_thermal_expansion_coefficient *= 2.0; EXPECT_EQ(linear_thermal_expansion_coefficient, - LinearThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin)); + LinearThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(LinearThermalExpansionCoefficient, AssignmentOperatorSubtraction) { LinearThermalExpansionCoefficient linear_thermal_expansion_coefficient{ - 3.0, Unit::ThermalExpansion::PerKelvin}; + 3.0, Unit::ReciprocalTemperature::PerKelvin}; linear_thermal_expansion_coefficient -= - LinearThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin); + LinearThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin); EXPECT_EQ(linear_thermal_expansion_coefficient, - LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(LinearThermalExpansionCoefficient, ComparisonOperators) { - const LinearThermalExpansionCoefficient first{0.1, Unit::ThermalExpansion::PerKelvin}; - const LinearThermalExpansionCoefficient second{0.2, Unit::ThermalExpansion::PerKelvin}; + const LinearThermalExpansionCoefficient first{0.1, Unit::ReciprocalTemperature::PerKelvin}; + const LinearThermalExpansionCoefficient second{0.2, Unit::ReciprocalTemperature::PerKelvin}; EXPECT_EQ(first, first); EXPECT_NE(first, second); EXPECT_LT(first, second); @@ -120,67 +120,72 @@ TEST(LinearThermalExpansionCoefficient, ComparisonOperators) { } TEST(LinearThermalExpansionCoefficient, Constructor) { - EXPECT_NO_THROW(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine)); - EXPECT_EQ(ScalarStrain(LinearThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin), - TemperatureDifference(4.0, Unit::TemperatureDifference::Kelvin)), - ScalarStrain(8.0)); + EXPECT_NO_THROW(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine)); + EXPECT_EQ( + ScalarStrain(LinearThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin), + TemperatureDifference(4.0, Unit::TemperatureDifference::Kelvin)), + ScalarStrain(8.0)); } TEST(LinearThermalExpansionCoefficient, CopyAssignmentOperator) { { - const LinearThermalExpansionCoefficient first(1.0F, Unit::ThermalExpansion::PerKelvin); + const LinearThermalExpansionCoefficient first( + 1.0F, Unit::ReciprocalTemperature::PerKelvin); LinearThermalExpansionCoefficient second = LinearThermalExpansionCoefficient::Zero(); second = first; - EXPECT_EQ( - second, LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(second, LinearThermalExpansionCoefficient( + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } { - const LinearThermalExpansionCoefficient first(1.0, Unit::ThermalExpansion::PerKelvin); + const LinearThermalExpansionCoefficient first( + 1.0, Unit::ReciprocalTemperature::PerKelvin); LinearThermalExpansionCoefficient second = LinearThermalExpansionCoefficient::Zero(); second = first; - EXPECT_EQ( - second, LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(second, LinearThermalExpansionCoefficient( + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } { const LinearThermalExpansionCoefficient first( - 1.0L, Unit::ThermalExpansion::PerKelvin); + 1.0L, Unit::ReciprocalTemperature::PerKelvin); LinearThermalExpansionCoefficient second = LinearThermalExpansionCoefficient::Zero(); second = first; - EXPECT_EQ( - second, LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(second, LinearThermalExpansionCoefficient( + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } } TEST(LinearThermalExpansionCoefficient, CopyConstructor) { { - const LinearThermalExpansionCoefficient first(1.0F, Unit::ThermalExpansion::PerKelvin); + const LinearThermalExpansionCoefficient first( + 1.0F, Unit::ReciprocalTemperature::PerKelvin); const LinearThermalExpansionCoefficient second{first}; - EXPECT_EQ( - second, LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(second, LinearThermalExpansionCoefficient( + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } { - const LinearThermalExpansionCoefficient first(1.0, Unit::ThermalExpansion::PerKelvin); + const LinearThermalExpansionCoefficient first( + 1.0, Unit::ReciprocalTemperature::PerKelvin); const LinearThermalExpansionCoefficient second{first}; - EXPECT_EQ( - second, LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(second, LinearThermalExpansionCoefficient( + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } { const LinearThermalExpansionCoefficient first( - 1.0L, Unit::ThermalExpansion::PerKelvin); + 1.0L, Unit::ReciprocalTemperature::PerKelvin); const LinearThermalExpansionCoefficient second{first}; - EXPECT_EQ( - second, LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(second, LinearThermalExpansionCoefficient( + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } } TEST(LinearThermalExpansionCoefficient, Create) { constexpr LinearThermalExpansionCoefficient linear_thermal_expansion_coefficient = - LinearThermalExpansionCoefficient<>::Create(1.0); + LinearThermalExpansionCoefficient<>::Create(1.0); EXPECT_EQ(linear_thermal_expansion_coefficient, - LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(LinearThermalExpansionCoefficient, DefaultConstructor) { @@ -188,14 +193,14 @@ TEST(LinearThermalExpansionCoefficient, DefaultConstructor) { } TEST(LinearThermalExpansionCoefficient, Dimensions) { - EXPECT_EQ( - LinearThermalExpansionCoefficient<>::Dimensions(), RelatedDimensions); + EXPECT_EQ(LinearThermalExpansionCoefficient<>::Dimensions(), + RelatedDimensions); } TEST(LinearThermalExpansionCoefficient, Hash) { - const LinearThermalExpansionCoefficient first{1.0, Unit::ThermalExpansion::PerRankine}; - const LinearThermalExpansionCoefficient second{1.00001, Unit::ThermalExpansion::PerRankine}; - const LinearThermalExpansionCoefficient third{-1.0, Unit::ThermalExpansion::PerRankine}; + const LinearThermalExpansionCoefficient first{1.0, Unit::ReciprocalTemperature::PerRankine}; + const LinearThermalExpansionCoefficient second{1.00001, Unit::ReciprocalTemperature::PerRankine}; + const LinearThermalExpansionCoefficient third{-1.0, Unit::ReciprocalTemperature::PerRankine}; const std::hash> hash; EXPECT_NE(hash(first), hash(second)); EXPECT_NE(hash(first), hash(third)); @@ -203,54 +208,55 @@ TEST(LinearThermalExpansionCoefficient, Hash) { } TEST(LinearThermalExpansionCoefficient, JSON) { - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).JSON(), + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).JSON(), "{\"value\":" + Print(1.0) + ",\"unit\":\"/K\"}"); - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .JSON(Unit::ThermalExpansion::PerRankine), + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .JSON(Unit::ReciprocalTemperature::PerRankine), "{\"value\":" + Print(1.0) + ",\"unit\":\"/°R\"}"); } TEST(LinearThermalExpansionCoefficient, MoveAssignmentOperator) { - LinearThermalExpansionCoefficient first{1.0, Unit::ThermalExpansion::PerKelvin}; + LinearThermalExpansionCoefficient first{1.0, Unit::ReciprocalTemperature::PerKelvin}; LinearThermalExpansionCoefficient second = LinearThermalExpansionCoefficient<>::Zero(); second = std::move(first); - EXPECT_EQ(second, LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(second, LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(LinearThermalExpansionCoefficient, MoveConstructor) { - LinearThermalExpansionCoefficient first{1.0, Unit::ThermalExpansion::PerKelvin}; + LinearThermalExpansionCoefficient first{1.0, Unit::ReciprocalTemperature::PerKelvin}; const LinearThermalExpansionCoefficient second{std::move(first)}; - EXPECT_EQ(second, LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ(second, LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(LinearThermalExpansionCoefficient, MutableValue) { LinearThermalExpansionCoefficient linear_thermal_expansion_coefficient{ - 1.0, Unit::ThermalExpansion::PerKelvin}; + 1.0, Unit::ReciprocalTemperature::PerKelvin}; double& value = linear_thermal_expansion_coefficient.MutableValue(); value = 2.0; EXPECT_EQ(linear_thermal_expansion_coefficient.Value(), 2.0); } TEST(LinearThermalExpansionCoefficient, Performance) { - LinearThermalExpansionCoefficient first{1.2345678901234567890, Unit::ThermalExpansion::PerKelvin}; + LinearThermalExpansionCoefficient first{ + 1.2345678901234567890, Unit::ReciprocalTemperature::PerKelvin}; LinearThermalExpansionCoefficient second{ - 1.2345678901234567890, Unit::ThermalExpansion::PerKelvin}; + 1.2345678901234567890, Unit::ReciprocalTemperature::PerKelvin}; double first_reference{1.2345678901234567890}; double second_reference{1.2345678901234567890}; Internal::TestScalarPerformance(first, second, first_reference, second_reference); } TEST(LinearThermalExpansionCoefficient, Print) { - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).Print(), + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).Print(), Print(1.0) + " /K"); - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .Print(Unit::ThermalExpansion::PerRankine), + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .Print(Unit::ReciprocalTemperature::PerRankine), Print(1.0) + " /°R"); } TEST(LinearThermalExpansionCoefficient, SetValue) { LinearThermalExpansionCoefficient linear_thermal_expansion_coefficient{ - 1.0, Unit::ThermalExpansion::PerKelvin}; + 1.0, Unit::ReciprocalTemperature::PerKelvin}; linear_thermal_expansion_coefficient.SetValue(2.0); EXPECT_EQ(linear_thermal_expansion_coefficient.Value(), 2.0); } @@ -261,49 +267,50 @@ TEST(LinearThermalExpansionCoefficient, SizeOf) { TEST(LinearThermalExpansionCoefficient, StaticValue) { constexpr LinearThermalExpansionCoefficient linear_thermal_expansion_coefficient = - LinearThermalExpansionCoefficient<>::Create(1.0); + LinearThermalExpansionCoefficient<>::Create(1.0); constexpr double value = - linear_thermal_expansion_coefficient.StaticValue(); + linear_thermal_expansion_coefficient.StaticValue(); EXPECT_EQ(value, 1.0); } TEST(LinearThermalExpansionCoefficient, Stream) { std::ostringstream stream; - stream << LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin); + stream << LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin); EXPECT_EQ(stream.str(), - LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).Print()); + LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).Print()); } TEST(LinearThermalExpansionCoefficient, Unit) { - EXPECT_EQ(LinearThermalExpansionCoefficient<>::Unit(), Standard); + EXPECT_EQ(LinearThermalExpansionCoefficient<>::Unit(), Standard); } TEST(LinearThermalExpansionCoefficient, Value) { - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).Value(), 1.0); - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .Value(Unit::ThermalExpansion::PerRankine), + EXPECT_EQ( + LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).Value(), 1.0); + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .Value(Unit::ReciprocalTemperature::PerRankine), 1.0); } TEST(LinearThermalExpansionCoefficient, XML) { - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).XML(), + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).XML(), "" + Print(1.0) + "/K"); - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .XML(Unit::ThermalExpansion::PerRankine), + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .XML(Unit::ReciprocalTemperature::PerRankine), "" + Print(1.0) + "/°R"); } TEST(LinearThermalExpansionCoefficient, YAML) { - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).YAML(), + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).YAML(), "{value:" + Print(1.0) + ",unit:\"/K\"}"); - EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .YAML(Unit::ThermalExpansion::PerRankine), + EXPECT_EQ(LinearThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .YAML(Unit::ReciprocalTemperature::PerRankine), "{value:" + Print(1.0) + ",unit:\"/°R\"}"); } TEST(LinearThermalExpansionCoefficient, Zero) { EXPECT_EQ(LinearThermalExpansionCoefficient<>::Zero(), - LinearThermalExpansionCoefficient(0.0, Unit::ThermalExpansion::PerKelvin)); + LinearThermalExpansionCoefficient(0.0, Unit::ReciprocalTemperature::PerKelvin)); } } // namespace diff --git a/test/Unit/ReciprocalTemperature.cpp b/test/Unit/ReciprocalTemperature.cpp new file mode 100644 index 00000000..d6d687de --- /dev/null +++ b/test/Unit/ReciprocalTemperature.cpp @@ -0,0 +1,123 @@ +// Copyright © 2020-2024 Alexandre Coderre-Chabot +// +// This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical +// models, and units of measure for scientific computing. +// +// Physical Quantities is hosted at: +// https://github.com/acodcha/phq +// +// Physical Quantities is licensed under the MIT License: +// https://mit-license.org +// +// 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. + +#include "../../include/PhQ/Unit/ReciprocalTemperature.hpp" + +#include +#include +#include +#include + +#include "../../include/PhQ/Base.hpp" +#include "../../include/PhQ/Dimension/ElectricCurrent.hpp" +#include "../../include/PhQ/Dimension/Length.hpp" +#include "../../include/PhQ/Dimension/Mass.hpp" +#include "../../include/PhQ/Dimension/Temperature.hpp" +#include "../../include/PhQ/Dimension/Time.hpp" +#include "../../include/PhQ/Dimensions.hpp" +#include "../../include/PhQ/UnitSystem.hpp" +#include "../Unit.hpp" + +namespace PhQ::Unit { + +namespace { + +constexpr std::array Units = { + ReciprocalTemperature::PerKelvin, + ReciprocalTemperature::PerCelsius, + ReciprocalTemperature::PerRankine, + ReciprocalTemperature::PerFahrenheit, +}; + +TEST(UnitThermalExpansion, Abbreviation) { + EXPECT_EQ(Abbreviation(ReciprocalTemperature::PerKelvin), "/K"); + EXPECT_EQ(Abbreviation(ReciprocalTemperature::PerCelsius), "/°C"); + EXPECT_EQ(Abbreviation(ReciprocalTemperature::PerRankine), "/°R"); + EXPECT_EQ(Abbreviation(ReciprocalTemperature::PerFahrenheit), "/°F"); +} + +TEST(UnitThermalExpansion, ConsistentUnit) { + EXPECT_EQ(ConsistentUnit(UnitSystem::MetreKilogramSecondKelvin), + ReciprocalTemperature::PerKelvin); + EXPECT_EQ(ConsistentUnit(UnitSystem::MillimetreGramSecondKelvin), + ReciprocalTemperature::PerKelvin); + EXPECT_EQ(ConsistentUnit(UnitSystem::FootPoundSecondRankine), + ReciprocalTemperature::PerRankine); + EXPECT_EQ(ConsistentUnit(UnitSystem::InchPoundSecondRankine), + ReciprocalTemperature::PerRankine); +} + +TEST(UnitThermalExpansion, Convert) { + constexpr long double value{1.234567890123456789L}; + Internal::TestConvert( + ReciprocalTemperature::PerKelvin, ReciprocalTemperature::PerKelvin, value, value); + Internal::TestConvert( + ReciprocalTemperature::PerKelvin, ReciprocalTemperature::PerCelsius, value, value); + Internal::TestConvert( + ReciprocalTemperature::PerKelvin, ReciprocalTemperature::PerRankine, value, value / 1.8L); + Internal::TestConvert( + ReciprocalTemperature::PerKelvin, ReciprocalTemperature::PerFahrenheit, value, value / 1.8L); +} + +TEST(UnitThermalExpansion, ConvertStatically) { + constexpr long double value{1.234567890123456789L}; + Internal::TestConvertStatically(value, value / 1.8L); +} + +TEST(UnitThermalExpansion, ParseEnumeration) { + EXPECT_EQ(ParseEnumeration("Hello world!"), std::nullopt); + EXPECT_EQ(ParseEnumeration("/K"), ReciprocalTemperature::PerKelvin); + EXPECT_EQ(ParseEnumeration("/°C"), ReciprocalTemperature::PerCelsius); + EXPECT_EQ(ParseEnumeration("/°R"), ReciprocalTemperature::PerRankine); + EXPECT_EQ(ParseEnumeration("/°F"), ReciprocalTemperature::PerFahrenheit); +} + +TEST(UnitThermalExpansion, RelatedDimensions) { + EXPECT_EQ(RelatedDimensions, + Dimensions(Dimension::Time{0}, Dimension::Length{0}, Dimension::Mass{0}, + Dimension::ElectricCurrent{0}, Dimension::Temperature{-1}, + Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0})); +} + +TEST(UnitThermalExpansion, RelatedUnitSystem) { + EXPECT_EQ(RelatedUnitSystem(ReciprocalTemperature::PerKelvin), std::nullopt); + EXPECT_EQ(RelatedUnitSystem(ReciprocalTemperature::PerCelsius), std::nullopt); + EXPECT_EQ(RelatedUnitSystem(ReciprocalTemperature::PerRankine), std::nullopt); + EXPECT_EQ(RelatedUnitSystem(ReciprocalTemperature::PerFahrenheit), std::nullopt); +} + +TEST(UnitThermalExpansion, Standard) { + EXPECT_EQ(Standard, ReciprocalTemperature::PerKelvin); +} + +TEST(UnitThermalExpansion, Stream) { + std::ostringstream stream; + stream << ReciprocalTemperature::PerKelvin; + EXPECT_EQ(stream.str(), Abbreviation(ReciprocalTemperature::PerKelvin)); +} + +} // namespace + +} // namespace PhQ::Unit diff --git a/test/Unit/ThermalExpansion.cpp b/test/Unit/ThermalExpansion.cpp deleted file mode 100644 index d3ffeab9..00000000 --- a/test/Unit/ThermalExpansion.cpp +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright © 2020-2024 Alexandre Coderre-Chabot -// -// This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical -// models, and units of measure for scientific computing. -// -// Physical Quantities is hosted at: -// https://github.com/acodcha/phq -// -// Physical Quantities is licensed under the MIT License: -// https://mit-license.org -// -// 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. - -#include "../../include/PhQ/Unit/ThermalExpansion.hpp" - -#include -#include -#include -#include - -#include "../../include/PhQ/Base.hpp" -#include "../../include/PhQ/Dimension/ElectricCurrent.hpp" -#include "../../include/PhQ/Dimension/Length.hpp" -#include "../../include/PhQ/Dimension/Mass.hpp" -#include "../../include/PhQ/Dimension/Temperature.hpp" -#include "../../include/PhQ/Dimension/Time.hpp" -#include "../../include/PhQ/Dimensions.hpp" -#include "../../include/PhQ/UnitSystem.hpp" -#include "../Unit.hpp" - -namespace PhQ::Unit { - -namespace { - -constexpr std::array Units = { - ThermalExpansion::PerKelvin, - ThermalExpansion::PerCelsius, - ThermalExpansion::PerRankine, - ThermalExpansion::PerFahrenheit, -}; - -TEST(UnitThermalExpansion, Abbreviation) { - EXPECT_EQ(Abbreviation(ThermalExpansion::PerKelvin), "/K"); - EXPECT_EQ(Abbreviation(ThermalExpansion::PerCelsius), "/°C"); - EXPECT_EQ(Abbreviation(ThermalExpansion::PerRankine), "/°R"); - EXPECT_EQ(Abbreviation(ThermalExpansion::PerFahrenheit), "/°F"); -} - -TEST(UnitThermalExpansion, ConsistentUnit) { - EXPECT_EQ(ConsistentUnit(UnitSystem::MetreKilogramSecondKelvin), - ThermalExpansion::PerKelvin); - EXPECT_EQ(ConsistentUnit(UnitSystem::MillimetreGramSecondKelvin), - ThermalExpansion::PerKelvin); - EXPECT_EQ(ConsistentUnit(UnitSystem::FootPoundSecondRankine), - ThermalExpansion::PerRankine); - EXPECT_EQ(ConsistentUnit(UnitSystem::InchPoundSecondRankine), - ThermalExpansion::PerRankine); -} - -TEST(UnitThermalExpansion, Convert) { - constexpr long double value{1.234567890123456789L}; - Internal::TestConvert( - ThermalExpansion::PerKelvin, ThermalExpansion::PerKelvin, value, value); - Internal::TestConvert( - ThermalExpansion::PerKelvin, ThermalExpansion::PerCelsius, value, value); - Internal::TestConvert( - ThermalExpansion::PerKelvin, ThermalExpansion::PerRankine, value, value / 1.8L); - Internal::TestConvert( - ThermalExpansion::PerKelvin, ThermalExpansion::PerFahrenheit, value, value / 1.8L); -} - -TEST(UnitThermalExpansion, ConvertStatically) { - constexpr long double value{1.234567890123456789L}; - Internal::TestConvertStatically(value, value / 1.8L); -} - -TEST(UnitThermalExpansion, ParseEnumeration) { - EXPECT_EQ(ParseEnumeration("Hello world!"), std::nullopt); - EXPECT_EQ(ParseEnumeration("/K"), ThermalExpansion::PerKelvin); - EXPECT_EQ(ParseEnumeration("/°C"), ThermalExpansion::PerCelsius); - EXPECT_EQ(ParseEnumeration("/°R"), ThermalExpansion::PerRankine); - EXPECT_EQ(ParseEnumeration("/°F"), ThermalExpansion::PerFahrenheit); -} - -TEST(UnitThermalExpansion, RelatedDimensions) { - EXPECT_EQ(RelatedDimensions, - Dimensions(Dimension::Time{0}, Dimension::Length{0}, Dimension::Mass{0}, - Dimension::ElectricCurrent{0}, Dimension::Temperature{-1}, - Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0})); -} - -TEST(UnitThermalExpansion, RelatedUnitSystem) { - EXPECT_EQ(RelatedUnitSystem(ThermalExpansion::PerKelvin), std::nullopt); - EXPECT_EQ(RelatedUnitSystem(ThermalExpansion::PerCelsius), std::nullopt); - EXPECT_EQ(RelatedUnitSystem(ThermalExpansion::PerRankine), std::nullopt); - EXPECT_EQ(RelatedUnitSystem(ThermalExpansion::PerFahrenheit), std::nullopt); -} - -TEST(UnitThermalExpansion, Standard) { - EXPECT_EQ(Standard, ThermalExpansion::PerKelvin); -} - -TEST(UnitThermalExpansion, Stream) { - std::ostringstream stream; - stream << ThermalExpansion::PerKelvin; - EXPECT_EQ(stream.str(), Abbreviation(ThermalExpansion::PerKelvin)); -} - -} // namespace - -} // namespace PhQ::Unit diff --git a/test/VolumetricThermalExpansionCoefficient.cpp b/test/VolumetricThermalExpansionCoefficient.cpp index 38ea5fbf..974dbfc9 100644 --- a/test/VolumetricThermalExpansionCoefficient.cpp +++ b/test/VolumetricThermalExpansionCoefficient.cpp @@ -31,8 +31,8 @@ #include "../include/PhQ/Strain.hpp" #include "../include/PhQ/TemperatureDifference.hpp" +#include "../include/PhQ/Unit/ReciprocalTemperature.hpp" #include "../include/PhQ/Unit/TemperatureDifference.hpp" -#include "../include/PhQ/Unit/ThermalExpansion.hpp" #include "Performance.hpp" namespace PhQ { @@ -40,75 +40,82 @@ namespace PhQ { namespace { TEST(VolumetricThermalExpansionCoefficient, ArithmeticOperatorAddition) { - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin) - + VolumetricThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin), - VolumetricThermalExpansionCoefficient(3.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ( + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin) + + VolumetricThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin), + VolumetricThermalExpansionCoefficient(3.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(VolumetricThermalExpansionCoefficient, ArithmeticOperatorDivision) { - EXPECT_EQ(VolumetricThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin) / 2.0, - VolumetricThermalExpansionCoefficient(4.0, Unit::ThermalExpansion::PerKelvin)); - EXPECT_EQ(VolumetricThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin) - / VolumetricThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin), - 4.0); + EXPECT_EQ( + VolumetricThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin) / 2.0, + VolumetricThermalExpansionCoefficient(4.0, Unit::ReciprocalTemperature::PerKelvin)); + EXPECT_EQ( + VolumetricThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin) + / VolumetricThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin), + 4.0); } TEST(VolumetricThermalExpansionCoefficient, ArithmeticOperatorMultiplication) { - EXPECT_EQ(VolumetricThermalExpansionCoefficient(4.0, Unit::ThermalExpansion::PerKelvin) * 2.0, - VolumetricThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin)); - EXPECT_EQ(2.0 * VolumetricThermalExpansionCoefficient(4.0, Unit::ThermalExpansion::PerKelvin), - VolumetricThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin)); - EXPECT_EQ(VolumetricThermalExpansionCoefficient(6.0, Unit::ThermalExpansion::PerKelvin) + EXPECT_EQ( + VolumetricThermalExpansionCoefficient(4.0, Unit::ReciprocalTemperature::PerKelvin) * 2.0, + VolumetricThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin)); + EXPECT_EQ( + 2.0 * VolumetricThermalExpansionCoefficient(4.0, Unit::ReciprocalTemperature::PerKelvin), + VolumetricThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin)); + EXPECT_EQ(VolumetricThermalExpansionCoefficient(6.0, Unit::ReciprocalTemperature::PerKelvin) * TemperatureDifference(2.0, Unit::TemperatureDifference::Kelvin), Strain(4.0, 0.0, 0.0, 4.0, 0.0, 4.0)); - EXPECT_EQ(TemperatureDifference(6.0, Unit::TemperatureDifference::Kelvin) - * VolumetricThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin), - Strain(4.0, 0.0, 0.0, 4.0, 0.0, 4.0)); + EXPECT_EQ( + TemperatureDifference(6.0, Unit::TemperatureDifference::Kelvin) + * VolumetricThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin), + Strain(4.0, 0.0, 0.0, 4.0, 0.0, 4.0)); } TEST(VolumetricThermalExpansionCoefficient, ArithmeticOperatorSubtraction) { - EXPECT_EQ(VolumetricThermalExpansionCoefficient(3.0, Unit::ThermalExpansion::PerKelvin) - - VolumetricThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin), - VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ( + VolumetricThermalExpansionCoefficient(3.0, Unit::ReciprocalTemperature::PerKelvin) + - VolumetricThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin), + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(VolumetricThermalExpansionCoefficient, AssignmentOperatorAddition) { VolumetricThermalExpansionCoefficient volumetric_thermal_expansion_coefficient{ - 1.0, Unit::ThermalExpansion::PerKelvin}; + 1.0, Unit::ReciprocalTemperature::PerKelvin}; volumetric_thermal_expansion_coefficient += - VolumetricThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin); + VolumetricThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin); EXPECT_EQ(volumetric_thermal_expansion_coefficient, - VolumetricThermalExpansionCoefficient(3.0, Unit::ThermalExpansion::PerKelvin)); + VolumetricThermalExpansionCoefficient(3.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(VolumetricThermalExpansionCoefficient, AssignmentOperatorDivision) { VolumetricThermalExpansionCoefficient volumetric_thermal_expansion_coefficient{ - 8.0, Unit::ThermalExpansion::PerKelvin}; + 8.0, Unit::ReciprocalTemperature::PerKelvin}; volumetric_thermal_expansion_coefficient /= 2.0; EXPECT_EQ(volumetric_thermal_expansion_coefficient, - VolumetricThermalExpansionCoefficient(4.0, Unit::ThermalExpansion::PerKelvin)); + VolumetricThermalExpansionCoefficient(4.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(VolumetricThermalExpansionCoefficient, AssignmentOperatorMultiplication) { VolumetricThermalExpansionCoefficient volumetric_thermal_expansion_coefficient{ - 4.0, Unit::ThermalExpansion::PerKelvin}; + 4.0, Unit::ReciprocalTemperature::PerKelvin}; volumetric_thermal_expansion_coefficient *= 2.0; EXPECT_EQ(volumetric_thermal_expansion_coefficient, - VolumetricThermalExpansionCoefficient(8.0, Unit::ThermalExpansion::PerKelvin)); + VolumetricThermalExpansionCoefficient(8.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(VolumetricThermalExpansionCoefficient, AssignmentOperatorSubtraction) { VolumetricThermalExpansionCoefficient volumetric_thermal_expansion_coefficient{ - 3.0, Unit::ThermalExpansion::PerKelvin}; + 3.0, Unit::ReciprocalTemperature::PerKelvin}; volumetric_thermal_expansion_coefficient -= - VolumetricThermalExpansionCoefficient(2.0, Unit::ThermalExpansion::PerKelvin); + VolumetricThermalExpansionCoefficient(2.0, Unit::ReciprocalTemperature::PerKelvin); EXPECT_EQ(volumetric_thermal_expansion_coefficient, - VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(VolumetricThermalExpansionCoefficient, ComparisonOperators) { - const VolumetricThermalExpansionCoefficient first{1.0, Unit::ThermalExpansion::PerKelvin}; - const VolumetricThermalExpansionCoefficient second{2.0, Unit::ThermalExpansion::PerKelvin}; + const VolumetricThermalExpansionCoefficient first{1.0, Unit::ReciprocalTemperature::PerKelvin}; + const VolumetricThermalExpansionCoefficient second{2.0, Unit::ReciprocalTemperature::PerKelvin}; EXPECT_EQ(first, first); EXPECT_NE(first, second); EXPECT_LT(first, second); @@ -120,71 +127,73 @@ TEST(VolumetricThermalExpansionCoefficient, ComparisonOperators) { } TEST(VolumetricThermalExpansionCoefficient, Constructor) { - EXPECT_NO_THROW(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine)); - EXPECT_EQ(Strain(VolumetricThermalExpansionCoefficient(6.0, Unit::ThermalExpansion::PerKelvin), - TemperatureDifference(2.0, Unit::TemperatureDifference::Kelvin)), - Strain(4.0, 0.0, 0.0, 4.0, 0.0, 4.0)); + EXPECT_NO_THROW( + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine)); + EXPECT_EQ( + Strain(VolumetricThermalExpansionCoefficient(6.0, Unit::ReciprocalTemperature::PerKelvin), + TemperatureDifference(2.0, Unit::TemperatureDifference::Kelvin)), + Strain(4.0, 0.0, 0.0, 4.0, 0.0, 4.0)); } TEST(VolumetricThermalExpansionCoefficient, CopyAssignmentOperator) { { const VolumetricThermalExpansionCoefficient first( - 1.0F, Unit::ThermalExpansion::PerKelvin); + 1.0F, Unit::ReciprocalTemperature::PerKelvin); VolumetricThermalExpansionCoefficient second = VolumetricThermalExpansionCoefficient::Zero(); second = first; EXPECT_EQ(second, VolumetricThermalExpansionCoefficient( - 1.0, Unit::ThermalExpansion::PerKelvin)); + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } { const VolumetricThermalExpansionCoefficient first( - 1.0, Unit::ThermalExpansion::PerKelvin); + 1.0, Unit::ReciprocalTemperature::PerKelvin); VolumetricThermalExpansionCoefficient second = VolumetricThermalExpansionCoefficient::Zero(); second = first; EXPECT_EQ(second, VolumetricThermalExpansionCoefficient( - 1.0, Unit::ThermalExpansion::PerKelvin)); + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } { const VolumetricThermalExpansionCoefficient first( - 1.0L, Unit::ThermalExpansion::PerKelvin); + 1.0L, Unit::ReciprocalTemperature::PerKelvin); VolumetricThermalExpansionCoefficient second = VolumetricThermalExpansionCoefficient::Zero(); second = first; EXPECT_EQ(second, VolumetricThermalExpansionCoefficient( - 1.0, Unit::ThermalExpansion::PerKelvin)); + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } } TEST(VolumetricThermalExpansionCoefficient, CopyConstructor) { { const VolumetricThermalExpansionCoefficient first( - 1.0F, Unit::ThermalExpansion::PerKelvin); + 1.0F, Unit::ReciprocalTemperature::PerKelvin); const VolumetricThermalExpansionCoefficient second{first}; EXPECT_EQ(second, VolumetricThermalExpansionCoefficient( - 1.0, Unit::ThermalExpansion::PerKelvin)); + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } { const VolumetricThermalExpansionCoefficient first( - 1.0, Unit::ThermalExpansion::PerKelvin); + 1.0, Unit::ReciprocalTemperature::PerKelvin); const VolumetricThermalExpansionCoefficient second{first}; EXPECT_EQ(second, VolumetricThermalExpansionCoefficient( - 1.0, Unit::ThermalExpansion::PerKelvin)); + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } { const VolumetricThermalExpansionCoefficient first( - 1.0L, Unit::ThermalExpansion::PerKelvin); + 1.0L, Unit::ReciprocalTemperature::PerKelvin); const VolumetricThermalExpansionCoefficient second{first}; EXPECT_EQ(second, VolumetricThermalExpansionCoefficient( - 1.0, Unit::ThermalExpansion::PerKelvin)); + 1.0, Unit::ReciprocalTemperature::PerKelvin)); } } TEST(VolumetricThermalExpansionCoefficient, Create) { constexpr VolumetricThermalExpansionCoefficient volumetric_thermal_expansion_coefficient = - VolumetricThermalExpansionCoefficient<>::Create(1.0); + VolumetricThermalExpansionCoefficient<>::Create(1.0); EXPECT_EQ(volumetric_thermal_expansion_coefficient, - VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(VolumetricThermalExpansionCoefficient, DefaultConstructor) { @@ -193,13 +202,14 @@ TEST(VolumetricThermalExpansionCoefficient, DefaultConstructor) { TEST(VolumetricThermalExpansionCoefficient, Dimensions) { EXPECT_EQ(VolumetricThermalExpansionCoefficient<>::Dimensions(), - RelatedDimensions); + RelatedDimensions); } TEST(VolumetricThermalExpansionCoefficient, Hash) { - const VolumetricThermalExpansionCoefficient first{1.0, Unit::ThermalExpansion::PerRankine}; - const VolumetricThermalExpansionCoefficient second{1.000001, Unit::ThermalExpansion::PerRankine}; - const VolumetricThermalExpansionCoefficient third{-1.0, Unit::ThermalExpansion::PerRankine}; + const VolumetricThermalExpansionCoefficient first{1.0, Unit::ReciprocalTemperature::PerRankine}; + const VolumetricThermalExpansionCoefficient second{ + 1.000001, Unit::ReciprocalTemperature::PerRankine}; + const VolumetricThermalExpansionCoefficient third{-1.0, Unit::ReciprocalTemperature::PerRankine}; const std::hash> hasher; EXPECT_NE(hasher(first), hasher(second)); EXPECT_NE(hasher(first), hasher(third)); @@ -207,29 +217,32 @@ TEST(VolumetricThermalExpansionCoefficient, Hash) { } TEST(VolumetricThermalExpansionCoefficient, JSON) { - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).JSON(), - "{\"value\":" + Print(1.0) + ",\"unit\":\"/K\"}"); - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .JSON(Unit::ThermalExpansion::PerRankine), + EXPECT_EQ( + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).JSON(), + "{\"value\":" + Print(1.0) + ",\"unit\":\"/K\"}"); + EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .JSON(Unit::ReciprocalTemperature::PerRankine), "{\"value\":" + Print(1.0) + ",\"unit\":\"/°R\"}"); } TEST(VolumetricThermalExpansionCoefficient, MoveAssignmentOperator) { - VolumetricThermalExpansionCoefficient first{1.0, Unit::ThermalExpansion::PerKelvin}; + VolumetricThermalExpansionCoefficient first{1.0, Unit::ReciprocalTemperature::PerKelvin}; VolumetricThermalExpansionCoefficient second = VolumetricThermalExpansionCoefficient<>::Zero(); second = std::move(first); - EXPECT_EQ(second, VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ( + second, VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(VolumetricThermalExpansionCoefficient, MoveConstructor) { - VolumetricThermalExpansionCoefficient first{1.0, Unit::ThermalExpansion::PerKelvin}; + VolumetricThermalExpansionCoefficient first{1.0, Unit::ReciprocalTemperature::PerKelvin}; const VolumetricThermalExpansionCoefficient second{std::move(first)}; - EXPECT_EQ(second, VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin)); + EXPECT_EQ( + second, VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin)); } TEST(VolumetricThermalExpansionCoefficient, MutableValue) { VolumetricThermalExpansionCoefficient volumetric_thermal_expansion_coefficient{ - 1.0, Unit::ThermalExpansion::PerKelvin}; + 1.0, Unit::ReciprocalTemperature::PerKelvin}; double& value = volumetric_thermal_expansion_coefficient.MutableValue(); value = 2.0; EXPECT_EQ(volumetric_thermal_expansion_coefficient.Value(), 2.0); @@ -237,25 +250,26 @@ TEST(VolumetricThermalExpansionCoefficient, MutableValue) { TEST(VolumetricThermalExpansionCoefficient, Performance) { VolumetricThermalExpansionCoefficient first{ - 1.2345678901234567890, Unit::ThermalExpansion::PerKelvin}; + 1.2345678901234567890, Unit::ReciprocalTemperature::PerKelvin}; VolumetricThermalExpansionCoefficient second{ - 1.2345678901234567890, Unit::ThermalExpansion::PerKelvin}; + 1.2345678901234567890, Unit::ReciprocalTemperature::PerKelvin}; double first_reference{1.2345678901234567890}; double second_reference{1.2345678901234567890}; Internal::TestScalarPerformance(first, second, first_reference, second_reference); } TEST(VolumetricThermalExpansionCoefficient, Print) { - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).Print(), - Print(1.0) + " /K"); - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .Print(Unit::ThermalExpansion::PerRankine), + EXPECT_EQ( + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).Print(), + Print(1.0) + " /K"); + EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .Print(Unit::ReciprocalTemperature::PerRankine), Print(1.0) + " /°R"); } TEST(VolumetricThermalExpansionCoefficient, SetValue) { VolumetricThermalExpansionCoefficient volumetric_thermal_expansion_coefficient{ - 1.0, Unit::ThermalExpansion::PerKelvin}; + 1.0, Unit::ReciprocalTemperature::PerKelvin}; volumetric_thermal_expansion_coefficient.SetValue(2.0); EXPECT_EQ(volumetric_thermal_expansion_coefficient.Value(), 2.0); } @@ -266,50 +280,54 @@ TEST(VolumetricThermalExpansionCoefficient, SizeOf) { TEST(VolumetricThermalExpansionCoefficient, StaticValue) { constexpr VolumetricThermalExpansionCoefficient volumetric_thermal_expansion_coefficient = - VolumetricThermalExpansionCoefficient<>::Create(1.0); - constexpr double value = - volumetric_thermal_expansion_coefficient.StaticValue(); + VolumetricThermalExpansionCoefficient<>::Create(1.0); + constexpr double value = volumetric_thermal_expansion_coefficient + .StaticValue(); EXPECT_EQ(value, 1.0); } TEST(VolumetricThermalExpansionCoefficient, Stream) { std::ostringstream stream; - stream << VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin); - EXPECT_EQ(stream.str(), - VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).Print()); + stream << VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin); + EXPECT_EQ( + stream.str(), + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).Print()); } TEST(VolumetricThermalExpansionCoefficient, Unit) { - EXPECT_EQ(VolumetricThermalExpansionCoefficient<>::Unit(), Standard); + EXPECT_EQ(VolumetricThermalExpansionCoefficient<>::Unit(), Standard); } TEST(VolumetricThermalExpansionCoefficient, Value) { EXPECT_EQ( - VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).Value(), 1.0); - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .Value(Unit::ThermalExpansion::PerRankine), + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).Value(), + 1.0); + EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .Value(Unit::ReciprocalTemperature::PerRankine), 1.0); } TEST(VolumetricThermalExpansionCoefficient, XML) { - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).XML(), - "" + Print(1.0) + "/K"); - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .XML(Unit::ThermalExpansion::PerRankine), + EXPECT_EQ( + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).XML(), + "" + Print(1.0) + "/K"); + EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .XML(Unit::ReciprocalTemperature::PerRankine), "" + Print(1.0) + "/°R"); } TEST(VolumetricThermalExpansionCoefficient, YAML) { - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerKelvin).YAML(), - "{value:" + Print(1.0) + ",unit:\"/K\"}"); - EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ThermalExpansion::PerRankine) - .YAML(Unit::ThermalExpansion::PerRankine), + EXPECT_EQ( + VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerKelvin).YAML(), + "{value:" + Print(1.0) + ",unit:\"/K\"}"); + EXPECT_EQ(VolumetricThermalExpansionCoefficient(1.0, Unit::ReciprocalTemperature::PerRankine) + .YAML(Unit::ReciprocalTemperature::PerRankine), "{value:" + Print(1.0) + ",unit:\"/°R\"}"); } TEST(VolumetricThermalExpansionCoefficient, Zero) { EXPECT_EQ(VolumetricThermalExpansionCoefficient<>::Zero(), - VolumetricThermalExpansionCoefficient(0.0, Unit::ThermalExpansion::PerKelvin)); + VolumetricThermalExpansionCoefficient(0.0, Unit::ReciprocalTemperature::PerKelvin)); } } // namespace