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_(
""),
85 yaml_balance_output_(false)
90 PythonLoader::initialize();
118 stringstream log_name;
120 if ( log_filename ==
"//" ) {
141 #ifdef FLOW123D_HAVE_PETSC
142 PetscErrorCode Application::petscvfprintf(FILE *fd,
const char format[], va_list Argp) {
146 if (fd != stdout && fd != stderr) {
147 ierr = PetscVFPrintfDefault(fd,
format,Argp); CHKERRQ(ierr);
149 const int buf_size = 65000;
152 ierr = PetscVSNPrintf(buff,buf_size,
format,&length,Argp);CHKERRQ(ierr);
157 PetscFunctionReturn(0);
163 #ifdef FLOW123D_HAVE_PETSC
168 PetscVFPrintf = this->petscvfprintf;
172 PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
181 MessageOut() <<
"MPI size: " << mpi_size << std::endl;
188 #ifdef FLOW123D_HAVE_PETSC
191 PetscErrorCode ierr=0;
193 ierr = PetscFinalize(); CHKERRQ(ierr);
208 #ifdef FLOW123D_HAVE_PERMON
209 PermonInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
214 #ifdef FLOW123D_HAVE_PERMON
217 PetscErrorCode ierr=0;
219 ierr = PermonFinalize(); CHKERRQ(ierr);
244 #ifndef FLOW123D_COMPILER_FLAGS_
245 #define FLOW123D_COMPILER_FLAGS_ "(unknown compiler flags)"
254 rev_num_data.
version = string(FLOW123D_VERSION_NAME_);
255 rev_num_data.
revision = string(FLOW123D_GIT_REVISION_);
256 rev_num_data.
branch = string(FLOW123D_GIT_BRANCH_);
257 rev_num_data.
url = string(FLOW123D_GIT_URL_);
267 "Version of Flow123d for which the input file was created."
268 "Flow123d only warn about version incompatibility. "
269 "However, external tools may use this information to provide conversion "
270 "of the input file to the structure required by another version of Flow123d.")
272 "Simulation problem to be solved.")
274 "If true, the program will wait for key press before it terminates.")
292 string build = string(__DATE__) +
", " + string(__TIME__)
296 MessageOut().fmt(
"This is Flow123d, version {} commit: {}\n",
298 MessageOut().fmt(
"Branch: {}\nBuild: {}\nFetch URL: {}\n",
299 rev_num_data.
branch, build, rev_num_data.
url );
307 cout <<
"Usage error: The main input file has to be specified through -s parameter.\n\n";
324 namespace po = boost::program_options;
329 po::options_description desc(
"Allowed options");
331 (
"help",
"produce help message")
332 (
"solve,s", po::value< string >(),
"Main input file to solve.")
333 (
"input_dir,i", po::value< string >()->default_value(
"input"),
"Directory for the $INPUT_DIR$ placeholder in the main input file.")
334 (
"output_dir,o", po::value< string >()->default_value(
"output"),
"Directory for all produced output files.")
335 (
"log,l", po::value< string >()->default_value(
"flow123"),
"Set base name for log files.")
336 (
"version",
"Display version and build information and exit.")
337 (
"no_log",
"Turn off logging.")
338 (
"no_signal_handler",
"Turn off signal handling. Useful for debugging with valgrind.")
339 (
"no_profiler,no-profiler",
"Turn off profiler output.")
340 (
"profiler_path,profiler-path", po::value< string >(),
"Path to the profiler file")
341 (
"input_format", po::value< string >(),
"Writes full structure of the main input file into given file.")
342 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.")
343 (
"yaml_balance",
"Redirect balance output to YAML format too (simultaneously with the selected balance output format).");
351 po::variables_map vm;
352 auto parser = po::basic_command_line_parser<char>(argc, argv)
354 .allow_unregistered();
355 po::parsed_options parsed = parser.run();
356 po::store(parsed, vm);
361 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
380 if (vm.count(
"no_profiler")) {
384 if (vm.count(
"profiler_path")) {
389 if (vm.count(
"help")) {
392 cout <<
"Usage:" << endl;
393 cout <<
" flow123d -s <main_input>.yaml <other options> <PETSC options>" << endl;
394 cout <<
" flow123d <main_input>.yaml <other options> <PETSC options>" << endl;
395 cout << desc <<
"\n";
396 THROW(ExcNoRunOption());
400 if (vm.count(
"version")) {
402 THROW(ExcNoRunOption());
408 if (vm.count(
"input_format")) {
410 ofstream json_stream;
418 THROW(ExcNoRunOption());
422 if (vm.count(
"petsc_redirect")) {
426 if (vm.count(
"no_signal_handler")) {
431 string input_filename =
"";
434 if (to_pass_further.size()) {
435 string file_candidate = to_pass_further[0];
436 if (file_candidate[0] !=
'-') {
438 input_filename = file_candidate;
439 to_pass_further.erase(to_pass_further.begin());
444 if (vm.count(
"solve")) {
445 input_filename = vm[
"solve"].as<
string>();
449 if (input_filename ==
"")
450 THROW(ExcMessage() << EI_Message(
"Main input file not specified (option -s)."));
457 if (vm.count(
"input_dir")) {
458 input_dir = vm[
"input_dir"].as<
string>();
460 if (vm.count(
"output_dir")) {
461 output_dir = vm[
"output_dir"].as<
string>();
469 }
catch (FilePath::ExcMkdirFail &e) {
474 if (vm.count(
"log")) {
478 if (vm.count(
"no_log")) {
497 string build = string(__DATE__) +
", " + string(__TIME__)
531 using namespace Input;
533 std::regex version_re(
"([^.]*)[.]([^.]*)[.]([^.]*)");
535 std::string version(FLOW123D_VERSION_NAME_);
537 if ( std::regex_match(version, match, version_re) ) {
538 ver_fields[0]=match[1];
539 ver_fields[1]=match[2];
540 ver_fields[2]=match[3];
545 std::string input_version = i_rec.
val<
string>(
"flow123d_version");
547 if ( std::regex_match(input_version, match, version_re) ) {
548 iver_fields[0]=match[1];
549 iver_fields[1]=match[2];
550 iver_fields[2]=match[3];
552 THROW( ExcVersionFormat() << EI_InputVersionStr(input_version) );
555 if ( iver_fields[0] != ver_fields[0] || iver_fields[1] > ver_fields[1] ) {
556 WarningOut().fmt(
"Input file with version: '{}' is no compatible with the program version: '{}' \n",
557 input_version, version);
572 THROW( ExcUnknownProblem() );
585 printf(
"\nPress <ENTER> for closing the window\n");
592 namespace py = pybind11;
594 if (json_filepath ==
"")
return;
597 auto python_module = PythonLoader::load_module_by_name (
"profiler.profiler_formatter_module");
601 auto convert_method = python_module.attr(
"convert");
603 convert_method(json_filepath, (json_filepath + output_file_suffix), formatter);
616 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)
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 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.