Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MeshImplTags Class Reference

Store tags and tag data for Mesquite's native mesh representation. More...

#include <MeshImplTags.hpp>

Classes

class  TagData
 Store data for a single tag. More...
 
class  TagIterator
 Iterate over list of valid tag handles. More...
 

Public Member Functions

 ~MeshImplTags ()
 
void clear ()
 Clear all data. More...
 
size_t handle (const msq_std::string &name, MsqError &err) const
 Get tag index from name. More...
 
const TagDescriptionproperties (size_t tag_handle, MsqError &err) const
 Get tag properties. More...
 
size_t create (const msq_std::string &name, Mesh::TagType type, unsigned length, const void *defval, MsqError &err)
 Create a new tag. More...
 
size_t create (const TagDescription &desc, MsqError &err)
 Create a new tag. More...
 
void destroy (size_t tag_index, MsqError &err)
 Remove a tag. More...
 
void set_element_data (size_t tag_handle, size_t num_indices, const size_t *elem_indices, const void *tag_data, MsqError &err)
 Set tag data on elements. More...
 
void set_vertex_data (size_t tag_handle, size_t num_indices, const size_t *elem_indices, const void *tag_data, MsqError &err)
 Set tag data on vertices. More...
 
void get_element_data (size_t tag_handle, size_t num_indices, const size_t *elem_indices, void *tag_data, MsqError &err) const
 Get tag data on elements. More...
 
void get_vertex_data (size_t tag_handle, size_t num_indices, const size_t *elem_indices, void *tag_data, MsqError &err) const
 Get tag data on vertices. More...
 
TagIterator tag_begin ()
 
TagIterator tag_end ()
 
bool tag_has_vertex_data (size_t index, MsqError &err)
 Check if any vertices have tag. More...
 
bool tag_has_element_data (size_t index, MsqError &err)
 Check if any elements have tag. More...
 
 ~MeshImplTags ()
 
void clear ()
 Clear all data. More...
 
size_t handle (const msq_std::string &name, MsqError &err) const
 Get tag index from name. More...
 
const TagDescriptionproperties (size_t tag_handle, MsqError &err) const
 Get tag properties. More...
 
size_t create (const msq_std::string &name, Mesh::TagType type, unsigned length, const void *defval, MsqError &err)
 Create a new tag. More...
 
size_t create (const TagDescription &desc, MsqError &err)
 Create a new tag. More...
 
void destroy (size_t tag_index, MsqError &err)
 Remove a tag. More...
 
void set_element_data (size_t tag_handle, size_t num_indices, const size_t *elem_indices, const void *tag_data, MsqError &err)
 Set tag data on elements. More...
 
void set_vertex_data (size_t tag_handle, size_t num_indices, const size_t *elem_indices, const void *tag_data, MsqError &err)
 Set tag data on vertices. More...
 
void get_element_data (size_t tag_handle, size_t num_indices, const size_t *elem_indices, void *tag_data, MsqError &err) const
 Get tag data on elements. More...
 
void get_vertex_data (size_t tag_handle, size_t num_indices, const size_t *elem_indices, void *tag_data, MsqError &err) const
 Get tag data on vertices. More...
 
TagIterator tag_begin ()
 
TagIterator tag_end ()
 
bool tag_has_vertex_data (size_t index, MsqError &err)
 Check if any vertices have tag. More...
 
bool tag_has_element_data (size_t index, MsqError &err)
 Check if any elements have tag. More...
 

Static Public Member Functions

static size_t size_from_tag_type (Mesh::TagType type)
 Get the size of the passed data type. More...
 
static size_t size_from_tag_type (Mesh::TagType type)
 Get the size of the passed data type. More...
 

Private Attributes

msq_std::vector< TagData * > tagList
 

Friends

class MeshImplTags::TagIterator
 

Detailed Description

Store tags and tag data for Mesquite's native mesh representation.

Stores for each tag: properties, element data, and vertex data. The tag element and vertex data sets are maps between some element or vertex index and a tag value.

Definition at line 72 of file includeLinks/MeshImplTags.hpp.

Constructor & Destructor Documentation

~MeshImplTags ( )
inline

Definition at line 75 of file includeLinks/MeshImplTags.hpp.

References MeshImplTags::clear().

75 { clear(); }
void clear()
Clear all data.

Here is the call graph for this function:

~MeshImplTags ( )
inline

Definition at line 75 of file src/Mesh/MeshImplTags.hpp.

References MeshImplTags::clear().

75 { clear(); }
void clear()
Clear all data.

Here is the call graph for this function:

Member Function Documentation

