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> 51 #ifndef FLOW123D_COMPILER_FLAGS_ 52 #define FLOW123D_COMPILER_FLAGS_ "(unknown compiler flags)" 62 "Version of Flow123d for which the input file was created." 63 "Flow123d only warn about version incompatibility. " 64 "However, external tools may use this information to provide conversion " 65 "of the input file to the structure required by another version of Flow123d.")
67 "Simulation problem to be solved.")
69 "If true, the program will wait for key press before it terminates.")
87 #ifdef FLOW123D_HAVE_PYTHON 88 PythonLoader::initialize(argv[0]);
97 if (delim_pos < string::npos) {
100 directory =path.substr(0,delim_pos);
101 file_name =path.substr(delim_pos+1);
112 rev_num_data.
version = string(FLOW123D_VERSION_NAME_);
113 rev_num_data.
revision = string(FLOW123D_GIT_REVISION_);
114 rev_num_data.
branch = string(FLOW123D_GIT_BRANCH_);
115 rev_num_data.
url = string(FLOW123D_GIT_URL_);
125 string build = string(__DATE__) +
", " + string(__TIME__)
129 xprintf(
Msg,
"This is Flow123d, version %s revision: %s\n",
136 rev_num_data.
branch.c_str(), build.c_str() , rev_num_data.
url.c_str() );
145 cout <<
"Usage error: The main input file has to be specified through -s parameter.\n\n";
155 }
catch (Input::ReaderToStorage::ExcInputError &e ) {
156 e << Input::ReaderToStorage::EI_File(fpath);
throw;
157 }
catch (Input::ReaderToStorage::ExcNotJSONFormat &e) {
158 e << Input::ReaderToStorage::EI_File(fpath);
throw;
167 namespace po = boost::program_options;
171 po::options_description desc(
"Allowed options");
173 (
"help",
"produce help message")
174 (
"solve,s", po::value< string >(),
"Main input file to solve.")
175 (
"input_dir,i", po::value< string >()->default_value(
"input"),
"Directory for the ${INPUT} placeholder in the main input file.")
176 (
"output_dir,o", po::value< string >()->default_value(
"output"),
"Directory for all produced output files.")
177 (
"log,l", po::value< string >()->default_value(
"flow123"),
"Set base name for log files.")
178 (
"version",
"Display version and build information and exit.")
179 (
"no_log",
"Turn off logging.")
180 (
"no_profiler",
"Turn off profiler output.")
181 (
"JSON_machine", po::value< string >(),
"Writes full structure of the main input file as a valid CON file into given file")
182 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.");
187 po::variables_map vm;
188 po::parsed_options parsed = po::basic_command_line_parser<char>(argc, argv).options(desc).allow_unregistered().run();
189 po::store(parsed, vm);
193 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
204 passed_argc_ = arg_i;
207 if (vm.count(
"help")) {
208 cout << desc <<
"\n";
212 if (vm.count(
"version")) {
227 if (vm.count(
"JSON_machine")) {
229 string json_filename = vm[
"JSON_machine"].as<
string>();
230 ofstream json_stream(json_filename);
232 if (json_stream.fail()) {
233 cerr <<
"Failed to open file '" << json_filename <<
"'" << endl;
244 if (vm.count(
"petsc_redirect")) {
249 if (vm.count(
"solve")) {
250 string input_filename = vm[
"solve"].as<
string>();
259 if (vm.count(
"input_dir")) {
260 input_dir = vm[
"input_dir"].as<
string>();
262 if (vm.count(
"output_dir")) {
263 output_dir = vm[
"output_dir"].as<
string>();
269 if (vm.count(
"log")) {
273 if (vm.count(
"no_log")) {
296 using namespace Input;
298 boost::regex version_re(
"([^.]*)[.]([^.]*)[.]([^.]*)");
300 std::string version(FLOW123D_VERSION_NAME_);
302 if ( boost::regex_match(version, match, version_re) ) {
303 ver_fields[0]=match[1];
304 ver_fields[1]=match[2];
305 ver_fields[2]=match[3];
307 OLD_ASSERT(1,
"Bad Flow123d version format: %s\n", version.c_str() );
310 std::string input_version = i_rec.
val<
string>(
"flow123d_version");
312 if ( boost::regex_match(input_version, match, version_re) ) {
313 iver_fields[0]=match[1];
314 iver_fields[1]=match[2];
315 iver_fields[2]=match[3];
317 THROW( ExcVersionFormat() << EI_InputVersionStr(input_version) );
320 if ( iver_fields[0] != ver_fields[0] || iver_fields[1] > ver_fields[1] ) {
321 xprintf(
Warn,
"Input file with version: '%s' is no compatible with the program version: '%s' \n",
322 input_version.c_str(), version.c_str());
350 printf(
"\nPress <ENTER> for closing the window\n");
382 int main(
int argc,
char **argv) {
385 app.
init(argc, argv);
386 }
catch (std::exception & e) {
387 std::cerr << e.what();
390 std::cerr <<
"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)
string main_input_filename_
filename of main input file
static bool petsc_initialized
Application(int argc, char **argv)
Application constructor.
char * xstrcpy(const char *src)
MAKE BRAND NEW COPY OF STRING.
bool use_profiler
If true, we do output of profiling information.
string petsc_redirect_file_
static void uninitialize()
static const int exit_failure
static const int exit_success
Return codes of application.
#define START_TIMER(tag)
Starts a timer with specified tag.
string main_input_dir_
directory of main input file (used to resolve relative paths of other input files) ...
void split_path(const string &path, string &directory, string &file_name)
void set_program_info(string program_name, string program_version, string branch, string revision, string build)
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 void set_io_dirs(const string working_dir, const string root_input, const string input, const string output)
static const int exit_output
static Profiler * instance()
string program_arguments_desc_
Description of possible command line arguments.
#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()