GRINS-0.8.0
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
GRINS::Runner Class Reference

Class to encapsulate initializing and running GRINS Simulation. More...

#include <runner.h>

Collaboration diagram for GRINS::Runner:
Collaboration graph
[legend]

Public Member Functions

 Runner (int argc, char *argv[])
 Setup input objects. More...
 
 ~Runner ()
 
const GetPot & get_input_file () const
 
const GetPot & get_command_line () const
 
Simulationget_simulation ()
 
const Simulationget_simulation () const
 
const libMesh::LibMeshInit & get_libmesh_init () const
 
void init ()
 Initialize the Simulation objects. More...
 
void run ()
 Runs the simulation that was setup at construction time. More...
 

Protected Member Functions

void echo_version_info (std::ostream &out, int argc, char *argv[])
 Echo GRINS, libMesh version info as well as command line. More...
 
std::string check_and_get_inputfile (int argc, char *argv[], GetPot &command_line)
 Check (and error if not found) and then return GetPot input file name. More...
 
void check_for_unused_vars (const GetPot &input, bool warning_only)
 Check for any unused variables in GetPot input file. More...
 

Protected Attributes

SimulationInitializer _initializer
 
SimulationBuilder _sim_builder
 
GetPot _command_line
 
libMesh::UniquePtr< libMesh::LibMeshInit > _libmesh_init
 
libMesh::UniquePtr< GetPot > _inputfile
 
libMesh::UniquePtr< Simulation_simulation
 

Private Member Functions

 Runner ()
 

Detailed Description

Class to encapsulate initializing and running GRINS Simulation.

This class encapsulates all of the construction, initialization, etc. libMesh and GRINS objects to facilitate easy construction of a GRINS-based program. The user only needs to construct this object, init(), and then run(). Accessors are provided to perform auxillary functions as needed beyond a single Simulation run.

Definition at line 47 of file runner.h.

Constructor & Destructor Documentation

GRINS::Runner::Runner ( int  argc,
char *  argv[] 
)

Setup input objects.

The constructor will only setup input parsing objects and LibMeshInit. The user must call init() to initialize the Simulation objects. This allows the user to use the underlying command line and input file objects to do steps that may be needed before Simulation initialization.

Definition at line 37 of file runner.C.

References _command_line, _inputfile, check_and_get_inputfile(), and echo_version_info().

38  : _initializer(),
39  _sim_builder(),
40  _command_line(argc,argv),
41  _libmesh_init( new libMesh::LibMeshInit(argc,argv) )
42  {
43  this->echo_version_info( libMesh::out, argc, argv );
44 
45  // Grab inputfile name and setup GetPot input file
46  std::string inputfile_name = this->check_and_get_inputfile(argc,argv,_command_line);
47  _inputfile.reset( new GetPot(inputfile_name) );
48 
49  // Allow command line options to override the inputfile
50  _inputfile->parse_command_line(argc,argv);
51  }
void echo_version_info(std::ostream &out, int argc, char *argv[])
Echo GRINS, libMesh version info as well as command line.
Definition: runner.C:62
SimulationBuilder _sim_builder
Definition: runner.h:96
SimulationInitializer _initializer
Definition: runner.h:94
GetPot _command_line
Definition: runner.h:98
std::string check_and_get_inputfile(int argc, char *argv[], GetPot &command_line)
Check (and error if not found) and then return GetPot input file name.
Definition: runner.C:76
libMesh::UniquePtr< GetPot > _inputfile
Definition: runner.h:102
libMesh::UniquePtr< libMesh::LibMeshInit > _libmesh_init
Definition: runner.h:100
GRINS::Runner::~Runner ( )
inline

Definition at line 58 of file runner.h.

58 {}
GRINS::Runner::Runner ( )
private

Member Function Documentation

std::string GRINS::Runner::check_and_get_inputfile ( int  argc,
char *  argv[],
GetPot &  command_line 
)
protected

