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) \
47  std::cout << "[" << __func__ << "] "
48 
49 #define OB_TODO(x__) MRPT_TODO(x__)
50 
51 namespace openbeam
52 {
53 inline num_t DEG2RAD(const num_t x) { return x * M_PI / num_t(180.0); }
54 inline num_t RAD2DEG(const num_t x) { return x * num_t(180.0) / M_PI; }
55 
56 constexpr num_t UNINITIALIZED_VALUE = (std::numeric_limits<num_t>::max());
57 
58 template <typename T>
59 inline T square(T x)
60 {
61  return x * x;
62 }
63 
64 extern mrpt::system::CTimeLogger timelog;
65 
69 using DynMatrix = Eigen::Matrix<num_t, Eigen::Dynamic, Eigen::Dynamic>;
70 using Matrix66 = Eigen::Matrix<num_t, 6, 6>;
71 using Matrix33 = Eigen::Matrix<num_t, 3, 3>;
72 using Vector6 = Eigen::Matrix<num_t, 6, 1>;
73 using Vector3 = Eigen::Matrix<num_t, 3, 1>;
74 
75 using vector_string_t = std::vector<std::string>;
76 
78 struct FaceStress
79 {
80  FaceStress() = default;
81  ~FaceStress() = default;
82 
83  num_t N = 0;
84  num_t Vy = 0;
85  num_t Vz = 0;
86  num_t Mx = 0;
87  num_t My = 0;
88  num_t Mz = 0;
89 
90  num_t operator[](const int idx) const
91  {
92  switch (idx)
93  {
94  case 0:
95  return N;
96  case 1:
97  return Vy;
98  case 2:
99  return Mz;
100  case 3:
101  return Vz;
102  case 4:
103  return My;
104  case 5:
105  return Mx;
106  default:
107  THROW_EXCEPTION("out of range");
108  };
109  }
110  num_t& operator[](const int idx)
111  {
112  switch (idx)
113  {
114  case 0:
115  return N;
116  case 1:
117  return Vy;
118  case 2:
119  return Mz;
120  case 3:
121  return Vz;
122  case 4:
123  return My;
124  case 5:
125  return Mx;
126  default:
127  THROW_EXCEPTION("out of range");
128  };
129  }
130 
131  FaceStress& operator+=(const FaceStress& o)
132  {
133  N += o.N;
134  Vy += o.Vy;
135  Vz += o.Vz;
136  Mx += o.Mx;
137  My += o.My;
138  Mz += o.Mz;
139  return *this;
140  }
141 
142  template <class MAT>
143  FaceStress& operator+=(const Eigen::MatrixBase<MAT>& o)
144  {
145  ASSERT_(o.size() == 6);
146  N += o[0];
147  Vy += o[1];
148  Vz += o[2];
149  Mx += o[3];
150  My += o[4];
151  Mz += o[5];
152  return *this;
153  }
154 };
155 
157 using ElementStress = std::vector<FaceStress>;
158 
159 // TODO: Move to its own header and put a forward decl here.
161 {
162  EvaluationContext() = default;
163 
166  num_t evaluate(const std::string& sVarVal) const;
167 
169  num_t evaluate(const mrpt::containers::yaml& proxy) const
170  {
171  return evaluate(proxy.node().as<std::string>());
172  }
173 
174  std::map<std::string, double> parameters;
175 
176  std::map<std::string, mrpt::containers::yaml> beamSectionParameters;
177 
178  vector_string_t* err_msgs = nullptr;
179  vector_string_t* warn_msgs = nullptr;
180  unsigned int lin_num = 0;
181 
182  // Warning switches:
183  const bool warn_unused_constraints = true;
184 };
185 
187 {
188  inline TRotation3D() : rot(Matrix33::Identity()), m_is_pure_identity(true)
189  {
190  }
191  TRotation3D(const num_t ang_x, const num_t ang_y, const num_t ang_z);
192 
193  inline const Matrix33& getRot() const { return rot; }
194  inline void setRot(const Matrix33& r)
195  {
196  rot = r;
197  m_is_pure_identity = false;
198  }
199 
200  static void matrix2angles(
201  const Matrix33& R, num_t& ang_x, num_t& ang_y, num_t& ang_z);
202 
203  bool isIdentity()
204  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 
218  num_t x, num_t y, num_t z, num_t ang_x, num_t ang_y, num_t ang_z)
219  : t(x, y, z), r(ang_x, ang_y, ang_z)
220  {
221  }
222 
223  TPoint3D t;
225 
226  num_t distanceTo(const TRotationTrans3D& o) const
227  {
228  return t.distanceTo(o.t);
229  }
230 };
231 
237 void setVerbosityLevel(int verbose_level);
238 
242 int getVerbosityLevel();
243 
245 bool strCmpI(const std::string& s1, const std::string& s2);
246 
249 num_t str2num(const std::string& s);
250 
251 using mrpt::format;
252 using array6 = std::array<num_t, 6>;
253 
254 using element_index_t = std::size_t;
255 using node_index_t = std::size_t;
256 
257 struct DrawStructureOptions;
258 struct RenderInitData;
259 struct DrawElementExtraParams;
260 struct StaticSolveProblemInfo;
261 
262 } // namespace openbeam
Definition: types.h:161
num_t evaluate(const std::string &sVarVal) const
num_t evaluate(const mrpt::containers::yaml &proxy) const
for use with evaluate(p["K"])
Definition: types.h:169
One entry per element "face".
Definition: types.h:79
num_t N
Axial.
Definition: types.h:83
num_t Mz
Moment Z.
Definition: types.h:88
num_t Vz
Shear Z.
Definition: types.h:85
num_t Vy
Shear Y.
Definition: types.h:84
num_t My
Moment Y.
Definition: types.h:87
num_t Mx
Moment X.
Definition: types.h:86
Definition: types.h:187
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:224
TPoint3D t
Translation vector in 3D.
Definition: types.h:223