47 #include "FileTokenizer.hpp"
48 #include "Vector3D.hpp"
52 #include "MsqDebug.hpp"
53 #include "MsqError.hpp"
55 #ifdef MSQ_USE_OLD_STD_HEADERS
67 #ifdef MSQ_USE_OLD_IO_HEADERS
78 #ifdef MSQ_USING_EXODUS
82 #include "MsqDebug.hpp"
108 ofstream file(out_filename);
116 file <<
"# vtk DataFile Version 2.0\n";
117 file <<
"Mesquite Mesh\n";
119 file <<
"DATASET UNSTRUCTURED_GRID\n";
131 file << coords[0] <<
' ' << coords[1] <<
' ' << coords[2] <<
'\n';
132 vertex_indices[
i] = count++;
144 msq_std::vector<VertexHandle> conn;
149 if (count > conn.size())
170 for (i = 0; i < count; ++
i)
171 file <<
' ' << vertex_indices[(
size_t)conn[
i]];
187 case TRIANGLE: type = count == 6 ? 22 : 5;
break;
189 case TETRAHEDRON: type = count == 10 ? 24 : 10;
break;
190 case HEXAHEDRON: type = count == 20 ? 25 : 12;
break;
191 case PRISM: type = 13;
break;
192 case PYRAMID: type = 14;
break;
195 "Cannot write element type %d to a VTK file\n",
201 file << type <<
'\n';
202 e_iter->operator++();
208 <<
"\nSCALARS fixed bit\nLOOKUP_TABLE default\n";
225 std::vector<char>::iterator iter = tagdata.begin();
265 std::vector<char>::iterator iter = tagdata.begin();
291 #ifndef MSQ_USING_EXODUS
293 MSQ_DBGOUT(1) <<
"Cannot read ExodusII file: " << in_filename <<
"\n";
299 int app_float_size =
sizeof(double);
300 int file_float_size = 0;
301 float exo_version = 0;
305 int file_id = ex_open(in_filename, EX_READ, &app_float_size,
306 &file_float_size, &exo_version);
316 if (file_float_size !=
sizeof(
double))
318 MSQ_SETERR(err)(
"File saved with float-sized reals. Can only read files "
323 char title[MAX_LINE_LENGTH];
324 int dim, vert_count, elem_count, block_count, ns_count, ss_count;
327 exo_err = ex_get_init(file_id, title, &dim, &vert_count,
328 &elem_count, &block_count, &ns_count, &ss_count);
331 MSQ_SETERR(err)(
"Unable to get entity counts from file.",
342 msq_std::vector<double> coords(vert_count * 3);
343 double* x_iter = &coords[0];
344 double* y_iter = &coords[vert_count];
345 double* z_iter = &coords[2*vert_count];
349 exo_err = ex_get_coord( file_id, x_iter, y_iter, 0 );
350 memset( z_iter, 0,
sizeof(
double)*vert_count );
354 exo_err = ex_get_coord( file_id, x_iter, y_iter, z_iter );
359 MSQ_SETERR(err)(
"Unable to retrieve vertex coordinates from file.",
366 for (i = 0; i < vert_count; ++
i)
372 msq_std::vector<int> block_ids(block_count);
373 exo_err = ex_get_elem_blk_ids(file_id, &block_ids[0]);
381 msq_std::vector<int> conn;
383 for (i = 0; i < block_count; i++)
386 char elem_type_str[MAX_STR_LENGTH];
387 int num_block_elems, verts_per_elem, num_atts;
388 exo_err = ex_get_elem_block(file_id, block_ids[i], elem_type_str,
389 &num_block_elems, &verts_per_elem,
399 for (
int j = 0;
j < 3;
j++)
400 elem_type_str[
j] = toupper(elem_type_str[
j]);
401 if (!strncmp(elem_type_str,
"TRI", 3))
405 else if (!strncmp(elem_type_str,
"QUA", 3) ||
406 !strncmp(elem_type_str,
"SHE", 3))
410 else if (!strncmp(elem_type_str,
"HEX", 3))
414 else if (!strncmp(elem_type_str,
"TET", 3))
420 MSQ_SETERR(err)(
"Unrecognized element type in block",
425 if (conn.size() < (unsigned)(num_block_elems*verts_per_elem))
426 conn.resize( num_block_elems*verts_per_elem );
427 exo_err = ex_get_elem_conn( file_id, block_ids[i], &conn[0] );
430 MSQ_SETERR(err)(
"Unable to read element block connectivity.",
435 msq_std::vector<size_t> vertices(verts_per_elem);
436 msq_std::vector<int>::iterator conn_iter = conn.begin();
437 for (
const size_t end = index + num_block_elems; index < end; ++index)
439 for (msq_std::vector<size_t>::iterator iter = vertices.begin();
440 iter != vertices.end(); ++iter, ++conn_iter)
441 *iter = *conn_iter - 1;
448 int num_fixed_nodes=0;
449 int num_dist_in_set=0;
451 exo_err=ex_get_node_set_param(file_id,111,&num_fixed_nodes,
454 MSQ_PRINT(1)(
"\nError opening nodeset 111, no boundary nodes marked.");
458 msq_std::vector<int> fixed_nodes(num_fixed_nodes);
459 exo_err = ex_get_node_set(file_id, 111, &fixed_nodes[0]);
465 for (i=0; i < num_fixed_nodes; ++
i)
471 exo_err=ex_close(file_id);
481 #ifndef MSQ_USING_EXODUS
482 MSQ_SETERR(err)(
"Exodus not enabled in this build of Mesquite",
484 MSQ_DBGOUT(1) <<
"Cannot read ExodusII file: " << out_filename <<
"\n";
488 if (!myMesh || !myMesh->num_vertices())
490 MSQ_SETERR(err)(
"No vertices in MeshImpl. Nothing written to file.",
499 const unsigned MAX_NODES = 27;
500 const unsigned MIN_NODES = 2;
501 int counts[
MIXED][MAX_NODES+1];
502 memset( counts, 0,
sizeof(counts) );
504 for (i = 0; i < myMesh->max_element_index(); ++
i)
506 if (!myMesh->is_element_valid(i))
510 unsigned nodes = myMesh->element_connectivity(i, err).size();
MSQ_ERRRTN(err);
511 if ((
unsigned)type >=
MIXED || nodes < MIN_NODES || nodes > MAX_NODES)
516 ++counts[type][nodes];
521 for (i = 0; i <
MIXED; ++
i)
522 for (j = MIN_NODES; j < MAX_NODES; ++
j)
527 int num_fixed_nodes=0;
528 for (i = 0; i < myMesh->max_vertex_index(); ++
i)
530 bool fixed = myMesh->is_vertex_valid(i) &&
531 myMesh->vertex_is_fixed(i, err);
MSQ_ERRRTN(err);
532 num_fixed_nodes += fixed;
537 int app_float_size =
sizeof(double);
538 int file_float_size =
sizeof(double);
542 int file_id = ex_create(out_filename, EX_CLOBBER, &app_float_size,
552 char title[MAX_LINE_LENGTH]=
"Mesquite Export";
557 get_all_sizes(vert_count, elem_count, temp_var, err);
560 if(num_fixed_nodes>0)
565 exo_err = ex_put_init(file_id, title, numCoords, vert_count,
566 elem_count, block_count, ns_count, ss_count);
575 msq_std::vector<double> coords(vert_count * 3);
576 msq_std::vector<double>::iterator
x,
y,
z;
580 for (i = 0; i < myMesh->max_vertex_index(); ++
i)
582 if (!myMesh->is_vertex_valid(i))
585 if (z == coords.end())
592 *x = coords.
x(); ++
x;
593 *y = coords.
y(); ++
y;
594 *z = coords.
z(); ++
z;
596 if(z != coords.end())
602 exo_err = ex_put_coord(file_id, &coords[0], &coords[vert_count], &coords[2*vert_count]);
610 char* coord_names[] = {
"x",
"y",
"z" };
611 exo_err = ex_put_coord_names(file_id, coord_names);
614 const char* tri_name =
"TRI";
615 const char* quad_name =
"SHELL";
616 const char* tet_name =
"TETRA";
617 const char* hex_name =
"HEX";
618 const char* wdg_name =
"PRISM";
619 const char* pyr_name =
"PYR";
620 const char* exo_names[
MIXED];
621 memset( exo_names, 0,
sizeof(exo_names) );
626 exo_names[
PRISM] = wdg_name;
628 unsigned min_nodes[
MIXED];
629 memset( min_nodes, 0,
sizeof(min_nodes) );
634 min_nodes[
PRISM] = 6;
641 msq_std::vector<int> conn;
642 for (i = 0; i <
MIXED; ++
i)
644 for (j = MIN_NODES; j < MAX_NODES; ++
j)
654 "Element topology %d not supported by ExodusII", (int)i );
659 if (j == min_nodes[i])
660 strcpy( name_buf, exo_names[i] );
662 sprintf( name_buf,
"%s%d", exo_names[i], (
int)j );
666 exo_err = ex_put_elem_block( file_id, block_id, name_buf,
667 counts[i][j], j, num_atts );
675 conn.resize( counts[i][j] * j );
676 std::vector<int>::iterator iter = conn.begin();
677 for (k = 0; k < myMesh->max_element_index(); ++
k)
680 if (!myMesh->is_element_valid(k) ||
681 (unsigned)(myMesh->element_topology(k, err)) != i)
686 const msq_std::vector<size_t>& elem_conn = myMesh->element_connectivity(k, err);
688 if (elem_conn.size() !=
j)
692 for (msq_std::vector<size_t>::const_iterator citer = elem_conn.begin();
693 citer != elem_conn.end(); ++citer, ++iter)
695 assert(iter != conn.end());
701 if (iter != conn.end())
708 exo_err = ex_put_elem_conn( file_id, block_id, &conn[0] );
719 if(num_fixed_nodes>0){
720 exo_err=ex_put_node_set_param(file_id, 111, num_fixed_nodes, 0);
727 msq_std::vector<int> fixed_nodes( num_fixed_nodes );
728 msq_std::vector<int>::iterator iter = fixed_nodes.begin();
729 for (i = 0; i < myMesh->max_vertex_index(); ++
i)
731 if (!myMesh->is_vertex_valid(i))
735 if (myMesh->vertex_is_fixed( i, err ))
737 if (iter == fixed_nodes.end())
747 if (iter != fixed_nodes.end())
753 exo_err=ex_put_node_set(file_id, 111, &fixed_nodes[0]);
759 exo_err=ex_close(file_id);
773 size_t& element_count,
774 size_t& vertex_use_count,
784 size_t* elem_conn_offsets,
size_t offset_len,
785 size_t* elem_conn_indices,
size_t index_len,
788 if (vert_len < myMesh->num_vertices() ||
789 elem_len < myMesh->num_elements() ||
790 offset_len < myMesh->num_elements()+1 ||
791 index_len < myMesh->num_vertex_uses()) {
806 for (
size_t i = 0;
i < count; ++
i)
856 for (
size_t i=0;
i<num_vtx; ++
i)
870 for (
size_t i=0;
i<num_vtx; ++
i) {
894 vertices_set_byte( &vertex, &byte, 1, err );
MSQ_CHKERR(err);
898 unsigned char *byte_array,
902 for (
size_t i = 0;
i < array_size;
i++)
920 unsigned char *byte_array,
924 for (
size_t i = 0;
i < array_size;
i++)
946 size_t sizeof_elem_array,
949 const msq_std::vector<size_t>& elems
952 if (sizeof_elem_array < elems.size())
958 memcpy( elem_array, &elems[0], elems.size() *
sizeof(size_t) );
1010 size_t& sizeof_vert_handles,
1012 size_t& sizeof_csr_data,
1013 size_t* csr_offsets,
1021 size_t elem = (size_t)elem_handles[0];
1022 const msq_std::vector<size_t>& conn
1026 if (conn.size() > sizeof_vert_handles ||
1027 conn.size() > sizeof_csr_data )
1029 sizeof_vert_handles = sizeof_csr_data = conn.size();
1034 memcpy( vert_handles, &conn[0],
sizeof(
size_t)*conn.size() );
1036 csr_offsets[1] = conn.size();
1037 for (
size_t j = 0;
j < conn.size(); ++
j)
1044 size_t vtx_count = 0;
1045 size_t use_count = 0;
1047 msq_std::map<size_t, size_t> index_map;
1048 for (
size_t i = 0;
i < num_elems; ++
i)
1050 size_t elem = (size_t)elem_handles[
i];
1051 const msq_std::vector<size_t>& conn
1054 csr_offsets[
i] = use_count;
1056 for (
size_t j = 0;
j < conn.size(); ++
j)
1059 size_t vert = conn[
j];
1060 msq_std::map<size_t, size_t>::const_iterator iter = index_map.find( vert );
1061 if (iter == index_map.end())
1064 if (idx < sizeof_vert_handles)
1066 index_map[vert] = idx;
1073 if (use_count < sizeof_csr_data)
1074 csr_data[use_count] = idx;
1078 csr_offsets[num_elems] = use_count;
1080 if (vtx_count > sizeof_vert_handles ||
1081 use_count > sizeof_csr_data )
1086 sizeof_vert_handles = vtx_count;
1087 sizeof_csr_data = use_count;
1095 const msq_std::vector<size_t>& conn
1097 if (conn.size() > array_size)
1102 memcpy( vert_array, &conn[0], conn.size() *
sizeof(
VertexHandle) );
1118 size_t num_elements,
1121 for (
size_t i = 0;
i < num_elements;
i++)
1123 element_topologies[
i] =
myMesh->
1124 element_topology( (
size_t)element_handle_array[
i], err );
1172 char vendor_string[257];
1175 FILE* file =
fopen( filename,
"r" );
1184 if (!fgets( vendor_string,
sizeof(vendor_string), file ))
1191 if (!strchr( vendor_string,
'\n' ) ||
1192 2 != sscanf( vendor_string,
"# vtk DataFile Version %d.%d", &major, &minor ))
1199 if (!fgets( vendor_string,
sizeof(vendor_string), file ))
1207 if (!strchr( vendor_string,
'\n' ))
1209 MSQ_SETERR(err)(
"Vendor string (line 2) exceeds 256 characters.",
1219 const char*
const file_type_names[] = {
"ASCII",
"BINARY", 0 };
1221 if (2 == filetype) {
1222 MSQ_SETERR(err)(
"Cannot read BINARY VTK files -- use ASCII.",
1242 const char*
const block_type_names[] = {
"POINT_DATA",
"CELL_DATA", 0 };
1244 while (!tokens.
eof())
1247 int new_block_type = tokens.
match_token( block_type_names, err );
1269 blocktype = new_block_type;
1276 "Count inconsistent with number of vertices"
1283 "Count inconsistent with number of elements"
1312 switch( tag_desc.
type )
1364 const char*
const data_type_names[] = {
"STRUCTURED_POINTS",
1366 "UNSTRUCTURED_GRID",
1388 double origin[3], space[3];
1394 if (dims[0] < 1 || dims[1] < 1 || dims[2] < 1)
1397 "Invalid dimension at line %d",
1406 const char*
const spacing_names[] = {
"SPACING",
"ASPECT_RATIO", 0 };
1413 Vector3D off( origin[0], origin[1], origin[2] );
1414 for (k = 0; k < dims[2]; ++
k)
1415 for (j = 0; j < dims[1]; ++
j)
1416 for (i = 0; i < dims[0]; ++
i)
1427 long num_verts, dims[3];
1433 if (dims[0] < 1 || dims[1] < 1 || dims[2] < 1)
1436 "Invalid dimension at line %d",
1446 if (num_verts != (dims[0] * dims[1] * dims[2]))
1449 "Point count not consistent with dimensions "
1455 for (
size_t vtx = 0; vtx < (size_t)num_verts; ++vtx)
1469 const char* labels[] = {
"X_COORDINATES",
"Y_COORDINATES",
"Z_COORDINATES" };
1470 vector<double> coords[3];
1476 if (dims[0] < 1 || dims[1] < 1 || dims[2] < 1)
1479 "Invalid dimension at line %d",
1484 for (i = 0; i < 3; i++)
1492 if (count != dims[i])
1495 "Coordinate count inconsistent with dimensions"
1500 coords[
i].resize(count);
1506 for (k = 0; k < dims[2]; ++
k)
1507 for (j = 0; j < dims[1]; ++
j)
1508 for (i = 0; i < dims[0]; ++
i)
1521 vector<int> connectivity;
1522 const char*
const poly_data_names[] = {
"VERTICES",
1536 "Invalid point count at line %d", tokens.
line_number());
1541 for (
size_t vtx = 0; vtx < (size_t)num_verts; ++vtx)
1556 "Unsupported type: triangle strips at line %d",
1562 "Entities of dimension < 2 at line %d",
1575 msq_std::vector<size_t> conn;
1576 assert(
sizeof(
long) ==
sizeof(
size_t));
1578 for (
int i = 0;
i < size[0]; ++
i)
1582 conn.resize( count );
1592 long i, num_verts, num_elems[2];
1602 "Invalid point count at line %d", tokens.
line_number());
1607 for (
size_t vtx = 0; vtx < (size_t)num_verts; ++vtx)
1619 msq_std::vector<size_t> conn;
1620 assert(
sizeof(
long) ==
sizeof(
size_t));
1621 for (i = 0; i < num_elems[0]; ++
i)
1625 conn.resize( count );
1634 if (num_elems[0] != num_elems[1])
1637 "Number of element types does not match number of elements"
1643 const int pixel_swap[] = { 2, 3, -1 };
1644 const int voxel_swap[] = { 2, 3, 6, 7, -1 };
1645 const int wedge_swap[] = { 1, 2, 4, 5, -1 };
1646 const int qhex_swap[] = { 12, 16, 13, 17, 14, 18, 15, 19, -1 };
1647 const struct {
const char* name;
1651 } vtk_cell_types[] = {
1653 {
"vertex",
MIXED, 1, 0 },
1654 {
"polyvertex",
MIXED, 0, 0 },
1655 {
"line",
MIXED, 2, 0 },
1656 {
"polyline",
MIXED, 0, 0 },
1658 {
"triangle strip",
MIXED, 0, 0 },
1665 {
"wedge",
PRISM, 6, wedge_swap },
1674 {
"quadratic tri",
TRIANGLE, 6, 0 },
1677 {
"quadratic hex",
HEXAHEDRON, 20, qhex_swap }
1680 msq_std::vector<size_t> tconn;
1681 for (i = 0; i < num_elems[0]; ++
i)
1688 if ((
unsigned long)type > 25 || !vtk_cell_types[type].name)
1691 "Invalid cell type %ld at line %d.",
1696 if (vtk_cell_types[type].topo ==
MIXED)
1699 "Unsupported cell type %ld (%s) at line %d.",
1700 type, vtk_cell_types[type].name, tokens.
line_number() );
1705 if (vtk_cell_types[type].
swap)
1708 if (vtk_cell_types[type].size != size)
1711 "Cell type %ld (%s) for element with %d nodes at Line %d",
1712 type, vtk_cell_types[type].name, (int)size, tokens.
line_number() );
1717 for (
const int* iter = vtk_cell_types[type].swap; *iter > 0; iter += 2)
1737 int non_zero[3] = {0,0,0};
1741 long edims[3] = { 1, 1, 1 };
1744 for (
int d = 0;
d < 3;
d++)
1747 non_zero[elem_dim++] =
d;
1748 edims[
d] = dims[
d] - 1;
1749 num_elems *= edims[
d];
1751 vert_per_elem = 1 << elem_dim;
1761 MSQ_SETERR(err)(
"Cannot create structured mesh with elements "
1762 "of dimension < 2 or > 3.",
1771 long k = dims[0]*dims[1];
1772 const long corners[8] = { 0, 1, 1+dims[0], dims[0],
k, k+1, k+1+dims[0], k+dims[0] };
1775 msq_std::vector<size_t> conn( vert_per_elem );
1776 size_t elem_idx = 0;
1777 for (
long z = 0;
z < edims[2]; ++
z)
1778 for (
long y = 0;
y < edims[1]; ++
y)
1779 for (
long x = 0;
x < edims[0]; ++
x)
1781 const long index =
x +
y*dims[0] +
z*(dims[0]*dims[1]);
1782 for (
long j = 0;
j < vert_per_elem; ++
j)
1783 conn[
j] = index + corners[
j];
1805 for (
long i = 0;
i < num_arrays; ++
i)
1813 long num_vals = dims[0] * dims[1];
1815 for (
long j = 0;
j < num_vals;
j++)
1828 const char*
const type_names[] = {
"SCALARS",
1832 "TEXTURE_COORDINATES",
1864 "Cannot read field data (line %d).",
1901 "Inconsistent types between element "
1902 "and vertex attributes of same name "
1909 msq_std::vector<size_t> vertex_handles;
1916 vertex_handles.size(),
1955 "Inconsistent types between element "
1956 "and vertex attributes of same name "
1963 msq_std::vector<size_t> element_handles;
1970 element_handles.size(),
1971 &element_handles[0],
1986 size_t count = per_elem * num_elem;
1990 tag.
size = per_elem*
sizeof(bool);
1992 data_ptr = malloc( num_elem*tag.
size );
2003 tag.
size = per_elem*
sizeof(int);
2005 data_ptr = malloc( num_elem*tag.
size );
2010 tag.
size = per_elem*
sizeof(double);
2012 data_ptr = malloc( num_elem*tag.
size );
2013 tokens.
get_doubles( count, (
double*)data_ptr, err );
2041 const char* end = 0;
2042 size = strtol( tok, (
char**)&end, 0 );
2050 if (size < 1 || size > 4)
2053 "Scalar count out of range [1,4]"
2062 if (!strcmp( tok,
"default" ))
2073 vector<long> table( size*count );
2074 if (type > 0 && type < 10)
2081 for (msq_std::vector<long>::iterator iter = table.begin(); iter != table.end(); ++iter)
2088 if ((
double)*iter != data)
2091 "Invalid lookup index (%.0f) at line %d",
2105 vector<float> table_data(table_count*4);
2110 float* data = (
float*)malloc(
sizeof(
float)*count*size*4 );
2111 float* data_iter = data;
2112 for (std::vector<long>::iterator idx = table.begin(); idx != table.end(); ++idx)
2114 if (*idx < 0 || *idx >= table_count)
2117 "LOOKUP_TABLE index %ld out of range.",
2123 for (
int i = 0;
i < 4;
i++)
2125 *data_iter = table_data[4 * *idx +
i];
2130 desc.
size = size * 4 *
sizeof(float);
2146 "Invalid size (%ld) at line %d",
2151 float* data = (
float*)malloc(
sizeof(
float)*count*size );
2159 tag.
size = size*
sizeof(float);
2188 if (dim < 1 || dim > 3)
2191 "Invalid dimension (%d) at line %d.",
2216 const void* data,
size_t count,
2221 MSQ_SETERR(err)(
"Cannot write HANDLE tag data to VTK file.",
2241 const char*
const typenames[] = {
"unsigned_char",
"bit",
"int",
"double" };
2247 num_per_line = vlen;
2248 file <<
"SCALARS " << desc.
name <<
" " << typenames[desc.
type] <<
" " << vlen <<
"\n";
2251 num_per_line = vlen;
2252 file <<
"COLOR_SCALARS " << desc.
name <<
" " << vlen <<
"\n";
2259 "Tag \"%s\" is labeled as a VTK vector attribute but has %u values.",
2260 desc.
name.c_str(), vlen);
2263 file <<
"VECTORS " << desc.
name <<
" " << typenames[desc.
type] <<
"\n";
2270 "Tag \"%s\" is labeled as a VTK normal attribute but has %u values.",
2271 desc.
name.c_str(), vlen);
2274 file <<
"NORMALS " << desc.
name <<
" " << typenames[desc.
type] <<
"\n";
2277 num_per_line = vlen;
2278 file <<
"TEXTURE_COORDINATES " << desc.
name <<
" " << typenames[desc.
type] <<
" " << vlen <<
"\n";
2285 "Tag \"%s\" is labeled as a VTK tensor attribute but has %u values.",
2286 desc.
name.c_str(), vlen);
2289 file <<
"TENSORS " << desc.
name <<
" " << typenames[desc.
type] <<
"\n";
2296 size_t i = 0, total = count*vlen;
2297 char* space =
new char[num_per_line];
2298 memset( space,
' ', num_per_line );
2300 const unsigned char* odata = (
const unsigned char*)data;
2301 const bool* bdata = (
const bool*)data;
2302 const int* idata = (
const int*)data;
2303 const double* ddata = (
const double*)data;
2304 switch ( desc.
type )
2308 file << (
unsigned int)odata[i++] << space[i%num_per_line];
2312 file << (bdata[i++] ?
'1' :
'0') << space[i%num_per_line];
2316 file << idata[i++] << space[i%num_per_line];
2320 file << ddata[i++] << space[i%num_per_line];
2360 msq_std::string& name,
2382 (
const size_t*)elem_array,
2395 (
const size_t*)elem_array,
2408 (
const size_t*)elem_array,
2421 (
const size_t*)elem_array,
An I/O error occured (e.g.
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 swap(int &a, int &b)
int line_number() const
Get the line number the last token was read from.
void unget_token()
Put current token back in buffer.
unsigned char get_vertex_byte(size_t index, MsqError &err) const
Get vertex byte.
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
void all_elements(msq_std::vector< size_t > &list, MsqError &err) const
Get all elements.
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 fix_vertex(size_t index, bool flag, MsqError &err)
Set vertex fixed flag.
void vtk_read_field(FileTokenizer &file, MsqError &err)
Read file-level field data.
size_t max_vertex_index() const
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.
bool match_token(const char *string, MsqError &err)
Match current token to passed string.
void int int REAL REAL * y
Used to hold the error state and return it to the application.
TagType
The type of a tag.
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.
msq_std::string name
Tag name.
Class to store mesh representation for MeshImpl.
VtkType vtkType
Attribute type from VTK file.
const msq_std::vector< size_t > & element_connectivity(size_t index, MsqError &err) const
Get element connectivity list, including mid-nodes.
requested functionality is not (yet) implemented
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.
size_t num_vertices() const
Get number of vertices, does not include mid-nodes.
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
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
void reset_element(size_t index, const msq_std::vector< size_t > &vertices, EntityTopology topology, MsqError &err)
Clear element at specified index (if any) including connectivity and adjacency data, and re-initialize with passed data.
void element_get_connectivity(ElementHandle element, VertexHandle *vert_handles, size_t sizeof_vert_handles, MsqError &err)
bool get_newline(MsqError &err)
check for newline
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.
int fclose(std::FILE *file)
Close a file, and check for possible errors.
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.
bool get_floats(size_t count, float *array, MsqError &err)
Parse a sequence of float values.
void write_vtk(const char *out_filename, Mesquite::MsqError &err)
void allocate_vertices(size_t count, MsqError &err)
Allocate space for specified number of vertices.
double length(Vector3D *const v, int n)
bool get_doubles(size_t count, double *array, MsqError &err)
Parse a sequence of double values.
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 "elem_handles...
const char * get_string(MsqError &err)
get next token
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.
void clear()
Clear all data.
EntityTopology element_topology(size_t index, MsqError &err) const
Get element type.
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
invalid function argument passed
const msq_std::vector< size_t > & vertex_adjacencies(size_t index, MsqError &err) const
Get vertex adjacency list.
NVec< 3, double > Vector3D
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...
#define MSQ_CHKERR(err)
Mesquite's Error Checking macro.
virtual void tag_delete(TagHandle handle, MsqError &err)
Remove a tag and all corresponding data.
VertexIterator for MeshImpl.
void int int int REAL REAL REAL * z
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.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
bool get_long_ints(size_t count, long *array, MsqError &err)
Parse a sequence of integer values.
void set_vertex_coords(size_t index, const Vector3D &coords, MsqError &err)
Set vertex coordinates.
bool is_vertex_valid(size_t index) const
Check if passed vertex index is valid.
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.
size_t max_element_index() const
virtual bool vertex_is_fixed(VertexHandle vertex, MsqError &err)
Returns true or false, indicating whether the vertex is allowed to be repositioned.
const Vector3D & get_vertex_coords(size_t index, MsqError &err) const
Get vertex coordinates.
void set_vertex_byte(size_t index, unsigned char value, MsqError &err)
Set vertex byte.
void vtk_read_cell_data(FileTokenizer &file, MsqError &err)
Read attribute data for elements.
File cannot be opened/created.
virtual int get_geometric_dimension(MsqError &err)
Returns whether this mesh lies in a 2D or 3D coordinate system.
bool vertex_is_fixed(size_t index, MsqError &err) const
Get vertex fixed flag.
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.
const char *const vtk_type_names[]
#define MSQ_PRINT(flag)
Check debug flag and print printf-style formatted output.
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...
object is in an invalid state
void clear()
resets error object to non-active state (no error).
const double * to_array() const
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.
void allocate_elements(size_t count, MsqError &err)
Allocate space for specified number of elements.
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.
ElementIterator for MeshImpl.
virtual bool is_at_end() const =0
Returns false until the iterator has been advanced PAST the last entity.
virtual void release()
Instead of deleting a Mesh when you think you are done, call release().
bool get_booleans(size_t count, bool *array, MsqError &err)
Parse a sequence of bit or boolean values.
void reset_vertex(size_t index, const Vector3D &coords, bool fixed, MsqError &err)
Set allocated but unset veretx to specified values.
#define MSQ_DBGOUT(flag)
Check debug flag and return ostream associated with flag.
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.
void copy_mesh(size_t *vertex_handle_array, size_t *element_hanlde_array, size_t *element_conn_offsets, size_t *element_conn_indices)
Copy internal representation into CSR rep Does not include mid-nodes.
virtual void restart()=0
Moves the iterator back to the first entity in the list.
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...
void all_vertices(msq_std::vector< size_t > &list, MsqError &err) const
Get all vertices, including mid-nodes.
#define MSQ_ERRRTN(err)
If passed error is true, return from a void function.
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.
size_t size
Size of tag data (sizeof(type)*array_length)
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.
std::FILE * fopen(const char *const path, const char *const mode)
Open a file, and check for possible errors.
size_t num_vertex_uses() const
Get number of vertex uses (sum of connectivity length for all elements) Does not count mid-nodes...
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.
bool get_integers(size_t count, int *array, MsqError &err)
Parse a sequence of integer values.
Error parsing input (or input file)
Mesh::TagType type
Tag data type.
bool is_element_valid(size_t index) const
Check if passed element index is valid.
size_t num_elements() const
Get number of elements.
bool eof() const
Check for end-of-file condition.
Parse a file as space-separated tokens.