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)
74 "This is OpenGeoSys-6 version {:s}. Log version: {:d}, Log level: "
81 auto const start_time = std::chrono::system_clock::now();
83 INFO(
"OGS started on {:s} in serial mode / Python embedded mode.",
87 std::optional<ApplicationsLib::TestDefinition> test_definition{
89 auto ogs_status = EXIT_SUCCESS;
93 simulation = std::make_unique<Simulation>(argc, argv);
102 catch (std::exception& e)
105 ogs_status = EXIT_FAILURE;
108 INFO(
"OpenGeoSys is now initialized.");
39int initOGS(std::vector<std::string>& argv_str) {
…}
118 auto const start_time = std::chrono::system_clock::now();
120 INFO(
"OGS started on {:s} in serial mode.", time_str);
123 auto ogs_status = EXIT_SUCCESS;
128 bool solver_succeeded =
simulation->executeSimulation();
132 if (solver_succeeded)
134 INFO(
"[time] Simulation completed. It took {:g} s.",
139 INFO(
"[time] Simulation failed. It took {:g} s.",
142 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
144 catch (std::exception& e)
147 ogs_status = EXIT_FAILURE;
150 if (ogs_status == EXIT_FAILURE)
152 auto const end_time = std::chrono::system_clock::now();
154 ERR(
"OGS terminated with error on {:s}.", time_str);
163 auto ogs_status = EXIT_SUCCESS;
166 bool solver_succeeded =
simulation->executeTimeStep();
167 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
169 catch (std::exception& e)
172 ogs_status = EXIT_FAILURE;
211 m.attr(
"__name__") =
"ogs.simulator";
212 m.doc() =
"pybind11 ogs example plugin";
213 m.def(
"initialize", &
initOGS,
"init OGS");
214 m.def(
"currentTime", &
currentTime,
"get current OGS time");
215 m.def(
"endTime", &
endTime,
"get end OGS time");
218 m.def(
"getMesh", &
getMesh,
"get unstructured grid from ogs");
219 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