Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
VolumetricThermalExpansionCoefficient.hpp
Go to the documentation of this file.
1 // Copyright © 2020-2024 Alexandre Coderre-Chabot
2 //
3 // This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical
4 // models, and units of measure for scientific computing.
5 //
6 // Physical Quantities is hosted at:
7 // https://github.com/acodcha/phq
8 //
9 // Physical Quantities is licensed under the MIT License:
10 // https://mit-license.org
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
13 // associated documentation files (the "Software"), to deal in the Software without restriction,
14 // including without limitation the rights to use, copy, modify, merge, publish, distribute,
15 // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 // - The above copyright notice and this permission notice shall be included in all copies or
18 // substantial portions of the Software.
19 // - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
20 // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 #ifndef PHQ_VOLUMETRIC_THERMAL_EXPANSION_COEFFICIENT_HPP
26 #define PHQ_VOLUMETRIC_THERMAL_EXPANSION_COEFFICIENT_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
33 #include "Strain.hpp"
36 
37 namespace PhQ {
38 
39 /// \brief Volumetric thermal expansion coefficient. Not to be confused with the linear thermal
40 /// expansion coefficient; see PhQ::LinearThermalExpansionCoefficient. For isotropic materials, the
41 /// volumetric thermal expansion coefficient is usually three times the linear thermal expansion
42 /// coefficient.
43 template <typename NumericType = double>
45  : public DimensionalScalar<Unit::ReciprocalTemperature, NumericType> {
46 public:
47  /// \brief Default constructor. Constructs a volumetric thermal expansion coefficient with an
48  /// uninitialized value.
50 
51  /// \brief Constructor. Constructs a volumetric thermal expansion coefficient with a given value
52  /// expressed in a given reciprocal temperature unit.
54  const NumericType value, const Unit::ReciprocalTemperature unit)
55  : DimensionalScalar<Unit::ReciprocalTemperature, NumericType>(value, unit) {}
56 
57  /// \brief Destructor. Destroys this volumetric thermal expansion coefficient.
59 
60  /// \brief Copy constructor. Constructs a volumetric thermal expansion coefficient by copying
61  /// another one.
63  const VolumetricThermalExpansionCoefficient<NumericType>& other) = default;
64 
65  /// \brief Copy constructor. Constructs a volumetric thermal expansion coefficient by copying
66  /// another one.
67  template <typename OtherNumericType>
69  const VolumetricThermalExpansionCoefficient<OtherNumericType>& other)
70  : VolumetricThermalExpansionCoefficient(static_cast<NumericType>(other.Value())) {}
71 
72  /// \brief Move constructor. Constructs a volumetric thermal expansion coefficient by moving
73  /// another one.
75  VolumetricThermalExpansionCoefficient<NumericType>&& other) noexcept = default;
76 
77  /// \brief Copy assignment operator. Assigns this volumetric thermal expansion coefficient by
78  /// copying another one.
81 
82  /// \brief Copy assignment operator. Assigns this volumetric thermal expansion coefficient by
83  /// copying another one.
84  template <typename OtherNumericType>
87  this->value = static_cast<NumericType>(other.Value());
88  return *this;
89  }
90 
91  /// \brief Move assignment operator. Assigns this volumetric thermal expansion coefficient by
92  /// moving another one.
94  VolumetricThermalExpansionCoefficient<NumericType>&& other) noexcept = default;
95 
96  /// \brief Statically creates a volumetric thermal expansion coefficient of zero.
97  [[nodiscard]] static constexpr VolumetricThermalExpansionCoefficient<NumericType> Zero() {
98  return VolumetricThermalExpansionCoefficient<NumericType>{static_cast<NumericType>(0)};
99  }
100 
101  /// \brief Statically creates a volumetric thermal expansion coefficient with a given value
102  /// expressed in a given reciprocal temperature unit.
103  template <Unit::ReciprocalTemperature Unit>
105  const NumericType value) {
107  ConvertStatically<Unit::ReciprocalTemperature, Unit, Standard<Unit::ReciprocalTemperature>>(
108  value)};
109  }
110 
113  volumetric_thermal_expansion_coefficient) const {
115  this->value + volumetric_thermal_expansion_coefficient.value};
116  }
117 
120  volumetric_thermal_expansion_coefficient) const {
122  this->value - volumetric_thermal_expansion_coefficient.value};
123  }
124 
126  const NumericType number) const {
128  }
129 
131  const TemperatureDifference<NumericType>& temperature_difference) const {
132  return Strain<NumericType>{*this, temperature_difference};
133  }
134 
136  const NumericType number) const {
138  }
139 
141  volumetric_thermal_expansion_coefficient) const noexcept {
142  return this->value / volumetric_thermal_expansion_coefficient.value;
143  }
144 
146  volumetric_thermal_expansion_coefficient) noexcept {
147  this->value += volumetric_thermal_expansion_coefficient.value;
148  }
149 
151  volumetric_thermal_expansion_coefficient) noexcept {
152  this->value -= volumetric_thermal_expansion_coefficient.value;
153  }
154 
155  constexpr void operator*=(const NumericType number) noexcept {
156  this->value *= number;
157  }
158 
159  constexpr void operator/=(const NumericType number) noexcept {
160  this->value /= number;
161  }
162 
163 private:
164  /// \brief Constructor. Constructs a volumetric thermal expansion coefficient with a given value
165  /// expressed in the standard reciprocal temperature unit.
166  explicit constexpr VolumetricThermalExpansionCoefficient(const NumericType value)
168 };
169 
170 template <typename NumericType>
171 inline constexpr bool operator==(
174  return left.Value() == right.Value();
175 }
176 
177 template <typename NumericType>
178 inline constexpr bool operator!=(
181  return left.Value() != right.Value();
182 }
183 
184 template <typename NumericType>
185 inline constexpr bool operator<(
188  return left.Value() < right.Value();
189 }
190 
191 template <typename NumericType>
192 inline constexpr bool operator>(
195  return left.Value() > right.Value();
196 }
197 
198 template <typename NumericType>
199 inline constexpr bool operator<=(
202  return left.Value() <= right.Value();
203 }
204 
205 template <typename NumericType>
206 inline constexpr bool operator>=(
209  return left.Value() >= right.Value();
210 }
211 
212 template <typename NumericType>
213 inline std::ostream& operator<<(
214  std::ostream& stream, const VolumetricThermalExpansionCoefficient<NumericType>&
215  volumetric_thermal_expansion_coefficient) {
216  stream << volumetric_thermal_expansion_coefficient.Print();
217  return stream;
218 }
219 
220 template <typename NumericType>
222  const NumericType number, const VolumetricThermalExpansionCoefficient<NumericType>&
223  volumetric_thermal_expansion_coefficient) {
224  return volumetric_thermal_expansion_coefficient * number;
225 }
226 
227 template <typename NumericType>
230  volumetric_thermal_expansion_coefficient,
231  const TemperatureDifference<NumericType>& temperature_difference)
232  : Strain<NumericType>(
233  volumetric_thermal_expansion_coefficient.Value() * temperature_difference.Value()
234  / static_cast<NumericType>(3),
235  static_cast<NumericType>(0), static_cast<NumericType>(0),
236  volumetric_thermal_expansion_coefficient.Value() * temperature_difference.Value()
237  / static_cast<NumericType>(3),
238  static_cast<NumericType>(0),
239  volumetric_thermal_expansion_coefficient.Value() * temperature_difference.Value()
240  / static_cast<NumericType>(3)) {}
241 
242 template <typename NumericType>
245  volumetric_thermal_expansion_coefficient) const {
246  return Strain<NumericType>{volumetric_thermal_expansion_coefficient, *this};
247 }
248 
249 } // namespace PhQ
250 
251 namespace std {
252 
253 template <typename NumericType>
254 struct hash<PhQ::VolumetricThermalExpansionCoefficient<NumericType>> {
255  inline size_t operator()(const PhQ::VolumetricThermalExpansionCoefficient<NumericType>&
256  volumetric_thermal_expansion_coefficient) const {
257  return hash<NumericType>()(volumetric_thermal_expansion_coefficient.Value());
258  }
259 };
260 
261 } // namespace std
262 
263 #endif // PHQ_VOLUMETRIC_THERMAL_EXPANSION_COEFFICIENT_HPP
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
double value
Value of this physical quantity expressed in its standard unit of measure.
constexpr double Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr Unit::ReciprocalTemperature Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
Three-dimensional Euclidean strain symmetric dyadic tensor. Contains six components in Cartesian coor...
Definition: Strain.hpp:68
Strain()=default
Default constructor. Constructs a strain tensor with an uninitialized value.
Temperature difference. Not to be confused with temperature; see PhQ::Temperature....
constexpr TemperatureDifference< NumericType > operator*(const NumericType number) const
Volumetric thermal expansion coefficient. Not to be confused with the linear thermal expansion coeffi...
constexpr VolumetricThermalExpansionCoefficient< NumericType > & operator=(const VolumetricThermalExpansionCoefficient< OtherNumericType > &other)
Copy assignment operator. Assigns this volumetric thermal expansion coefficient by copying another on...
constexpr void operator/=(const NumericType number) noexcept
constexpr VolumetricThermalExpansionCoefficient< NumericType > operator*(const NumericType number) const
~VolumetricThermalExpansionCoefficient() noexcept=default
Destructor. Destroys this volumetric thermal expansion coefficient.
VolumetricThermalExpansionCoefficient(const NumericType value, const Unit::ReciprocalTemperature unit)
Constructor. Constructs a volumetric thermal expansion coefficient with a given value expressed in a ...
constexpr VolumetricThermalExpansionCoefficient< NumericType > operator/(const NumericType number) const
VolumetricThermalExpansionCoefficient()=default
Default constructor. Constructs a volumetric thermal expansion coefficient with an uninitialized valu...
constexpr void operator+=(const VolumetricThermalExpansionCoefficient< NumericType > &volumetric_thermal_expansion_coefficient) noexcept
constexpr VolumetricThermalExpansionCoefficient(const NumericType value)
Constructor. Constructs a volumetric thermal expansion coefficient with a given value expressed in th...
constexpr void operator-=(const VolumetricThermalExpansionCoefficient< NumericType > &volumetric_thermal_expansion_coefficient) noexcept
constexpr VolumetricThermalExpansionCoefficient< NumericType > operator-(const VolumetricThermalExpansionCoefficient< NumericType > &volumetric_thermal_expansion_coefficient) const
constexpr VolumetricThermalExpansionCoefficient< NumericType > & operator=(VolumetricThermalExpansionCoefficient< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this volumetric thermal expansion coefficient by moving another one...
constexpr NumericType operator/(const VolumetricThermalExpansionCoefficient< NumericType > &volumetric_thermal_expansion_coefficient) const noexcept
constexpr Strain< NumericType > operator*(const TemperatureDifference< NumericType > &temperature_difference) const
static constexpr VolumetricThermalExpansionCoefficient< NumericType > Zero()
Statically creates a volumetric thermal expansion coefficient of zero.
constexpr void operator*=(const NumericType number) noexcept
constexpr VolumetricThermalExpansionCoefficient< NumericType > & operator=(const VolumetricThermalExpansionCoefficient< NumericType > &other)=default
Copy assignment operator. Assigns this volumetric thermal expansion coefficient by copying another on...
constexpr VolumetricThermalExpansionCoefficient(VolumetricThermalExpansionCoefficient< NumericType > &&other) noexcept=default
Move constructor. Constructs a volumetric thermal expansion coefficient by moving another one.
static constexpr VolumetricThermalExpansionCoefficient< NumericType > Create(const NumericType value)
Statically creates a volumetric thermal expansion coefficient with a given value expressed in a given...
constexpr VolumetricThermalExpansionCoefficient< NumericType > operator+(const VolumetricThermalExpansionCoefficient< NumericType > &volumetric_thermal_expansion_coefficient) const
ReciprocalTemperature
Reciprocal temperature units. Reciprocal temperature is the inverse of temperature.
Namespace that encompasses all of the Physical Quantities library's content.
constexpr bool operator<(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator<=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr Acceleration< NumericType > operator*(const NumericType number, const Acceleration< NumericType > &acceleration)
constexpr bool operator>(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator==(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator>=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)