45 #include <boost/program_options/parsers.hpp>
46 #include <boost/program_options/variables_map.hpp>
47 #include <boost/program_options/options_description.hpp>
55 #define _PROGRAM_VERSION_ "0.0.0"
57 #ifndef _PROGRAM_REVISION_
58 #define _PROGRAM_REVISION_ "(unknown revision)"
61 #ifndef _PROGRAM_BRANCH_
62 #define _PROGRAM_BRANCH_ "(unknown branch)"
65 #ifndef _COMPILER_FLAGS_
66 #define _COMPILER_FLAGS_ "(unknown compiler flags)"
72 namespace it = Input::Type;
78 =
it::Record(
"Root",
"Root record of JSON input for Flow123d.")
81 "Simulation problem to be solved.")
83 "If true, the program will wait for key press before it terminates.");
92 main_input_filename_(
""),
100 PythonLoader::initialize(argv[0]);
109 if (delim_pos < string::npos) {
112 directory =path.substr(0,delim_pos);
113 file_name =path.substr(delim_pos+1);
123 string version(_VERSION_NAME_);
124 string revision(_GIT_REVISION_);
125 string branch(_GIT_BRANCH_);
126 string url(_GIT_URL_);
127 string build = string(__DATE__) +
", " + string(__TIME__) +
" flags: " + string(
_COMPILER_FLAGS_);
130 xprintf(
Msg,
"This is Flow123d, version %s revision: %s\n", version.c_str(), revision.c_str());
135 branch.c_str(), build.c_str() , url.c_str() );
143 cout <<
"Usage error: The main input file has to be specified through -s parameter.\n\n";
150 std::ifstream in_stream(fname.c_str());
152 xprintf(
UsrErr,
"Can not open main input file: '%s'.\n", fname.c_str());
157 }
catch (Input::JSONToStorage::ExcInputError &e ) {
158 e << Input::JSONToStorage::EI_File(fname);
throw;
159 }
catch (Input::JSONToStorage::ExcNotJSONFormat &e) {
160 e << Input::JSONToStorage::EI_File(fname);
throw;
170 namespace po = boost::program_options;
174 po::options_description desc(
"Allowed options");
176 (
"help",
"produce help message")
177 (
"solve,s", po::value< string >(),
"Main input file to solve.")
178 (
"input_dir,i", po::value< string >()->default_value(
"input"),
"Directory for the ${INPUT} placeholder in the main input file.")
179 (
"output_dir,o", po::value< string >()->default_value(
"output"),
"Directory for all produced output files.")
180 (
"log,l", po::value< string >()->default_value(
"flow123"),
"Set base name for log files.")
181 (
"version",
"Display version and build information and exit.")
182 (
"no_log",
"Turn off logging.")
183 (
"no_profiler",
"Turn off profiler output.")
184 (
"full_doc",
"Prints full structure of the main input file.")
185 (
"JSON_template",
"Prints description of the main input file as a valid CON file.")
186 (
"latex_doc",
"Prints description of the main input file in Latex format using particular macros.")
187 (
"JSON_machine",
"Prints full structure of the main input file as a valid CON file.")
188 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.");
193 po::variables_map vm;
194 po::parsed_options parsed = po::basic_command_line_parser<char>(argc, argv).options(desc).allow_unregistered().run();
195 po::store(parsed, vm);
199 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
210 passed_argc_ = arg_i;
213 if (vm.count(
"help")) {
214 cout << desc <<
"\n";
218 if (vm.count(
"version")) {
224 if (vm.count(
"full_doc")) {
232 if (vm.count(
"JSON_template")) {
238 if (vm.count(
"latex_doc")) {
246 if (vm.count(
"JSON_machine")) {
252 if (vm.count(
"petsc_redirect")) {
257 if (vm.count(
"solve")) {
258 string input_filename = vm[
"solve"].as<
string>();
267 if (vm.count(
"input_dir")) {
268 input_dir = vm[
"input_dir"].as<
string>();
270 if (vm.count(
"output_dir")) {
271 output_dir = vm[
"output_dir"].as<
string>();
277 if (vm.count(
"log")) {
281 if (vm.count(
"no_log")) {
304 using namespace Input;
333 printf(
"\nPress <ENTER> for closing the window\n");
354 int main(
int argc,
char **argv) {
357 app.
init(argc, argv);
358 }
catch (std::exception & e) {
359 std::cerr << e.what();
362 std::cerr <<
"Unknown exception" << endl;
416 void main_compute_mh(
struct Problem *problem) {
417 int type=
OptGetInt(
"Global",
"Problem_type", NULL);
419 case STEADY_SATURATED:
420 main_compute_mh_steady_saturated(problem);
422 case UNSTEADY_SATURATED:
423 main_compute_mh_unsteady_saturated(problem);
425 case PROBLEM_DENSITY:
436 void main_compute_mh_unsteady_saturated(
struct Problem *problem)
439 const string& mesh_file_name = IONameHandler::get_instance()->get_input_file_name(
OptGetStr(
"Input",
"Mesh", NULL));
443 meshReader->
read(mesh_file_name, mesh);
445 mesh->setup_materials(* problem->material_database);
452 string output_file = IONameHandler::get_instance()->get_output_file_name(
OptGetFileName(
"Output",
"Output_file",
"\\"));
453 output_time =
new OutputTime(mesh, output_file);
460 TimeMark::Type output_mark_type = main_time_marks->new_strict_mark_type();
463 while (! water_time.
is_end()) {
464 water->compute_one_step();
465 water_output->postprocess();
467 if ( main_time_marks->
is_current(water_time, output_mark_type) ) {
468 output_time->get_data_from_mesh();
472 output_time->free_data_from_mesh();
480 void main_compute_mh_steady_saturated(
struct Problem *problem)
482 const string& mesh_file_name = IONameHandler::get_instance()->get_input_file_name(
OptGetStr(
"Input",
"Mesh", NULL));
486 meshReader->
read(mesh_file_name, mesh);
488 mesh->setup_materials(* problem->material_database);
502 problem->water=
new DarcyFlowMH_Steady(main_time_marks, mesh, problem->material_database);
506 problem->water->compute_one_step();
508 if (
OptGetBool(
"Transport",
"Transport_on",
"no") ==
true) {
514 water_output->postprocess();
517 string out_fname = IONameHandler::get_instance()->get_output_file_name(
OptGetFileName(
"Output",
"Output_file", NULL));
518 Output *output =
new Output(mesh, out_fname);
519 output->get_data_from_mesh();
522 output->write_data();
523 output->free_data_from_mesh();
588 if (
OptGetBool(
"Transport",
"Transport_on",
"no") ==
true) {
589 problem->otransport->convection();
627 void main_compute_mh_density(
struct Problem *problem)
629 Mesh* mesh = (
Mesh*) ConstantDB::getInstance()->getObject(MESH::MAIN_INSTANCE);
630 int i, j, dens_step, n_step, frame = 0, rank;
631 double save_step, stop_time;
644 output_time =
new OutputTime(mesh, problem->otransport->transport_out_fname);
void add_time_marks(double time, double dt, double end_time, TimeMark::Type type)
double end_time() const
End time.
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.
bool is_end() const
Returns true if the actual time is greater than or equal to the end time.
static Input::Type::AbstractRecord input_type
Coupling of a transport model with a reaction model by operator splitting.
bool OptGetBool(const char *section, const char *key, const char *defval)
char * xstrcpy(const char *src)
MAKE BRAND NEW COPY OF STRING.
Basic time management functionality for unsteady (and steady) solvers (class Equation).
char * OptGetFileName(const char *section, const char *key, const char *defval)
bool use_profiler
If true, we do output of profiling information.
string petsc_redirect_file_
static void uninitialize()
unsigned int n_elements() const
static const int exit_failure
bool is_current(const TimeGovernor &tg, const TimeMark::Type &mask) const
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) ...
Mixed-hybrid model of linear Darcy flow, possibly unsteady.
long int OptGetInt(const char *section, const char *key, const char *defval)
The class for outputing data during time.
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)
double OptGetDbl(const char *section, const char *key, const char *defval)
This class is a collection of time marks to manage various events occurring during simulation time...
static Input::Type::Record input_type
int main(int argc, char **argv)
void init(int argc, char **argv)
virtual void read(const std::string &file_name, Mesh *)=0
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
virtual int write_data(void)=0
Edge lumped mixed-hybrid solution of unsteady Darcy flow.
string program_arguments_desc_
Description of possible command line arguments.
Mixed-hybrid of steady Darcy flow with sources and variable density.
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)
char * OptGetStr(const char *section, const char *key, const char *defval)
Create new string from selected variable from ini file.
Input::Record read_input()