Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (unstable)

ratioindicator.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:
10#ifndef DUNE_MMESH_REMESHING_RATIOINDICATOR_HH
11#define DUNE_MMESH_REMESHING_RATIOINDICATOR_HH
12
13#include <dune/common/exceptions.hh>
14#include <dune/grid/common/partitionset.hh>
16#include <memory>
17
18namespace Dune {
19
27template <class Grid>
29 static constexpr int dim = Grid::dimensionworld;
30 using ctype = typename Grid::ctype;
31 using GlobalCoordinate = FieldVector<ctype, dim>;
32
33 public:
35
44 RatioIndicator(ctype h = 0.0, ctype distProportion = 1.0, ctype factor = 1.0)
45 : edgeRatio_(4.), // the edge ratio. Decreases minH!
46 K_(2.), // the factor for the maximal edge length. Defaults to 2,
47 // because we use edge bisection.
48 maxH_(K_ * h),
49 k_(K_ / (2. * edgeRatio_)), // ensure that a triangle with two edges
50 // longer than maxH splits up to a triangle
51 // where all edges are longer than minH
52 minH_(k_ * h),
53 radiusRatio_(30.), // additional radius ratio to avoid very ugly cells
54 distProportion_(distProportion), // cells with distance to interface of
55 // value greater than distProportion_
56 // * max(dist) are refined to ...
57 factor_(factor) // ... edge length in [factor * minH_, factor * maxH_]
58 {}
59
62 void init(const Grid& grid) {
63 maxH_ = 0.0;
64 minH_ = 1e100;
65
66 for (const auto& edge : edges(grid.interfaceGrid().leafGridView())) {
67 const ctype h = edge.geometry().volume();
68 maxH_ = std::max(maxH_, h);
69 minH_ = std::min(minH_, h);
70 }
71
72 maxH_ = K_ * maxH_;
73 minH_ = k_ * minH_;
74
75 ctype maxh = 0.0;
76 ctype minh = 1e100;
77 for (const auto& edge : edges(grid.leafGridView())) {
78 const ctype h = edge.geometry().volume();
79 maxh = std::max(maxh, h);
80 minh = std::min(minh, h);
81 }
82
83 // fallback if there is no interface
84 if (grid.interfaceGrid().size(1) == 0) {
85 maxH_ = K_ * maxh;
86 minH_ = k_ * minh;
87 }
88
89 factor_ = maxh / minh;
90 distance_ = DistanceType(grid);
91 };
92
94 void update() {
95 distance_.update();
96 maxDist_ = distProportion_ * distance_.maximum();
97 }
98
106 template <class Element>
107 int operator()(const Element& element) const {
108 static constexpr int edgeCodim = Element::dimension - 1;
109
110 int refine = 0;
111 int coarse = 0;
112
113 ctype minE = 1e100;
114 ctype maxE = -1e100;
115 ctype sumE = 0.0;
116
117 // edge length
118 ctype dist = std::min(maxDist_, distance_(element));
119 const ctype l = dist / maxDist_;
120 const ctype minH = (1. - l) * minH_ + l * factor_ * minH_;
121 const ctype maxH = (1. - l) * maxH_ + l * factor_ * maxH_;
122
123 for (std::size_t i = 0; i < element.subEntities(edgeCodim); ++i) {
124 const auto& edge = element.template subEntity<edgeCodim>(i);
125 const ctype len = edge.geometry().volume();
126
127 if (len < minH) coarse++;
128
129 if (len > maxH) refine++;
130
131 minE = std::min(minE, len);
132 maxE = std::max(maxE, len);
133
134 sumE += len;
135 }
136
137 // edge ratio criterion
138 const ctype edgeRatio = maxE / minE;
139 if (edgeRatio > edgeRatio_) coarse++;
140
141 // radius ratio criterion
142 const auto& geo = element.geometry();
143 const ctype innerRadius = dim * geo.volume() / sumE;
144 const ctype outerRadius =
145 (geo.impl().circumcenter() - geo.corner(0)).two_norm();
146 const ctype radiusRatio = outerRadius / (innerRadius * dim);
147
148 if (radiusRatio > radiusRatio_) coarse++;
149
150 // priority on coarse
151 if (coarse > 0)
152 if (dim != 3) // disable coarsening in 3d until it is implemented
153 return -1;
154
155 // then refine
156 if (refine > 0) return 1;
157
158 // nothing to do
159 return 0;
160 }
161
162 ctype edgeRatio() const { return edgeRatio_; }
163
165 ctype maxH() const { return maxH_; }
166
168 ctype& maxH() { return maxH_; }
169
171 ctype minH() const { return minH_; }
172
174 ctype& minH() { return minH_; }
175
176 ctype radiusRatio() const { return radiusRatio_; }
177
179 ctype& distProportion() { return distProportion_; }
180
182 ctype& factor() { return factor_; }
183
185 const DistanceType& distance() const {
186 if (!distance_.initialized()) distance_.update();
187 return distance_;
188 }
189
190 private:
191 const ctype edgeRatio_;
192 const ctype K_;
193 ctype maxH_;
194 const ctype k_;
195 ctype minH_;
196 const ctype radiusRatio_;
197 ctype distProportion_;
198 ctype factor_;
199 ctype maxDist_;
200 mutable DistanceType distance_;
201};
202
203} // end namespace Dune
204
205#endif
Class for computing the distance to the interface.
Definition: distance.hh:23
bool initialized() const
Return if distance has been initialized.
Definition: distance.hh:62
void update()
Update the distances of all vertices.
Definition: distance.hh:42
ctype maximum() const
return maximum distance
Definition: distance.hh:118
Class defining an indicator for grid remeshing regarding the edge length ratio. By default,...
Definition: ratioindicator.hh:28
RatioIndicator(ctype h=0.0, ctype distProportion=1.0, ctype factor=1.0)
Calculates the indicator for each grid cell.
Definition: ratioindicator.hh:44
void init(const Grid &grid)
Definition: ratioindicator.hh:62
void update()
Update the distances of all vertices.
Definition: ratioindicator.hh:94
ctype & maxH()
Returns reference to maxH.
Definition: ratioindicator.hh:168
ctype maxH() const
Returns maxH.
Definition: ratioindicator.hh:165
int operator()(const Element &element) const
Function call operator to return mark.
Definition: ratioindicator.hh:107
ctype minH() const
Returns minH.
Definition: ratioindicator.hh:171
ctype & factor()
Returns reference to factor.
Definition: ratioindicator.hh:182
ctype & minH()
Returns reference to minH.
Definition: ratioindicator.hh:174
const DistanceType & distance() const
Returns distance object.
Definition: ratioindicator.hh:185
ctype & distProportion()
Returns reference to distProportion.
Definition: ratioindicator.hh:179
Class for computing the distance to the interface.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 17, 23:30, 2025)