Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hdf2pltV2.C File Reference

This utility converts a set of HDF files to a single multi-zone TECPLOT file to visualize within tecplot. More...

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include "TAIL.H"
#include "PrimitiveTypes.H"
#include "roccom.h"
#include "PaneConnectivity.hpp"
#include "MeshPointIdToGlobalIdMap.hpp"
Include dependency graph for hdf2pltV2.C:

Go to the source code of this file.

Enumerations

enum  DataItemType { NODEDATA, CELLDATA }
 The data item type. More...
 

Functions

 COM_EXTERN_MODULE (Rocin)
 
 COM_EXTERN_MODULE (Rocmap)
 
void showUsage ()
 Displays usage information to Standard-out about the different switches and command line arguments that can be used with this program. More...
 
void parseArguments (int argc, char **argv)
 Parses the command line arguments. More...
 
std::string getWindow ()
 Loads the set of HDF files into a single window. More...
 
void writePlotFile ()
 Generates a single zone plot file from the stitched mesh. More...
 
void printWindow (const std::string &windowName)
 Prints the window with the given name. More...
 
std::string convertWindow (const std::string &wname)
 Converts the window from block-structured format to unstructured format. More...
 
void writeVtkFiles (std::vector< Mesh::UnstructuredMesh > &m)
 Writes the set of meshes into separate VTK files that can be visualized with Paraview. More...
 
void getPaneConnnectivity (const std::string &wname)
 This method calls Rocmap to query the pane connectivity information for the given window. More...
 
void maskPoints ()
 This method is called from getPaneConnectivity() to mask the flag the mesh points that are shared on each grid. More...
 
void stitchGrids ()
 This method will stitch the grids into a single, global grid. More...
 
void stitchSolutionData (MeshPointIdToGlobalIdMap *hash)
 This method will stitch the partitioned solution for the single grid. More...
 
int addToGlobalNodeList (const double x, const double y, const double z, std::vector< double > &nodelist)
 This method adds the vertex with the given x,y,z coordinates to the global node list and returns the assigned global id (index). More...
 
void updateHash (const int meshPaneId, const int pointId, const int globalId, MeshPointIdToGlobalIdMap *hash)
 This method updates a MeshPointIdToGlobalIdMap hash with the mesh panes and point IDs mapping to the global ID. More...
 
void writeVtkData ()
 Writes the merged grid and its data in VTK UNSTRUCTURED_GRID file format. More...
 
void printVtk (std::vector< double > &vlist, std::vector< std::vector< int > > &elist)
 This method prints the global grid in VTK file format. More...
 
int main (int argc, char **argv)
 Program main. More...
 
void stitchSolutionData (MeshPointIdToGlobalIdMap *hash, MeshPointIdToGlobalIdMap *ehash)
 This method will stitch the partitioned solution for the single grid. More...
 
void getPaneConnectivity (const std::string &wName)
 Computes the pane connectivity using Rocmap. More...
 

Variables

struct {
   bool   readControlFile
 Data is read from the control file. More...
 
   bool   withGhost
 Ghost nodes will be used. More...
 
   bool   blocks
 Input data is block-structured grid. More...
 
   bool   vtk
 Writes vtk files. More...
 
   std::string   cntrlfile
 Control file string. More...
 
   std::string   fileregx
 File regular expression. More...
 
   std::string   outputfile
 Output file to write the file. More...
 
   std::string   prgmname
 The program name. More...
 
   int   numberOfPanes
 The number of panes, aka number of sub-domains. More...
 
   std::vector< int >   paneIds
 Array of paneIds. More...
 
   std::vector
< Mesh::UnstructuredMesh >   meshes
 The list of grids to write. More...
 
   std::vector< std::vector< bool > >   mask
 Masks the points that are shared (true) share (false) not shared. More...
 
   std::vector< SolnMetaData >   smdv
 The solution Metadata. More...
 
   std::vector< std::vector
< std::vector< double > > >   solution
 The solution data. More...
 
   std::vector< PaneConnectivity >   pconns
 Inter-zone (pane) connectivity information. More...
 
   std::map< int, int >   paneIds2index
 Maps the pane ids to the index in the corresponding vectors. More...
 
   std::vector< std::vector
< double > >   globalSolution
 Contains the global solution. More...
 
   std::vector< bool >   solutionignore
 Masks the data to be ignored. More...
 
   std::vector< double >   globalNodeList
 The global node list. More...
 
