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_ "1.8.1"
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_(
""),
99 std::cout <<
"Application constructor" << std::endl;
102 PythonLoader::initialize(argv[0]);
112 if (delim_pos < string::npos) {
115 directory =path.substr(0,delim_pos);
116 file_name =path.substr(delim_pos+1);
127 string revision(_GIT_REVISION_);
128 string branch(_GIT_BRANCH_);
129 string url(_GIT_URL_);
130 string build = string(__DATE__) +
", " + string(__TIME__) +
" flags: " + string(
_COMPILER_FLAGS_);
133 xprintf(
Msg,
"This is Flow123d, version %s revision: %s\n", version.c_str(), revision.c_str());
138 branch.c_str(), build.c_str() , url.c_str() );
146 cout <<
"Usage error: The main input file has to be specified through -s parameter.\n\n";
153 std::ifstream in_stream(fname.c_str());
155 xprintf(
UsrErr,
"Can not open main input file: '%s'.\n", fname.c_str());
160 }
catch (Input::JSONToStorage::ExcInputError &e ) {
161 e << Input::JSONToStorage::EI_File(fname);
throw;
162 }
catch (Input::JSONToStorage::ExcNotJSONFormat &e) {
163 e << Input::JSONToStorage::EI_File(fname);
throw;
173 namespace po = boost::program_options;
177 po::options_description desc(
"Allowed options");
179 (
"help",
"produce help message")
180 (
"solve,s", po::value< string >(),
"Main input file to solve.")
181 (
"input_dir,i", po::value< string >()->default_value(
"input"),
"Directory for the ${INPUT} placeholder in the main input file.")
182 (
"output_dir,o", po::value< string >()->default_value(
"output"),
"Directory for all produced output files.")
183 (
"log,l", po::value< string >()->default_value(
"flow123"),
"Set base name for log files.")
184 (
"version",
"Display version and build information and exit.")
185 (
"no_log",
"Turn off logging.")
186 (
"no_profiler",
"Turn off profiler output.")
187 (
"full_doc",
"Prints full structure of the main input file.")
188 (
"JSON_template",
"Prints description of the main input file as a valid CON file.")
189 (
"latex_doc",
"Prints description of the main input file in Latex format using particular macros.")
190 (
"JSON_machine",
"Prints full structure of the main input file as a valid CON file.")
191 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.");
196 po::variables_map vm;
197 po::parsed_options parsed = po::basic_command_line_parser<char>(argc, argv).options(desc).allow_unregistered().run();
198 po::store(parsed, vm);
202 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
213 passed_argc_ = arg_i;
216 if (vm.count(
"help")) {
217 cout << desc <<
"\n";
221 if (vm.count(
"version")) {
227 if (vm.count(
"full_doc")) {
235 if (vm.count(
"JSON_template")) {
241 if (vm.count(
"latex_doc")) {
249 if (vm.count(
"JSON_machine")) {
255 if (vm.count(
"petsc_redirect")) {
260 if (vm.count(
"solve")) {
261 string input_filename = vm[
"solve"].as<
string>();
270 if (vm.count(
"input_dir")) {
271 input_dir = vm[
"input_dir"].as<
string>();
273 if (vm.count(
"output_dir")) {
274 output_dir = vm[
"output_dir"].as<
string>();
280 if (vm.count(
"log")) {
284 if (vm.count(
"no_log")) {
307 using namespace Input;
337 printf(
"\nPress <ENTER> for closing the window\n");
358 int main(
int argc,
char **argv) {
361 app.
init(argc, argv);
362 }
catch (std::exception & e) {
363 std::cerr << e.what();
366 std::cerr <<
"Unknown exception" << endl;
414 xprintf(
Err,
"Not implemented yet in this version\n");
420 void main_compute_mh(
struct Problem *problem) {
421 int type=
OptGetInt(
"Global",
"Problem_type", NULL);
423 case STEADY_SATURATED:
424 main_compute_mh_steady_saturated(problem);
426 case UNSTEADY_SATURATED:
427 main_compute_mh_unsteady_saturated(problem);
429 case PROBLEM_DENSITY:
440 void main_compute_mh_unsteady_saturated(
struct Problem *problem)
443 const string& mesh_file_name = IONameHandler::get_instance()->get_input_file_name(
OptGetStr(
"Input",
"Mesh", NULL));
447 meshReader->
read(mesh_file_name, mesh);
449 mesh->setup_materials(* problem->material_database);
456 string output_file = IONameHandler::get_instance()->get_output_file_name(
OptGetFileName(
"Output",
"Output_file",
"\\"));
457 output_time =
new OutputTime(mesh, output_file);
464 TimeMark::Type output_mark_type = main_time_marks->new_strict_mark_type();
467 while (! water_time.
is_end()) {
468 water->compute_one_step();
469 water_output->postprocess();
471 if ( main_time_marks->
is_current(water_time, output_mark_type) ) {
472 output_time->get_data_from_mesh();
476 output_time->free_data_from_mesh();
484 void main_compute_mh_steady_saturated(
struct Problem *problem)
486 const string& mesh_file_name = IONameHandler::get_instance()->get_input_file_name(
OptGetStr(
"Input",
"Mesh", NULL));
490 meshReader->
read(mesh_file_name, mesh);
492 mesh->setup_materials(* problem->material_database);
506 problem->water=
new DarcyFlowMH_Steady(main_time_marks, mesh, problem->material_database);
510 problem->water->compute_one_step();
512 if (
OptGetBool(
"Transport",
"Transport_on",
"no") ==
true) {
518 water_output->postprocess();
521 string out_fname = IONameHandler::get_instance()->get_output_file_name(
OptGetFileName(
"Output",
"Output_file", NULL));
522 Output *output =
new Output(mesh, out_fname);
523 output->get_data_from_mesh();
526 output->write_data();
527 output->free_data_from_mesh();
592 if (
OptGetBool(
"Transport",
"Transport_on",
"no") ==
true) {
593 problem->otransport->convection();
631 void main_compute_mh_density(
struct Problem *problem)
633 Mesh* mesh = (
Mesh*) ConstantDB::getInstance()->getObject(MESH::MAIN_INSTANCE);
634 int i, j, dens_step, n_step, frame = 0, rank;
635 double save_step, stop_time;
648 output_time =
new OutputTime(mesh, problem->otransport->transport_out_fname);