MFEM  v3.2
Finite element discretization library
 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.org.
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 
35  std::string name;
36  Mesh::TagType type;
37  size_t size;
38 
39  inline MfemTagDescription( std::string n,
40  Mesh::TagType t,
41  size_t s)
42  : name(n), type(t), size(s) {}
43 
44  inline MfemTagDescription( )
45  : type(Mesh::BYTE), size(0) {}
46 
47  inline bool operator==(const MfemTagDescription& o) const
48  { return name == o.name && type == o.type && size == o.size; }
49  inline bool operator!=(const MfemTagDescription& o) const
50  { return name != o.name || type != o.type || size != o.size; }
51  };
52 
60  class MeshTags
61  {
62  public:
63 
64  ~MeshTags() { clear(); }
65 
69  struct TagData
70  {
71 
73  const MfemTagDescription desc;
74 
76  void* elementData;
77 
79  size_t elementCount;
80 
82  void* vertexData;
83 
85  size_t vertexCount;
86 
88  void* defaultValue;
89 
96  inline TagData( const std::string& name,
97  Mesh::TagType type, unsigned length,
98  void* default_val = 0)
99  : desc(name, type, length*size_from_tag_type(type)),
100  elementData(0), elementCount(0),
101  vertexData(0), vertexCount(0),
102  defaultValue(default_val) {}
103 
107  inline TagData( const MfemTagDescription& descr )
108  : desc(descr), elementData(0), elementCount(0),
109  vertexData(0), vertexCount(0),
110  defaultValue(0) {}
111 
112  ~TagData();
113  };
114 
116  static size_t size_from_tag_type( Mesh::TagType type );
117 
119  void clear();
120 
122  size_t handle( const std::string& name, MsqError& err ) const;
123 
125  const MfemTagDescription& properties( size_t tag_handle, MsqError& err ) const;
126 
135  size_t create( const std::string& name,
136  Mesh::TagType type,
137  unsigned length,
138  const void* defval,
139  MsqError& err );
140 
145  size_t create( const MfemTagDescription& desc,
146  const void* defval,
147  MsqError& err );
148 
150  void destroy( size_t tag_index, MsqError& err );
151 
153  void set_element_data( size_t tag_handle,
154  size_t num_indices,
155  const size_t* elem_indices,
156  const void* tag_data,
157  MsqError& err );
158 
160  void set_vertex_data( size_t tag_handle,
161  size_t num_indices,
162  const size_t* elem_indices,
163  const void* tag_data,
164  MsqError& err );
165 
167  void get_element_data( size_t tag_handle,
168  size_t num_indices,
169  const size_t* elem_indices,
170  void* tag_data,
171  MsqError& err ) const;
172 
174  void get_vertex_data( size_t tag_handle,
175  size_t num_indices,
176  const size_t* elem_indices,
177  void* tag_data,
178  MsqError& err ) const;
179 
185  {
186  public:
187  TagIterator() : tags(0), index(0) {}
188  TagIterator( MeshTags* d, size_t i ) : tags(d), index(i) {}
189  size_t operator*() const { return index+1; }
190  TagIterator operator++();
191  TagIterator operator--();
192  TagIterator operator++(int);
193  TagIterator operator--(int);
194  bool operator==(TagIterator other) const { return index == other.index; }
195  bool operator!=(TagIterator other) const { return index != other.index; }
196  private:
197  MeshTags* tags;
198  size_t index;
199  };
200  TagIterator tag_begin();
201  TagIterator tag_end() { return TagIterator(this,tagList.size()); }
202 
204  bool tag_has_vertex_data( size_t index, MsqError& err ) ;
206  bool tag_has_element_data( size_t index, MsqError& err ) ;
207 
208  private:
209 
210  friend class MeshTags::TagIterator;
211 
212  std::vector<TagData*> tagList;
213  }; // class MeshTags
214 
215  // data members
216 private:
217  int ndofs; // number of nodes (or vertices) in mesh
218  int nelems; // number of elements in mesh
219  mfem::Mesh *mesh; // pointer to mfem mesh object
220  mfem::Element *elem; // pointer to mfem element object
221  mfem::GridFunction *nodes; // pointer to mfem grid function object
222  // for nodes
223  mfem::FiniteElementSpace *fes; // pointer to mfem finite element
224  // space object
225  mfem::Table *dof_elem; // dof to element table
226  std::vector<char> mByte; // length = ndofs
227  std::vector<bool> mFixed; // length = ndofs
228 
229  MeshTags* myTags;
230 
231 public:
232 
233  // The constructor
234  MesquiteMesh(mfem::Mesh *mfem_mesh);
235 
236  // The mesh dimension
237  int get_geometric_dimension(MsqError &err);
238 
239  // The handles are just pointers to the indexes of the nodes/elements
240  void get_all_elements(std::vector<ElementHandle>& elements,
241  MsqError& err );
242  void get_all_vertices(std::vector<VertexHandle>& vertices,
243  MsqError& err );
244 
245  // Get/set vertex coordinates
246  void vertices_get_coordinates(const VertexHandle vert_array[],
247  MsqVertex* coordinates,
248  size_t num_vtx,
249  MsqError &err );
250  void vertex_set_coordinates(VertexHandle vertex,
251  const Vector3D &coordinates,
252  MsqError &err );
253 
254  // These are internal markers for Mesquite that we should allocate for them
255  void vertex_set_byte(VertexHandle vertex,
256  unsigned char byte,
257  MsqError &err);
258  void vertices_set_byte(const VertexHandle *vert_array,
259  const unsigned char *byte_array,
260  size_t array_size,
261  MsqError &err );
262  void vertices_get_fixed_flag(const VertexHandle vert_array[],
263  std::vector<bool>& fixed_flag_array,
264  size_t num_vtx,
265  MsqError &err );
266  void vertices_set_fixed_flag(const VertexHandle vert_array[],
267  const std::vector< bool > &fixed_flag_array,
268  size_t num_vtx,
269  MsqError &err );
270  void vertex_get_byte( const VertexHandle vertex,
271  unsigned char *byte,
272  MsqError &err );
273  void vertices_get_byte( const VertexHandle *vertex,
274  unsigned char *byte_array,
275  size_t array_size,
276  MsqError &err );
277  // The dof_elem table
278  void vertices_get_attached_elements(const VertexHandle* vertex_array,
279  size_t num_vertex,
280  std::vector<ElementHandle>& elements,
281  std::vector<size_t>& offsets,
282  MsqError& err );
283  // The elem_dof table
284  void elements_get_attached_vertices(const ElementHandle *elem_handles,
285  size_t num_elems,
286  std::vector<VertexHandle>& vert_handles,
287  std::vector<size_t>& offsets,
288  MsqError &err);
289 
290  // The topology of the elements: tri/tet/quad/hex...
291  void elements_get_topologies(const ElementHandle *element_handle_array,
292  EntityTopology *element_topologies,
293  size_t num_elements,
294  MsqError &err);
295  // The destructor
296  ~MesquiteMesh();
297 
298  // tag the attributes on the elements from the underlying mfem mesh
299  void tag_attributes();
300 
301  // Clean these up .....
302  void vertices_get_slaved_flag( const VertexHandle vert_array[],
303  std::vector<bool>& slaved_flag_array,
304  size_t num_vtx,
305  MsqError &err ) {};
306 
307  TagHandle tag_create( const std::string& tag_name,
308  TagType type, unsigned length,
309  const void* default_value,
310  MsqError &err);
311 
312  void tag_delete( TagHandle handle, MsqError& err );
313 
314  TagHandle tag_get( const std::string& name,
315  MsqError& err );
316 
317  void tag_properties( TagHandle handle,
318  std::string& name_out,
319  TagType& type_out,
320  unsigned& length_out,
321  MsqError& err );
322 
323  void tag_set_element_data( TagHandle handle,
324  size_t num_elems,
325  const ElementHandle* elem_array,
326  const void* tag_data,
327  MsqError& err );
328 
329  void tag_set_vertex_data ( TagHandle handle,
330  size_t num_elems,
331  const VertexHandle* node_array,
332  const void* tag_data,
333  MsqError& err );
334 
335  void tag_get_element_data( TagHandle handle,
336  size_t num_elems,
337  const ElementHandle* elem_array,
338  void* tag_data,
339  MsqError& err );
340 
341  void tag_get_vertex_data ( TagHandle handle,
342  size_t num_elems,
343  const VertexHandle* node_array,
344  void* tag_data,
345  MsqError& err );
346 
347  void release_entity_handles(const EntityHandle *handle_array,
348  size_t num_handles,
349  MsqError &err) {};
350  void release() {};
351 };
352 
353 }
354 
355 #endif
356 
357 #endif
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:27
const MfemTagDescription desc
tag meta data
Definition: mesquite.hpp:73
TagData(const std::string &name, Mesh::TagType type, unsigned length, void *default_val=0)
Construct tag.
Definition: mesquite.hpp:96
void * vertexData
per-vertex data, or NULL if none has been set.
Definition: mesquite.hpp:82
size_t vertexCount
number of entries in vertexData
Definition: mesquite.hpp:85
bool operator==(TagIterator other) const
Definition: mesquite.hpp:194
void * defaultValue
Default value for tag.
Definition: mesquite.hpp:88
void * elementData
per-element data, or NULL if none has been set.
Definition: mesquite.hpp:76
size_t elementCount
number of entries in elementData
Definition: mesquite.hpp:79
bool operator!=(const Array< T > &LHS, const Array< T > &RHS)
Definition: array.hpp:240
bool operator==(const Array< T > &LHS, const Array< T > &RHS)
Definition: array.hpp:231
TagData(const MfemTagDescription &descr)
Construct tag.
Definition: mesquite.hpp:107
void vertices_get_slaved_flag(const VertexHandle vert_array[], std::vector< bool > &slaved_flag_array, size_t num_vtx, MsqError &err)
Definition: mesquite.hpp:302
bool operator!=(TagIterator other) const
Definition: mesquite.hpp:195
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:347