Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
hierarchic-approximation.hh
Go to the documentation of this file.
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set ts=8 sw=4 et sts=4:
3
4// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUFEM_GRID_HIERARCHIC_APPROXIMATION_HH
8#define DUNE_FUFEM_GRID_HIERARCHIC_APPROXIMATION_HH
9
10// Based on
11// dune/grid/utility/hierarchicsearch.hh
12
19#include <cstddef>
20#include <sstream>
21#include <string>
22#include <utility>
23
26
27#include <dune/grid/common/grid.hh>
29
31
35template <class Grid, class IS> class HierarchicApproximation {
37 enum { dim = Grid::dimension };
38
40 enum { 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 template <class Iterator>
52 Entity findBestEntity(Iterator first, Iterator last,
54 double minDistance = std::numeric_limits<double>::infinity();
55 Entity ret;
56
57 for (Iterator it = first; it != last; ++it) {
58 const Entity child = *it;
59 const double d = distance(global, child.geometry(), tolerance_);
60 if (d < minDistance) {
61 ret = child;
62 minDistance = d;
63 }
64 }
65 return ret;
66 }
67
78 Entity hFindEntity(const Entity &entity,
80 const int childLevel = entity.level() + 1;
81 Entity const best = findBestEntity(entity.hbegin(childLevel),
82 entity.hend(childLevel), global);
83 if (indexSet_.contains(best))
84 return best;
85 else
86 return hFindEntity(best, global);
87 }
88
89public:
94 HierarchicApproximation(const Grid &g, const IS &is, double tolerance)
95 : grid_(g), indexSet_(is), tolerance_(tolerance) {}
96
102 return findEntity<Dune::All_Partition>(global);
103 }
104
109 template <Dune::PartitionIteratorType partition>
111 typedef typename Grid::LevelGridView LevelGV;
112 const LevelGV &gv = grid_.template levelGridView(0);
113
114 Entity const best = findBestEntity(gv.template begin<0, partition>(),
115 gv.template end<0, partition>(), global);
116 if (indexSet_.contains(best))
117 return best;
118 else
119 return hFindEntity(best, global);
120 }
121
122private:
123 const Grid &grid_;
124 const IS &indexSet_;
125 const double tolerance_;
126};
127#endif
double distance(const Coordinate &target, const ConvexPolyhedron< Coordinate > &segment, double correctionTolerance, size_t maxIterations=1000)
Definition polyhedrondistance.hh:99
const GlobalIndex & global() const
Search an IndexSet for the Entity closest to a given point.
Definition hierarchic-approximation.hh:35
Entity findEntity(const Dune::FieldVector< ct, dimw > &global) const
Search the IndexSet of this HierarchicSearch for the Entity closest to the point global.
Definition hierarchic-approximation.hh:110
HierarchicApproximation(const Grid &g, const IS &is, double tolerance)
Construct a HierarchicApproximation object from a Grid, an IndexSet, and an approximation tolerance.
Definition hierarchic-approximation.hh:94
Entity findEntity(const Dune::FieldVector< ct, dimw > &global) const
Search the IndexSet of this HierarchicSearch for the Entity closest to the point global.
Definition hierarchic-approximation.hh:101
T infinity(T... args)