38 #define VTK_EMPTY_CELL 0
40 #define VTK_POLY_VERTEX 2
42 #define VTK_POLY_LINE 4
43 #define VTK_TRIANGLE 5
44 #define VTK_TRIANGLE_STRIP 6
50 #define VTK_HEXAHEDRON 12
52 #define VTK_PYRAMID 14
53 #define VTK_PENTAGONAL_PRISM 15
54 #define VTK_HEXAGONAL_PRISM 16
57 #define VTK_QUADRATIC_EDGE 21
58 #define VTK_QUADRATIC_TRIANGLE 22
59 #define VTK_QUADRATIC_QUAD 23
60 #define VTK_QUADRATIC_TETRA 24
61 #define VTK_QUADRATIC_HEXAHEDRON 25
62 #define VTK_QUADRATIC_WEDGE 26
63 #define VTK_QUADRATIC_PYRAMID 27
66 #define VTK_CONVEX_POINT_SET 41
69 #define VTK_PARAMETRIC_CURVE 51
70 #define VTK_PARAMETRIC_SURFACE 52
71 #define VTK_PARAMETRIC_TRI_SURFACE 53
72 #define VTK_PARAMETRIC_QUAD_SURFACE 54
73 #define VTK_PARAMETRIC_TETRA_REGION 55
74 #define VTK_PARAMETRIC_HEX_REGION 56
77 #define SwitchOnDataType(dType, funcCall) \
84 case COM_UNSIGNED_CHAR: \
85 { typedef unsigned char TT; \
92 case COM_UNSIGNED_SHORT: \
93 { typedef unsigned short TT; \
101 { typedef unsigned int TT; \
108 case COM_UNSIGNED_LONG: \
109 { typedef unsigned long TT; \
113 { typedef float TT; \
117 { typedef double TT; \
120 case COM_LONG_DOUBLE: \
121 { typedef long double TT; \
147 else if (rtype ==
"t6")
149 else if (rtype ==
"q4")
151 else if (rtype ==
"q8")
153 else if (rtype ==
"T4")
155 else if (rtype ==
"T10")
157 else if (rtype ==
"H8")
159 else if (rtype ==
"B20")
161 else if (rtype ==
"P5")
163 else if (rtype ==
"W6")
165 else if (rtype ==
"P6")
175 template <
typename TT>
177 const int* dims_nodes,
int ghost,
char loc,
180 const int dims[3] = { dims_nodes[0] - (loc ==
'e'),
181 ndims >= 2 ? dims_nodes[1] - (loc ==
'e') : 0,
182 ndims >= 3 ? dims_nodes[2] - (loc ==
'e') : 0 };
184 const int last[3] = { dims[0] - ghost,
185 ndims >= 2 ? dims[1] - ghost : 0,
186 ndims >= 3 ? dims[2] - ghost : 0 };
191 for (i=ghost; i<last[0]; ++
i) {
192 for (c=0; c<nComp; ++c)
193 out << (pData[c] ? pData[c][i] : (TT)-987654321) <<
' ';
199 for (j=ghost; j<last[1]; ++
j)
200 for (i=ghost; i<last[0]; ++
i) {
201 for (c=0; c<nComp; ++c)
202 out << (pData[c] ? pData[c][i+j*dims[0]] : (TT)-987654321) <<
' ';
208 for (k=ghost; k<last[2]; ++
k)
209 for (j=ghost; j<last[1]; ++
j)
210 for (i=ghost; i<last[0]; ++
i) {
211 for (c=0; c<nComp; ++c)
212 out << (pData[c] ? pData[c][i+j*dims[0]+k*dims[0]*dims[1]]
213 : (TT)-987654321) <<
' ';
220 template <
typename TT>
224 for (i=0; i<size; ++
i) {
226 for (c=0; c<nComp; ++c)
227 out << (pData[c] ? pData[c][i] : (TT)-987654321) <<
' ';
242 std::istringstream
sin(ci.
m_type.substr(1));
250 for (elem=0; elem<ne; ++elem) {
260 const std::string& file_in,
bool mesh_only, std::ofstream & out)
262 static std::map<int, std::string> DataTypeAsString;
263 static std::map<std::string, int> COM2VTK;
264 if (DataTypeAsString.empty()) {
265 DataTypeAsString[
COM_CHAR] =
"char";
266 DataTypeAsString[
COM_BYTE] =
"char";
270 DataTypeAsString[
COM_INT] =
"int";
272 DataTypeAsString[
COM_LONG] =
"long";
279 if (COM2VTK.empty()) {
310 std::vector<AttrInfo> attrs(nAttrs+1);
311 attrs[0].m_name =
"nc";
313 &(attrs[0].m_location), &(attrs[0].m_dataType),
314 &(attrs[0].m_numComp), &(attrs[0].m_units));
318 std::istringstream
sin(attrStr);
319 for (i=1; i<nAttrs+1; ++
i) {
320 sin >> attrs[
i].m_name;
322 &(attrs[i].m_location), &(attrs[i].m_dataType),
323 &(attrs[i].m_numComp), &(attrs[i].m_units));
328 std::set<char> locset;
329 std::vector<AttrInfo>::iterator p = attrs.begin();
331 while (p != attrs.end()) {
332 char loc = (*p).m_location;
333 if (loc ==
'w' || loc ==
'p') {
343 for (i=0; i<nPanes; ++
i) {
347 out <<
"# SMF Version 1.1" << std::endl;
350 out <<
"#ASCII" << std::endl;
355 name = wName +
".nc";
364 const int* dims = NULL;
365 int ndims, eTotal = 0, eSize = 0;
366 std::vector<ConnInfo> connInfo(nConn);
367 std::vector<std::pair<int, int> > cellTypes;
368 if (nConn == 1 && strncmp(connNames,
":st", 3) == 0) {
369 name = wName +
'.' + connNames;
373 COM_get_array_const(name.c_str(), paneIds[
i], &dims);
375 out <<
"DATASET STRUCTURED_GRID" << std::endl;
376 out <<
"DIMENSIONS " << dims[0] - 2 * ghost <<
" " << dims[1] - 2 * ghost
377 <<
" " << dims[2] - 2 * ghost << std::endl;
379 eTotal = (dims[0] - 2 * ghost > 1 ? dims[0] - 2 * ghost - 1 : 1)
380 * (dims[1] - 2 * ghost > 1 ? dims[1] - 2 * ghost - 1 : 1)
381 * (dims[2] - 2 * ghost > 1 ? dims[2] - 2 * ghost - 1 : 1);
383 out <<
"#DATASET UNSTRUCTURED_GRID" << std::endl;
385 std::istringstream
sin(connNames);
386 std::vector<ConnInfo>::iterator c;
387 for (c=connInfo.begin(); c!=connInfo.end(); ++c) {
389 (*c).m_name = wName +
'.' + (*c).m_type;
390 (*c).m_type.erase(0, 1);
391 std::string::size_type
x = (*c).m_type.find(
':', 2);
392 if (x != std::string::npos)
393 (*c).m_type.erase(x);
395 COM_get_size((*c).m_name.c_str(), paneIds[
i], &((*c).m_numElements),
397 eTotal += (*c).m_numElements - (*c).m_numGhost;
400 if ((*c).m_type ==
"q9")
403 std::istringstream
sin((*c).m_type.substr(1));
406 eSize += ((*c).m_numElements - (*c).m_numGhost) * (nn + 1);
408 cellTypes.push_back(std::pair<int, int>(COM2VTK[(*c).m_type],
409 (*c).m_numElements - (*c).m_numGhost));
413 out <<
"#POINTS " << nNodes <<
' ' << DataTypeAsString[attrs[0].m_dataType]
415 const void* pArray[9] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
419 for (comp=1; comp<=(*p).m_numComp; ++comp) {
420 std::ostringstream sout;
421 sout << wName <<
'.' << comp <<
'-' << (*p).m_name;
422 COM_get_array_const(sout.str().c_str(), paneIds[
i], &(pArray[comp-1]));
428 ndims, dims, ghost, (*p).m_location,
436 if (nConn != 1 || strncmp(connNames,
":st", 3) != 0) {
437 out <<
"#CELLS " << eTotal <<
' ' << eSize << std::endl;
439 std::vector<ConnInfo>::iterator c;
440 for (c=connInfo.begin(); c!=connInfo.end(); ++c) {
441 const int* pConn = NULL;
442 COM_get_array_const((*c).m_name.c_str(), paneIds[
i], &pConn);
446 out <<
"#CELL_TYPES " << eTotal << std::endl;
460 if (!mesh_only && locset.count(
'n') > 0) {
461 out <<
"#POINT_DATA " << nNodes << std::endl;
462 for (p=attrs.begin(); p!=attrs.end(); ++p) {
463 if ((*p).m_location !=
'n')
466 if ((*p).m_numComp == 1) {
467 COM_get_array_const((wName +
'.' + (*p).m_name).c_str(), paneIds[
i],
472 for (comp=1; comp<=(*p).m_numComp; ++comp) {
473 std::ostringstream sout;
474 sout << wName <<
'.' << comp <<
'-' << (*p).m_name;
475 COM_get_array_const(sout.str().c_str(), paneIds[
i],
478 if ((*p).m_numComp == 3)
484 out << (*p).m_name <<
' ' << DataTypeAsString[(*p).m_dataType]
487 if ((*p).m_numComp == 1)
488 out <<
"#LOOKUP_TABLE default" << std::endl;
493 ndims, dims, ghost, (*p).m_location,
503 if (!mesh_only && locset.count(
'e') > 0) {
504 out << std::endl <<
"#CELL_DATA " << eTotal << std::endl;
505 for (p=attrs.begin(); p!=attrs.end(); ++p) {
506 if ((*p).m_location !=
'e')
509 if ((*p).m_numComp == 1) {
510 COM_get_array_const((wName +
'.' + (*p).m_name).c_str(), paneIds[
i],
515 for (comp=1; comp<=(*p).m_numComp; ++comp) {
516 std::ostringstream sout;
517 sout << wName <<
'.' << comp <<
'-' << (*p).m_name;
518 COM_get_array_const(sout.str().c_str(), paneIds[
i],
521 if ((*p).m_numComp == 3)
527 out << (*p).m_name <<
' ' << DataTypeAsString[(*p).m_dataType]
530 if ((*p).m_numComp == 1)
531 out <<
"LOOKUP_TABLE default" << std::endl;
536 ndims, dims, ghost, (*p).m_location,
554 int main(
int argc,
char* argv[])
558 bool mesh_only =
false;
561 if (std::strcmp(argv[1],
"-meshonly") == 0)
575 std::cerr <<
"Usage: cgns2smf [-meshonly] <cgns file> <smf file>" << std::endl;
579 ofstream outfile(argv[argc-1], ios::out);
587 std::string file_in(argv[argc-2]);
588 std::string win_in(file_in);
589 std::string::size_type st = win_in.find_last_of(
'/');
590 if (st != std::string::npos)
591 win_in.erase(0, st+1);
592 st = win_in.find_first_not_of(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
593 if (st != std::string::npos)
597 char timeStr[16] =
"";
600 std::cout <<
"Reading CGNS file(s) " << file_in
601 <<
" into window " << win_in << std::endl;
607 cerr <<
"Finished reading CGNS file into window\n";
611 std::cout <<
"Printing surface mesh to..." << argv[argc-1] << std::endl;
613 std::cout <<
"Done" << std::endl;
void PrintConn(const int *pConn, const ConnInfo &ci, std::ostream &out)
void COM_get_attribute(const std::string wa_str, char *loc, int *type, int *ncomp, std::string *unit)
void PrintUnstructured(const TT **pData, int nComp, int size, std::ostream &out)
This file contains the prototypes for Roccom API.
void COM_print_window(const char *wName, std::ostream &ostr)
Print a terse human-readable description of this window to this ostream.
void PrintStructured(const TT **pData, int nComp, int ndims, const int *dims_nodes, int ghost, char loc, std::ostream &out)
void COM_set_verbose(int i)
int COM_get_attribute_handle(const char *waname)
void COM_get_connectivities(const char *wname, int pane_id, int *nc, std::string &names)
#define VTK_QUADRATIC_HEXAHEDRON
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
void COM_get_attributes(const char *wname, int *na, std::string &names)
#define VTK_QUADRATIC_QUAD
void COM_get_size(const char *wa_str, int pane_id, int *size, int *ng=0)
Get the sizes of an attribute.
#define VTK_QUADRATIC_TETRA
void COM_set_profiling(int i)
void COM_call_function(const int wf, int argc,...)
Rocin creates a series of Roccom windows by reading in a list of files.
int main(int argc, char *argv[])
#define SwitchOnDataType(dType, funcCall)
#define VTK_QUADRATIC_TRIANGLE
void COM_init(int *argc, char ***argv)
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
void COM_free_buffer(int **buf)
bool rocElement2SMF(string rtype, string &etype)
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
int COM_get_function_handle(const char *wfname)
#define COM_EXTERN_MODULE(moduleName)
std::vector< int > paneIds
Array of paneIds.