Nektar++
Typedefs | Functions | Variables
LibUtilities.cpp File Reference
#include <LibUtilities/Python/NekPyConfig.hpp>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <sstream>

Go to the source code of this file.

Typedefs

using NekError = Nektar::ErrorUtil::NekError
 

Functions

void export_Basis ()
 Basis exports. More...
 
void export_Comm ()
 Export for Comm communicator. More...
 
void export_Points ()
 Points exports. More...
 
void export_SessionReader ()
 SessionReader exports. More...
 
void export_ShapeType ()
 Export for ShapeType enumeration. More...
 
template<typename T >
void export_SharedArray ()
 
template<typename T >
void export_NekMatrix ()
 
PyObject * CreateExceptionClass (const char *name, PyObject *baseTypeObj=PyExc_Exception)
 
void TranslateNekError (NekError const &e)
 
 BOOST_PYTHON_MODULE (_LibUtilities)
 

Variables

PyObject * NekErrorType = nullptr
 
std::stringstream errorStream
 

Typedef Documentation

◆ NekError

Definition at line 55 of file LibUtilities.cpp.

Function Documentation

◆ BOOST_PYTHON_MODULE()

BOOST_PYTHON_MODULE ( _LibUtilities  )

Definition at line 80 of file LibUtilities.cpp.

81 {
82  np::initialize();
83 
84  // Register the NekError exception.
85  NekErrorType = CreateExceptionClass("NekError");
86  py::register_exception_translator<NekError>(&TranslateNekError);
87 
88  // Set a stringstream as an error sink to avoid duplicate output.
90 
91  export_Basis();
92  export_Points();
97  export_Comm();
98 }
void export_Comm()
Export for Comm communicator.
void export_Basis()
Basis exports.
PyObject * NekErrorType
PyObject * CreateExceptionClass(const char *name, PyObject *baseTypeObj=PyExc_Exception)
void TranslateNekError(NekError const &e)
void export_ShapeType()
Export for ShapeType enumeration.
Definition: ShapeType.cpp:44
std::stringstream errorStream
void export_Points()
Points exports.
void export_SessionReader()
SessionReader exports.
template void export_NekMatrix< double >()
template void export_SharedArray< double >()
static void SetErrorStream(std::ostream &o)
Definition: ErrorUtil.hpp:73

References CreateExceptionClass(), errorStream, export_Basis(), export_Comm(), export_NekMatrix< double >(), export_Points(), export_SessionReader(), export_ShapeType(), export_SharedArray< double >(), NekErrorType, Nektar::ErrorUtil::SetErrorStream(), and TranslateNekError().

◆ CreateExceptionClass()

PyObject* CreateExceptionClass ( const char *  name,
PyObject *  baseTypeObj = PyExc_Exception 
)

Definition at line 57 of file LibUtilities.cpp.

59 {
60  std::string qualifiedName0 = std::string("NekPy.LibUtilities.") + name;
61 
62  PyObject* typeObj = PyErr_NewException(
63  const_cast<char*>(qualifiedName0.c_str()), baseTypeObj, 0);
64 
65  if (!typeObj)
66  {
67  py::throw_error_already_set();
68  }
69 
70  py::scope().attr(name) = py::handle<>(py::borrowed(typeObj));
71  return typeObj;
72 }

References CellMLToNektar.pycml::name.

Referenced by BOOST_PYTHON_MODULE().

◆ export_Basis()

void export_Basis ( )

Basis exports.

Definition at line 55 of file Python/Foundations/Basis.cpp.

