Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DriverProgram.H
Go to the documentation of this file.
1 #ifndef __EXAMPLE_PROGRAM_H__
8 #define __EXAMPLE_PROGRAM_H__
9 #ifdef _GRIDCONVERSION_PARALLEL_
10 #include "COMM.H"
11 #endif
12 #include "Global.H"
13 #include "Profiler.H"
14 #include "Mesh.H"
15 
16 namespace GridConversion {
17 
40  namespace DriverProgram {
44  typedef IRAD::Profiler::ProfilerObj ProfilerType;
48  typedef std::string StackType;
56  typedef IRAD::Global::GlobalObj<StackType,int,ProfilerType> GlobalType;
57 #ifdef _GRIDCONVERSION_PARALLEL_
58  typedef IRAD::Comm::CommunicatorObject CommType;
65  typedef IRAD::Global::ParallelGlobalObj<CommType,StackType,int,ProfilerType> PGlobalType;
66 #endif
67  class DriverProgramComLine : public IRAD::Util::ComLineObject
76  {
77  public:
79  : IRAD::Util::ComLineObject()
80  {};
81  DriverProgramComLine(const char *args[])
82  : IRAD::Util::ComLineObject(args)
83  {};
90  void Initialize(){
91  AddOption('h',"help");
92  //AddOption('q',"quadratic");
93  AddOption('v',"verbosity",1);
94  AddOption('o',"output",2,"filename");
95  AddArgument("grid input> <bc input",1);
96  AddHelp("help","Prints this long version of help.");
97  AddHelp("output","Specifies the name of the output file.");
98  std::ostringstream Ostr;
99  //Ostr << "If using a mesh with tetrahedral elements, specifying" << std::endl
100  // << "this flag will cause the application to change the 4 node" << std::endl
101  // << " tetrahedra from input to 10 node quadratic tetrahedra";
102  //AddHelp("quadratic",Ostr.str());
103  Ostr.str("");
104  Ostr << "GridConversion requires two arguments in order:" << std::endl
105  << " "
106  << "su2 grid file> <bc file> where the su2 is a grid" << std::endl
107  << " "
108  << "analysis file output from Pointwise in Stanford format." << std::endl
109  << " "
110  << "The bc file indicates a Rocfrac boundary condition for "
111  << "each" << std::endl
112  << " domain." << std::endl
113  << " See the Grid Conversion User Manual for more "
114  << "information on" << std::endl
115  << " the formats of these two files" << std::endl;
116  AddArgHelp("grid input> <bc input",Ostr.str());
117  // The following commented string formation is kept around to
118  // illustrate the required tabs and newlines to make the output
119  // look proper:
120  //
121  // Ostr << "Use fixed problem size in scalability analysis. Only makes"
122  // << "\n\t\tsense when scalability mode is enabled.";
123  // Ostr.str("");
124  Ostr.str("");
125  Ostr << "Main GridConversion program.";
126  _description.assign(Ostr.str());
127 
128  };
129  };
130 
141  typedef IRAD::Global::Program<GlobalType,ComLineType> SerialProgramType;
142 #ifdef _GRIDCONVERSION_PARALLEL_
143  typedef IRAD::Global::Program<PGlobalType,ComLineType> ParallelProgramType;
150 #endif
151  class SerialProgram : public SerialProgramType
179  {
180  protected:
182  std::string output_name;
184  std::string input_name;
186  std::string bc_input_name;
190  std::ofstream Ouf;
192  std::ifstream Inf;
194  bool quadratic;
196  int numNodes;
198  std::vector<double> nodes;
199  // vector of vectors to hold nodal bc flags
200  std::vector< std::vector<int> > nodeBCs;
203  std::vector< std::vector< std::vector<double> > > nodeBCValues;
204  // vector to hold the list of nodes to domains
205  SolverUtils::Mesh::Connectivity nodesToDomains;
209  std::vector<unsigned int> elemEdges;
213  std::vector<unsigned int> elemToElemEdges;
214  //number of edges per element
217  int numElems;
219  std::vector< std::vector<unsigned int> > nodeToNode;
221  std::vector<unsigned int> elems;
223  std::vector< std::vector<int> > elemBCs;
226  std::vector< std::vector< std::vector<double> > > elemBCValues;
230  std::vector< std::vector<int> >elemsToDomains;
234  std::vector<std::string> shapes;
238  std::vector< std::vector<unsigned int> > domains;
240  std::vector< std::vector<int> > domainBCs;
243  std::vector< std::vector< std::vector<double> > > domainBCValues;
245  std::vector< std::vector<int> > edges;
247  std::vector< std::vector<int> > edgeBCs;
250  std::vector< std::vector< std::vector<double> > > edgeBCValues;
251  public:
257  {};
261  SerialProgram(int nargs,char **args) :
262  SerialProgramType(nargs,args)
263  {};
267  virtual int Initialize()
268  {
269  int retval = SerialProgramType::Initialize();
270  if(!_command_line.GetOption("help").empty()){
271  std::ostringstream Ostr;
272  Ostr << _command_line.LongUsage() << std::endl;
273  StdOut(Ostr.str());
274  return(-1);
275  }
276  if(retval){
277  std::ostringstream Ostr;
278  Ostr << _command_line.ErrorReport() << std::endl
279  << std::endl << _command_line.ShortUsage() << std::endl;
280  ErrOut(Ostr.str());
281  return(retval);
282  }
283 
284  //Initialize mesh values to 0
285  numNodes = 0;
286  numElems = 0;
287  numDomains = 0;
288  numNodesPerElem = 0;
289  elemShape = 0;
290 
291  //Set element shape vector (shape numbers are those used in Patran grid files)
292  shapes.resize(10);
293  shapes[0] = shapes[1] = shapes[6] = "none";
294  shapes[2]= "bar";
295  shapes[3] = "triangle";
296  shapes[4] = "quadrilateral";
297  shapes[5] = "tetrahedron";
298  shapes[7] = "triangular prism";
299  shapes[8] = "hexahedron";
300  shapes[9] = "pyramid";
301 
302  // Check if we should create higher order elements
303  quadratic = false;
304  if(!_command_line.GetOption("quadratic").empty())
305  quadratic = true;
306 
307  // Check if output file is specified
308  output_name = _command_line.GetOption("output");
309 
310  // Set input file to first argument
311  std::vector<std::string> args(_command_line.GetArgs());
312  input_name = args[0];
313  bc_input_name = args[1];
314 
315  // Check the verbosity level
316  std::string sverb(_command_line.GetOption("verbosity"));
317  if(sverb.empty() || sverb == ".true.")
318  verblevel = 1;
319  else {
320  std::istringstream Vin(sverb);
321  Vin >> verblevel;
322  if(verblevel < 0)
323  verblevel = 1;
324  }
325 
326  // If high verbosity, stick a configuration blurb to stdout.
327  if(verblevel > 1){
328  std::ostringstream Ostr;
329  Ostr << "Configuration:" << std::endl
330  << "verbosity = " << verblevel << std::endl
331  << "input_name = " << input_name << std::endl
332  << "bc_input_name = " << bc_input_name << std::endl;
333  if(!output_name.empty())
334  Ostr << "output file = " << output_name << std::endl;
335  Ostr << std::endl;
336  StdOut(Ostr.str());
337  }
338 
339  return(0);
340  };
344  int VerbLevel() const { return verblevel;};
348  virtual ~SerialProgram() {
349  if(Ouf){
350  Ouf.close();
351  SetOutStream(std::cout);
352  }
353  };
357  virtual int Run();
361  virtual int ReadPatranInput();
365  virtual int ReadStanfordInput();
370  virtual int HigherOrderTets(SolverUtils::Mesh::Connectivity elemEdgeToElems,
371  SolverUtils::Mesh::Connectivity nodesToDomains);
376  virtual int ConnectivityMaps(SolverUtils::Mesh::Connectivity nodesToElems);
380  virtual int WriteOutput();
381  };
382 
383 
384 #ifdef _GRIDCONVERSION_PARALLEL_
385  class ParallelProgram : public ParallelProgramType
454  {
455  protected:
457  std::string output_name;
459  int verblevel;
461  std::ofstream Ouf;
463  int ndiv;
464  public:
468  ParallelProgram() :
469  ParallelProgramType()
470  {verblevel = 0;};
474  ParallelProgram(int nargs,char **args) :
475  ParallelProgramType(nargs,args)
476  {verblevel = 0;};
480  ParallelProgram(ComLineType &comline,CommType &incomm)
481  {
482  this->_command_line.Copy(comline);
483  this->Init(_command_line.ProgramName(),incomm);
484  verblevel = 0;
485  };
489  virtual int Initialize()
490  {
491  int retval = ParallelProgramType::Initialize();
492  // Check if the user just entered -h or --help
493  if(!_command_line.GetOption("help").empty()){
494  std::ostringstream Ostr;
495  Ostr << _command_line.LongUsage() << std::endl;
496  StdOut(Ostr.str());
497  return(-1);
498  }
499  if(retval){ // then there were errors on the command line
500  std::ostringstream Ostr;
501  Ostr << _command_line.ErrorReport() << std::endl
502  << std::endl << _command_line.ShortUsage() << std::endl;
503  ErrOut(Ostr.str());
504  return(retval);
505  }
506 
507  // Everything is OK up to here, so check for an output file.
508  output_name = _command_line.GetOption("output");
509 
510  // Set number of divisions to first argument
511  std::vector<std::string> args(_command_line.GetArgs());
512  std::istringstream Istr(args[0]);
513  Istr >> ndiv;
514 
515  // Check the verbosity level
516  std::string sverb(_command_line.GetOption("verbosity"));
517  if(sverb.empty() || sverb == ".true.")
518  verblevel = 1;
519  else {
520  std::istringstream Vin(sverb);
521  Vin >> verblevel;
522  if(verblevel < 0)
523  verblevel = 1;
524  }
525 
526  // If high verbosity, stick a configuration blurb to stdout.
527  if(verblevel > 1){
528  std::ostringstream Ostr;
529  Ostr << "Configuration:" << std::endl
530  << "verbosity = " << verblevel << std::endl
531  << "number of divisions = " << ndiv << std::endl;
532  if(!output_name.empty())
533  Ostr << "output file = " << output_name << std::endl;
534  Ostr << std::endl;
535  StdOut(Ostr.str());
536  }
537 
538  return(0);
539  };
543  int VerbLevel() const { return verblevel;};
547  virtual ~ParallelProgram() {
548  if(Ouf){
549  Ouf.close();
550  SetOutStream(std::cout);
551  }
552  };
556  virtual int Run();
557  };
558 #endif
559 
560 
571  template<typename ProgramType>
572  int Driver(int argc,char *argv[])
573  {
574  ProgramType MyProgram(argc,argv);
575  int retval = MyProgram.Initialize();
576  if(retval){
577  if(retval > 0){ // then there was an error
578  MyProgram.ErrOut("Error in Program Initialization.\n");
579  return(1);
580  }
581  else return(0); // no error, but the program should not continue
582  }
583  if(MyProgram.VerbLevel() > 1)
584  MyProgram.StdOut("Calling RUN.\n");
585  if(MyProgram.Run()){
586  MyProgram.ErrOut("Error in Program RUN method.\n");
587  return(1);
588  }
589  if(MyProgram.VerbLevel() > 1){
590  std::ostringstream Ostr;
591  MyProgram.Report(Ostr);
592  MyProgram.StdOut(Ostr.str());
593  MyProgram.StdOut("Calling Finalize.\n");
594  }
595  if(MyProgram.Finalize()){
596  MyProgram.ErrOut("Error in Program Finalization.\n");
597  return(1);
598  }
599  if(MyProgram.VerbLevel() > 1)
600  MyProgram.StdOut("All done.\n");
601  return(0);
602  }
603 
604 
609 #ifdef _GRIDCONVERSION_PARALLEL_
610  inline double f(double x)
621  {
622  return (4.0 / (1.0 + x*x));
623  }
627  typedef GridConversion::DriverProgram::ParallelProgram PEProgramType;
628 #endif
629  };
630 };
631 #endif
IRAD::Profiler::ProfilerObj ProfilerType
Convenience type definition for Profiler object.
Definition: DriverProgram.H:44
IRAD::Global::Program< GlobalType, ComLineType > SerialProgramType
Convenience type definition for the serial program.
virtual int WriteOutput()
This function writes the output grid file.
Definition: WriteOutput.C:6
virtual int HigherOrderTets(SolverUtils::Mesh::Connectivity elemEdgeToElems, SolverUtils::Mesh::Connectivity nodesToDomains)
This function creates higher order tets from linear tets.
Definition: HigherOrder.C:6
std::vector< std::vector< unsigned int > > domains
vector of vectors to hold the domains
int numDomains
number of domains in mesh
std::vector< std::vector< int > > elemBCs
vector to hold list of element bc values
void Initialize()
This is where the actual options and arguments are described.
Definition: DriverProgram.H:90
virtual int ReadPatranInput()
This function parses a Patran format input file.
int numElemEdges
number of element edges in mesh
Mesh Stuff.
Implementation of the basic parts of the serial program example.
virtual int Initialize()
Initializes native data structures from commandline args.
virtual int Run()
This function implements the main function executed by the program.
Definition: DriverProgram.C:16
virtual int ConnectivityMaps(SolverUtils::Mesh::Connectivity nodesToElems)
This function creates a few different connectivity maps that are needed.
std::vector< unsigned int > elemToElemEdges
map of elements to element edges
std::vector< unsigned int > elems
vector for holding element connectivies read from input
int numElems
number of elements in mesh
std::vector< std::vector< int > > edgeBCs
vector to hold list of edge bc flags
std::vector< std::vector< int > > elemsToDomains
vector to hold the domains for each element
DriverProgramComLine ComLineType
Convenience type definition for the Main comline object.
SerialProgram(int nargs, char **args)
Constructor designed to take the commandline args.
std::vector< std::vector< int > > nodeBCs
IRAD::Global::GlobalObj< StackType, int, ProfilerType > GlobalType
Convenience type definition for the serial global object.
Definition: DriverProgram.H:56
int numNodesPerElemEdge
number of nodes per element edge
GridConversion::DriverProgram::SerialProgram SEProgramType
Convenience definition for serial program type.
std::string output_name
Name of file for output.
std::vector< std::string > shapes
vector to hold the element shapes (only used for Patran input format)
SolverUtils::Mesh::Connectivity nodesToDomains
std::ofstream Ouf
Outfile stream for output.
IRAD::Comm::CommunicatorObject CommType
Convenience typedef for CommunicatorObject.
The ComLineObject for the example programs.
Definition: DriverProgram.H:75
void int int REAL * x
Definition: read.cpp:74
int numNodesPerElem
number of nodes per element
std::vector< std::vector< int > > domainBCs
vector to hold list of domain bc flags
std::ifstream Inf
Infile stream for input.
virtual int ReadStanfordInput()
This function parses a Stanford format input file.
int Driver(int argc, char *argv[])
Unified driver for the example programs.
std::vector< std::vector< int > > edges
vector of vectors to hold the edges
std::vector< std::vector< std::vector< double > > > domainBCValues
vector to hold list of domain bc values (these are different for each bc type - see the Rocfrac docum...
std::vector< std::vector< std::vector< double > > > edgeBCValues
vector to hold list of edge bc values (these are different for each bc type - see the Rocfrac documen...
std::vector< std::vector< unsigned int > > nodeToNode
vector for holding node to node map
int elemShape
integer to denote the shape of elements used in the mesh
std::vector< unsigned int > elemEdges
vector for holding element edges
std::string bc_input_name
Name of bc input file.
std::string input_name
Name of input file.
std::vector< double > nodes
vector for holding nodal coordinates read from input
std::string StackType
Convenience type definition for program stack.
Definition: DriverProgram.H:48
std::vector< std::vector< std::vector< double > > > elemBCValues
vector to hold list of element bc values (these are different for each bc type - see the Rocfrac docu...
int VerbLevel() const
Returns verbosity level.
std::vector< std::vector< std::vector< double > > > nodeBCValues
vector to hold list of node bc values (these are different for each bc type - see the Rocfrac documen...
bool quadratic
boolean for changing the elements to higher order