Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Loading...
Searching...
No Matches
VolumeRate.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_VOLUME_RATE_HPP
26#define PHQ_VOLUME_RATE_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
33#include "Frequency.hpp"
34#include "Time.hpp"
35#include "Unit/VolumeRate.hpp"
36#include "Volume.hpp"
37
38namespace PhQ {
39
40// Forward declaration for class PhQ::VolumeRate.
41template <typename NumericType>
42class MassDensity;
43
44// Forward declaration for class PhQ::VolumeRate.
45template <typename NumericType>
46class MassRate;
47
48/// \brief Volume rate. Can represent a time rate of change of a volume or a volume flow rate. See
49/// also PhQ::Volume, PhQ::Time, and PhQ::Frequency.
50template <typename NumericType = double>
51class VolumeRate : public DimensionalScalar<Unit::VolumeRate, NumericType> {
52public:
53 /// \brief Default constructor. Constructs a volume rate with an uninitialized value.
54 VolumeRate() = default;
55
56 /// \brief Constructor. Constructs a volume rate with a given value expressed in a given volume
57 /// rate unit.
58 VolumeRate(const NumericType value, const Unit::VolumeRate unit)
59 : DimensionalScalar<Unit::VolumeRate, NumericType>(value, unit) {}
60
61 /// \brief Constructor. Constructs a volume rate from a given volume and time using the definition
62 /// of volume rate.
63 constexpr VolumeRate(const Volume<NumericType>& volume, const Time<NumericType>& time)
64 : VolumeRate<NumericType>(volume.Value() / time.Value()) {}
65
66 /// \brief Constructor. Constructs a volume rate from a given volume and frequency using the
67 /// definition of volume rate.
68 constexpr VolumeRate(const Volume<NumericType>& volume, const Frequency<NumericType>& frequency)
69 : VolumeRate<NumericType>(volume.Value() * frequency.Value()) {}
70
71 /// \brief Constructor. Constructs a volume rate from a given mass rate and mass density using the
72 /// definition of mass density.
73 constexpr VolumeRate(
74 const MassRate<NumericType>& mass_rate, const MassDensity<NumericType>& mass_density);
75
76 /// \brief Destructor. Destroys this volume rate.
77 ~VolumeRate() noexcept = default;
78
79 /// \brief Copy constructor. Constructs a volume rate by copying another one.
80 constexpr VolumeRate(const VolumeRate<NumericType>& other) = default;
81
82 /// \brief Copy constructor. Constructs a volume rate by copying another one.
83 template <typename OtherNumericType>
84 explicit constexpr VolumeRate(const VolumeRate<OtherNumericType>& other)
85 : VolumeRate(static_cast<NumericType>(other.Value())) {}
86
87 /// \brief Move constructor. Constructs a volume rate by moving another one.
88 constexpr VolumeRate(VolumeRate<NumericType>&& other) noexcept = default;
89
90 /// \brief Copy assignment operator. Assigns this volume rate by copying another one.
91 constexpr VolumeRate<NumericType>& operator=(const VolumeRate<NumericType>& other) = default;
92
93 /// \brief Copy assignment operator. Assigns this volume rate by copying another one.
94 template <typename OtherNumericType>
96 this->value = static_cast<NumericType>(other.Value());
97 return *this;
98 }
99
100 /// \brief Move assignment operator. Assigns this volume rate by moving another one.
101 constexpr VolumeRate<NumericType>& operator=(VolumeRate<NumericType>&& other) noexcept = default;
102
103 /// \brief Statically creates a volume rate of zero.
104 [[nodiscard]] static constexpr VolumeRate<NumericType> Zero() {
105 return VolumeRate<NumericType>{static_cast<NumericType>(0)};
106 }
107
108 /// \brief Statically creates a volume rate with a given value expressed in a given volume rate
109 /// unit.
110 template <Unit::VolumeRate Unit>
111 [[nodiscard]] static constexpr VolumeRate<NumericType> Create(const NumericType value) {
113 ConvertStatically<Unit::VolumeRate, Unit, Standard<Unit::VolumeRate>>(value)};
114 }
115
116 constexpr VolumeRate<NumericType> operator+(const VolumeRate<NumericType>& volume_rate) const {
117 return VolumeRate<NumericType>{this->value + volume_rate.value};
118 }
119
120 constexpr VolumeRate<NumericType> operator-(const VolumeRate<NumericType>& volume_rate) const {
121 return VolumeRate<NumericType>{this->value - volume_rate.value};
122 }
123
124 constexpr VolumeRate<NumericType> operator*(const NumericType number) const {
125 return VolumeRate<NumericType>{this->value * number};
126 }
127
128 constexpr Volume<NumericType> operator*(const Time<NumericType>& time) const {
129 return Volume<NumericType>{*this, time};
130 }
131
132 constexpr MassRate<NumericType> operator*(const MassDensity<NumericType>& mass_density) const;
133
134 constexpr VolumeRate<NumericType> operator/(const NumericType number) const {
135 return VolumeRate<NumericType>{this->value / number};
136 }
137
138 constexpr Volume<NumericType> operator/(const Frequency<NumericType>& frequency) const {
139 return Volume<NumericType>{*this, frequency};
140 }
141
142 constexpr Frequency<NumericType> operator/(const Volume<NumericType>& volume) const {
143 return Frequency<NumericType>{*this, volume};
144 }
145
146 constexpr NumericType operator/(const VolumeRate<NumericType>& volume_rate) const noexcept {
147 return this->value / volume_rate.value;
148 }
149
150 constexpr void operator+=(const VolumeRate<NumericType>& volume_rate) noexcept {
151 this->value += volume_rate.value;
152 }
153
154 constexpr void operator-=(const VolumeRate<NumericType>& volume_rate) noexcept {
155 this->value -= volume_rate.value;
156 }
157
158 constexpr void operator*=(const NumericType number) noexcept {
159 this->value *= number;
160 }
161
162 constexpr void operator/=(const NumericType number) noexcept {
163 this->value /= number;
164 }
165
166private:
167 /// \brief Constructor. Constructs a volume rate with a given value expressed in the standard
168 /// volume rate unit.
169 explicit constexpr VolumeRate(const NumericType value)
170 : DimensionalScalar<Unit::VolumeRate, NumericType>(value) {}
171};
172
173template <typename NumericType>
174inline constexpr bool operator==(
175 const VolumeRate<NumericType>& left, const VolumeRate<NumericType>& right) noexcept {
176 return left.Value() == right.Value();
177}
178
179template <typename NumericType>
180inline constexpr bool operator!=(
181 const VolumeRate<NumericType>& left, const VolumeRate<NumericType>& right) noexcept {
182 return left.Value() != right.Value();
183}
184
185template <typename NumericType>
186inline constexpr bool operator<(
187 const VolumeRate<NumericType>& left, const VolumeRate<NumericType>& right) noexcept {
188 return left.Value() < right.Value();
189}
190
191template <typename NumericType>
192inline constexpr bool operator>(
193 const VolumeRate<NumericType>& left, const VolumeRate<NumericType>& right) noexcept {
194 return left.Value() > right.Value();
195}
196
197template <typename NumericType>
198inline constexpr bool operator<=(
199 const VolumeRate<NumericType>& left, const VolumeRate<NumericType>& right) noexcept {
200 return left.Value() <= right.Value();
201}
202
203template <typename NumericType>
204inline constexpr bool operator>=(
205 const VolumeRate<NumericType>& left, const VolumeRate<NumericType>& right) noexcept {
206 return left.Value() >= right.Value();
207}
208
209template <typename NumericType>
210inline std::ostream& operator<<(std::ostream& stream, const VolumeRate<NumericType>& volume_rate) {
211 stream << volume_rate.Print();
212 return stream;
213}
214
215template <typename NumericType>
217 const NumericType number, const VolumeRate<NumericType>& volume_rate) {
218 return volume_rate * number;
219}
220
221template <typename NumericType>
223 const VolumeRate<NumericType>& volume_rate, const Time<NumericType>& time)
224 : Volume<NumericType>(volume_rate.Value() * time.Value()) {}
225
226template <typename NumericType>
228 const VolumeRate<NumericType>& volume_rate, const Frequency<NumericType>& frequency)
229 : Volume<NumericType>(volume_rate.Value() / frequency.Value()) {}
230
231template <typename NumericType>
232inline constexpr Time<NumericType>::Time(
233 const Volume<NumericType>& volume, const VolumeRate<NumericType>& volume_rate)
234 : Time<NumericType>(volume.Value() / volume_rate.Value()) {}
235
236template <typename NumericType>
238 const VolumeRate<NumericType>& volume_rate, const Volume<NumericType>& volume)
239 : Frequency<NumericType>(volume_rate.Value() / volume.Value()) {}
240
241template <typename NumericType>
243 const VolumeRate<NumericType>& volume_rate) const {
244 return Volume<NumericType>{volume_rate, *this};
245}
246
247template <typename NumericType>
249 const Frequency<NumericType>& frequency) const {
250 return VolumeRate<NumericType>{*this, frequency};
251}
252
253template <typename NumericType>
255 const VolumeRate<NumericType>& volume_rate) const {
256 return Time<NumericType>{*this, volume_rate};
257}
258
259template <typename NumericType>
261 const Volume<NumericType>& volume) const {
262 return VolumeRate<NumericType>{volume, *this};
263}
264
265template <typename NumericType>
267 const Time<NumericType>& time) const {
268 return VolumeRate<NumericType>{*this, time};
269}
270
271} // namespace PhQ
272
273namespace std {
274
275template <typename NumericType>
276struct hash<PhQ::VolumeRate<NumericType>> {
277 inline size_t operator()(const PhQ::VolumeRate<NumericType>& volume_rate) const {
278 return hash<NumericType>()(volume_rate.Value());
279 }
280};
281
282} // namespace std
283
284#endif // PHQ_VOLUME_RATE_HPP
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
NumericType value
Value of this physical quantity expressed in its standard unit of measure.
constexpr NumericType Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr UnitType 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...
Frequency. Inverse of a time duration. See also PhQ::Time.
Definition Frequency.hpp:40
constexpr Frequency< NumericType > operator*(const NumericType number) const
Frequency()=default
Default constructor. Constructs a frequency with an uninitialized value.
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
Mass rate. Can represent the time rate of change of a mass or a mass flow rate; see PhQ::Mass,...
Definition MassRate.hpp:51
Time. Can represent either a point in time, a time duration, or a period. For the inverse of time,...
Definition Time.hpp:172
constexpr Time< NumericType > operator*(const NumericType number) const
Definition Time.hpp:278
Time()=default
Default constructor. Constructs a time quantity with an uninitialized value.
Volume rate. Can represent a time rate of change of a volume or a volume flow rate....
constexpr VolumeRate(const Volume< NumericType > &volume, const Frequency< NumericType > &frequency)
Constructor. Constructs a volume rate from a given volume and frequency using the definition of volum...
constexpr void operator/=(const NumericType number) noexcept
constexpr VolumeRate< NumericType > & operator=(const VolumeRate< OtherNumericType > &other)
Copy assignment operator. Assigns this volume rate by copying another one.
VolumeRate(const NumericType value, const Unit::VolumeRate unit)
Constructor. Constructs a volume rate with a given value expressed in a given volume rate unit.
~VolumeRate() noexcept=default
Destructor. Destroys this volume rate.
constexpr Volume< NumericType > operator*(const Time< NumericType > &time) const
constexpr Volume< NumericType > operator/(const Frequency< NumericType > &frequency) const
constexpr VolumeRate(const Volume< NumericType > &volume, const Time< NumericType > &time)
Constructor. Constructs a volume rate from a given volume and time using the definition of volume rat...
constexpr VolumeRate< NumericType > operator/(const NumericType number) const
constexpr Frequency< NumericType > operator/(const Volume< NumericType > &volume) const
static constexpr VolumeRate< NumericType > Zero()
Statically creates a volume rate of zero.
constexpr VolumeRate(const NumericType value)
Constructor. Constructs a volume rate with a given value expressed in the standard volume rate unit.
constexpr VolumeRate< NumericType > operator*(const NumericType number) const
constexpr void operator-=(const VolumeRate< NumericType > &volume_rate) noexcept
VolumeRate()=default
Default constructor. Constructs a volume rate with an uninitialized value.
static constexpr VolumeRate< NumericType > Create(const NumericType value)
Statically creates a volume rate with a given value expressed in a given volume rate unit.
constexpr NumericType operator/(const VolumeRate< NumericType > &volume_rate) const noexcept
constexpr VolumeRate(VolumeRate< NumericType > &&other) noexcept=default
Move constructor. Constructs a volume rate by moving another one.
constexpr VolumeRate< NumericType > & operator=(const VolumeRate< NumericType > &other)=default
Copy assignment operator. Assigns this volume rate by copying another one.
constexpr VolumeRate< NumericType > & operator=(VolumeRate< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this volume rate by moving another one.
constexpr VolumeRate< NumericType > operator-(const VolumeRate< NumericType > &volume_rate) const
constexpr VolumeRate< NumericType > operator+(const VolumeRate< NumericType > &volume_rate) const
constexpr void operator*=(const NumericType number) noexcept
constexpr void operator+=(const VolumeRate< NumericType > &volume_rate) noexcept
Volume. For the time rate of change of volume, see PhQ::VolumeRate; see also PhQ::Time and PhQ::Frequ...
Definition Volume.hpp:62
Volume()=default
Default constructor. Constructs a volume with an uninitialized value.
constexpr Volume< NumericType > operator/(const NumericType number) const
Definition Volume.hpp:143
constexpr Volume< NumericType > operator*(const NumericType number) const
Definition Volume.hpp:135
VolumeRate
Volume rate units. Can represent a time rate of change of a volume or a volume flow rate.
MassDensity
Mass density units.
MassRate
Mass rate units. Can represent the time rate of change of a mass or a mass flow rate.
Definition MassRate.hpp:53
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, 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 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