Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
PoissonRatio.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_POISSON_RATIO_HPP
26 #define PHQ_POISSON_RATIO_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionlessScalar.hpp"
33 
34 namespace PhQ {
35 
36 /// \brief Poisson's ratio of a deformable solid material. Measures the deformation of a deformable
37 /// solid material subjected to a load in directions perpendicular to the direction of loading.
38 /// Poisson's ratios range from -1 to 0.5, though most deformable solid materials have a
39 /// Poisson's ratio between 0 and 0.5.
40 template <typename NumericType = double>
41 class PoissonRatio : public DimensionlessScalar<NumericType> {
42 public:
43  /// \brief Default constructor. Constructs a Poisson's ratio with an uninitialized value.
44  PoissonRatio() = default;
45 
46  /// \brief Constructor. Constructs a Poisson's ratio with a given value.
47  explicit constexpr PoissonRatio(const NumericType value)
48  : DimensionlessScalar<NumericType>(value) {}
49 
50  /// \brief Destructor. Destroys this Poisson's ratio.
51  ~PoissonRatio() noexcept = default;
52 
53  /// \brief Copy constructor. Constructs a Poisson's ratio by copying another one.
54  constexpr PoissonRatio(const PoissonRatio<NumericType>& other) = default;
55 
56  /// \brief Copy constructor. Constructs a Poisson's ratio by copying another one.
57  template <typename OtherNumericType>
58  explicit constexpr PoissonRatio(const PoissonRatio<OtherNumericType>& other)
59  : PoissonRatio(static_cast<NumericType>(other.Value())) {}
60 
61  /// \brief Move constructor. Constructs a Poisson's ratio by moving another one.
62  constexpr PoissonRatio(PoissonRatio<NumericType>&& other) noexcept = default;
63 
64  /// \brief Copy assignment operator. Assigns this Poisson's ratio by copying another one.
66 
67  /// \brief Copy assignment operator. Assigns this Poisson's ratio by copying another one.
68  template <typename OtherNumericType>
70  this->value = static_cast<NumericType>(other.Value());
71  return *this;
72  }
73 
74  /// \brief Move assignment operator. Assigns this Poisson's ratio by moving another one.
76  PoissonRatio<NumericType>&& other) noexcept = default;
77 
78  /// \brief Statically creates a Poisson's ratio of zero.
79  [[nodiscard]] static constexpr PoissonRatio<NumericType> Zero() {
80  return PoissonRatio<NumericType>{static_cast<NumericType>(0)};
81  }
82 
84  const PoissonRatio<NumericType>& poisson_ratio) const {
85  return PoissonRatio<NumericType>{this->value + poisson_ratio.value};
86  }
87 
89  const PoissonRatio<NumericType>& poisson_ratio) const {
90  return PoissonRatio<NumericType>{this->value - poisson_ratio.value};
91  }
92 
93  constexpr PoissonRatio<NumericType> operator*(const NumericType number) const {
94  return PoissonRatio<NumericType>{this->value * number};
95  }
96 
97  constexpr PoissonRatio<NumericType> operator/(const NumericType number) const {
98  return PoissonRatio<NumericType>{this->value / number};
99  }
100 
101  constexpr NumericType operator/(const PoissonRatio<NumericType>& poisson_ratio) const noexcept {
102  return this->value / poisson_ratio.value;
103  }
104 
105  constexpr void operator+=(const PoissonRatio<NumericType>& poisson_ratio) noexcept {
106  this->value += poisson_ratio.value;
107  }
108 
109  constexpr void operator-=(const PoissonRatio<NumericType>& poisson_ratio) noexcept {
110  this->value -= poisson_ratio.value;
111  }
112 
113  constexpr void operator*=(const NumericType number) noexcept {
114  this->value *= number;
115  }
116 
117  constexpr void operator/=(const NumericType number) noexcept {
118  this->value /= number;
119  }
120 };
121 
122 template <typename NumericType>
123 inline constexpr bool operator==(
124  const PoissonRatio<NumericType>& left, const PoissonRatio<NumericType>& right) noexcept {
125  return left.Value() == right.Value();
126 }
127 
128 template <typename NumericType>
129 inline constexpr bool operator!=(
130  const PoissonRatio<NumericType>& left, const PoissonRatio<NumericType>& right) noexcept {
131  return left.Value() != right.Value();
132 }
133 
134 template <typename NumericType>
135 inline constexpr bool operator<(
136  const PoissonRatio<NumericType>& left, const PoissonRatio<NumericType>& right) noexcept {
137  return left.Value() < right.Value();
138 }
139 
140 template <typename NumericType>
141 inline constexpr bool operator>(
142  const PoissonRatio<NumericType>& left, const PoissonRatio<NumericType>& right) noexcept {
143  return left.Value() > right.Value();
144 }
145 
146 template <typename NumericType>
147 inline constexpr bool operator<=(
148  const PoissonRatio<NumericType>& left, const PoissonRatio<NumericType>& right) noexcept {
149  return left.Value() <= right.Value();
150 }
151 
152 template <typename NumericType>
153 inline constexpr bool operator>=(
154  const PoissonRatio<NumericType>& left, const PoissonRatio<NumericType>& right) noexcept {
155  return left.Value() >= right.Value();
156 }
157 
158 template <typename NumericType>
159 inline std::ostream& operator<<(
160  std::ostream& stream, const PoissonRatio<NumericType>& poisson_ratio) {
161  stream << poisson_ratio.Print();
162  return stream;
163 }
164 
165 template <typename NumericType>
167  const NumericType number, const PoissonRatio<NumericType>& poisson_ratio) {
168  return PoissonRatio<NumericType>{number * poisson_ratio.Value()};
169 }
170 
171 } // namespace PhQ
172 
173 namespace std {
174 
175 template <typename NumericType>
176 struct hash<PhQ::PoissonRatio<NumericType>> {
177  inline size_t operator()(const PhQ::PoissonRatio<NumericType>& poisson_ratio) const {
178  return hash<NumericType>()(poisson_ratio.Value());
179  }
180 };
181 
182 } // namespace std
183 
184 #endif // PHQ_POISSON_RATIO_HPP
Abstract base class that represents any dimensionless scalar physical quantity. Such a physical quant...
constexpr double Value() const noexcept
Value of this physical quantity.
double value
Value of this physical quantity.
std::string Print() const
Prints this physical quantity as a string.
Poisson's ratio of a deformable solid material. Measures the deformation of a deformable solid materi...
constexpr PoissonRatio< NumericType > & operator=(PoissonRatio< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this Poisson's ratio by moving another one.
constexpr void operator/=(const NumericType number) noexcept
constexpr PoissonRatio(const NumericType value)
Constructor. Constructs a Poisson's ratio with a given value.
constexpr void operator-=(const PoissonRatio< NumericType > &poisson_ratio) noexcept
constexpr PoissonRatio< NumericType > operator/(const NumericType number) const
static constexpr PoissonRatio< NumericType > Zero()
Statically creates a Poisson's ratio of zero.
constexpr PoissonRatio< NumericType > & operator=(const PoissonRatio< OtherNumericType > &other)
Copy assignment operator. Assigns this Poisson's ratio by copying another one.
constexpr PoissonRatio< NumericType > operator*(const NumericType number) const
PoissonRatio()=default
Default constructor. Constructs a Poisson's ratio with an uninitialized value.
constexpr PoissonRatio(PoissonRatio< NumericType > &&other) noexcept=default
Move constructor. Constructs a Poisson's ratio by moving another one.
constexpr PoissonRatio< NumericType > & operator=(const PoissonRatio< NumericType > &other)=default
Copy assignment operator. Assigns this Poisson's ratio by copying another one.
constexpr NumericType operator/(const PoissonRatio< NumericType > &poisson_ratio) const noexcept
~PoissonRatio() noexcept=default
Destructor. Destroys this Poisson's ratio.
constexpr PoissonRatio< NumericType > operator-(const PoissonRatio< NumericType > &poisson_ratio) const
constexpr void operator+=(const PoissonRatio< NumericType > &poisson_ratio) noexcept
constexpr PoissonRatio< NumericType > operator+(const PoissonRatio< NumericType > &poisson_ratio) const
constexpr void operator*=(const NumericType number) noexcept
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)