void clear ( )

Clear all data.

Definition at line 48 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::tagList.

Referenced by MeshImpl::clear(), and MeshImplTags::~MeshImplTags().

49 {
50  for (msq_std::vector<TagData*>::iterator iter = tagList.begin();
51  iter != tagList.end(); ++iter)
52  if (*iter)
53  delete *iter;
54 
55  tagList.clear();
56 }
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

void clear ( )

Clear all data.

size_t create ( const msq_std::string &  name,
Mesh::TagType  type,
unsigned  length,
const void *  defval,
MsqError err 
)

Create a new tag.

Create a new tag with the passed properties

Parameters
nameTag name (must be unique)
typeTag data type
lengthNumber of values in tag (array length, 1 for scalar)
defvalOptional default value for tag

Definition at line 70 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::TagData::defaultValue, MeshImplTags::TagData::desc, MeshImplTags::handle(), MsqError::INVALID_ARG, MSQ_SETERR, TagDescription::size, MeshImplTags::size_from_tag_type(), MsqError::TAG_ALREADY_EXISTS, and MeshImplTags::tagList.

Referenced by MeshImpl::vtk_read_cell_data(), and MeshImpl::vtk_read_point_data().

75 {
76  size_t h = handle( name, err );
77  if (h)
78  {
80  return 0;
81  }
82 
83  if (length == 0 || size_from_tag_type(type) == 0)
84  {
86  return 0;
87  }
88 
89  TagData* tag = new TagData( name, type, length );
90  h = tagList.size();
91  tagList.push_back(tag);
92 
93  if (defval)
94  {
95  tag->defaultValue = malloc( tag->desc.size );
96  memcpy( tag->defaultValue, defval, tag->desc.size );
97  }
98 
99  return h+1;
100 }
size_t handle(const msq_std::string &name, MsqError &err) const
Get tag index from name.
Attempt to create tag that already exists.
double length(Vector3D *const v, int n)
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
msq_std::vector< TagData * > tagList
static size_t size_from_tag_type(Mesh::TagType type)
Get the size of the passed data type.

Here is the call graph for this function:

Here is the caller graph for this function:

size_t create ( const msq_std::string &  name,
Mesh::TagType  type,
unsigned  length,
const void *  defval,
MsqError err 
)

Create a new tag.

Create a new tag with the passed properties

Parameters
nameTag name (must be unique)
typeTag data type
lengthNumber of values in tag (array length, 1 for scalar)
defvalOptional default value for tag
size_t create ( const TagDescription desc,
MsqError err 
)

Create a new tag.

Create a new tag with the passed properties

size_t create ( const TagDescription desc,
MsqError err 
)

Create a new tag.

Create a new tag with the passed properties

Definition at line 102 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::handle(), MsqError::INVALID_ARG, MSQ_SETERR, TagDescription::name, TagDescription::size, MeshImplTags::size_from_tag_type(), MsqError::TAG_ALREADY_EXISTS, MeshImplTags::tagList, and TagDescription::type.

104 {
105  size_t h = handle( desc.name.c_str(), err );
106  if (h)
107  {
108  MSQ_SETERR(err)(desc.name.c_str(), MsqError::TAG_ALREADY_EXISTS);
109  return 0;
110  }
111 
112  if (desc.size == 0 || (desc.size % size_from_tag_type(desc.type)) != 0)
113  {
115  return 0;
116  }
117 
118  TagData* tag = new TagData( desc );
119  h = tagList.size();
120  tagList.push_back(tag);
121 
122  return h+1;
123 }
size_t handle(const msq_std::string &name, MsqError &err) const
Get tag index from name.
Attempt to create tag that already exists.
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
msq_std::vector< TagData * > tagList
static size_t size_from_tag_type(Mesh::TagType type)
Get the size of the passed data type.

Here is the call graph for this function:

void destroy ( size_t  tag_index,
MsqError err 
)

Remove a tag.

void destroy ( size_t  tag_index,
MsqError err 
)

Remove a tag.

Definition at line 125 of file Mesh/MeshImplTags.cpp.

References MSQ_SETERR, MsqError::TAG_NOT_FOUND, and MeshImplTags::tagList.

Referenced by MeshImpl::tag_delete().

126 {
127  --tag_index;
128  if (tag_index >= tagList.size() || 0 == tagList[tag_index])
129  {
131  return ;
132  }
133 
134  delete tagList[tag_index];
135  tagList[tag_index] = 0;
136 }
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
Specified tag does not exist.
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

void get_element_data ( size_t  tag_handle,
size_t  num_indices,
const size_t *  elem_indices,
void *  tag_data,
MsqError err 
) const

