27 #ifdef FLOW123D_HAVE_PETSC
30 #include <petsc/private/petscimpl.h>
33 #ifdef FLOW123D_HAVE_PERMON
34 #include <permonsys.h>
42 #include "petscerror.h"
55 if (signal == SIGINT) {
58 if (signal == SIGFPE ||
64 THROW( ExcSignal() << EI_Signal(signal) << EI_SignalName(strsignal(signal)) );
66 return PetscSignalHandlerDefault(signal,(
void*)0);
78 signal_handler_off_(false),
80 main_input_filename_(
""),
84 memory_monitoring(false),
86 yaml_balance_output_(false)
91 PythonLoader::initialize();
119 stringstream log_name;
121 if ( log_filename ==
"//" ) {
142 #ifdef FLOW123D_HAVE_PETSC
143 PetscErrorCode Application::petscvfprintf(FILE *fd,
const char format[], va_list Argp) {
147 if (fd != stdout && fd != stderr) {
148 ierr = PetscVFPrintfDefault(fd,
format,Argp); CHKERRQ(ierr);
150 const int buf_size = 65000;
153 ierr = PetscVSNPrintf(buff,buf_size,
format,&length,Argp);CHKERRQ(ierr);
158 PetscFunctionReturn(0);
164 #ifdef FLOW123D_HAVE_PETSC
169 PetscVFPrintf = this->petscvfprintf;
173 PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
182 MessageOut() <<
"MPI size: " << mpi_size << std::endl;
189 #ifdef FLOW123D_HAVE_PETSC
192 PetscErrorCode ierr=0;
194 ierr = PetscFinalize(); CHKERRQ(ierr);
209 #ifdef FLOW123D_HAVE_PERMON
210 PermonInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
215 #ifdef FLOW123D_HAVE_PERMON
218 PetscErrorCode ierr=0;
220 ierr = PermonFinalize(); CHKERRQ(ierr);
245 #ifndef FLOW123D_COMPILER_FLAGS_
246 #define FLOW123D_COMPILER_FLAGS_ "(unknown compiler flags)"
255 rev_num_data.
version = string(FLOW123D_VERSION_NAME_);
256 rev_num_data.
revision = string(FLOW123D_GIT_REVISION_);
257 rev_num_data.
branch = string(FLOW123D_GIT_BRANCH_);
258 rev_num_data.
url = string(FLOW123D_GIT_URL_);
268 "Version of Flow123d for which the input file was created."
269 "Flow123d only warn about version incompatibility. "
270 "However, external tools may use this information to provide conversion "
271 "of the input file to the structure required by another version of Flow123d.")
273 "Simulation problem to be solved.")
275 "If true, the program will wait for key press before it terminates.")
293 string build = string(__DATE__) +
", " + string(__TIME__)
297 MessageOut().fmt(
"This is Flow123d, version {} commit: {}\n",
299 MessageOut().fmt(
"Branch: {}\nBuild: {}\nFetch URL: {}\n",
300 rev_num_data.
branch, build, rev_num_data.
url );
308 cout <<
"Usage error: The main input file has to be specified through -s parameter.\n\n";
325 namespace po = boost::program_options;
330 po::options_description desc(
"Allowed options");
332 (
"help",
"produce help message")
333 (
"solve,s", po::value< string >(),
"Main input file to solve.")
334 (
"input_dir,i", po::value< string >()->default_value(
"input"),
"Directory for the $INPUT_DIR$ placeholder in the main input file.")
335 (
"output_dir,o", po::value< string >()->default_value(
"output"),
"Directory for all produced output files.")
336 (
"log,l", po::value< string >()->default_value(
"flow123"),
"Set base name for log files.")
337 (
"version",
"Display version and build information and exit.")
338 (
"no_log",
"Turn off logging.")
339 (
"no_signal_handler",
"Turn off signal handling. Useful for debugging with valgrind.")
340 (
"no_profiler,no-profiler",
"Turn off profiler output.")
341 (
"profiler_path,profiler-path", po::value< string >(),
"Path to the profiler file")
342 (
"memory_monitoring,memory-monitoring",
"Switch on memory monitoring.")
343 (
"input_format", po::value< string >(),
"Writes full structure of the main input file into given file.")
344 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.")
345 (
"yaml_balance",
"Redirect balance output to YAML format too (simultaneously with the selected balance output format).");
353 po::variables_map vm;
354 auto parser = po::basic_command_line_parser<char>(argc, argv)
356 .allow_unregistered();
357 po::parsed_options parsed = parser.run();
358 po::store(parsed, vm);
363 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
382 if (vm.count(
"no_profiler")) {
386 if (vm.count(
"profiler_path")) {
390 if (vm.count(
"memory_monitoring")) {
395 if (vm.count(
"help")) {
398 cout <<
"Usage:" << endl;
399 cout <<
" flow123d -s <main_input>.yaml <other options> <PETSC options>" << endl;
400 cout <<
" flow123d <main_input>.yaml <other options> <PETSC options>" << endl;
401 cout << desc <<
"\n";
402 THROW(ExcNoRunOption());
406 if (vm.count(
"version")) {
408 THROW(ExcNoRunOption());
414 if (vm.count(
"input_format")) {
416 ofstream json_stream;
424 THROW(ExcNoRunOption());
428 if (vm.count(
"petsc_redirect")) {
432 if (vm.count(
"no_signal_handler")) {
437 string input_filename =
"";
440 if (to_pass_further.size()) {
441 string file_candidate = to_pass_further[0];
442 if (file_candidate[0] !=
'-') {
444 input_filename = file_candidate;
445 to_pass_further.erase(to_pass_further.begin());
450 if (vm.count(
"solve")) {
451 input_filename = vm[
"solve"].as<
string>();
455 if (input_filename ==
"")
456 THROW(ExcMessage() << EI_Message(
"Main input file not specified (option -s)."));
463 if (vm.count(
"input_dir")) {
464 input_dir = vm[
"input_dir"].as<
string>();
466 if (vm.count(
"output_dir")) {
467 output_dir = vm[
"output_dir"].as<
string>();
475 }
catch (FilePath::ExcMkdirFail &e) {
480 if (vm.count(
"log")) {
484 if (vm.count(
"no_log")) {
503 string build = string(__DATE__) +
", " + string(__TIME__)
538 using namespace Input;
540 std::regex version_re(
"([^.]*)[.]([^.]*)[.]([^.]*)");
542 std::string version(FLOW123D_VERSION_NAME_);
544 if ( std::regex_match(version, match, version_re) ) {
545 ver_fields[0]=match[1];
546 ver_fields[1]=match[2];
547 ver_fields[2]=match[3];
552 std::string input_version = i_rec.
val<
string>(
"flow123d_version");
554 if ( std::regex_match(input_version, match, version_re) ) {
555 iver_fields[0]=match[1];
556 iver_fields[1]=match[2];
557 iver_fields[2]=match[3];
559 THROW( ExcVersionFormat() << EI_InputVersionStr(input_version) );
562 if ( iver_fields[0] != ver_fields[0] || iver_fields[1] > ver_fields[1] ) {
563 WarningOut().fmt(
"Input file with version: '{}' is no compatible with the program version: '{}' \n",
564 input_version, version);
579 THROW( ExcUnknownProblem() );
592 printf(
"\nPress <ENTER> for closing the window\n");
599 namespace py = pybind11;
601 if (json_filepath ==
"")
return;
604 auto python_module = PythonLoader::load_module_by_name (
"profiler.profiler_formatter_module");
608 auto convert_method = python_module.attr(
"convert");
610 convert_method(json_filepath, (json_filepath + output_file_suffix), formatter);
623 string profiler_json;
PetscErrorCode petsc_signal_handler(int signal, FMT_UNUSED void *context)
void _transform_profiler_data(const string &json_filepath, const string &output_file_suffix, const string &formatter)
void system_signal_handler(int signal)
#define FLOW123D_COMPILER_FLAGS_
named version of the program
Input::Type::RevNumData get_rev_num_data()
#define ASSERT_PERMANENT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
static bool permon_initialized
string main_input_filename_
filename of main input file
Input::Record read_input()
static FILE * petsc_output_
File handler for redirecting PETSc output.
static const int exit_failure
string program_arguments_desc_
Description of possible command line arguments.
void init(int argc, char **argv)
~Application()
Destructor.
void system_init(MPI_Comm comm, const string &log_filename)
bool use_profiler
If true, we do output of profiling information.
string profiler_path
location of the profiler report file
void permon_initialize(int argc, char **argv)
static Input::Type::Record & get_input_type()
Root of the Input::Type tree. Description of whole input structure.
string petsc_redirect_file_
void petsc_initialize(int argc, char **argv)
Input::Record root_record
root input record
void parse_cmd_line(const int argc, char **argv)
bool memory_monitoring
If true, memory monitoring is switched on.
HC_ExplicitSequential * problem_
Get version of program and other base data from rev_num.h and store them to map.
static bool petsc_initialized
bool signal_handler_off_
Turn off signal handling useful to debug with valgrind.
static void set_yaml_output()
Set global variable to output balance files into YAML format (in addition to the table format).
static Input::Type::Abstract & get_input_type()
Dedicated class for storing path to input and output files.
void open_stream(Stream &stream) const
static string set_dirs_from_input(const string main_yaml, const string input, const string output)
Method for set input and output directories.
Class for solution of steady or unsteady flow with sequentially coupled explicit transport.
static const Input::Type::Record & get_input_type()
static LoggerOptions & get_instance()
Getter of singleton instance object.
int setup_mpi(MPI_Comm comm)
Set rank of actual process by MPI communicator.
void set_log_file(std::string log_file_base)
Initialize instance object in format 'log_file_base.process.log'.
static void uninitialize()
void output(MPI_Comm, ostream &)
static void set_memory_monitoring(bool)
static Profiler * instance(bool clear=false)
void set_program_info(string, string, string, string, string)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
#define WarningOut()
Macro defining 'warning' record of log.
#define MessageOut()
Macro defining 'message' record of log.
manipulators::Array< T, Delim > format(T const &deduce, Delim delim=", ")
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
#define END_TIMER(tag)
Ends a timer with specified tag.
#define START_TIMER(tag)
Starts a timer with specified tag.