Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ConstitutiveModel.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_CONSTITUTIVE_MODEL_HPP
26 #define PHQ_CONSTITUTIVE_MODEL_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 #include <string>
32 
33 #include "Base.hpp"
34 #include "Strain.hpp"
35 #include "StrainRate.hpp"
36 #include "Stress.hpp"
37 
38 namespace PhQ {
39 
40 /// \brief Abstract base class for a material's constitutive model, which is a model that defines
41 /// the relationship between the stress and the strain and strain rate at any point in the material.
43 public:
44  // Forward declaration for class PhQ::ConstitutiveModel.
45  template <typename NumericType = double>
47 
48  // Forward declaration for class PhQ::ConstitutiveModel.
49  template <typename NumericType = double>
51 
52  // Forward declaration for class PhQ::ConstitutiveModel.
53  template <typename NumericType = double>
55 
56  /// \brief Type of a material's constitutive model.
57  enum class Type : int8_t {
58  /// \brief Compressible Newtonian fluid constitutive model
60 
61  /// \brief Elastic isotropic solid constitutive model
63 
64  /// \brief Incompressible Newtonian fluid constitutive model
66  };
67 
68  /// \brief Default constructor. Constructs this constitutive model.
69  constexpr ConstitutiveModel() = default;
70 
71  /// \brief Destructor. Destroys this constitutive model.
72  virtual ~ConstitutiveModel() noexcept = default;
73 
74  /// \brief Copy constructor. Constructs a constitutive model by copying another one.
75  constexpr ConstitutiveModel(const ConstitutiveModel& other) = default;
76 
77  /// \brief Move constructor. Constructs a constitutive model by moving another one.
78  constexpr ConstitutiveModel(ConstitutiveModel&& other) noexcept = default;
79 
80  /// \brief Copy assignment operator. Assigns this constitutive model by copying another one.
81  ConstitutiveModel& operator=(const ConstitutiveModel& other) = default;
82 
83  /// \brief Move assignment operator. Assigns this constitutive model by moving another one.
84  ConstitutiveModel& operator=(ConstitutiveModel&& other) noexcept = default;
85 
86  /// \brief Returns this constitutive model's type.
87  [[nodiscard]] virtual inline Type GetType() const noexcept = 0;
88 
89  /// \brief Returns the stress resulting from a given strain and strain rate.
90  [[nodiscard]] virtual inline PhQ::Stress<float> Stress(
91  const PhQ::Strain<float>& strain, const PhQ::StrainRate<float>& strain_rate) const = 0;
92 
93  /// \brief Returns the stress resulting from a given strain and strain rate.
94  [[nodiscard]] virtual inline PhQ::Stress<double> Stress(
95  const PhQ::Strain<double>& strain, const PhQ::StrainRate<double>& strain_rate) const = 0;
96 
97  /// \brief Returns the stress resulting from a given strain and strain rate.
98  [[nodiscard]] virtual inline PhQ::Stress<long double> Stress(
99  const PhQ::Strain<long double>& strain,
100  const PhQ::StrainRate<long double>& strain_rate) const = 0;
101 
102  /// \brief Returns the stress resulting from a given strain.
103  [[nodiscard]] virtual inline PhQ::Stress<float> Stress(
104  const PhQ::Strain<float>& strain) const = 0;
105 
106  /// \brief Returns the stress resulting from a given strain.
107  [[nodiscard]] virtual inline PhQ::Stress<double> Stress(
108  const PhQ::Strain<double>& strain) const = 0;
109 
110  /// \brief Returns the stress resulting from a given strain.
111  [[nodiscard]] virtual inline PhQ::Stress<long double> Stress(
112  const PhQ::Strain<long double>& strain) const = 0;
113 
114  /// \brief Returns the stress resulting from a given strain rate.
115  [[nodiscard]] virtual inline PhQ::Stress<float> Stress(
116  const PhQ::StrainRate<float>& strain_rate) const = 0;
117 
118  /// \brief Returns the stress resulting from a given strain rate.
119  [[nodiscard]] virtual inline PhQ::Stress<double> Stress(
120  const PhQ::StrainRate<double>& strain_rate) const = 0;
121 
122  /// \brief Returns the stress resulting from a given strain rate.
123  [[nodiscard]] virtual inline PhQ::Stress<long double> Stress(
124  const PhQ::StrainRate<long double>& strain_rate) const = 0;
125 
126  /// \brief Returns the strain resulting from a given stress.
127  [[nodiscard]] virtual inline PhQ::Strain<float> Strain(
128  const PhQ::Stress<float>& stress) const = 0;
129 
130  /// \brief Returns the strain resulting from a given stress.
131  [[nodiscard]] virtual inline PhQ::Strain<double> Strain(
132  const PhQ::Stress<double>& stress) const = 0;
133 
134  /// \brief Returns the strain resulting from a given stress.
135  [[nodiscard]] virtual inline PhQ::Strain<long double> Strain(
136  const PhQ::Stress<long double>& stress) const = 0;
137 
138  /// \brief Returns the strain rate resulting from a given stress.
139  [[nodiscard]] virtual inline PhQ::StrainRate<float> StrainRate(
140  const PhQ::Stress<float>& stress) const = 0;
141 
142  /// \brief Returns the strain rate resulting from a given stress.
143  [[nodiscard]] virtual inline PhQ::StrainRate<double> StrainRate(
144  const PhQ::Stress<double>& stress) const = 0;
145 
146  /// \brief Returns the strain rate resulting from a given stress.
147  [[nodiscard]] virtual inline PhQ::StrainRate<long double> StrainRate(
148  const PhQ::Stress<long double>& stress) const = 0;
149 
150  /// \brief Prints this constitutive model as a string.
151  [[nodiscard]] virtual inline std::string Print() const = 0;
152 
153  /// \brief Serializes this constitutive model as a JSON message.
154  [[nodiscard]] virtual inline std::string JSON() const = 0;
155 
156  /// \brief Serializes this constitutive model as an XML message.
157  [[nodiscard]] virtual inline std::string XML() const = 0;
158 
159  /// \brief Serializes this constitutive model as a YAML message.
160  [[nodiscard]] virtual inline std::string YAML() const = 0;
161 };
162 
163 template <>
164 inline const std::map<typename ConstitutiveModel::Type, std::string_view>
165  Internal::Abbreviations<typename ConstitutiveModel::Type>{
166  {ConstitutiveModel::Type::ElasticIsotropicSolid, "Elastic Isotropic Solid" },
167  {ConstitutiveModel::Type::IncompressibleNewtonianFluid, "Incompressible Newtonian Fluid"},
168  {ConstitutiveModel::Type::CompressibleNewtonianFluid, "Compressible Newtonian Fluid" },
169 };
170 
171 template <>
172 inline const std::unordered_map<std::string_view, typename ConstitutiveModel::Type>
173  Internal::Spellings<typename ConstitutiveModel::Type>{
174  {"Elastic Isotropic Solid", ConstitutiveModel::Type::ElasticIsotropicSolid },
175  {"ELASTIC ISOTROPIC SOLID", ConstitutiveModel::Type::ElasticIsotropicSolid },
176  {"elastic isotropic solid", ConstitutiveModel::Type::ElasticIsotropicSolid },
177  {"ElasticIsotropicSolid", ConstitutiveModel::Type::ElasticIsotropicSolid },
178  {"ELASTIC_ISOTROPIC_SOLID", ConstitutiveModel::Type::ElasticIsotropicSolid },
179  {"elastic_isotropic_solid", ConstitutiveModel::Type::ElasticIsotropicSolid },
180  {"Incompressible Newtonian Fluid", ConstitutiveModel::Type::IncompressibleNewtonianFluid},
181  {"INCOMPRESSIBLE NEWTONIAN FLUID", ConstitutiveModel::Type::IncompressibleNewtonianFluid},
182  {"incompressible newtonian fluid", ConstitutiveModel::Type::IncompressibleNewtonianFluid},
183  {"IncompressibleNewtonianFluid", ConstitutiveModel::Type::IncompressibleNewtonianFluid},
184  {"INCOMPRESSIBLE_NEWTONIAN_FLUID", ConstitutiveModel::Type::IncompressibleNewtonianFluid},
185  {"incompressible_newtonian_fluid", ConstitutiveModel::Type::IncompressibleNewtonianFluid},
186  {"Compressible Newtonian Fluid", ConstitutiveModel::Type::CompressibleNewtonianFluid },
187  {"COMPRESSIBLE NEWTONIAN FLUID", ConstitutiveModel::Type::CompressibleNewtonianFluid },
188  {"compressible newtonian fluid", ConstitutiveModel::Type::CompressibleNewtonianFluid },
189  {"CompressibleNewtonianFluid", ConstitutiveModel::Type::CompressibleNewtonianFluid },
190  {"COMPRESSIBLE_NEWTONIAN_FLUID", ConstitutiveModel::Type::CompressibleNewtonianFluid },
191  {"compressible_newtonian_fluid", ConstitutiveModel::Type::CompressibleNewtonianFluid },
192 };
193 
194 inline std::ostream& operator<<(std::ostream& stream, const ConstitutiveModel& model) {
195  stream << model.Print();
196  return stream;
197 }
198 
199 } // namespace PhQ
200 
201 #endif // PHQ_CONSTITUTIVE_MODEL_HPP
Constitutive model for a compressible Newtonian fluid. This is the simplest constitutive model for a ...
Constitutive model for an elastic isotropic solid. This is the simplest constitutive model for a defo...
Constitutive model for an incompressible Newtonian fluid. This is the simplest constitutive model for...
Abstract base class for a material's constitutive model, which is a model that defines the relationsh...
virtual ~ConstitutiveModel() noexcept=default
Destructor. Destroys this constitutive model.
Type
Type of a material's constitutive model.
@ IncompressibleNewtonianFluid
Incompressible Newtonian fluid constitutive model.
@ CompressibleNewtonianFluid
Compressible Newtonian fluid constitutive model.
@ ElasticIsotropicSolid
Elastic isotropic solid constitutive model.
virtual std::string XML() const =0
Serializes this constitutive model as an XML message.
virtual Type GetType() const noexcept=0
Returns this constitutive model's type.
virtual std::string YAML() const =0
Serializes this constitutive model as a YAML message.
virtual std::string JSON() const =0
Serializes this constitutive model as a JSON message.
virtual std::string Print() const =0
Prints this constitutive model as a string.
constexpr ConstitutiveModel()=default
Default constructor. Constructs this constitutive model.
Three-dimensional Euclidean strain rate symmetric dyadic tensor. Time rate of change of strain....
Definition: StrainRate.hpp:51
Three-dimensional Euclidean strain symmetric dyadic tensor. Contains six components in Cartesian coor...
Definition: Strain.hpp:68
Three-dimensional Euclidean Cauchy stress symmetric dyadic tensor. Contains six components in Cartesi...
Definition: Stress.hpp:50
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)