Get tag data on elements.

Definition at line 213 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::TagData::defaultValue, MeshImplTags::TagData::desc, MeshImplTags::TagData::elementCount, MeshImplTags::TagData::elementData, for(), i, MsqError::INVALID_ARG, MSQ_SETERR, TagDescription::size, MsqError::TAG_NOT_FOUND, and MeshImplTags::tagList.

Referenced by MeshImpl::tag_get_element_data(), and MeshImpl::write_vtk().

218 {
219  --tag_index;
220  if (tag_index >= tagList.size() || !tagList[tag_index])
221  {
222  MSQ_SETERR(err)("Invalid tag handle", MsqError::INVALID_ARG);
223  return;
224  }
225 
226  TagData* tag = tagList[tag_index];
227 
228  char* iter = (char*)values;
229  const char* data = (const char*)tag->elementData;
230 
231  for (size_t i = 0; i < num_indices; ++i)
232  {
233  const void* ptr;
234  size_t index = index_array[i];
235  if (index >= tag->elementCount)
236  {
237  ptr = tag->defaultValue;
238  if (!ptr)
239  {
241  return;
242  }
243  }
244  else
245  {
246  ptr = data + index * tag->desc.size;
247  }
248 
249  memcpy( iter, ptr, tag->desc.size );
250  iter += tag->desc.size;
251  }
252 }
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
blockLoc i
Definition: read.cpp:79
Specified tag does not exist.
msq_std::vector< TagData * > tagList
for(;;)

Here is the call graph for this function:

Here is the caller graph for this function:

void get_element_data ( size_t  tag_handle,
size_t  num_indices,
const size_t *  elem_indices,
void *  tag_data,
MsqError err 
) const

Get tag data on elements.

void get_vertex_data ( size_t  tag_handle,
size_t  num_indices,
const size_t *  elem_indices,
void *  tag_data,
MsqError err 
) const

Get tag data on vertices.

Definition at line 305 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::TagData::defaultValue, MeshImplTags::TagData::desc, for(), i, MsqError::INVALID_ARG, MSQ_SETERR, TagDescription::size, MsqError::TAG_NOT_FOUND, MeshImplTags::tagList, MeshImplTags::TagData::vertexCount, and MeshImplTags::TagData::vertexData.

Referenced by MeshImpl::read_vtk(), MeshImpl::tag_get_vertex_data(), and MeshImpl::write_vtk().

310 {
311  --tag_index;
312  if (tag_index >= tagList.size() || !tagList[tag_index])
313  {
314  MSQ_SETERR(err)("Invalid tag handle", MsqError::INVALID_ARG);
315  return;
316  }
317 
318  TagData* tag = tagList[tag_index];
319 
320  char* iter = (char*)values;
321  const char* data = (const char*)tag->vertexData;
322 
323  for (size_t i = 0; i < num_indices; ++i)
324  {
325  const void* ptr;
326  size_t index = index_array[i];
327  if (index >= tag->vertexCount)
328  {
329  ptr = tag->defaultValue;
330  if (!ptr)
331  {
333  return;
334  }
335  }
336  else
337  {
338  ptr = data + index * tag->desc.size;
339  }
340 
341  memcpy( iter, ptr, tag->desc.size );
342  iter += tag->desc.size;
343  }
344 }
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
blockLoc i
Definition: read.cpp:79
Specified tag does not exist.
msq_std::vector< TagData * > tagList
for(;;)

Here is the call graph for this function:

Here is the caller graph for this function:

void get_vertex_data ( size_t  tag_handle,
size_t  num_indices,
const size_t *  elem_indices,
void *  tag_data,
MsqError err 
) const

Get tag data on vertices.

size_t handle ( const msq_std::string &  name,
MsqError err 
) const

Get tag index from name.

size_t handle ( const msq_std::string &  name,
MsqError err 
) const

Get tag index from name.

Definition at line 138 of file Mesh/MeshImplTags.cpp.

References i, and MeshImplTags::tagList.

Referenced by MeshImplTags::create(), rflo_initgenxinterface(), rflu_modrocstaradmin::rflu_genx_initrocman(), MeshImpl::tag_get(), MeshImpl::vtk_read_cell_data(), and MeshImpl::vtk_read_point_data().

139 {
140  for (size_t i = 0; i < tagList.size(); ++i)
141  if (tagList[i] && tagList[i]->desc.name == name)
142  return i+1;
143 
144  return 0;
145 }
blockLoc i
Definition: read.cpp:79
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

