31 #include <boost/regex.hpp> 32 #include <boost/program_options/parsers.hpp> 33 #include <boost/program_options/variables_map.hpp> 34 #include <boost/program_options/options_description.hpp> 35 #include <boost/filesystem.hpp> 52 #ifndef FLOW123D_COMPILER_FLAGS_ 53 #define FLOW123D_COMPILER_FLAGS_ "(unknown compiler flags)" 63 "Version of Flow123d for which the input file was created." 64 "Flow123d only warn about version incompatibility. " 65 "However, external tools may use this information to provide conversion " 66 "of the input file to the structure required by another version of Flow123d.")
68 "Simulation problem to be solved.")
70 "If true, the program will wait for key press before it terminates.")
89 #ifdef FLOW123D_HAVE_PYTHON 90 PythonLoader::initialize(argv[0]);
99 rev_num_data.
version = string(FLOW123D_VERSION_NAME_);
100 rev_num_data.
revision = string(FLOW123D_GIT_REVISION_);
101 rev_num_data.
branch = string(FLOW123D_GIT_BRANCH_);
102 rev_num_data.
url = string(FLOW123D_GIT_URL_);
112 string build = string(__DATE__) +
", " + string(__TIME__)
116 MessageOut().fmt(
"This is Flow123d, version {} commit: {}\n",
118 MessageOut().fmt(
"Branch: {}\nBuild: {}\nFetch URL: {}\n",
119 rev_num_data.
branch, build, rev_num_data.
url );
128 cout <<
"Usage error: The main input file has to be specified through -s parameter.\n\n";
138 }
catch (Input::ReaderToStorage::ExcInputError &e ) {
139 e << Input::ReaderToStorage::EI_File(fpath);
throw;
140 }
catch (Input::ReaderToStorage::ExcNotJSONFormat &e) {
141 e << Input::ReaderToStorage::EI_File(fpath);
throw;
149 namespace po = boost::program_options;
153 po::options_description desc(
"Allowed options");
155 (
"help",
"produce help message")
156 (
"solve,s", po::value< string >(),
"Main input file to solve.")
157 (
"input_dir,i", po::value< string >()->default_value(
"input"),
"Directory for the ${INPUT} placeholder in the main input file.")
158 (
"output_dir,o", po::value< string >()->default_value(
"output"),
"Directory for all produced output files.")
159 (
"log,l", po::value< string >()->default_value(
"flow123"),
"Set base name for log files.")
160 (
"version",
"Display version and build information and exit.")
161 (
"no_log",
"Turn off logging.")
162 (
"no_signal_handler",
"Turn off signal handling. Useful for debugging with valgrind.")
163 (
"no_profiler",
"Turn off profiler output.")
164 (
"input_format", po::value< string >(),
"Writes full structure of the main input file into given file.")
165 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.")
166 (
"yaml_balance",
"Redirect balance output to YAML format too (simultaneously with the selected balance output format).");
174 po::variables_map vm;
175 auto parser = po::basic_command_line_parser<char>(argc, argv)
177 .allow_unregistered();
178 po::parsed_options parsed = parser.run();
179 po::store(parsed, vm);
183 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
201 if (vm.count(
"help")) {
204 cout <<
"Usage:" << endl;
205 cout <<
" flow123d -s <main_input>.yaml <other options> <PETSC options>" << endl;
206 cout <<
" flow123d <main_input>.yaml <other options> <PETSC options>" << endl;
207 cout << desc <<
"\n";
211 if (vm.count(
"version")) {
217 if (vm.count(
"input_format")) {
219 ofstream json_stream;
230 if (vm.count(
"petsc_redirect")) {
234 if (vm.count(
"no_signal_handler")) {
239 string input_filename =
"";
242 if (to_pass_further.size()) {
243 string file_candidate = to_pass_further[0];
244 if (file_candidate[0] !=
'-') {
246 input_filename = file_candidate;
247 to_pass_further.erase(to_pass_further.begin());
251 if (vm.count(
"solve")) {
252 input_filename = vm[
"solve"].as<
string>();
255 if (input_filename ==
"")
256 THROW(ExcMessage() << EI_Message(
"Main input file not specified (option -s)."));
266 if (vm.count(
"input_dir")) {
267 input_dir = vm[
"input_dir"].as<
string>();
269 if (vm.count(
"output_dir")) {
270 output_dir = vm[
"output_dir"].as<
string>();
276 }
catch (FilePath::ExcMkdirFail &e) {
281 if (vm.count(
"log")) {
285 if (vm.count(
"no_log")) {
308 using namespace Input;
310 boost::regex version_re(
"([^.]*)[.]([^.]*)[.]([^.]*)");
312 std::string version(FLOW123D_VERSION_NAME_);
314 if ( boost::regex_match(version, match, version_re) ) {
315 ver_fields[0]=match[1];
316 ver_fields[1]=match[2];
317 ver_fields[2]=match[3];
319 OLD_ASSERT(1,
"Bad Flow123d version format: %s\n", version.c_str() );
322 std::string input_version = i_rec.
val<
string>(
"flow123d_version");
324 if ( boost::regex_match(input_version, match, version_re) ) {
325 iver_fields[0]=match[1];
326 iver_fields[1]=match[2];
327 iver_fields[2]=match[3];
329 THROW( ExcVersionFormat() << EI_InputVersionStr(input_version) );
332 if ( iver_fields[0] != ver_fields[0] || iver_fields[1] > ver_fields[1] ) {
333 WarningOut().fmt(
"Input file with version: '{}' is no compatible with the program version: '{}' \n",
334 input_version, version);
360 printf(
"\nPress <ENTER> for closing the window\n");
377 if (boost::filesystem::exists(mass_file)) {
378 boost::filesystem::remove(mass_file);
380 if (boost::filesystem::exists(water_file)) {
381 boost::filesystem::remove(water_file);
383 if (boost::filesystem::exists(energy_file)) {
384 boost::filesystem::remove(energy_file);
411 int main(
int argc,
char **argv) {
414 app.
init(argc, argv);
415 }
catch (std::exception & e) {
416 _LOG( Logger::MsgType::error ) << e.what();
419 _LOG( Logger::MsgType::error ) <<
"Unknown exception" << endl;
static Input::Type::Abstract & get_input_type()
Input::Type::RevNumData get_rev_num_data()
Get version of program and other base data from rev_num.h and store them to map.
virtual void parse_cmd_line(const int argc, char **argv)
#define MessageOut()
Macro defining 'message' record of log.
string main_input_filename_
filename of main input file
static bool petsc_initialized
Application(int argc, char **argv)
Application constructor.
bool use_profiler
If true, we do output of profiling information.
static string set_dirs_from_input(const string main_yaml, const string input, const string output)
Method for set input and output directories.
string petsc_redirect_file_
HC_ExplicitSequential * problem_
Main Flow123d problem.
void open_stream(Stream &stream) const
static void uninitialize()
static const int exit_failure
static const int exit_success
Return codes of application.
#define _LOG(type)
Internal macro defining universal record of log.
bool yaml_balance_output_
If true, preserves output of balance in YAML format.
#define START_TIMER(tag)
Starts a timer with specified tag.
void set_program_info(string program_name, string program_version, string branch, string revision, string build)
bool signal_handler_off_
Turn off signal handling useful to debug with valgrind.
static Input::Type::Record & get_input_type()
Root of the Input::Type tree. Description of whole input structure.
int main(int argc, char **argv)
void init(int argc, char **argv)
void transform_profiler_data(const string &output_file_suffix, const string &formatter)
Dedicated class for storing path to input and output files.
static const int exit_output
static Profiler * instance()
string program_arguments_desc_
Description of possible command line arguments.
#define WarningOut()
Macro defining 'warning' record of log.
#define END_TIMER(tag)
Ends a timer with specified tag.
static const Input::Type::Record & get_input_type()
Class for solution of steady or unsteady flow with sequentially coupled explicit transport.
virtual ~Application()
Destructor.
#define FLOW123D_COMPILER_FLAGS_
named version of the program
Input::Record root_record
root input record
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
void output(MPI_Comm comm, ostream &os)
Input::Record read_input()
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)