MechanicalFemPhysics
The GeMA Mechanical FEM Physics Plugin
Loading...
Searching...
No Matches
gmpMechanic.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_PLUGIN_MECHANICAL_PHYSICS_MECHANIC_H_
25#define _GEMA_PLUGIN_MECHANICAL_PHYSICS_MECHANIC_H_
26
27
29#include <gmTrace.h>
30#include <math.h>
31
32
34template <class T> class GmpMechanic : public T
35{
36public:
37 GmpMechanic(const char* pluginType, GmSimulationData* simulation, QString id, QString description,
38 const GmpFemPhysicsCommonMaterialFactory* matFactory, const GmLogCategory& logger)
39 : T(pluginType, simulation, id, description, matFactory, logger)
40 {}
41
42protected:
43 // Comments on the base class
44 virtual double fillBuMatrix(const GmElement* e, const GmShape* shape, const GmVector& ncoord,
45 const GmMatrix& X, const GmVector& N, const GmMatrix& J, GmMatrix& Bu)
46 {
47 S_TRACE();
48 assert(e); Q_UNUSED(X); Q_UNUSED(N);
49
50 int d = GmpFemPhysicsCommon::nodeDim();
51 GmMatrix B;
52 double detJ = shape->shapeCartesianPartialsFromJacobian(ncoord, J, B, true);
53
54 assert(Bu.n_rows == 2*d && Bu.n_cols == e->numNodes()*d);
55 Bu.zeros();
56 // 2D solid element
57 if (d == 2)
58 {
59 for (int i = 0; i < e->numNodes(); i++)
60 {
61 int k = 2 * i + 1;
62 int l = 2 * i;
63 Bu(0, l) = B(0, i);
64 Bu(1, k) = B(1, i);
65 Bu(3, l) = B(1, i);
66 Bu(3, k) = B(0, i);
67 }
68 }
69 // 3D solid element
70 else if (d == 3)
71 {
72 constexpr int bstride = 3;
73 constexpr int bustride = 6;
74 const double* bptr = B.memptr();
75 double * buptr = Bu.memptr();
76 for (int i = 0, n = e->numNodes(); i < n; i++)
77 {
78 int m = 3 * i + 2;
79 int k = m - 1;
80 int l = m - 2;
81
82 const double* bi = bptr + i*bstride;
83 double b0 = bi[0], b1 = bi[1], b2 = bi[2];
84 /*
85 Bu(0, l) = B(0, i);
86 Bu(3, l) = B(1, i);
87 Bu(4, l) = B(2, i);
88 */
89 double* bu = buptr + bustride * l;
90 bu[0] = b0;
91 bu[3] = b1;
92 bu[4] = b2;
93
94 /*
95 Bu(1, k) = B(1, i);
96 Bu(3, k) = B(0, i);
97 Bu(5, k) = B(2, i);
98 */
99
100 bu = buptr + bustride * k;
101 bu[1] = b1;
102 bu[3] = b0;
103 bu[5] = b2;
104
105 /*
106 Bu(2, m) = B(2, i);
107 Bu(4, m) = B(0, i);
108 Bu(5, m) = B(1, i);
109 */
110
111 bu = buptr + bustride * m;
112 bu[2] = b2;
113 bu[4] = b0;
114 bu[5] = b1;
115 }
116 }
117 return detJ;
118 }
119};
120
121template <class T> class GmpMechanicPlaneStress : public T
122{
123public:
124 GmpMechanicPlaneStress(const char* pluginType, GmSimulationData* simulation, QString id, QString description,
125 const GmpFemPhysicsCommonMaterialFactory* matFactory, const GmLogCategory& logger)
126 : T(pluginType, simulation, id, description, matFactory, logger)
127 {}
128
129protected:
130 // Comments on the base class
131 virtual double fillBuMatrix(const GmElement* e, const GmShape* shape, const GmVector& ncoord, const GmMatrix& X, const GmVector& N, const GmMatrix& J, GmMatrix& Bu)
132 {
133 S_TRACE();
134 assert(e); Q_UNUSED(X); Q_UNUSED(N);
135
136 double k, l;
137 GmMatrix B;
138 double detJ = shape->shapeCartesianPartialsFromJacobian(ncoord, J, B, true);
139
140 assert(Bu.n_rows == 2 * nodeDim() && Bu.n_cols == e->numNodes()*nodeDim());
141 Bu.zeros();
142
143 // 2D solid element
144 assert(nodeDim() == 2);
145 for (int i = 0; i < e->numNodes(); i++)
146 {
147 k = 2 * i + 1;
148 l = 2 * i;
149 Bu(0, l) = B(0, i);
150 Bu(1, k) = B(1, i);
151 Bu(3, l) = B(1, i);
152 Bu(3, k) = B(0, i);
153 }
154 return detJ;
155 }
156 // Comments on the base class
157 virtual bool isPlaneStress() { return true; }
158};
159
161template <class T> class GmpMechanicAxy : public T
162{
163public:
164 GmpMechanicAxy(const char* pluginType, GmSimulationData* simulation, QString id, QString description,
165 const GmpFemPhysicsCommonMaterialFactory* matFactory, const GmLogCategory& logger)
166 : T(pluginType, simulation, id, description, matFactory, logger)
167 {}
168
169protected:
171 virtual bool isAxisymmetric() { return true; }
172
173 // Comments on the base class
174 virtual double fillBuMatrix(const GmElement* e, const GmShape* shape, const GmVector& ncoord, const GmMatrix& X, const GmVector& N, const GmMatrix& J, GmMatrix& Bu)
175 {
176 S_TRACE();
177 assert(e);
178
179 int n = e->numNodes();
180 double k, l;
181 GmMatrix B;
182 double detJ = shape->shapeCartesianPartialsFromJacobian(ncoord, J, B, true);
183
184 double rGauss = 0.0;
185 for (int j = 0; j < n; ++j)
186 rGauss += N(j)*X(j, 0);
187
188 assert(Bu.n_rows == 2 * nodeDim() && Bu.n_cols == n*nodeDim());
189 Bu.zeros();
190 // 2D solid element
191 assert(nodeDim() == 2);
192 for (int i = 0; i < e->numNodes(); i++)
193 {
194 k = 2 * i + 1;
195 l = 2 * i;
196 Bu(0, l) = B(0, i);
197 Bu(1, k) = B(1, i);
198 Bu(2, l) = N(i) / rGauss;
199 Bu(3, l) = B(1, i);
200 Bu(3, k) = B(0, i);
201 }
202
203 return detJ;
204 }
205
206 // Comments on the base class
207 virtual double axisymmetricFactor(const GmElement* e, const GmMatrix& X, const GmVector& N) const
208 {
209 int n = e->numNodes();
210
211 double rGauss = 0.0;
212 for (int j = 0; j < n; ++j)
213 rGauss += N(j)*X(j, 0);
214 return 2 * arma::datum::pi * rGauss;
215 }
216
217};
218
219#endif
virtual int numNodes() const=0
virtual double shapeCartesianPartialsFromJacobian(const GmVector &ncoord, const GmMatrix &J, GmMatrix &dN, bool transposed=false) const
Mechanic Axissymetric for Quad and Tri, Elements.
Definition gmpMechanic.h:162
virtual bool isAxisymmetric()
Returns TRUE only for axisymmetric models.
Definition gmpMechanic.h:171
Mechanic 2D & 3D for Quad, Tri, Hex and Tet Elements.
Definition gmpMechanic.h:35
Definition gmpMechanic.h:122
arma::mat GmMatrix
#define S_TRACE()
arma::vec GmVector
Declaration of the GmpMechanicalPhysics class.