4#include <pybind11/pybind11.h>
5#include <pybind11/stl.h>
6#include <spdlog/spdlog.h>
7#include <tclap/CmdLine.h>
26static_assert(EXIT_FAILURE == 1);
27static_assert(EXIT_SUCCESS == 0);
31 INFO(
"Parsing the OGS commandline ...");
32 int argc = argv_str.size();
33 char** argv =
new char*[argc];
34 for (
int i = 0; i < argc; ++i)
36 argv[i] = argv_str[i].data();
44 catch (TCLAP::ArgException
const& e)
46 ERR(
"Parsing the OGS commandline failed: {}", e.what());
51 catch (TCLAP::ExitException
const& e)
53 if (e.getExitStatus() == 0)
62 INFO(
"Parsing the OGS commandline passed");
73 int argc = argv_str.size();
74 char** argv =
new char*[argc];
75 for (
int i = 0; i < argc; ++i)
77 argv[i] = argv_str[i].data();
85 catch (TCLAP::ArgException
const& e)
87 std::cerr <<
"Parsing the OGS commandline failed: " << e.what()
93 catch (TCLAP::ExitException
const& e)
100 DBUG(
"OGSSimulation::OGSSimulation(std::vector<std::string>&)");
103 "This is OpenGeoSys-6 version {:s}. Log version: {:d}, Log level: "
110 auto const start_time = std::chrono::system_clock::now();
113 INFO(
"OGS starts on {:s} in serial mode / Python embedded mode.",
118 simulation = std::make_unique<Simulation>(argc, argv);
127 catch (std::exception& e)
133 INFO(
"OpenGeoSys is now initialized.");
141 auto const start_time = std::chrono::system_clock::now();
143 INFO(
"OGS started on {:s} in serial mode.", time_str);
146 std::optional<ApplicationsLib::TestDefinition> test_definition{
152 bool solver_succeeded =
simulation->executeSimulation();
154 test_definition =
simulation->getTestDefinition();
156 if (solver_succeeded)
158 INFO(
"[time] Simulation completed. It took {:g} s.",
163 INFO(
"[time] Simulation failed. It took {:g} s.",
166 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
168 catch (std::exception& e)
176 auto const end_time = std::chrono::system_clock::now();
178 ERR(
"OGS terminated with error on {:s}.", time_str);
190 bool solver_succeeded =
simulation->executeTimeStep();
191 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
193 catch (std::exception& e)
210 INFO(
"found OGSMesh '{}' with address: {}", name,
211 fmt::ptr(&(mesh_it->second)));
212 return mesh_it->second;
215 auto const& [it, success] =
219 OGS_FATAL(
"Could not access mesh '{}'.", name);
221 INFO(
"insert OGSMesh '{}' with address: {}", name,
222 fmt::ptr(&(it->second)));
243 catch (std::exception& e)
266 m.attr(
"__name__") =
"ogs.OGSSimulator";
267 m.doc() =
"pybind11 ogs plugin";
270 "check the command line arguments");
272 pybind11::class_<OGSSimulation>(m,
"OGSSimulation")
273 .def(pybind11::init<std::vector<std::string>&>())
275 "get current OGS time")
278 "execute OGS simulation")
280 "execute OGS time step")
282 pybind11::return_value_policy::automatic_reference,
283 pybind11::arg(
"name"),
"get unstructured grid from ogs")
285 "get names of all meshes from ogs")
CommandLineArguments parseCommandLineArguments(int argc, char *argv[], bool const exit_on_exception)
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
static void assertNoSwallowedErrors()
Asserts that there have not been any errors reported in the destructor.
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
std::map< std::string, OGSMesh > mesh_mapping
OGSMesh & getMesh(std::string const &name)
std::unique_ptr< Simulation > simulation
OGSSimulation(std::vector< std::string > &argv_str)
double currentTime() const
std::vector< std::string > getMeshNames() const
static OGS_EXPORT_SYMBOL int runTestDefinitions(std::optional< ApplicationsLib::TestDefinition > &test_definition)
void initOGSLogger(std::string const &log_level)
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
static constexpr int EXIT_ARGPARSE_EXIT_OK
int checkCommandLineArguments(std::vector< std::string > &argv_str)
PYBIND11_MODULE(OGSSimulator, m)
static constexpr int EXIT_ARGPARSE_FAILURE
bool reference_path_is_set
std::string reference_path
std::vector< std::string > xml_patch_file_names