Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
BulkDynamicViscosity.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_BULK_DYNAMIC_VISCOSITY_HPP
26 #define PHQ_BULK_DYNAMIC_VISCOSITY_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
34 
35 namespace PhQ {
36 
37 /// \brief Bulk dynamic viscosity, also known as volume dynamic viscosity or dilatational dynamic
38 /// viscosity. Not to be confused with dynamic viscosity; see PhQ::DynamicViscosity.
39 template <typename NumericType = double>
40 class BulkDynamicViscosity : public DimensionalScalar<Unit::DynamicViscosity, NumericType> {
41 public:
42  /// \brief Default constructor. Constructs a bulk dynamic viscosity with an uninitialized value.
43  BulkDynamicViscosity() = default;
44 
45  /// \brief Constructor. Constructs a bulk dynamic viscosity with a given value expressed in a
46  /// given dynamic viscosity unit.
47  BulkDynamicViscosity(const NumericType value, const Unit::DynamicViscosity unit)
48  : DimensionalScalar<Unit::DynamicViscosity, NumericType>(value, unit) {}
49 
50  /// \brief Destructor. Destroys this bulk dynamic viscosity.
51  ~BulkDynamicViscosity() noexcept = default;
52 
53  /// \brief Copy constructor. Constructs a bulk dynamic viscosity by copying another one.
54  constexpr BulkDynamicViscosity(const BulkDynamicViscosity<NumericType>& other) = default;
55 
56  /// \brief Copy constructor. Constructs a bulk dynamic viscosity by copying another one.
57  template <typename OtherNumericType>
58  explicit constexpr BulkDynamicViscosity(const BulkDynamicViscosity<OtherNumericType>& other)
59  : BulkDynamicViscosity(static_cast<NumericType>(other.Value())) {}
60 
61  /// \brief Move constructor. Constructs a bulk dynamic viscosity by moving another one.
62  constexpr BulkDynamicViscosity(BulkDynamicViscosity<NumericType>&& other) noexcept = default;
63 
64  /// \brief Copy assignment operator. Assigns this bulk dynamic viscosity by copying another one.
66  const BulkDynamicViscosity<NumericType>& other) = default;
67 
68  /// \brief Copy assignment operator. Assigns this bulk dynamic viscosity by copying another one.
69  template <typename OtherNumericType>
72  this->value = static_cast<NumericType>(other.Value());
73  return *this;
74  }
75 
76  /// \brief Move assignment operator. Assigns this bulk dynamic viscosity by moving another one.
78  BulkDynamicViscosity<NumericType>&& other) noexcept = default;
79 
80  /// \brief Statically creates a bulk dynamic viscosity of zero.
81  [[nodiscard]] static constexpr BulkDynamicViscosity<NumericType> Zero() {
82  return BulkDynamicViscosity<NumericType>{static_cast<NumericType>(0)};
83  }
84 
85  /// \brief Statically creates a bulk dynamic viscosity with a given value expressed in a given
86  /// dynamic viscosity unit.
87  template <Unit::DynamicViscosity Unit>
88  [[nodiscard]] static constexpr BulkDynamicViscosity<NumericType> Create(const NumericType value) {
90  ConvertStatically<Unit::DynamicViscosity, Unit, Standard<Unit::DynamicViscosity>>(value)};
91  }
92 
94  const BulkDynamicViscosity<NumericType>& bulk_dynamic_viscosity) const {
95  return BulkDynamicViscosity<NumericType>{this->value + bulk_dynamic_viscosity.value};
96  }
97 
99  const BulkDynamicViscosity<NumericType>& bulk_dynamic_viscosity) const {
100  return BulkDynamicViscosity<NumericType>{this->value - bulk_dynamic_viscosity.value};
101  }
102 
103  constexpr BulkDynamicViscosity<NumericType> operator*(const NumericType number) const {
104  return BulkDynamicViscosity<NumericType>{this->value * number};
105  }
106 
107  constexpr BulkDynamicViscosity<NumericType> operator/(const NumericType number) const {
108  return BulkDynamicViscosity<NumericType>{this->value / number};
109  }
110 
111  constexpr NumericType operator/(
112  const BulkDynamicViscosity<NumericType>& bulk_dynamic_viscosity) const noexcept {
113  return this->value / bulk_dynamic_viscosity.value;
114  }
115 
116  constexpr void operator+=(
117  const BulkDynamicViscosity<NumericType>& bulk_dynamic_viscosity) noexcept {
118  this->value += bulk_dynamic_viscosity.value;
119  }
120 
121  constexpr void operator-=(
122  const BulkDynamicViscosity<NumericType>& bulk_dynamic_viscosity) noexcept {
123  this->value -= bulk_dynamic_viscosity.value;
124  }
125 
126  constexpr void operator*=(const NumericType number) noexcept {
127  this->value *= number;
128  }
129 
130  constexpr void operator/=(const NumericType number) noexcept {
131  this->value /= number;
132  }
133 
134 private:
135  /// \brief Constructor. Constructs a bulk dynamic viscosity with a given value expressed in the
136  /// standard dynamic viscosity unit.
137  explicit constexpr BulkDynamicViscosity(const NumericType value)
138  : DimensionalScalar<Unit::DynamicViscosity, NumericType>(value) {}
139 
140  friend class ConstitutiveModel;
141 };
142 
143 template <typename NumericType>
144 inline constexpr bool operator==(const BulkDynamicViscosity<NumericType>& left,
145  const BulkDynamicViscosity<NumericType>& right) noexcept {
146  return left.Value() == right.Value();
147 }
148 
149 template <typename NumericType>
150 inline constexpr bool operator!=(const BulkDynamicViscosity<NumericType>& left,
151  const BulkDynamicViscosity<NumericType>& right) noexcept {
152  return left.Value() != right.Value();
153 }
154 
155 template <typename NumericType>
156 inline constexpr bool operator<(const BulkDynamicViscosity<NumericType>& left,
157  const BulkDynamicViscosity<NumericType>& right) noexcept {
158  return left.Value() < right.Value();
159 }
160 
161 template <typename NumericType>
162 inline constexpr bool operator>(const BulkDynamicViscosity<NumericType>& left,
163  const BulkDynamicViscosity<NumericType>& right) noexcept {
164  return left.Value() > right.Value();
165 }
166 
167 template <typename NumericType>
168 inline constexpr bool operator<=(const BulkDynamicViscosity<NumericType>& left,
169  const BulkDynamicViscosity<NumericType>& right) noexcept {
170  return left.Value() <= right.Value();
171 }
172 
173 template <typename NumericType>
174 inline constexpr bool operator>=(const BulkDynamicViscosity<NumericType>& left,
175  const BulkDynamicViscosity<NumericType>& right) noexcept {
176  return left.Value() >= right.Value();
177 }
178 
179 template <typename NumericType>
180 inline std::ostream& operator<<(
181  std::ostream& stream, const BulkDynamicViscosity<NumericType>& mass_density) {
182  stream << mass_density.Print();
183  return stream;
184 }
185 
186 template <typename NumericType>
188  const NumericType number, const BulkDynamicViscosity<NumericType>& mass_density) {
189  return mass_density * number;
190 }
191 
192 } // namespace PhQ
193 
194 namespace std {
195 
196 template <typename NumericType>
197 struct hash<PhQ::BulkDynamicViscosity<NumericType>> {
198  inline size_t operator()(
199  const PhQ::BulkDynamicViscosity<NumericType>& bulk_dynamic_viscosity) const {
200  return hash<NumericType>()(bulk_dynamic_viscosity.Value());
201  }
202 };
203 
204 } // namespace std
205 
206 #endif // PHQ_BULK_DYNAMIC_VISCOSITY_HPP
Bulk dynamic viscosity, also known as volume dynamic viscosity or dilatational dynamic viscosity....
~BulkDynamicViscosity() noexcept=default
Destructor. Destroys this bulk dynamic viscosity.
constexpr void operator/=(const NumericType number) noexcept
constexpr BulkDynamicViscosity< NumericType > & operator=(const BulkDynamicViscosity< OtherNumericType > &other)
Copy assignment operator. Assigns this bulk dynamic viscosity by copying another one.
static constexpr BulkDynamicViscosity< NumericType > Zero()
Statically creates a bulk dynamic viscosity of zero.
constexpr void operator*=(const NumericType number) noexcept
constexpr void operator+=(const BulkDynamicViscosity< NumericType > &bulk_dynamic_viscosity) noexcept
constexpr BulkDynamicViscosity< NumericType > & operator=(const BulkDynamicViscosity< NumericType > &other)=default
Copy assignment operator. Assigns this bulk dynamic viscosity by copying another one.
constexpr BulkDynamicViscosity< NumericType > operator/(const NumericType number) const
constexpr void operator-=(const BulkDynamicViscosity< NumericType > &bulk_dynamic_viscosity) noexcept
constexpr BulkDynamicViscosity< NumericType > operator-(const BulkDynamicViscosity< NumericType > &bulk_dynamic_viscosity) const
constexpr NumericType operator/(const BulkDynamicViscosity< NumericType > &bulk_dynamic_viscosity) const noexcept
constexpr BulkDynamicViscosity(const NumericType value)
Constructor. Constructs a bulk dynamic viscosity with a given value expressed in the standard dynamic...
static constexpr BulkDynamicViscosity< NumericType > Create(const NumericType value)
Statically creates a bulk dynamic viscosity with a given value expressed in a given dynamic viscosity...
constexpr BulkDynamicViscosity< NumericType > operator+(const BulkDynamicViscosity< NumericType > &bulk_dynamic_viscosity) const
constexpr BulkDynamicViscosity< NumericType > operator*(const NumericType number) const
BulkDynamicViscosity()=default
Default constructor. Constructs a bulk dynamic viscosity with an uninitialized value.
BulkDynamicViscosity(const NumericType value, const Unit::DynamicViscosity unit)
Constructor. Constructs a bulk dynamic viscosity with a given value expressed in a given dynamic visc...
constexpr BulkDynamicViscosity< NumericType > & operator=(BulkDynamicViscosity< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this bulk dynamic viscosity by moving another one.
constexpr BulkDynamicViscosity(BulkDynamicViscosity< NumericType > &&other) noexcept=default
Move constructor. Constructs a bulk dynamic viscosity by moving another one.
Abstract base class for a material's constitutive model, which is a model that defines the relationsh...
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::DynamicViscosity 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...
DynamicViscosity
Dynamic viscosity units.
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)