Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ScalarThermalConductivity.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_SCALAR_THERMAL_CONDUCTIVITY_HPP
26 #define PHQ_SCALAR_THERMAL_CONDUCTIVITY_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
34 
35 namespace PhQ {
36 
37 // Forward declaration for class PhQ::ScalarThermalConductivity.
38 template <typename NumericType>
39 class DynamicViscosity;
40 
41 // Forward declaration for class PhQ::ScalarThermalConductivity.
42 template <typename NumericType>
43 class MassDensity;
44 
45 // Forward declaration for class PhQ::ScalarThermalConductivity.
46 template <typename NumericType>
47 class PrandtlNumber;
48 
49 // Forward declaration for class PhQ::ScalarThermalConductivity.
50 template <typename NumericType>
51 class SpecificIsobaricHeatCapacity;
52 
53 // Forward declaration for class PhQ::ScalarThermalConductivity.
54 template <typename NumericType>
55 class ThermalDiffusivity;
56 
57 /// \brief Scalar component or resultant of a three-dimensional Euclidean thermal conductivity
58 /// symmetric dyadic tensor. In general, thermal conductivity is a tensor; however, in isotropic
59 /// materials, thermal conductivity simplifies to a scalar. For the related tensor, see
60 /// PhQ::ThermalConductivity.
61 template <typename NumericType = double>
62 class ScalarThermalConductivity : public DimensionalScalar<Unit::ThermalConductivity, NumericType> {
63 public:
64  /// \brief Default constructor. Constructs a scalar thermal conductivity with an uninitialized
65  /// value.
67 
68  /// \brief Constructor. Constructs a scalar thermal conductivity with a given value expressed in a
69  /// given thermal conductivity unit.
71  : DimensionalScalar<Unit::ThermalConductivity, NumericType>(value, unit) {}
72 
73  /// \brief Constructor. Constructs a scalar thermal conductivity from a given mass density,
74  /// specific isobaric heat capacity, and thermal diffusivity using the definition of thermal
75  /// diffusivity.
76  constexpr ScalarThermalConductivity(
77  const MassDensity<NumericType>& mass_density,
78  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
79  const ThermalDiffusivity<NumericType>& thermal_diffusivity);
80 
81  /// \brief Constructor. Constructs a scalar thermal conductivity from a given specific isobaric
82  /// heat capacity, dynamic viscosity, and Prandtl number using the definition of the Prandtl
83  /// number.
84  constexpr ScalarThermalConductivity(
85  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
86  const DynamicViscosity<NumericType>& dynamic_viscosity,
87  const PrandtlNumber<NumericType>& prandtl_number);
88 
89  /// \brief Destructor. Destroys this scalar thermal conductivity.
90  ~ScalarThermalConductivity() noexcept = default;
91 
92  /// \brief Copy constructor. Constructs a scalar thermal conductivity by copying another one.
94  const ScalarThermalConductivity<NumericType>& other) = default;
95 
96  /// \brief Copy constructor. Constructs a scalar thermal conductivity by copying another one.
97  template <typename OtherNumericType>
98  explicit constexpr ScalarThermalConductivity(
99  const ScalarThermalConductivity<OtherNumericType>& other)
100  : ScalarThermalConductivity(static_cast<NumericType>(other.Value())) {}
101 
102  /// \brief Move constructor. Constructs a scalar thermal conductivity by moving another one.
104  ScalarThermalConductivity<NumericType>&& other) noexcept = default;
105 
106  /// \brief Copy assignment operator. Assigns this scalar thermal conductivity by copying another
107  /// one.
109  const ScalarThermalConductivity<NumericType>& other) = default;
110 
111  /// \brief Copy assignment operator. Assigns this scalar thermal conductivity by copying another
112  /// one.
113  template <typename OtherNumericType>
116  this->value = static_cast<NumericType>(other.Value());
117  return *this;
118  }
119 
120  /// \brief Move assignment operator. Assigns this scalar thermal conductivity by moving another
121  /// one.
123  ScalarThermalConductivity<NumericType>&& other) noexcept = default;
124 
125  /// \brief Statically creates a scalar thermal conductivity of zero.
126  [[nodiscard]] static constexpr ScalarThermalConductivity<NumericType> Zero() {
127  return ScalarThermalConductivity<NumericType>{static_cast<NumericType>(0)};
128  }
129 
130  /// \brief Statically creates a scalar thermal conductivity with a given value expressed in a
131  /// given thermal conductivity unit.
132  template <Unit::ThermalConductivity Unit>
133  [[nodiscard]] static constexpr ScalarThermalConductivity<NumericType> Create(
134  const NumericType value) {
136  ConvertStatically<Unit::ThermalConductivity, Unit, Standard<Unit::ThermalConductivity>>(
137  value)};
138  }
139 
141  const ScalarThermalConductivity<NumericType>& thermal_conductivity_scalar) const {
142  return ScalarThermalConductivity<NumericType>{this->value + thermal_conductivity_scalar.value};
143  }
144 
146  const ScalarThermalConductivity<NumericType>& thermal_conductivity_scalar) const {
147  return ScalarThermalConductivity<NumericType>{this->value - thermal_conductivity_scalar.value};
148  }
149 
150  constexpr ScalarThermalConductivity<NumericType> operator*(const NumericType number) const {
151  return ScalarThermalConductivity<NumericType>{this->value * number};
152  }
153 
154  constexpr ScalarThermalConductivity<NumericType> operator/(const NumericType number) const {
155  return ScalarThermalConductivity<NumericType>{this->value / number};
156  }
157 
158  constexpr NumericType operator/(
159  const ScalarThermalConductivity<NumericType>& thermal_conductivity_scalar) const noexcept {
160  return this->value / thermal_conductivity_scalar.value;
161  }
162 
163  constexpr void operator+=(
164  const ScalarThermalConductivity<NumericType>& thermal_conductivity_scalar) noexcept {
165  this->value += thermal_conductivity_scalar.value;
166  }
167 
168  constexpr void operator-=(
169  const ScalarThermalConductivity<NumericType>& thermal_conductivity_scalar) noexcept {
170  this->value -= thermal_conductivity_scalar.value;
171  }
172 
173  constexpr void operator*=(const NumericType number) noexcept {
174  this->value *= number;
175  }
176 
177  constexpr void operator/=(const NumericType number) noexcept {
178  this->value /= number;
179  }
180 
181 private:
182  /// \brief Constructor. Constructs a scalar thermal conductivity with a given value expressed in
183  /// the standard thermal conductivity unit.
184  explicit constexpr ScalarThermalConductivity(const NumericType value)
185  : DimensionalScalar<Unit::ThermalConductivity, NumericType>(value) {}
186 
187  template <typename OtherNumericType>
188  friend class ThermalConductivity;
189 };
190 
191 template <typename NumericType>
192 inline constexpr bool operator==(const ScalarThermalConductivity<NumericType>& left,
193  const ScalarThermalConductivity<NumericType>& right) noexcept {
194  return left.Value() == right.Value();
195 }
196 
197 template <typename NumericType>
198 inline constexpr bool operator!=(const ScalarThermalConductivity<NumericType>& left,
199  const ScalarThermalConductivity<NumericType>& right) noexcept {
200  return left.Value() != right.Value();
201 }
202 
203 template <typename NumericType>
204 inline constexpr bool operator<(const ScalarThermalConductivity<NumericType>& left,
205  const ScalarThermalConductivity<NumericType>& right) noexcept {
206  return left.Value() < right.Value();
207 }
208 
209 template <typename NumericType>
210 inline constexpr bool operator>(const ScalarThermalConductivity<NumericType>& left,
211  const ScalarThermalConductivity<NumericType>& right) noexcept {
212  return left.Value() > right.Value();
213 }
214 
215 template <typename NumericType>
216 inline constexpr bool operator<=(const ScalarThermalConductivity<NumericType>& left,
217  const ScalarThermalConductivity<NumericType>& right) noexcept {
218  return left.Value() <= right.Value();
219 }
220 
221 template <typename NumericType>
222 inline constexpr bool operator>=(const ScalarThermalConductivity<NumericType>& left,
223  const ScalarThermalConductivity<NumericType>& right) noexcept {
224  return left.Value() >= right.Value();
225 }
226 
227 template <typename NumericType>
228 inline std::ostream& operator<<(
229  std::ostream& stream,
230  const ScalarThermalConductivity<NumericType>& thermal_conductivity_scalar) {
231  stream << thermal_conductivity_scalar.Print();
232  return stream;
233 }
234 
235 template <typename NumericType>
237  const NumericType number,
238  const ScalarThermalConductivity<NumericType>& thermal_conductivity_scalar) {
239  return thermal_conductivity_scalar * number;
240 }
241 
242 } // namespace PhQ
243 
244 namespace std {
245 
246 template <typename NumericType>
247 struct hash<PhQ::ScalarThermalConductivity<NumericType>> {
248  inline size_t operator()(
249  const PhQ::ScalarThermalConductivity<NumericType>& thermal_conductivity_scalar) const {
250  return hash<NumericType>()(thermal_conductivity_scalar.Value());
251  }
252 };
253 
254 } // namespace std
255 
256 #endif // PHQ_SCALAR_THERMAL_CONDUCTIVITY_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::ThermalConductivity 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...
Dynamic viscosity, also known as molecular dynamic viscosity. Dynamic viscosity is the relationship b...
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
Definition: MassDensity.hpp:83
Prandtl number of a fluid. Represents the ratio of the momentum diffusivity to the thermal diffusivit...
Scalar component or resultant of a three-dimensional Euclidean thermal conductivity symmetric dyadic ...
constexpr ScalarThermalConductivity< NumericType > & operator=(const ScalarThermalConductivity< NumericType > &other)=default
Copy assignment operator. Assigns this scalar thermal conductivity by copying another one.
static constexpr ScalarThermalConductivity< NumericType > Zero()
Statically creates a scalar thermal conductivity of zero.
constexpr void operator*=(const NumericType number) noexcept
constexpr ScalarThermalConductivity< NumericType > & operator=(const ScalarThermalConductivity< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar thermal conductivity by copying another one.
constexpr ScalarThermalConductivity< NumericType > operator*(const NumericType number) const
static constexpr ScalarThermalConductivity< NumericType > Create(const NumericType value)
Statically creates a scalar thermal conductivity with a given value expressed in a given thermal cond...
constexpr ScalarThermalConductivity(const NumericType value)
Constructor. Constructs a scalar thermal conductivity with a given value expressed in the standard th...
constexpr NumericType operator/(const ScalarThermalConductivity< NumericType > &thermal_conductivity_scalar) const noexcept
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarThermalConductivity< NumericType > operator-(const ScalarThermalConductivity< NumericType > &thermal_conductivity_scalar) const
constexpr void operator-=(const ScalarThermalConductivity< NumericType > &thermal_conductivity_scalar) noexcept
ScalarThermalConductivity()=default
Default constructor. Constructs a scalar thermal conductivity with an uninitialized value.
constexpr ScalarThermalConductivity< NumericType > operator/(const NumericType number) const
constexpr ScalarThermalConductivity(ScalarThermalConductivity< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar thermal conductivity by moving another one.
constexpr void operator+=(const ScalarThermalConductivity< NumericType > &thermal_conductivity_scalar) noexcept
ScalarThermalConductivity(const NumericType value, const Unit::ThermalConductivity unit)
Constructor. Constructs a scalar thermal conductivity with a given value expressed in a given thermal...
~ScalarThermalConductivity() noexcept=default
Destructor. Destroys this scalar thermal conductivity.
constexpr ScalarThermalConductivity< NumericType > & operator=(ScalarThermalConductivity< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar thermal conductivity by moving another one.
constexpr ScalarThermalConductivity< NumericType > operator+(const ScalarThermalConductivity< NumericType > &thermal_conductivity_scalar) const
Mass-specific isobaric heat capacity, also known as mass-specific heat capacity at constant pressure,...
Three-dimensional Euclidean Cauchy thermal conductivity symmetric dyadic tensor. Contains six compone...
Thermal diffusivity of a material. Measures the rate of heat transfer inside a material....
ThermalConductivity
Thermal conductivity units.
DynamicViscosity
Dynamic viscosity units.
MassDensity
Mass density units.
Definition: MassDensity.hpp:54
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)