G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsMaterialMatrixXml.hpp
Go to the documentation of this file.
1
14#pragma once
15
16#include <fstream>
19
25
26
27namespace gismo {
28
29namespace internal {
30
32template<class T>
33class gsXml< gsMaterialMatrixBase<T> >
34{
35private:
36 gsXml() { }
37 typedef gsMaterialMatrixBase<T> Object;
38
39public:
40 GSXML_COMMON_FUNCTIONS(Object);
41 static std::string tag () { return "MaterialMatrix"; }
42 static std::string type () { return ""; }
43
44 // GSXML_GET_INTO(Object)
45
46 static void get_into(gsXmlNode * node, Object & obj)
47 {
48 obj = *get(node);
49 // obj = *tmp;
50 }
51
52 static Object * get(gsXmlNode * node)
53 {
54 GISMO_ASSERT( ( !strcmp( node->name(),"MaterialMatrix") ),
55 "Something went wrong, was waiting for a MaterialMatrix tag.\n" );
56
57 gsXmlAttribute * gtype = node->first_attribute("type");
58 if ( ! gtype )
59 {
60 gsWarn<< "MaterialMatrix without a type in the xml file\n";
61 return NULL;
62 }
63
64 const gsXmlAttribute * att_TFT = node->first_attribute("TFT");
65 bool TFT = false;
66 if (NULL != att_TFT)
67 {
68 if ((strcmp("1", att_TFT->value()) == 0) ||
69 (strcmp("true", att_TFT->value()) == 0) ||
70 (strcmp("True", att_TFT->value()) == 0) )
71 TFT = true;
72 }
73
74 std::string s = gtype->value() ;
75 Object * tmp = get_impl(node);
76 if (TFT)
77 {
78 if ( ( s == "Linear2" ) )
79 return new gsMaterialMatrixTFT<2,T,true>(tmp);
80 else if ( ( s == "Linear3" ) )
81 return new gsMaterialMatrixTFT<3,T,true>(tmp);
82 else if ( ( s == "CompressibleNH2" ) ||
83 ( s == "IncompressibleNH2" ) ||
84 ( s == "CompressibleNHe2" ) ||
85 // ( s == "IncompressibleNHe2" ) ||
86 ( s == "CompressibleMR2" ) ||
87 ( s == "IncompressibleMR2" ) ||
88 ( s == "CompressibleOG2" ) ||
89 ( s == "IncompressibleOG2" ) )
90 return new gsMaterialMatrixTFT<2,T,false>(tmp);
91 else if ( ( s == "CompressibleNH3" ) ||
92 ( s == "IncompressibleNH3" ) ||
93 ( s == "CompressibleNHe3" ) ||
94 // ( s == "IncompressibleNHe3" ) ||
95 ( s == "CompressibleMR3" ) ||
96 ( s == "IncompressibleMR3" ) ||
97 ( s == "CompressibleOG3" ) ||
98 ( s == "IncompressibleOG3" ) )
99 return new gsMaterialMatrixTFT<3,T,false>(tmp);
100 else
101 {
102 gsWarn<<"Material matrix for TFT model not recognised\n";
103 return NULL;
104 }
105 }
106 else
107 return tmp;
108 }
109
110 static Object * get_impl(gsXmlNode * node)
111 {
112 GISMO_ASSERT( ( !strcmp( node->name(),"MaterialMatrix") ),
113 "Something went wrong, was waiting for a MaterialMatrix tag.\n" );
114
115 gsXmlAttribute * gtype = node->first_attribute("type");
116 if ( ! gtype )
117 {
118 gsWarn<< "MaterialMatrix without a type in the xml file\n";
119 return NULL;
120 }
121
122 std::string s = gtype->value() ;
123 if ( s == "Linear2" )
124 return gsXml< gsMaterialMatrixLinear<2,T> >::get(node);
125 if ( s == "Linear3" )
126 return gsXml< gsMaterialMatrixLinear<3,T> >::get(node);
127
128 if ( s == "CompressibleNH2" )
129 return gsXml< gsMaterialMatrixNonlinear<2,T,11,true> >::get(node);
130 if ( s == "CompressibleNH3" )
131 return gsXml< gsMaterialMatrixNonlinear<3,T,11,true> >::get(node);
132 if ( s == "IncompressibleNH2" )
133 return gsXml< gsMaterialMatrixNonlinear<2,T,11,false> >::get(node);
134 if ( s == "IncompressibleNH3" )
135 return gsXml< gsMaterialMatrixNonlinear<3,T,11,false> >::get(node);
136
137 if ( s == "CompressibleNHe2" )
138 return gsXml< gsMaterialMatrixNonlinear<2,T,12,true> >::get(node);
139 if ( s == "CompressibleNHe3" )
140 return gsXml< gsMaterialMatrixNonlinear<3,T,12,true> >::get(node);
141 // if ( s == "IncompressibleNHe2" )
142 // return gsXml< gsMaterialMatrixNonlinear<2,T,12,false> >::get(node);
143 // if ( s == "IncompressibleNHe3" )
144 // return gsXml< gsMaterialMatrixNonlinear<3,T,12,false> >::get(node);
145
146 if ( s == "CompressibleMR2" )
147 return gsXml< gsMaterialMatrixNonlinear<2,T,13,true> >::get(node);
148 if ( s == "CompressibleMR3" )
149 return gsXml< gsMaterialMatrixNonlinear<3,T,13,true> >::get(node);
150 if ( s == "IncompressibleMR2" )
151 return gsXml< gsMaterialMatrixNonlinear<2,T,13,false> >::get(node);
152 if ( s == "IncompressibleMR3" )
153 return gsXml< gsMaterialMatrixNonlinear<3,T,13,false> >::get(node);
154
155 if ( s == "CompressibleOG2" )
156 return gsXml< gsMaterialMatrixNonlinear<2,T,34,true> >::get(node);
157 if ( s == "CompressibleOG3" )
158 return gsXml< gsMaterialMatrixNonlinear<3,T,34,true> >::get(node);
159 if ( s == "IncompressibleOG2" )
160 return gsXml< gsMaterialMatrixNonlinear<2,T,34,false> >::get(node);
161 if ( s == "IncompressibleOG3" )
162 return gsXml< gsMaterialMatrixNonlinear<3,T,34,false> >::get(node);
163
164 gsWarn<<"gsMaterialMatrixBase: get<MaterialMatrixBase<T>>: No known MaterialMatrix \""<<s<<"\". Error.\n";
165 return NULL;
166 }
167
168 static gsXmlNode * put (const Object & obj,
169 gsXmlTree & data)
170 {
171 const Object * ptr = & obj;
172 if (dynamic_cast<const gsMaterialMatrixTFT<2,T,true> *>( ptr )
173 ||
174 dynamic_cast<const gsMaterialMatrixTFT<3,T,true> *>( ptr )
175 ||
176 dynamic_cast<const gsMaterialMatrixTFT<2,T,false> *>( ptr )
177 ||
178 dynamic_cast<const gsMaterialMatrixTFT<3,T,false> *>( ptr )
179 )
180 {
181 gsXmlNode * tmp = put_impl(ptr->material(),data);
182 tmp->append_attribute(internal::makeAttribute("TFT","true",data));
183 return tmp;
184 }
185 else
186 return put_impl(ptr,data);
187 }
188
189 static gsXmlNode * put_impl (const Object * obj,
190 gsXmlTree & data)
191 {
192 if ( const gsMaterialMatrixLinear<2,T> * mm =
193 dynamic_cast<const gsMaterialMatrixLinear<2,T> *>( obj ) )
194 return gsXml< gsMaterialMatrixLinear<2,T> >::put(*mm,data);
195 if ( const gsMaterialMatrixLinear<3,T> * mm =
196 dynamic_cast<const gsMaterialMatrixLinear<3,T> *>( obj ) )
197 return gsXml< gsMaterialMatrixLinear<3,T> >::put(*mm,data);
198
199 // CompressibleNH2
200 if ( const gsMaterialMatrixNonlinear<2,T,11,true> * mm =
201 dynamic_cast<const gsMaterialMatrixNonlinear<2,T,11,true> *>( obj ) )
202 return gsXml< gsMaterialMatrixNonlinear<2,T,11,true> >::put(*mm,data);
203 // CompressibleNH3
204 if ( const gsMaterialMatrixNonlinear<3,T,11,true> * mm =
205 dynamic_cast<const gsMaterialMatrixNonlinear<3,T,11,true> *>( obj ) )
206 return gsXml< gsMaterialMatrixNonlinear<3,T,11,true> >::put(*mm,data);
207 // IncompressibleNH2
208 if ( const gsMaterialMatrixNonlinear<2,T,11,false> * mm =
209 dynamic_cast<const gsMaterialMatrixNonlinear<2,T,11,false> *>( obj ) )
210 return gsXml< gsMaterialMatrixNonlinear<2,T,11,false> >::put(*mm,data);
211 // IncompressibleNH3
212 if ( const gsMaterialMatrixNonlinear<3,T,11,false> * mm =
213 dynamic_cast<const gsMaterialMatrixNonlinear<3,T,11,false> *>( obj ) )
214 return gsXml< gsMaterialMatrixNonlinear<3,T,11,false> >::put(*mm,data);
215
216 // CompressibleNHe2
217 if ( const gsMaterialMatrixNonlinear<2,T,12,true> * mm =
218 dynamic_cast<const gsMaterialMatrixNonlinear<2,T,12,true> *>( obj ) )
219 return gsXml< gsMaterialMatrixNonlinear<2,T,12,true> >::put(*mm,data);
220 // CompressibleNHe3
221 if ( const gsMaterialMatrixNonlinear<3,T,12,true> * mm =
222 dynamic_cast<const gsMaterialMatrixNonlinear<3,T,12,true> *>( obj ) )
223 return gsXml< gsMaterialMatrixNonlinear<3,T,12,true> >::put(*mm,data);
224 // // IncompressibleNHe2
225 // if ( const gsMaterialMatrixNonlinear<2,T,12,false> * mm =
226 // dynamic_cast<const gsMaterialMatrixNonlinear<2,T,12,false> *>( obj ) )
227 // return gsXml< gsMaterialMatrixNonlinear<2,T,12,false> >::put(*mm,data);
228 // // IncompressibleNHe3
229 // if ( const gsMaterialMatrixNonlinear<3,T,12,false> * mm =
230 // dynamic_cast<const gsMaterialMatrixNonlinear<3,T,12,false> *>( obj ) )
231 // return gsXml< gsMaterialMatrixNonlinear<3,T,12,false> >::put(*mm,data);
232
233 // CompressibleMR2
234 if ( const gsMaterialMatrixNonlinear<2,T,13,true> * mm =
235 dynamic_cast<const gsMaterialMatrixNonlinear<2,T,13,true> *>( obj ) )
236 return gsXml< gsMaterialMatrixNonlinear<2,T,13,true> >::put(*mm,data);
237 // CompressibleMR3
238 if ( const gsMaterialMatrixNonlinear<3,T,13,true> * mm =
239 dynamic_cast<const gsMaterialMatrixNonlinear<3,T,13,true> *>( obj ) )
240 return gsXml< gsMaterialMatrixNonlinear<3,T,13,true> >::put(*mm,data);
241 // IncompressibleMR2
242 if ( const gsMaterialMatrixNonlinear<2,T,13,false> * mm =
243 dynamic_cast<const gsMaterialMatrixNonlinear<2,T,13,false> *>( obj ) )
244 return gsXml< gsMaterialMatrixNonlinear<2,T,13,false> >::put(*mm,data);
245 // IncompressibleMR3
246 if ( const gsMaterialMatrixNonlinear<3,T,13,false> * mm =
247 dynamic_cast<const gsMaterialMatrixNonlinear<3,T,13,false> *>( obj ) )
248 return gsXml< gsMaterialMatrixNonlinear<3,T,13,false> >::put(*mm,data);
249
250 // CompressibleOG2
251 if ( const gsMaterialMatrixNonlinear<2,T,34,true> * mm =
252 dynamic_cast<const gsMaterialMatrixNonlinear<2,T,34,true> *>( obj ) )
253 return gsXml< gsMaterialMatrixNonlinear<2,T,34,true> >::put(*mm,data);
254 // CompressibleOG3
255 if ( const gsMaterialMatrixNonlinear<3,T,34,true> * mm =
256 dynamic_cast<const gsMaterialMatrixNonlinear<3,T,34,true> *>( obj ) )
257 return gsXml< gsMaterialMatrixNonlinear<3,T,34,true> >::put(*mm,data);
258 // IncompressibleOG2
259 if ( const gsMaterialMatrixNonlinear<2,T,34,false> * mm =
260 dynamic_cast<const gsMaterialMatrixNonlinear<2,T,34,false> *>( obj ) )
261 return gsXml< gsMaterialMatrixNonlinear<2,T,34,false> >::put(*mm,data);
262 // IncompressibleOG3
263 if ( const gsMaterialMatrixNonlinear<3,T,34,false> * mm =
264 dynamic_cast<const gsMaterialMatrixNonlinear<3,T,34,false> *>( obj ) )
265 return gsXml< gsMaterialMatrixNonlinear<3,T,34,false> >::put(*mm,data);
266
267 gsWarn<<"gsMaterialMatrixBase: put<MaterialMatrixBase<T>>: No known MaterialMatrix "<< obj <<"Error.\n";
268 return NULL;
269 }
270};
271
272template<class Object>
273Object getMaterialMatrixFromXml ( gsXmlNode * node)
274{
275 typedef typename Object::Scalar_t T;
276
277 //gsWarn<<"Reading "<< gsXml<Object>::type() <<" Geometry..\n";
278 assert ( ( !strcmp( node->name(),"MaterialMatrix") ) &&
279 ( !strcmp(node->first_attribute("type")->value(), gsXml<Object>::type().c_str() ) ) );
280
281 Object result = Object();
282
283 gsXmlNode * tmp;
284
285 tmp = node->first_node("Thickness");
286 GISMO_ASSERT(tmp,"Thickness must be assigned!");
287 gsFunctionExpr<T> thickness;
288 gsXml<gsFunctionExpr<T> >::get_into(tmp->first_node("Function"), thickness);
289 result.setThickness(thickness);
290
291 tmp = node->first_node("Density");
292 gsFunctionExpr<T> density;
293 bool hasDensity = tmp;
294 if ( hasDensity )
295 {
296 gsXml<gsFunctionExpr<T> >::get_into(tmp->first_node("Function"), density);
297 result.setDensity(density);
298 }
299
300 gsXmlNode * parNode = node->first_node("Parameters");
301 // Read function inventory
302 gsFunctionExpr<T> fun;
303 for (gsXmlNode * child = parNode->first_node("Function"); child; child =
304 child->next_sibling("Function"))
305 {
306 const int i = atoi(child->first_attribute("index")->value());
307 gsXml<gsFunctionExpr<T> >::get_into(child, fun);
308 result.setParameter(i,fun);
309 }
310 return result;
311}
312
313template<class Object>
314gsXmlNode * putMaterialMatrixToXml ( Object const & obj, gsXmlTree & data)
315{
316
317 typedef typename Object::Scalar_t T;
318
319 // Make a new XML Geometry node
320 gsXmlNode * mm = internal::makeNode("MaterialMatrix", data);
321 mm->append_attribute( makeAttribute("type",
322 internal::gsXml<Object>::type().c_str(), data) );
323
324 GISMO_ASSERT(obj.hasThickness(),"Thickness is not assigned");
325 gsXmlNode * t = internal::makeNode("Thickness", data);
326 gsXmlNode * tfun = putFunctionToXml<T>(obj.getThickness(), data, 0);
327 t->append_node(tfun);
328 mm->append_node(t);
329 if (obj.hasDensity())
330 {
331 gsXmlNode * r = internal::makeNode("Density", data);
332 gsXmlNode * rfun = putFunctionToXml<T>(obj.getDensity(), data, 0);
333 r->append_node(rfun);
334 mm->append_node(r);
335 }
336
337 gsXmlNode * p = internal::makeNode("Parameters", data);
338 for (index_t k=0; k!=obj.numParameters(); k++)
339 {
340 gsXmlNode * pfun = putFunctionToXml<T>(obj.getParameter(k), data, k);
341 p->append_node(pfun);
342 }
343 mm->append_node(p);
344
345 return mm;
346}
347
348}// end namespace internal
349
350}// end namespace gismo
351
352//#undef GSXML_COMMON_FUNCTIONS
353//#undef TMPLA2
354//#undef TMPLA3
#define index_t
Definition gsConfig.h:32
#define gsWarn
Definition gsDebug.h:50
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides declaration of FunctionExpr class.
Provides a base class for material matrices.
Provides a container for material matrices for thin shells.
Provides linear material matrices.
Provides hyperelastic material matrices.
Provides linear material matrices.
Provides implementation of generic XML functions.
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition gsXml.cpp:54
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition gsXml.cpp:37
The G+Smo namespace, containing all definitions for the library.