Flow123d
JB_transport-d4c8564
|
Go to the documentation of this file.
31 #include <boost/program_options/parsers.hpp>
32 #include <boost/program_options/variables_map.hpp>
33 #include <boost/program_options/options_description.hpp>
34 #include <boost/filesystem.hpp>
54 #ifndef FLOW123D_COMPILER_FLAGS_
55 #define FLOW123D_COMPILER_FLAGS_ "(unknown compiler flags)"
65 "Version of Flow123d for which the input file was created."
66 "Flow123d only warn about version incompatibility. "
67 "However, external tools may use this information to provide conversion "
68 "of the input file to the structure required by another version of Flow123d.")
70 "Simulation problem to be solved.")
72 "If true, the program will wait for key press before it terminates.")
83 main_input_filename_(
""),
88 yaml_balance_output_(false)
100 rev_num_data.
version = string(FLOW123D_VERSION_NAME_);
101 rev_num_data.
revision = string(FLOW123D_GIT_REVISION_);
102 rev_num_data.
branch = string(FLOW123D_GIT_BRANCH_);
103 rev_num_data.
url = string(FLOW123D_GIT_URL_);
113 string build = string(__DATE__) +
", " + string(__TIME__)
117 MessageOut().fmt(
"This is Flow123d, version {} commit: {}\n",
119 MessageOut().fmt(
"Branch: {}\nBuild: {}\nFetch URL: {}\n",
120 rev_num_data.
branch, build, rev_num_data.
url );
129 cout <<
"Usage error: The main input file has to be specified through -s parameter.\n\n";
146 namespace po = boost::program_options;
150 po::options_description desc(
"Allowed options");
152 (
"help",
"produce help message")
153 (
"solve,s", po::value< string >(),
"Main input file to solve.")
154 (
"input_dir,i", po::value< string >()->default_value(
"input"),
"Directory for the $INPUT_DIR$ placeholder in the main input file.")
155 (
"output_dir,o", po::value< string >()->default_value(
"output"),
"Directory for all produced output files.")
156 (
"log,l", po::value< string >()->default_value(
"flow123"),
"Set base name for log files.")
157 (
"version",
"Display version and build information and exit.")
158 (
"no_log",
"Turn off logging.")
159 (
"no_signal_handler",
"Turn off signal handling. Useful for debugging with valgrind.")
160 (
"no_profiler,no-profiler",
"Turn off profiler output.")
161 (
"profiler_path,profiler-path", po::value< string >(),
"Path to the profiler file")
162 (
"input_format", po::value< string >(),
"Writes full structure of the main input file into given file.")
163 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.")
164 (
"yaml_balance",
"Redirect balance output to YAML format too (simultaneously with the selected balance output format).");
172 po::variables_map vm;
173 auto parser = po::basic_command_line_parser<char>(argc, argv)
175 .allow_unregistered();
176 po::parsed_options parsed = parser.run();
177 po::store(parsed, vm);
181 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
199 if (vm.count(
"no_profiler")) {
203 if (vm.count(
"profiler_path")) {
208 if (vm.count(
"help")) {
211 cout <<
"Usage:" << endl;
212 cout <<
" flow123d -s <main_input>.yaml <other options> <PETSC options>" << endl;
213 cout <<
" flow123d <main_input>.yaml <other options> <PETSC options>" << endl;
214 cout << desc <<
"\n";
218 if (vm.count(
"version")) {
224 if (vm.count(
"input_format")) {
226 ofstream json_stream;
237 if (vm.count(
"petsc_redirect")) {
241 if (vm.count(
"no_signal_handler")) {
246 string input_filename =
"";
249 if (to_pass_further.size()) {
250 string file_candidate = to_pass_further[0];
251 if (file_candidate[0] !=
'-') {
253 input_filename = file_candidate;
254 to_pass_further.erase(to_pass_further.begin());
258 if (vm.count(
"solve")) {
259 input_filename = vm[
"solve"].as<
string>();
262 if (input_filename ==
"")
263 THROW(ExcMessage() << EI_Message(
"Main input file not specified (option -s)."));
270 if (vm.count(
"input_dir")) {
271 input_dir = vm[
"input_dir"].as<
string>();
273 if (vm.count(
"output_dir")) {
274 output_dir = vm[
"output_dir"].as<
string>();
280 }
catch (FilePath::ExcMkdirFail &e) {
285 if (vm.count(
"log")) {
289 if (vm.count(
"no_log")) {
312 using namespace Input;
314 std::regex version_re(
"([^.]*)[.]([^.]*)[.]([^.]*)");
316 std::string version(FLOW123D_VERSION_NAME_);
318 if ( std::regex_match(version, match, version_re) ) {
319 ver_fields[0]=match[1];
320 ver_fields[1]=match[2];
321 ver_fields[2]=match[3];
326 std::string input_version = i_rec.
val<
string>(
"flow123d_version");
328 if ( std::regex_match(input_version, match, version_re) ) {
329 iver_fields[0]=match[1];
330 iver_fields[1]=match[2];
331 iver_fields[2]=match[3];
333 THROW( ExcVersionFormat() << EI_InputVersionStr(input_version) );
336 if ( iver_fields[0] != ver_fields[0] || iver_fields[1] > ver_fields[1] ) {
337 WarningOut().fmt(
"Input file with version: '{}' is no compatible with the program version: '{}' \n",
338 input_version, version);
353 THROW( ExcUnknownProblem() );
366 printf(
"\nPress <ENTER> for closing the window\n");
378 std::this_thread::sleep_for(std::chrono::microseconds(10));
418 int main(
int argc,
char **argv) {
421 app.
init(argc, argv);
423 }
catch (std::exception & e) {
424 _LOG( Logger::MsgType::error ).every_proc() << e.what();
428 _LOG( Logger::MsgType::error ).every_proc() <<
"Unknown exception" << endl;
virtual ~Application()
Destructor.
static Profiler * instance(bool clear=false)
void init(int argc, char **argv)
static Input::Type::Abstract & get_input_type()
void transform_profiler_data(const string &, const string &)
Input::Type::RevNumData get_rev_num_data()
Get version of program and other base data from rev_num.h and store them to map.
Dedicated class for storing path to input and output files.
void output(MPI_Comm, ostream &)
string profiler_path
location of the profiler report file
string main_input_filename_
filename of main input file
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
HC_ExplicitSequential * problem_
Main Flow123d problem.
#define FLOW123D_COMPILER_FLAGS_
named version of the program
static void uninitialize()
void open_stream(Stream &stream) const
Application(const std::string &python_path)
Application constructor.
void set_program_info(string, string, string, string, string)
bool use_profiler
If true, we do output of profiling information.
string petsc_redirect_file_
#define ASSERT_PERMANENT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
#define MPI_Test(request, flag, status)
static Input::Type::Record & get_input_type()
Root of the Input::Type tree. Description of whole input structure.
int main(int argc, char **argv)
static string set_dirs_from_input(const string main_yaml, const string input, const string output)
Method for set input and output directories.
string program_arguments_desc_
Description of possible command line arguments.
static const int exit_output
static bool petsc_initialized
#define _LOG(type)
Internal macro defining universal record of log.
static void set_yaml_output()
Set global variable to output balance files into YAML format (in addition to the table format).
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
#define WarningOut()
Macro defining 'warning' record of log.
bool signal_handler_off_
Turn off signal handling useful to debug with valgrind.
static const int exit_failure
Class for solution of steady or unsteady flow with sequentially coupled explicit transport.
static const Input::Type::Record & get_input_type()
Input::Record read_input()
Input::Record root_record
root input record
#define START_TIMER(tag)
Starts a timer with specified tag.
#define END_TIMER(tag)
Ends a timer with specified tag.
virtual void parse_cmd_line(const int argc, char **argv)
#define MessageOut()
Macro defining 'message' record of log.
static const int exit_success
Return codes of application.