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)
 
void SessionReader_SetParameterInt (SessionReaderSharedPtr session, std::string paramName, int paramValue)
 
void SessionReader_SetParameterDouble (SessionReaderSharedPtr session, std::string paramName, double paramValue)
 
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 136 of file Python/BasicUtils/SessionReader.cpp.

137 {
138  py::class_<SessionReader, std::shared_ptr<SessionReader>,
139  boost::noncopyable>("SessionReader", py::no_init)
140 
141  .def("CreateInstance", SessionReader_CreateInstance)
142  .staticmethod("CreateInstance")
143 
144  .def("GetSessionName", &SessionReader::GetSessionName,
145  py::return_value_policy<py::copy_const_reference>())
146 
147  .def("Finalise", &SessionReader::Finalise)
148 
149  .def("DefinesParameter", &SessionReader::DefinesParameter)
150  .def("GetParameter", &SessionReader::GetParameter,
151  py::return_value_policy<py::return_by_value>())
152 
153  .def("SetParameter", SessionReader_SetParameterInt)
154  .def("SetParameter", SessionReader_SetParameterDouble)
155 
156  .def("GetVariable", &SessionReader::GetVariable,
157  py::return_value_policy<py::copy_const_reference>())
158 
159  .def("GetComm", &SessionReader::GetComm)
160 
161  .def("GetSharedFilesystem", &SessionReader::GetSharedFilesystem);
162 }
void SessionReader_SetParameterDouble(SessionReaderSharedPtr session, std::string paramName, double paramValue)
SessionReaderSharedPtr SessionReader_CreateInstance(py::list &ns)
void SessionReader_SetParameterInt(SessionReaderSharedPtr session, std::string paramName, int paramValue)
static void Finalise(gs_data *pGsh)
Deallocates the GSLib mapping data.
Definition: GsLib.hpp:251

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

Referenced by BOOST_PYTHON_MODULE().

◆ SessionReader_CreateInstance()

SessionReaderSharedPtr SessionReader_CreateInstance ( py::list &  ns)

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

57 {
58  int i, argc = py::len(ns), bufSize = 0;
59  char **argv = new char *[argc + 1], *p;
60 
61  // Create argc, argv to give to the session reader. Note that this needs to
62  // be a contiguous block in memory, otherwise MPI (specifically OpenMPI)
63  // will likely segfault.
64  for (i = 0; i < argc; ++i)
65  {
66  std::string tmp = py::extract<std::string>(ns[i]);
67  bufSize += tmp.size() + 1;
68  }
69 
70  std::vector<char> buf(bufSize);
71  for (i = 0, p = &buf[0]; i < argc; ++i)
72  {
73  std::string tmp = py::extract<std::string>(ns[i]);
74  std::copy(tmp.begin(), tmp.end(), p);
75  p[tmp.size()] = '\0';
76  argv[i] = p;
77  p += tmp.size() + 1;
78  }
79 
80  // Also make sure we set argv[argc] = NULL otherwise OpenMPI will also
81  // segfault.
82  argv[argc] = NULL;
83 
84 #ifdef NEKTAR_USE_MPI
85  // In the case we're using MPI, it may already have been initialised. So to
86  // handle this, we'll construct our own CommMpi object and pass through to
87  // the SessionReader. This will persist indefinitely, or at least until the
88  // library is unloaded by Python.
89 
90  if (!MPICOMM)
91  {
92  MPICOMM = GetCommFactory().CreateInstance("ParallelMPI", argc, argv);
93  }
94 
95  std::vector<std::string> filenames(argc - 1);
96  for (i = 1; i < argc; ++i)
97  {
98  filenames[i - 1] = std::string(argv[i]);
99  }
100 
101  // Create session reader.
103  SessionReader::CreateInstance(argc, argv, filenames, MPICOMM);
104 #else
105  // Create session reader.
106  SessionReaderSharedPtr sr = SessionReader::CreateInstance(argc, argv);
107 #endif
108 
109  // Clean up.
110  delete[] argv;
111 
112  return sr;
113 }
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
def copy(self)
Definition: pycml.py:2663
std::shared_ptr< SessionReader > SessionReaderSharedPtr
CommFactory & GetCommFactory()

References CellMLToNektar.pycml::copy(), Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), Nektar::LibUtilities::GetCommFactory(), and CellMLToNektar.cellml_metadata::p.

Referenced by export_SessionReader().

◆ SessionReader_SetParameterDouble()

void SessionReader_SetParameterDouble ( SessionReaderSharedPtr  session,
std::string  paramName,
double  paramValue 
)

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

123 {
124  session->SetParameter(paramName, paramValue);
125 }

Referenced by export_SessionReader().

◆ SessionReader_SetParameterInt()

void SessionReader_SetParameterInt ( SessionReaderSharedPtr  session,
std::string  paramName,
int  paramValue 
)

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

117 {
118  session->SetParameter(paramName, paramValue);
119 }

Referenced by export_SessionReader().