Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
DimensionlessSymmetricDyad.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_SYMMETRIC_DYAD_HPP
26 #define PHQ_DIMENSIONLESS_SYMMETRIC_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 "SymmetricDyad.hpp"
38 
39 namespace PhQ {
40 
41 /// \brief Abstract base class that represents any dimensionless symmetric dyadic tensor physical
42 /// quantity. Such a physical quantity is composed only of a value where the value is a
43 /// three-dimensional symmetric dyadic tensor. Such a physical quantity has no unit of measure and
44 /// no dimension set.
45 /// \tparam NumericType Floating-point numeric type: float, double, or long double. Defaults to
46 /// double if unspecified.
47 template <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 
53 public:
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::SymmetricDyad<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::SymmetricDyad<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::SymmetricDyad<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 
95 protected:
96  /// \brief Default constructor. Constructs a dimensionless symmetric dyadic tensor physical
97  /// quantity with an uninitialized value.
99 
100  /// \brief Constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity whose
101  /// value has the given xx, xy, xz, yy, yz, and zz Cartesian components.
103  const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yy,
104  const NumericType yz, const NumericType zz)
105  : value(xx, xy, xz, yy, yz, zz) {}
106 
107  /// \brief Constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity from
108  /// a given array representing its value's xx, xy, xz, yy, yz, and zz Cartesian components.
109  explicit constexpr DimensionlessSymmetricDyad(const std::array<NumericType, 6>& xx_xy_xz_yy_yz_zz)
110  : value(xx_xy_xz_yy_yz_zz) {}
111 
112  /// \brief Constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity with
113  /// a given value.
115  : value(value) {}
116 
117  /// \brief Destructor. Destroys this dimensionless symmetric dyadic tensor physical quantity.
118  ~DimensionlessSymmetricDyad() noexcept = default;
119 
120  /// \brief Copy constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity
121  /// by copying another one.
123  const DimensionlessSymmetricDyad<NumericType>& other) = default;
124 
125  /// \brief Copy constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity
126  /// by copying another one.
127  /// \tparam OtherNumericType Floating-point numeric type of the other physical quantity. Deduced
128  /// automatically.
129  template <typename OtherNumericType>
130  explicit constexpr DimensionlessSymmetricDyad(
131  const DimensionlessSymmetricDyad<OtherNumericType>& other)
132  : value(static_cast<PhQ::SymmetricDyad<NumericType>>(other.Value())) {}
133 
134  /// \brief Move constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity
135  /// by moving another one.
137  DimensionlessSymmetricDyad<NumericType>&& other) noexcept = default;
138 
139  /// \brief Copy assignment operator. Assigns this dimensionless symmetric dyadic tensor physical
140  /// quantity by copying another one.
142  const DimensionlessSymmetricDyad<NumericType>& other) = default;
143 
144  /// \brief Copy assignment operator. Assigns this dimensionless symmetric dyadic tensor physical
145  /// quantity by copying another one.
146  /// \tparam OtherNumericType Floating-point numeric type of the other physical quantity. Deduced
147  /// automatically.
148  template <typename OtherNumericType>
151  value = static_cast<PhQ::SymmetricDyad<NumericType>>(other.Value());
152  return *this;
153  }
154 
155  /// \brief Move assignment operator. Assigns this dimensionless symmetric dyadic tensor physical
156  /// quantity by moving another one.
158  DimensionlessSymmetricDyad<NumericType>&& other) noexcept = default;
159 
160  /// \brief Value of this physical quantity.
162 };
163 
164 } // namespace PhQ
165 
166 #endif // PHQ_DIMENSIONLESS_SYMMETRIC_DYAD_HPP
Abstract base class that represents any dimensionless symmetric dyadic tensor physical quantity....
std::string XML() const
Serializes this physical quantity as an XML message.
constexpr DimensionlessSymmetricDyad< NumericType > & operator=(const DimensionlessSymmetricDyad< NumericType > &other)=default
Copy assignment operator. Assigns this dimensionless symmetric dyadic tensor physical quantity by cop...
~DimensionlessSymmetricDyad() noexcept=default
Destructor. Destroys this dimensionless symmetric dyadic tensor physical quantity.
constexpr PhQ::SymmetricDyad< NumericType > & MutableValue() noexcept
Returns the value of this physical quantity as a mutable value.
constexpr DimensionlessSymmetricDyad(DimensionlessSymmetricDyad< NumericType > &&other) noexcept=default
Move constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity by moving anot...
std::string JSON() const
Serializes this physical quantity as a JSON message.
static constexpr PhQ::Dimensions Dimensions()
Physical dimension set of this physical quantity. Since this physical quantity is dimensionless,...
std::string YAML() const
Serializes this physical quantity as a YAML message.
constexpr DimensionlessSymmetricDyad(const PhQ::SymmetricDyad< NumericType > &value)
Constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity with a given value.
constexpr void SetValue(const PhQ::SymmetricDyad< NumericType > &value) noexcept
Sets the value of this physical quantity to the given value.
constexpr const PhQ::SymmetricDyad< NumericType > & Value() const noexcept
Value of this physical quantity.
DimensionlessSymmetricDyad()=default
Default constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity with an uni...
std::string Print() const
Prints this physical quantity as a string.
constexpr DimensionlessSymmetricDyad< NumericType > & operator=(DimensionlessSymmetricDyad< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this dimensionless symmetric dyadic tensor physical quantity by mov...
constexpr DimensionlessSymmetricDyad(const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yy, const NumericType yz, const NumericType zz)
Constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity whose value has the...
constexpr DimensionlessSymmetricDyad(const std::array< NumericType, 6 > &xx_xy_xz_yy_yz_zz)
Constructor. Constructs a dimensionless symmetric dyadic tensor physical quantity from a given array ...
PhQ::SymmetricDyad< NumericType > value
Value of this physical quantity.
constexpr DimensionlessSymmetricDyad< NumericType > & operator=(const DimensionlessSymmetricDyad< OtherNumericType > &other)
Copy assignment operator. Assigns this dimensionless symmetric dyadic tensor physical quantity by cop...
Physical dimension set of a unit of measure or physical quantity. Composed of the seven independent b...
Definition: Dimensions.hpp:49
Symmetric three-dimensional Euclidean dyadic tensor. Contains six components in Cartesian coordinates...
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....
Definition: Dimensions.hpp:406