const TagDescription& properties ( size_t  tag_handle,
MsqError err 
) const

Get tag properties.

const TagDescription & properties ( size_t  tag_handle,
MsqError err 
) const

Get tag properties.

Definition at line 147 of file Mesh/MeshImplTags.cpp.

References MsqError::INVALID_ARG, MSQ_SETERR, and MeshImplTags::tagList.

Referenced by MeshImpl::read_vtk(), MeshImpl::tag_properties(), MeshImpl::vtk_read_cell_data(), MeshImpl::vtk_read_point_data(), and MeshImpl::write_vtk().

148 {
149  static TagDescription dummy_desc;
150  --tag_index;
151 
152  if (tag_index >= tagList.size() || !tagList[tag_index])
153  {
154  MSQ_SETERR(err)("Invalid tag handle", MsqError::INVALID_ARG);
155  return dummy_desc;
156  }
157 
158  return tagList[tag_index]->desc;
159 }
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

void set_element_data ( size_t  tag_handle,
size_t  num_indices,
const size_t *  elem_indices,
const void *  tag_data,
MsqError err 
)

Set tag data on elements.

Definition at line 162 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::TagData::defaultValue, MeshImplTags::TagData::desc, MeshImplTags::TagData::elementCount, MeshImplTags::TagData::elementData, i, MsqError::INVALID_ARG, MSQ_SETERR, TagDescription::size, and MeshImplTags::tagList.

Referenced by MeshImpl::tag_set_element_data(), and MeshImpl::vtk_read_cell_data().

167 {
168  size_t i;
169  char* data;
170  --tag_index;
171  if (tag_index >= tagList.size() || !tagList[tag_index])
172  {
173  MSQ_SETERR(err)("Invalid tag handle", MsqError::INVALID_ARG);
174  return;
175  }
176 
177  TagData* tag = tagList[tag_index];
178 
179  // Get highest element index
180  size_t total = tag->elementCount;
181  for (i = 0; i < num_indices; ++i)
182  if (index_array[i] >= total)
183  total = index_array[i] + 1;
184 
185  // If need more space
186  if (total > tag->elementCount)
187  {
188  // allocate more space
189  tag->elementData = realloc( tag->elementData, tag->desc.size * total );
190  // if a default value, initialize new space with it
191  if (tag->defaultValue)
192  {
193  data = ((char*)tag->elementData) + tag->elementCount * tag->desc.size;
194  for (i = tag->elementCount; i < total; ++i)
195  {
196  memcpy( data, tag->defaultValue, tag->desc.size );
197  data += tag->desc.size;
198  }
199  }
200  tag->elementCount = total;
201  }
202 
203  // Store passed tag values
204  data = (char*)tag->elementData;
205  const char* iter = (const char*)values;
206  for (i = 0; i < num_indices; ++i)
207  {
208  memcpy( data + index_array[i]*tag->desc.size, iter, tag->desc.size );
209  iter += tag->desc.size;
210  }
211 }
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
blockLoc i
Definition: read.cpp:79
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

void set_element_data ( size_t  tag_handle,
size_t  num_indices,
const size_t *  elem_indices,
const void *  tag_data,
MsqError err 
)

Set tag data on elements.

void set_vertex_data ( size_t  tag_handle,
size_t  num_indices,
const size_t *  elem_indices,
const void *  tag_data,
MsqError err 
)

Set tag data on vertices.

Definition at line 254 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::TagData::defaultValue, MeshImplTags::TagData::desc, i, MsqError::INVALID_ARG, MSQ_SETERR, TagDescription::size, MeshImplTags::tagList, MeshImplTags::TagData::vertexCount, and MeshImplTags::TagData::vertexData.

Referenced by MeshImpl::tag_set_vertex_data(), and MeshImpl::vtk_read_point_data().

259 {
260  size_t i;
261  char* data;
262  --tag_index;
263  if (tag_index >= tagList.size() || !tagList[tag_index])
264  {
265  MSQ_SETERR(err)("Invalid tag handle", MsqError::INVALID_ARG);
266  return;
267  }
268 
269  TagData* tag = tagList[tag_index];
270 
271  // Get highest element index
272  size_t total = tag->vertexCount;
273  for (i = 0; i < num_indices; ++i)
274  if (index_array[i] >= total)
275  total = index_array[i] + 1;
276 
277  // If need more space
278  if (total > tag->vertexCount)
279  {
280  // allocate more space
281  tag->vertexData = realloc( tag->vertexData, tag->desc.size * total );
282  // if a default value, initialize new space with it
283  if (tag->defaultValue)
284  {
285  data = ((char*)tag->vertexData) + tag->vertexCount * tag->desc.size;
286  for (i = tag->vertexCount; i < total; ++i)
287  {
288  memcpy( data, tag->defaultValue, tag->desc.size );
289  data += tag->desc.size;
290  }
291  }
292  tag->vertexCount = total;
293  }
294 
295  // Store passed tag values
296  data = (char*)tag->vertexData;
297  const char* iter = (const char*)values;
298  for (i = 0; i < num_indices; ++i)
299  {
300  memcpy( data + index_array[i]*tag->desc.size, iter, tag->desc.size );
301  iter += tag->desc.size;
302  }
303 }
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
blockLoc i
Definition: read.cpp:79
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

