Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/MeshImpl.hpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government retains certain
7  rights in this software.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
24  pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov ,
25  kraftche@cae.wisc.edu
26 
27  ***************************************************************** */
38 #ifndef MESQUITE_MESH_IMPL_HPP
39 #define MESQUITE_MESH_IMPL_HPP
40 
41 #include "MeshInterface.hpp"
42 
43 #ifdef MSQ_USE_OLD_STD_HEADERS
44 #include <map.h>
45 #else
46 #include <map>
47 #endif
48 
49 namespace Mesquite
50 {
51  class FileTokenizer;
52  class MeshImplData;
53  class MeshImplTags;
54  struct TagDescription;
55 
63  class MeshImpl : public Mesquite::Mesh
64  {
65  public:
66 //********* Functions that are NOT inherited ************
67  MeshImpl();
68  virtual ~MeshImpl();
69  void read_vtk(const char* in_filename, Mesquite::MsqError &err);
70  void write_vtk(const char* out_filename, Mesquite::MsqError &err);
71  void read_exodus(const char* in_filename, Mesquite::MsqError &err);
72  void write_exodus(const char* out_filename, Mesquite::MsqError &err);
73 //********* Functions that ARE inherited ************
74  // Returns whether this mesh lies in a 2D or 3D coordinate system.
75  virtual int get_geometric_dimension(MsqError &err) ;
76 
87  virtual void get_all_sizes( size_t& vertex_count,
88  size_t& element_count,
89  size_t& vertex_use_count,
90  MsqError& err );
91 
110  virtual void get_all_mesh( VertexHandle* vert_array, size_t vert_len,
111  ElementHandle* elem_array, size_t elem_len,
112  size_t* elem_conn_offsets, size_t offset_len,
113  size_t* elem_conn_indices, size_t index_len,
114  MsqError& err );
115 
117  virtual size_t get_vertex_use_count( ElementHandle* elem_array,
118  size_t elem_array_length,
119  MsqError& err );
120 
121  // Returns a pointer to an iterator that iterates over the
122  // set of all vertices in this mesh. The calling code should
123  // delete the returned iterator when it is finished with it.
124  // If vertices are added or removed from the Mesh after obtaining
125  // an iterator, the behavior of that iterator is undefined.
126  virtual VertexIterator* vertex_iterator(MsqError &err);
127 
128  // Returns a pointer to an iterator that iterates over the
129  // set of all top-level elements in this mesh. The calling code should
130  // delete the returned iterator when it is finished with it.
131  // If elements are added or removed from the Mesh after obtaining
132  // an iterator, the behavior of that iterator is undefined.
134 
135 //************ Vertex Properties ********************
136  // Returns true or false, indicating whether the vertex
137  // is allowed to be repositioned. True indicates that the vertex
138  // is fixed and cannot be moved. Note that this is a read-only
139  // property; this flag can't be modified by users of the
140  // Mesquite::Mesh interface.
141  virtual bool vertex_is_fixed(VertexHandle vertex, MsqError &err);
142 
143  // Returns true or false, indicating whether the vertex
144  // is on the boundary. Boundary nodes may be treated as
145  // a special case by some algorithms or culling methods.
146  // Note that this is a read-only
147  // property; this flag can't be modified by users of the
148  // Mesquite::Mesh interface.
149  virtual void vertices_are_on_boundary(VertexHandle vert_array[], bool on_bnd[],
150  size_t num_vtx, MsqError &err);
151 
152  // Get/set location of a vertex
153  virtual void vertices_get_coordinates(const Mesh::VertexHandle vert_array[],
154  Mesquite::MsqVertex* coordinates,
155  size_t num_vtx,
156  MsqError &err);
157  virtual void vertex_set_coordinates(VertexHandle vertex,
158  const Vector3D &coordinates,
159  MsqError &err);
160 
161  // Each vertex has a byte-sized flag that can be used to store
162  // flags. This byte's value is neither set nor used by the mesh
163  // implementation. It is intended to be used by Mesquite algorithms.
164  // Until a vertex's byte has been explicitly set, its value is 0.
165  virtual void vertex_set_byte (VertexHandle vertex,
166  unsigned char byte,
167  MsqError &err);
168  virtual void vertices_set_byte (VertexHandle *vert_array,
169  unsigned char *byte_array,
170  size_t array_size,
171  MsqError &err);
172 
173  // Retrieve the byte value for the specified vertex or vertices.
174  // The byte value is 0 if it has not yet been set via one of the
175  // *_set_byte() functions.
176  virtual void vertex_get_byte(VertexHandle vertex,
177  unsigned char *byte,
178  MsqError &err);
179  virtual void vertices_get_byte(VertexHandle *vertex,
180  unsigned char *byte_array,
181  size_t array_size,
182  MsqError &err);
183 
184 //**************** Vertex Topology *****************
185  // Gets the number of elements attached to this vertex.
186  // Useful to determine how large the "elem_array" parameter
187  // of the vertex_get_attached_elements() function must be.
188  virtual size_t vertex_get_attached_element_count(VertexHandle vertex,
189  MsqError &err);
190 
191  // Gets the elements attached to this vertex.
192  virtual void vertex_get_attached_elements(VertexHandle vertex,
193  ElementHandle* elem_array,
194  size_t sizeof_elem_array,
195  MsqError &err);
196 
197 
198 //*************** Element Topology *************
199 
200  // Gets the number of vertices in this element.
201  // This data can also be found by querying the
202  // element's topology and getting the number
203  // of vertices per element for that topology type.
205  MsqError &err);
206 
207 // Returns the vertices that are part of the topological definition of each
208 // element in the "elem_handles" array. When this function is called, the
209 // following must be true:
210 // a) "elem_handles" points at an array of "num_elems" element handles.
211 // b) "vert_handles" points at an array of size "sizeof_vert_handles"
212 // c) "csr_data" points at an array of size "sizeof_csr_data"
213 // d) "csr_offsets" points at an array of size "num_elems+1"
214 //
215 // When this function returns, adjacency information will be stored
216 // in csr format:
217 // a) "vert_handles" stores handles to all vertices found in one
218 // or more of the elements. Each vertex appears only
219 // once in "vert_handles", even if it is in multiple elements.
220 // b) "sizeof_vert_handles" is set to the number of vertex
221 // handles placed into "vert_handles".
222 // c) "sizeof_csr_data" is set to the total number of vertex uses (for
223 // example, sizeof_csr_data = 6 in the case of 2 TRIANGLES, even if
224 // the two triangles share some vertices).
225 // c) "csr_offsets" is filled such that csr_offset[i] indicates the location
226 // of entity i's first adjacency in "csr_data". The number of vertices
227 // in element i is equal to csr_offsets[i+1] - csr_offsets[i]. For this
228 // reason, csr_offsets[num_elems] is set to the new value of
229 // "sizeof_csr_data".
230 // d) "csr_data" stores integer offsets which give the location of
231 // each adjacency in the "vert_handles" array.
232 //
233 // As an example of how to use this data, you can get the handle of the first
234 // vertex in element #3 like this:
235 // VertexHandle vh = vert_handles[ csr_data[ csr_offsets[3] ] ]
236 //
237 // and the second vertex of element #3 like this:
238 // VertexHandle vh = vert_handles[ csr_data[ csr_offsets[3]+1 ] ]
239 //
240  virtual void elements_get_attached_vertices(ElementHandle *elem_handles,
241  size_t num_elems,
242  VertexHandle *vert_handles,
243  size_t &sizeof_vert_handles,
244  size_t *csr_data,
245  size_t &sizeof_csr_data,
246  size_t *csr_offsets,
247  MsqError &err);
248 
250  VertexHandle* vert_handles,
251  size_t sizeof_vert_handles,
252  MsqError& err );
253 
254  // Returns the topology of the given entity.
255  virtual EntityTopology element_get_topology(ElementHandle entity_handle,
256  MsqError &err);
257  // Returns the topologies of the given entities. The "entity_topologies"
258  // array must be at least "num_elements" in size.
259  virtual void elements_get_topologies(ElementHandle *element_handle_array,
260  EntityTopology *element_topologies,
261  size_t num_elements,
262  MsqError &err);
263 
264 
265 //*************** Tags ***********
266 
279  virtual TagHandle tag_create( const msq_std::string& tag_name,
280  TagType type, unsigned length,
281  const void* default_value,
282  MsqError &err);
283 
288  virtual void tag_delete( TagHandle handle, MsqError& err );
289 
290 
292  virtual TagHandle tag_get( const msq_std::string& name,
293  MsqError& err );
294 
303  virtual void tag_properties( TagHandle handle,
304  msq_std::string& name_out,
305  TagType& type_out,
306  unsigned& length_out,
307  MsqError& err );
308 
319  virtual void tag_set_element_data( TagHandle handle,
320  size_t num_elems,
321  const ElementHandle* elem_array,
322  const void* tag_data,
323  MsqError& err );
324 
335  virtual void tag_set_vertex_data ( TagHandle handle,
336  size_t num_elems,
337  const VertexHandle* node_array,
338  const void* tag_data,
339  MsqError& err );
340 
341 
352  virtual void tag_get_element_data( TagHandle handle,
353  size_t num_elems,
354  const ElementHandle* elem_array,
355  void* tag_data,
356  MsqError& err );
357 
368  virtual void tag_get_vertex_data ( TagHandle handle,
369  size_t num_elems,
370  const VertexHandle* node_array,
371  void* tag_data,
372  MsqError& err );
373 
374 //**************** Memory Management ****************
375  // Tells the mesh that the client is finished with a given
376  // entity handle.
377  virtual void release_entity_handles(EntityHandle *handle_array,
378  size_t num_handles,
379  MsqError &err);
380 
381  // Instead of deleting a Mesh when you think you are done,
382  // call release(). In simple cases, the implementation could
383  // just call the destructor. More sophisticated implementations
384  // may want to keep the Mesh object to live longer than Mesquite
385  // is using it.
386  virtual void release();
387 
388  // Remove all data
389  void clear();
390 
391  private:
392 
395 
398 
399 
400 //**************** VTK Parsing ****************
401 
403  void vtk_read_dataset( FileTokenizer& file, MsqError& err );
404 
408  void vtk_read_structured_grid ( FileTokenizer& file, MsqError& err );
410  void vtk_read_rectilinear_grid ( FileTokenizer& file, MsqError& err );
412  void vtk_read_polydata ( FileTokenizer& file, MsqError& err );
416  void vtk_read_field ( FileTokenizer& file, MsqError& err );
417 
419  void vtk_read_polygons( FileTokenizer& file, MsqError& err );
421  void vtk_create_structured_elems( const long* dims, MsqError& err );
422 
424  void vtk_read_point_data( FileTokenizer& file, MsqError& err );
426  void vtk_read_cell_data ( FileTokenizer& file, MsqError& err );
429  void* vtk_read_attrib_data( FileTokenizer& file,
430  long num_data_to_read,
431  TagDescription& tag_out,
432  MsqError& err );
435  void* vtk_read_typed_data( FileTokenizer& file, int type,
436  size_t per_elem, size_t num_elem,
437  TagDescription& tag_out,
438  MsqError& err );
439 
442  void* vtk_read_scalar_attrib ( FileTokenizer& file, long count,
443  TagDescription& tag_out, MsqError& err );
446  void* vtk_read_color_attrib ( FileTokenizer& file, long count,
447  TagDescription& tag_out, MsqError& err );
450  void* vtk_read_vector_attrib ( FileTokenizer& file, long count,
451  TagDescription& tag_out, MsqError& err );
454  void* vtk_read_texture_attrib( FileTokenizer& file, long count,
455  TagDescription& tag_out, MsqError& err );
458  void* vtk_read_tensor_attrib ( FileTokenizer& file, long count,
459  TagDescription& tag_out, MsqError& err );
460 
462  void vtk_write_attrib_data( msq_stdio::ostream& file,
463  const TagDescription& desc,
464  const void* data, size_t count,
465  MsqError& err ) const;
466 
467 //**************** End VTK Parsing ****************
468  };
469 }
470 
471 #endif
Iterates through a set of entities. An EntityIterator is typically obtained via Mesh::vertex_iterator...
void * vtk_read_tensor_attrib(FileTokenizer &file, long count, TagDescription &tag_out, MsqError &err)
Read tensor (3x3 matrix) data Initializes size and type fields of passed TagDescroption.
virtual void vertices_set_byte(VertexHandle *vert_array, unsigned char *byte_array, size_t array_size, MsqError &err)
void * vtk_read_attrib_data(FileTokenizer &file, long num_data_to_read, TagDescription &tag_out, MsqError &err)
Read actual data for both vtk_read_point_data and vtk_read_cell_data Initializes all fields of passed...
void * vtk_read_texture_attrib(FileTokenizer &file, long count, TagDescription &tag_out, MsqError &err)
Read texture attribute data Initializes size and type fields of passed TagDescroption.
void vtk_read_field(FileTokenizer &file, MsqError &err)
Read file-level field data.
void * vtk_read_color_attrib(FileTokenizer &file, long count, TagDescription &tag_out, MsqError &err)
Read color attribute data Initializes size and type fields of passed TagDescroption.
virtual size_t get_vertex_use_count(ElementHandle *elem_array, size_t elem_array_length, MsqError &err)
Get sum of number of vertices in each element.
Used to hold the error state and return it to the application.
TagType
The type of a tag.
EntityTopology
Definition: Mesquite.hpp:92
virtual TagHandle tag_create(const msq_std::string &tag_name, TagType type, unsigned length, const void *default_value, MsqError &err)
Create a tag.
virtual void tag_set_vertex_data(TagHandle handle, size_t num_elems, const VertexHandle *node_array, const void *tag_data, MsqError &err)
Set tag values on vertices.
virtual void vertices_get_byte(VertexHandle *vertex, unsigned char *byte_array, size_t array_size, MsqError &err)
void vtk_read_dataset(FileTokenizer &file, MsqError &err)
Read a data block from the file.
void vtk_read_unstructured_grid(FileTokenizer &file, MsqError &err)
Read unstructured mesh.
Class to store mesh representation for MeshImpl.
EntityHandle VertexHandle
virtual void vertex_set_byte(VertexHandle vertex, unsigned char byte, MsqError &err)
Each vertex has a byte-sized flag that can be used to store flags.
virtual void vertex_get_attached_elements(VertexHandle vertex, ElementHandle *elem_array, size_t sizeof_elem_array, MsqError &err)
Gets the elements attached to this vertex.
virtual void vertex_get_byte(VertexHandle vertex, unsigned char *byte, MsqError &err)
Retrieve the byte value for the specified vertex or vertices.
EntityHandle ElementHandle
This file contains the Mesquite mesh interface. Many users will want to implement a concrete class de...
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
void element_get_connectivity(ElementHandle element, VertexHandle *vert_handles, size_t sizeof_vert_handles, MsqError &err)
void * EntityHandle
Opaque EntityHandle type and tag type.
virtual VertexIterator * vertex_iterator(MsqError &err)
Returns a pointer to an iterator that iterates over the set of all vertices in this mesh...
void * vtk_read_vector_attrib(FileTokenizer &file, long count, TagDescription &tag_out, MsqError &err)
Read vector or normal attribute data Initializes size and type fields of passed TagDescroption.
virtual void vertices_get_coordinates(const Mesh::VertexHandle vert_array[], Mesquite::MsqVertex *coordinates, size_t num_vtx, MsqError &err)
Get/set location of a vertex.
void write_vtk(const char *out_filename, Mesquite::MsqError &err)
double length(Vector3D *const v, int n)
virtual void elements_get_attached_vertices(ElementHandle *elem_handles, size_t num_elems, VertexHandle *vert_handles, size_t &sizeof_vert_handles, size_t *csr_data, size_t &sizeof_csr_data, size_t *csr_offsets, MsqError &err)
Returns the vertices that are part of the topological definition of each element in the &quot;elem_handles...
virtual void tag_get_element_data(TagHandle handle, size_t num_elems, const ElementHandle *elem_array, void *tag_data, MsqError &err)
Get tag values on elements.
virtual void get_all_sizes(size_t &vertex_count, size_t &element_count, size_t &vertex_use_count, MsqError &err)
get sizes for calling get_all_mesh
void * vtk_read_typed_data(FileTokenizer &file, int type, size_t per_elem, size_t num_elem, TagDescription &tag_out, MsqError &err)
Read a 2-D array of data of the specified type from the file Initializes size and type fields of pass...
virtual void tag_delete(TagHandle handle, MsqError &err)
Remove a tag and all corresponding data.
void read_exodus(const char *in_filename, Mesquite::MsqError &err)
virtual void tag_set_element_data(TagHandle handle, size_t num_elems, const ElementHandle *elem_array, const void *tag_data, MsqError &err)
Set tag values on elements.
virtual size_t vertex_get_attached_element_count(VertexHandle vertex, MsqError &err)
Gets the number of elements attached to this vertex.
void vtk_create_structured_elems(const long *dims, MsqError &err)
Helper function for readers of structured mesh - create elements.
void vtk_read_polygons(FileTokenizer &file, MsqError &err)
Helper function for vtk_read_polydata - reads polygon subsection.
int numCoords
Coordinate values per vertex.
void * vtk_read_scalar_attrib(FileTokenizer &file, long count, TagDescription &tag_out, MsqError &err)
Read scalar attribute data Initializes size and type fields of passed TagDescroption.
A Mesquite::Mesh is a collection of mesh elements which are composed of mesh vertices. Intermediate objects are not accessible through this interface (where intermediate objects include things like the faces of a hex, or an element&#39;s edges).
virtual bool vertex_is_fixed(VertexHandle vertex, MsqError &err)
Returns true or false, indicating whether the vertex is allowed to be repositioned.
MeshImpl is a Mesquite implementation of the Mesh interface. Applications can also provide their own ...
void vtk_read_cell_data(FileTokenizer &file, MsqError &err)
Read attribute data for elements.
virtual int get_geometric_dimension(MsqError &err)
Returns whether this mesh lies in a 2D or 3D coordinate system.
void vtk_write_attrib_data(msq_stdio::ostream &file, const TagDescription &desc, const void *data, size_t count, MsqError &err) const
Write tag data to VTK attributes.
virtual void vertices_are_on_boundary(VertexHandle vert_array[], bool on_bnd[], size_t num_vtx, MsqError &err)
Returns true or false, indicating whether the vertex is on the boundary.
void vtk_read_polydata(FileTokenizer &file, MsqError &err)
Read polydata mesh.
virtual ElementIterator * element_iterator(MsqError &err)
Returns a pointer to an iterator that iterates over the set of all top-level elements in this mesh...
virtual EntityTopology element_get_topology(ElementHandle entity_handle, MsqError &err)
Returns the topology of the given entity.
virtual void tag_properties(TagHandle handle, msq_std::string &name_out, TagType &type_out, unsigned &length_out, MsqError &err)
Get properites of tag.
void read_vtk(const char *in_filename, Mesquite::MsqError &err)
void vtk_read_point_data(FileTokenizer &file, MsqError &err)
Read attribute data for vertices.
void * TagHandle
Type used to refer to a tag defintion.
virtual void get_all_mesh(VertexHandle *vert_array, size_t vert_len, ElementHandle *elem_array, size_t elem_len, size_t *elem_conn_offsets, size_t offset_len, size_t *elem_conn_indices, size_t index_len, MsqError &err)
Get entities and connectivity.
virtual void release()
Instead of deleting a Mesh when you think you are done, call release().
virtual void elements_get_topologies(ElementHandle *element_handle_array, EntityTopology *element_topologies, size_t num_elements, MsqError &err)
Returns the topologies of the given entities.
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...
void vtk_read_structured_grid(FileTokenizer &file, MsqError &err)
Read structured grid mesh.
virtual size_t element_get_attached_vertex_count(ElementHandle elem, MsqError &err)
Gets the number of vertices in this element.
void write_exodus(const char *out_filename, Mesquite::MsqError &err)
Writes an exodus file of the mesh.
void vtk_read_structured_points(FileTokenizer &file, MsqError &err)
Read structured point mesh.
virtual TagHandle tag_get(const msq_std::string &name, MsqError &err)
Get handle for existing tag, by name.
void vtk_read_rectilinear_grid(FileTokenizer &file, MsqError &err)
Read rectilinear grid structured mesh.
virtual void tag_get_vertex_data(TagHandle handle, size_t num_elems, const VertexHandle *node_array, void *tag_data, MsqError &err)
Get tag values on vertices.
virtual void vertex_set_coordinates(VertexHandle vertex, const Vector3D &coordinates, MsqError &err)
virtual void release_entity_handles(EntityHandle *handle_array, size_t num_handles, MsqError &err)
Tells the mesh that the client is finished with a given entity handle.
Store tags and tag data for Mesquite&#39;s native mesh representation.
Parse a file as space-separated tokens.