Nektar++
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
46
47using namespace Nektar;
48using namespace Nektar::SpatialDomains;
49
50template <class T, class S>
51std::shared_ptr<T> Geometry_Init(int id, py::list &facets)
52{
53 std::vector<std::shared_ptr<S>> geomVec;
54
55 for (int i = 0; i < py::len(facets); ++i)
56 {
57 geomVec.push_back(py::cast<std::shared_ptr<S>>(facets[i]));
58 }
59
60 return std::make_shared<T>(id, &geomVec[0]);
61}
62
63template <class T, class S>
64std::shared_ptr<T> Geometry_Init_Curved(int id, py::list &facets,
65 CurveSharedPtr curve)
66{
67 std::vector<std::shared_ptr<S>> geomVec;
68
69 for (int i = 0; i < py::len(facets); ++i)
70 {
71 geomVec.push_back(py::cast<std::shared_ptr<S>>(facets[i]));
72 }
73
74 return std::make_shared<T>(id, &geomVec[0], curve);
75}
76
77template <class T, class S> void export_Geom_2d(py::module &m, const char *name)
78{
79 py::class_<T, Geometry2D, std::shared_ptr<T>>(m, name)
80 .def(py::init<>())
81 .def(py::init<>(&Geometry_Init<T, S>), py::arg("id"),
82 py::arg("segments") = py::list())
83 .def(py::init<>(&Geometry_Init_Curved<T, S>), py::arg("id"),
84 py::arg("segments"), py::arg("curve"));
85}
86
87template <class T, class S> void export_Geom_3d(py::module &m, const char *name)
88{
89 py::class_<T, Geometry3D, std::shared_ptr<T>>(m, name)
90 .def(py::init<>())
91 .def(py::init<>(&Geometry_Init<T, S>), py::arg("id"),
92 py::arg("segments") = py::list());
93}
94
95SegGeomSharedPtr SegGeom_Init(int id, int coordim, py::list &points,
96 CurveSharedPtr curve)
97{
98 std::vector<PointGeomSharedPtr> geomVec;
99
100 for (int i = 0; i < py::len(points); ++i)
101 {
102 geomVec.push_back(py::cast<PointGeomSharedPtr>(points[i]));
103 }
104
105 if (!curve)
106 {
107 return std::make_shared<SegGeom>(id, coordim, &geomVec[0]);
108 }
109 else
110 {
111 return std::make_shared<SegGeom>(id, coordim, &geomVec[0], curve);
112 }
113}
114
116{
117 return py::make_tuple(self.x(), self.y(), self.z());
118}
119
120void export_GeomElements(py::module &m)
121{
122 // Geometry dimensioned base classes
123 py::class_<Geometry1D, Geometry, std::shared_ptr<Geometry1D>>(m,
124 "Geometry1D");
125 py::class_<Geometry2D, Geometry, std::shared_ptr<Geometry2D>>(m,
126 "Geometry2D")
127 .def("GetCurve", &Geometry2D::GetCurve);
128 py::class_<Geometry3D, Geometry, std::shared_ptr<Geometry3D>>(m,
129 "Geometry3D");
130
131 // Point geometries
132 py::class_<PointGeom, Geometry, std::shared_ptr<PointGeom>>(m, "PointGeom")
133 .def(py::init<>())
134 .def(py::init<int, int, NekDouble, NekDouble, NekDouble>())
135 .def("GetCoordinates", &PointGeom_GetCoordinates);
136
137 // Segment geometries
138 py::class_<SegGeom, Geometry, std::shared_ptr<SegGeom>>(m, "SegGeom")
139 .def(py::init<>())
140 .def(py::init<>(&SegGeom_Init), py::arg("id"), py::arg("coordim"),
141 py::arg("points") = py::list(),
142 py::arg("curve") = CurveSharedPtr())
143 .def("GetCurve", &SegGeom::GetCurve);
144
145 export_Geom_2d<TriGeom, SegGeom>(m, "TriGeom");
146 export_Geom_2d<QuadGeom, SegGeom>(m, "QuadGeom");
147 export_Geom_3d<TetGeom, TriGeom>(m, "TetGeom");
148 export_Geom_3d<PrismGeom, Geometry2D>(m, "PrismGeom");
149 export_Geom_3d<PyrGeom, Geometry2D>(m, "PyrGeom");
150 export_Geom_3d<HexGeom, QuadGeom>(m, "HexGeom");
151}
py::tuple PointGeom_GetCoordinates(const PointGeom &self)
void export_Geom_3d(py::module &m, const char *name)
void export_Geom_2d(py::module &m, const char *name)
std::shared_ptr< T > Geometry_Init(int id, py::list &facets)
void export_GeomElements(py::module &m)
std::shared_ptr< T > Geometry_Init_Curved(int id, py::list &facets, CurveSharedPtr curve)
SegGeomSharedPtr SegGeom_Init(int id, int coordim, py::list &points, CurveSharedPtr curve)
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
std::shared_ptr< Curve > CurveSharedPtr
Definition: Curve.hpp:58
std::shared_ptr< SegGeom > SegGeomSharedPtr
Definition: Geometry2D.h:58