   std::vector< std::vector< int > >   globalElementList
 The global element list. More...
 
Program
 

Detailed Description

This utility converts a set of HDF files to a single multi-zone TECPLOT file to visualize within tecplot.

Note
Based on the initial hdf2plt base-code.
Date
Aug 3, 2009
Author
George Zagaris (gzaga.nosp@m.ris@.nosp@m.illin.nosp@m.ois..nosp@m.edu)

Definition in file hdf2pltV2.C.

Enumeration Type Documentation

The data item type.

Enumerator
NODEDATA 
CELLDATA 

Definition at line 40 of file hdf2pltV2.C.

Function Documentation

int addToGlobalNodeList ( const double  x,
const double  y,
const double  z,
std::vector< double > &  nodelist 
)

This method adds the vertex with the given x,y,z coordinates to the global node list and returns the assigned global id (index).

Parameters
xthe x–coordinate of the vector being added.
ythe y–coordinate of the vector being added.
zthe z–coordinate of the vector being added.
nodelistthe global node list where the new node will be inserted.
Returns
GlobalID the global id of the vertex added.
Postcondition
nodelist.size( ) is incremented by 3.
GlobalID >= 0.

Definition at line 951 of file hdf2pltV2.C.

Referenced by stitchGrids().

952 {
953  nodelist.push_back( x );
954  nodelist.push_back( y );
955  nodelist.push_back( z );
956 
957  return( (nodelist.size( )/3)-1 );
958 }
void int int REAL REAL * y
Definition: read.cpp:74
void int int int REAL REAL REAL * z
Definition: write.cpp:76
void int int REAL * x
Definition: read.cpp:74

Here is the caller graph for this function:

COM_EXTERN_MODULE ( Rocin  )
COM_EXTERN_MODULE ( Rocmap  )
std::string convertWindow ( const std::string &  wName)

Converts the window from block-structured format to unstructured format.

Utilizes Roctail to convert the panes to an unstructured grid format.

This function is called iff -block-structured is supplied to the command line.

Parameters
wnamethe name of the window.
Returns
newWindowName the name of the window that contains the grids in an unstructured format.
Parameters
wNamethe window name.
Returns
S new window name which holds the unstructured mesh data.

Definition at line 1422 of file hdf2pltV2.C.

References COM_new_window(), COM_window_init_done(), i, and Program.

Referenced by printWindow().

1423 {
1424 
1425  std::cout << "\n\n\n";
1426  std::cout << "Converting window to Unstructured mesh...";
1427  std::cout.flush( );
1428 
1429  TAIL_Window2UnstructuredMesh( wName, Program.meshes, Program.smdv, Program.solution, 0, true );
1430 
1431  std::cout << "[DONE]\n";
1432 
1433 // for( int i=0; i < Program.solution.size( ); ++i )
1434 // {
1435 // std::cout << "I: " << i << std::endl;
1436 // for( int j=0; j < Program.solution[ i ].size( ); ++j )
1437 // {
1438 // std::cout << "\tJ: " << j << " Name: " << Program.smdv[ j ].name << " Location: " << Program.smdv[ j ].loc;
1439 // std::cout << " Number of components: " << Program.smdv[ j ].ncomp << std::endl;
1440 // for( int k=0; k < Program.solution[ i ][ j ].size( ); ++k )
1441 // {
1442 // std::cout << "\t\t k[" << k << "]:" << Program.solution[ i ][ j ][ k ] << std::endl;
1443 // }
1444 // }
1445 // }
1446 // assert( false );
1447 
1448  #ifdef ASSERT_ON
1449  assert( Program.meshes.size( ) == Program.numberOfPanes );
1450  #endif
1451 
1452  std::string newWindow( "unstructured" );
1453  COM_new_window( newWindow.c_str( ) );
1454 
1455  for( int i=0; i < Program.meshes.size( ); ++i )
1456  {
1457  TAIL_UnstructuredMesh2Pane( newWindow, Program.paneIds[ i ],
1458  Program.meshes[ i ], Program.smdv[ i ], Program.solution[ i ], 0 );
1459  }
1460 
1461  COM_window_init_done( newWindow.c_str( ) );
1462 
1463 // #ifdef ASSERT_ON
1464 // assert( Program.solution.size( ) == Program.numberOfPanes );
1465 // for( int i=0; i < Program.solution.size( ); ++i )
1466 // {
1467 // assert( Program.solution[ i ].size( ) == Program.smdv.size( ) );
1468 // for( int j=0; j < Program.solution[ i ].size( ); ++j )
1469 // {
1470 // assert( Program.solution[ i ][ j ].size( ) > 0 );
1471 // }
1472 // }
1473 // #endif
1474 
1475  return newWindow;
1476 }
blockLoc i
Definition: read.cpp:79
struct globarg Program
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86

Here is the call graph for this function:

Here is the caller graph for this function:

void getPaneConnectivity ( const std::string &  wName)

Computes the pane connectivity using Rocmap.

Note
Based on Rocmap's User/Developer guid.
Parameters
wnamethe window name.

Definition at line 1302 of file hdf2pltV2.C.

References COM_call_function(), COM_get_array(), COM_get_attribute_handle(), COM_get_function_handle(), COM_get_size(), i, maskPoints(), and Program.

Referenced by printWindow().

1303 {
1304 
1305  Program.pconns.resize( Program.numberOfPanes );
1306  std::cout << "Getting the pane connectivity...";
1307 
1308  int MAP_compute_pconn = COM_get_function_handle( "MAP.compute_pconn" );
1309  int mesh_hndl = COM_get_attribute_handle( ( wName + ".mesh" ).c_str( ) );
1310  int pconn_hndl = COM_get_attribute_handle( ( wName + ".pconn" ).c_str( ) );
1311 
1312  COM_call_function( MAP_compute_pconn, &mesh_hndl, &pconn_hndl );
1313 
1314  for( int i=0; i < Program.numberOfPanes; ++i )
1315  {
1316 
1317  /* Get the pconn array */
1318  int *pconn = NULL;
1319  COM_get_array( ( wName + ".pconn" ).c_str( ), /* Window Name (in) */
1320  Program.paneIds[ i ], /* Pane Id (in) */
1321  &pconn ); /* pconn array (in/out) */
1322 
1323  #ifdef ASSERT_ON
1324  assert( pconn != NULL );
1325  #endif
1326 
1327  int size = -1;
1328  int gs = -1;
1329  COM_get_size( ( wName + ".pconn" ).c_str( ), /* Window Name (in) */
1330  Program.paneIds[ i ], /* Pane Id (in) */
1331  &size, /* Size of the pconn array (in/out) */
1332  &gs ); /* ghost node size (in/out) */
1333 
1334  #ifdef ASSERT_ON
1335  assert( size >= 0 );
1336  assert( gs == 0 );
1337  #endif
1338 
1339  Program.pconns[ i ].constructPaneConnectivityFromArray( pconn, size );
1340 
1341  delete [] pconn;
1342  pconn = NULL;
1343  }
1344  std::cout << "[DONE]\n";
1345 
1346  maskPoints( );
1347 
1348 }
void COM_get_array(const char *wa_str, int pane_id, void **addr, int *strd, int *cap)
Get the address for an attribute on a specific pane.
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
void maskPoints()
This method is called from getPaneConnectivity() to mask the flag the mesh points that are shared on ...
Definition: hdf2pltV2.C:1234
blockLoc i
Definition: read.cpp:79
struct globarg Program
void COM_get_size(const char *wa_str, int pane_id, int *size, int *ng=0)
Get the sizes of an attribute.
Definition: roccom_c++.h:274
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428

Here is the call graph for this function:

Here is the caller graph for this function:

void getPaneConnnectivity ( const std::string &  wname)

This method calls Rocmap to query the pane connectivity information for the given window.

A PaneConnectivity object is constructed for each mesh and the shared nodes are flaged for each mesh.

Parameters
wnamethe window name.
See Also
Rocstar::Rocin::Utilities::PaneConnectivity.hpp
std::string getWindow ( )

Loads the set of HDF files into a single window.

Returns a window consisting of the HDF input files.

Each sub-domain, or block, or zone is stored on a separate pane of the window. Moreover, the data layout is changed to contiguous from the default stacked layout of HDF files.

Returns
WindowName the name of the window.
s the window name.
Note
The window layout is changed to contiguous and the number of panes and paneIds is obtained.

Definition at line 1540 of file hdf2pltV2.C.

References globarg::cntrlfile, COM_call_function(), COM_clone_attribute(), COM_delete_attribute(), COM_delete_window(), COM_get_function_handle(), COM_get_panes(), COM_new_window(), COM_window_init_done(), globarg::fileregx, i, Program, and globarg::readControlFile.

Referenced by main().

1541 {
1542  std::string win_in;
1543  if( Program.readControlFile )
1544  win_in = Program.cntrlfile;
1545  else
1546  win_in = Program.fileregx;
1547 
1548  std::string::size_type st = win_in.find_last_of('/');
1549  if (st != std::string::npos)
1550  win_in.erase(0, st+1);
1551  st = win_in.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
1552  if (st != std::string::npos)
1553  win_in.erase(st);
1554 
1555  // Initialize an empty time string
1556  int len = 15;
1557  char timeStr[16];
1558  timeStr[0] = '\0';
1559 
1560  if( Program.readControlFile )
1561  {
1562  std::cout << "Reading by control file " << Program.cntrlfile << " into window " << win_in << "...";
1563  int IN_read = COM_get_function_handle( "IN.read_by_control_file" );
1564  COM_call_function( IN_read,Program.cntrlfile.c_str( ),
1565  win_in.c_str(),NULL,timeStr,&len );
1566  std::cout << "[DONE]\n";
1567 
1568  }
1569  else
1570  {
1571  std::cout << "Reading HDF file(s) " << Program.fileregx << " into window " << win_in << "...";
1572  int IN_read = COM_get_function_handle( "IN.read_window");
1573  COM_call_function( IN_read,Program.fileregx.c_str( ),
1574  win_in.c_str(),NULL,NULL,timeStr,&len );
1575  std::cout << "[DONE]\n";
1576  }
1577 
1578  // Change the memory layout to contiguous
1579  // Taken from from Roctail::TAIL_HDF2Window
1580  std::string win_out( "win_out" );
1581  COM_new_window( win_out.c_str( ) );
1582  COM_clone_attribute( (win_out+".all").c_str(), (win_in+".all").c_str(), 1 );
1583  COM_window_init_done( win_out.c_str( ) );
1584 
1585  // Delete the old memory layout.
1586  COM_delete_attribute(( win_in+".atts").c_str( ) );
1587  COM_delete_window( win_in.c_str( ) );
1588 
1589  // Get the number of panes and the corresponding paneIds
1590  int *paneids = NULL;
1591  COM_get_panes( win_out.c_str(), &(Program.numberOfPanes), &paneids );
1592  Program.paneIds.resize( Program.numberOfPanes );
1593 
1594  // Compute the paneId2index mapping
1595  for( int i=0; i < Program.numberOfPanes; ++i )
1596  {
1597  Program.paneIds[ i ] = paneids[ i ];
1598 
1599  #ifdef ASSERT_ON
1600  assert( Program.paneIds2index.find( Program.paneIds[ i ] ) ==
1601  Program.paneIds2index.end( ) );
1602  #endif
1603 
1604  Program.paneIds2index[ Program.paneIds[ i ] ] = i;
1605  }
1606 
1607  delete [] paneids; paneids = NULL;
1608 
1609  #ifdef ASSERT_ON
1610  assert( Program.paneIds2index.size( ) == Program.numberOfPanes );
1611  #endif
1612 
1613  return win_out;
1614 
1615 }
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
void COM_delete_attribute(const char *wa_str)
Delete an existing attribute.
Definition: roccom_c++.h:128
blockLoc i
Definition: read.cpp:79
struct globarg Program
std::string cntrlfile
Filename of the control file.
Definition: hdf2plt.C:740
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void COM_clone_attribute(const char *wname, const char *attr, int wg=1, const char *ptnname=0, int val=0)
Clone the subset of panes of another window of which the given pane attribute has value val...
Definition: roccom_c++.h:234
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
bool readControlFile
A flag that specifies that a control file needs to be read.
Definition: hdf2plt.C:739
std::string fileregx
Regular expression that describes the files that need to be read.
Definition: hdf2plt.C:742
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
Definition: roccom_c++.h:350
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Program main.

Parameters
argcthe argument counter.
argvthe argument vector.
Returns
0 if success, else, false.

Definition at line 412 of file hdf2pltV2.C.

References COM_finalize(), COM_init(), getWindow(), parseArguments(), globarg::printInfo(), printWindow(), and Program.

413 {
414  /* Parse the user-supplied command line */
415  parseArguments( argc, argv );
416 
417  /* Print program information to STDOUT */
418  Program.printInfo( );
419 
420  /* Initialize Roccom Environment */
421  COM_init( &argc, &argv );
422 
423  /* Load all required modules */
424  Program.loadModules( );
425 
426  /* Get window */
427  std::string windowname = getWindow( );
428 
429  std::cout << "Read window: " << windowname << std::endl;
430  std::cout << "Number of panes: " << Program.numberOfPanes << std::endl;
431 
432  /* Print window */
433  printWindow( windowname );
434 
435  /* Unload modules */
436  Program.unloadModules( );
437 
438  /* Finalize the COM Environment */
439  COM_finalize( );
440 
441  return 0;
442 }
void printInfo()
Definition: hdf2plt.C:745
void parseArguments(int argc, char **argv)
Parses the command line arguments.
Definition: hdf2plt.C:805
void COM_finalize()
Definition: roccom_c++.h:59
struct globarg Program
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
void printWindow(const std::string &windowName)
Prints the window with the given name.
Definition: hdf2pltV2.C:1483
std::string getWindow()
Loads the set of HDF files into a single window.
Definition: hdf2pltV2.C:1540

Here is the call graph for this function:

void maskPoints ( )

This method is called from getPaneConnectivity() to mask the flag the mesh points that are shared on each grid.

Masks the points that are shared based on the pane connectivity.

Precondition
Program.mask.size( ) == 0.
Program.numberOfPanes >= 1.
Program.pconns.size( ) == Program.numberOfPanes.
Program.paneIds.size( ) == Program.numberOfPanes.
Postcondition
Program.mask.size( ) == Program.numberOfPanes.
Program.mask[ i ] is created for each mesh, m_i, 0 <= i <= Program.numberOfPanes.
Program.mask is created for each mesh.
Precondition
Program.paneIds
Program.mask.size( ) == 0.
Program.numberOfPanes >= 1.
Program.pconnSizes[ i ] >= 0, 0 <= i < Program.numberOfPanes.
Program.pconns[ i ] != NULL, 0 <= i < Program.numberOfPanes.

Definition at line 1234 of file hdf2pltV2.C.

References PaneConnectivity::getNodesSharedWithRemotePane(), PaneConnectivity::getNumberOfNodesSharedWithRemotePane(), PaneConnectivity::getRemotePaneIds(), i, and Program.

Referenced by getPaneConnectivity().

1235 {
1236 
1237  #ifdef ASSERT_ON
1238  assert( Program.mask.size( ) == 0 );
1239  assert( Program.numberOfPanes >= 1 );
1240  assert( Program.pconns.size( ) == Program.numberOfPanes );
1241  assert( Program.paneIds.size( ) == Program.numberOfPanes );
1242  #endif
1243 
1244  Program.mask.resize( Program.numberOfPanes );
1245  for( int pane=0; pane < Program.numberOfPanes; ++pane )
1246  {
1247  /* Initially no nodes are shared so the entire mask is set to false */
1248  Program.mask[ pane ].resize( Program.meshes[ pane ].nc.Size( ),false );
1249 
1250  /* Get pointer to the pane connectivity object corresponding to this pane */
1251  PaneConnectivity *pconPtr = &( Program.pconns[ pane ] );
1252 
1253  #ifdef ASSERT_ON
1254  assert( pconPtr != NULL );
1255  #endif
1256 
1257  /* Get the remote pane ids connecting to this pane */
1258  std::vector< int > remotePaneIds;
1259  pconPtr ->getRemotePaneIds( remotePaneIds );
1260 
1261  #ifdef ASSERT_ON
1262  assert( pconPtr ->getNumberOfConnections( ) == remotePaneIds.size( ) );
1263  #endif
1264 
1265  /* For all remote panes, get the local shared nodes that are shared with each remote pane */
1266  for( int rmtPane=0; rmtPane < remotePaneIds.size( ); ++rmtPane )
1267  {
1268 // std::cout << "Pane: [" << Program.paneIds[ pane ] << "] shares ";
1269 // std::cout << pconPtr ->getNumberOfNodesSharedWithRemotePane( remotePaneIds[ rmtPane ] );
1270 // std::cout << " Remote pane: [" << remotePaneIds[ rmtPane ] << "]\n";
1271 
1272  int id = remotePaneIds[ rmtPane ];
1273  std::vector< int > nodeList = pconPtr ->getNodesSharedWithRemotePane( id );
1274 
1275  #ifdef ASSERT_ON
1276  assert( nodeList.size( ) == pconPtr ->getNumberOfNodesSharedWithRemotePane( id ) );
1277  #endif
1278 
1279  for( int i=0; i < nodeList.size( ); ++i )
1280  {
1281  int nodeId = nodeList[ i ];
1282 
1283  #ifdef ASSERT_ON
1284  assert( nodeId >= 0 && nodeId < Program.mask[ pane ].size( ) );
1285  #endif
1286 
1287  Program.mask[ pane ][ nodeId ] = true;
1288 
1289  } /* For all shared nodes in the node list */
1290 
1291  } /* End For all remote panes */
1292 
1293  } /* End For all panes, i.e., zones or sub-domains */
1294 
1295 }
int getNumberOfNodesSharedWithRemotePane(const int remotePane)
Returns the number of nodes shared with a particular remote pane.
std::vector< int > & getNodesSharedWithRemotePane(const int remotePane)
Returns a reference to the list of nodes shared with the remotePane.
blockLoc i
Definition: read.cpp:79
struct globarg Program
void getRemotePaneIds(std::vector< int > &rmtpanes)
Returns the remote pane ids that are connected to this instance.

Here is the call graph for this function:

Here is the caller graph for this function:

void parseArguments ( int  argc,
char **  argv 
)

Parses the command line arguments.

Parses the user-supplied command line arguments.

Parameters
argcthe argument counter.
argvthe argument vector.
Precondition
argc >= 1.
argv != NULL.
Parameters
argcthe argument counter
argvthe argument vector
void printVtk ( std::vector< double > &  vlist,
std::vector< std::vector< int > > &  elist 
)

This method prints the global grid in VTK file format.

Note
Mostly used for debugging.
Parameters
vlistthe global vertex list.
elistthe element list.

Definition at line 822 of file hdf2pltV2.C.

References i, and j.

Referenced by stitchGrids().

823 {
824  std::ofstream ofs;
825  ofs.open( std::string( "global_mesh.vtk" ).c_str( ) );
826 
827  if( !ofs.is_open( ) )
828  {
829  std::cerr << "Cannot write global VTK file! " << std::endl;
830  std::cerr << "File: " << __FILE__ << std::endl;
831  std::cerr << "Line: " << __LINE__ << std::endl;
832  assert( false );
833  }
834 
835  ofs << "# vtk DataFile Version 3.0\n";
836  ofs << "Global Mesh Output" << std::endl;
837  ofs << "ASCII\n";
838  ofs << "DATASET UNSTRUCTURED_GRID\n";
839  ofs << "POINTS " << vlist.size( )/3 << " double\n";
840 
841  for( int i=0; i < vlist.size( )/3; ++i )
842  {
843  ofs << vlist[ i*3 ] << " ";
844  ofs << vlist[ i*3+1 ] << " ";
845  ofs << vlist[ i*3+2 ] << "\n";
846  }
847 
848  int maxnodes = 0; /* the maximum number of nodes per element */
849  for( int i=0; i < elist.size( ); ++i )
850  {
851  if( maxnodes < elist[ i ].size( ) )
852  maxnodes = elist[ i ].size( );
853  }
854 
855  ofs << "CELLS " << elist.size( ) << " " << elist.size( )*( maxnodes+1) << "\n";
856  for( int i=0; i < elist.size( ); ++i )
857  {
858  ofs << elist[ i ].size( ) << " ";
859  for( int j=0; j < elist[ i ].size( ); ++j )
860  ofs << elist[ i ][ j ]<< " ";
861  ofs << std::endl;
862  }
863 
864  ofs << "CELL_TYPES " << elist.size( ) << std::endl;
865  for( int i=0; i < elist.size( ); ++i )
866  {
867 
868  if( elist[ i ].size( ) == 8 )
869  ofs << "12\n";
870  else if( elist[ i ].size( ) == 4 )
871  ofs << "10\n";
872  else {
873  std::cerr << "Undefined element type!\n";
874  std::cerr << "File: " << __FILE__ << std::endl;
875  std::cerr << "Line: " << __LINE__ << std::endl;
876  }
877 
878  }
879  ofs.close( );
880 }
blockLoc i
Definition: read.cpp:79
j indices j
Definition: Indexing.h:6

Here is the caller graph for this function:

void printWindow ( const std::string &  wName)

Prints the window with the given name.

This function prints the panes/grids in the window a into a Tecplot file.

Parameters
windowNamethe name of the window.
wnameThe name of the window.

Definition at line 1483 of file hdf2pltV2.C.

References convertWindow(), getPaneConnectivity(), Program, stitchGrids(), writePlotFile(), writeVtkData(), and writeVtkFiles().

Referenced by main().

1484 {
1485  std::string window = wName;
1486 
1487  if( Program.blocks )
1488  {
1489  std::cout << "Converting block-structured grids to unstructured...\n";
1490  std::cout.flush( );
1491 
1492  window = convertWindow( wName );
1493 
1494  std::cout << "[DONE]\n";
1495  std::cout.flush( );
1496  }
1497  else
1498  {
1499  //TODO: Load the Unstructured meshes from the window to the data-structures.
1500  std::cerr << "Unstructured grids are currently not supported!\n";
1501  std::cerr << "If your data-set consists of block structured grids make sure the -block-structured argument is supplied at the command line.\n";
1502  std::cerr << "File: " << __FILE__ << std::endl;
1503  std::cerr << "Line: " << __LINE__ << std::endl;
1504  std::cerr << "core dumping...\n";
1505  assert( false );
1506  }
1507 
1508  /* Get the pane connectivity and mask the shared points. */
1509  getPaneConnectivity( window );
1510 
1511  #ifdef ASSERT_ON
1512  if( Program.vtk )
1513  {
1514  std::cout << "Writting VTK files...";
1515  writeVtkFiles( Program.meshes );
1516  std::cout << "[DONE]\n";
1517  }
1518  #endif
1519 
1520  // TODO: delete the window and panes, the data is now
1521  // stored in the separate data-structures, hence it is
1522  // no longer needed.
1523 
1524  stitchGrids( );
1525 
1526  if( Program.vtk )
1527  writeVtkData( );
1528 
1529  writePlotFile( );
1530 
1531 }
void getPaneConnectivity(const std::string &wName)
Computes the pane connectivity using Rocmap.
Definition: hdf2pltV2.C:1302
void stitchGrids()
This method will stitch the grids into a single, global grid.
Definition: hdf2pltV2.C:1131
void writeVtkFiles(std::vector< Mesh::UnstructuredMesh > &m)
Writes the set of meshes into separate VTK files that can be visualized with Paraview.
Definition: hdf2pltV2.C:1354
struct globarg Program
void writePlotFile()
Generates a single zone plot file from the stitched mesh.
Definition: hdf2pltV2.C:459
void writeVtkData()
Writes the merged grid and its data in VTK UNSTRUCTURED_GRID file format.
Definition: hdf2pltV2.C:645
std::string convertWindow(const std::string &wname)
Converts the window from block-structured format to unstructured format.
Definition: hdf2pltV2.C:1422

Here is the call graph for this function:

Here is the caller graph for this function:

void showUsage ( )

Displays usage information to Standard-out about the different switches and command line arguments that can be used with this program.

Prints usage and examples to STDOUT.

void stitchGrids ( )

This method will stitch the grids into a single, global grid.

Precondition
Program.meshes.size( ) == Program.numberOfPanes
Program.pconns.size( ) == Program.numberOfPanes
Postcondition
Program.globalMesh is constructed.

Definition at line 1131 of file hdf2pltV2.C.

References addToGlobalNodeList(), Mesh::UnstructuredMesh::con, Mesh::Connectivity::Esize(), i, MeshPointIdToGlobalIdMap::insert(), Mesh::UnstructuredMesh::nc, Mesh::Connectivity::Nelem(), Mesh::Connectivity::Node(), printVtk(), Program, Mesh::NodalCoordinates::Size(), stitchSolutionData(), updateHash(), Mesh::NodalCoordinates::y(), and Mesh::NodalCoordinates::z().

Referenced by printWindow().

1132 {
1133  std::cout << "Stitching grids...";
1134  std::cout.flush( );
1135 
1136  #ifdef ASSERT_ON
1137  assert( Program.meshes.size( ) == Program.numberOfPanes );
1138  assert( Program.pconns.size( ) == Program.numberOfPanes );
1139  assert( Program.paneIds.size( ) == Program.numberOfPanes );
1140  #endif
1141 
1142  MeshPointIdToGlobalIdMap hash; /* Node Hash */
1143  MeshPointIdToGlobalIdMap ehash; /* Element Hash */
1144 
1145  for( int i=0; i < Program.meshes.size( ); ++i )
1146  {
1147  int meshPaneId = Program.paneIds[ i ];
1148  Mesh::UnstructuredMesh *mesh = &( Program.meshes[ i ] );
1149 
1150  #ifdef ASSERT_ON
1151  assert( mesh != NULL );
1152  #endif
1153 
1154 
1155  int count = 0;
1156  for( int node=0; node < mesh ->nc.Size( ); ++node )
1157  {
1158  if( ! Program.isNodeShared( i, node ) )
1159  {
1160  /* insert the node */
1161  int globalId = addToGlobalNodeList(
1162  mesh ->nc.x( node+1 ), mesh ->nc.y( node+1 ), mesh ->nc.z( node+1 ),
1163  Program.globalNodeList );
1164 
1165  #ifdef ASSERT_ON
1166  assert( ! hash.exists( meshPaneId, node ) );
1167  #endif
1168 
1169  hash.insert( meshPaneId, node, globalId );
1170 
1171  }
1172  else if( !hash.exists( meshPaneId, node ) )
1173  {
1174  /* insert the node */
1175  int globalId = addToGlobalNodeList(
1176  mesh ->nc.x( node+1 ), mesh ->nc.y( node+1 ), mesh ->nc.z( node+1 ),
1177  Program.globalNodeList );
1178 
1179  /* update the hash */
1180  updateHash( meshPaneId, node, globalId, &hash );
1181  }
1182 
1183  } /* End for all nodes */
1184 
1185  for( int element=0; element < mesh ->con.Nelem( ); ++element )
1186  {
1187  int size = mesh ->con.Esize( element+1 );
1188 
1189  std::vector< int > elt;
1190  elt.resize( size );
1191 
1192  for( int i=0; i < size; ++i )
1193  {
1194  int localId = mesh ->con.Node( element+1, i+1 )-1;
1195 
1196  #ifdef ASSERT_ON
1197  assert( hash.exists( meshPaneId, localId ) );
1198  #endif
1199 
1200  int globalId = hash.getGlobalId( meshPaneId, localId );
1201  elt[ i ] = globalId;
1202  }
1203 
1204  Program.globalElementList.push_back( elt );
1205  int globalElementId = Program.globalElementList.size( )-1;
1206  ehash.insert( meshPaneId, element, globalElementId );
1207 
1208  } /* End for all elements */
1209 
1210  } /* End for all meshes */
1211 
1212  std::cout << "[DONE]\n";
1213 
1214  std::cout << "Total number of nodes: " << (Program.globalNodeList.size( )/3) << std::endl;
1215  std::cout << "Total number of elements: " << Program.globalElementList.size( ) << std::endl;
1216 
1217  #ifdef ASSERT_ON
1218  printVtk( Program.globalNodeList, Program.globalElementList );
1219  #endif
1220 
1221  stitchSolutionData( &hash, &ehash );
1222 
1223 }
void printVtk(std::vector< double > &vlist, std::vector< std::vector< int > > &elist)
This method prints the global grid in VTK file format.
Definition: hdf2pltV2.C:822
int addToGlobalNodeList(const double x, const double y, const double z, std::vector< double > &nodelist)
This method adds the vertex with the given x,y,z coordinates to the global node list and returns the ...
Definition: hdf2pltV2.C:951
void updateHash(const int meshPaneId, const int pointId, const int globalId, MeshPointIdToGlobalIdMap *hash)
This method updates a MeshPointIdToGlobalIdMap hash with the mesh panes and point IDs mapping to the ...
Definition: hdf2pltV2.C:894
Definition: adj.h:150
void insert(const int meshPaneId, const int meshPointId, const int globalId)
This method constructs a new key-pair for the meshPaneId and meshPointId which maps into globalId and...
double & z(IndexType n=1)
Definition: Mesh.H:300
IndexType Size() const
Definition: Mesh.C:49
IndexType & Node(IndexType e, IndexType n)
Definition: Mesh.H:354
IndexType Esize(IndexType n) const
Definition: Mesh.H:365
blockLoc i
Definition: read.cpp:79
struct globarg Program
IndexType Nelem() const
Definition: Mesh.H:364
Connectivity con
Definition: Mesh.H:450
NodalCoordinates nc
Definition: Mesh.H:449
void stitchSolutionData(MeshPointIdToGlobalIdMap *hash)
This method will stitch the partitioned solution for the single grid.
double & y(IndexType n=1)
Definition: Mesh.H:290

Here is the call graph for this function:

Here is the caller graph for this function:

void stitchSolutionData ( MeshPointIdToGlobalIdMap hash)

This method will stitch the partitioned solution for the single grid.

Parameters
hasha hash of the local mesh points to the corresponding global Id.
Precondition
hash != NULL

Referenced by stitchGrids().

Here is the caller graph for this function:

void stitchSolutionData ( MeshPointIdToGlobalIdMap hash,
MeshPointIdToGlobalIdMap ehash 
)

This method will stitch the partitioned solution for the single grid.

Parameters
hasha hash of the local mesh points to the corresponding global Id.
ehasha hash of the lobal element ids to the corresponding global element Id.
Precondition
hash != NULL && ehash != NULL.
hash ->size( ) > 0 && ehash ->size( ) > 0..
Program.globalNodeList.size( ) > 0.
Program.globalElementList.size( ) > 0.
Program.solution.size( ) == Program.numberOfPanes.

Definition at line 971 of file hdf2pltV2.C.

References CELLDATA, MeshPointIdToGlobalIdMap::getGlobalId(), i, NODEDATA, and Program.

972 {
973 
974  Program.solutionignore.resize( Program.smdv.size( ), false );
975 
976  std::cout << "Stitching the solution...";
977  std::cout.flush( );
978 
979  #ifdef ASSERT_ON
980  assert( hash != NULL && ehash != NULL );
981  assert( Program.globalNodeList.size( ) > 0 );
982  assert( Program.globalElementList.size( ) > 0 );
983  assert( hash ->size( ) > 0 && ehash ->size( ) > 0 );
984  assert( Program.solution.size( ) == Program.numberOfPanes );
985  #endif
986 
987  /* Initialize the global solution vector */
988 
989  Program.globalSolution.resize( Program.smdv.size( ) );
990 
991  for( int i=0; i < Program.globalSolution.size( ); ++i )
992  {
993  if( Program.getDataItemType( i ) == NODEDATA )
994  Program.globalSolution[ i ].resize( Program.globalNodeList.size( )*Program.smdv[ i ].ncomp, 0.0 );
995  else if( Program.getDataItemType( i ) == CELLDATA )
996  Program.globalSolution[ i ].resize( Program.globalElementList.size( )*Program.smdv[ i ].ncomp, 0.0 );
997  else {
998  std::cerr << "Code should not reach here!\n";
999  std::cerr << "File: " << __FILE__ << std::endl;
1000  std::cerr << "Line: " << __LINE__ << std::endl;
1001  assert( false );
1002  }
1003 
1004  }
1005 
1006  for( int paneidx=0; paneidx < Program.numberOfPanes; ++paneidx )
1007  {
1008  int paneId = Program.paneIds[ paneidx ];
1009 
1010  #ifdef ASSERT_ON
1011  assert( Program.solution[ paneidx ].size( ) == Program.smdv.size( ) );
1012  #endif
1013 
1014  for( int dataidx=0; dataidx < Program.solution[ paneidx].size( ); ++dataidx )
1015  {
1016 
1017  #ifdef ASSERT_ON
1018  assert( dataidx >= 0 && dataidx < Program.solution[paneidx].size( ) );
1019  #endif
1020 
1021  if( Program.getDataItemType( dataidx ) == NODEDATA )
1022  {
1023 
1024  if( Program.solution[ paneidx ][ dataidx ].size( ) == 0 )
1025  {
1026  Program.solutionignore[ dataidx ] = true;
1027  Program.globalSolution[ dataidx ].resize( 0 );
1028  }
1029  else
1030  {
1031 
1032  int N = Program.smdv[ dataidx ].ncomp;
1033  int NumNodes = Program.meshes[ paneidx ].nc.Size( );
1034 
1035  #ifdef ASSERT_ON
1036  assert( Program.meshes[ paneidx ].nc.Size( )*N == Program.solution[ paneidx ][ dataidx ].size( ) );
1037  #endif
1038 
1039  for( int localNodeId=0; localNodeId < NumNodes; ++localNodeId )
1040  {
1041 
1042  #ifdef ASSERT_ON
1043  assert( hash ->exists( paneId, localNodeId ) );
1044  #endif
1045 
1046  int globalId = hash ->getGlobalId( paneId, localNodeId );
1047  for( int component=0; component < N; ++component )
1048  {
1049  int gidx = globalId*N+component; /* The global index */
1050  int lidx = localNodeId*N+component; /* The local index */
1051 
1052  #ifdef ASSERT_ON
1053  assert( gidx >= 0 && gidx < Program.globalSolution[ dataidx ].size( ) );
1054  assert( lidx >= 0 && lidx < Program.solution[ paneidx ][ dataidx ].size( ) );
1055  #endif
1056 
1057  Program.globalSolution[ dataidx ][ gidx ] = Program.solution[ paneidx ][ dataidx ][ lidx ];
1058 
1059  } // End for all components
1060 
1061  } // End for all nodes
1062 
1063  } // End else
1064 
1065  } // End if NodeData
1066  else if( Program.getDataItemType( dataidx ) == CELLDATA )
1067  {
1068  if( Program.solution[ paneidx ][ dataidx ].size( ) == 0 )
1069  {
1070  Program.solutionignore[ dataidx ] = true;
1071  Program.globalSolution[ dataidx ].resize( 0 );
1072  }
1073  else
1074  {
1075 
1076  int N = Program.smdv[ dataidx ].ncomp;
1077  int NumElements = Program.meshes[ paneidx ].con.Nelem( );
1078 
1079  #ifdef ASSERT_ON
1080  assert( Program.meshes[ paneidx ].con.Nelem( )*N == Program.solution[ paneidx ][ dataidx ].size( ) );
1081  #endif
1082 
1083  for( int localElement=0; localElement < NumElements; ++ localElement )
1084  {
1085  #ifdef ASSERT_ON
1086  assert( ehash ->exists( paneId, localElement ) );
1087  #endif
1088 
1089  int globalId = ehash ->getGlobalId( paneId, localElement );
1090  for( int component=0; component < N; ++component )
1091  {
1092  int gidx = globalId*N+component; /* The global index */
1093  int lidx = localElement*N+component; /* The local index */
1094 
1095  #ifdef ASSERT_ON
1096  assert( gidx >= 0 && gidx < Program.globalSolution[ dataidx ].size( ) );
1097  assert( lidx >= 0 && lidx < Program.solution[ paneidx ][ dataidx ].size( ) );
1098  #endif
1099 
1100  Program.globalSolution[ dataidx ][ gidx ] = Program.solution[ paneidx ][ dataidx ][ lidx ];
1101 
1102  } // End for all components
1103 
1104  } // End for all elements
1105 
1106  } // End else
1107 
1108  } // End if CellData
1109  else
1110  {
1111  std::cerr << "Code should not reach here!\n";
1112  std::cerr << "File: " << __FILE__ << std::endl;
1113  std::cerr << "Line: " << __LINE__ << std::endl;
1114  assert( false );
1115  }
1116 
1117  } /* End for all solution data */
1118 
1119  } /* End For all panes */
1120 
1121  std::cout << "[DONE]\n";
1122 
1123 }
int getGlobalId(const int meshPaneId, const int meshPointId)
Returns the assigned global id to meshPointId of the mesh associated with the provided meshPaneId...
blockLoc i
Definition: read.cpp:79
struct globarg Program

Here is the call graph for this function:

void updateHash ( const int  meshPaneId,
const int  pointId,
const int  globalId,
MeshPointIdToGlobalIdMap hash 
)

This method updates a MeshPointIdToGlobalIdMap hash with the mesh panes and point IDs mapping to the global ID.

Parameters
meshPaneIdthe pane id of the mesh that the local point id belongs to.
pointIdthe point id of the point assigned a new global ID.
globalIdthe global Id to be assigned to the given point.
hashpointer to the has data-structure to be updated.
Precondition
Program.hasPane(meshPaneId ) == true.
pointId >= 0 && pointId < Program.meshes[ Program.getPaneIndex( meshPaneId ) ].nc.Size( )
globalId >= 0.
hash != NULL.

Definition at line 894 of file hdf2pltV2.C.

References i, MeshPointIdToGlobalIdMap::insert(), key, and Program.

Referenced by stitchGrids().

895 {
896  #ifdef ASSERT_ON
897  assert( Program.hasPane( meshPaneId ) );
898  assert( pointId >= 0 && pointId < Program.meshes[ Program.getPaneIndex( meshPaneId ) ].nc.Size( ) );
899  assert( globalId >= 0 );
900  assert( hash != NULL );
901  #endif
902 
903  hash ->insert( meshPaneId, pointId, globalId );
904 
905  int idx = Program.getPaneIndex( meshPaneId );
906 
907  #ifdef ASSERT_ON
908  assert( idx >= 0 && idx < Program.numberOfPanes );
909  #endif
910 
911  std::vector< std::pair< int, int > > connections;
912  Program.getPaneConnectivity( idx ) ->getPointConnectionPairs( pointId, connections );
913 
914  for( int i=0; i < connections.size( ); ++i )
915  {
916 
917  int remotePaneId = connections[ i ].first;
918  int nodeIndex = connections[ i ].second;
919 
920  #ifdef ASSERT_ON
921  assert( Program.hasPane( remotePaneId ) );
922  #endif
923 
924  int remotePoint = Program.getPaneConnectivity( Program.getPaneIndex( remotePaneId ) )->getSharedPointIdAt( meshPaneId, nodeIndex );
925  std::pair< int, int > key = std::make_pair( remotePaneId, remotePoint );
926 
927 
928  #ifdef ASSERT_ON
929  assert( remotePoint >= 0 && remotePoint < Program.meshes[ Program.getPaneIndex( remotePaneId ) ].nc.Size( ) );
930  assert( Program.isNodeShared( Program.getPaneIndex( remotePaneId ), remotePoint ) == true );
931  #endif
932 
933  if( !hash ->exists( remotePaneId, remotePoint ) )
934  hash ->insert( remotePaneId, remotePoint, globalId );
935 
936  }
937 
938 }
void insert(const int meshPaneId, const int meshPointId, const int globalId)
This method constructs a new key-pair for the meshPaneId and meshPointId which maps into globalId and...
blockLoc i
Definition: read.cpp:79
struct globarg Program
static T_Key key
Definition: vinci_lass.c:76

Here is the call graph for this function:

Here is the caller graph for this function:

void writePlotFile ( )

Generates a single zone plot file from the stitched mesh.

Generates a single zone plot file from the merged mesh.

Precondition
Program.globalNodeList.size( ) > 0.
Program.globalElementList.size( ) > 0.
Program.smdv.size( ) > 0.
Program.globalSolution.size( ) == Program.smdv.size( ).
Program.solutionignore.size( ) == Program.smdv.size( ).
Program.outputfile != ""
Postcondition
A VTK formatted file is written in Program.outputfile.vtk
Note
The extension in the outputfile will be appended.
Precondition
Program.globalNodeList.size( ) > 0.
Program.globalElementList.size( ) > 0.
Program.smdv.size( ) > 0.
Program.globalSolution.size( ) == Program.smdv.size( ).
Program.solutionignore.size( ) == Program.smdv.size( ).
Program.outputfile != ""
Postcondition
A Tecplot formatted file is written in Program.outputfile.plt
Note
The extension in the outputfile will be appended.

Definition at line 459 of file hdf2pltV2.C.

References CELLDATA, i, j, globarg::outputfile, and Program.

Referenced by printWindow().

460 {
461  std::cout << "Writing TECPLOT file...";
462  std::cout.flush( );
463 
464  #ifdef ASSERT_ON
465  assert( Program.globalNodeList.size( ) > 0 );
466  assert( Program.globalElementList.size( ) > 0 );
467  assert( Program.smdv.size( ) > 0 );
468  assert( Program.globalSolution.size( ) == Program.smdv.size( ) );
469  assert( Program.solutionignore.size( ) == Program.smdv.size( ) );
470  assert( Program.outputfile != "" );
471  #endif
472 
473  std::ofstream ofs;
474  ofs.open( std::string(Program.outputfile + ".dat").c_str( ) );
475 
476  if( !ofs.is_open( ) )
477  {
478  std::cerr << "Cannot write TECPLOT file: " << Program.outputfile+".vtk" << std::endl;
479  std::cerr << "File: " << __FILE__ << std::endl;
480  std::cerr << "Line: " << __LINE__ << std::endl;
481  assert( false );
482  }
483 
484  /* Write title */
485  ofs << "TITLE=\"" << Program.outputfile << " " << __DATE__ << "\"" << std::endl;
486 
487  /* Write Variables */
488  int variableCount = 3;
489  std::vector< int > ecenteredidx;
490 
491  ofs << "VARIABLES= \"X\", \"Y\", \"Z\"";
492 
493  for( int i=0; i < Program.smdv.size( ); ++i )
494  {
495  if( !Program.solutionignore[ i ] )
496  {
497 
498  if( Program.smdv[ i ].ncomp > 1 )
499  {
500  for( int component=0; component < Program.smdv[ i ].ncomp; ++component )
501  {
502  ofs << ", \"";
503  ofs << component+1 << "-" << Program.smdv[ i ].name;
504  ofs << "\"";
505  ++variableCount;
506 
507  if( Program.getDataItemType( i ) == CELLDATA )
508  ecenteredidx.push_back( variableCount );
509  }
510  }
511  else
512  {
513  ofs << ", \"" << Program.smdv[ i ].name << "\"";
514  ++variableCount;
515  if( Program.getDataItemType( i ) == CELLDATA )
516  ecenteredidx.push_back( variableCount );
517  }
518 
519  } /* End if solution is not ignored */
520 
521  } /* End for all variables */
522 
523  /* Write Zone header */
524  ofs << std::endl;
525  ofs << "ZONE " << "NODES=" << Program.globalNodeList.size( )/3 << " ";
526  ofs << "ELEMENTS=" << Program.globalElementList.size( ) << " ";
527  ofs << "ZONETYPE=" << Program.getTecplotZoneType( ) << " ";
528  ofs << "DATAPACKING=BLOCK ";
529 
530  if( !ecenteredidx.empty( ) )
531  {
532  ofs << "VARLOCATION=([";
533  ofs << ecenteredidx[ 0 ];
534  for( int i=1; i < ecenteredidx.size( ); ++i )
535  ofs << "," << ecenteredidx[ i ];
536  ofs << "]=CELLCENTERED)";
537  }
538  ofs << std::endl;
539 
540  /* Write nodes */
541 
542  for( int i=0; i < 3; ++i )
543  {
544  switch( i )
545  {
546  case 0:
547  ofs << "# Begin X\n";
548  break;
549  case 1:
550  ofs << "# Begin Y\n";
551  break;
552  case 2:
553  ofs << "# Begin Z\n";
554  break;
555  default:
556  std::cerr << "Error: Code should not reach here!\n";
557  std::cerr << "File: " << __FILE__ << std::endl;
558  std::cerr << "Line: " << __LINE__ << std::endl;
559  std::cerr << "core dumping...\n";
560  assert( false );
561  }
562 
563  for( int node=0; node < Program.globalNodeList.size( )/3; ++node )
564  {
565  ofs << Program.globalNodeList[ node*3 + i] << " ";
566  if( node % 10 == 9 )
567  ofs << std::endl;
568  }
569  ofs << std::endl;
570 
571  }/* End for all dimensions */
572 
573  /* End Write nodes */
574 
575 
576  /* Write the solution */
577  for( int i=0; i < Program.globalSolution.size( ); ++i )
578  {
579  if( ! Program.solutionignore[ i ] )
580  {
581  if( Program.smdv[ i ].ncomp > 1 )
582  {
583  for( int component=0; component < Program.smdv[ i ].ncomp; ++component )
584  {
585  ofs << "\n# Begin " << component+1 << "-" << Program.smdv[ i ].name << std::endl;
586 
587  int stride = Program.smdv[ i ].ncomp;
588  int NumItems = Program.globalSolution[ i ].size( )/stride;
589  for( int dataidx=0; dataidx < NumItems; ++dataidx )
590  {
591  ofs << Program.globalSolution[ i ][ dataidx*stride+component ] << " ";
592  if( dataidx % 10 == 9 )
593  ofs << std::endl;
594  }
595 
596  }
597  }
598  else
599  {
600  ofs << "\n# Begin " << Program.smdv[ i ].name << std::endl;
601  for( int dataidx=0; dataidx < Program.globalSolution[ i ].size( ); ++dataidx )
602  {
603  ofs << Program.globalSolution[ i ][ dataidx ] << " ";
604  if( dataidx % 10 == 9 )
605  ofs << std::endl;
606  }
607 
608  }
609 
610  ofs << std::endl;
611 
612  } /* End if solution is not ignored */
613 
614  }
615  /* End write solution */
616 
617  /* Write the element connectivity */
618  ofs << std::endl << "# Begin Element Connectivity\n";
619  for( int i=0; i < Program.globalElementList.size( ); ++i )
620  {
621  for( int j=0; j < Program.globalElementList[ i ].size( ); ++j )
622  {
623  ofs << Program.globalElementList[ i ][ j ]+1 << " ";
624  }
625  ofs << std::endl;
626  }
627  /* End write the element connectivity */
628 
629  ofs.close( );
630 
631  std::cout << "[DONE]\n";
632 }
Definition: adj.h:150
std::string outputfile
The filename of the output file.
Definition: hdf2plt.C:743
blockLoc i
Definition: read.cpp:79
struct globarg Program
j indices j
Definition: Indexing.h:6

Here is the caller graph for this function:

void writeVtkData ( )

Writes the merged grid and its data in VTK UNSTRUCTURED_GRID file format.

Precondition
Program.globalNodeList.size( ) > 0.
Program.globalElementList.size( ) > 0.
Program.smdv.size( ) > 0.
Program.globalSolution.size( ) == Program.smdv.size( ).
Program.solutionignore.size( ) == Program.smdv.size( ).
Program.outputfile != ""
Postcondition
A VTK formatted file is written in Program.outputfile.vtk
Note
The extension in the outputfile will be appended.

Definition at line 645 of file hdf2pltV2.C.

References CELLDATA, i, j, NODEDATA, globarg::outputfile, and Program.

Referenced by printWindow().

646 {
647 
648  std::cout << "Writing VTK data...";
649  std::cout.flush( );
650 
651  #ifdef ASSERT_ON
652  assert( Program.globalNodeList.size( ) > 0 );
653  assert( Program.globalElementList.size( ) > 0 );
654  assert( Program.smdv.size( ) > 0 );
655  assert( Program.globalSolution.size( ) == Program.smdv.size( ) );
656  assert( Program.solutionignore.size( ) == Program.smdv.size( ) );
657  assert( Program.outputfile != "" );
658  #endif
659 
660  std::ofstream ofs;
661  ofs.open( std::string(Program.outputfile + ".vtk").c_str( ) );
662 
663  if( !ofs.is_open( ) )
664  {
665  std::cerr << "Cannot write VTK file: " << Program.outputfile+".vtk" << std::endl;
666  std::cerr << "File: " << __FILE__ << std::endl;
667  std::cerr << "Line: " << __LINE__ << std::endl;
668  assert( false );
669  }
670 
671  /* STEP 1: Write the header */
672  ofs << "# vtk DataFile Version 3.0\n";
673  ofs << "Global Mesh Output" << std::endl;
674  ofs << "ASCII\n";
675  ofs << "DATASET UNSTRUCTURED_GRID\n";
676  ofs << "POINTS " << Program.globalNodeList.size( )/3 << " double\n";
677 
678  /* STEP 2: Write the nodes */
679  for( int i=0; i < Program.globalNodeList.size( )/3; ++i )
680  {
681  ofs << Program.globalNodeList[ i*3 ] << " ";
682  ofs << Program.globalNodeList[ i*3+1 ] << " ";
683  ofs << Program.globalNodeList[ i*3+2 ] << std::endl;
684  }
685 
686  /* STEP 3: Write the max element size */
687  int maxnodes = 0; /* the maximum number of nodes per element */
688  for( int i=0; i < Program.globalElementList.size( ); ++i )
689  {
690  if( maxnodes < Program.globalElementList[ i ].size( ) )
691  maxnodes = Program.globalElementList[ i ].size( );
692  }
693 
694  /* STEP 4: Write the element connectivity */
695  ofs << "CELLS " << Program.globalElementList.size( ) << " " << Program.globalElementList.size( )*( maxnodes+1) << "\n";
696  for( int i=0; i < Program.globalElementList.size( ); ++i )
697  {
698  ofs << Program.globalElementList[ i ].size( ) << " ";
699  for( int j=0; j < Program.globalElementList[ i ].size( ); ++j )
700  ofs << Program.globalElementList[ i ][ j ]<< " ";
701  ofs << std::endl;
702  }
703 
704  /* STEP 5: Write the cell types */
705  ofs << "CELL_TYPES " << Program.globalElementList.size( ) << std::endl;
706  for( int i=0; i < Program.globalElementList.size( ); ++i )
707  {
708 
709  if( Program.globalElementList[ i ].size( ) == 8 )
710  ofs << "12\n";
711  else if( Program.globalElementList[ i ].size( ) == 4 )
712  ofs << "10\n";
713  else {
714  std::cerr << "Undefined element type!\n";
715  std::cerr << "File: " << __FILE__ << std::endl;
716  std::cerr << "Line: " << __LINE__ << std::endl;
717  }
718 
719  }
720 
721  /* STEP 6: Write the solution data attached to the points */
722  bool wroteHeader = false;
723  for( int i=0; i < Program.globalSolution.size( ); ++i )
724  {
725 
726  if( ! Program.solutionignore[ i ] && Program.getDataItemType( i ) == NODEDATA )
727  {
728 
729  int N = Program.globalNodeList.size( )/3;
730  int NC = Program.smdv[ i ].ncomp;
731 
732  if(!wroteHeader)
733  {
734  ofs << "POINT_DATA " << N << std::endl;
735  wroteHeader = true;
736  }
737 
738  if( NC == 1 )
739  {
740  ofs << "SCALARS " << Program.smdv[ i ].name << " double" << std::endl;
741  ofs << "LOOKUP_TABLE default\n";
742  }
743  else if( NC == 3 )
744  {
745  ofs << "VECTORS " << Program.smdv[ i ].name << " double" << std::endl;
746  }
747  else
748  {
749  ofs << "TENSORS " << Program.smdv[ i ].name << " double" << std::endl;
750  }
751 
752  for( int j=0; j < N; ++j )
753  {
754  for( int component=0; component < NC; ++component )
755  {
756  ofs << Program.globalSolution[ i ][ j*NC+component ] << " ";
757  }
758  ofs << std::endl;
759  }
760 
761  } /* End if the solution is not ignored */
762 
763  } /* End for all solution data */
764 
765 
766  /* STEP 6: Write the solution data attached to the cells */
767  wroteHeader = false;
768  for( int i=0; i < Program.globalSolution.size( ); ++i )
769  {
770 
771  if( ! Program.solutionignore[ i ] && Program.getDataItemType( i ) == CELLDATA )
772  {
773 
774  int N = Program.globalElementList.size();
775  int NC = Program.smdv[ i ].ncomp;
776 
777  if( !wroteHeader )
778  {
779  ofs << "CELL_DATA " << N << std::endl;
780  wroteHeader = true;
781  }
782 
783  if( NC == 1 )
784  {
785  ofs << "SCALARS " << Program.smdv[ i ].name << " double" << std::endl;
786  ofs << "LOOKUP_TABLE default\n";
787  }
788  else if( NC == 3 )
789  {
790  ofs << "VECTORS " << Program.smdv[ i ].name << " double" << std::endl;
791  }
792  else
793  {
794  ofs << "TENSORS " << Program.smdv[ i ].name << " double" << std::endl;
795  }
796 
797  for( int j=0; j < N; ++j )
798  {
799  for( int component=0; component < NC; ++component )
800  {
801  ofs << Program.globalSolution[ i ][ j*NC+component ] << " ";
802  }
803  ofs << std::endl;
804  }
805 
806  } /* End if the solution is not ignored */
807 
808  } /* End for all solution data */
809 
810  ofs.close( );
811 
812  std::cout << "[DONE]\n";
813 
814 }
std::string outputfile
The filename of the output file.
Definition: hdf2plt.C:743
blockLoc i
Definition: read.cpp:79
struct globarg Program
j indices j
Definition: Indexing.h:6

Here is the caller graph for this function:

void writeVtkFiles ( std::vector< Mesh::UnstructuredMesh > &  meshes)

Writes the set of meshes into separate VTK files that can be visualized with Paraview.

Writes VTK files for the corresponding meshes.

The format of the files is {outputFile}.paneId.vtk.

Note
This method is mainly used for debugging.
Parameters
mthe set of meshes.
meshesList of meshes in the current window.

Definition at line 1354 of file hdf2pltV2.C.

References i, j, globarg::outputfile, and Program.

Referenced by printWindow().

1355 {
1356 
1357  // TODO: Generalize this function for any type of mesh.
1358  for( int m=0; m < meshes.size( ); ++m )
1359  {
1360 
1361  std::ostringstream oss; oss.clear( );
1362  oss << Program.outputfile << "." << Program.paneIds[ m ] << ".vtk";
1363 
1364  std::ofstream ofs;
1365  ofs.open( oss.str( ).c_str( ) );
1366 
1367  if( !ofs.is_open( ) )
1368  {
1369  std::cerr << "Cannot write VTK file: " << oss.str( ) << std::endl;
1370  std::cerr << "File: " << __FILE__ << std::endl;
1371  std::cerr << "Line: " << __LINE__ << std::endl;
1372  assert( false );
1373  }
1374 
1375  ofs << "# vtk DataFile Version 3.0\n";
1376  ofs << oss.str( ) << std::endl;
1377  ofs << "ASCII\n";
1378  ofs << "DATASET UNSTRUCTURED_GRID\n";
1379  ofs << "POINTS " << meshes[ m ].nc.Size( ) << " double\n";
1380 
1381  for( int i=1; i <= meshes[ m ].nc.Size( ); ++i )
1382  {
1383  ofs << meshes[ m ].nc.x( i ) << " ";
1384  ofs << meshes[ m ].nc.y( i ) << " ";
1385  ofs << meshes[ m ].nc.z( i ) << "\n";
1386  }
1387 
1388  ofs << "CELLS " << meshes[ m ].con.Nelem( ) << " " << meshes[ m ].con.Nelem( )*9 << "\n";
1389  for( int e=1; e <= meshes[ m ].con.Nelem( ); ++e )
1390  {
1391  ofs << "8 ";
1392  for( int j=1; j <= 8; ++j )
1393  ofs << meshes[ m ].con.Node( e, j )-1<< " ";
1394  ofs << std::endl;
1395  }
1396 
1397  ofs << "CELL_TYPES " << meshes[ m ].con.Nelem( ) << std::endl;
1398  for( int e=1; e <= meshes[ m ].con.Nelem( ); ++ e )
1399  ofs << "12\n";
1400 
1401  ofs << "POINT_DATA " << Program.mask[ m ].size( ) << std::endl;
1402  ofs << "SCALARS SharedNodes double\nLOOKUP_TABLE default\n";
1403  for( int i=0; i < Program.mask[ m ].size( ); ++i )
1404  {
1405  if( Program.mask[ m ][ i ] )
1406  ofs << "1\n";
1407  else
1408  ofs << "0\n";
1409  }
1410  ofs.close( );
1411 
1412  }
1413 
1414 }
std::string outputfile
The filename of the output file.
Definition: hdf2plt.C:743
blockLoc i
Definition: read.cpp:79
struct globarg Program
j indices j
Definition: Indexing.h:6

Here is the caller graph for this function:

Variable Documentation

bool blocks

Input data is block-structured grid.

Definition at line 51 of file hdf2pltV2.C.

Referenced by __scalegrd.f90__(), COM_print_window(), main(), and readBlock().

std::string cntrlfile

Control file string.

Definition at line 53 of file hdf2pltV2.C.

std::string fileregx

File regular expression.

Definition at line 54 of file hdf2pltV2.C.

std::vector< std::vector< int > > globalElementList

The global element list.

Definition at line 73 of file hdf2pltV2.C.

std::vector< double > globalNodeList

The global node list.

Definition at line 72 of file hdf2pltV2.C.

std::vector< std::vector< double > > globalSolution

Contains the global solution.

Definition at line 70 of file hdf2pltV2.C.

std::vector< std::vector< bool > > mask
std::vector< Mesh::UnstructuredMesh > meshes

The list of grids to write.

Definition at line 61 of file hdf2pltV2.C.

int numberOfPanes

The number of panes, aka number of sub-domains.

Definition at line 59 of file hdf2pltV2.C.

std::string outputfile

Output file to write the file.

Definition at line 55 of file hdf2pltV2.C.

Referenced by main(), parseCmdParameters(), and searchTopFile().

std::vector< int > paneIds

Array of paneIds.

Definition at line 60 of file hdf2pltV2.C.

Referenced by COM_print_window(), project_window(), Rocout::write_attr_internal(), and Rocout::write_rocin_control_file().

std::map< int, int > paneIds2index

Maps the pane ids to the index in the corresponding vectors.

Definition at line 66 of file hdf2pltV2.C.

std::vector< PaneConnectivity > pconns

Inter-zone (pane) connectivity information.

Definition at line 65 of file hdf2pltV2.C.

std::string prgmname

The program name.

Definition at line 58 of file hdf2pltV2.C.

struct { ... } Program
bool readControlFile

Data is read from the control file.

Definition at line 49 of file hdf2pltV2.C.

std::vector< SolnMetaData > smdv

The solution Metadata.

Definition at line 63 of file hdf2pltV2.C.

std::vector< std::vector< std::vector< double > > > solution

The solution data.

Definition at line 64 of file hdf2pltV2.C.

std::vector< bool > solutionignore

Masks the data to be ignored.

Definition at line 71 of file hdf2pltV2.C.

bool vtk

Writes vtk files.

Definition at line 52 of file hdf2pltV2.C.

bool withGhost

Ghost nodes will be used.

Definition at line 50 of file hdf2pltV2.C.