Loading [MathJax]/extensions/tex2jax.js

DUNE-GRID-GLUE (2.10)

extractor.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-dune-grid-glue-exception
5/*
6 * Filename: extractor.hh
7 * Version: 1.0
8 * Created on: Oct 05, 2009
9 * Author: Christian Engwer
10 * ---------------------------------
11 * Project: dune-grid-glue
12 * Description: base class for all grid extractors
13 *
14 */
20#ifndef DUNE_GRIDGLUE_EXTRACTORS_EXTRACTOR_HH
21#define DUNE_GRIDGLUE_EXTRACTORS_EXTRACTOR_HH
22
23#include <vector>
24#include <map>
25#include <algorithm>
26#include <dune/common/exceptions.hh>
27#include <dune/common/fvector.hh>
28#include <dune/common/version.hh>
29#include <dune/grid/common/geometry.hh>
30#include <dune/grid/common/grid.hh>
31#include <dune/grid/common/mcmgmapper.hh>
32#include <dune/geometry/multilineargeometry.hh>
33
34namespace Dune {
35
36 namespace GridGlue {
37
44template<typename GV, int cd>
46{
47
48public:
49
50 static constexpr auto dimworld = GV::dimensionworld;
51 static constexpr auto dim = GV::dimension;
52 static constexpr auto codim = cd;
53
54 static constexpr int cube_corners = 1 << (dim-codim);
55
56 typedef GV GridView;
57 typedef typename GridView::Grid Grid;
58
59 typedef typename GV::Grid::ctype ctype;
60 typedef Dune::FieldVector<ctype, dimworld> Coords;
61 typedef Dune::FieldVector<ctype, dim> LocalCoords;
62
63 typedef typename GV::Traits::template Codim<dim>::Entity Vertex;
64 typedef typename Vertex::EntitySeed VertexSeed;
65
66 typedef typename GV::Traits::template Codim<0>::Entity Element;
67 typedef typename Element::EntitySeed ElementSeed;
68
69 typedef std::vector<unsigned int> VertexVector;
70 using CellMapper = MultipleCodimMultipleGeomTypeMapper<GridView>;
71
72 // typedef typename CellMapper::IndexType IndexType;
73 typedef int IndexType;
74public:
75
76 // transformations
77 typedef Dune::MultiLinearGeometry<ctype, dim-codim, dimworld> Geometry;
78 typedef Dune::MultiLinearGeometry<ctype, dim-codim, dim> LocalGeometry;
79
80protected:
81 /************************** PRIVATE SUBCLASSES **********************/
82
88 {
89 unsigned int idx : 28;
90 unsigned int num : 4;
91 };
92
93 struct CoordinateInfo
94 {
95 CoordinateInfo()
96 {}
97
98 CoordinateInfo(unsigned int index_, IndexType vtxindex_)
99 : vtxindex(vtxindex_), index(index_)
100 {}
101
103 IndexType vtxindex;
104
106 Coords coord;
107
109 unsigned int index;
110 };
111
116 {
117 VertexInfo(unsigned int idx_, const Vertex& p_) : idx(idx_), p(p_.seed())
118 {}
119 unsigned int idx;
120 VertexSeed p;
121 };
122
123
128 {
129 ElementInfo(unsigned int idx_, const Element& p_, unsigned int f_) : idx(idx_), faces(f_), p(p_.seed())
130 {}
131
133 unsigned int idx : 28;
134
136 unsigned int faces : 4;
137
139 ElementSeed p;
140 };
141
142
147 {
149 /*
150 * TODO: move default value of `geometryType_` to member declaration
151 * when removing support for older dune-geometry
152 */
153 : geometryType_(GeometryTypes::simplex(dim-codim))
154 {}
155
156 SubEntityInfo(IndexType parent_, unsigned int num_in_parent_,
157 const Dune::GeometryType& geometryType)
158 : parent(parent_), num_in_parent(num_in_parent_), geometryType_(geometryType)
159 {}
160
161 unsigned int nCorners() const
162 {
163 return Dune::ReferenceElements<ctype, dim-codim>::general(geometryType_).size(dim-codim);
164 }
165
167 IndexType parent;
168
170 unsigned int num_in_parent : 3;
171
173 Dune::GeometryType geometryType_;
174
181 CornerInfo corners[cube_corners]; // sim = number of vertices in a simplex
182 };
183
184
185 typedef std::map<IndexType, ElementInfo> ElementInfoMap;
186 typedef std::map<IndexType, VertexInfo> VertexInfoMap;
187
188 /************************** MEMBER VARIABLES ************************/
189
191 const GridView gv_;
192
193 /* Geometrical and Topological Information */
194
196 std::vector<CoordinateInfo> coords_;
197
199 std::vector<SubEntityInfo> subEntities_;
200
206 VertexInfoMap vtxInfo_;
207
213 ElementInfoMap elmtInfo_;
214
215 CellMapper cellMapper_;
216
217public:
218
219 /* C O N S T R U C T O R S A N D D E S T R U C T O R S */
220
225 Extractor(const GV& gv)
226 : gv_(gv)
227 , cellMapper_(gv, mcmgElementLayout())
228 {}
229
230 /* F U N C T I O N A L I T Y */
231
235 void clear()
236 {
237 coords_.clear();
238 coords_.shrink_to_fit();
239
240 subEntities_.clear();
241 subEntities_.shrink_to_fit();
242
243 // ...then clear the maps themselves, too
244 vtxInfo_.clear();
245 elmtInfo_.clear();
246 }
247
248
249 /* G E T T E R S */
250
256 void getCoords(std::vector<Dune::FieldVector<ctype, dimworld> >& coords) const
257 {
258 coords.resize(coords_.size());
259 for (unsigned int i = 0; i < coords_.size(); ++i)
260 coords[i] = coords_[i].coord;
261 }
262
263
268 unsigned int nCoords() const
269 {
270 return coords_.size();
271 }
272
274 void getGeometryTypes(std::vector<Dune::GeometryType>& geometryTypes) const
275 {
276 geometryTypes.resize(subEntities_.size());
277 for (size_t i=0; i<subEntities_.size(); i++)
278 geometryTypes[i] = subEntities_[i].geometryType_;
279 }
280
281
285 void getFaces(std::vector<VertexVector>& faces) const
286 {
287 faces.resize(subEntities_.size());
288 for (unsigned int i = 0; i < subEntities_.size(); ++i) {
289 faces[i].resize(subEntities_[i].nCorners());
290 for (unsigned int j = 0; j < subEntities_[i].nCorners(); ++j)
291 faces[i][j] = subEntities_[i].corners[j].idx;
292 }
293 }
294
295
304 bool faceIndices(const Element& e, int& first, int& count) const
305 {
306 typename ElementInfoMap::const_iterator it =
307 elmtInfo_.find(cellMapper_.map(e));
308 if (it == elmtInfo_.end())
309 {
310 first = -1;
311 count = 0;
312 return false;
313 }
314 // the iterator is valid, fill the out params
315 first = it->second.idx;
316 count = it->second.faces;
317 return true;
318 }
319
320
326 int indexInInside(unsigned int index) const
327 {
328 return index < subEntities_.size() ? subEntities_[index].num_in_parent : -1;
329 }
330
331 // /**
332 // * @brief tests that a given entry in the extraction set does have local couplings
333 // * @todo parallel interface
334 // */
335 // bool contains (unsigned int global, unsigned int & local) const
336 // {
337 // local = global;
338 // return true;
339 // }
340
344 const GridView & gridView() const
345 {
346 return gv_;
347 }
348
349 const Grid& grid() const
350 {
351 return gv_.grid();
352 }
353
360 Element
361 element(unsigned int index) const
362 {
363 if (index >= subEntities_.size())
364 DUNE_THROW(Dune::GridError, "invalid face index");
365 const ElementSeed seed = elmtInfo_.at(subEntities_[index].parent).p;
366 return grid().entity(seed);
367 }
368
369#if 1
376 Vertex
377 vertex(unsigned int index) const
378 {
379 if (index >= coords_.size())
380 DUNE_THROW(Dune::GridError, "invalid coordinate index");
381 const VertexSeed seed = vtxInfo_.at(coords_[index].vtxindex).p;
382 return grid().entity(seed);
383 }
384#endif
385
387 Geometry geometry(unsigned int index) const;
388
390 LocalGeometry geometryLocal(unsigned int index) const;
391
392};
393
394
396template<typename GV, int cd>
397typename Extractor<GV,cd>::Geometry Extractor<GV,cd>::geometry(unsigned int index) const
398{
399 std::vector<Coords> corners(subEntities_[index].nCorners());
400 for (unsigned int i = 0; i < subEntities_[index].nCorners(); ++i)
401 corners[i] = coords_[subEntities_[index].corners[i].idx].coord;
402
403 return Geometry(subEntities_[index].geometryType_, corners);
404}
405
406
408template<typename GV, int cd>
409typename Extractor<GV,cd>::LocalGeometry Extractor<GV,cd>::geometryLocal(unsigned int index) const
410{
411 std::vector<LocalCoords> corners(subEntities_[index].nCorners());
412
413 // get face info
414 const SubEntityInfo & face = subEntities_[index];
415 Dune::GeometryType facetype = subEntities_[index].geometryType_;
416
417 // get reference element
418 const auto elmtseed = elmtInfo_.at(face.parent).p;
419 const auto elmt = grid().entity(elmtseed);
420 const Dune::GeometryType celltype = elmt.type();
421 const auto& re = Dune::ReferenceElements<ctype, dim>::general(celltype);
422 for (unsigned int i = 0; i < subEntities_[index].nCorners(); ++i)
423 corners[i] = re.position(face.corners[i].num,dim);
424
425 return LocalGeometry(facetype, corners);
426}
427
428} // namespace GridGlue
429
430} // namespace Dune
431
432#endif // DUNE_GRIDGLUE_EXTRACTORS_EXTRACTOR_HH
Provides codimension-independent methods for grid extraction.
Definition: extractor.hh:46
VertexInfoMap vtxInfo_
a map enabling faster access to vertices and coordinates
Definition: extractor.hh:206
Element element(unsigned int index) const
gets the parent element for a given face index, throws an exception if index not valid
Definition: extractor.hh:361
int indexInInside(unsigned int index) const
gets the number face in the parent element
Definition: extractor.hh:326
LocalGeometry geometryLocal(unsigned int index) const
Get geometry of the extracted face in element coordinates.
Definition: extractor.hh:409
std::vector< CoordinateInfo > coords_
all information about the corner vertices of the extracted
Definition: extractor.hh:196
const GridView & gridView() const
give access to the Dune::GridView where this Patch belongs to
Definition: extractor.hh:344
void getFaces(std::vector< VertexVector > &faces) const
Get the corners of the extracted subentities.
Definition: extractor.hh:285
const GridView gv_
the grid object to extract the surface from
Definition: extractor.hh:191
std::vector< SubEntityInfo > subEntities_
all information about the extracted subEntities
Definition: extractor.hh:199
Vertex vertex(unsigned int index) const
gets the vertex for a given coordinate index throws an exception if index not valid
Definition: extractor.hh:377
void getGeometryTypes(std::vector< Dune::GeometryType > &geometryTypes) const
Get the list of geometry types.
Definition: extractor.hh:274
bool faceIndices(const Element &e, int &first, int &count) const
gets index of first subentity as well as the total number of subentities that were extracted from thi...
Definition: extractor.hh:304
Geometry geometry(unsigned int index) const
Get world geometry of the extracted face.
Definition: extractor.hh:397
unsigned int nCoords() const
getter for the count of coordinates
Definition: extractor.hh:268
Extractor(const GV &gv)
Constructor.
Definition: extractor.hh:225
void getCoords(std::vector< Dune::FieldVector< ctype, dimworld > > &coords) const
getter for the coordinates array
Definition: extractor.hh:256
ElementInfoMap elmtInfo_
a map enabling faster access to elements and faces
Definition: extractor.hh:213
void clear()
delete everything build up so far and free the memory
Definition: extractor.hh:235
Helpful struct holding one index for the coordinate (vertex) to which it is associated and the elemen...
Definition: extractor.hh:88
unsigned int idx
index of the vertex
Definition: extractor.hh:89
unsigned int num
element corner
Definition: extractor.hh:90
simple struct holding an element seed and an index
Definition: extractor.hh:128
unsigned int idx
the index of this element's first face in the internal list of extracted faces
Definition: extractor.hh:133
unsigned int faces
the number of extracted faces for this element
Definition: extractor.hh:136
ElementSeed p
the entity seed for the element
Definition: extractor.hh:139
Holds some information about an element's subentity involved in a coupling.
Definition: extractor.hh:147
CornerInfo corners[cube_corners]
the corner indices plus the numbers of the vertices in the parent element
Definition: extractor.hh:181
IndexType parent
the index of the parent element (from index set)
Definition: extractor.hh:167
unsigned int num_in_parent
the number of the face in the parent element
Definition: extractor.hh:170
Dune::GeometryType geometryType_
The GeometryType of the subentity.
Definition: extractor.hh:173
simple struct holding a vertex pointer and an index
Definition: extractor.hh:116
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 15, 23:04, 2025)