G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMaterialMatrixContainer.h
Go to the documentation of this file.
1 
16 #pragma once
17 
19 
20 namespace gismo
21 {
22 
23 
32 template <class T>
33 class gsMaterialMatrixContainer // change name to PtrContainer
34 {
35 public:
36  typedef typename std::vector<typename gsMaterialMatrixBase<T>::Ptr> Container;
37 
38  typedef typename Container::iterator iterator;
39  typedef typename Container::const_iterator const_iterator;
40 
42  typedef memory::shared_ptr< gsMaterialMatrixContainer > Ptr;
43 
45  typedef memory::unique_ptr< gsMaterialMatrixContainer > uPtr;
46 public:
47 
50  {
51  m_container.resize(size);
52  // To do: initialize with null pointers
53  }
54 
56  {
57  // for (index_t k=0; k!=other.m_container.size(); k++)
58  // add(memory::make_unique(other.m_container.at(k)));
59  m_container = give(other.m_container);
60  }
61 
63  {
64  // freeAll(m_container);
65  }
66 
68  void add(const gsMaterialMatrixBase<T> & mat)
69  {
70  m_container.push_back( memory::make_shared(mat.clone().release()) );
71  }
72 
74  void add(const gsMaterialMatrixBase<T> * mat)
75  {
76  m_container.push_back( memory::make_shared_not_owned(mat) );
77  }
78 
80  void set(const index_t i, const gsMaterialMatrixBase<T> & mat)
81  {
82  m_container[i] = memory::make_shared(mat.clone().release());
83  }
84 
86  void set(const index_t i, const gsMaterialMatrixBase<T> * mat)
87  {
88  m_container[i] = memory::make_shared_not_owned(mat);
89  }
90 
92  void set(const index_t i, const typename gsMaterialMatrixBase<T>::Ptr mat)
93  {
94  m_container[i] = mat;
95  }
96 
97  gsMaterialMatrixBase<T> * piece(const index_t k) const
98  {
99  return m_container.at(k).get();
100  }
101 
102  index_t size() const {return m_container.size();}
103 
104  std::ostream &print(std::ostream &os) const
105  {
106  os << "Piecewise Function with "<<m_container.size() <<" pieces.\n";
107  return os;
108  }
109 
110  friend std::ostream & operator<<(std::ostream & os, const gsMaterialMatrixContainer & pwf)
111  {
112  return pwf.print(os);
113  }
114 
116  void clear()
117  {
118  m_container.clear();
119  }
120 
121 protected:
122  Container m_container;
123 
124 };
125 
126 namespace internal
127 {
128 
132 template<class T>
133 class gsXml< gsMaterialMatrixContainer<T> >
134 {
135 private:
136  gsXml() { }
137  typedef gsMaterialMatrixContainer<T> Object;
138 
139 public:
140  GSXML_COMMON_FUNCTIONS(gsMaterialMatrixContainer<T>);
141  static std::string tag () { return "MaterialMatrixContainer"; }
142  static std::string type () { return ""; }
143 
144  GSXML_GET_POINTER(Object);
145 
146  static void get_into(gsXmlNode * node,Object & obj)
147  {
148  const int size = atoi(node->first_attribute("size")->value());
149 
150  // Read material inventory
151  int count = countByTag("MaterialMatrix", node);
152  std::vector<typename gsMaterialMatrixBase<T>::Ptr> mat(count);
153  for (gsXmlNode * child = node->first_node("MaterialMatrix"); child; child =
154  child->next_sibling("MaterialMatrix"))
155  {
156  const int i = atoi(child->first_attribute("index")->value());
157  mat[i] = memory::make_shared(gsXml<gsMaterialMatrixBase<T>>::get(child));
158  }
159 
160  obj = gsMaterialMatrixContainer<T>(size);
161  for (gsXmlNode * child = node->first_node("group"); child;
162  child = child->next_sibling("group"))
163  {
164  const int mIndex = atoi(child->first_attribute("material")->value());
165  std::istringstream group_str;
166  group_str.str( child->value() );
167 
168  for(int patch; ( gsGetInt(group_str,patch)); )
169  obj.set(patch,mat[mIndex]);
170  }
171 
172  }
173 
174  static gsXmlNode * put (const Object & obj,
175  gsXmlTree & data)
176  {
177  GISMO_ERROR("Writing gsMaterialMatrixContainer to Xml is not implemented");
178  // gsWarn<<"Writing gsMaterialMatrixContainer to Xml is not implemented\n";
179  // gsXmlNode * result;
180  // return result;
181  // return putMaterialMatrixToXml< Object >( obj,data );
182  }
183 };
184 
185 } // namespace internal
186 
187 } // namespace gismo
memory::shared_ptr< gsMaterialMatrixContainer > Ptr
Shared pointer for gsMaterialMatrixContainer.
Definition: gsMaterialMatrixContainer.h:42
shared_ptr< T > make_shared_not_owned(const T *x)
Creates a shared pointer which does not eventually delete the underlying raw pointer. Usefull to refer to objects which should not be destroyed.
Definition: gsMemory.h:189
gsMaterialMatrixContainer(index_t size=0)
Constructor.
Definition: gsMaterialMatrixContainer.h:49
int countByTag(const std::string &tag, gsXmlNode *root)
Definition: gsXml.cpp:81
void set(const index_t i, const gsMaterialMatrixBase< T > &mat)
Set a material matrix by copying argument.
Definition: gsMaterialMatrixContainer.h:80
This class serves as the evaluator of material matrices, based on gsMaterialMatrixBase.
Definition: gsMaterialMatrixContainer.h:33
S give(S &x)
Definition: gsMemory.h:266
#define index_t
Definition: gsConfig.h:32
This class defines the base class for material matrices.
Definition: gsMaterialMatrixBase.h:32
void add(const gsMaterialMatrixBase< T > &mat)
Add a material matrix by copying argument.
Definition: gsMaterialMatrixContainer.h:68
void set(const index_t i, const gsMaterialMatrixBase< T > *mat)
Set a material matrix from a gsMaterialMatrixBase&lt;T&gt;::uPtr.
Definition: gsMaterialMatrixContainer.h:86
memory::unique_ptr< gsMaterialMatrixContainer > uPtr
Unique pointer for gsMaterialMatrixContainer.
Definition: gsMaterialMatrixContainer.h:45
void clear()
Clear all function pointers.
Definition: gsMaterialMatrixContainer.h:116
void set(const index_t i, const typename gsMaterialMatrixBase< T >::Ptr mat)
Set a material matrix from a gsMaterialMatrixBase&lt;T&gt;::uPtr.
Definition: gsMaterialMatrixContainer.h:92
Provides a base class for material matrices.
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
memory::shared_ptr< gsMaterialMatrixBase > Ptr
Shared pointer for gsGeometry.
Definition: gsMaterialMatrixBase.h:41
void add(const gsMaterialMatrixBase< T > *mat)
Add a material matrix from a gsMaterialMatrixBase&lt;T&gt;::uPtr.
Definition: gsMaterialMatrixContainer.h:74
shared_ptr< T > make_shared(T *x)
Definition: gsMemory.h:181