56 {
57  // Enumerator for basis type
59 
60  py::class_<BasisKey>("BasisKey", py::init<const BasisType&, const int,
61  const PointsKey&>())
62 
63  .def("GetNumModes", &BasisKey::GetNumModes)
64  .def("GetTotNumModes", &BasisKey::GetTotNumModes)
65  .def("GetNumPoints", &BasisKey::GetNumPoints)
66  .def("GetTotNumPoints", &BasisKey::GetTotNumPoints)
67  .def("GetBasisType", &BasisKey::GetBasisType)
68  .def("GetPointsKey", &BasisKey::GetPointsKey)
69  .def("GetPointsType", &BasisKey::GetPointsType)
70  .def("Collocation", &BasisKey::Collocation)
71  ;
72 
73  py::class_<Basis,
74  std::shared_ptr<Basis> >(
75  "Basis", py::no_init)
76 
77  .def("Create", &Basis_Create)
78  .staticmethod("Create")
79 
80  .def("GetNumModes", &Basis::GetNumModes)
81  .def("GetTotNumModes", &Basis::GetTotNumModes)
82  .def("GetNumPoints", &Basis::GetNumPoints)
83  .def("GetTotNumPoints", &Basis::GetTotNumPoints)
84  .def("GetBasisType", &Basis::GetBasisType)
85  .def("GetPointsKey", &Basis::GetPointsKey)
86  .def("GetBasisKey", &Basis::GetBasisKey)
87  .def("GetPointsType", &Basis::GetBasisType)
88  .def("Initialize", &Basis::Initialize)
89 
90  .def("GetZ", &Basis::GetZ,
91  py::return_value_policy<py::copy_const_reference>())
92  .def("GetW", &Basis::GetW,
93  py::return_value_policy<py::copy_const_reference>())
94  .def("GetZW", &Basis_GetZW)
95 
96  .def("GetBdata", &Basis::GetBdata,
97  py::return_value_policy<py::copy_const_reference>())
98  .def("GetDbdata", &Basis::GetDbdata,
99  py::return_value_policy<py::copy_const_reference>())
100  ;
101 }
#define NEKPY_WRAP_ENUM(ENUMNAME, MAPNAME)
Definition: NekPyConfig.hpp:66
BasisSharedPtr Basis_Create(const BasisKey &pts)
py::tuple Basis_GetZW(BasisSharedPtr pts)
Represents a basis of a given type.
Definition: Basis.h:212
Defines a specification for a set of points.
Definition: Points.h:60
const char *const BasisTypeMap[]
Definition: Foundations.hpp:46

References Basis_Create(), Basis_GetZW(), Nektar::LibUtilities::BasisTypeMap, Nektar::LibUtilities::BasisKey::Collocation(), Nektar::LibUtilities::Basis::GetBasisKey(), Nektar::LibUtilities::BasisKey::GetBasisType(), Nektar::LibUtilities::Basis::GetBasisType(), Nektar::LibUtilities::Basis::GetBdata(), Nektar::LibUtilities::Basis::GetDbdata(), Nektar::LibUtilities::BasisKey::GetNumModes(), Nektar::LibUtilities::Basis::GetNumModes(), Nektar::LibUtilities::BasisKey::GetNumPoints(), Nektar::LibUtilities::Basis::GetNumPoints(), Nektar::LibUtilities::BasisKey::GetPointsKey(), Nektar::LibUtilities::Basis::GetPointsKey(), Nektar::LibUtilities::BasisKey::GetPointsType(), Nektar::LibUtilities::BasisKey::GetTotNumModes(), Nektar::LibUtilities::Basis::GetTotNumModes(), Nektar::LibUtilities::BasisKey::GetTotNumPoints(), Nektar::LibUtilities::Basis::GetTotNumPoints(), Nektar::LibUtilities::Basis::GetW(), Nektar::LibUtilities::Basis::GetZ(), Nektar::LibUtilities::Basis::Initialize(), and NEKPY_WRAP_ENUM.

Referenced by BOOST_PYTHON_MODULE().

◆ export_Comm()

void export_Comm ( )

Export for Comm communicator.

Definition at line 53 of file Python/Communication/Comm.cpp.

54 {
55  // Export ReduceOperator enum
57 
58  py::class_<Comm, std::shared_ptr<Comm>,
59  boost::noncopyable>("Comm", py::no_init)
60  .def("GetSize", &Comm::GetSize)
61  .def("GetRank", &Comm::GetRank)
62  .def("GetType", &Comm::GetType,
63  py::return_value_policy<py::copy_const_reference>())
64  .def("AllReduce", &AllReduce<double>)
65  .def("AllReduce", &AllReduce<int>)
66  .def("AllReduce", &AllReduce<long>)
67  .def("AllReduce", &AllReduce<Array<OneD, NekDouble>>)
68  ;
69 }
T AllReduce(CommSharedPtr &comm, T toReduce, ReduceOperator oper)
const char *const ReduceOperatorMap[]
Definition: Comm.h:74
ReduceOperator
Type of operation to perform in AllReduce.
Definition: Comm.h:67

References AllReduce(), Nektar::LibUtilities::Comm::GetRank(), Nektar::LibUtilities::Comm::GetSize(), Nektar::LibUtilities::Comm::GetType(), NEKPY_WRAP_ENUM, and Nektar::LibUtilities::ReduceOperatorMap.

Referenced by BOOST_PYTHON_MODULE().

