Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (1.4)

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