12#ifndef DUMUX_GRIDADAPTINITIALIZATIONINDICATOR_HH
13#define DUMUX_GRIDADAPTINITIALIZATIONINDICATOR_HH
17#include <dune/geometry/type.hh>
32template<
class TypeTag>
38 using Element =
typename GridView::Traits::template Codim<0>::Entity;
61 std::shared_ptr<const GridGeometry> gridGeometry,
62 std::shared_ptr<const GridVariables> gridVariables)
64 , gridGeometry_(gridGeometry)
65 , gridVariables_(gridVariables)
66 , minLevel_(
getParamFromGroup<std::size_t>(problem->paramGroup(),
"Adaptive.MinLevel"))
67 , maxLevel_(
getParamFromGroup<std::size_t>(problem->paramGroup(),
"Adaptive.MaxLevel"))
68 , refineAtDirichletBC_(
getParamFromGroup<bool>(problem->paramGroup(),
"Adaptive.RefineAtDirichletBC", true))
69 , refineAtFluxBC_(
getParamFromGroup<bool>(problem->paramGroup(),
"Adaptive.RefineAtFluxBC", true))
70 , refineAtSource_(
getParamFromGroup<bool>(problem->paramGroup(),
"Adaptive.RefineAtSource", true))
71 , eps_(
getParamFromGroup<Scalar>(problem->paramGroup(),
"Adaptive.BCRefinementThreshold", 1e-10))
93 void setLevels(std::size_t minLevel, std::size_t maxLevel)
104 refineAtDirichletBC_ = refine;
112 refineAtSource_ = refine;
120 refineAtFluxBC_ = refine;
128 template<
class SolutionVector>
132 indicatorVector_.assign(gridGeometry_->gridView().size(0),
false);
135 auto fvGeometry =
localView(*gridGeometry_);
136 auto elemVolVars =
localView(gridVariables_->curGridVolVars());
138 auto elemFluxVarsCache =
localView(gridVariables_->gridFluxVarsCache());
140 for (
const auto& element : elements(gridGeometry_->gridView()))
142 const auto eIdx = gridGeometry_->elementMapper().index(element);
145 if (element.level() < minLevel_)
147 indicatorVector_[eIdx] =
true;
152 if (!refineAtSource_ && !refineAtFluxBC_ && !refineAtDirichletBC_)
156 if (element.level() == maxLevel_)
160 fvGeometry.bind(element);
161 elemVolVars.bind(element, fvGeometry, sol);
162 elemFluxVarsCache.bind(element, fvGeometry, elemVolVars);
168 for (
const auto& scv : scvs(fvGeometry))
170 auto source = problem_->source(element, fvGeometry, elemVolVars, scv);
171 auto pointSource = problem_->scvPointSources(element, fvGeometry, elemVolVars, scv);
172 if (source.infinity_norm() + pointSource.infinity_norm() > eps_)
174 indicatorVector_[eIdx] =
true;
181 if (!indicatorVector_[eIdx]
182 && element.hasBoundaryIntersections()
183 && (refineAtDirichletBC_ || refineAtFluxBC_))
188 for (
const auto& scvf : scvfs(fvGeometry))
191 if (!scvf.boundary())
194 const auto bcTypes = problem_->boundaryTypes(element, scvf);
196 if(bcTypes.hasOnlyDirichlet() && refineAtDirichletBC_)
198 indicatorVector_[eIdx] =
true;
203 else if(refineAtFluxBC_)
205 const auto fluxes = problem_->neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
206 if (fluxes.infinity_norm() > eps_)
208 indicatorVector_[eIdx] =
true;
219 std::vector<BoundaryTypes> bcTypes(fvGeometry.numScv());
222 for (
const auto& scv : scvs(fvGeometry))
224 bcTypes[scv.localDofIndex()] = problem_->boundaryTypes(element, scv);
225 if (refineAtDirichletBC_ && bcTypes[scv.localDofIndex()].hasDirichlet())
227 indicatorVector_[eIdx] =
true;
233 if (!indicatorVector_[eIdx] && refineAtFluxBC_)
235 for (
const auto& scvf : scvfs(fvGeometry))
238 if (scvf.boundary() && bcTypes[scvf.insideScvIdx()].hasNeumann())
240 const auto fluxes = problem_->neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
241 if (fluxes.infinity_norm() > eps_)
243 indicatorVector_[eIdx] =
true;
267 if (indicatorVector_[gridGeometry_->elementMapper().index(element)])
273 std::shared_ptr<const Problem> problem_;
274 std::shared_ptr<const GridGeometry> gridGeometry_;
275 std::shared_ptr<const GridVariables> gridVariables_;
276 std::vector<bool> indicatorVector_;
280 bool refineAtDirichletBC_;
281 bool refineAtFluxBC_;
282 bool refineAtSource_;
Class to specify the type of a boundary.
Definition: common/boundarytypes.hh:26
Class defining an initialization indicator for grid adaption. Refines at sources and boundaries....
Definition: initializationindicator.hh:34
void setRefinementAtFluxBoundaries(bool refine)
Function to set if refinement at sources is to be used.
Definition: initializationindicator.hh:118
void setLevels(std::size_t minLevel, std::size_t maxLevel)
Function to set the minimum/maximum allowed levels.
Definition: initializationindicator.hh:93
void setMaxLevel(std::size_t maxLevel)
Function to set the maximum allowed level.
Definition: initializationindicator.hh:85
void calculate(const SolutionVector &sol)
Calculates the indicator used for refinement/coarsening for each grid cell.
Definition: initializationindicator.hh:129
void setRefinementAtDirichletBC(bool refine)
Function to set if refinement at Dirichlet boundaries is to be used.
Definition: initializationindicator.hh:102
int operator()(const Element &element) const
function call operator to return mark
Definition: initializationindicator.hh:265
GridAdaptInitializationIndicator(std::shared_ptr< const Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry, std::shared_ptr< const GridVariables > gridVariables)
Constructor.
Definition: initializationindicator.hh:60
void setRefinementAtSources(bool refine)
Function to set if refinement at sources is to be used.
Definition: initializationindicator.hh:110
void setMinLevel(std::size_t minLevel)
Function to set the minimum allowed level.
Definition: initializationindicator.hh:77
Defines all properties used in Dumux.
Type traits for problem classes.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition: parameters.hh:149
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
The available discretization methods in Dumux.
constexpr Box box
Definition: method.hh:147
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
typename Detail::template ProblemTraits< Problem, typename GridGeometry::DiscretizationMethod >::BoundaryTypes BoundaryTypes
Definition: common/typetraits/problem.hh:34