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 if ( full_file_name.size() > 0 ) {
130 #ifdef FLOW123D_HAVE_PETSC
131 PetscErrorCode Application::petscvfprintf(FILE *fd,
const char format[], va_list Argp) {
135 if (fd != stdout && fd != stderr) {
136 ierr = PetscVFPrintfDefault(fd,
format,Argp); CHKERRQ(ierr);
138 const int buf_size = 65000;
141 ierr = PetscVSNPrintf(buff,buf_size,
format,&length,Argp);CHKERRQ(ierr);
146 PetscFunctionReturn(0);
152 #ifdef FLOW123D_HAVE_PETSC
157 PetscVFPrintf = this->petscvfprintf;
161 PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
170 MessageOut() <<
"MPI size: " << mpi_size << std::endl;
177 #ifdef FLOW123D_HAVE_PETSC
180 PetscErrorCode ierr=0;
182 ierr = PetscFinalize(); CHKERRQ(ierr);
197 #ifdef FLOW123D_HAVE_PERMON
198 PermonInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
203 #ifdef FLOW123D_HAVE_PERMON
206 PetscErrorCode ierr=0;
208 ierr = PermonFinalize(); CHKERRQ(ierr);
233 #ifndef FLOW123D_COMPILER_FLAGS_
234 #define FLOW123D_COMPILER_FLAGS_ "(unknown compiler flags)"
243 rev_num_data.
version = string(FLOW123D_VERSION_NAME_);
244 rev_num_data.
revision = string(FLOW123D_GIT_REVISION_);
245 rev_num_data.
branch = string(FLOW123D_GIT_BRANCH_);
246 rev_num_data.
url = string(FLOW123D_GIT_URL_);
256 "Version of Flow123d for which the input file was created."
257 "Flow123d only warn about version incompatibility. "
258 "However, external tools may use this information to provide conversion "
259 "of the input file to the structure required by another version of Flow123d.")
261 "Simulation problem to be solved.")
263 "If true, the program will wait for key press before it terminates.")
281 string build = string(__DATE__) +
", " + string(__TIME__)
285 MessageOut().fmt(
"This is Flow123d, version {} commit: {}\n",
287 MessageOut().fmt(
"Branch: {}\nBuild: {}\nFetch URL: {}\n",
288 rev_num_data.
branch, build, rev_num_data.
url );
296 cout <<
"Usage error: The main input file has to be specified through -s parameter.\n\n";
313 namespace po = boost::program_options;
318 po::options_description desc(
"Allowed options");
320 (
"help",
"produce help message")
321 (
"solve,s", po::value< string >(),
"Main input file to solve.")
322 (
"input_dir,i", po::value< string >()->default_value(
"input"),
"Directory for the $INPUT_DIR$ placeholder in the main input file.")
323 (
"output_dir,o", po::value< string >()->default_value(
"output"),
"Directory for all produced output files.")
324 (
"log,l", po::value< string >()->default_value(
"flow123"),
"Set base name for log files.")
325 (
"version",
"Display version and build information and exit.")
326 (
"no_log",
"Turn off logging.")
327 (
"no_signal_handler",
"Turn off signal handling. Useful for debugging with valgrind.")
328 (
"no_profiler,no-profiler",
"Turn off profiler output.")
329 (
"profiler_path,profiler-path", po::value< string >(),
"Path to the profiler file")
330 (
"input_format", po::value< string >(),
"Writes full structure of the main input file into given file.")
331 (
"petsc_redirect", po::value<string>(),
"Redirect all PETSc stdout and stderr to given file.")
332 (
"yaml_balance",
"Redirect balance output to YAML format too (simultaneously with the selected balance output format).");
340 po::variables_map vm;
341 auto parser = po::basic_command_line_parser<char>(argc, argv)
343 .allow_unregistered();
344 po::parsed_options parsed = parser.run();
345 po::store(parsed, vm);
350 vector<string> to_pass_further = po::collect_unrecognized(parsed.options, po::include_positional);
369 if (vm.count(
"no_profiler")) {
373 if (vm.count(
"profiler_path")) {
378 if (vm.count(
"help")) {
381 cout <<
"Usage:" << endl;
382 cout <<
" flow123d -s <main_input>.yaml <other options> <PETSC options>" << endl;
383 cout <<
" flow123d <main_input>.yaml <other options> <PETSC options>" << endl;
384 cout << desc <<
"\n";
385 THROW(ExcNoRunOption());
389 if (vm.count(
"version")) {
391 THROW(ExcNoRunOption());
397 if (vm.count(
"input_format")) {
399 ofstream json_stream;
407 THROW(ExcNoRunOption());
411 if (vm.count(
"petsc_redirect")) {
415 if (vm.count(
"no_signal_handler")) {
420 string input_filename =
"";
423 if (to_pass_further.size()) {
424 string file_candidate = to_pass_further[0];
425 if (file_candidate[0] !=
'-') {
427 input_filename = file_candidate;
428 to_pass_further.erase(to_pass_further.begin());
433 if (vm.count(
"solve")) {
434 input_filename = vm[
"solve"].as<
string>();
438 if (input_filename ==
"")
439 THROW(ExcMessage() << EI_Message(
"Main input file not specified (option -s)."));
446 if (vm.count(
"input_dir")) {
447 input_dir = vm[
"input_dir"].as<
string>();
449 if (vm.count(
"output_dir")) {
450 output_dir = vm[
"output_dir"].as<
string>();
458 }
catch (FilePath::ExcMkdirFail &e) {
463 if (vm.count(
"log")) {
467 if (vm.count(
"no_log")) {
486 string build = string(__DATE__) +
", " + string(__TIME__)
520 using namespace Input;
522 std::regex version_re(
"([^.]*)[.]([^.]*)[.]([^.]*)");
524 std::string version(FLOW123D_VERSION_NAME_);
526 if ( std::regex_match(version, match, version_re) ) {
527 ver_fields[0]=match[1];
528 ver_fields[1]=match[2];
529 ver_fields[2]=match[3];
534 std::string input_version = i_rec.
val<
string>(
"flow123d_version");
536 if ( std::regex_match(input_version, match, version_re) ) {
537 iver_fields[0]=match[1];
538 iver_fields[1]=match[2];
539 iver_fields[2]=match[3];
541 THROW( ExcVersionFormat() << EI_InputVersionStr(input_version) );
544 if ( iver_fields[0] != ver_fields[0] || iver_fields[1] > ver_fields[1] ) {
545 WarningOut().fmt(
"Input file with version: '{}' is no compatible with the program version: '{}' \n",
546 input_version, version);
561 THROW( ExcUnknownProblem() );
574 printf(
"\nPress <ENTER> for closing the window\n");
581 namespace py = pybind11;
583 if (json_filepath ==
"")
return;
586 auto python_module = PythonLoader::load_module_by_name (
"profiler.profiler_formatter_module");
590 auto convert_method = python_module.attr(
"convert");
592 convert_method(json_filepath, (json_filepath + output_file_suffix), formatter);
605 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.
string parent_path() const
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()
void set_stream(std::string abs_path)
Set init_ flag.
static LoggerOptions & get_instance()
Getter of singleton instance object.
void set_mpi_rank(int mpi_rank)
Set rank of actual process.
std::string log_file_name(std::string log_file_base)
Create unique log file name.
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.