OGS
ogs_python_module.cpp File Reference

Detailed Description

Implementation of OpenGeoSys simulation application python module.

Definition in file ogs_python_module.cpp.

#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/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 37 of file ogs_python_module.cpp.

38{
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)
43 {
44 argv[i] = argv_str[i].data();
45 }
46
47 CommandLineArguments cli_args;
48 try
49 {
50 cli_args = parseCommandLineArguments(argc, argv, false);
51 }
52 catch (TCLAP::ArgException const& e)
53 {
54 ERR("Parsing the OGS commandline failed: {}", e.what());
56
57 // "mangle" TCLAP's status
59 }
60 catch (TCLAP::ExitException const& e)
61 {
62 if (e.getExitStatus() == 0)
63 {
66 }
67
69 // "mangle" TCLAP's status
71 }
72
73 INFO("Parsing the OGS commandline passed");
75 return EXIT_SUCCESS;
76}
CommandLineArguments parseCommandLineArguments(int argc, char *argv[], bool const exit_on_exception)
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
void unsetProjectDirectory()
Unsets the project directory.
static constexpr int EXIT_ARGPARSE_EXIT_OK
static constexpr int EXIT_ARGPARSE_FAILURE

References ERR(), EXIT_ARGPARSE_EXIT_OK, EXIT_ARGPARSE_FAILURE, INFO(), parseCommandLineArguments(), and BaseLib::unsetProjectDirectory().

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

268{
270 m.attr("__name__") = "ogs.OGSSimulator";
271 m.doc() = "pybind11 ogs plugin";
272
273 m.def("check_command_line_arguments", &checkCommandLineArguments,
274 "check the command line arguments");
275
276 pybind11::class_<OGSSimulation>(m, "OGSSimulation")
277 .def(pybind11::init<std::vector<std::string>&>())
278 .def("current_time", &OGSSimulation::currentTime,
279 "get current OGS time")
280 .def("end_time", &OGSSimulation::endTime, "get end OGS time")
281 .def("execute_simulation", &OGSSimulation::executeSimulation,
282 "execute OGS simulation")
283 .def("execute_time_step", &OGSSimulation::executeTimeStep,
284 "execute OGS time step")
285 .def("mesh", &OGSSimulation::getMesh,
286 pybind11::return_value_policy::automatic_reference,
287 pybind11::arg("name"), "get unstructured grid from ogs")
288 .def("mesh_names", &OGSSimulation::getMeshNames,
289 "get names of all meshes from ogs")
290 .def("close", &OGSSimulation::finalize, "finalize OGS simulation");
291}
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:64
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 33 of file ogs_python_module.cpp.

Referenced by checkCommandLineArguments().

◆ EXIT_ARGPARSE_FAILURE

int EXIT_ARGPARSE_FAILURE = 3
staticconstexpr

Definition at line 32 of file ogs_python_module.cpp.

Referenced by checkCommandLineArguments().