OGS
ogs_python_module.cpp File Reference
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <spdlog/spdlog.h>
#include <tclap/CmdLine.h>
#include <algorithm>
#include "../ogs.OGSMesh/OGSMesh.h"
#include "Applications/ApplicationsLib/Simulation.h"
#include "Applications/ApplicationsLib/TestDefinition.h"
#include "BaseLib/ConfigTree.h"
#include "BaseLib/DateTools.h"
#include "BaseLib/Error.h"
#include "BaseLib/FileTools.h"
#include "BaseLib/Logging.h"
#include "BaseLib/RunTime.h"
#include "CommandLineArgumentParser.h"
#include "InfoLib/GitInfo.h"
#include "ogs_embedded_python.h"
Include dependency graph for ogs_python_module.cpp:

Go to the source code of this file.

Classes

class  OGSSimulation

Functions

int checkCommandLineArguments (std::vector< std::string > &argv_str)
 PYBIND11_MODULE (OGSSimulator, m)

Variables

static constexpr int EXIT_ARGPARSE_FAILURE = 3
static constexpr int EXIT_ARGPARSE_EXIT_OK = 2

Function Documentation

◆ checkCommandLineArguments()

int checkCommandLineArguments ( std::vector< std::string > & argv_str)

Definition at line 29 of file ogs_python_module.cpp.

30{
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)
35 {
36 argv[i] = argv_str[i].data();
37 }
38
39 CommandLineArguments cli_args;
40 try
41 {
42 cli_args = parseCommandLineArguments(argc, argv, false);
43 }
44 catch (TCLAP::ArgException const& e)
45 {
46 ERR("Parsing the OGS commandline failed: {}", e.what());
47
48 // "mangle" TCLAP's status
50 }
51 catch (TCLAP::ExitException const& e)
52 {
53 if (e.getExitStatus() == 0)
54 {
56 }
57
58 // "mangle" TCLAP's status
60 }
61
62 INFO("Parsing the OGS commandline passed");
63 return EXIT_SUCCESS;
64}
CommandLineArguments parseCommandLineArguments(int argc, char *argv[], bool const exit_on_exception)
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
static constexpr int EXIT_ARGPARSE_EXIT_OK
static constexpr int EXIT_ARGPARSE_FAILURE

References ERR(), EXIT_ARGPARSE_EXIT_OK, EXIT_ARGPARSE_FAILURE, INFO(), and parseCommandLineArguments().

Referenced by PYBIND11_MODULE().

◆ PYBIND11_MODULE()

PYBIND11_MODULE ( OGSSimulator ,
m  )

To use this module import dependencies first: import ogs.mesh as mesh import ogs.OGSSimulator as sim

See also https://github.com/pybind/pybind11/issues/1391#issuecomment-912642979

Definition at line 263 of file ogs_python_module.cpp.

264{
266 m.attr("__name__") = "ogs.OGSSimulator";
267 m.doc() = "pybind11 ogs plugin";
268
269 m.def("check_command_line_arguments", &checkCommandLineArguments,
270 "check the command line arguments");
271
272 pybind11::class_<OGSSimulation>(m, "OGSSimulation")
273 .def(pybind11::init<std::vector<std::string>&>())
274 .def("current_time", &OGSSimulation::currentTime,
275 "get current OGS time")
276 .def("end_time", &OGSSimulation::endTime, "get end OGS time")
277 .def("execute_simulation", &OGSSimulation::executeSimulation,
278 "execute OGS simulation")
279 .def("execute_time_step", &OGSSimulation::executeTimeStep,
280 "execute OGS time step")
281 .def("mesh", &OGSSimulation::getMesh,
282 pybind11::return_value_policy::automatic_reference,
283 pybind11::arg("name"), "get unstructured grid from ogs")
284 .def("mesh_names", &OGSSimulation::getMeshNames,
285 "get names of all meshes from ogs")
286 .def("close", &OGSSimulation::finalize, "finalize OGS simulation");
287}
OGSMesh & getMesh(std::string const &name)
double endTime() const
double currentTime() const
std::vector< std::string > getMeshNames() const
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:56
int checkCommandLineArguments(std::vector< std::string > &argv_str)

References checkCommandLineArguments(), OGSSimulation::currentTime(), OGSSimulation::endTime(), OGSSimulation::executeSimulation(), OGSSimulation::executeTimeStep(), OGSSimulation::finalize(), OGSSimulation::getMesh(), OGSSimulation::getMeshNames(), and BaseLib::initOGSLogger().

Variable Documentation

◆ EXIT_ARGPARSE_EXIT_OK

int EXIT_ARGPARSE_EXIT_OK = 2
staticconstexpr

Definition at line 25 of file ogs_python_module.cpp.

Referenced by checkCommandLineArguments().

◆ EXIT_ARGPARSE_FAILURE

int EXIT_ARGPARSE_FAILURE = 3
staticconstexpr

Definition at line 24 of file ogs_python_module.cpp.

Referenced by checkCommandLineArguments().