25 #include "text_flow.hpp"
45 std::pair<unsigned int, unsigned int>
47 const unsigned int default_dim = 2,
48 const unsigned int default_spacedim = 2)
51 std::to_string(default_dim),
54 std::to_string(default_spacedim),
61 return {dim, spacedim};
63 catch (std::exception &exc)
65 return {default_dim, default_spacedim};
88 std::tuple<int, int, std::string, std::string>
91 argh::parser cli(argv, argh::parser::PREFER_PARAM_FOR_UNREG_OPTION);
93 unsigned int spacedim = 2;
94 std::string input_parameter_file =
"";
95 std::string output_parameter_file =
"";
97 const std::string exename =
98 cli(0).str().substr(cli(0).str().find_last_of(
"/") + 1);
102 cli({
"i",
"input_prm_file"}, input_parameter_file) >> input_parameter_file;
103 cli(1, input_parameter_file) >> input_parameter_file;
105 const bool has_dim_or_spacedim =
106 cli[{
"d",
"dim"}] || cli[{
"s",
"spacedim"}];
108 cli({
"d",
"dim"}) >> dim;
110 cli({
"s",
"spacedim"}, dim) >> spacedim;
113 const auto [prm_dim, prm_spacedim] =
120 !has_dim_or_spacedim || (dim == prm_dim) && (spacedim == prm_spacedim),
122 "You have specified a parameter file that contains a specification "
123 "of the dimension and of the space dimension, as <" +
124 std::to_string(prm_dim) +
", " + std::to_string(prm_spacedim) +
125 ">, but you also indicated a -d (--dim) = " + std::to_string(dim) +
126 " or -s (--spacedim) = " + std::to_string(spacedim) +
127 " argument on the command line that do not match the content of the parameter file. "
128 "Use only one of the two ways to select the dimension and the "
129 "space dimension, or make sure that what you specify in the parameter file "
130 "matches what you specify on the command line."));
135 if (input_parameter_file !=
"")
137 auto rel_name = input_parameter_file.substr(
138 input_parameter_file.find_last_of(
"/") + 1);
139 output_parameter_file =
"used_" + rel_name;
143 output_parameter_file =
"used_" + exename +
".prm";
147 cli({
"o",
"output_prm_file"}, output_parameter_file) >>
148 output_parameter_file;
150 deallog <<
"Will run in dimension " << dim <<
" and spacedimension "
151 << spacedim << std::endl
152 <<
"Input parameter file: " << input_parameter_file << std::endl
153 <<
"Output parameter file: " << output_parameter_file << std::endl;
155 return std::make_tuple(prm_dim,
157 input_parameter_file,
158 output_parameter_file);
184 const std::string &input_parameter_file,
185 const std::string &output_parameter_file)
187 argh::parser cli(argv, argh::parser::PREFER_PARAM_FOR_UNREG_OPTION);
190 if (cli[{
"h",
"help"}])
192 auto format = [](
const auto &a,
const auto &
b) {
193 return TextFlow::Column(a).width(34) + TextFlow::Column(
b).width(46);
197 const std::string exename =
198 cli(0).str().substr(cli(0).str().find_last_of(
"/") + 1);
201 <<
"Usage: " << cli(0).str() <<
" [OPTIONS] [PRM FILE]" << std::endl
202 <<
"Options:" << std::endl
203 << format(
"-h, --help",
"Print this help message") << std::endl
205 "-i, --input_prm_file <filename>",
206 "Input parameter file. Defaults"
207 " to the empty string (meaning: use the default values, or the "
208 "values specified on the command line). Notice that you can "
209 "specify the input paramter file also as the first positional arguement to the program.")
212 "-o, --output_prm_file <filename>",
213 "Where to write the file containing the actual parameters "
214 "used in this run of the program. It defaults to the string `used_" +
216 "' if the input parameter file is not specified, "
217 "otherwise it defaults to the string `used_' followed by the "
218 "name of the input parameter file.")
222 "Dimension at which this program should be run. Defaults to 2.")
225 "-s, --spacedim <value>",
226 "Space dimension at which this program should run. Defaults to 2.")
229 "-\"Section/option name\"=<value>",
230 "Any of the options that you can specify in the parameter file. "
231 "The format here is the following: "
232 "-\"Section/Subsection/option\"=\"value,another value\", "
233 "where the quotes are required only if an otpion contains spaces, "
234 "or if a value contains separators, like commas, columns, etc.")
236 << format(
"-pause",
"Wait for a keypress to attach a debugger.")
244 std::set<std::string> non_prm{
"h",
255 for (
auto &p : cli.params())
256 if (non_prm.find(p.first) == non_prm.end())
259 const std::string entry = path.back();
262 for (
const auto &
sec : path)
267 for (
const auto &
sec : path)
274 for (
auto &p : cli.pos_args())
275 if (p != argv[0] && p != input_parameter_file)
277 deallog <<
"WARNING -- ignoring positional argument: " << p
283 output_parameter_file,
289 std::cout <<
"============================================" << std::endl
290 <<
"PID: " << getpid() << std::endl
291 <<
"============================================" << std::endl
292 <<
"Press any key to continue..." << std::endl
293 <<
"============================================"
static void initialize(const std::string &filename="", const std::string &output_filename="", const ParameterHandler::OutputStyle output_style_for_output_filename=ParameterHandler::Short, ParameterHandler &prm=ParameterAcceptor::prm, const ParameterHandler::OutputStyle output_style_for_filename=ParameterHandler::DefaultStyle)
static ParameterHandler prm
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="", const bool skip_undefined=false)
void enter_subsection(const std::string &subsection, const bool create_path_if_needed=true)
std::ostream & print_parameters(std::ostream &out, const OutputStyle style) const
long int get_integer(const std::string &entry_string) const
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation="", const bool has_to_be_set=false)
void set(const std::string &entry_name, const std::string &new_value)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Expression sec(const Expression &x)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Gather some functions and classes typically used in the main() of the FSI-suite applications.
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,...
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.
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 dimensio...