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
DimensionlessDyad.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_DIMENSIONLESS_DYAD_HPP
26#define PHQ_DIMENSIONLESS_DYAD_HPP
27
28#include <array>
29#include <cstddef>
30#include <functional>
31#include <ostream>
32#include <string>
33#include <type_traits>
34
35#include "Base.hpp"
36#include "Dimensions.hpp"
37#include "Dyad.hpp"
38
39namespace PhQ {
40
41/// \brief Abstract base class that represents any dimensionless dyadic tensor physical quantity.
42/// Such a physical quantity is composed only of a value where the value is a three-dimensional
43/// dyadic tensor. The tensor may be non-symmetric. Such a physical quantity has no unit of measure
44/// and no dimension set.
45/// \tparam NumericType Floating-point numeric type: float, double, or long double. Defaults to
46/// double if unspecified.
47template <typename NumericType = double>
49 static_assert(std::is_floating_point<NumericType>::value,
50 "The NumericType template parameter of a physical quantity must be a numeric "
51 "floating-point type: float, double, or long double.");
52
53public:
54 /// \brief Physical dimension set of this physical quantity. Since this physical quantity is
55 /// dimensionless, its physical dimension set is simply the null set.
56 [[nodiscard]] static constexpr PhQ::Dimensions Dimensions() {
57 return PhQ::Dimensionless;
58 }
59
60 /// \brief Value of this physical quantity.
61 [[nodiscard]] constexpr const PhQ::Dyad<NumericType>& Value() const noexcept {
62 return value;
63 }
64
65 /// \brief Returns the value of this physical quantity as a mutable value.
66 [[nodiscard]] constexpr PhQ::Dyad<NumericType>& MutableValue() noexcept {
67 return value;
68 }
69
70 /// \brief Sets the value of this physical quantity to the given value.
71 constexpr void SetValue(const PhQ::Dyad<NumericType>& value) noexcept {
72 this->value = value;
73 }
74
75 /// \brief Prints this physical quantity as a string.
76 [[nodiscard]] std::string Print() const {
77 return value.Print();
78 }
79
80 /// \brief Serializes this physical quantity as a JSON message.
81 [[nodiscard]] std::string JSON() const {
82 return value.JSON();
83 }
84
85 /// \brief Serializes this physical quantity as an XML message.
86 [[nodiscard]] std::string XML() const {
87 return value.XML();
88 }
89
90 /// \brief Serializes this physical quantity as a YAML message.
91 [[nodiscard]] std::string YAML() const {
92 return value.YAML();
93 }
94
95protected:
96 /// \brief Default constructor. Constructs a dimensionless dyadic tensor physical quantity with an
97 /// uninitialized value.
98 DimensionlessDyad() = default;
99
100 /// \brief Constructor. Constructs a dimensionless dyadic tensor physical quantity whose value has
101 /// the given xx, xy, xz, yx, yy, yz, zx, zy, and zz Cartesian components.
102 constexpr DimensionlessDyad(const NumericType xx, const NumericType xy, const NumericType xz,
103 const NumericType yx, const NumericType yy, const NumericType yz,
104 const NumericType zx, const NumericType zy, const NumericType zz)
105 : value(xx, xy, xz, yx, yy, yz, zx, zy, zz) {}
106
107 /// \brief Constructor. Constructs a dimensionless dyadic tensor physical quantity from a given
108 /// array representing its value's xx, xy, xz, yx, yy, yz, zx, zy, and zz Cartesian components.
109 explicit constexpr DimensionlessDyad(const std::array<NumericType, 9>& xx_xy_xz_yx_yy_yz_zx_zy_zz)
110 : value(xx_xy_xz_yx_yy_yz_zx_zy_zz) {}
111
112 /// \brief Constructor. Constructs a dimensionless dyadic tensor physical quantity with a given
113 /// value.
115
116 /// \brief Destructor. Destroys this dimensionless dyadic tensor physical quantity.
117 ~DimensionlessDyad() noexcept = default;
118
119 /// \brief Copy constructor. Constructs a dimensionless dyadic tensor physical quantity by copying
120 /// another one.
121 constexpr DimensionlessDyad(const DimensionlessDyad<NumericType>& other) = default;
122
123 /// \brief Copy constructor. Constructs a dimensionless dyadic tensor physical quantity by copying
124 /// another one.
125 /// \tparam OtherNumericType Floating-point numeric type of the other physical quantity. Deduced
126 /// automatically.
127 template <typename OtherNumericType>
128 explicit constexpr DimensionlessDyad(const DimensionlessDyad<OtherNumericType>& other)
129 : value(static_cast<PhQ::Dyad<NumericType>>(other.Value())) {}
130
131 /// \brief Move constructor. Constructs a dimensionless dyadic tensor physical quantity by moving
132 /// another one.
133 constexpr DimensionlessDyad(DimensionlessDyad<NumericType>&& other) noexcept = default;
134
135 /// \brief Copy assignment operator. Assigns this dimensionless dyadic tensor physical quantity by
136 /// copying another one.
138 const DimensionlessDyad<NumericType>& other) = default;
139
140 /// \brief Copy assignment operator. Assigns this dimensionless dyadic tensor physical quantity by
141 /// copying another one.
142 /// \tparam OtherNumericType Floating-point numeric type of the other physical quantity. Deduced
143 /// automatically.
144 template <typename OtherNumericType>
147 value = static_cast<PhQ::Dyad<NumericType>>(other.Value());
148 return *this;
149 }
150
151 /// \brief Move assignment operator. Assigns this dimensionless dyadic tensor physical quantity by
152 /// moving another one.
154 DimensionlessDyad<NumericType>&& other) noexcept = default;
155
156 /// \brief Value of this physical quantity.
158};
159
160} // namespace PhQ
161
162#endif // PHQ_DIMENSIONLESS_DYAD_HPP
Abstract base class that represents any dimensionless dyadic tensor physical quantity....
std::string XML() const
Serializes this physical quantity as an XML message.
constexpr DimensionlessDyad(const std::array< NumericType, 9 > &xx_xy_xz_yx_yy_yz_zx_zy_zz)
Constructor. Constructs a dimensionless dyadic tensor physical quantity from a given array representi...
DimensionlessDyad()=default
Default constructor. Constructs a dimensionless dyadic tensor physical quantity with an uninitialized...
constexpr PhQ::Dyad< NumericType > & MutableValue() noexcept
Returns the value of this physical quantity as a mutable value.
constexpr DimensionlessDyad< NumericType > & operator=(DimensionlessDyad< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this dimensionless dyadic tensor physical quantity by moving anothe...
std::string YAML() const
Serializes this physical quantity as a YAML message.
constexpr DimensionlessDyad(const PhQ::Dyad< NumericType > &value)
Constructor. Constructs a dimensionless dyadic tensor physical quantity with a given value.
std::string Print() const
Prints this physical quantity as a string.
constexpr DimensionlessDyad(const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yx, const NumericType yy, const NumericType yz, const NumericType zx, const NumericType zy, const NumericType zz)
Constructor. Constructs a dimensionless dyadic tensor physical quantity whose value has the given xx,...
static constexpr PhQ::Dimensions Dimensions()
Physical dimension set of this physical quantity. Since this physical quantity is dimensionless,...
std::string JSON() const
Serializes this physical quantity as a JSON message.
PhQ::Dyad< NumericType > value
Value of this physical quantity.
constexpr DimensionlessDyad(DimensionlessDyad< NumericType > &&other) noexcept=default
Move constructor. Constructs a dimensionless dyadic tensor physical quantity by moving another one.
constexpr const PhQ::Dyad< NumericType > & Value() const noexcept
Value of this physical quantity.
constexpr void SetValue(const PhQ::Dyad< NumericType > &value) noexcept
Sets the value of this physical quantity to the given value.
constexpr DimensionlessDyad< NumericType > & operator=(const DimensionlessDyad< NumericType > &other)=default
Copy assignment operator. Assigns this dimensionless dyadic tensor physical quantity by copying anoth...
~DimensionlessDyad() noexcept=default
Destructor. Destroys this dimensionless dyadic tensor physical quantity.
constexpr DimensionlessDyad< NumericType > & operator=(const DimensionlessDyad< OtherNumericType > &other)
Copy assignment operator. Assigns this dimensionless dyadic tensor physical quantity by copying anoth...
Physical dimension set of a unit of measure or physical quantity. Composed of the seven independent b...
Three-dimensional Euclidean dyadic tensor. Contains nine components in Cartesian coordinates: xx,...
Definition Dyad.hpp:51
Namespace that encompasses all of the Physical Quantities library's content.
constexpr Dimensions Dimensionless
Dimensionless physical dimension set. This dimension set has all base dimensions of zero....