OpenBeam
C++ library for static analysis of mechanical structures
types.h
1 /* +---------------------------------------------------------------------------+
2  | OpenBeam - C++ Finite Element Analysis library |
3  | |
4  | Copyright (C) 2010-2021 Jose Luis Blanco Claraco |
5  | University of Malaga |
6  | |
7  | OpenBeam is free software: you can redistribute it and/or modify |
8  | it under the terms of the GNU General Public License as published by |
9  | the Free Software Foundation, either version 3 of the License, or |
10  | (at your option) any later version. |
11  | |
12  | OpenBeam is distributed in the hope that it will be useful, |
13  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15  | GNU General Public License for more details. |
16  | |
17  | You should have received a copy of the GNU General Public License |
18  | along with OpenBeam. If not, see <http://www.gnu.org/licenses/>. |
19  | |
20  +---------------------------------------------------------------------------+
21  */
22 
23 #pragma once
24 
25 #include <openbeam/config.h>
26 //
27 #include <mrpt/containers/yaml.h>
28 #include <mrpt/core/exceptions.h> // ASSERT_(), etc.
29 #include <mrpt/core/format.h> // mrpt::format()
30 #include <mrpt/math/TPoint3D.h>
31 #include <mrpt/system/CTimeLogger.h>
32 
33 #include <Eigen/Dense>
34 #include <Eigen/StdVector>
35 #include <array>
36 #include <cmath>
37 #include <cstdlib>
38 #include <limits>
39 #include <string>
40 
45 #define OB_MESSAGE(VERBOSE_LEVEL) \
46  if (openbeam::getVerbosityLevel() >= VERBOSE_LEVEL) std::cout << "[" << __func__ << "] "
47 
48 #define OB_TODO(x__) MRPT_TODO(x__)
49 
50 namespace openbeam
51 {
52 inline num_t DEG2RAD(const num_t x) { return x * M_PI / num_t(180.0); }
53 inline num_t RAD2DEG(const num_t x) { return x * num_t(180.0) / M_PI; }
54 
55 constexpr num_t UNINITIALIZED_VALUE = (std::numeric_limits<num_t>::max());
56 
57 template <typename T>
58 inline T square(T x)
59 {
60  return x * x;
61 }
62 
63 extern mrpt::system::CTimeLogger timelog;
64 
68 using DynMatrix = Eigen::Matrix<num_t, Eigen::Dynamic, Eigen::Dynamic>;
69 using Matrix66 = Eigen::Matrix<num_t, 6, 6>;
70 using Matrix33 = Eigen::Matrix<num_t, 3, 3>;
71 using Vector6 = Eigen::Matrix<num_t, 6, 1>;
72 using Vector3 = Eigen::Matrix<num_t, 3, 1>;
73 
74 using vector_string_t = std::vector<std::string>;
75 
77 struct FaceStress
78 {
79  FaceStress() = default;
80  ~FaceStress() = default;
81 
82  num_t N = 0;
83  num_t Vy = 0;
84  num_t Vz = 0;
85  num_t Mx = 0;
86  num_t My = 0;
87  num_t Mz = 0;
88 
89  num_t operator[](const int idx) const
90  {
91  switch (idx)
92  {
93  case 0:
94  return N;
95  case 1:
96  return Vy;
97  case 2:
98  return Mz;
99  case 3:
100  return Vz;
101  case 4:
102  return My;
103  case 5:
104  return Mx;
105  default:
106  THROW_EXCEPTION("out of range");
107  };
108  }
109  num_t& operator[](const int idx)
110  {
111  switch (idx)
112  {
113  case 0:
114  return N;
115  case 1:
116  return Vy;
117  case 2:
118  return Mz;
119  case 3:
120  return Vz;
121  case 4:
122  return My;
123  case 5:
124  return Mx;
125  default:
126  THROW_EXCEPTION("out of range");
127  };
128  }
129 
130  FaceStress& operator+=(const FaceStress& o)
131  {
132  N += o.N;
133  Vy += o.Vy;
134  Vz += o.Vz;
135  Mx += o.Mx;
136  My += o.My;
137  Mz += o.Mz;
138  return *this;
139  }
140 
141  template <class MAT>
142  FaceStress& operator+=(const Eigen::MatrixBase<MAT>& o)
143  {
144  ASSERT_(o.size() == 6);
145  N += o[0];
146  Vy += o[1];
147  Vz += o[2];
148  Mx += o[3];
149  My += o[4];
150  Mz += o[5];
151  return *this;
152  }
153 };
154 
156 using ElementStress = std::vector<FaceStress>;
157 
158 // TODO: Move to its own header and put a forward decl here.
160 {
161  EvaluationContext() = default;
162 
165  num_t evaluate(const std::string& sVarVal) const;
166 
168  num_t evaluate(const mrpt::containers::yaml& proxy) const
169  {
170  return evaluate(proxy.node().as<std::string>());
171  }
173  num_t evaluate(const mrpt::containers::yaml_cref& proxy) const
174  {
175  return evaluate(proxy.node().as<std::string>());
176  }
177 
178  std::map<std::string, double> parameters;
179 
180  std::map<std::string, mrpt::containers::yaml> beamSectionParameters;
181 
182  vector_string_t* err_msgs = nullptr;
183  vector_string_t* warn_msgs = nullptr;
184  unsigned int lin_num = 0;
185 
186  // Warning switches:
187  const bool warn_unused_constraints = true;
188 };
189 
191 {
192  inline TRotation3D() : rot(Matrix33::Identity()), m_is_pure_identity(true) {}
193  TRotation3D(const num_t ang_x, const num_t ang_y, const num_t ang_z);
194 
195  inline const Matrix33& getRot() const { return rot; }
196  inline void setRot(const Matrix33& r)
197  {
198  rot = r;
199  m_is_pure_identity = false;
200  }
201 
202  static void matrix2angles(const Matrix33& R, num_t& ang_x, num_t& ang_y, num_t& ang_z);
203 
204  bool isIdentity() const;
205 
206  private:
207  Matrix33 rot;
208  bool m_is_pure_identity;
209 };
210 
211 using TPoint3D = mrpt::math::TPoint3D_<num_t>;
212 
214 {
215  TRotationTrans3D() = default;
216 
217  TRotationTrans3D(num_t x, num_t y, num_t z, num_t ang_x, num_t ang_y, num_t ang_z) :
218  t(x, y, z), r(ang_x, ang_y, ang_z)
219  {
220  }
221 
222  TPoint3D t;
224 
225  num_t distanceTo(const TRotationTrans3D& o) const { return t.distanceTo(o.t); }
226 };
227 
233 void setVerbosityLevel(int verbose_level);
234 
238 int getVerbosityLevel();
239 
241 bool strCmpI(const std::string& s1, const std::string& s2);
242 
245 num_t str2num(const std::string& s);
246 
247 using mrpt::format;
248 using array6 = std::array<num_t, 6>;
249 
250 using element_index_t = std::size_t;
251 using node_index_t = std::size_t;
252 
253 struct DrawStructureOptions;
254 struct RenderInitData;
255 struct DrawElementExtraParams;
256 struct StaticSolveProblemInfo;
257 
258 } // namespace openbeam
Definition: types.h:160
num_t evaluate(const std::string &sVarVal) const
num_t evaluate(const mrpt::containers::yaml_cref &proxy) const
for use with evaluate(p["K"]) on a const yaml object
Definition: types.h:173
num_t evaluate(const mrpt::containers::yaml &proxy) const
for use with evaluate(p["K"])
Definition: types.h:168
One entry per element "face".
Definition: types.h:78
num_t N
Axial.
Definition: types.h:82
num_t Mz
Moment Z.
Definition: types.h:87
num_t Vz
Shear Z.
Definition: types.h:84
num_t Vy
Shear Y.
Definition: types.h:83
num_t My
Moment Y.
Definition: types.h:86
num_t Mx
Moment X.
Definition: types.h:85
Definition: types.h:191
bool isIdentity() const
Test for whether this 3x3 matrix is EXACTLY the identity.
Definition: types.h:214
TRotation3D r
Rotation in 3D.
Definition: types.h:223
TPoint3D t
Translation vector in 3D.
Definition: types.h:222