13#include <pybind11/pybind11.h>
14#include <pybind11/stl.h>
15#include <spdlog/spdlog.h>
16#include <tclap/CmdLine.h>
36static_assert(EXIT_FAILURE == 1);
37static_assert(EXIT_SUCCESS == 0);
39int initOGS(std::vector<std::string>& argv_str)
41 int argc = argv_str.size();
42 char** argv =
new char*[argc];
43 for (
int i = 0; i < argc; ++i)
45 argv[i] = argv_str[i].data();
53 catch (TCLAP::ArgException
const& e)
55 ERR(
"Parsing the OGS commandline failed: {}", e.what());
60 catch (TCLAP::ExitException
const& e)
62 if (e.getExitStatus() == 0)
73 INFO(
"This is OpenGeoSys-6 version {:s}.",
79 auto const start_time = std::chrono::system_clock::now();
81 INFO(
"OGS started on {:s}.", time_str);
84 std::optional<ApplicationsLib::TestDefinition> test_definition{
86 auto ogs_status = EXIT_SUCCESS;
90 simulation = std::make_unique<Simulation>(argc, argv);
99 catch (std::exception& e)
102 ogs_status = EXIT_FAILURE;
105 INFO(
"OpenGeoSys is now initialized.");
115 auto const start_time = std::chrono::system_clock::now();
117 INFO(
"OGS started on {:s}.", time_str);
120 auto ogs_status = EXIT_SUCCESS;
125 bool solver_succeeded =
simulation->executeSimulation();
129 INFO(
"[time] Execution took {:g} s.", run_time.
elapsed());
130 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
132 catch (std::exception& e)
135 ogs_status = EXIT_FAILURE;
139 auto const end_time = std::chrono::system_clock::now();
141 INFO(
"OGS terminated on {:s}.", time_str);
149 auto ogs_status = EXIT_SUCCESS;
152 bool solver_succeeded =
simulation->executeTimeStep();
153 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
155 catch (std::exception& e)
158 ogs_status = EXIT_FAILURE;
197 m.attr(
"__name__") =
"ogs.simulator";
198 m.doc() =
"pybind11 ogs example plugin";
199 m.def(
"initialize", &
initOGS,
"init OGS");
200 m.def(
"currentTime", &
currentTime,
"get current OGS time");
201 m.def(
"endTime", &
endTime,
"get end OGS time");
204 m.def(
"getMesh", &
getMesh,
"get unstructured grid from ogs");
205 m.def(
"finalize", &
finalize,
"finalize OGS simulation");
CommandLineArguments parseCommandLineArguments(int argc, char *argv[], bool const exit_on_exception)
Declaration of CommandLineArgumentParser.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the RunTime class.
Declaration of class Simulation.
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
void initOGSLogger(std::string const &log_level)
std::string formatDate(std::chrono::time_point< std::chrono::system_clock > const &time)
void unsetProjectDirectory()
Unsets the project directory.
bool createOutputDirectory(std::string const &dir)
GITINFOLIB_EXPORT const std::string ogs_version
static constexpr int EXIT_ARGPARSE_EXIT_OK
int initOGS(std::vector< std::string > &argv_str)
static constexpr int EXIT_ARGPARSE_FAILURE
OGSMesh getMesh(std::string const &name)
std::unique_ptr< Simulation > simulation
PYBIND11_MODULE(simulator, m)
bool reference_path_is_set
std::string reference_path
std::vector< std::string > xml_patch_file_names