Check (and error if not found) and then return GetPot input file name.

Definition at line 76 of file runner.C.

Referenced by Runner().

77  {
78  if( argc < 2 )
79  {
80  std::stringstream error_msg;
81  error_msg << "ERROR: Found only 1 command line argument, but was expecting an inputfile name!"
82  << std::endl
83  << " Please specify the name of the input file on the command line as the first" << std::endl
84  << " command line argument or using the '--input <filename>' option." << std::endl;
85  libmesh_error_msg(error_msg.str());
86  }
87 
88  std::string inputfile_name;
89  if( command_line.search("--input") )
90  inputfile_name = command_line.next(std::string("DIE!"));
91  else
92  inputfile_name = argv[1];
93 
94  std::ifstream i(inputfile_name.c_str());
95  if (!i)
96  {
97  std::string error_msg = "Error: Could not read from input file "+inputfile_name+"!\n";
98  libmesh_error_msg(error_msg);
99  }
100 
101  return inputfile_name;
102  }
void GRINS::Runner::check_for_unused_vars ( const GetPot &  input,
bool  warning_only 
)
protected

Check for any unused variables in GetPot input file.

Definition at line 114 of file runner.C.

Referenced by run().

115  {
116  /* Everything should be set up now, so check if there's any unused variables
117  in the input file. If so, then tell the user what they were and error out. */
118  std::vector<std::string> unused_vars = input.unidentified_variables();
119 
120  bool unused_vars_detected = false;
121 
122  // String we use to check if there is a variable in the Materials section
123  std::string mat_string = "Materials/";
124 
125  // If we do have unused variables, make sure they are in the Materials
126  // section since we're allowing those to be present and not used.
127  if( !unused_vars.empty() )
128  {
129  int n_total = unused_vars.size();
130 
131  int n_mats = 0;
132 
133  for( int v = 0; v < n_total; v++ )
134  if( (unused_vars[v]).find(mat_string) != std::string::npos )
135  n_mats += 1;
136 
137  libmesh_assert_greater_equal( n_total, n_mats );
138 
139  if( n_mats < n_total )
140  unused_vars_detected = true;
141  }
142 
143  if( unused_vars_detected )
144  {
145  libMesh::err << "==========================================================" << std::endl;
146  if( warning_only )
147  libMesh::err << "Warning: ";
148  else
149  libMesh::err << "Error: ";
150 
151  libMesh::err << "Found unused variables!" << std::endl;
152 
153  for( std::vector<std::string>::const_iterator it = unused_vars.begin();
154  it != unused_vars.end(); ++it )
155  {
156  // Don't print out any unused Material variables, since we allow these
157  if( (*it).find(mat_string) != std::string::npos )
158  continue;
159 
160  libMesh::err << *it << std::endl;
161  }
162  libMesh::err << "==========================================================" << std::endl;
163 
164  if( !warning_only )
165  libmesh_error();
166  }
167  }
void GRINS::Runner::echo_version_info ( std::ostream &  out,
int  argc,
char *  argv[] 
)
protected

Echo GRINS, libMesh version info as well as command line.

Definition at line 62 of file runner.C.

Referenced by Runner().

63  {
64  out << "==========================================================" << std::endl;
65  out << "GRINS Version: " << GRINS_BUILD_VERSION << std::endl
66  << "libMesh Version: " << LIBMESH_BUILD_VERSION << std::endl
67  << "Running with command:\n";
68 
69  for (int i=0; i != argc; ++i)
70  out << argv[i] << ' ';
71 
72  out << std::endl
73  << "==========================================================" << std::endl;
74  }
const GetPot& GRINS::Runner::get_command_line ( ) const
inline

Definition at line 63 of file runner.h.

References _command_line.

Referenced by main().

64  { return _command_line; }
GetPot _command_line
Definition: runner.h:98
const GetPot& GRINS::Runner::get_input_file ( ) const
inline

