Nektar++
Loading...
Searching...
No Matches
Python/MeshGraph.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: MeshGraph.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 MeshGraph.
32//
33////////////////////////////////////////////////////////////////////////////////
34
40
41using namespace Nektar;
42using namespace Nektar::SpatialDomains;
43
44/*
45 * @brief Simple wrapper to build Composite objects from lists of
46 * Geometry objects.
47 */
49{
50 CompositeSharedPtr composite = std::make_shared<Composite>();
51 composite->m_geomVec.clear();
52 for (int i = 0; i < py::len(geometries); i++)
53 {
54 composite->m_geomVec.emplace_back(py::cast<Geometry *>(geometries[i]));
55 }
56 return composite;
57}
58
59template <typename T>
61{
62 auto id = geom->GetGlobalID();
63 graph->AddGeom(id, std::move(geom));
64}
65
66template <typename T>
67void MeshGraph_GeomMapView(py::module_ &m, const std::string &name)
68{
69 using MapView = GeomMapView<T>;
70
71 py::class_<MapView>(m, name.c_str())
72 .def("__getitem__", &MapView::at, py::return_value_policy::reference)
73 .def("__len__", &MapView::size)
74 .def(
75 "__iter__",
76 [](const MapView &self) {
77 return py::make_key_iterator(self.begin(), self.end());
78 },
79 py::keep_alive<0, 1>()) // keep object alive while iterating
80 .def(
81 "items",
82 [](const MapView &self) {
83 return py::make_iterator(self.begin(), self.end());
84 },
85 py::keep_alive<0, 1>())
86 .def("values",
87 [](const MapView &self) {
88 py::list result;
89 for (const auto &[_, ptr] : self)
90 {
91 result.append(ptr);
92 }
93 return result;
94 })
95 .def("keys",
96 [](const MapView &self) {
97 py::list result;
98 for (const auto &[id, _] : self)
99 {
100 result.append(id);
101 }
102 return result;
103 })
104 .def(
105 "get",
106 [](const MapView &self, int id) -> T * {
107 auto it = self.find(id);
108 return (*it).second;
109 },
110 py::return_value_policy::reference);
111}
112
113/**
114 * @brief MeshGraph exports.
115 */
116void export_MeshGraph(py::module &m)
117{
118 py::bind_map<LibUtilities::FieldMetaDataMap>(m, "FieldMetaDataMap");
119 py::bind_vector<std::vector<Geometry *>>(m, "GeometryList");
120
121 py::class_<Composite, std::shared_ptr<Composite>>(m, "Composite")
122 .def(py::init<>())
123 .def(py::init<>(&Composite_Init))
124 .def_readwrite("geometries", &Composite::m_geomVec);
125
126 py::bind_map<CurveMap>(m, "CurveMap");
127 py::bind_map<CompositeMap>(m, "CompositeMap");
128 py::bind_map<std::map<int, CompositeMap>>(m, "DomainMap");
129
130 MeshGraph_GeomMapView<PointGeom>(m, "PointGeomView");
131 MeshGraph_GeomMapView<SegGeom>(m, "SegGeomView");
132 MeshGraph_GeomMapView<TriGeom>(m, "TriGeomView");
133 MeshGraph_GeomMapView<QuadGeom>(m, "QuadGeomView");
134 MeshGraph_GeomMapView<TetGeom>(m, "TetGeomView");
135 MeshGraph_GeomMapView<PyrGeom>(m, "PyrGeomView");
136 MeshGraph_GeomMapView<PrismGeom>(m, "PrismGeomView");
137 MeshGraph_GeomMapView<HexGeom>(m, "HexGeomView");
138
139 py::class_<MeshGraph, std::shared_ptr<MeshGraph>>(m, "MeshGraph")
140 .def(py::init<>())
141
142 .def("Empty", &MeshGraph::Empty)
143
144 .def("GetMeshDimension", &MeshGraph::GetMeshDimension)
145 .def("GetSpaceDimension", &MeshGraph::GetSpaceDimension)
146 .def("SetMeshDimension", &MeshGraph::SetMeshDimension)
147 .def("SetSpaceDimension", &MeshGraph::SetSpaceDimension)
148
149 .def_property_readonly("points", &MeshGraph::GetGeomMap<PointGeom>,
150 py::return_value_policy::reference_internal)
151 .def_property_readonly("segments", &MeshGraph::GetGeomMap<SegGeom>,
152 py::return_value_policy::reference_internal)
153 .def_property_readonly("quads", &MeshGraph::GetGeomMap<QuadGeom>,
154 py::return_value_policy::reference_internal)
155 .def_property_readonly("tris", &MeshGraph::GetGeomMap<TriGeom>,
156 py::return_value_policy::reference_internal)
157 .def_property_readonly("tets", &MeshGraph::GetGeomMap<TetGeom>,
158 py::return_value_policy::reference_internal)
159 .def_property_readonly("pyrs", &MeshGraph::GetGeomMap<PyrGeom>,
160 py::return_value_policy::reference_internal)
161 .def_property_readonly("prisms", &MeshGraph::GetGeomMap<PrismGeom>,
162 py::return_value_policy::reference_internal)
163 .def_property_readonly("hexes", &MeshGraph::GetGeomMap<HexGeom>,
164 py::return_value_policy::reference_internal)
165
166 .def("AddGeom", &MeshGraph_AddGeom<PointGeom>)
167 .def("AddGeom", &MeshGraph_AddGeom<SegGeom>)
168 .def("AddGeom", &MeshGraph_AddGeom<TriGeom>)
169 .def("AddGeom", &MeshGraph_AddGeom<QuadGeom>)
170
171 .def("GetVertex", &MeshGraph::GetPointGeom,
172 py::return_value_policy::reference_internal)
173 .def("GetPointGeom", &MeshGraph::GetPointGeom,
174 py::return_value_policy::reference_internal)
175 .def("GetSegGeom", &MeshGraph::GetSegGeom,
176 py::return_value_policy::reference_internal)
177 .def("GetTriGeom", &MeshGraph::GetTriGeom,
178 py::return_value_policy::reference_internal)
179 .def("GetQuadGeom", &MeshGraph::GetQuadGeom,
180 py::return_value_policy::reference_internal)
181 .def("GetHexGeom", &MeshGraph::GetHexGeom,
182 py::return_value_policy::reference_internal)
183 .def("GetPrismGeom", &MeshGraph::GetPrismGeom,
184 py::return_value_policy::reference_internal)
185 .def("GetTetGeom", &MeshGraph::GetTetGeom,
186 py::return_value_policy::reference_internal)
187 .def("GetPyrGeom", &MeshGraph::GetPyrGeom,
188 py::return_value_policy::reference_internal)
189
190 //.def("AddGeom", &MeshGraph::AddGeom<PointGeom>)
191 .def("GetCurvedEdges", &MeshGraph::GetCurvedEdges,
192 py::return_value_policy::reference_internal)
193 .def("GetCurvedFaces", &MeshGraph::GetCurvedFaces,
194 py::return_value_policy::reference_internal)
195 .def("GetComposites", &MeshGraph::GetComposites,
196 py::return_value_policy::reference_internal)
197 .def<std::map<int, CompositeMap> &(MeshGraph::*)()>(
198 "GetDomain", &MeshGraph::GetDomain,
199 py::return_value_policy::reference_internal)
200
201 .def("GetMovement", &MeshGraph::GetMovement,
202 py::return_value_policy::reference_internal)
203
204 .def("GetNumElements", &MeshGraph::GetNumElements)
205
206 .def("SetExpansionInfosToEvenlySpacedPoints",
208 .def("SetExpansionInfosToPolyOrder",
210 .def("SetExpansionInfosToPointOrder",
212}
void export_MeshGraph(py::module &m)
MeshGraph exports.
CompositeSharedPtr Composite_Init(py::list geometries)
void MeshGraph_GeomMapView(py::module_ &m, const std::string &name)
void MeshGraph_AddGeom(MeshGraphSharedPtr graph, unique_ptr_objpool< T > geom)
Base class for a spectral/hp element mesh.
Definition MeshGraph.h:290
TriGeom * GetTriGeom(int id)
Returns triangle id from the MeshGraph.
Definition MeshGraph.h:506
int GetMeshDimension()
Dimension of the mesh (can be a 1D curve in 3D space).
Definition MeshGraph.h:317
std::map< int, std::map< int, CompositeSharedPtr > > & GetDomain()
Definition MeshGraph.h:383
void SetExpansionInfoToEvenlySpacedPoints(int npoints=0)
Sets expansions to have equispaced points.
std::map< int, CompositeSharedPtr > & GetComposites()
Definition MeshGraph.h:373
PrismGeom * GetPrismGeom(int id)
Returns prism id from the MeshGraph.
Definition MeshGraph.h:538
SegGeom * GetSegGeom(int id)
Returns segment id from the MeshGraph.
Definition MeshGraph.h:498
void SetExpansionInfoToPointOrder(int npts)
Reset expansion to have specified point order npts.
void Empty(int dim, int space)
Definition MeshGraph.h:295
HexGeom * GetHexGeom(int id)
Returns hex id from the MeshGraph.
Definition MeshGraph.h:546
int GetSpaceDimension()
Dimension of the space (can be a 1D curve in 3D space).
Definition MeshGraph.h:323
PyrGeom * GetPyrGeom(int id)
Returns pyramid id from the MeshGraph.
Definition MeshGraph.h:530
void SetExpansionInfoToNumModes(int nmodes)
Reset expansion to have specified polynomial order nmodes.
MovementSharedPtr & GetMovement()
Definition MeshGraph.h:789
PointGeom * GetPointGeom(int id)
Returns vertex id from the MeshGraph.
Definition MeshGraph.h:490
QuadGeom * GetQuadGeom(int id)
Returns quadrilateral id from the MeshGraph.
Definition MeshGraph.h:514
TetGeom * GetTetGeom(int id)
Returns tetrahedron id from the MeshGraph.
Definition MeshGraph.h:522
std::shared_ptr< Composite > CompositeSharedPtr
Definition MeshGraph.h:178
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition MeshGraph.h:217
std::unique_ptr< T, typename ObjPoolManager< T >::UniquePtrDeleter > unique_ptr_objpool
std::vector< Geometry * > m_geomVec
Definition MeshGraph.h:175