44 #include <boost/program_options/parsers.hpp>
45 #include <boost/program_options/variables_map.hpp>
46 #include <boost/program_options/options_description.hpp>
53 #define _PROGRAM_VERSION_ "0.0.0"
55 #ifndef _PROGRAM_REVISION_
56 #define _PROGRAM_REVISION_ "(unknown revision)"
59 #ifndef _PROGRAM_BRANCH_
60 #define _PROGRAM_BRANCH_ "(unknown branch)"
63 #ifndef _COMPILER_FLAGS_
64 #define _COMPILER_FLAGS_ "(unknown compiler flags)"
68 namespace it = Input::Type;
72 =
it::Record(
"Root",
"Root record of JSON input for Flow123d.")
74 "Simulation problem to be solved.")
76 "If true, the program will wait for key press before it terminates.");
83 main_input_filename_(
""),
91 PythonLoader::initialize(argv[0]);
100 if (delim_pos < string::npos) {
103 directory =path.substr(0,delim_pos);
104 file_name =path.substr(delim_pos+1);
114 string version(_VERSION_NAME_);
115 string revision(_GIT_REVISION_);
116 string branch(_GIT_BRANCH_);
117 string url(_GIT_URL_);
118 string build = string(__DATE__) +
", " + string(__TIME__) +
" flags: " + string(
_COMPILER_FLAGS_);
121 xprintf(
Msg,
"This is Flow123d, version %s revision: %s\n", version.c_str(), revision.c_str());
126 branch.c_str(), build.c_str() , url.c_str() );
134 cout <<
"Usage error: The main input file has to be specified through -s parameter.\n\n";
141 std::ifstream in_stream(fname.c_str());
143 xprintf(
UsrErr,
"Can not open main input file: '%s'.\n", fname.c_str());
148 }
catch (Input::JSONToStorage::ExcInputError &e ) {
149 e << Input::JSONToStorage::EI_File(fname);
throw;
150 }
catch (Input::JSONToStorage::ExcNotJSONFormat &e) {
151 e << Input::JSONToStorage::EI_File(fname);
throw;
161 namespace po = boost::program_options;
165 po::options_description desc(
"Allowed options");
167 (
"help",
"produce help message")
168 (
"solve,s", po::value< string >(),
"Main input file to solve.")
169 (
"input_dir,i", po::value< string >()->default_value(
"input"),
"Directory for the ${INPUT} placeholder in the main input file.")
170 (
"output_dir,o", po::value< string >()->default_value(
"output"),
"Directory for all produced output files.")
171 (
"log,l", po::value< string >()->default_value(
"flow123"),
"Set base name for log files.")
172 (
"version",
"Display version and build information and exit.")
173 (
"no_log",
"Turn off logging.")
174 (
"no_profiler",
"Turn off profiler output.")
175 (
"full_doc",
"Prints full structure of the main input file.")
176 (
"JSON_template",
"Prints description of the main input file as a valid CON file.")
177 (
"latex_doc",
"Prints description of the main input file in Latex format using particular macros.")
178 (
"JSON_machine",
"Prints full structure of the main input file as a valid CON file.")
179 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.");
184 po::variables_map vm;
185 po::parsed_options parsed = po::basic_command_line_parser<char>(argc, argv).options(desc).allow_unregistered().run();
186 po::store(parsed, vm);
190 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
201 passed_argc_ = arg_i;
204 if (vm.count(
"help")) {
205 cout << desc <<
"\n";
209 if (vm.count(
"version")) {
215 if (vm.count(
"full_doc")) {
223 if (vm.count(
"JSON_template")) {
229 if (vm.count(
"latex_doc")) {
237 if (vm.count(
"JSON_machine")) {
243 if (vm.count(
"petsc_redirect")) {
248 if (vm.count(
"solve")) {
249 string input_filename = vm[
"solve"].as<
string>();
258 if (vm.count(
"input_dir")) {
259 input_dir = vm[
"input_dir"].as<
string>();
261 if (vm.count(
"output_dir")) {
262 output_dir = vm[
"output_dir"].as<
string>();
268 if (vm.count(
"log")) {
272 if (vm.count(
"no_log")) {
293 using namespace Input;
322 printf(
"\nPress <ENTER> for closing the window\n");
343 int main(
int argc,
char **argv) {
346 app.
init(argc, argv);
347 }
catch (std::exception & e) {
348 std::cerr << e.what();
351 std::cerr <<
"Unknown exception" << endl;
virtual void parse_cmd_line(const int argc, char **argv)
string main_input_filename_
filename of main input file
static Profiler * instance()
Application(int argc, char **argv)
Application constructor.
static Input::Type::AbstractRecord input_type
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.
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 input_type
int main(int argc, char **argv)
void init(int argc, char **argv)
static void set_io_dirs(const string working_dir, const string root_input, const string input, const string output)
static Input::Type::Record input_type
Root of the Input::Type tree. Description of whole input structure.
static const int exit_output
string program_arguments_desc_
Description of possible command line arguments.
Class for create text documentation.
Class for solution of steady or unsteady flow with sequentially coupled explicit transport.
static bool is_initialized()
virtual ~Application()
Destructor.
Input::Record root_record
root input record
void output(MPI_Comm comm, ostream &os)
Input::Record read_input()