Nektar++
Loading...
Searching...
No Matches
GeomElements.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: GeomElements.cpp
4//
5// For more information, please see: http://www.nektar.info/
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Python wrapper for GeomElements.
32//
33////////////////////////////////////////////////////////////////////////////////
34
37
47
48using namespace Nektar;
49using namespace Nektar::SpatialDomains;
50
52
53template <class T, class S>
54unique_ptr_objpool<T> Geometry_Init(int id, py::list &facets)
55{
56 std::array<S *, T::kNfacets> geomArr;
57
58 if (py::len(facets) != T::kNfacets)
59 {
60 throw new NekError("Incorrect number of facets for this geometry");
61 }
62
63 for (int i = 0; i < T::kNfacets; ++i)
64 {
65 geomArr[i] = py::cast<S *>(facets[i]);
66 }
67
68 return ObjPoolManager<T>::AllocateUniquePtr(id, geomArr);
69}
70
71template <class T, class S>
73 Curve *curve)
74{
75 std::array<S *, T::kNfacets> geomArr;
76
77 if (py::len(facets) != T::kNfacets)
78 {
79 throw new NekError("Incorrect number of facets for this geometry");
80 }
81
82 for (int i = 0; i < T::kNfacets; ++i)
83 {
84 geomArr[i] = py::cast<S *>(facets[i]);
85 }
86
87 return ObjPoolManager<T>::AllocateUniquePtr(id, geomArr, curve);
88}
89
90template <class T, class S> void export_Geom_2d(py::module &m, const char *name)
91{
92 py::classh<T, Geometry2D>(m, name)
93 .def(py::init<>(&Geometry_Init<T, S>), py::arg("id"),
94 py::arg("segments") = py::list())
95 .def(py::init<>(&Geometry_Init_Curved<T, S>), py::arg("id"),
96 py::arg("segments"), py::arg("curve"));
97}
98
99template <class T, class S> void export_Geom_3d(py::module &m, const char *name)
100{
101 py::classh<T, Geometry3D>(m, name).def(py::init<>(&Geometry_Init<T, S>),
102 py::arg("id"),
103 py::arg("segments") = py::list());
104}
105
106unique_ptr_objpool<SegGeom> SegGeom_Init(int id, int coordim, py::list &points,
107 Curve *curve)
108{
109 std::array<PointGeom *, 2> geomArr;
110
111 if (py::len(points) != 2)
112 {
113 throw new NekError("Incorrect number of facets for this geometry");
114 }
115
116 for (int i = 0; i < 2; ++i)
117 {
118 geomArr[i] = py::cast<PointGeom *>(points[i]);
119 }
120
121 if (!curve)
122 {
123 return ObjPoolManager<SegGeom>::AllocateUniquePtr(id, coordim, geomArr);
124 }
125 else
126 {
127 return ObjPoolManager<SegGeom>::AllocateUniquePtr(id, coordim, geomArr,
128 curve);
129 }
130}
131
133 NekDouble y, NekDouble z)
134{
135 return ObjPoolManager<PointGeom>::AllocateUniquePtr(coordim, id, x, y, z);
136}
137
139{
140 return py::make_tuple(self.x(), self.y(), self.z());
141}
142
143void export_GeomElements(py::module &m)
144{
145 // Geometry dimensioned base classes
146 py::classh<Geometry1D, Geometry>(m, "Geometry1D");
147 py::classh<Geometry2D, Geometry>(m, "Geometry2D")
148 .def("GetCurve", &Geometry2D::GetCurve,
149 py::return_value_policy::reference);
150 py::classh<Geometry3D, Geometry>(m, "Geometry3D");
151
152 // Point geometries
153 py::classh<PointGeom, Geometry>(m, "PointGeom")
154 .def(py::init<>(&PointGeom_Init), py::arg("coordim"), py::arg("id"),
155 py::arg("x"), py::arg("y"), py::arg("z"))
156 .def("GetCoordinates", &PointGeom_GetCoordinates);
157
158 // Segment geometries
159 py::classh<SegGeom, Geometry>(m, "SegGeom")
160 .def(py::init<>(&SegGeom_Init), py::arg("id"), py::arg("coordim"),
161 py::arg("points") = py::list(), py::arg("curve") = nullptr)
162 .def("GetCurve", &SegGeom::GetCurve,
163 py::return_value_policy::reference);
164
165 export_Geom_2d<TriGeom, SegGeom>(m, "TriGeom");
166 export_Geom_2d<QuadGeom, SegGeom>(m, "QuadGeom");
167 export_Geom_3d<TetGeom, TriGeom>(m, "TetGeom");
168 export_Geom_3d<PrismGeom, Geometry2D>(m, "PrismGeom");
169 export_Geom_3d<PyrGeom, Geometry2D>(m, "PyrGeom");
170 export_Geom_3d<HexGeom, QuadGeom>(m, "HexGeom");
171}
py::tuple PointGeom_GetCoordinates(const PointGeom &self)
unique_ptr_objpool< T > Geometry_Init_Curved(int id, py::list &facets, Curve *curve)
void export_Geom_3d(py::module &m, const char *name)
void export_Geom_2d(py::module &m, const char *name)
Nektar::ErrorUtil::NekError NekError
void export_GeomElements(py::module &m)
unique_ptr_objpool< T > Geometry_Init(int id, py::list &facets)
unique_ptr_objpool< SegGeom > SegGeom_Init(int id, int coordim, py::list &points, Curve *curve)
unique_ptr_objpool< PointGeom > PointGeom_Init(int coordim, int id, NekDouble x, NekDouble y, NekDouble z)
boost::call_traits< DataType >::const_reference x() const
Definition NekPoint.hpp:160
boost::call_traits< DataType >::const_reference z() const
Definition NekPoint.hpp:172
boost::call_traits< DataType >::const_reference y() const
Definition NekPoint.hpp:166
static std::unique_ptr< DataType, UniquePtrDeleter > AllocateUniquePtr(const Args &...args)
std::unique_ptr< T, typename ObjPoolManager< T >::UniquePtrDeleter > unique_ptr_objpool