Dune Core Modules (2.9.1)

hierarchicsearch.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_GRID_HIERARCHICSEARCH_HH
7#define DUNE_GRID_HIERARCHICSEARCH_HH
8
15#include <cstddef>
16#include <sstream>
17#include <string>
18#include <utility>
19
23
25#include <dune/grid/common/gridenums.hh>
26
27namespace Dune
28{
29
33 template<class Grid, class IS>
35 {
37 constexpr static int dim = Grid::dimension;
38
40 constexpr static int dimw = Grid::dimensionworld;
41
43 typedef typename Grid::ctype ct;
44
46 typedef typename Grid::template Codim<0>::Entity Entity;
47
49 typedef typename Grid::HierarchicIterator HierarchicIterator;
50
51 static std::string formatEntityInformation ( const Entity &e ) {
52 const typename Entity::Geometry &geo = e.geometry();
53 std::ostringstream info;
54 info << "level=" << e.level() << " "
55 << "partition=" << e.partitionType() << " "
56 << "center=(" << geo.center() << ") "
57 << "corners=[(" << geo.corner(0) << ")";
58 for(int i = 1; i < geo.corners(); ++i)
59 info << " (" << e.geometry().corner(i) << ")";
60 info << "]";
61 return info.str();
62 }
63
74 Entity hFindEntity ( const Entity &entity,
75 const FieldVector<ct,dimw>& global) const
76 {
77 // type of element geometry
78 typedef typename Entity::Geometry Geometry;
79 // type of local coordinate
80 typedef typename Geometry::LocalCoordinate LocalCoordinate;
81
82 const int childLevel = entity.level()+1 ;
83 // loop over all child Entities
84 const HierarchicIterator end = entity.hend( childLevel );
85 for( HierarchicIterator it = entity.hbegin( childLevel ); it != end; ++it )
86 {
87 Entity child = *it;
88 Geometry geo = child.geometry();
89
90 LocalCoordinate local = geo.local(global);
91 if (referenceElement( geo ).checkInside(local))
92 {
93 // return if we found the leaf, else search through the child entites
94 if( indexSet_.contains( child ) )
95 return child;
96 else
97 return hFindEntity( child, global );
98 }
99 }
100 std::ostringstream children;
101 HierarchicIterator it = entity.hbegin( childLevel );
102 if(it != end) {
103 children << "{" << formatEntityInformation(*it) << "}";
104 for( ++it; it != end; ++it )
105 children << " {" << formatEntityInformation(*it) << "}";
106 }
107 DUNE_THROW(Exception, "{" << className(*this) << "} Unexpected "
108 "internal Error: none of the children of the entity "
109 "{" << formatEntityInformation(entity) << "} contains "
110 "coordinate (" << global << "). Children are: "
111 "[" << children.str() << "].");
112 }
113
114 public:
118 HierarchicSearch(const Grid & g, const IS & is) : grid_(g), indexSet_(is) {}
119
127 Entity findEntity(const FieldVector<ct,dimw>& global) const
128 { return findEntity<All_Partition>(global); }
129
137 template<PartitionIteratorType partition>
138 Entity findEntity(const FieldVector<ct,dimw>& global) const
139 {
140 typedef typename Grid::LevelGridView LevelGV;
141 const LevelGV &gv = grid_.levelGridView(0);
142
144 typedef typename LevelGV::template Codim<0>::template Partition<partition>::Iterator LevelIterator;
145
146 // type of element geometry
147 typedef typename Entity::Geometry Geometry;
148 // type of local coordinate
149 typedef typename Geometry::LocalCoordinate LocalCoordinate;
150
151 // loop over macro level
152 const LevelIterator end = gv.template end<0, partition>();
153 for (LevelIterator it = gv.template begin<0, partition>(); it != end; ++it)
154 {
155 Entity entity = *it;
156 Geometry geo = entity.geometry();
157
158 LocalCoordinate local = geo.local( global );
159 if( !referenceElement( geo ).checkInside( local ) )
160 continue;
161
162 if( (int(dim) != int(dimw)) && ((geo.global( local ) - global).two_norm() > 1e-8) )
163 continue;
164
165 // return if we found the leaf, else search through the child entites
166 if( indexSet_.contains( entity ) )
167 return entity;
168 else
169 return hFindEntity( entity, global );
170 }
171 DUNE_THROW( GridError, "Coordinate " << global << " is outside the grid." );
172 }
173
174 private:
175 const Grid& grid_;
176 const IS& indexSet_;
177 };
178
179} // end namespace Dune
180
181#endif // DUNE_GRID_HIERARCHICSEARCH_HH
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: entity.hh:100
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Wrapper class for geometries.
Definition: geometry.hh:71
GlobalCoordinate global(const LocalCoordinate &local) const
Evaluate the map .
Definition: geometry.hh:228
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:20
Grid abstract base class.
Definition: grid.hh:375
static constexpr int dimension
The dimension of the grid.
Definition: grid.hh:387
GridFamily::Traits::HierarchicIterator HierarchicIterator
A type that is a model of Dune::HierarchicIterator A type of iterator that allows to examine,...
Definition: grid.hh:482
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: grid.hh:402
static constexpr int dimensionworld
The dimension of the world the grid lives in.
Definition: grid.hh:390
LevelGridView levelGridView(int level) const
View for a grid level for All_Partition.
Definition: grid.hh:598
ct ctype
Define type used for coordinates in grid module.
Definition: grid.hh:532
Search an IndexSet for an Entity containing a given point.
Definition: hierarchicsearch.hh:35
Entity findEntity(const FieldVector< ct, dimw > &global) const
Search the IndexSet of this HierarchicSearch for an Entity containing point global.
Definition: hierarchicsearch.hh:127
Entity findEntity(const FieldVector< ct, dimw > &global) const
Search the IndexSet of this HierarchicSearch for an Entity containing point global.
Definition: hierarchicsearch.hh:138
HierarchicSearch(const Grid &g, const IS &is)
Construct a HierarchicSearch object from a Grid and an IndexSet.
Definition: hierarchicsearch.hh:118
A free function to provide the demangled class name of a given object or type as a string.
Different resources needed by all grid implementations.
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
Dune namespace.
Definition: alignedallocator.hh:13
std::string className()
Provide the demangled class name of a type T as a string.
Definition: classname.hh:47
Static tag representing a codimension.
Definition: dimension.hh:24
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)