◆ export_NekMatrix()

template<typename T >
void export_NekMatrix ( )

Definition at line 96 of file NekMatrix.cpp.

97 {
98  py::to_python_converter<std::shared_ptr<NekMatrix<T, StandardMatrixTag>>,
100 }

◆ export_Points()

void export_Points ( )

Points exports.

Definition at line 73 of file Python/Foundations/Points.cpp.

74 {
76  "Characterise the type of points.\n"
77  "\n"
78  "Sample usage: PointsType.GaussLobattoLegendre\n"
79  "\n"
80  "Available point types:\n"
81  "\tNoPointsType: No points type.\n"
82  "\tGaussGaussLegendre: 1D Gauss-Gauss-Legendre quadrature points.\n"
83  "\tGaussRadauMLegendre: 1D Gauss-Radau-Legendre quadrature points,\n"
84  "\t\tpinned at x=-1.\n"
85  "\tGaussRadauPLegendre: 1D Gauss-Radau-Legendre quadrature points,\n"
86  "\t\tpinned at x=1.\n"
87  "\tGaussLobattoLegendre: 1D Gauss-Lobatto-Legendre quadrature points.\n"
88  "\tGaussGaussChebyshev: 1D Gauss-Gauss-Chebyshev quadrature points.\n"
89  "\tGaussRadauMChebyshev: 1D Gauss-Radau-Chebyshev quadrature points,\n"
90  "\t\tpinned at x=-1.\n"
91  "\tGaussRadauPChebyshev: 1D Gauss-Radau-Chebyshev quadrature points,\n"
92  "\t\tpinned at x=1.\n"
93  "\tGaussLobattoChebyshev: 1D Gauss-Lobatto-Legendre quadrature points\n"
94  "\tGaussRadauMAlpha0Beta1: Gauss Radau pinned at x=-1,\n"
95  "\t\talpha = 0, beta = 1\n"
96  "\tGaussRadauMAlpha0Beta2: Gauss Radau pinned at x=-1,\n"
97  "\t\talpha = 0, beta = 2\n"
98  "\tGaussRadauMAlpha1Beta0: Gauss Radau pinned at x=-1,\n"
99  "\t\talpha = 1, beta = 0\n"
100  "\tGaussRadauMAlpha2Beta0: Gauss Radau pinned at x=-1,\n"
101  "\t\talpha = 2, beta = 0\n"
102  "\tGaussKronrodLegendre: 1D Gauss-Kronrod-Legendre quadrature points.\n"
103  "\tGaussRadauKronrodMLegendre: 1D Gauss-Radau-Kronrod-Legendre quadrature\n"
104  "\t\tpoints, pinned at x=-1.\n"
105  "\tGaussRadauKronrodMAlpha1Beta0: 1D Gauss-Radau-Kronrod-Legendre\n"
106  "\t\tpinned at x=-1, alpha = 1, beta = 0\n"
107  "\tGaussLobattoKronrodLegendre: 1D Lobatto Kronrod quadrature points.\n"
108  "\tPolyEvenlySpaced: 1D Evenly-spaced points using Lagrange polynomial.\n"
109  "\tFourierEvenlySpaced: 1D Evenly-spaced points using Fourier Fit.\n"
110  "\tFourierSingleModeSpaced: 1D Non Evenly-spaced points for Single Mode\n"
111  "\t\tanalysis.\n"
112  "\tBoundaryLayerPoints: 1D power law distribution for boundary layer points.\n"
113  "\tBoundaryLayerPointsRev: 1D power law distribution for boundary layer\n"
114  "\t\tpoints.\n"
115  "\tNodalTriElec: 2D Nodal Electrostatic Points on a Triangle.\n"
116  "\tNodalTriFekete: 2D Nodal Fekete Points on a Triangle.\n"
117  "\tNodalTriEvenlySpaced: 2D Evenly-spaced points on a Triangle.\n"
118  "\tNodalTetEvenlySpaced: 3D Evenly-spaced points on a Tetrahedron.\n"
119  "\tNodalTetElec: 3D Nodal Electrostatic Points on a Tetrahedron.\n"
120  "\tNodalPrismEvenlySpaced: 3D Evenly-spaced points on a Prism.\n"
121  "\tNodalPrismElec: 3D electrostatically spaced points on a Prism.\n"
122  "\tNodalTriSPI: 2D Nodal Symmetric positive internal triangle\n"
123  "\t\t(Whitherden, Vincent).\n"
124  "\tNodalTetSPI: 3D Nodal Symmetric positive internal tet\n"
125  "\t\t(Whitherden, Vincent).\n"
126  "\tNodalPrismSPI: 3D prism SPI.\n"
127  "\tNodalQuadElec: 2D GLL for quad.\n"
128  "\tNodalHexElec: 3D GLL for hex");
129 
130  py::class_<PointsKey>("PointsKey",
131  "Create a PointsKey which uniquely defines quadrature points.\n"
132  "\n"
133  "Args:\n"
134  "\tnQuadPoints (integer): The number of quadrature points.\n"
135  "\tpointsType (PointsType object): The type of quadrature points.",
136  py::init<const int, const PointsType&>())
137 
138  .def("GetNumPoints", &PointsKey::GetNumPoints,
139  "Get the number of quadrature points in PointsKey.\n"
140  "\n"
141  "Args:\n"
142  "\tNone\n"
143  "Returns:\n"
144  "\tInteger defining the number of quadrature points in PointsKey.")
145  .def("GetPointsType", &PointsKey::GetPointsType,
146  "Get the type of points in PointsKey.\n"
147  "\n"
148  "Args:\n"
149  "\tNone\n"
150  "Returns:\n"
151  "\tPointsType object specifying the type of points in PointsKey.")
152  .def("GetPointsDim", &PointsKey::GetPointsDim,
153  "Get the dimension of the PointsKey.\n"
154  "\n"
155  "Args:\n"
156  "\tNone\n"
157  "Returns:\n"
158  "\tInteger characterising the dimension of the PointsKey (e.g. 2\n"
159  "\tfor 2D PointsKey).")
160  .def("GetTotNumPoints", &PointsKey::GetTotNumPoints,
161  "Get the total number of points in PointsKey.\n"
162  "\n"
163  "Args:\n"
164  "\tNone\n"
165  "Returns:\n"
166  "\tInteger defining the total number of points in PointsKey.")
167  ;
168 
169  py::class_<Points<double>,
170  std::shared_ptr<Points<double> >,
171  boost::noncopyable>(
172  "Points",
173  "Create a set of points which can be used to calculate\n"
174  "quadrature zeros, weights etc."
175  "\n"
176  "Args:\n"
177  "\tNone",
178  py::no_init)
179  .def("Create", &Points_Create,
180  "Create a Points object using PointsKey.\n"
181  "\n"
182  "Args:\n"
183  "\tpointsKey (PointsKey object): The PointsKey to be used to\n"
184  "\tcreate points.\n"
185  "Returns:\n"
186  "\tPoints object created with the given PointsKey.")
187  .staticmethod("Create")
188 
189  .def("Initialise", &Points<double>::Initialize,
190  "Initialise Points object by calculating points, weights\n"
191  "and differentiation matrix.\n"
192  "\n"
193  "Args:\n"
194  "\tNone\n"
195  "Returns:\n"
196  "\tNone")
197  .def("GetPointsDim", &Points<double>::GetPointsDim,
198  "Get the dimension of the Points object.\n"
199  "\n"
200  "Args:\n"
201  "\tNone\n"
202  "Returns:\n"
203  "\tInteger characterising the dimension of the Points object\n"
204  "\t(e.g. 2 for 2D Points object).")
205  .def("GetPointsType", &Points<double>::GetPointsType,
206  "Get the type of points in Points object.\n"
207  "\n"
208  "Args:\n"
209  "\tNone\n"
210  "Returns:\n"
211  "\tPointsType object specifying the type of points in Points\n"
212  "\tobject.")
213  .def("GetNumPoints", &Points<double>::GetNumPoints,
214  "Get the number of quadrature points in Points object.\n"
215  "\n"
216  "Args:\n"
217  "\tNone\n"
218  "Returns:\n"
219  "\tInteger defining the number of quadrature points in Points\n"
220  "\tobject.")
221  .def("GetTotNumPoints", &Points<double>::GetTotNumPoints,
222  "Get the total number of points in Points object.\n"
223  "\n"
224  "Args:\n"
225  "\tNone\n"
226  "Returns:\n"
227  "\tInteger defining the total number of points in Points\n"
228  "\tobject.")
229 
230  .def("GetZ", &Points<double>::GetZ,
231  py::return_value_policy<py::copy_const_reference>(),
232  "Get quadrature zeros.\n"
233  "\n"
234  "Args:\n"
235  "\tNone\n"
236  "Returns:\n"
237  "\tNumPy ndarray of length equal to the number of quadrature\n"
238  "\tpoints, containing quadrature zeros.")
239  .def("GetW", &Points<double>::GetW,
240  py::return_value_policy<py::copy_const_reference>(),
241  "Get quadrature weights.\n"
242  "\n"
243  "Args:\n"
244  "\tNone\n"
245  "Returns:\n"
246  "\tNumPy ndarray of length equal to the number of quadrature\n"
247  "\tpoints, containing quadrature weights.")
248  .def("GetZW", &Points_GetZW,
249  "Get quadrature zeros and weights.\n"
250  "\n"
251  "Args:\n"
252  "\tNone\n"
253  "Returns:\n"
254  "\tTuple containing the quadrature zeros and quadrature weights,\n"
255  "\ti.e. (Points.GetZ(), Points.GetW()).")
256  .def("GetD", &Points_GetD,
257  "Get the differentiation matrix.\n"
258  "\n"
259  "Args:\n"
260  "\tNone\n"
261  "Returns:\n"
262  "\tNumPy ndarray of n x n dimensions, where n is equal to\n"
263  "\tthe number of quadrature points, containing the\n"
264  "\tdifferentiation matrix.")
265  .def("GetD", &Points_GetD2,
266  "Get the differentiation matrix.\n"
267  "\n"
268  "Args:\n"
269  "\tdir (Direction object): The direction of the desired\n"
270  "\tdifferentiation matrix.\n"
271  "Returns:\n"
272  "\tNumPy ndarray of n x n dimensions, where n is equal to\n"
273  "\tthe number of quadrature points containing the\n"
274  "\tdifferentiation matrix.")
275  ;
276 }
#define NEKPY_WRAP_ENUM_STRING_DOCS(ENUMNAME, MAPNAME, DOCSTRING)
Definition: NekPyConfig.hpp:99
py::tuple Points_GetZW(PointsSharedPtr pts)
MatrixSharedPtrType Points_GetD(PointsSharedPtr pts)
PointsSharedPtr Points_Create(const PointsKey &pts)
MatrixSharedPtrType Points_GetD2(PointsSharedPtr pts, Direction dir)
Stores a set of points of datatype DataT, defined by a PointKey.
Definition: Points.h:251
const std::string kPointsTypeStr[]
Definition: Foundations.hpp:70

