OGS
ogs.cpp
Go to the documentation of this file.
1
14#include <pybind11/pybind11.h>
15#include <spdlog/spdlog.h>
16#include <tclap/CmdLine.h>
17
18#include <algorithm>
19#include <chrono>
20#include <sstream>
21
23
24#ifndef _WIN32
25#ifdef __APPLE__
26#ifdef __SSE__
27#include <xmmintrin.h>
28#endif // __SSE__
29#else
30#include <cfenv>
31#endif // __APPLE__
32#endif // _WIN32
33
36#include "BaseLib/DateTools.h"
37#include "BaseLib/Error.h"
38#include "BaseLib/FileTools.h"
39#include "BaseLib/Logging.h"
40#include "BaseLib/RunTime.h"
41#include "InfoLib/GitInfo.h"
42
43#ifndef _WIN32 // On windows this command line option is not present.
45{
46#ifdef __APPLE__
47#ifdef __SSE__
48 _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID);
49#endif // __SSE__
50#else
51 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
52#endif // __APPLE__
53}
54#endif // _WIN32
55
56int main(int argc, char* argv[])
57{
60#ifndef _WIN32 // TODO: On windows floating point exceptions are not handled
61 if (cli_arg.enable_fpe_is_set)
62 {
64 }
65#endif // _WIN32
66
67 INFO("This is OpenGeoSys-6 version {:s}.",
69
71
72 {
73 auto const start_time = std::chrono::system_clock::now();
74 auto const time_str = BaseLib::formatDate(start_time);
75 INFO("OGS started on {:s}.", time_str);
76 }
77
78 std::optional<ApplicationsLib::TestDefinition> test_definition{
79 std::nullopt};
80 auto ogs_status = EXIT_SUCCESS;
81
82 try
83 {
84 Simulation simulation(argc, argv);
85
86 BaseLib::RunTime run_time;
87 run_time.start();
88
89 bool solver_succeeded = false;
90 try
91 {
92 simulation.initializeDataStructures(
93 std::move(cli_arg.project),
94 std::move(cli_arg.xml_patch_file_names),
96 std::move(cli_arg.reference_path), cli_arg.nonfatal,
97 std::move(cli_arg.outdir), std::move(cli_arg.mesh_dir),
98 std::move(cli_arg.script_dir), cli_arg.write_prj);
99 solver_succeeded = simulation.executeSimulation();
100 simulation.outputLastTimeStep();
101 test_definition = simulation.getTestDefinition();
102 }
103 catch (pybind11::error_already_set const& e)
104 {
105 OGS_FATAL("Python exception thrown: {}", e.what());
106 }
107
108 INFO("[time] Execution took {:g} s.", run_time.elapsed());
109 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
110 }
111 catch (std::exception& e)
112 {
113 ERR("{}", e.what());
114 ogs_status = EXIT_FAILURE;
115 }
116
117 {
118 auto const end_time = std::chrono::system_clock::now();
119 auto const time_str = BaseLib::formatDate(end_time);
120 INFO("OGS terminated on {:s}.", time_str);
121 }
122
123 if (ogs_status == EXIT_FAILURE)
124 {
125 ERR("OGS terminated with error.");
126 return EXIT_FAILURE;
127 }
128
129 if (!test_definition)
130 {
131 // There are no tests, so just exit;
132 return ogs_status;
133 }
134
135 INFO("");
136 INFO("##########################################");
137 INFO("# Running tests #");
138 INFO("##########################################");
139 INFO("");
140 if (!test_definition->runTests())
141 {
142 ERR("One of the tests failed.");
143 return EXIT_FAILURE;
144 }
145 return EXIT_SUCCESS;
146}
CommandLineArguments parseCommandLineArguments(int argc, char *argv[], bool const exit_on_exception)
Declaration of CommandLineArgumentParser.
Definition of date helper functions.
#define OGS_FATAL(...)
Definition Error.h:26
Filename manipulation routines.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
Definition of the RunTime class.
Declaration of class Simulation.
Count the running time.
Definition RunTime.h:29
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:42
void start()
Start the timer.
Definition RunTime.h:32
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:54
std::string formatDate(std::chrono::time_point< std::chrono::system_clock > const &time)
bool createOutputDirectory(std::string const &dir)
GITINFOLIB_EXPORT const std::string ogs_version
int main(int argc, char *argv[])
Definition ogs.cpp:56
void enableFloatingPointExceptions()
Definition ogs.cpp:44
std::unique_ptr< Simulation > simulation
std::vector< std::string > xml_patch_file_names