Nektar++
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#include <boost/python/suite/indexing/map_indexing_suite.hpp>
41#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
42
43using namespace Nektar;
44using namespace Nektar::SpatialDomains;
45
46/*
47 * @brief Lightweight wrapper around MeshGraph::Read to avoid wrapping
48 * DomainRange struct.
49 */
52{
53 return MeshGraph::Read(session);
54}
55
56/*
57 * @brief Simple wrapper to build Composite objects from lists of
58 * Geometry objects.
59 */
61{
62 CompositeSharedPtr composite = std::make_shared<Composite>();
63 composite->m_geomVec.clear();
64 for (int i = 0; i < py::len(geometries); i++)
65 {
66 composite->m_geomVec.emplace_back(
67 py::extract<GeometrySharedPtr>(geometries[i]));
68 }
69 return composite;
70}
71
72/*
73 * @brief Wrapper to construct MeshGraphXml object, initialising mesh
74 * and spatial dimensions.
75 */
76std::shared_ptr<MeshGraph> MeshGraphXml_Init(int meshDim, int spatialDim)
77{
78 auto result = MeshGraphXml::create();
79 result->Empty(meshDim, spatialDim);
80 return result;
81}
82
83/*
84 * @brief Wrapper to construct MeshGraphXmlCompressed object, initialising mesh
85 * and spatial dimensions.
86 */
87std::shared_ptr<MeshGraph> MeshGraphXmlCompressed_Init(int meshDim,
88 int spatialDim)
89{
90 auto result = MeshGraphXmlCompressed::create();
91 result->Empty(meshDim, spatialDim);
92 return result;
93}
94
95/**
96 * @brief MeshGraph exports.
97 */
99{
100 py::class_<LibUtilities::FieldMetaDataMap>("FieldMetaDataMap")
101 .def(py::map_indexing_suite<LibUtilities::FieldMetaDataMap, true>());
102
103 py::class_<std::vector<GeometrySharedPtr>>("GeometryList")
104 .def(py::vector_indexing_suite<std::vector<GeometrySharedPtr>, true>());
105 py::class_<Composite, std::shared_ptr<Composite>>("Composite", py::init<>())
106 .def("__init__", py::make_constructor(&Composite_Init))
107 .def_readwrite("geometries", &Composite::m_geomVec);
108
109 py::class_<PointGeomMap>("PointGeomMap")
110 .def(py::map_indexing_suite<PointGeomMap, true>());
111 py::class_<SegGeomMap>("SegGeomMap")
112 .def(py::map_indexing_suite<SegGeomMap, true>());
113 py::class_<QuadGeomMap>("QuadGeomMap")
114 .def(py::map_indexing_suite<QuadGeomMap, true>());
115 py::class_<TriGeomMap>("TriGeomMap")
116 .def(py::map_indexing_suite<TriGeomMap, true>());
117 py::class_<TetGeomMap>("TetGeomMap")
118 .def(py::map_indexing_suite<TetGeomMap, true>());
119 py::class_<PrismGeomMap>("PrismGeomMap")
120 .def(py::map_indexing_suite<PrismGeomMap, true>());
121 py::class_<PyrGeomMap>("PyrGeomMap")
122 .def(py::map_indexing_suite<PyrGeomMap, true>());
123 py::class_<HexGeomMap>("HexGeomMap")
124 .def(py::map_indexing_suite<HexGeomMap, true>());
125 py::class_<CurveMap>("CurveMap")
126 .def(py::map_indexing_suite<CurveMap, true>());
127 py::class_<CompositeMap>("CompositeMap")
128 .def(py::map_indexing_suite<CompositeMap, true>());
129 py::class_<std::map<int, CompositeMap>>("DomainMap")
130 .def(py::map_indexing_suite<std::map<int, CompositeMap>, true>());
131
132 py::class_<MeshGraph, std::shared_ptr<MeshGraph>, boost::noncopyable>(
133 "MeshGraph", py::no_init)
134
135 .def("Read", MeshGraph_Read)
136 .staticmethod("Read")
137
138 .def("Write", &MeshGraph::WriteGeometry, py::default_call_policies(),
139 (py::arg("outfile"), py::arg("defaultExp") = false,
140 py::arg("metadata") = LibUtilities::NullFieldMetaDataMap))
141
142 .def("GetMeshDimension", &MeshGraph::GetMeshDimension)
143 .def("GetAllPointGeoms", &MeshGraph::GetAllPointGeoms,
144 py::return_internal_reference<>())
145 .def("GetAllSegGeoms", &MeshGraph::GetAllSegGeoms,
146 py::return_internal_reference<>())
147 .def("GetAllQuadGeoms", &MeshGraph::GetAllQuadGeoms,
148 py::return_internal_reference<>())
149 .def("GetAllTriGeoms", &MeshGraph::GetAllTriGeoms,
150 py::return_internal_reference<>())
151 .def("GetAllTetGeoms", &MeshGraph::GetAllTetGeoms,
152 py::return_internal_reference<>())
153 .def("GetAllPrismGeoms", &MeshGraph::GetAllPrismGeoms,
154 py::return_internal_reference<>())
155 .def("GetAllPyrGeoms", &MeshGraph::GetAllPyrGeoms,
156 py::return_internal_reference<>())
157 .def("GetAllHexGeoms", &MeshGraph::GetAllHexGeoms,
158 py::return_internal_reference<>())
159 .def("GetCurvedEdges", &MeshGraph::GetCurvedEdges,
160 py::return_internal_reference<>())
161 .def("GetCurvedFaces", &MeshGraph::GetCurvedFaces,
162 py::return_internal_reference<>())
163 .def("GetComposites", &MeshGraph::GetComposites,
164 py::return_internal_reference<>())
165 .def<std::map<int, CompositeMap> &(MeshGraph::*)()>(
166 "GetDomain", &MeshGraph::GetDomain,
167 py::return_internal_reference<>())
168
169 .def("GetMovement", &MeshGraph::GetMovement,
170 py::return_value_policy<py::return_by_value>())
171
172 .def("GetNumElements", &MeshGraph::GetNumElements)
173
174 .def("SetExpansionInfosToEvenlySpacedPoints",
175 &MeshGraph::SetExpansionInfoToEvenlySpacedPoints)
176 .def("SetExpansionInfosToPolyOrder",
177 &MeshGraph::SetExpansionInfoToNumModes)
178 .def("SetExpansionInfosToPointOrder",
179 &MeshGraph::SetExpansionInfoToPointOrder);
180
181 py::class_<MeshGraphXml, py::bases<MeshGraph>,
182 std::shared_ptr<MeshGraphXml>, boost::noncopyable>(
183 "MeshGraphXml", py::no_init)
184 .def("__init__", py::make_constructor(&MeshGraphXml_Init));
185
186 py::class_<MeshGraphXmlCompressed, py::bases<MeshGraphXml>,
187 std::shared_ptr<MeshGraphXmlCompressed>, boost::noncopyable>(
188 "MeshGraphXmlCompressed", py::no_init)
189 .def("__init__", py::make_constructor(&MeshGraphXmlCompressed_Init));
190}
void export_MeshGraph()
MeshGraph exports.
MeshGraphSharedPtr MeshGraph_Read(const LibUtilities::SessionReaderSharedPtr &session)
CompositeSharedPtr Composite_Init(py::list geometries)
std::shared_ptr< MeshGraph > MeshGraphXmlCompressed_Init(int meshDim, int spatialDim)
std::shared_ptr< MeshGraph > MeshGraphXml_Init(int meshDim, int spatialDim)
Base class for a spectral/hp element mesh.
Definition: MeshGraph.h:181
std::shared_ptr< SessionReader > SessionReaderSharedPtr
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:51
std::shared_ptr< Composite > CompositeSharedPtr
Definition: MeshGraph.h:135
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174