Gather some functions and classes typically used in the main()
of the FSI-suite applications.
More...
Functions | |
std::tuple< int, int, std::string, std::string > | get_dimensions_and_parameter_files (char **argv) |
Parse from the command line the parameter file names (both input and output) and the running dimensions (both dim and spacedim). More... | |
int | setup_parameters_from_cli (char **argv, const std::string &input_parameter_file, const std::string &output_parameter_file) |
Setup the ParameterAcceptor::prm according to the parameters specified in the parameter file, and the parameters specified from the command line. More... | |
template<typename Class > | |
void | run (char **argv, const std::string &input_parameter_file, const std::string &output_parameter_file) |
Setup parameters from the command line, and call the Class::run() method. More... | |
std::pair< unsigned int, unsigned int > | get_dimension_and_spacedimension (const std::string &prm_file, const unsigned int default_dim=2, const unsigned int default_spacedim=2) |
Retrieves the dimension and space dimension from a parameter file. More... | |
Gather some functions and classes typically used in the main()
of the FSI-suite applications.
std::tuple< int, int, std::string, std::string > Runner::get_dimensions_and_parameter_files | ( | char ** | argv | ) |
Parse from the command line the parameter file names (both input and output) and the running dimensions (both dim and spacedim).
Retrieves the dimensions and parameter files from the command line arguments.
This function uses the command line interface parsers from the argh library (https://github.com/adishavit/argh), and recognizes the following parameters from the command line:
Example usage (assuming you have a class called MyClass derived from ParameterAcceptor):
argv | Arguments of the command line. |
This function parses the command line arguments and extracts the dimensions and parameter file names. It supports both options and positional arguments for specifying the input parameter file. It also checks if the dimensions specified in the parameter file and the command line arguments match.
argv | The command line arguments. |
Definition at line 89 of file runner.cc.
References AssertThrow, deallog, StandardExceptions::ExcMessage(), and get_dimension_and_spacedimension().
int Runner::setup_parameters_from_cli | ( | char ** | argv, |
const std::string & | input_parameter_file, | ||
const std::string & | output_parameter_file | ||
) |
Setup the ParameterAcceptor::prm according to the parameters specified in the parameter file, and the parameters specified from the command line.
Sets up the program parameters from the command-line arguments.
This function uses the command line interface parsers from the argh library (https://github.com/adishavit/argh), and allows you to specify input parameter files, output parameter files, and to change any option recognized by the parameter file itself from the command line.
This function is usually used in conjunction with the function get_dimensions_and_parameter_files(), in order to ask from the command line what simulation to run (1d, 2d, 3d, etc.), and what input parameter files to read from. These are then passed to this function, after you have called at least once ParameterAcceptor::initialize() on your classes (which you will have instantiated with the correct dimension thanks to the function above).
Example usage (assuming you have a class called MyClass derived from ParameterAcceptor):
If the option -h
or --help
is found on the command line, this function outputs the following help message:
followed by a list of the options that are recognized by the parameter file, i.e., for the mesh_handler.cc application, we get:
This function parses the command-line arguments using the argh
library and sets up the program parameters accordingly. It initializes the ParameterAcceptor
with the input and output parameter file paths. If the -h
or --help
option is provided, it prints the help message and the list of available options. The function also handles setting the values for options specified in the command-line arguments. It ignores any positional arguments other than the program name and the input parameter file. After setting up the parameters, it initializes the ParameterAcceptor
again with the output parameter file path. If the --pause
option is provided and the current MPI process is the root process, it waits for a keypress before continuing.
argv | The command-line arguments. |
input_parameter_file | The path to the input parameter file. |
output_parameter_file | The path to the output parameter file. |
Definition at line 183 of file runner.cc.
References b(), deallog, ParameterHandler::Description, ParameterHandler::enter_subsection(), ParameterAcceptor::initialize(), ParameterHandler::KeepDeclarationOrder, ParameterHandler::leave_subsection(), ParameterHandler::print_parameters(), ParameterAcceptor::prm, sec(), ParameterHandler::set(), ParameterHandler::Short, Utilities::split_string_list(), and Utilities::MPI::this_mpi_process().
Referenced by run().
void Runner::run | ( | char ** | argv, |
const std::string & | input_parameter_file, | ||
const std::string & | output_parameter_file | ||
) |
Setup parameters from the command line, and call the Class::run() method.
Class | Type of the class to instantiate and run. |
argv | Arguments of the command line. |
input_parameter_file | Input parameter file. |
output_parameter_file | Output parameter file. |
Definition at line 219 of file runner.h.
References setup_parameters_from_cli().
std::pair<unsigned int, unsigned int> Runner::get_dimension_and_spacedimension | ( | const std::string & | prm_file, |
const unsigned int | default_dim = 2 , |
||
const unsigned int | default_spacedim = 2 |
||
) |
Retrieves the dimension and space dimension from a parameter file.
This function reads a parameter file and retrieves the values of the "dimension" and "space dimension" parameters. If the reading of the input file fails, it returns the default values provided.
prm_file
The path to the parameter file. default_dim
The default value for the dimension. default_spacedim
The default value for the space dimension.
std::exception | If an error occurs while parsing the input file. |
Definition at line 46 of file runner.cc.
References ParameterHandler::declare_entry(), ParameterHandler::get_integer(), ParameterHandler::parse_input(), and ParameterAcceptor::prm.
Referenced by get_dimensions_and_parameter_files().