void set_vertex_data ( size_t  tag_handle,
size_t  num_indices,
const size_t *  elem_indices,
const void *  tag_data,
MsqError err 
)

Set tag data on vertices.

static size_t size_from_tag_type ( Mesh::TagType  type)
static

Get the size of the passed data type.

size_t size_from_tag_type ( Mesh::TagType  type)
static

Get the size of the passed data type.

Definition at line 58 of file Mesh/MeshImplTags.cpp.

References Mesh::BOOL, Mesh::BYTE, Mesh::DOUBLE, Mesh::HANDLE, and Mesh::INT.

Referenced by MeshImplTags::create(), MeshImpl::tag_properties(), and MeshImpl::vtk_write_attrib_data().

59 {
60  switch( type ) {
61  case Mesh::BYTE: return 1;
62  case Mesh::BOOL: return sizeof(bool);
63  case Mesh::DOUBLE: return sizeof(double);
64  case Mesh::INT: return sizeof(int);
65  case Mesh::HANDLE: return sizeof(void*);
66  default: assert(0); return 0;
67  }
68 }

Here is the caller graph for this function:

TagIterator tag_begin ( )

Definition at line 372 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::tagList.

Referenced by MeshImpl::write_vtk().

373 {
374  size_t index = 0;
375  while (index < tagList.size() && tagList[index] == NULL)
376  ++index;
377  return TagIterator( this, index );
378 }
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

TagIterator tag_end ( )
inline

Definition at line 210 of file src/Mesh/MeshImplTags.hpp.

References MeshImplTags::tagList.

210 { return TagIterator(this,tagList.size()); }
msq_std::vector< TagData * > tagList
TagIterator tag_end ( )
inline

Definition at line 210 of file includeLinks/MeshImplTags.hpp.

References MeshImplTags::tagList.

Referenced by MeshImpl::write_vtk().

210 { return TagIterator(this,tagList.size()); }
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

bool tag_has_element_data ( size_t  index,
MsqError err 
)

Check if any elements have tag.

Definition at line 359 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::TagData::defaultValue, MeshImplTags::TagData::elementData, MsqError::INVALID_ARG, MSQ_SETERR, and MeshImplTags::tagList.

Referenced by MeshImpl::write_vtk().

360 {
361  --tag_index;
362  if (tag_index >= tagList.size() || !tagList[tag_index])
363  {
364  MSQ_SETERR(err)("Invalid tag handle", MsqError::INVALID_ARG);
365  return false;
366  }
367 
368  TagData* tag = tagList[tag_index];
369  return 0 != tag->elementData || tag->defaultValue;
370 }
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

bool tag_has_element_data ( size_t  index,
MsqError err 
)

Check if any elements have tag.

bool tag_has_vertex_data ( size_t  index,
MsqError err 
)

Check if any vertices have tag.

bool tag_has_vertex_data ( size_t  index,
MsqError err 
)

Check if any vertices have tag.

Definition at line 346 of file Mesh/MeshImplTags.cpp.

References MeshImplTags::TagData::defaultValue, MsqError::INVALID_ARG, MSQ_SETERR, MeshImplTags::tagList, and MeshImplTags::TagData::vertexData.

Referenced by MeshImpl::read_vtk(), and MeshImpl::write_vtk().

347 {
348  --tag_index;
349  if (tag_index >= tagList.size() || !tagList[tag_index])
350  {
351  MSQ_SETERR(err)("Invalid tag handle", MsqError::INVALID_ARG);
352  return false;
353  }
354 
355  TagData* tag = tagList[tag_index];
356  return 0 != tag->vertexData || tag->defaultValue;
357 }
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
msq_std::vector< TagData * > tagList

Here is the caller graph for this function:

Friends And Related Function Documentation

Definition at line 219 of file includeLinks/MeshImplTags.hpp.

Member Data Documentation


The documentation for this class was generated from the following files: