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
ScalarForce.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_FORCE_HPP
26#define PHQ_SCALAR_FORCE_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "Area.hpp"
33#include "DimensionalScalar.hpp"
34#include "Unit/Force.hpp"
35
36namespace PhQ {
37
38// Forward declaration for class PhQ::ScalarForce.
39template <typename NumericType>
40class Direction;
41
42// Forward declaration for class PhQ::ScalarForce.
43template <typename NumericType>
44class Force;
45
46// Forward declaration for class PhQ::ScalarForce.
47template <typename NumericType>
48class PlanarDirection;
49
50// Forward declaration for class PhQ::ScalarForce.
51template <typename NumericType>
52class PlanarForce;
53
54// Forward declaration for class PhQ::ScalarForce.
55template <typename NumericType>
56class ScalarTraction;
57
58// Forward declaration for class PhQ::ScalarForce.
59template <typename NumericType>
60class StaticPressure;
61
62/// \brief Scalar force component or magnitude of a force vector. For a three-dimensional Euclidean
63/// force vector, see PhQ::Force. For a two-dimensional Euclidean force vector in the XY plane, see
64/// PhQ::PlanarForce.
65template <typename NumericType = double>
66class ScalarForce : public DimensionalScalar<Unit::Force, NumericType> {
67public:
68 /// \brief Default constructor. Constructs a scalar force with an uninitialized value.
69 ScalarForce() = default;
70
71 /// \brief Constructor. Constructs a scalar force with a given value expressed in a given force
72 /// unit.
73 ScalarForce(const NumericType value, const Unit::Force unit)
74 : DimensionalScalar<Unit::Force, NumericType>(value, unit) {}
75
76 /// \brief Constructor. Constructs a scalar force from a given scalar traction and area using the
77 /// definition of traction.
78 constexpr ScalarForce(
79 const ScalarTraction<NumericType>& scalar_traction, const Area<NumericType>& area);
80
81 /// \brief Constructor. Constructs a scalar force from a given static pressure and area using the
82 /// definition of pressure.
83 constexpr ScalarForce(
84 const StaticPressure<NumericType>& static_pressure, const Area<NumericType>& area);
85
86 /// \brief Destructor. Destroys this scalar force.
87 ~ScalarForce() noexcept = default;
88
89 /// \brief Copy constructor. Constructs a scalar force by copying another one.
90 constexpr ScalarForce(const ScalarForce<NumericType>& other) = default;
91
92 /// \brief Copy constructor. Constructs a scalar force by copying another one.
93 template <typename OtherNumericType>
94 explicit constexpr ScalarForce(const ScalarForce<OtherNumericType>& other)
95 : ScalarForce(static_cast<NumericType>(other.Value())) {}
96
97 /// \brief Move constructor. Constructs a scalar force by moving another one.
98 constexpr ScalarForce(ScalarForce<NumericType>&& other) noexcept = default;
99
100 /// \brief Copy assignment operator. Assigns this scalar force by copying another one.
102
103 /// \brief Copy assignment operator. Assigns this scalar force by copying another one.
104 template <typename OtherNumericType>
106 this->value = static_cast<NumericType>(other.Value());
107 return *this;
108 }
109
110 /// \brief Move assignment operator. Assigns this scalar force by moving another one.
112 ScalarForce<NumericType>&& other) noexcept = default;
113
114 /// \brief Statically creates a scalar force of zero.
115 [[nodiscard]] static constexpr ScalarForce<NumericType> Zero() {
116 return ScalarForce<NumericType>{static_cast<NumericType>(0)};
117 }
118
119 /// \brief Statically creates a scalar force with a given value expressed in a given force unit.
120 template <Unit::Force Unit>
121 [[nodiscard]] static constexpr ScalarForce<NumericType> Create(const NumericType value) {
123 ConvertStatically<Unit::Force, Unit, Standard<Unit::Force>>(value)};
124 }
125
126 constexpr ScalarForce<NumericType> operator+(const ScalarForce<NumericType>& scalar_force) const {
127 return ScalarForce<NumericType>{this->value + scalar_force.value};
128 }
129
130 constexpr ScalarForce<NumericType> operator-(const ScalarForce<NumericType>& scalar_force) const {
131 return ScalarForce<NumericType>{this->value - scalar_force.value};
132 }
133
134 constexpr ScalarForce<NumericType> operator*(const NumericType number) const {
135 return ScalarForce<NumericType>{this->value * number};
136 }
137
139 const PlanarDirection<NumericType>& planar_direction) const;
140
141 constexpr Force<NumericType> operator*(const Direction<NumericType>& direction) const;
142
143 constexpr ScalarForce<NumericType> operator/(const NumericType number) const {
144 return ScalarForce<NumericType>{this->value / number};
145 }
146
147 constexpr StaticPressure<NumericType> operator/(const Area<NumericType>& area) const;
148
149 constexpr NumericType operator/(const ScalarForce<NumericType>& scalar_force) const noexcept {
150 return this->value / scalar_force.value;
151 }
152
153 constexpr void operator+=(const ScalarForce<NumericType>& scalar_force) noexcept {
154 this->value += scalar_force.value;
155 }
156
157 constexpr void operator-=(const ScalarForce<NumericType>& scalar_force) noexcept {
158 this->value -= scalar_force.value;
159 }
160
161 constexpr void operator*=(const NumericType number) noexcept {
162 this->value *= number;
163 }
164
165 constexpr void operator/=(const NumericType number) noexcept {
166 this->value /= number;
167 }
168
169private:
170 /// \brief Constructor. Constructs a scalar force with a given value expressed in the standard
171 /// force unit.
172 explicit constexpr ScalarForce(const NumericType value)
173 : DimensionalScalar<Unit::Force, NumericType>(value) {}
174
175 template <typename OtherNumericType>
176 friend class PlanarForce;
177
178 template <typename OtherNumericType>
179 friend class Force;
180};
181
182template <typename NumericType>
183inline constexpr bool operator==(
184 const ScalarForce<NumericType>& left, const ScalarForce<NumericType>& right) noexcept {
185 return left.Value() == right.Value();
186}
187
188template <typename NumericType>
189inline constexpr bool operator!=(
190 const ScalarForce<NumericType>& left, const ScalarForce<NumericType>& right) noexcept {
191 return left.Value() != right.Value();
192}
193
194template <typename NumericType>
195inline constexpr bool operator<(
196 const ScalarForce<NumericType>& left, const ScalarForce<NumericType>& right) noexcept {
197 return left.Value() < right.Value();
198}
199
200template <typename NumericType>
201inline constexpr bool operator>(
202 const ScalarForce<NumericType>& left, const ScalarForce<NumericType>& right) noexcept {
203 return left.Value() > right.Value();
204}
205
206template <typename NumericType>
207inline constexpr bool operator<=(
208 const ScalarForce<NumericType>& left, const ScalarForce<NumericType>& right) noexcept {
209 return left.Value() <= right.Value();
210}
211
212template <typename NumericType>
213inline constexpr bool operator>=(
214 const ScalarForce<NumericType>& left, const ScalarForce<NumericType>& right) noexcept {
215 return left.Value() >= right.Value();
216}
217
218template <typename NumericType>
219inline std::ostream& operator<<(
220 std::ostream& stream, const ScalarForce<NumericType>& scalar_force) {
221 stream << scalar_force.Print();
222 return stream;
223}
224
225template <typename NumericType>
227 const NumericType number, const ScalarForce<NumericType>& scalar_force) {
228 return scalar_force * number;
229}
230
231} // namespace PhQ
232
233namespace std {
234
235template <typename NumericType>
236struct hash<PhQ::ScalarForce<NumericType>> {
237 inline size_t operator()(const PhQ::ScalarForce<NumericType>& scalar_force) const {
238 return hash<NumericType>()(scalar_force.Value());
239 }
240};
241
242} // namespace std
243
244#endif // PHQ_SCALAR_FORCE_HPP
Surface area or cross-sectional area. Can also represent a scalar component of a vector area or the m...
Definition Area.hpp:71
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...
constexpr const PhQ::Vector< NumericType > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Three-dimensional Euclidean direction vector. Contains three components in Cartesian coordinates: x,...
Three-dimensional Euclidean force vector. Contains three components in Cartesian coordinates: x,...
Definition Force.hpp:52
two-dimensional Euclidean direction vector in the XY plane. Contains two components in Cartesian coor...
Two-dimensional Euclidean force vector in the XY plane. Contains two components in Cartesian coordina...
Scalar force component or magnitude of a force vector. For a three-dimensional Euclidean force vector...
constexpr ScalarForce< NumericType > & operator=(const ScalarForce< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar force by copying another one.
constexpr void operator-=(const ScalarForce< NumericType > &scalar_force) noexcept
constexpr ScalarForce< NumericType > operator-(const ScalarForce< NumericType > &scalar_force) const
constexpr ScalarForce(ScalarForce< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar force by moving another one.
static constexpr ScalarForce< NumericType > Zero()
Statically creates a scalar force of zero.
constexpr NumericType operator/(const ScalarForce< NumericType > &scalar_force) const noexcept
constexpr void operator+=(const ScalarForce< NumericType > &scalar_force) noexcept
constexpr ScalarForce< NumericType > operator+(const ScalarForce< NumericType > &scalar_force) const
constexpr void operator*=(const NumericType number) noexcept
ScalarForce(const NumericType value, const Unit::Force unit)
Constructor. Constructs a scalar force with a given value expressed in a given force unit.
static constexpr ScalarForce< NumericType > Create(const NumericType value)
Statically creates a scalar force with a given value expressed in a given force unit.
constexpr ScalarForce< NumericType > operator/(const NumericType number) const
~ScalarForce() noexcept=default
Destructor. Destroys this scalar force.
constexpr ScalarForce(const NumericType value)
Constructor. Constructs a scalar force with a given value expressed in the standard force unit.
constexpr ScalarForce< NumericType > operator*(const NumericType number) const
ScalarForce()=default
Default constructor. Constructs a scalar force with an uninitialized value.
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarForce< NumericType > & operator=(ScalarForce< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar force by moving another one.
constexpr ScalarForce< NumericType > & operator=(const ScalarForce< NumericType > &other)=default
Copy assignment operator. Assigns this scalar force by copying another one.
Scalar traction component or magnitude of a traction vector. Traction is similar to pressure; however...
Static pressure. Pressure of a fluid at rest. Not to be confused with dynamic pressure,...
Force
Force units.
Definition Force.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