G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMaterialMatrixXml.hpp
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <fstream>
17 #include <gsCore/gsFunctionExpr.h>
19 
20 namespace gismo {
21 
22 namespace internal {
23 
24 template<class Object>
25 Object getMaterialMatrixFromXml ( gsXmlNode * node)
26 {
27  typedef typename Object::Scalar_t T;
28 
29  //gsWarn<<"Reading "<< gsXml<Object>::type() <<" Geometry..\n";
30  assert ( ( !strcmp( node->name(),"MaterialMatrix") ) &&
31  ( !strcmp(node->first_attribute("type")->value(), gsXml<Object>::type().c_str() ) ) );
32 
33  Object result = Object();
34 
35  gsXmlNode * tmp;
36 
37  tmp = node->first_node("Thickness");
38  GISMO_ASSERT(tmp,"Thickness must be assigned!");
39  gsFunctionExpr<T> thickness;
40  gsXml<gsFunctionExpr<T> >::get_into(tmp->first_node("Function"), thickness);
41  result.setThickness(thickness);
42 
43  tmp = node->first_node("Density");
44  gsFunctionExpr<T> density;
45  bool hasDensity = tmp;
46  if ( hasDensity )
47  {
48  gsXml<gsFunctionExpr<T> >::get_into(tmp->first_node("Function"), density);
49  result.setDensity(density);
50  }
51 
52  gsXmlNode * parNode = node->first_node("Parameters");
53  // Read function inventory
54  gsFunctionExpr<T> fun;
55  for (gsXmlNode * child = parNode->first_node("Function"); child; child =
56  child->next_sibling("Function"))
57  {
58  const int i = atoi(child->first_attribute("index")->value());
59  gsXml<gsFunctionExpr<T> >::get_into(child, fun);
60  result.setParameter(i,fun);
61  }
62  return result;
63 }
64 
65 template<class Object>
66 gsXmlNode * putMaterialMatrixToXml ( Object const & obj, gsXmlTree & data)
67 {
68 
69  typedef typename Object::Scalar_t T;
70 
71  // Make a new XML Geometry node
72  gsXmlNode * mm = internal::makeNode("MaterialMatrix", data);
73  mm->append_attribute( makeAttribute("type",
74  internal::gsXml<Object>::type().c_str(), data) );
75 
76  GISMO_ASSERT(obj.hasThickness(),"Thickness is not assigned");
77  gsXmlNode * t = internal::makeNode("Thickness", data);
78  gsXmlNode * tfun = putFunctionToXml<T>(obj.getThickness(), data, 0);
79  t->append_node(tfun);
80  mm->append_node(t);
81  if (obj.hasDensity())
82  {
83  gsXmlNode * r = internal::makeNode("Density", data);
84  gsXmlNode * rfun = putFunctionToXml<T>(obj.getDensity(), data, 0);
85  r->append_node(rfun);
86  mm->append_node(r);
87  }
88 
89  gsXmlNode * p = internal::makeNode("Parameters", data);
90  for (index_t k=0; k!=obj.numParameters(); k++)
91  {
92  gsXmlNode * pfun = putFunctionToXml<T>(obj.getParameter(k), data, k);
93  p->append_node(pfun);
94  }
95  mm->append_node(p);
96 
97  return mm;
98 }
99 
100 }// end namespace internal
101 
102 }// end namespace gismo
103 
104 //#undef GSXML_COMMON_FUNCTIONS
105 //#undef TMPLA2
106 //#undef TMPLA3
Provides declaration of FunctionExpr class.
#define index_t
Definition: gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Provides implementation of generic XML functions.
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition: gsXml.cpp:37
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition: gsXml.cpp:54