References Nektar::LibUtilities::PointsKey::GetNumPoints(), Nektar::LibUtilities::PointsKey::GetPointsDim(), Nektar::LibUtilities::PointsKey::GetPointsType(), Nektar::LibUtilities::PointsKey::GetTotNumPoints(), Nektar::LibUtilities::kPointsTypeStr, NEKPY_WRAP_ENUM_STRING_DOCS, Points_Create(), Points_GetD(), Points_GetD2(), and Points_GetZW().

Referenced by BOOST_PYTHON_MODULE().

◆ 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.

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 }
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.
static void Finalise(gs_data *pGsh)
Deallocates the GSLib mapping data.
Definition: GsLib.hpp:226

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().

◆ export_ShapeType()

void export_ShapeType ( )

Export for ShapeType enumeration.

Definition at line 44 of file ShapeType.cpp.

45 {
47 }
const char *const ShapeTypeMap[]
Definition: ShapeType.hpp:67

References NEKPY_WRAP_ENUM, and Nektar::LibUtilities::ShapeTypeMap.

Referenced by BOOST_PYTHON_MODULE().

◆ export_SharedArray()

template<typename T >
void export_SharedArray ( )

Definition at line 209 of file SharedArray.cpp.

210 {
211  py::to_python_converter<Array<OneD, const T>, OneDArrayToPython<const T> >();
212  py::to_python_converter<Array<OneD, T>, OneDArrayToPython<T> >();
213 
216 }

◆ TranslateNekError()

void TranslateNekError ( NekError const &  e)

Definition at line 74 of file LibUtilities.cpp.

75 {
76  PyErr_SetString(NekErrorType, e.what());
77 }

References NekErrorType.

Referenced by BOOST_PYTHON_MODULE().

Variable Documentation

◆ errorStream

std::stringstream errorStream

Definition at line 53 of file LibUtilities.cpp.

Referenced by BOOST_PYTHON_MODULE().

◆ NekErrorType

PyObject* NekErrorType = nullptr

Definition at line 52 of file LibUtilities.cpp.

Referenced by BOOST_PYTHON_MODULE(), and TranslateNekError().