Nektar++
Functions
Python/BasicUtils/SessionReader.cpp File Reference
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/Python/NekPyConfig.hpp>

Go to the source code of this file.

Functions

SessionReaderSharedPtr SessionReader_CreateInstance (py::list &ns)
 Thin wrapper around SessionReader to provide a nicer Pythonic interface. More...
 
void export_SessionReader ()
 SessionReader exports. More...
 

Function Documentation

◆ export_SessionReader()

void export_SessionReader ( )

SessionReader exports.

Currently wrapped functions:

  • SessionReader::CreateInstance for creating objects
  • SessionReader::GetSessionName to return the session name
  • SessionReader::Finalise to deal with finalising things

Definition at line 95 of file Python/BasicUtils/SessionReader.cpp.

References Nektar::LibUtilities::SessionReader::DefinesParameter(), Nektar::LibUtilities::SessionReader::Finalise(), Nektar::LibUtilities::SessionReader::GetComm(), Nektar::LibUtilities::SessionReader::GetParameter(), Nektar::LibUtilities::SessionReader::GetSessionName(), Nektar::LibUtilities::SessionReader::GetVariable(), and SessionReader_CreateInstance().

Referenced by BOOST_PYTHON_MODULE().

96 {
97  py::class_<SessionReader,
98  std::shared_ptr<SessionReader>,
99  boost::noncopyable>(
100  "SessionReader", py::no_init)
101 
102  .def("CreateInstance", SessionReader_CreateInstance)
103  .staticmethod("CreateInstance")
104 
105  .def("GetSessionName", &SessionReader::GetSessionName,
106  py::return_value_policy<py::copy_const_reference>())
107 
108  .def("Finalise", &SessionReader::Finalise)
109 
110  .def("DefinesParameter", &SessionReader::DefinesParameter)
111  .def("GetParameter", &SessionReader::GetParameter,
112  py::return_value_policy<py::return_by_value>())
113 
114  .def("GetVariable", &SessionReader::GetVariable,
115  py::return_value_policy<py::copy_const_reference>())
116 
117  .def("GetComm", &SessionReader::GetComm)
118 
119  ;
120 }
static void Finalise(gs_data *pGsh)
Deallocates the GSLib mapping data.
Definition: GsLib.hpp:226
SessionReaderSharedPtr SessionReader_CreateInstance(py::list &ns)
Thin wrapper around SessionReader to provide a nicer Pythonic interface.
Reads and parses information from a Nektar++ XML session file.

◆ SessionReader_CreateInstance()

SessionReaderSharedPtr SessionReader_CreateInstance ( py::list &  ns)

Thin wrapper around SessionReader to provide a nicer Pythonic interface.

This allows us to do, for example

session = SessionReader.CreateInstance(sys.argv)

which is more natural in Python.

Definition at line 50 of file Python/BasicUtils/SessionReader.cpp.

References CellMLToNektar.pycml::copy(), Nektar::LibUtilities::SessionReader::CreateInstance(), and CellMLToNektar.cellml_metadata::p.

Referenced by export_SessionReader().

51 {
52  int i, argc = py::len(ns), bufSize = 0;
53  char **argv = new char *[argc+1], *p;
54 
55  // Create argc, argv to give to the session reader. Note that this needs to
56  // be a contiguous block in memory, otherwise MPI (specifically OpenMPI)
57  // will likely segfault.
58  for (i = 0; i < argc; ++i)
59  {
60  std::string tmp = py::extract<std::string>(ns[i]);
61  bufSize += tmp.size() + 1;
62  }
63 
64  std::vector<char> buf(bufSize);
65  for (i = 0, p = &buf[0]; i < argc; ++i)
66  {
67  std::string tmp = py::extract<std::string>(ns[i]);
68  std::copy(tmp.begin(), tmp.end(), p);
69  p[tmp.size()] = '\0';
70  argv[i] = p;
71  p += tmp.size()+1;
72  }
73 
74  // Also make sure we set argv[argc] = NULL otherwise OpenMPI will also
75  // segfault.
76  argv[argc] = NULL;
77 
78  // Create session reader.
79  SessionReaderSharedPtr sr = SessionReader::CreateInstance(argc, argv);
80 
81  // Clean up.
82  delete [] argv;
83 
84  return sr;
85 }
def copy(self)
Definition: pycml.py:2663
std::shared_ptr< SessionReader > SessionReaderSharedPtr