Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mesh/CornerTag.cpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2005 Lawrence Livermore National Laboratory. Under
5  the terms of Contract B545069 with the University of Wisconsin --
6  Madison, Lawrence Livermore National Laboratory 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  kraftche@cae.wisc.edu
24 
25  ***************************************************************** */
26 
27 #include "CornerTag.hpp"
28 #include "MeshSet.hpp"
29 
30 namespace Mesquite {
31 
33 {
34  switch (type) {
35  case Mesh::BYTE: return 1;
36  case Mesh::BOOL: return sizeof(bool);
37  case Mesh::INT: return sizeof(int);
38  case Mesh::DOUBLE: return sizeof(double);
39  case Mesh::HANDLE: return sizeof(Mesh::EntityHandle);
40  default: return 0;
41  }
42 }
43 
44 int CornerTagHandles::num_corners( PatchData* pd, int elem_index )
45 {
46  return pd->element_by_index(elem_index).vertex_count();
47 }
48 
49 
51 {
52  return pd->get_mesh_set() ? pd->get_mesh_set()->get_current_mesh() : 0;
53 }
54 
55 TagHandle CornerTagHandles::get_handle( Mesh* mesh, unsigned corners, MsqError& err )
56 {
57  // Resize vector as necessary
58  if (corners >= cornerHandles.size())
59  {
60  cornerHandles.resize( corners+1, 0 );
61  }
62 
63  // Get handle if we don't already have it
64  if (!cornerHandles[corners])
65  {
66  // Construct tag name
67  char numbuf[16];
68  sprintf(numbuf, "%d", corners );
69  msq_std::string name = tagName + numbuf;
70 
71  // Try to get existing handle
72  cornerHandles[corners] = mesh->tag_get( name, err ); MSQ_ERRZERO(err);
73  // If got handle, make sure type is correct
74  if (cornerHandles[corners])
75  {
76  Mesh::TagType type;
77  unsigned size;
78  mesh->tag_properties( cornerHandles[corners], name, type, size, err );
79  MSQ_ERRZERO(err);
80 
81  if (type != tagType || size != corners*tagLen)
82  {
83  MSQ_SETERR(err)("Invalid tag type", MsqError::INVALID_ARG );
84  return 0;
85  }
86  }
87  // If didn't get handle, try to create it
88  else
89  {
90  cornerHandles[corners] = mesh->tag_create( name, tagType, tagLen * corners, 0, err );
91  MSQ_ERRZERO(err);
92  }
93  }
94 
95  return cornerHandles[corners];
96 }
97 
99  size_t elem_index, void* data,
100  size_t bytes, MsqError& err )
101 {
102  Mesh* mesh = get_current_mesh( pd );
103  if (!mesh) // this happens for some tests in the test suite.
104  return;
105 
106  MsqMeshEntity* elem_array = pd->get_element_array( err );
107  unsigned num_corners = elem_array[elem_index].vertex_count();
108  const Mesh::ElementHandle handle = pd->get_element_handles_array()[elem_index];
109  TagHandle tag = get_handle( mesh, num_corners, err ); MSQ_ERRRTN(err);
110  if (load)
111  mesh->tag_get_element_data( tag, 1, &handle, data, err );
112  else
113  mesh->tag_set_element_data( tag, 1, &handle, data, err );
114  MSQ_CHKERR(err);
115 }
116 
117 } // namespace Mesquite
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
static size_t size(Mesh::TagType type)
static Mesh * get_current_mesh(PatchData *pd)
Used to hold the error state and return it to the application.
TagType
The type of a tag.
virtual TagHandle tag_get(const msq_std::string &name, MsqError &err)=0
Get handle for existing tag, by name.
virtual void tag_set_element_data(TagHandle handle, size_t num_elems, const ElementHandle *elem_array, const void *tag_data, MsqError &err)=0
Set tag values on elements.
const Mesh::ElementHandle * get_element_handles_array() const
EntityHandle ElementHandle
MsqMeshEntity is the Mesquite object that stores information about the elements in the mesh...
void * EntityHandle
Opaque EntityHandle type and tag type.
virtual TagHandle tag_create(const msq_std::string &tag_name, TagType type, unsigned length, const void *default_value, MsqError &err)=0
Create a tag.
invalid function argument passed
msq_stdc::size_t vertex_count() const
Returns the number of vertices in this element, based on its element type.
#define MSQ_CHKERR(err)
Mesquite's Error Checking macro.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
static int num_corners(PatchData *pd, int elem_index)
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's edges).
MsqMeshEntity & element_by_index(size_t index)
virtual void tag_properties(TagHandle handle, msq_std::string &name_out, TagType &type_out, unsigned &length_out, MsqError &err)=0
Get properites of tag.
MeshSet * get_mesh_set()
Returns the originating meshSet.
void save_load_tags(bool load, PatchData *pd, size_t elem_index, void *data, size_t tag_byes, MsqError &err)
void * TagHandle
Type used to refer to a tag defintion.
const MsqMeshEntity * get_element_array(MsqError &err) const
Returns a pointer to the start of the element array.
TagHandle get_handle(Mesh *mesh, unsigned num_corners, MsqError &err)
Get the tag handle for storing this tag type with the specified number of values (corners).
msq_std::vector< TagHandle > cornerHandles
virtual void tag_get_element_data(TagHandle handle, size_t num_elems, const ElementHandle *elem_array, void *tag_data, MsqError &err)=0
Get tag values on elements.
#define MSQ_ERRRTN(err)
If passed error is true, return from a void function.