MFEM  v3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
mesquite.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.googlecode.com.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_MESQUITE
13 #define MFEM_MESQUITE
14 
15 #include "../config/config.hpp"
16 #include"mesh.hpp"
17 
18 #ifdef MFEM_USE_MESQUITE
19 
20 #include "Mesquite_all_headers.hpp"
21 
22 namespace mfem
23 {
24 
25 using namespace Mesquite;
26 
27 class MesquiteMesh : public Mesquite::Mesh
28 {
29  // tagging interface definition
30 private:
31 
32  struct MfemTagDescription {
33 
34  std::string name;
35  Mesh::TagType type;
36  size_t size;
37 
38  inline MfemTagDescription( std::string n,
39  Mesh::TagType t,
40  size_t s)
41  : name(n), type(t), size(s){}
42 
43  inline MfemTagDescription( )
44  : type(Mesh::BYTE), size(0) {}
45 
46  inline bool operator==(const MfemTagDescription& o) const
47  { return name == o.name && type == o.type && size == o.size; }
48  inline bool operator!=(const MfemTagDescription& o) const
49  { return name != o.name || type != o.type || size != o.size; }
50  };
51 
59  class MeshTags {
60  public:
61 
62  ~MeshTags() { clear(); }
63 
67  struct TagData {
68 
70  const MfemTagDescription desc;
71 
73  void* elementData;
74 
76  size_t elementCount;
77 
79  void* vertexData;
80 
82  size_t vertexCount;
83 
85  void* defaultValue;
86 
93  inline TagData( const std::string& name,
94  Mesh::TagType type, unsigned length,
95  void* default_val = 0)
96  : desc(name, type, length*size_from_tag_type(type)),
97  elementData(0), elementCount(0),
98  vertexData(0), vertexCount(0),
99  defaultValue(default_val) {}
100 
104  inline TagData( const MfemTagDescription& descr )
105  : desc(descr), elementData(0), elementCount(0),
106  vertexData(0), vertexCount(0),
107  defaultValue(0) {}
108 
109  ~TagData();
110  };
111 
113  static size_t size_from_tag_type( Mesh::TagType type );
114 
116  void clear();
117 
119  size_t handle( const std::string& name, MsqError& err ) const;
120 
122  const MfemTagDescription& properties( size_t tag_handle, MsqError& err ) const;
123 
132  size_t create( const std::string& name,
133  Mesh::TagType type,
134  unsigned length,
135  const void* defval,
136  MsqError& err );
137 
142  size_t create( const MfemTagDescription& desc,
143  const void* defval,
144  MsqError& err );
145 
147  void destroy( size_t tag_index, MsqError& err );
148 
150  void set_element_data( size_t tag_handle,
151  size_t num_indices,
152  const size_t* elem_indices,
153  const void* tag_data,
154  MsqError& err );
155 
157  void set_vertex_data( size_t tag_handle,
158  size_t num_indices,
159  const size_t* elem_indices,
160  const void* tag_data,
161  MsqError& err );
162 
164  void get_element_data( size_t tag_handle,
165  size_t num_indices,
166  const size_t* elem_indices,
167  void* tag_data,
168  MsqError& err ) const;
169 
171  void get_vertex_data( size_t tag_handle,
172  size_t num_indices,
173  const size_t* elem_indices,
174  void* tag_data,
175  MsqError& err ) const;
176 
182  {
183  public:
184  TagIterator() : tags(0), index(0) {}
185  TagIterator( MeshTags* d, size_t i ) : tags(d), index(i) {}
186  size_t operator*() const { return index+1; }
187  TagIterator operator++();
188  TagIterator operator--();
189  TagIterator operator++(int);
190  TagIterator operator--(int);
191  bool operator==(TagIterator other) const { return index == other.index; }
192  bool operator!=(TagIterator other) const { return index != other.index; }
193  private:
194  MeshTags* tags;
195  size_t index;
196  };
197  TagIterator tag_begin();
198  TagIterator tag_end() { return TagIterator(this,tagList.size()); }
199 
201  bool tag_has_vertex_data( size_t index, MsqError& err ) ;
203  bool tag_has_element_data( size_t index, MsqError& err ) ;
204 
205  private:
206 
207  friend class MeshTags::TagIterator;
208 
209  std::vector<TagData*> tagList;
210  }; // class MeshTags
211 
212  // data members
213 private:
214  int ndofs; // number of nodes (or vertices) in mesh
215  int nelems; // number of elements in mesh
216  mfem::Mesh *mesh; // pointer to mfem mesh object
217  mfem::Element *elem; // pointer to mfem element object
218  mfem::GridFunction *nodes; // pointer to mfem grid function object
219  // for nodes
220  mfem::FiniteElementSpace *fes; // pointer to mfem finite element
221  // space object
222  mfem::Table *dof_elem; // dof to element table
223  std::vector<char> mByte; // length = ndofs
224  std::vector<bool> mFixed; // length = ndofs
225 
226  MeshTags* myTags;
227 
228 public:
229 
230  // The constructor
231  MesquiteMesh(mfem::Mesh *mfem_mesh);
232 
233  // The mesh dimension
234  int get_geometric_dimension(MsqError &err);
235 
236  // The handles are just pointers to the indexes of the nodes/elements
237  void get_all_elements(std::vector<ElementHandle>& elements,
238  MsqError& err );
239  void get_all_vertices(std::vector<VertexHandle>& vertices,
240  MsqError& err );
241 
242  // Get/set vertex coordinates
243  void vertices_get_coordinates(const VertexHandle vert_array[],
244  MsqVertex* coordinates,
245  size_t num_vtx,
246  MsqError &err );
247  void vertex_set_coordinates(VertexHandle vertex,
248  const Vector3D &coordinates,
249  MsqError &err );
250 
251  // These are internal markers for Mesquite that we should allocate for them
252  void vertex_set_byte(VertexHandle vertex,
253  unsigned char byte,
254  MsqError &err);
255  void vertices_set_byte(const VertexHandle *vert_array,
256  const unsigned char *byte_array,
257  size_t array_size,
258  MsqError &err );
259  void vertices_get_fixed_flag(const VertexHandle vert_array[],
260  std::vector<bool>& fixed_flag_array,
261  size_t num_vtx,
262  MsqError &err );
263  void vertices_set_fixed_flag(const VertexHandle vert_array[],
264  const std::vector< bool > &fixed_flag_array,
265  size_t num_vtx,
266  MsqError &err );
267  void vertex_get_byte( const VertexHandle vertex,
268  unsigned char *byte,
269  MsqError &err );
270  void vertices_get_byte( const VertexHandle *vertex,
271  unsigned char *byte_array,
272  size_t array_size,
273  MsqError &err );
274  // The dof_elem table
275  void vertices_get_attached_elements(const VertexHandle* vertex_array,
276  size_t num_vertex,
277  std::vector<ElementHandle>& elements,
278  std::vector<size_t>& offsets,
279  MsqError& err );
280  // The elem_dof table
281  void elements_get_attached_vertices(const ElementHandle *elem_handles,
282  size_t num_elems,
283  std::vector<VertexHandle>& vert_handles,
284  std::vector<size_t>& offsets,
285  MsqError &err);
286 
287  // The topology of the elements: tri/tet/quad/hex...
288  void elements_get_topologies(const ElementHandle *element_handle_array,
289  EntityTopology *element_topologies,
290  size_t num_elements,
291  MsqError &err);
292  // The destructor
293  ~MesquiteMesh();
294 
295  // tag the attributes on the elements from the underlying mfem mesh
296  void tag_attributes();
297 
298  // Clean these up .....
299  void vertices_get_slaved_flag( const VertexHandle vert_array[],
300  std::vector<bool>& slaved_flag_array,
301  size_t num_vtx,
302  MsqError &err ){};
303 
304  TagHandle tag_create( const std::string& tag_name,
305  TagType type, unsigned length,
306  const void* default_value,
307  MsqError &err);
308 
309  void tag_delete( TagHandle handle, MsqError& err );
310 
311  TagHandle tag_get( const std::string& name,
312  MsqError& err );
313 
314  void tag_properties( TagHandle handle,
315  std::string& name_out,
316  TagType& type_out,
317  unsigned& length_out,
318  MsqError& err );
319 
320  void tag_set_element_data( TagHandle handle,
321  size_t num_elems,
322  const ElementHandle* elem_array,
323  const void* tag_data,
324  MsqError& err );
325 
326  void tag_set_vertex_data ( TagHandle handle,
327  size_t num_elems,
328  const VertexHandle* node_array,
329  const void* tag_data,
330  MsqError& err );
331 
332  void tag_get_element_data( TagHandle handle,
333  size_t num_elems,
334  const ElementHandle* elem_array,
335  void* tag_data,
336  MsqError& err );
337 
338  void tag_get_vertex_data ( TagHandle handle,
339  size_t num_elems,
340  const VertexHandle* node_array,
341  void* tag_data,
342  MsqError& err );
343 
344  void release_entity_handles(const EntityHandle *handle_array,
345  size_t num_handles,
346  MsqError &err){};
347  void release(){};
348 };
349 
350 }
351 
352 #endif
353 
354 #endif
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:26
const MfemTagDescription desc
tag meta data
Definition: mesquite.hpp:70
TagData(const std::string &name, Mesh::TagType type, unsigned length, void *default_val=0)
Construct tag.
Definition: mesquite.hpp:93
void * vertexData
per-vertex data, or NULL if none has been set.
Definition: mesquite.hpp:79
size_t vertexCount
number of entries in vertexData
Definition: mesquite.hpp:82
bool operator==(TagIterator other) const
Definition: mesquite.hpp:191
void * defaultValue
Default value for tag.
Definition: mesquite.hpp:85
void * elementData
per-element data, or NULL if none has been set.
Definition: mesquite.hpp:73
size_t elementCount
number of entries in elementData
Definition: mesquite.hpp:76
Abstract finite element space.
Definition: fespace.hpp:61
TagData(const MfemTagDescription &descr)
Construct tag.
Definition: mesquite.hpp:104
void vertices_get_slaved_flag(const VertexHandle vert_array[], std::vector< bool > &slaved_flag_array, size_t num_vtx, MsqError &err)
Definition: mesquite.hpp:299
bool operator!=(TagIterator other) const
Definition: mesquite.hpp:192
Abstract data type element.
Definition: element.hpp:27
void release_entity_handles(const EntityHandle *handle_array, size_t num_handles, MsqError &err)
Definition: mesquite.hpp:344