dune-mmesh 1.4.1-git
Loading...
Searching...
No Matches
python/mmesh/grid.hh
Go to the documentation of this file.
1// -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_PYTHON_MMESH_INTERFACEGRID_HH
4#define DUNE_PYTHON_MMESH_INTERFACEGRID_HH
5
6#include <dune/python/pybind11/functional.h>
7#include <dune/python/pybind11/numpy.h>
8#include <dune/python/pybind11/pybind11.h>
9#include <dune/python/pybind11/stl.h>
10
11#include <array>
15#include <dune/geometry/type.hh>
16#include <dune/python/common/mpihelper.hh>
17#include <dune/python/common/typeregistry.hh>
18#include <dune/python/grid/capabilities.hh>
19#include <dune/python/grid/enums.hh>
20#include <dune/python/grid/factory.hh>
21#include <dune/python/grid/gridview.hh>
22#include <dune/python/grid/idset.hh>
23#include <functional>
24#include <list>
25#include <map>
26#include <memory>
27#include <sstream>
28#include <type_traits>
29
30namespace Dune {
31
32namespace Python {
33
34namespace MMIFGrid {
36template <class Grid, class... options>
37void registerHierarchicalGrid(pybind11::module module,
38 pybind11::class_<Grid, options...> cls) {
39 Dune::Python::registerHierarchicalGrid(module, cls);
40
41 cls.def_property_readonly(
42 "bulkGrid",
43 [](const Grid &grid) { return grid.getMMesh().leafGridView(); },
44 R"doc(
45 Obtain bulk grid of the MMesh
46
47 Returns: bulk grid
48 )doc");
49}
50
51} // end namespace MMIFGrid
52
53namespace MMGrid {
55template <int d, class... options>
57 pybind11::module module,
58 pybind11::class_<Dune::MovingMesh<d>, options...> cls) {
59 Dune::Python::registerHierarchicalGrid(module, cls);
60
62
63 cls.def_property_readonly(
64 "interfaceHierarchicalGrid",
65 [](const Grid &grid) -> const auto & { return grid.interfaceGrid(); },
66 pybind11::return_value_policy::reference, pybind11::keep_alive<0, 1>(),
67 R"doc(
68 Obtain interface hierarchical grid of the MMesh
69
70 Returns: interface hierarchical grid
71 )doc");
72
73 using Element = typename Grid::template Codim<0>::Entity;
74 using Vertex = typename Grid::template Codim<d>::Entity;
75 using Intersection = typename Grid::Intersection;
76 using InterfaceEntity = typename Grid::InterfaceEntity;
77 using InterfaceGrid = typename Grid::InterfaceGrid;
78 using InterfaceVertex =
79 typename InterfaceGrid::template Codim<InterfaceGrid::dimension>::Entity;
81
82 cls.def(
83 "preAdapt", [](Grid &self) { self.preAdapt(); },
84 R"doc(
85 Prepare grid for adaption
86 )doc");
87
88 cls.def(
89 "ensureInterfaceMovement",
90 [](Grid &self, const std::vector<FieldVector> &shifts) {
91 return self.ensureInterfaceMovement(shifts);
92 },
93 R"doc(
94 Ensure the non-degeneration of the mesh after movement of the interface vertices
95 )doc");
96
97 cls.def(
98 "markElements", [](Grid &self) { return self.markElements(); },
99 R"doc(
100 Mark all elements in accordance to the default indicator
101 )doc");
102
103 cls.def(
104 "adapt", [](Grid &self) { self.adapt(); },
105 R"doc(
106 Adapt the grid
107 )doc");
108
109 cls.def(
110 "getConnectedComponent",
111 [](Grid &self, const Element &element) {
112 return self.getConnectedComponent(element);
113 },
114 R"doc(
115 Return the connected component of an entity
116 )doc");
117
118 cls.def(
119 "moveInterface",
120 [](Grid &self, const std::vector<FieldVector> &shifts) {
121 self.moveInterface(shifts);
122 },
123 R"doc(
124 Move the interface by the given movement for each interface vertex
125 )doc");
126
127 cls.def(
128 "moveVertices",
129 [](Grid &self, const std::vector<FieldVector> &shifts) {
130 self.moveVertices(shifts);
131 },
132 R"doc(
133 Move all vertices of the triangulation by the given movement
134 )doc");
135
136 cls.def(
137 "isInterface",
138 [](Grid &self, const Intersection &intersection) {
139 return self.isInterface(intersection);
140 },
141 R"doc(
142 Return if intersection is part of the interface
143 )doc");
144
145 cls.def(
146 "isInterface",
147 [](Grid &self, const Vertex &vertex) { return self.isInterface(vertex); },
148 R"doc(
149 Return if vertex is part of the interface
150 )doc");
151
152 cls.def(
153 "asInterfaceEntity",
154 [](Grid &self, const Intersection &intersection) {
155 return self.asInterfaceEntity(intersection);
156 },
157 R"doc(
158 Return intersection as entity of the interface grid
159 )doc");
160
161 cls.def(
162 "asIntersection",
163 [](Grid &self, const InterfaceEntity &interfaceEntity) {
164 return self.asIntersection(interfaceEntity);
165 },
166 R"doc(
167 Return entity of the interface grid as (some) intersection of the MMesh
168 )doc");
169
170 cls.def(
171 "addInterface",
172 [](Grid &self, const Intersection &intersection) {
173 self.addInterface(intersection);
174 },
175 R"doc(
176 Add the intersection to the set of interface edges
177 )doc");
178
179 cls.def(
180 "addInterface",
181 [](Grid &self, const Intersection &intersection,
182 const std::size_t marker) { self.addInterface(intersection, marker); },
183 R"doc(
184 Add the intersection to the set of interface edges and mark it with marker
185 )doc");
186
187 cls.def(
188 "postAdapt", [](Grid &self) { self.postAdapt(); },
189 R"doc(
190 Remove adaption markers and connected components
191 )doc");
192
193 cls.def(
194 "isTip",
195 [](Grid &self, const InterfaceVertex &interfaceVertex) {
196 return interfaceVertex.impl().isTip();
197 },
198 R"doc(
199 Return if interface vertex is a tip
200 )doc");
201
202 cls.def(
203 "refineEdge",
204 [](Grid &self, const Element &element, const std::size_t edgeIndex,
205 const double where) {
206 return self.refineEdge(element, edgeIndex, where);
207 },
208 R"doc(
209 Refine edge manually
210 )doc");
211
212 cls.def(
213 "refineEdge",
214 [](Grid &self, const Element &element, const std::size_t edgeIndex) {
215 return self.refineEdge(element, edgeIndex, 0.5);
216 },
217 R"doc(
218 Refine edge manually
219 )doc");
220
221 cls.def(
222 "removeVertex",
223 [](Grid &self, const Vertex &vertex) {
224 return self.removeVertex(vertex);
225 },
226 R"doc(
227 Remove vertex manually
228 )doc");
229
230 cls.def(
231 "removeVertex",
232 [](Grid &self, const InterfaceVertex &vertex) {
233 return self.removeVertex(vertex);
234 },
235 R"doc(
236 Remove interface vertex manually
237 )doc");
238
239 cls.def(
240 "insertVertexInCell",
241 [](Grid &self, const FieldVector &position) {
242 return self.insertVertexInCell(position);
243 },
244 R"doc(
245 Insert vertex in cell manually
246 )doc");
247}
248
249} // namespace MMGrid
250
251} // namespace Python
252
253} // namespace Dune
254
255#endif
Dune::ParameterTree options
void registerHierarchicalGrid(pybind11::module module, pybind11::class_< Grid, options... > cls)
register interface grid
Definition python/mmesh/grid.hh:37
void registerHierarchicalGrid(pybind11::module module, pybind11::class_< Dune::MovingMesh< d >, options... > cls)
register bulk grid
Definition python/mmesh/grid.hh:56
@ Vertex
Definition curvatureoperator.hh:22
@ Element
Definition curvatureoperator.hh:22
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
bool preAdapt()
void postAdapt()
bool adapt()
The MMesh class templatized by the CGAL host grid type and the dimension. .
Definition grid/mmesh.hh:158