Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/CornerTag.hpp
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 #ifndef MSQ_CORNER_TAG_HPP
28 #define MSQ_CORNER_TAG_HPP
29 
30 #ifdef MSQ_USE_OLD_STD_HEADERS
31 # include <vector.h>
32 #else
33 # include <vector>
34 #endif
35 #include <string>
36 #include <assert.h>
37 
38 #include "MeshInterface.hpp"
39 #include "MsqError.hpp"
40 
41 namespace Mesquite {
42 
43 class PatchData;
44 
55 {
56 public:
57  CornerTagHandles( const char* tag_name,
58  Mesh::TagType type,
59  unsigned tag_len )
60  : tagName( tag_name ),
61  tagType(type),
62  tagLen(tag_len)
63  {}
64 
68  TagHandle get_handle( Mesh* mesh, unsigned num_corners, MsqError& err );
69 
70  void save_load_tags( bool load, PatchData* pd, size_t elem_index, void* data, size_t tag_byes, MsqError& err );
71 
72  static Mesh* get_current_mesh( PatchData* pd );
73 
74  static size_t size( Mesh::TagType type );
75 
76  static int num_corners( PatchData* pd, int elem_index );
77 
78 private:
79 
80  const msq_std::string tagName;
82  const unsigned tagLen;
83 
84  msq_std::vector<TagHandle> cornerHandles;
85 };
86 
87 
110 template <typename T> class CornerTag
111 {
112  public:
113 
121  CornerTag( const char* name, Mesh::TagType type = Mesh::BYTE);
122 
123  ~CornerTag();
124 
128  inline void clear( );
129 
135  inline const T* get_element_corner_tags( PatchData* pd, int elem_idx, MsqError& err );
136 
137  inline void set_element_corner_tags( PatchData* pd, int elem_idx, const T* data, MsqError& err );
138 
139  private:
140 
142  msq_std::vector<T*> tagData; //< Cached tag data for all elems of patch
143 };
144 
145 
146 template <typename T>
147 CornerTag<T>::CornerTag( const char* tag_name, Mesh::TagType type )
148  : tagHandles( tag_name, type, sizeof(T) / CornerTagHandles::size(type) )
149 {
150  // We're going to assume this for all tag read/writes,
151  // so make sure its true now.
152  assert( (sizeof(T) % CornerTagHandles::size(type)) == 0 );
153 }
154 
155 template <typename T>
157 {
158  clear();
159 }
160 
161 template <typename T>
163 {
164  for (typename msq_std::vector<T*>::iterator i = tagData.begin(); i != tagData.end(); ++i)
165  delete [] *i;
166  tagData.clear();
167 }
168 
169 template <typename T>
171  int elem_index,
172  MsqError& err )
173 {
174  if (tagData.size() <= (unsigned)elem_index)
175  tagData.resize( elem_index+1, 0 );
176 
177  int num_corners = tagHandles.num_corners( pd, elem_index );
178  if (!tagData[elem_index]) {
179  tagData[elem_index] = new T[num_corners];
180  tagHandles.save_load_tags( true, pd, elem_index, tagData[elem_index], sizeof(T), err );
181  MSQ_ERRZERO(err);
182  }
183 
184  return tagData[elem_index];
185 }
186 
187 template <typename T>
189  int elem_index,
190  const T* data,
191  MsqError& err )
192 {
193  if (tagData.size() <= (unsigned)elem_index)
194  tagData.resize( elem_index+1, 0 );
195 
196  int num_corners = tagHandles.num_corners( pd, elem_index );
197  if (!tagData[elem_index])
198  tagData[elem_index] = new T[num_corners];
199  memcpy( tagData[elem_index], data, num_corners * sizeof(T) );
200 
201  tagHandles.save_load_tags( false, pd, elem_index, (void*)data, sizeof(T), err );
202  MSQ_CHKERR(err);
203 }
204 
205 
206 } // namespace Mesquite
207 
208 #endif
CornerTag(const char *name, Mesh::TagType type=Mesh::BYTE)
Initialize.
CornerTagHandles(const char *tag_name, Mesh::TagType type, unsigned tag_len)
#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.
This file contains the Mesquite mesh interface. Many users will want to implement a concrete class de...
void set_element_corner_tags(PatchData *pd, int elem_idx, const T *data, MsqError &err)
Utility class to manage tag handles for corner tags.
msq_std::vector< T * > tagData
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.
const T * get_element_corner_tags(PatchData *pd, int elem_idx, MsqError &err)
Get a pointer to the array of all corner tag values for a given element.
blockLoc i
Definition: read.cpp:79
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&#39;s edges).
A class for caching and managing Tags on element corners.
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.
void clear()
Clear cached data.
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