MFEM  v4.2.0
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-2020, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_MESQUITE
13 #define MFEM_MESQUITE
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_MESQUITE
18 
19 #include "mesh.hpp"
20 
21 #include "Mesquite_all_headers.hpp"
22 
23 namespace mfem
24 {
25 
26 using namespace Mesquite;
27 
28 class MesquiteMesh : public Mesquite::Mesh
29 {
30  // tagging interface definition
31 private:
32 
33  struct MfemTagDescription
34  {
35 
36  std::string name; //!< Tag name
37  Mesh::TagType type; //!< Tag data type
38  size_t size; //!< Size of tag data (sizeof(type)*array_length)
39 
40  inline MfemTagDescription( std::string n,
41  Mesh::TagType t,
42  size_t s)
43  : name(n), type(t), size(s) {}
44 
45  inline MfemTagDescription( )
46  : type(Mesh::BYTE), size(0) {}
47 
48  inline bool operator==(const MfemTagDescription& o) const
49  { return name == o.name && type == o.type && size == o.size; }
50  inline bool operator!=(const MfemTagDescription& o) const
51  { return name != o.name || type != o.type || size != o.size; }
52  };
53 
54  /**\class MeshTags
55  *
56  * Store tags and tag data for MFEM's mesh representation.
57  * Stores for each tag: properties, element data, and vertex data.
58  * The tag element and vertex data sets are maps between some element
59  * or vertex index and a tag value.
60  */
61  class MeshTags
62  {
63  public:
64 
65  ~MeshTags() { clear(); }
66 
67  /** \class TagData
68  * Store data for a single tag
69  */
70  struct TagData
71  {
72 
73  //! tag meta data
74  const MfemTagDescription desc;
75 
76  //! per-element data, or NULL if none has been set.
77  void* elementData;
78 
79  //! number of entries in elementData
80  size_t elementCount;
81 
82  //! per-vertex data, or NULL if none has been set.
83  void* vertexData;
84 
85  //! number of entries in vertexData
86  size_t vertexCount;
87 
88  //! Default value for tag
89  void* defaultValue;
90 
91  /** \brief Construct tag
92  *\param name Tag name
93  *\param type Tag data type
94  *\param length Tag array length (1 for scalar/non-array)
95  *\param default_val Default value for tag
96  */
97  inline TagData( const std::string& name,
98  Mesh::TagType type, unsigned length,
99  void* default_val = 0)
100  : desc(name, type, length*size_from_tag_type(type)),
101  elementData(0), elementCount(0),
102  vertexData(0), vertexCount(0),
103  defaultValue(default_val) {}
104 
105  /** \brief Construct tag
106  *\param descr Tag description object
107  */
108  inline TagData( const MfemTagDescription& descr )
109  : desc(descr), elementData(0), elementCount(0),
110  vertexData(0), vertexCount(0),
111  defaultValue(0) {}
112 
113  ~TagData();
114  };
115 
116  /** \brief Get the size of the passed data type */
117  static size_t size_from_tag_type( Mesh::TagType type );
118 
119  /** \brief Clear all data */
120  void clear();
121 
122  /** \brief Get tag index from name */
123  size_t handle( const std::string& name, MsqError& err ) const;
124 
125  /** \brief Get tag properties */
126  const MfemTagDescription& properties( size_t tag_handle, MsqError& err ) const;
127 
128  /** \brief Create a new tag
129  *
130  * Create a new tag with the passed properties
131  *\param name Tag name (must be unique)
132  *\param type Tag data type
133  *\param length Number of values in tag (array length, 1 for scalar)
134  *\param defval Optional default value for tag
135  */
136  size_t create( const std::string& name,
137  Mesh::TagType type,
138  unsigned length,
139  const void* defval,
140  MsqError& err );
141 
142  /** \brief Create a new tag
143  *
144  * Create a new tag with the passed properties
145  */
146  size_t create( const MfemTagDescription& desc,
147  const void* defval,
148  MsqError& err );
149 
150  /**\brief Remove a tag */
151  void destroy( size_t tag_index, MsqError& err );
152 
153  /**\brief Set tag data on elements */
154  void set_element_data( size_t tag_handle,
155  size_t num_indices,
156  const size_t* elem_indices,
157  const void* tag_data,
158  MsqError& err );
159 
160  /**\brief Set tag data on vertices */
161  void set_vertex_data( size_t tag_handle,
162  size_t num_indices,
163  const size_t* elem_indices,
164  const void* tag_data,
165  MsqError& err );
166 
167  /**\brief Get tag data on elements */
168  void get_element_data( size_t tag_handle,
169  size_t num_indices,
170  const size_t* elem_indices,
171  void* tag_data,
172  MsqError& err ) const;
173 
174  /**\brief Get tag data on vertices */
175  void get_vertex_data( size_t tag_handle,
176  size_t num_indices,
177  const size_t* elem_indices,
178  void* tag_data,
179  MsqError& err ) const;
180 
181  /**\class TagIterator
182  *
183  * Iterate over list of valid tag handles
184  */
186  {
187  public:
188  TagIterator() : tags(0), index(0) {}
189  TagIterator( MeshTags* d, size_t i ) : tags(d), index(i) {}
190  size_t operator*() const { return index+1; }
191  TagIterator operator++();
192  TagIterator operator--();
193  TagIterator operator++(int);
194  TagIterator operator--(int);
195  bool operator==(TagIterator other) const { return index == other.index; }
196  bool operator!=(TagIterator other) const { return index != other.index; }
197  private:
198  MeshTags* tags;
199  size_t index;
200  };
201  TagIterator tag_begin();
202  TagIterator tag_end() { return TagIterator(this,tagList.size()); }
203 
204  /**\brief Check if any vertices have tag */
205  bool tag_has_vertex_data( size_t index, MsqError& err ) ;
206  /**\brief Check if any elements have tag */
207  bool tag_has_element_data( size_t index, MsqError& err ) ;
208 
209  private:
210 
211  friend class MeshTags::TagIterator;
212 
213  std::vector<TagData*> tagList;
214  }; // class MeshTags
215 
216  // data members
217 private:
218  int ndofs; // number of nodes (or vertices) in mesh
219  int nelems; // number of elements in mesh
220  mfem::Mesh *mesh; // pointer to mfem mesh object
221  mfem::Element *elem; // pointer to mfem element object
222  mfem::GridFunction *nodes; // pointer to mfem grid function object
223  // for nodes
224  mfem::FiniteElementSpace *fes; // pointer to mfem finite element
225  // space object
226  mfem::Table *dof_elem; // dof to element table
227  std::vector<char> mByte; // length = ndofs
228  std::vector<bool> mFixed; // length = ndofs
229 
230  MeshTags* myTags;
231 
232 public:
233 
234  // The constructor
235  MesquiteMesh(mfem::Mesh *mfem_mesh);
236 
237  // The mesh dimension
238  int get_geometric_dimension(MsqError &err);
239 
240  // The handles are just pointers to the indexes of the nodes/elements
241  void get_all_elements(std::vector<ElementHandle>& elements,
242  MsqError& err );
243  void get_all_vertices(std::vector<VertexHandle>& vertices,
244  MsqError& err );
245 
246  // Get/set vertex coordinates
247  void vertices_get_coordinates(const VertexHandle vert_array[],
248  MsqVertex* coordinates,
249  size_t num_vtx,
250  MsqError &err );
251  void vertex_set_coordinates(VertexHandle vertex,
252  const Vector3D &coordinates,
253  MsqError &err );
254 
255  // These are internal markers for Mesquite that we should allocate for them
256  void vertex_set_byte(VertexHandle vertex,
257  unsigned char byte,
258  MsqError &err);
259  void vertices_set_byte(const VertexHandle *vert_array,
260  const unsigned char *byte_array,
261  size_t array_size,
262  MsqError &err );
263  void vertices_get_fixed_flag(const VertexHandle vert_array[],
264  std::vector<bool>& fixed_flag_array,
265  size_t num_vtx,
266  MsqError &err );
267  void vertices_set_fixed_flag(const VertexHandle vert_array[],
268  const std::vector< bool > &fixed_flag_array,
269  size_t num_vtx,
270  MsqError &err );
271  void vertex_get_byte( const VertexHandle vertex,
272  unsigned char *byte,
273  MsqError &err );
274  void vertices_get_byte( const VertexHandle *vertex,
275  unsigned char *byte_array,
276  size_t array_size,
277  MsqError &err );
278  // The dof_elem table
279  void vertices_get_attached_elements(const VertexHandle* vertex_array,
280  size_t num_vertex,
281  std::vector<ElementHandle>& elements,
282  std::vector<size_t>& offsets,
283  MsqError& err );
284  // The elem_dof table
285  void elements_get_attached_vertices(const ElementHandle *elem_handles,
286  size_t num_elems,
287  std::vector<VertexHandle>& vert_handles,
288  std::vector<size_t>& offsets,
289  MsqError &err);
290 
291  // The topology of the elements: tri/tet/quad/hex...
292  void elements_get_topologies(const ElementHandle *element_handle_array,
293  EntityTopology *element_topologies,
294  size_t num_elements,
295  MsqError &err);
296  // The destructor
297  ~MesquiteMesh();
298 
299  // tag the attributes on the elements from the underlying mfem mesh
300  void tag_attributes();
301 
302  // Clean these up .....
303  void vertices_get_slaved_flag( const VertexHandle vert_array[],
304  std::vector<bool>& slaved_flag_array,
305  size_t num_vtx,
306  MsqError &err ) {};
307 
308  TagHandle tag_create( const std::string& tag_name,
309  TagType type, unsigned length,
310  const void* default_value,
311  MsqError &err);
312 
313  void tag_delete( TagHandle handle, MsqError& err );
314 
315  TagHandle tag_get( const std::string& name,
316  MsqError& err );
317 
318  void tag_properties( TagHandle handle,
319  std::string& name_out,
320  TagType& type_out,
321  unsigned& length_out,
322  MsqError& err );
323 
324  void tag_set_element_data( TagHandle handle,
325  size_t num_elems,
326  const ElementHandle* elem_array,
327  const void* tag_data,
328  MsqError& err );
329 
330  void tag_set_vertex_data ( TagHandle handle,
331  size_t num_elems,
332  const VertexHandle* node_array,
333  const void* tag_data,
334  MsqError& err );
335 
336  void tag_get_element_data( TagHandle handle,
337  size_t num_elems,
338  const ElementHandle* elem_array,
339  void* tag_data,
340  MsqError& err );
341 
342  void tag_get_vertex_data ( TagHandle handle,
343  size_t num_elems,
344  const VertexHandle* node_array,
345  void* tag_data,
346  MsqError& err );
347 
348  void release_entity_handles(const EntityHandle *handle_array,
349  size_t num_handles,
350  MsqError &err) {};
351  void release() {};
352 };
353 
354 }
355 
356 #endif
357 
358 #endif
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:30
const MfemTagDescription desc
tag meta data
Definition: mesquite.hpp:74
TagData(const std::string &name, Mesh::TagType type, unsigned length, void *default_val=0)
Construct tag.
Definition: mesquite.hpp:97
void * vertexData
per-vertex data, or NULL if none has been set.
Definition: mesquite.hpp:83
size_t vertexCount
number of entries in vertexData
Definition: mesquite.hpp:86
bool operator==(TagIterator other) const
Definition: mesquite.hpp:195
void * defaultValue
Default value for tag.
Definition: mesquite.hpp:89
void * elementData
per-element data, or NULL if none has been set.
Definition: mesquite.hpp:77
size_t elementCount
number of entries in elementData
Definition: mesquite.hpp:80
bool operator!=(const Array< T > &LHS, const Array< T > &RHS)
Definition: array.hpp:326
bool operator==(const Array< T > &LHS, const Array< T > &RHS)
Definition: array.hpp:315
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:87
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
Definition: globals.hpp:71
TagData(const MfemTagDescription &descr)
Construct tag.
Definition: mesquite.hpp:108
void vertices_get_slaved_flag(const VertexHandle vert_array[], std::vector< bool > &slaved_flag_array, size_t num_vtx, MsqError &err)
Definition: mesquite.hpp:303
bool operator!=(TagIterator other) const
Definition: mesquite.hpp:196
int index(int i, int j, int nx, int ny)
Definition: life.cpp:241
Abstract data type element.
Definition: element.hpp:28
void release_entity_handles(const EntityHandle *handle_array, size_t num_handles, MsqError &err)
Definition: mesquite.hpp:348