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
SpecificPower.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_SPECIFIC_POWER_HPP
26#define PHQ_SPECIFIC_POWER_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
33#include "Frequency.hpp"
34#include "Mass.hpp"
35#include "Power.hpp"
36#include "SpecificEnergy.hpp"
37#include "Time.hpp"
39
40namespace PhQ {
41
42/// \brief Mass-specific power. Power per unit mass; see PhQ::Power and PhQ::Mass.
43template <typename NumericType = double>
44class SpecificPower : public DimensionalScalar<Unit::SpecificPower, NumericType> {
45public:
46 /// \brief Default constructor. Constructs a specific power quantity with an uninitialized value.
47 SpecificPower() = default;
48
49 /// \brief Constructor. Constructs a specific power quantity with a given value expressed in a
50 /// given specific power unit.
51 SpecificPower(const NumericType value, const Unit::SpecificPower unit)
52 : DimensionalScalar<Unit::SpecificPower, NumericType>(value, unit) {}
53
54 /// \brief Constructor. Constructs a specific power quantity from a given specific energy and time
55 /// duration using the definition of specific power.
56 constexpr SpecificPower(
57 const SpecificEnergy<NumericType>& specific_energy, const Time<NumericType>& time)
58 : SpecificPower<NumericType>(specific_energy.Value() / time.Value()) {}
59
60 /// \brief Constructor. Constructs a specific power quantity from a given specific energy and
61 /// frequency using the definition of specific power.
62 constexpr SpecificPower(
63 const SpecificEnergy<NumericType>& specific_energy, const Frequency<NumericType>& frequency)
64 : SpecificPower<NumericType>(specific_energy.Value() * frequency.Value()) {}
65
66 /// \brief Constructor. Constructs a specific power quantity from a given power and mass using the
67 /// definition of specific power.
68 constexpr SpecificPower(const Power<NumericType>& power, const Mass<NumericType>& mass)
69 : SpecificPower<NumericType>(power.Value() / mass.Value()) {}
70
71 /// \brief Destructor. Destroys this specific power quantity.
72 ~SpecificPower() noexcept = default;
73
74 /// \brief Copy constructor. Constructs a specific power quantity by copying another one.
75 constexpr SpecificPower(const SpecificPower<NumericType>& other) = default;
76
77 /// \brief Copy constructor. Constructs a specific power quantity by copying another one.
78 template <typename OtherNumericType>
79 explicit constexpr SpecificPower(const SpecificPower<OtherNumericType>& other)
80 : SpecificPower(static_cast<NumericType>(other.Value())) {}
81
82 /// \brief Move constructor. Constructs a specific power quantity by moving another one.
83 constexpr SpecificPower(SpecificPower<NumericType>&& other) noexcept = default;
84
85 /// \brief Copy assignment operator. Assigns this specific power quantity by copying another one.
87 const SpecificPower<NumericType>& other) = default;
88
89 /// \brief Copy assignment operator. Assigns this specific power quantity by copying another one.
90 template <typename OtherNumericType>
92 this->value = static_cast<NumericType>(other.Value());
93 return *this;
94 }
95
96 /// \brief Move assignment operator. Assigns this specific power quantity by moving another one.
98 SpecificPower<NumericType>&& other) noexcept = default;
99
100 /// \brief Statically creates a specific power quantity of zero.
101 [[nodiscard]] static constexpr SpecificPower<NumericType> Zero() {
102 return SpecificPower<NumericType>{static_cast<NumericType>(0)};
103 }
104
105 /// \brief Statically creates a specific power quantity with a given value expressed in a given
106 /// specific power unit.
107 template <Unit::SpecificPower Unit>
108 [[nodiscard]] static constexpr SpecificPower<NumericType> Create(const NumericType value) {
110 ConvertStatically<Unit::SpecificPower, Unit, Standard<Unit::SpecificPower>>(value)};
111 }
112
114 const SpecificPower<NumericType>& specific_power) const {
115 return SpecificPower<NumericType>{this->value + specific_power.value};
116 }
117
119 const SpecificPower<NumericType>& specific_power) const {
120 return SpecificPower<NumericType>{this->value - specific_power.value};
121 }
122
123 constexpr SpecificPower<NumericType> operator*(const NumericType number) const {
124 return SpecificPower<NumericType>{this->value * number};
125 }
126
128 return SpecificEnergy<NumericType>{*this, time};
129 }
130
131 constexpr Power<NumericType> operator*(const Mass<NumericType>& mass) const {
132 return Power<NumericType>{*this, mass};
133 }
134
135 constexpr SpecificPower<NumericType> operator/(const NumericType number) const {
136 return SpecificPower<NumericType>{this->value / number};
137 }
138
140 return SpecificEnergy<NumericType>{*this, frequency};
141 }
142
144 const SpecificEnergy<NumericType>& specific_energy) const {
145 return Frequency<NumericType>{*this, specific_energy};
146 }
147
148 constexpr NumericType operator/(const SpecificPower<NumericType>& specific_power) const noexcept {
149 return this->value / specific_power.value;
150 }
151
152 constexpr void operator+=(const SpecificPower<NumericType>& specific_power) noexcept {
153 this->value += specific_power.value;
154 }
155
156 constexpr void operator-=(const SpecificPower<NumericType>& specific_power) noexcept {
157 this->value -= specific_power.value;
158 }
159
160 constexpr void operator*=(const NumericType number) noexcept {
161 this->value *= number;
162 }
163
164 constexpr void operator/=(const NumericType number) noexcept {
165 this->value /= number;
166 }
167
168private:
169 /// \brief Constructor. Constructs a specific power quantity with a given value expressed in the
170 /// standard specific power unit.
171 explicit constexpr SpecificPower(const NumericType value)
172 : DimensionalScalar<Unit::SpecificPower, NumericType>(value) {}
173};
174
175template <typename NumericType>
176inline constexpr bool operator==(
177 const SpecificPower<NumericType>& left, const SpecificPower<NumericType>& right) noexcept {
178 return left.Value() == right.Value();
179}
180
181template <typename NumericType>
182inline constexpr bool operator!=(
183 const SpecificPower<NumericType>& left, const SpecificPower<NumericType>& right) noexcept {
184 return left.Value() != right.Value();
185}
186
187template <typename NumericType>
188inline constexpr bool operator<(
189 const SpecificPower<NumericType>& left, const SpecificPower<NumericType>& right) noexcept {
190 return left.Value() < right.Value();
191}
192
193template <typename NumericType>
194inline constexpr bool operator>(
195 const SpecificPower<NumericType>& left, const SpecificPower<NumericType>& right) noexcept {
196 return left.Value() > right.Value();
197}
198
199template <typename NumericType>
200inline constexpr bool operator<=(
201 const SpecificPower<NumericType>& left, const SpecificPower<NumericType>& right) noexcept {
202 return left.Value() <= right.Value();
203}
204
205template <typename NumericType>
206inline constexpr bool operator>=(
207 const SpecificPower<NumericType>& left, const SpecificPower<NumericType>& right) noexcept {
208 return left.Value() >= right.Value();
209}
210
211template <typename NumericType>
212inline std::ostream& operator<<(
213 std::ostream& stream, const SpecificPower<NumericType>& specific_power) {
214 stream << specific_power.Print();
215 return stream;
216}
217
218template <typename NumericType>
220 const NumericType number, const SpecificPower<NumericType>& specific_power) {
221 return specific_power * number;
222}
223
224template <typename NumericType>
225inline constexpr Time<NumericType>::Time(const SpecificEnergy<NumericType>& specific_energy,
226 const SpecificPower<NumericType>& specific_power)
227 : Time<NumericType>(specific_energy.Value() / specific_power.Value()) {}
228
229template <typename NumericType>
231 const SpecificPower<NumericType>& specific_power,
232 const SpecificEnergy<NumericType>& specific_energy)
233 : Frequency<NumericType>(specific_power.Value() / specific_energy.Value()) {}
234
235template <typename NumericType>
236inline constexpr Mass<NumericType>::Mass(
237 const Power<NumericType>& power, const SpecificPower<NumericType>& specific_power)
238 : Mass<NumericType>(power.Value() / specific_power.Value()) {}
239
240template <typename NumericType>
242 const SpecificPower<NumericType>& specific_power, const Mass<NumericType>& mass)
243 : Power<NumericType>(specific_power.Value() * mass.Value()) {}
244
245template <typename NumericType>
247 const SpecificPower<NumericType>& specific_power, const Time<NumericType>& time)
248 : SpecificEnergy<NumericType>(specific_power.Value() * time.Value()) {}
249
250template <typename NumericType>
252 const SpecificPower<NumericType>& specific_power, const Frequency<NumericType>& frequency)
253 : SpecificEnergy<NumericType>(specific_power.Value() / frequency.Value()) {}
254
255template <typename NumericType>
257 const SpecificPower<NumericType>& specific_power) const {
258 return Power<NumericType>{specific_power, *this};
259}
260
261template <typename NumericType>
263 const SpecificPower<NumericType>& specific_power) const {
264 return SpecificEnergy<NumericType>{specific_power, *this};
265}
266
267template <typename NumericType>
269 const SpecificEnergy<NumericType>& specific_energy) const {
270 return SpecificPower<NumericType>{specific_energy, *this};
271}
272
273template <typename NumericType>
275 const Frequency<NumericType>& frequency) const {
276 return SpecificPower<NumericType>{*this, frequency};
277}
278
279template <typename NumericType>
281 const SpecificPower<NumericType>& specific_power) const {
282 return Mass<NumericType>{*this, specific_power};
283}
284
285template <typename NumericType>
287 const Mass<NumericType>& mass) const {
288 return SpecificPower<NumericType>{*this, mass};
289}
290
291template <typename NumericType>
293 const Time<NumericType>& time) const {
294 return SpecificPower<NumericType>{*this, time};
295}
296
297template <typename NumericType>
299 const SpecificPower<NumericType>& specific_power) const {
300 return Time<NumericType>{*this, specific_power};
301}
302
303} // namespace PhQ
304
305namespace std {
306
307template <typename NumericType>
308struct hash<PhQ::SpecificPower<NumericType>> {
309 inline size_t operator()(const PhQ::SpecificPower<NumericType>& specific_power) const {
310 return hash<NumericType>()(specific_power.Value());
311 }
312};
313
314} // namespace std
315
316#endif // PHQ_SPECIFIC_POWER_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. For the time rate of change of mass, see PhQ::MassRate; see also PhQ::Time and PhQ::Frequency.
Definition Mass.hpp:100
Mass()=default
Default constructor. Constructs a mass with an uninitialized value.
constexpr Mass< NumericType > operator*(const NumericType number) const
Definition Mass.hpp:192
Power. Time rate of change of energy or energy transfer rate; see PhQ::Energy, PhQ::Time,...
Definition Power.hpp:51
constexpr Power< NumericType > operator/(const NumericType number) const
Definition Power.hpp:134
Power()=default
Default constructor. Constructs a power quantity with an uninitialized value.
Mass-specific energy. Energy per unit mass; see PhQ::Energy and PhQ::Mass.
constexpr SpecificEnergy< NumericType > operator*(const NumericType number) const
constexpr SpecificEnergy< NumericType > operator/(const NumericType number) const
SpecificEnergy()=default
Default constructor. Constructs a specific energy quantity with an uninitialized value.
Mass-specific power. Power per unit mass; see PhQ::Power and PhQ::Mass.
static constexpr SpecificPower< NumericType > Zero()
Statically creates a specific power quantity of zero.
constexpr SpecificPower< NumericType > operator/(const NumericType number) const
~SpecificPower() noexcept=default
Destructor. Destroys this specific power quantity.
constexpr SpecificPower< NumericType > & operator=(SpecificPower< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this specific power quantity by moving another one.
constexpr SpecificPower< NumericType > & operator=(const SpecificPower< NumericType > &other)=default
Copy assignment operator. Assigns this specific power quantity by copying another one.
constexpr SpecificPower(const Power< NumericType > &power, const Mass< NumericType > &mass)
Constructor. Constructs a specific power quantity from a given power and mass using the definition of...
constexpr void operator/=(const NumericType number) noexcept
constexpr void operator+=(const SpecificPower< NumericType > &specific_power) noexcept
constexpr Power< NumericType > operator*(const Mass< NumericType > &mass) const
constexpr SpecificPower(const SpecificEnergy< NumericType > &specific_energy, const Frequency< NumericType > &frequency)
Constructor. Constructs a specific power quantity from a given specific energy and frequency using th...
constexpr SpecificPower< NumericType > operator+(const SpecificPower< NumericType > &specific_power) const
constexpr SpecificPower< NumericType > & operator=(const SpecificPower< OtherNumericType > &other)
Copy assignment operator. Assigns this specific power quantity by copying another one.
SpecificPower()=default
Default constructor. Constructs a specific power quantity with an uninitialized value.
constexpr SpecificPower(SpecificPower< NumericType > &&other) noexcept=default
Move constructor. Constructs a specific power quantity by moving another one.
constexpr SpecificPower< NumericType > operator*(const NumericType number) const
constexpr SpecificPower(const SpecificEnergy< NumericType > &specific_energy, const Time< NumericType > &time)
Constructor. Constructs a specific power quantity from a given specific energy and time duration usin...
constexpr SpecificEnergy< NumericType > operator/(const Frequency< NumericType > &frequency) const
constexpr SpecificEnergy< NumericType > operator*(const Time< NumericType > &time) const
static constexpr SpecificPower< NumericType > Create(const NumericType value)
Statically creates a specific power quantity with a given value expressed in a given specific power u...
constexpr NumericType operator/(const SpecificPower< NumericType > &specific_power) const noexcept
constexpr SpecificPower< NumericType > operator-(const SpecificPower< NumericType > &specific_power) const
constexpr SpecificPower(const NumericType value)
Constructor. Constructs a specific power quantity with a given value expressed in the standard specif...
constexpr void operator*=(const NumericType number) noexcept
constexpr Frequency< NumericType > operator/(const SpecificEnergy< NumericType > &specific_energy) const
SpecificPower(const NumericType value, const Unit::SpecificPower unit)
Constructor. Constructs a specific power quantity with a given value expressed in a given specific po...
constexpr void operator-=(const SpecificPower< NumericType > &specific_power) noexcept
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.
SpecificPower
Mass-specific power units.
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