G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMaterialMatrixBase.hpp
Go to the documentation of this file.
1 
16 /*
17  To Do [updated 16-06-2020]:
18  - Make beta (compressible materials) and material parameters universal for all integration points over the thickness. So get them out of the _dPsi functions etc and move them into the integration loops as global variables.
19 
20 */
21 
22 
23 
24 #pragma once
25 
30 
31 namespace gismo
32 {
33 
34 // template <class T>
35 // std::ostream & gsMaterialMatrixBase<T>::print(std::ostream &os) const
36 // {
37 // // TFT
38 // if (const gsMaterialMatrixTFT<2,T,true> * mm =
39 // dynamic_cast<const gsMaterialMatrixTFT<2,T,true> *>( this ) )
40 // return mm->print(os);
41 // if (const gsMaterialMatrixTFT<2,T,false> * mm =
42 // dynamic_cast<const gsMaterialMatrixTFT<2,T,false> *>( this ) )
43 // return mm->print(os);
44 // if (const gsMaterialMatrixTFT<3,T,true> * mm =
45 // dynamic_cast<const gsMaterialMatrixTFT<3,T,true> *>( this ) )
46 // return mm->print(os);
47 // if (const gsMaterialMatrixTFT<3,T,false> * mm =
48 // dynamic_cast<const gsMaterialMatrixTFT<3,T,false> *>( this ) )
49 // return mm->print(os);
50 
51 // // Linear
52 // if ( const gsMaterialMatrixLinear<2,T> * mm =
53 // dynamic_cast<const gsMaterialMatrixLinear<2,T> *>( this ) )
54 // return mm->print(os);
55 // if ( const gsMaterialMatrixLinear<3,T> * mm =
56 // dynamic_cast<const gsMaterialMatrixLinear<3,T> *>( this ) )
57 // return mm->print(os);
58 
59 // // CompressibleNH2
60 // if ( const gsMaterialMatrixNonlinear<2,T,11,true> * mm =
61 // dynamic_cast<const gsMaterialMatrixNonlinear<2,T,11,true> *>( this ) )
62 // return mm->print(os);
63 // // CompressibleNH3
64 // if ( const gsMaterialMatrixNonlinear<3,T,11,true> * mm =
65 // dynamic_cast<const gsMaterialMatrixNonlinear<3,T,11,true> *>( this ) )
66 // return mm->print(os);
67 // // IncompressibleNH2
68 // if ( const gsMaterialMatrixNonlinear<2,T,11,false> * mm =
69 // dynamic_cast<const gsMaterialMatrixNonlinear<2,T,11,false> *>( this ) )
70 // return mm->print(os);
71 // // IncompressibleNH3
72 // if ( const gsMaterialMatrixNonlinear<3,T,11,false> * mm =
73 // dynamic_cast<const gsMaterialMatrixNonlinear<3,T,11,false> *>( this ) )
74 // return mm->print(os);
75 
76 // // CompressibleNHe2
77 // if ( const gsMaterialMatrixNonlinear<2,T,12,true> * mm =
78 // dynamic_cast<const gsMaterialMatrixNonlinear<2,T,12,true> *>( this ) )
79 // return mm->print(os);
80 // // CompressibleNHe3
81 // if ( const gsMaterialMatrixNonlinear<3,T,12,true> * mm =
82 // dynamic_cast<const gsMaterialMatrixNonlinear<3,T,12,true> *>( this ) )
83 // return mm->print(os);
84 // // IncompressibleNHe2
85 // if ( const gsMaterialMatrixNonlinear<2,T,12,false> * mm =
86 // dynamic_cast<const gsMaterialMatrixNonlinear<2,T,12,false> *>( this ) )
87 // return mm->print(os);
88 // // IncompressibleNHe3
89 // if ( const gsMaterialMatrixNonlinear<3,T,12,false> * mm =
90 // dynamic_cast<const gsMaterialMatrixNonlinear<3,T,12,false> *>( this ) )
91 // return mm->print(os);
92 
93 // // CompressibleMR2
94 // if ( const gsMaterialMatrixNonlinear<2,T,13,true> * mm =
95 // dynamic_cast<const gsMaterialMatrixNonlinear<2,T,13,true> *>( this ) )
96 // return mm->print(os);
97 // // CompressibleMR3
98 // if ( const gsMaterialMatrixNonlinear<3,T,13,true> * mm =
99 // dynamic_cast<const gsMaterialMatrixNonlinear<3,T,13,true> *>( this ) )
100 // return mm->print(os);
101 // // IncompressibleMR2
102 // if ( const gsMaterialMatrixNonlinear<2,T,13,false> * mm =
103 // dynamic_cast<const gsMaterialMatrixNonlinear<2,T,13,false> *>( this ) )
104 // return mm->print(os);
105 // // IncompressibleMR3
106 // if ( const gsMaterialMatrixNonlinear<3,T,13,false> * mm =
107 // dynamic_cast<const gsMaterialMatrixNonlinear<3,T,13,false> *>( this ) )
108 // return mm->print(os);
109 
110 // // CompressibleOG2
111 // if ( const gsMaterialMatrixNonlinear<2,T,34,true> * mm =
112 // dynamic_cast<const gsMaterialMatrixNonlinear<2,T,34,true> *>( this ) )
113 // return mm->print(os);
114 // // CompressibleOG3
115 // if ( const gsMaterialMatrixNonlinear<3,T,34,true> * mm =
116 // dynamic_cast<const gsMaterialMatrixNonlinear<3,T,34,true> *>( this ) )
117 // return mm->print(os);
118 // // IncompressibleOG2
119 // if ( const gsMaterialMatrixNonlinear<2,T,34,false> * mm =
120 // dynamic_cast<const gsMaterialMatrixNonlinear<2,T,34,false> *>( this ) )
121 // return mm->print(os);
122 // // IncompressibleOG3
123 // if ( const gsMaterialMatrixNonlinear<3,T,34,false> * mm =
124 // dynamic_cast<const gsMaterialMatrixNonlinear<3,T,34,false> *>( this ) )
125 // return mm->print(os);
126 
127 // os<<"gsMaterialMatrixBase (type not understood).\n";
128 // return os;
129 // }
130 
131 namespace internal {
132 
134 template<class T>
135 class gsXml< gsMaterialMatrixBase<T> >
136 {
137 private:
138  gsXml() { }
139  typedef gsMaterialMatrixBase<T> Object;
140 
141 public:
142  GSXML_COMMON_FUNCTIONS(Object);
143  static std::string tag () { return "MaterialMatrix"; }
144  static std::string type () { return ""; }
145 
146  // GSXML_GET_INTO(Object)
147 
148  static void get_into(gsXmlNode * node, Object & obj)
149  {
150  obj = *get(node);
151  // obj = *tmp;
152  }
153 
154  static Object * get(gsXmlNode * node)
155  {
156  GISMO_ASSERT( ( !strcmp( node->name(),"MaterialMatrix") ),
157  "Something went wrong, was waiting for a MaterialMatrix tag.\n" );
158 
159  gsXmlAttribute * gtype = node->first_attribute("type");
160  if ( ! gtype )
161  {
162  gsWarn<< "MaterialMatrix without a type in the xml file\n";
163  return NULL;
164  }
165 
166  const gsXmlAttribute * att_TFT = node->first_attribute("TFT");
167  bool TFT = false;
168  if (NULL != att_TFT)
169  {
170  if ((strcmp("1", att_TFT->value()) == 0) ||
171  (strcmp("true", att_TFT->value()) == 0) ||
172  (strcmp("True", att_TFT->value()) == 0) )
173  TFT = true;
174  }
175 
176  std::string s = gtype->value() ;
177  Object * tmp = get_impl(node);
178  if (TFT)
179  {
180  if ( ( s == "Linear2" ) )
181  return new gsMaterialMatrixTFT<2,T,true>(tmp);
182  else if ( ( s == "Linear3" ) )
183  return new gsMaterialMatrixTFT<3,T,true>(tmp);
184  else if ( ( s == "CompressibleNH2" ) ||
185  ( s == "IncompressibleNH2" ) ||
186  ( s == "CompressibleNHe2" ) ||
187  ( s == "IncompressibleNHe2" ) ||
188  ( s == "CompressibleMR2" ) ||
189  ( s == "IncompressibleMR2" ) ||
190  ( s == "CompressibleOG2" ) ||
191  ( s == "IncompressibleOG2" ) )
192  return new gsMaterialMatrixTFT<2,T,false>(tmp);
193  else if ( ( s == "CompressibleNH3" ) ||
194  ( s == "IncompressibleNH3" ) ||
195  ( s == "CompressibleNHe3" ) ||
196  ( s == "IncompressibleNHe3" ) ||
197  ( s == "CompressibleMR3" ) ||
198  ( s == "IncompressibleMR3" ) ||
199  ( s == "CompressibleOG3" ) ||
200  ( s == "IncompressibleOG3" ) )
201  return new gsMaterialMatrixTFT<3,T,false>(tmp);
202  else
203  {
204  gsWarn<<"Material matrix for TFT model not recognised\n";
205  return NULL;
206  }
207  }
208  else
209  return tmp;
210  }
211 
212  static Object * get_impl(gsXmlNode * node)
213  {
214  GISMO_ASSERT( ( !strcmp( node->name(),"MaterialMatrix") ),
215  "Something went wrong, was waiting for a MaterialMatrix tag.\n" );
216 
217  gsXmlAttribute * gtype = node->first_attribute("type");
218  if ( ! gtype )
219  {
220  gsWarn<< "MaterialMatrix without a type in the xml file\n";
221  return NULL;
222  }
223 
224  std::string s = gtype->value() ;
225  if ( s == "Linear2" )
226  return gsXml< gsMaterialMatrixLinear<2,T> >::get(node);
227  if ( s == "Linear3" )
228  return gsXml< gsMaterialMatrixLinear<3,T> >::get(node);
229 
230  if ( s == "CompressibleNH2" )
231  return gsXml< gsMaterialMatrixNonlinear<2,T,11,true> >::get(node);
232  if ( s == "CompressibleNH3" )
233  return gsXml< gsMaterialMatrixNonlinear<3,T,11,true> >::get(node);
234  if ( s == "IncompressibleNH2" )
235  return gsXml< gsMaterialMatrixNonlinear<2,T,11,false> >::get(node);
236  if ( s == "IncompressibleNH3" )
237  return gsXml< gsMaterialMatrixNonlinear<3,T,11,false> >::get(node);
238 
239  if ( s == "CompressibleNHe2" )
240  return gsXml< gsMaterialMatrixNonlinear<2,T,12,true> >::get(node);
241  if ( s == "CompressibleNHe3" )
242  return gsXml< gsMaterialMatrixNonlinear<3,T,12,true> >::get(node);
243  if ( s == "IncompressibleNHe2" )
244  return gsXml< gsMaterialMatrixNonlinear<2,T,12,false> >::get(node);
245  if ( s == "IncompressibleNHe3" )
246  return gsXml< gsMaterialMatrixNonlinear<3,T,12,false> >::get(node);
247 
248  if ( s == "CompressibleMR2" )
249  return gsXml< gsMaterialMatrixNonlinear<2,T,13,true> >::get(node);
250  if ( s == "CompressibleMR3" )
251  return gsXml< gsMaterialMatrixNonlinear<3,T,13,true> >::get(node);
252  if ( s == "IncompressibleMR2" )
253  return gsXml< gsMaterialMatrixNonlinear<2,T,13,false> >::get(node);
254  if ( s == "IncompressibleMR3" )
255  return gsXml< gsMaterialMatrixNonlinear<3,T,13,false> >::get(node);
256 
257  if ( s == "CompressibleOG2" )
258  return gsXml< gsMaterialMatrixNonlinear<2,T,34,true> >::get(node);
259  if ( s == "CompressibleOG3" )
260  return gsXml< gsMaterialMatrixNonlinear<3,T,34,true> >::get(node);
261  if ( s == "IncompressibleOG2" )
262  return gsXml< gsMaterialMatrixNonlinear<2,T,34,false> >::get(node);
263  if ( s == "IncompressibleOG3" )
264  return gsXml< gsMaterialMatrixNonlinear<3,T,34,false> >::get(node);
265 
266  gsWarn<<"gsMaterialMatrixBase: get<MaterialMatrixBase<T>>: No known MaterialMatrix \""<<s<<"\". Error.\n";
267  return NULL;
268  }
269 
270  static gsXmlNode * put (const Object & obj,
271  gsXmlTree & data)
272  {
273  const Object * ptr = & obj;
274  if (dynamic_cast<const gsMaterialMatrixTFT<2,T,true> *>( ptr )
275  ||
276  dynamic_cast<const gsMaterialMatrixTFT<3,T,true> *>( ptr )
277  ||
278  dynamic_cast<const gsMaterialMatrixTFT<2,T,false> *>( ptr )
279  ||
280  dynamic_cast<const gsMaterialMatrixTFT<3,T,false> *>( ptr )
281  )
282  {
283  gsXmlNode * tmp = put_impl(ptr->material(),data);
284  tmp->append_attribute(internal::makeAttribute("TFT","true",data));
285  return tmp;
286  }
287  else
288  return put_impl(ptr,data);
289  }
290 
291  static gsXmlNode * put_impl (const Object * obj,
292  gsXmlTree & data)
293  {
294  if ( const gsMaterialMatrixLinear<2,T> * mm =
295  dynamic_cast<const gsMaterialMatrixLinear<2,T> *>( obj ) )
296  return gsXml< gsMaterialMatrixLinear<2,T> >::put(*mm,data);
297  if ( const gsMaterialMatrixLinear<3,T> * mm =
298  dynamic_cast<const gsMaterialMatrixLinear<3,T> *>( obj ) )
299  return gsXml< gsMaterialMatrixLinear<3,T> >::put(*mm,data);
300 
301  // CompressibleNH2
302  if ( const gsMaterialMatrixNonlinear<2,T,11,true> * mm =
303  dynamic_cast<const gsMaterialMatrixNonlinear<2,T,11,true> *>( obj ) )
304  return gsXml< gsMaterialMatrixNonlinear<2,T,11,true> >::put(*mm,data);
305  // CompressibleNH3
306  if ( const gsMaterialMatrixNonlinear<3,T,11,true> * mm =
307  dynamic_cast<const gsMaterialMatrixNonlinear<3,T,11,true> *>( obj ) )
308  return gsXml< gsMaterialMatrixNonlinear<3,T,11,true> >::put(*mm,data);
309  // IncompressibleNH2
310  if ( const gsMaterialMatrixNonlinear<2,T,11,false> * mm =
311  dynamic_cast<const gsMaterialMatrixNonlinear<2,T,11,false> *>( obj ) )
312  return gsXml< gsMaterialMatrixNonlinear<2,T,11,false> >::put(*mm,data);
313  // IncompressibleNH3
314  if ( const gsMaterialMatrixNonlinear<3,T,11,false> * mm =
315  dynamic_cast<const gsMaterialMatrixNonlinear<3,T,11,false> *>( obj ) )
316  return gsXml< gsMaterialMatrixNonlinear<3,T,11,false> >::put(*mm,data);
317 
318  // CompressibleNHe2
319  if ( const gsMaterialMatrixNonlinear<2,T,12,true> * mm =
320  dynamic_cast<const gsMaterialMatrixNonlinear<2,T,12,true> *>( obj ) )
321  return gsXml< gsMaterialMatrixNonlinear<2,T,12,true> >::put(*mm,data);
322  // CompressibleNHe3
323  if ( const gsMaterialMatrixNonlinear<3,T,12,true> * mm =
324  dynamic_cast<const gsMaterialMatrixNonlinear<3,T,12,true> *>( obj ) )
325  return gsXml< gsMaterialMatrixNonlinear<3,T,12,true> >::put(*mm,data);
326  // IncompressibleNHe2
327  if ( const gsMaterialMatrixNonlinear<2,T,12,false> * mm =
328  dynamic_cast<const gsMaterialMatrixNonlinear<2,T,12,false> *>( obj ) )
329  return gsXml< gsMaterialMatrixNonlinear<2,T,12,false> >::put(*mm,data);
330  // IncompressibleNHe3
331  if ( const gsMaterialMatrixNonlinear<3,T,12,false> * mm =
332  dynamic_cast<const gsMaterialMatrixNonlinear<3,T,12,false> *>( obj ) )
333  return gsXml< gsMaterialMatrixNonlinear<3,T,12,false> >::put(*mm,data);
334 
335  // CompressibleMR2
336  if ( const gsMaterialMatrixNonlinear<2,T,13,true> * mm =
337  dynamic_cast<const gsMaterialMatrixNonlinear<2,T,13,true> *>( obj ) )
338  return gsXml< gsMaterialMatrixNonlinear<2,T,13,true> >::put(*mm,data);
339  // CompressibleMR3
340  if ( const gsMaterialMatrixNonlinear<3,T,13,true> * mm =
341  dynamic_cast<const gsMaterialMatrixNonlinear<3,T,13,true> *>( obj ) )
342  return gsXml< gsMaterialMatrixNonlinear<3,T,13,true> >::put(*mm,data);
343  // IncompressibleMR2
344  if ( const gsMaterialMatrixNonlinear<2,T,13,false> * mm =
345  dynamic_cast<const gsMaterialMatrixNonlinear<2,T,13,false> *>( obj ) )
346  return gsXml< gsMaterialMatrixNonlinear<2,T,13,false> >::put(*mm,data);
347  // IncompressibleMR3
348  if ( const gsMaterialMatrixNonlinear<3,T,13,false> * mm =
349  dynamic_cast<const gsMaterialMatrixNonlinear<3,T,13,false> *>( obj ) )
350  return gsXml< gsMaterialMatrixNonlinear<3,T,13,false> >::put(*mm,data);
351 
352  // CompressibleOG2
353  if ( const gsMaterialMatrixNonlinear<2,T,34,true> * mm =
354  dynamic_cast<const gsMaterialMatrixNonlinear<2,T,34,true> *>( obj ) )
355  return gsXml< gsMaterialMatrixNonlinear<2,T,34,true> >::put(*mm,data);
356  // CompressibleOG3
357  if ( const gsMaterialMatrixNonlinear<3,T,34,true> * mm =
358  dynamic_cast<const gsMaterialMatrixNonlinear<3,T,34,true> *>( obj ) )
359  return gsXml< gsMaterialMatrixNonlinear<3,T,34,true> >::put(*mm,data);
360  // IncompressibleOG2
361  if ( const gsMaterialMatrixNonlinear<2,T,34,false> * mm =
362  dynamic_cast<const gsMaterialMatrixNonlinear<2,T,34,false> *>( obj ) )
363  return gsXml< gsMaterialMatrixNonlinear<2,T,34,false> >::put(*mm,data);
364  // IncompressibleOG3
365  if ( const gsMaterialMatrixNonlinear<3,T,34,false> * mm =
366  dynamic_cast<const gsMaterialMatrixNonlinear<3,T,34,false> *>( obj ) )
367  return gsXml< gsMaterialMatrixNonlinear<3,T,34,false> >::put(*mm,data);
368 
369  gsWarn<<"gsMaterialMatrixBase: put<MaterialMatrixBase<T>>: No known MaterialMatrix "<< obj <<"Error.\n";
370  return NULL;
371  }
372 };
373 
374 }// end namespace internal
375 
376 } // end namespace
Provides linear material matrices.
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
#define gsWarn
Definition: gsDebug.h:50
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition: gsXml.cpp:37
Provides linear material matrices.
Provides hyperelastic material matrices.
Provides a base class for material matrices.