3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
initializationindicator.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_GRIDADAPTINITIALIZATIONINDICATOR_HH
25#define DUMUX_GRIDADAPTINITIALIZATIONINDICATOR_HH
26
27#include <memory>
28
29#include <dune/geometry/type.hh>
34
35namespace Dumux {
36
44template<class TypeTag>
46{
50 using Element = typename GridView::Traits::template Codim<0>::Entity;
51
54
56
57public:
58
72 GridAdaptInitializationIndicator(std::shared_ptr<const Problem> problem,
73 std::shared_ptr<const GridGeometry> gridGeometry,
74 std::shared_ptr<const GridVariables> gridVariables)
75 : problem_(problem)
76 , gridGeometry_(gridGeometry)
77 , gridVariables_(gridVariables)
78 , minLevel_(getParamFromGroup<std::size_t>(problem->paramGroup(), "Adaptive.MinLevel"))
79 , maxLevel_(getParamFromGroup<std::size_t>(problem->paramGroup(), "Adaptive.MaxLevel"))
80 , refineAtDirichletBC_(getParamFromGroup<bool>(problem->paramGroup(), "Adaptive.RefineAtDirichletBC", true))
81 , refineAtFluxBC_(getParamFromGroup<bool>(problem->paramGroup(), "Adaptive.RefineAtFluxBC", true))
82 , refineAtSource_(getParamFromGroup<bool>(problem->paramGroup(), "Adaptive.RefineAtSource", true))
83 , eps_(getParamFromGroup<Scalar>(problem->paramGroup(), "Adaptive.BCRefinementThreshold", 1e-10))
84 {}
85
89 void setMinLevel(std::size_t minLevel)
90 {
91 minLevel_ = minLevel;
92 }
93
97 void setMaxLevel(std::size_t maxLevel)
98 {
99 maxLevel_ = maxLevel;
100 }
101
105 void setLevels(std::size_t minLevel, std::size_t maxLevel)
106 {
107 minLevel_ = minLevel;
108 maxLevel_ = maxLevel;
109 }
110
115 {
116 refineAtDirichletBC_ = refine;
117 }
118
122 void setRefinementAtSources(bool refine)
123 {
124 refineAtSource_ = refine;
125 }
126
131 {
132 refineAtFluxBC_ = refine;
133 }
134
140 template<class SolutionVector>
141 void calculate(const SolutionVector& sol)
142 {
144 indicatorVector_.assign(gridGeometry_->gridView().size(0), false);
145
146 // get the fvGeometry and elementVolVars needed for the bc and source interfaces
147 auto fvGeometry = localView(*gridGeometry_);
148 auto elemVolVars = localView(gridVariables_->curGridVolVars());
149 // elemFluxVarsCache for neumann interface
150 auto elemFluxVarsCache = localView(gridVariables_->gridFluxVarsCache());
151
152 for (const auto& element : elements(gridGeometry_->gridView()))
153 {
154 const auto eIdx = gridGeometry_->elementMapper().index(element);
155
157 if (element.level() < minLevel_)
158 {
159 indicatorVector_[eIdx] = true;
160 continue; // proceed to the next element
161 }
162
163 // If refinement at sources/BCs etc is deactivated, skip the rest
164 if (!refineAtSource_ && !refineAtFluxBC_ && !refineAtDirichletBC_)
165 continue;
166
167 // if the element is already on the maximum permissive level, skip rest
168 if (element.level() == maxLevel_)
169 continue;
170
171 // Bind all of the local views
172 fvGeometry.bind(element);
173 elemVolVars.bind(element, fvGeometry, sol);
174 elemFluxVarsCache.bind(element, fvGeometry, elemVolVars);
175
176
178 if (refineAtSource_)
179 {
180 for (const auto& scv : scvs(fvGeometry))
181 {
182 auto source = problem_->source(element, fvGeometry, elemVolVars, scv);
183 auto pointSource = problem_->scvPointSources(element, fvGeometry, elemVolVars, scv);
184 if (source.infinity_norm() + pointSource.infinity_norm() > eps_)
185 {
186 indicatorVector_[eIdx] = true;
187 break; // element is marked, escape scv loop
188 }
189 }
190 }
191
193 if (!indicatorVector_[eIdx] // proceed if element is not already marked
194 && element.hasBoundaryIntersections() // proceed if element is on boundary
195 && (refineAtDirichletBC_ || refineAtFluxBC_)) // proceed if boundary refinement is active
196 {
197 // cell-centered schemes
198 if (!isBox)
199 {
200 for (const auto& scvf : scvfs(fvGeometry))
201 {
202 // skip non-boundary scvfs
203 if (!scvf.boundary())
204 continue;
205
206 const auto bcTypes = problem_->boundaryTypes(element, scvf);
207 // We assume pure BCs, mixed boundary types are not allowed anyway!
208 if(bcTypes.hasOnlyDirichlet() && refineAtDirichletBC_)
209 {
210 indicatorVector_[eIdx] = true;
211 break; // element is marked, escape scvf loop
212 }
213
214 // we are on a pure Neumann boundary
215 else if(refineAtFluxBC_)
216 {
217 const auto fluxes = problem_->neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
218 if (fluxes.infinity_norm() > eps_)
219 {
220 indicatorVector_[eIdx] = true;
221 break; // element is marked, escape scvf loop
222 }
223 }
224 }
225 }
226 // box-scheme
227 else
228 {
229 // container to store bcTypes
231 std::vector<BoundaryTypes> bcTypes(fvGeometry.numScv());
232
233 // Get bcTypes and maybe mark for refinement on Dirichlet boundaries
234 for (const auto& scv : scvs(fvGeometry))
235 {
236 bcTypes[scv.localDofIndex()] = problem_->boundaryTypes(element, scv);
237 if (refineAtDirichletBC_ && bcTypes[scv.localDofIndex()].hasDirichlet())
238 {
239 indicatorVector_[eIdx] = true;
240 break; // element is marked, escape scv loop
241 }
242 }
243
244 // If element hasn't been marked because of Dirichlet BCS, check Neumann BCs
245 if (!indicatorVector_[eIdx] && refineAtFluxBC_)
246 {
247 for (const auto& scvf : scvfs(fvGeometry))
248 {
250 if (scvf.boundary() && bcTypes[scvf.insideScvIdx()].hasNeumann())
251 {
252 const auto fluxes = problem_->neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
253 if (fluxes.infinity_norm() > eps_)
254 {
255 indicatorVector_[eIdx] = true;
256 break; // element is marked, escape scvf loop
257 }
258 }
259 }
260 }
261 }
262 }
263 }
264 }
265
277 int operator() (const Element& element) const
278 {
279 if (indicatorVector_[gridGeometry_->elementMapper().index(element)])
280 return 1;
281 return 0;
282 }
283
284private:
285 std::shared_ptr<const Problem> problem_;
286 std::shared_ptr<const GridGeometry> gridGeometry_;
287 std::shared_ptr<const GridVariables> gridVariables_;
288 std::vector<bool> indicatorVector_;
289
290 int minLevel_;
291 int maxLevel_;
292 bool refineAtDirichletBC_;
293 bool refineAtFluxBC_;
294 bool refineAtSource_;
295 Scalar eps_;
296};
297
298} // end namespace Dumux
299
300#endif
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition: parameters.hh:161
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:180
constexpr Box box
Definition: method.hh:136
Class defining an initialization indicator for grid adaption. Refines at sources and boundaries....
Definition: initializationindicator.hh:46
void setRefinementAtFluxBoundaries(bool refine)
Function to set if refinement at sources is to be used.
Definition: initializationindicator.hh:130
void setLevels(std::size_t minLevel, std::size_t maxLevel)
Function to set the minimum/maximum allowed levels.
Definition: initializationindicator.hh:105
void setMaxLevel(std::size_t maxLevel)
Function to set the maximum allowed level.
Definition: initializationindicator.hh:97
void calculate(const SolutionVector &sol)
Calculates the indicator used for refinement/coarsening for each grid cell.
Definition: initializationindicator.hh:141
void setRefinementAtDirichletBC(bool refine)
Function to set if refinement at Dirichlet boundaries is to be used.
Definition: initializationindicator.hh:114
int operator()(const Element &element) const
function call operator to return mark
Definition: initializationindicator.hh:277
GridAdaptInitializationIndicator(std::shared_ptr< const Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry, std::shared_ptr< const GridVariables > gridVariables)
Constructor.
Definition: initializationindicator.hh:72
void setRefinementAtSources(bool refine)
Function to set if refinement at sources is to be used.
Definition: initializationindicator.hh:122
void setMinLevel(std::size_t minLevel)
Function to set the minimum allowed level.
Definition: initializationindicator.hh:89
Class to specify the type of a boundary.
Definition: common/boundarytypes.hh:38
typename Detail::template ProblemTraits< Problem, typename GridGeometry::DiscretizationMethod >::BoundaryTypes BoundaryTypes
Definition: common/typetraits/problem.hh:46
Declares all properties used in Dumux.
Type traits for problem classes.