MechanicalFemPhysics
The GeMA Mechanical FEM Physics Plugin
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 
28 #include "gmpMechanicalPhysics.h"
29 #include <gmTrace.h>
30 #include <math.h>
31 
32 
34 template <class T> class GmpMechanic : public T
35 {
36 public:
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 
42 protected:
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  double k, l, m;
52  GmMatrix B;
53  double detJ = shape->shapeCartesianPartialsFromJacobian(ncoord, J, B, true);
54 
55  assert(Bu.n_rows == 2*d && Bu.n_cols == e->numNodes()*d);
56  Bu.zeros();
57  // 2D solid element
58  if (d == 2)
59  {
60  for (int i = 0; i < e->numNodes(); i++)
61  {
62  k = 2 * i + 1;
63  l = 2 * i;
64  Bu(0, l) = B(0, i);
65  Bu(1, k) = B(1, i);
66  Bu(3, l) = B(1, i);
67  Bu(3, k) = B(0, i);
68  }
69  }
70  // 3D solid element
71  else if (d == 3)
72  {
73  for (int i = 0; i < e->numNodes(); i++)
74  {
75  m = 3 * i + 2;
76  k = m - 1;
77  l = m - 2;
78  Bu(0, l) = B(0, i);
79  Bu(1, k) = B(1, i);
80  Bu(2, m) = B(2, i);
81  Bu(3, l) = B(1, i);
82  Bu(3, k) = B(0, i);
83  Bu(4, l) = B(2, i);
84  Bu(4, m) = B(0, i);
85  Bu(5, k) = B(2, i);
86  Bu(5, m) = B(1, i);
87  }
88  }
89  return detJ;
90  }
91 };
92 
93 template <class T> class GmpMechanicPlaneStress : public T
94 {
95 public:
96  GmpMechanicPlaneStress(const char* pluginType, GmSimulationData* simulation, QString id, QString description,
97  const GmpFemPhysicsCommonMaterialFactory* matFactory, const GmLogCategory& logger)
98  : T(pluginType, simulation, id, description, matFactory, logger)
99  {}
100 
101 protected:
102  // Comments on the base class
103  virtual double fillBuMatrix(const GmElement* e, const GmShape* shape, const GmVector& ncoord, const GmMatrix& X, const GmVector& N, const GmMatrix& J, GmMatrix& Bu)
104  {
105  S_TRACE();
106  assert(e); Q_UNUSED(X); Q_UNUSED(N);
107 
108  double k, l;
109  GmMatrix B;
110  double detJ = shape->shapeCartesianPartialsFromJacobian(ncoord, J, B, true);
111 
112  assert(Bu.n_rows == 2 * nodeDim() && Bu.n_cols == e->numNodes()*nodeDim());
113  Bu.zeros();
114 
115  // 2D solid element
116  assert(nodeDim() == 2);
117  for (int i = 0; i < e->numNodes(); i++)
118  {
119  k = 2 * i + 1;
120  l = 2 * i;
121  Bu(0, l) = B(0, i);
122  Bu(1, k) = B(1, i);
123  Bu(3, l) = B(1, i);
124  Bu(3, k) = B(0, i);
125  }
126  return detJ;
127  }
128  // Comments on the base class
129  virtual bool isPlaneStress() { return true; }
130 };
131 
133 template <class T> class GmpMechanicAxy : public T
134 {
135 public:
136  GmpMechanicAxy(const char* pluginType, GmSimulationData* simulation, QString id, QString description,
137  const GmpFemPhysicsCommonMaterialFactory* matFactory, const GmLogCategory& logger)
138  : T(pluginType, simulation, id, description, matFactory, logger)
139  {}
140 
141 protected:
143  virtual bool isAxisymmetric() { return true; }
144 
145  // Comments on the base class
146  virtual double fillBuMatrix(const GmElement* e, const GmShape* shape, const GmVector& ncoord, const GmMatrix& X, const GmVector& N, const GmMatrix& J, GmMatrix& Bu)
147  {
148  S_TRACE();
149  assert(e);
150 
151  int n = e->numNodes();
152  double k, l;
153  GmMatrix B;
154  double detJ = shape->shapeCartesianPartialsFromJacobian(ncoord, J, B, true);
155 
156  double rGauss = 0.0;
157  for (int j = 0; j < n; ++j)
158  rGauss += N(j)*X(j, 0);
159 
160  assert(Bu.n_rows == 2 * nodeDim() && Bu.n_cols == n*nodeDim());
161  Bu.zeros();
162  // 2D solid element
163  assert(nodeDim() == 2);
164  for (int i = 0; i < e->numNodes(); i++)
165  {
166  k = 2 * i + 1;
167  l = 2 * i;
168  Bu(0, l) = B(0, i);
169  Bu(1, k) = B(1, i);
170  Bu(2, l) = N(i) / rGauss;
171  Bu(3, l) = B(1, i);
172  Bu(3, k) = B(0, i);
173  }
174 
175  return detJ;
176  }
177 
178  // Comments on the base class
179  virtual double axisymmetricFactor(const GmElement* e, const GmMatrix& X, const GmVector& N)
180  {
181  int n = e->numNodes();
182 
183  double rGauss = 0.0;
184  for (int j = 0; j < n; ++j)
185  rGauss += N(j)*X(j, 0);
186  return 2 * arma::datum::pi * rGauss;
187  }
188 
189 };
190 
191 #endif
Mechanic Axissymetric for Quad and Tri, Elements.
Definition: gmpMechanic.h:133
Declaration of the GmpMechanicalPhysics class.
#define S_TRACE()
Definition: gmpMechanic.h:93
virtual bool isAxisymmetric()
Returns TRUE only for axisymmetric models.
Definition: gmpMechanic.h:143
Mechanic 2D & 3D for Quad, Tri, Hex and Tet Elements.
Definition: gmpMechanic.h:34
virtual int numNodes() const=0
virtual double shapeCartesianPartialsFromJacobian(const GmVector &ncoord, const GmMatrix &J, GmMatrix &dN, bool transposed=false) const
arma::vec GmVector
arma::mat GmMatrix