Definition at line 60 of file runner.h.

References _inputfile.

Referenced by main().

61  { return *_inputfile; }
libMesh::UniquePtr< GetPot > _inputfile
Definition: runner.h:102
const libMesh::LibMeshInit& GRINS::Runner::get_libmesh_init ( ) const
inline

Definition at line 74 of file runner.h.

References _libmesh_init.

Referenced by main().

75  { return *_libmesh_init; }
libMesh::UniquePtr< libMesh::LibMeshInit > _libmesh_init
Definition: runner.h:100
Simulation& GRINS::Runner::get_simulation ( )
inline

Definition at line 66 of file runner.h.

References _simulation.

Referenced by main(), and run().

67  { libmesh_assert(_simulation);
68  return *_simulation; }
libMesh::UniquePtr< Simulation > _simulation
Definition: runner.h:104
const Simulation& GRINS::Runner::get_simulation ( ) const
inline

Definition at line 70 of file runner.h.

References _simulation.

71  { libmesh_assert(_simulation);
72  return *_simulation; }
libMesh::UniquePtr< Simulation > _simulation
Definition: runner.h:104
void GRINS::Runner::init ( )

Initialize the Simulation objects.

Definition at line 53 of file runner.C.

References _command_line, _inputfile, _libmesh_init, _sim_builder, and _simulation.

Referenced by main(), and run().

54  {
55  // Initialize Simulation
56  _simulation.reset( new Simulation( *_inputfile,
59  _libmesh_init->comm() ) );
60  }
libMesh::UniquePtr< Simulation > _simulation
Definition: runner.h:104
SimulationBuilder _sim_builder
Definition: runner.h:96
GetPot _command_line
Definition: runner.h:98
libMesh::UniquePtr< GetPot > _inputfile
Definition: runner.h:102
libMesh::UniquePtr< libMesh::LibMeshInit > _libmesh_init
Definition: runner.h:100
void GRINS::Runner::run ( )

Runs the simulation that was setup at construction time.

Definition at line 104 of file runner.C.

References _command_line, _inputfile, _simulation, and check_for_unused_vars().

Referenced by main(), and run().

105  {
106  // First check for any unused variables
107  bool warning_only = _command_line.search("--warn-only-unused-var");
108 
109  this->check_for_unused_vars(*_inputfile, warning_only );
110 
111  _simulation->run();
112  }
libMesh::UniquePtr< Simulation > _simulation
Definition: runner.h:104
void check_for_unused_vars(const GetPot &input, bool warning_only)
Check for any unused variables in GetPot input file.
Definition: runner.C:114
GetPot _command_line
Definition: runner.h:98
libMesh::UniquePtr< GetPot > _inputfile
Definition: runner.h:102

Member Data Documentation

GetPot GRINS::Runner::_command_line
protected

Definition at line 98 of file runner.h.

Referenced by get_command_line(), init(), run(), and Runner().

SimulationInitializer GRINS::Runner::_initializer
protected

Definition at line 94 of file runner.h.

libMesh::UniquePtr<GetPot> GRINS::Runner::_inputfile
protected

Definition at line 102 of file runner.h.

Referenced by get_input_file(), init(), run(), and Runner().

libMesh::UniquePtr<libMesh::LibMeshInit> GRINS::Runner::_libmesh_init
protected

Definition at line 100 of file runner.h.

Referenced by get_libmesh_init(), and init().

SimulationBuilder GRINS::Runner::_sim_builder
protected

Definition at line 96 of file runner.h.

Referenced by init().

libMesh::UniquePtr<Simulation> GRINS::Runner::_simulation
protected

Definition at line 104 of file runner.h.

Referenced by get_simulation(), init(), and run().


The documentation for this class was generated from the following files:

Generated on Tue Dec 19 2017 12:47:32 for GRINS-0.8.0 by  doxygen 1.8.9.1