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 (
"latex_doc",
"Prints description of the main input file in Latex format using particular macros.")
177 (
"JSON_machine",
"Prints full structure of the main input file as a valid CON file.")
178 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.");
183 po::variables_map vm;
184 po::parsed_options parsed = po::basic_command_line_parser<char>(argc, argv).options(desc).allow_unregistered().run();
185 po::store(parsed, vm);
189 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
200 passed_argc_ = arg_i;
203 if (vm.count(
"help")) {
204 cout << desc <<
"\n";
208 if (vm.count(
"version")) {
214 if (vm.count(
"full_doc")) {
222 if (vm.count(
"latex_doc")) {
230 if (vm.count(
"JSON_machine")) {
236 if (vm.count(
"petsc_redirect")) {
241 if (vm.count(
"solve")) {
242 string input_filename = vm[
"solve"].as<
string>();
251 if (vm.count(
"input_dir")) {
252 input_dir = vm[
"input_dir"].as<
string>();
254 if (vm.count(
"output_dir")) {
255 output_dir = vm[
"output_dir"].as<
string>();
261 if (vm.count(
"log")) {
265 if (vm.count(
"no_log")) {
286 using namespace Input;
315 printf(
"\nPress <ENTER> for closing the window\n");
336 int main(
int argc,
char **argv) {
339 app.
init(argc, argv);
340 }
catch (std::exception & e) {
341 std::cerr << e.what();
344 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()