Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hdf2pltV2.C
Go to the documentation of this file.
1 
10 /* Global Variables */
11 #include <string>
12 #include <iostream>
13 #include <fstream>
14 #include <iomanip>
15 #include <sstream>
16 #include <cstring>
17 #include <cstdlib>
18 #include <cassert>
19 #include <vector>
20 #include <map>
21 #include <utility>
22 #include <algorithm>
23 
24 #include "TAIL.H"
25 #include "PrimitiveTypes.H"
26 #include "roccom.h"
27 
28 #include "PaneConnectivity.hpp" /* Gives high-level dynamic pane connectivity access */
29 #include "MeshPointIdToGlobalIdMap.hpp" /* Data-structure for mapping (mesh,point) pairs to assigned global IDs */
30 
31 /* External Dynamically Linked Modules */
32 COM_EXTERN_MODULE( Rocin ); // Used to read in the HDF files.
33 COM_EXTERN_MODULE( Rocmap ); // Used to compute the pane connectivity.
34 
35 using namespace Rocstar::Rocin::Utilities;
36 
41 
46 struct
47 {
48  /* These are the program parameters */
50  bool withGhost;
51  bool blocks;
52  bool vtk;
53  std::string cntrlfile;
54  std::string fileregx;
55  std::string outputfile;
57  /* HDF2Plot Persistent Data */
58  std::string prgmname;
60  std::vector< int > paneIds;
61  std::vector< Mesh::UnstructuredMesh > meshes;
62  std::vector< std::vector< bool > > mask;
63  std::vector< SolnMetaData > smdv;
64  std::vector< std::vector< std::vector< double > > > solution;
65  std::vector< PaneConnectivity > pconns;
66  std::map< int, int > paneIds2index;
70  std::vector< std::vector< double > > globalSolution;
71  std::vector< bool > solutionignore;
72  std::vector< double > globalNodeList;
73  std::vector< std::vector< int > > globalElementList;
82  inline std::string getTecplotZoneType( )
83  {
84  #ifdef ASSERT_ON
85  assert( globalElementList.size( ) > 0 );
86  #endif
87 
88  std::string retString = "";
89 
90  int maxElementSize = 0;
91  for( int i=0; i < globalElementList.size( ); ++i )
92  {
93  if( globalElementList[ i ].size( ) > maxElementSize )
94  maxElementSize = globalElementList[ i ].size( );
95  }
96 
97  switch( maxElementSize )
98  {
99  case 8:
100  retString = "FEBRICK";
101  break;
102  case 4:
103  retString = "FETETRAHEDRON";
104  break;
105  case 5:
106  case 6:
107  retString = "FEPOLYHEDRAL";
108  break;
109  default:
110  std::cerr << "Undefined element size: " << maxElementSize << std::endl;
111  std::cerr << "File: " << __FILE__ << std::endl;
112  std::cerr << "Line: " << __LINE__ << std::endl;
113  assert( false );
114  }
115  return retString;
116  }
117 
125  inline DataItemType getDataItemType( const int metaDataIdx )
126  {
127  #ifdef ASSERT_ON
128  assert( metaDataIdx >= 0 && metaDataIdx < smdv.size( ) );
129  #endif
130 
131  if( smdv[ metaDataIdx ].loc == 'e' )
132  return CELLDATA;
133  else if( smdv[ metaDataIdx ].loc == 'n' )
134  return NODEDATA;
135  else {
136  std::cerr << "Undefined location: " << smdv[ metaDataIdx ].loc << std::endl;
137  std::cerr << "File: " << __FILE__ << std::endl;
138  std::cerr << "Line: " << __LINE__ << std::endl;
139  assert( false );
140  }
141  }
142 
151  inline bool isNodeShared( const int meshidx, const int pointidx )
152  {
153  #ifdef ASSERT_ON
154  assert( meshidx >= 0 && meshidx < numberOfPanes );
155  assert( pointidx >= 0 && pointidx < meshes[ meshidx ].nc.Size( ) );
156  #endif
157  return mask[ meshidx ][ pointidx ];
158  }
159 
168  inline int getPaneIndex( const int paneId )
169  {
170  #ifdef ASSERT_ON
171  assert( hasPane( paneId ) );
172  #endif
173 
174  int idx = paneIds2index[ paneId ];
175 
176  #ifdef ASSERT_ON
177  assert( idx >= 0 && idx < numberOfPanes );
178  #endif
179 
180  return idx;
181  }
182 
188  inline bool hasPane( const int paneId )
189  {
190  if( paneIds2index.find( paneId ) != paneIds2index.end( ) )
191  return true;
192  else
193  return false;
194  }
195 
202  inline PaneConnectivity *getPaneConnectivity( const int meshIndex )
203  {
204  #ifdef ASSERT_ON
205  assert( meshIndex >= 0 && meshIndex < meshes.size( ) );
206  assert( meshes.size( ) == pconns.size( ) );
207  #endif
208  return( &pconns[ meshIndex ] );
209  }
210 
214  inline void loadModules( )
215  {
217  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocmap, "MAP" );
218  }
219 
223  inline void unloadModules( )
224  {
226  COM_UNLOAD_MODULE_STATIC_DYNAMIC( Rocmap, "MAP" );
227  }
228 
233  inline void printInfo( )
234  {
235 
236  std::cout << "Program: " << prgmname << std::endl;
237  std::cout << "Date: " << __DATE__ << std::endl;
238  if( readControlFile )
239  {
240  std::cout << "Read control file: yes\n";
241  std::cout << "Control file: " << cntrlfile << std::endl;
242  }
243  else
244  {
245  std::cout << "Read control file: no\n";
246  std::cout << "File(s): " << fileregx << std::endl;
247  }
248 
249  std::cout << "Use ghost nodes: ";
250  (withGhost)? std::cout << "yes\n" : std::cout << "no\n";
251 
252  if( outputfile == "" )
253  std::cout << "Output file: standard out\n";
254  else
255  std::cout << "Output file: " << outputfile << std::endl;
256  }
257 
258 } Program;
259 
260 /******************************************** Function Prototypes ************************************************************************************/
261 
267 void showUsage( );
268 
276 void parseArguments( int argc, char **argv );
277 
285 std::string getWindow( );
286 
298 void writePlotFile( );
299 
304 void printWindow( const std::string &windowName );
305 
312 std::string convertWindow( const std::string &wname );
313 
320 void writeVtkFiles( std::vector< Mesh::UnstructuredMesh > &m );
321 
329 void getPaneConnnectivity( const std::string &wname );
330 
341 void maskPoints( );
342 
349 void stitchGrids( );
350 
357 
368 int addToGlobalNodeList( const double x, const double y, const double z, std::vector< double > &nodelist );
369 
381 void updateHash( const int meshPaneId, const int pointId, const int globalId, MeshPointIdToGlobalIdMap *hash );
382 
394 void writeVtkData( );
395 
402 void printVtk( std::vector< double > &vlist, std::vector< std::vector< int > > &elist );
403 
404 /******************************************** End Function Prototypes ************************************************************************************/
405 
412 int main( int argc, char **argv )
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 }
443 
444 //----------------------------------------------------------------------------------------------------------------------------------------------------------
445 // F U N C T I O N P R O T O T Y P E I M P L E M E N T A T I O N
446 //----------------------------------------------------------------------------------------------------------------------------------------------------------
447 
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 }
633 
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 }
815 
822 void printVtk( std::vector< double > &vlist, std::vector< std::vector< int > > &elist )
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 }
881 
882 
894 void updateHash( const int meshPaneId, const int pointId, const int globalId, MeshPointIdToGlobalIdMap *hash )
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 }
939 
940 
951 int addToGlobalNodeList( const double x, const double y, const double z, std::vector< double > &nodelist )
952 {
953  nodelist.push_back( x );
954  nodelist.push_back( y );
955  nodelist.push_back( z );
956 
957  return( (nodelist.size( )/3)-1 );
958 }
959 
960 
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 }
1124 
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 }
1224 
1234 void maskPoints( )
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 }
1296 
1302 void getPaneConnectivity( const std::string &wName )
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 }
1349 
1354 void writeVtkFiles( std::vector< Mesh::UnstructuredMesh > &meshes )
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 }
1415 
1416 
1422 std::string convertWindow( const std::string &wName )
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 }
1477 
1483 void printWindow( const std::string &wName )
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 }
1532 
1533 
1540 std::string getWindow( )
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 }
1616 
1622 void parseArguments( int argc, char **argv )
1623 {
1624  Program.prgmname = std::string( argv[ 0 ] );
1625  Program.withGhost = false;
1626  Program.readControlFile = false;
1627  Program.blocks = false;
1628  Program.vtk = false;
1629  Program.numberOfPanes = 0;
1630  Program.cntrlfile = "";
1631  Program.fileregx = "";
1632 
1633  for( int i=1; i < argc; ++i )
1634  {
1635 
1636  if( std::strcmp( argv[ i ], "-g" ) == 0 )
1637  {
1638  Program.withGhost = true;
1639  }
1640  else if( std::strcmp( argv[ i ], "-c" ) == 0 )
1641  {
1642  Program.readControlFile = true;
1643  Program.cntrlfile = std::string( argv[ ++i ] );
1644  }
1645  else if( std::strcmp( argv[ i ], "-o" ) == 0 )
1646  {
1647  Program.outputfile = std::string( argv[ ++i ] );
1648  }
1649  else if( std::strcmp( argv[ i ], "-regex") == 0 )
1650  {
1651  Program.fileregx = std::string( argv[ ++i ] );
1652  }
1653  else if( std::strcmp( argv[ i ], "-block-structured") == 0 )
1654  {
1655  Program.blocks = true;
1656  }
1657  else if( std::strcmp( argv[ i ], "-vtk" ) == 0 )
1658  {
1659  Program.vtk = true;
1660  }
1661  else if( std::strcmp( argv[ i ], "-h") == 0 )
1662  {
1663  showUsage( );
1664  exit( 0 );
1665  }
1666 
1667  }
1668 
1669  if( Program.cntrlfile == "" && Program.fileregx == "" )
1670  {
1671  std::cerr << "Error parsing command line input!\n";
1672  showUsage( );
1673  exit( -1 );
1674  }
1675 
1676 
1677 }
1678 
1682 void showUsage( )
1683 {
1684  std::cout << "HDF2PLT OPTIONS:\n";
1685  std::cout << "-regex \"{somestring}*.hdf\" : Specifies a set of hdf files\n";
1686  std::cout << "-g : Enables ghost node inclusion in the output file\n";
1687  std::cout << "-c {cntrlfile} : Specifies a control file to use\n";
1688  std::cout << "-block-structured: Indicates the the input files are block-structured grids which must be converted to unstructured format\n";
1689  std::cout << "-o {outputfile} : Specifies output file name. Note, do not append a file extension. A file extension will be automatically appended.\n";
1690  std::cout << "-vtk : Enables printing of VTK files as well.\n";
1691  std::cout << "-h : Prints this help menu.\n";
1692  std::cout << "Examples:\n";
1693  std::cout << "\thdf2plt -g -regex \"fluid*.hdf\" -block-structured -o output\n";
1694  std::cout.flush( );
1695 }
1696 
1697 
1698 
1699 
1700 
1701 
1702 
std::vector< Mesh::UnstructuredMesh > meshes
The list of grids to write.
Definition: hdf2pltV2.C:61
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 printInfo()
Definition: hdf2plt.C:745
std::map< int, int > paneIds2index
Maps the pane ids to the index in the corresponding vectors.
Definition: hdf2pltV2.C:66
void parseArguments(int argc, char **argv)
Parses the command line arguments.
Definition: hdf2plt.C:805
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
void int int REAL REAL * y
Definition: read.cpp:74
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
This file contains the prototypes for Roccom API.
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.
DataItemType
The data item type.
Definition: hdf2pltV2.C:40
std::vector< PaneConnectivity > pconns
Inter-zone (pane) connectivity information.
Definition: hdf2pltV2.C:65
The MeshPointIdToGlobalIdMap provides the functionality for mapping a pair consisting of (mesh_pane_i...
int getNumberOfNodesSharedWithRemotePane(const int remotePane)
Returns the number of nodes shared with a particular remote pane.
Definition: adj.h:150
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
void COM_delete_attribute(const char *wa_str)
Delete an existing attribute.
Definition: roccom_c++.h:128
std::vector< int > & getNodesSharedWithRemotePane(const int remotePane)
Returns a reference to the list of nodes shared with the remotePane.
std::string fileregx
File regular expression.
Definition: hdf2pltV2.C:54
void getPaneConnectivity(const std::string &wName)
Computes the pane connectivity using Rocmap.
Definition: hdf2pltV2.C:1302
std::vector< SolnMetaData > smdv
The solution Metadata.
Definition: hdf2pltV2.C:63
std::string cntrlfile
Control file string.
Definition: hdf2pltV2.C:53
int getGlobalId(const int meshPaneId, const int meshPointId)
Returns the assigned global id to meshPointId of the mesh associated with the provided meshPaneId...
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...
std::string outputfile
The filename of the output file.
Definition: hdf2plt.C:743
void stitchGrids()
This method will stitch the grids into a single, global grid.
Definition: hdf2pltV2.C:1131
std::vector< double > globalNodeList
The global node list.
Definition: hdf2pltV2.C:72
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
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:113
double & z(IndexType n=1)
Definition: Mesh.H:300
IndexType Size() const
Definition: Mesh.C:49
void COM_finalize()
Definition: roccom_c++.h:59
void maskPoints()
This method is called from getPaneConnectivity() to mask the flag the mesh points that are shared on ...
Definition: hdf2pltV2.C:1234
void int int int REAL REAL REAL * z
Definition: write.cpp:76
int numberOfPanes
The number of panes, aka number of sub-domains.
Definition: hdf2pltV2.C:59
IndexType & Node(IndexType e, IndexType n)
Definition: Mesh.H:354
IndexType Esize(IndexType n) const
Definition: Mesh.H:365
bool vtk
Writes vtk files.
Definition: hdf2pltV2.C:52
Definition: Rocin.h:64
std::vector< std::vector< std::vector< double > > > solution
The solution data.
Definition: hdf2pltV2.C:64
std::string outputfile
Output file to write the file.
Definition: hdf2pltV2.C:55
blockLoc i
Definition: read.cpp:79
struct globarg Program
void int int REAL * x
Definition: read.cpp:74
std::string cntrlfile
Filename of the control file.
Definition: hdf2plt.C:740
IndexType Nelem() const
Definition: Mesh.H:364
bool readControlFile
Data is read from the control file.
Definition: hdf2pltV2.C:49
std::string prgmname
The program name.
Definition: hdf2pltV2.C:58
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void showUsage()
Prints usage and examples to STDOUT.
Definition: hdf2plt.C:785
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
bool withGhost
A flag that specifies that ghost nodes need to be included.
Definition: hdf2plt.C:738
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 blocks
Input data is block-structured grid.
Definition: hdf2pltV2.C:51
std::vector< std::vector< bool > > mask
Masks the points that are shared (true) share (false) not shared.
Definition: hdf2pltV2.C:62
int main(int argc, char *argv[])
Definition: blastest.C:94
void getPaneConnnectivity(const std::string &wname)
This method calls Rocmap to query the pane connectivity information for the given window...
std::vector< std::vector< int > > globalElementList
The global element list.
Definition: hdf2pltV2.C:73
void writePlotFile()
Generates a single zone plot file from the stitched mesh.
Definition: hdf2pltV2.C:459
bool readControlFile
A flag that specifies that a control file needs to be read.
Definition: hdf2plt.C:739
j indices j
Definition: Indexing.h:6
The PaneConnectivity object holds the inter-zone connectivity of each grid.
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
void writeVtkData()
Writes the merged grid and its data in VTK UNSTRUCTURED_GRID file format.
Definition: hdf2pltV2.C:645
std::string fileregx
Regular expression that describes the files that need to be read.
Definition: hdf2plt.C:742
void printWindow(const std::string &windowName)
Prints the window with the given name.
Definition: hdf2pltV2.C:1483
void getRemotePaneIds(std::vector< int > &rmtpanes)
Returns the remote pane ids that are connected to this instance.
Connectivity con
Definition: Mesh.H:450
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
Definition: roccom_c++.h:350
static T_Key key
Definition: vinci_lass.c:76
bool withGhost
Ghost nodes will be used.
Definition: hdf2pltV2.C:50
std::vector< bool > solutionignore
Masks the data to be ignored.
Definition: hdf2pltV2.C:71
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:111
std::string convertWindow(const std::string &wname)
Converts the window from block-structured format to unstructured format.
Definition: hdf2pltV2.C:1422
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428
std::string getWindow()
Loads the set of HDF files into a single window.
Definition: hdf2pltV2.C:1540
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
std::vector< std::vector< double > > globalSolution
Contains the global solution.
Definition: hdf2pltV2.C:70
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116
std::vector< int > paneIds
Array of paneIds.
Definition: hdf2pltV2.C:60