OGS
ogs_python_module.cpp File Reference
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <spdlog/spdlog.h>
#include <tclap/CmdLine.h>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/transform.hpp>
#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/MPI.h"
#include "BaseLib/RunTime.h"
#include "BaseLib/TCLAPArguments.h"
#include "CommandLineArgumentParser.h"
#include "InfoLib/GitInfo.h"
Include dependency graph for ogs_python_module.cpp:

Go to the source code of this file.

Classes

class  OGSSimulation

Macros

#define OGS_ALWAYS_ASSERT(cond)

Functions

std::pair< int, std::vector< char * > > toArgcArgv (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

Macro Definition Documentation

◆ OGS_ALWAYS_ASSERT

#define OGS_ALWAYS_ASSERT ( cond)
Value:
if (!(cond)) \
{ \
OGS_FATAL("OGS assertion failed {}", #cond); \
}

Definition at line 31 of file ogs_python_module.cpp.

31#define OGS_ALWAYS_ASSERT(cond) \
32 if (!(cond)) \
33 { \
34 OGS_FATAL("OGS assertion failed {}", #cond); \
35 }

Referenced by OGSSimulation::currentTime(), OGSSimulation::endTime(), OGSSimulation::executeSimulation(), OGSSimulation::executeTimeStep(), OGSSimulation::getMesh(), and OGSSimulation::getMeshNames().

Function Documentation

◆ 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 283 of file ogs_python_module.cpp.

284{
285 m.attr("__name__") = "ogs.OGSSimulator";
286 m.doc() = "pybind11 ogs plugin";
287
288 pybind11::class_<OGSSimulation>(m, "OGSSimulation")
289 .def(pybind11::init<std::vector<std::string>&>())
290 .def("current_time", &OGSSimulation::currentTime,
291 "get current OGS time")
292 .def("end_time", &OGSSimulation::endTime, "get end OGS time")
293 .def("execute_simulation", &OGSSimulation::executeSimulation,
294 "execute OGS simulation")
295 .def("execute_time_step", &OGSSimulation::executeTimeStep,
296 "execute OGS time step")
297 .def("mesh", &OGSSimulation::getMesh,
298 pybind11::return_value_policy::automatic_reference,
299 pybind11::arg("name"), "get unstructured grid from ogs")
300 .def("mesh_names", &OGSSimulation::getMeshNames,
301 "get names of all meshes from ogs")
302 .def("close", &OGSSimulation::finalize, "finalize OGS simulation")
303 .def_property_readonly("status", &OGSSimulation::status)
304 .def_property_readonly(
305 "initialized", &OGSSimulation::initialized,
306 "Tells if the simulation object has been completely initialized.");
307}
bool initialized() const
OGSMesh & getMesh(std::string const &name)
double endTime() const
double currentTime() const
std::vector< std::string > getMeshNames() const

References OGSSimulation::currentTime(), OGSSimulation::endTime(), OGSSimulation::executeSimulation(), OGSSimulation::executeTimeStep(), OGSSimulation::finalize(), OGSSimulation::getMesh(), OGSSimulation::getMeshNames(), OGSSimulation::initialized(), and OGSSimulation::status().

◆ toArgcArgv()

std::pair< int, std::vector< char * > > toArgcArgv ( std::vector< std::string > & argv_str)

Definition at line 37 of file ogs_python_module.cpp.

39{
40 int argc = argv_str.size();
41 auto argv_vec = argv_str |
42 ranges::views::transform([](auto& s) { return s.data(); }) |
43 ranges::to<std::vector<char*>>();
44 argv_vec.push_back(nullptr); // last entry must be a nullptr!
45
46 return {argc, std::move(argv_vec)};
47}

Referenced by OGSSimulation::OGSSimulation().

Variable Documentation

◆ EXIT_ARGPARSE_EXIT_OK

int EXIT_ARGPARSE_EXIT_OK = 2
staticconstexpr

Definition at line 27 of file ogs_python_module.cpp.

◆ EXIT_ARGPARSE_FAILURE

int EXIT_ARGPARSE_FAILURE = 3
staticconstexpr

Definition at line 26 of file ogs_python_module.cpp.