13#include <pybind11/pybind11.h>
14#include <pybind11/stl.h>
15#include <spdlog/spdlog.h>
16#include <tclap/CmdLine.h>
34static_assert(EXIT_FAILURE == 1);
35static_assert(EXIT_SUCCESS == 0);
39 INFO(
"Parsing the OGS commandline ...");
40 int argc = argv_str.size();
41 char** argv =
new char*[argc];
42 for (
int i = 0; i < argc; ++i)
44 argv[i] = argv_str[i].data();
52 catch (TCLAP::ArgException
const& e)
54 ERR(
"Parsing the OGS commandline failed: {}", e.what());
60 catch (TCLAP::ExitException
const& e)
62 if (e.getExitStatus() == 0)
73 INFO(
"Parsing the OGS commandline passed");
85 int argc = argv_str.size();
86 char** argv =
new char*[argc];
87 for (
int i = 0; i < argc; ++i)
89 argv[i] = argv_str[i].data();
97 catch (TCLAP::ArgException
const& e)
99 std::cerr <<
"Parsing the OGS commandline failed: " << e.what()
105 catch (TCLAP::ExitException
const& e)
112 DBUG(
"OGSSimulation::OGSSimulation(std::vector<std::string>&)");
115 "This is OpenGeoSys-6 version {:s}. Log version: {:d}, Log level: "
122 auto const start_time = std::chrono::system_clock::now();
125 INFO(
"OGS starts on {:s} in serial mode / Python embedded mode.",
130 simulation = std::make_unique<Simulation>(argc, argv);
131 simulation->initializeDataStructures(
139 catch (std::exception& e)
142 ogs_status = EXIT_FAILURE;
146 INFO(
"OpenGeoSys is now initialized.");
154 auto const start_time = std::chrono::system_clock::now();
156 INFO(
"OGS started on {:s} in serial mode.", time_str);
159 std::optional<ApplicationsLib::TestDefinition> test_definition{
165 bool solver_succeeded = simulation->executeSimulation();
166 simulation->outputLastTimeStep();
167 test_definition = simulation->getTestDefinition();
169 if (solver_succeeded)
171 INFO(
"[time] Simulation completed. It took {:g} s.",
176 INFO(
"[time] Simulation failed. It took {:g} s.",
179 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
181 catch (std::exception& e)
184 ogs_status = EXIT_FAILURE;
187 if (ogs_status == EXIT_FAILURE)
189 auto const end_time = std::chrono::system_clock::now();
191 ERR(
"OGS terminated with error on {:s}.", time_str);
200 auto ogs_status = EXIT_SUCCESS;
203 bool solver_succeeded = simulation->executeTimeStep();
204 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
206 catch (std::exception& e)
209 ogs_status = EXIT_FAILURE;
216 double endTime()
const {
return simulation->endTime(); }
220 auto const mesh_it = mesh_mapping.find(name);
221 if (mesh_it != mesh_mapping.end())
223 INFO(
"found OGSMesh '{}' with address: {}", name,
224 fmt::ptr(&(mesh_it->second)));
225 return mesh_it->second;
228 auto const& [it, success] =
229 mesh_mapping.insert({name,
OGSMesh(simulation->getMesh(name))});
232 OGS_FATAL(
"Could not access mesh '{}'.", name);
234 INFO(
"insert OGSMesh '{}' with address: {}", name,
235 fmt::ptr(&(it->second)));
241 return simulation->getMeshNames();
246 simulation->outputLastTimeStep();
247 simulation.reset(
nullptr);
255 int ogs_status = EXIT_SUCCESS;
270 m.attr(
"__name__") =
"ogs.OGSSimulator";
271 m.doc() =
"pybind11 ogs plugin";
274 "check the command line arguments");
276 pybind11::class_<OGSSimulation>(m,
"OGSSimulation")
277 .def(pybind11::init<std::vector<std::string>&>())
279 "get current OGS time")
282 "execute OGS simulation")
284 "execute OGS time step")
286 pybind11::return_value_policy::automatic_reference,
287 pybind11::arg(
"name"),
"get unstructured grid from ogs")
289 "get names of all meshes from ogs")
CommandLineArguments parseCommandLineArguments(int argc, char *argv[], bool const exit_on_exception)
Declaration of CommandLineArgumentParser.
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)
Definition of the RunTime class.
Declaration of class Simulation.
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)
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 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