OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
PyPolynomialPatch.cpp
Go to the documentation of this file.
1#include <Python.h>
2#include <structmember.h>
3
4#include <exception>
5#include <iostream>
6#include <boost/python.hpp>
7
11
13
14namespace PyOpal {
15
17
18using namespace interpolation;
19namespace py = boost::python;
20
22 NDGrid* points,
23 boost::python::list values,
24 int polyPatchOrder,
25 int smoothingOrder) {
26 int gLength = py::len(values);
27 std::vector<std::vector<double> > valuesVec(gLength);
28 for (int i = 0; i < gLength; ++i) {
29 int lineLength = py::len(values[i]);
30 valuesVec[i] = std::vector<double>(lineLength);
31 for (int j = 0; j < lineLength; ++j) {
32 valuesVec[i][j] = py::extract<double>(values[i][j]);
33 }
34 }
35 // points is owned by Python; clone to get a clean copy...
36 Mesh* pointsClone = points->clone();
37 PolynomialPatch* patch = PPSolveFactory(pointsClone,
38 valuesVec,
39 polyPatchOrder,
40 polyPatchOrder).solve();
41 return patch;
42}
43
44py::list function(PolynomialPatch* patch, py::list point) {
45 int pointDim = patch->getPointDimension();
46 int valueDim = patch->getValueDimension();
47 if (py::len(point) != pointDim) {
48 //error
49 }
50 std::vector<double> pointVec(pointDim);
51 for (int i = 0; i < pointDim; ++i) {
52 pointVec[i] = py::extract<double>(point[i]);
53 }
54 std::vector<double> valueVec(valueDim);
55 patch->function(&pointVec[0], &valueVec[0]);
56 py::list value = py::list();
57 for (int i = 0; i < valueDim; ++i) {
58 value.append(valueVec[i]);
59 }
60 return value;
61}
62
63
64const char* module_docstring = "polynomial_patch module returns the field";
65
66BOOST_PYTHON_MODULE(polynomial_patch) {
68 py::class_<PolynomialPatch, boost::noncopyable>("PolynomialPatch")
69 .def("initialise_from_solve_factory", &initialiseFromSolveFactory,
70 py::return_value_policy<py::manage_new_object>())
71 .staticmethod("initialise_from_solve_factory")
72 .def("function", &function)
73 ;
74}
75
76} // namespace PyPolynomialPatch
77} // namespace PyOpal
BOOST_PYTHON_MODULE(polynomial_patch)
PolynomialPatch * initialiseFromSolveFactory(NDGrid *points, boost::python::list values, int polyPatchOrder, int smoothingOrder)
py::list function(PolynomialPatch *patch, py::list point)
Base class for meshing routines.
Definition: Mesh.h:49
NDGrid * clone()
Definition: NDGrid.h:350
Patches together many SquarePolynomialVectors to make a multidimensional polynomial spline.
unsigned int getPointDimension() const
virtual void function(const double *point, double *value) const
unsigned int getValueDimension() const
PPSolveFactory solves the system of linear equations to interpolate from a grid of points using highe...