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