OGS
ogs.cpp File Reference

Detailed Description

Implementation of OpenGeoSys simulation application.

Date
2014-08-04

Definition in file ogs.cpp.

#include <algorithm>
#include <pybind11/pybind11.h>
#include <spdlog/spdlog.h>
#include <tclap/CmdLine.h>
#include <chrono>
#include <filesystem>
#include <sstream>
#include "CommandLineArgumentParser.h"
#include <cfenv>
#include "Applications/ApplicationsLib/Simulation.h"
#include "Applications/ApplicationsLib/TestDefinition.h"
#include "BaseLib/DateTools.h"
#include "BaseLib/Error.h"
#include "BaseLib/Logging.h"
#include "BaseLib/RunTime.h"
#include "InfoLib/GitInfo.h"
Include dependency graph for ogs.cpp:

Go to the source code of this file.

Functions

void enableFloatingPointExceptions ()
 
int main (int argc, char *argv[])
 

Function Documentation

◆ enableFloatingPointExceptions()

void enableFloatingPointExceptions ( )

Definition at line 44 of file ogs.cpp.

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}

Referenced by main().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 56 of file ogs.cpp.

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
70 if (cli_arg.outdir.length() > 0)
71 {
72 std::error_code mkdir_err;
73 if (std::filesystem::create_directories(cli_arg.outdir, mkdir_err))
74 {
75 INFO("Output directory {:s} created.", cli_arg.outdir);
76 }
77 else if (mkdir_err.value() != 0)
78 {
79 WARN(
80 "Could not create output directory {:s}. Error code {:d}, {:s}",
81 cli_arg.outdir, mkdir_err.value(), mkdir_err.message());
82 }
83 }
84
85 {
86 auto const start_time = std::chrono::system_clock::now();
87 auto const time_str = BaseLib::formatDate(start_time);
88 INFO("OGS started on {:s}.", time_str);
89 }
90
91 std::optional<ApplicationsLib::TestDefinition> test_definition{
92 std::nullopt};
93 auto ogs_status = EXIT_SUCCESS;
94
95 try
96 {
97 Simulation simulation(argc, argv);
98
99 BaseLib::RunTime run_time;
100 run_time.start();
101
102 bool solver_succeeded = false;
103 try
104 {
105 simulation.initializeDataStructures(
106 std::move(cli_arg.project),
107 std::move(cli_arg.xml_patch_file_names),
108 cli_arg.reference_path_is_set,
109 std::move(cli_arg.reference_path), cli_arg.nonfatal,
110 std::move(cli_arg.outdir), std::move(cli_arg.mesh_dir),
111 std::move(cli_arg.script_dir), cli_arg.write_prj);
112 solver_succeeded = simulation.executeSimulation();
113 simulation.outputLastTimeStep();
114 test_definition = simulation.getTestDefinition();
115 }
116 catch (pybind11::error_already_set const& e)
117 {
118 OGS_FATAL("Python exception thrown: {}", e.what());
119 }
120
121 INFO("[time] Execution took {:g} s.", run_time.elapsed());
122 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
123 }
124 catch (std::exception& e)
125 {
126 ERR("{}", e.what());
127 ogs_status = EXIT_FAILURE;
128 }
129
130 {
131 auto const end_time = std::chrono::system_clock::now();
132 auto const time_str = BaseLib::formatDate(end_time);
133 INFO("OGS terminated on {:s}.", time_str);
134 }
135
136 if (ogs_status == EXIT_FAILURE)
137 {
138 ERR("OGS terminated with error.");
139 return EXIT_FAILURE;
140 }
141
142 if (!test_definition)
143 {
144 // There are no tests, so just exit;
145 return ogs_status;
146 }
147
148 INFO("");
149 INFO("##########################################");
150 INFO("# Running tests #");
151 INFO("##########################################");
152 INFO("");
153 if (!test_definition->runTests())
154 {
155 ERR("One of the tests failed.");
156 return EXIT_FAILURE;
157 }
158 return EXIT_SUCCESS;
159}
CommandLineArguments parseCommandLineArguments(int argc, char *argv[], bool const exit_on_exception)
#define OGS_FATAL(...)
Definition Error.h:26
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
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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
void enableFloatingPointExceptions()
Definition ogs.cpp:44
std::unique_ptr< Simulation > simulation
std::vector< std::string > xml_patch_file_names

References BaseLib::RunTime::elapsed(), CommandLineArguments::enable_fpe_is_set, enableFloatingPointExceptions(), ERR(), BaseLib::formatDate(), INFO(), BaseLib::initOGSLogger(), CommandLineArguments::log_level, CommandLineArguments::mesh_dir, CommandLineArguments::nonfatal, OGS_FATAL, GitInfoLib::GitInfo::ogs_version, CommandLineArguments::outdir, parseCommandLineArguments(), CommandLineArguments::project, CommandLineArguments::reference_path, CommandLineArguments::reference_path_is_set, CommandLineArguments::script_dir, simulation, BaseLib::RunTime::start(), WARN(), CommandLineArguments::write_prj, and CommandLineArguments::xml_patch_file_names.