24#ifndef DUMUX_COMMON_FV_PROBLEM_HH
25#define DUMUX_COMMON_FV_PROBLEM_HH
30#include <dune/common/fvector.hh>
31#include <dune/grid/common/gridenums.hh>
48template<
class TypeTag>
54 using FVElementGeometry =
typename GridGeometry::LocalView;
55 using GridView =
typename GridGeometry::GridView;
56 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
57 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
58 using Element =
typename GridView::template Codim<0>::Entity;
59 using GlobalPosition =
typename Element::Geometry::GlobalCoordinate;
61 enum { dim = GridView::dimension };
65 using PointSourceMap = std::map< std::pair<std::size_t, std::size_t>,
66 std::vector<PointSource> >;
70 using ElementVolumeVariables =
typename GridVariables::GridVolumeVariables::LocalView;
71 using VolumeVariables =
typename ElementVolumeVariables::VolumeVariables;
103 problemName_ = getParamFromGroup<std::string>(
paramGroup,
"Problem.Name");
113 const std::string&
name()
const
129 problemName_ = newName;
145 const SubControlVolume &scv)
const
148 DUNE_THROW(Dune::InvalidStateException,
149 "boundaryTypes(..., scv) called for cell-centered method.");
152 return asImp_().boundaryTypesAtPos(scv.dofPosition());
163 const SubControlVolumeFace &scvf)
const
166 DUNE_THROW(Dune::InvalidStateException,
167 "boundaryTypes(..., scvf) called for box method.");
170 return asImp_().boundaryTypesAtPos(scvf.ipGlobal());
183 BoundaryTypes bcTypes;
184 bcTypes.setAllDirichlet();
198 PrimaryVariables
dirichlet(
const Element &element,
const SubControlVolumeFace &scvf)
const
203 DUNE_THROW(Dune::InvalidStateException,
"dirichlet(scvf) called for box method.");
206 return asImp_().dirichletAtPos(scvf.ipGlobal());
219 PrimaryVariables
dirichlet(
const Element &element,
const SubControlVolume &scv)
const
222 if (!isBox && !isStaggered)
224 DUNE_THROW(Dune::InvalidStateException,
"dirichlet(scv) called for other than box or staggered method.");
227 return asImp_().dirichletAtPos(scv.dofPosition());
242 DUNE_THROW(Dune::InvalidStateException,
243 "The problem specifies that some boundary "
244 "segments are dirichlet, but does not provide "
245 "a dirichlet() or a dirichletAtPos() method.");
284 const FVElementGeometry& fvGeometry,
285 const ElementVolumeVariables& elemVolVars,
286 const ElementFluxVariablesCache& elemFluxVarsCache,
287 const SubControlVolumeFace& scvf)
const
290 return asImp_().neumannAtPos(scvf.ipGlobal());
306 return NumEqVector(0.0);
327 NumEqVector
source(
const Element &element,
328 const FVElementGeometry& fvGeometry,
329 const ElementVolumeVariables& elemVolVars,
330 const SubControlVolume &scv)
const
333 return asImp_().sourceAtPos(scv.center());
353 return NumEqVector(0.0);
391 const Element &element,
392 const FVElementGeometry& fvGeometry,
393 const ElementVolumeVariables& elemVolVars,
394 const SubControlVolume &scv)
const
416 const GlobalPosition &globalPos)
const {}
422 template<
class MatrixBlock>
424 const Element& element,
425 const FVElementGeometry& fvGeometry,
426 const VolumeVariables& volVars,
427 const SubControlVolume& scv)
const {}
436 const FVElementGeometry& fvGeometry,
437 const ElementVolumeVariables& elemVolVars,
438 const SubControlVolume &scv)
const
441 auto scvIdx = scv.indexInElement();
442 auto key = std::make_pair(gridGeometry_->elementMapper().index(element), scvIdx);
443 if (pointSourceMap_.count(key))
447 auto pointSources = pointSourceMap_.at(key);
452 const auto volume = scv.volume()*elemVolVars[scv].extrusionFactor();
486 pointSourceMap_.clear();
489 std::vector<PointSource> sources;
490 asImp_().addPointSources(sources);
493 if (!sources.empty())
496 PointSourceHelper::computePointSourceMap(*gridGeometry_,
506 {
return pointSourceMap_; }
515 applyInitialSolutionImpl_(sol, std::integral_constant<bool, isBox>());
525 template<
class Entity>
526 PrimaryVariables
initial(
const Entity& entity)
const
528 static_assert(int(Entity::codimension) == 0 || int(Entity::codimension) == dim,
"Entity must be element or vertex");
529 return asImp_().initialAtPos(entity.geometry().center());
541 DUNE_THROW(Dune::InvalidStateException,
542 "The problem does not provide "
543 "an initial() or an initialAtPos() method.");
555 template<
class ElementSolution>
557 const SubControlVolume& scv,
558 const ElementSolution& elemSol)
const
561 return asImp_().extrusionFactorAtPos(scv.center());
583 [[deprecated(
"Use gridGeometry() instead. fvGridGeometry() will be removed after 3.1!")]]
589 {
return *gridGeometry_; }
593 {
return paramGroup_; }
598 {
return *
static_cast<Implementation *
>(
this); }
602 {
return *
static_cast<const Implementation *
>(
this); }
608 void applyInitialSolutionImpl_(SolutionVector& sol, std::true_type)
const
610 const auto numDofs = gridGeometry_->vertexMapper().size();
611 const auto numVert = gridGeometry_->gridView().size(dim);
616 if (numDofs != numVert)
618 std::vector<bool> dofVisited(numDofs,
false);
619 for (
const auto& element : elements(gridGeometry_->gridView()))
621 for (
int i = 0; i < element.subEntities(dim); ++i)
623 const auto dofIdxGlobal = gridGeometry_->vertexMapper().subIndex(element, i, dim);
626 if (!dofVisited[dofIdxGlobal])
628 sol[dofIdxGlobal] =
asImp_().initial(element.template subEntity<dim>(i));
629 dofVisited[dofIdxGlobal] =
true;
638 for (
const auto& vertex : vertices(gridGeometry_->gridView()))
640 const auto dofIdxGlobal = gridGeometry_->vertexMapper().index(vertex);
641 sol[dofIdxGlobal] =
asImp_().initial(vertex);
649 void applyInitialSolutionImpl_(SolutionVector& sol, std::false_type)
const
651 sol.resize(gridGeometry_->numDofs());
652 for (
const auto& element : elements(gridGeometry_->gridView()))
654 const auto dofIdxGlobal = gridGeometry_->elementMapper().index(element);
655 sol[dofIdxGlobal] =
asImp_().initial(element);
660 std::shared_ptr<const GridGeometry> gridGeometry_;
663 std::string paramGroup_;
666 std::string problemName_;
669 PointSourceMap pointSourceMap_;
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
Base class for all finite-volume problems.
Definition: common/fvproblem.hh:50
void computePointSourceMap()
Compute the point source map, i.e. which scvs have point source contributions.
Definition: common/fvproblem.hh:483
const std::string & name() const
The problem name.
Definition: common/fvproblem.hh:113
NumEqVector scvPointSources(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Adds contribution of point sources for a specific sub control volume to the values....
Definition: common/fvproblem.hh:435
const std::string & paramGroup() const
The parameter group in which to retrieve runtime parameters.
Definition: common/fvproblem.hh:592
NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a neumann boundary segment.
Definition: common/fvproblem.hh:302
void setName(const std::string &newName)
Set the problem name.
Definition: common/fvproblem.hh:127
PrimaryVariables initial(const Entity &entity) const
Evaluate the initial value for an element (for cell-centered models) or vertex (for box / vertex-cent...
Definition: common/fvproblem.hh:526
NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: common/fvproblem.hh:349
const Implementation & asImp_() const
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:601
PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:219
Scalar extrusionFactor(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol) const
Return how much the domain is extruded at a given sub-control volume.
Definition: common/fvproblem.hh:556
FVProblem(std::shared_ptr< const GridGeometry > gridGeometry, const std::string ¶mGroup="")
Constructor.
Definition: common/fvproblem.hh:98
void applyInitialSolution(SolutionVector &sol) const
Applies the initial solution for all degrees of freedom of the grid.
Definition: common/fvproblem.hh:512
void addPointSources(std::vector< PointSource > &pointSources) const
Applies a vector of point sources. The point sources are possibly solution dependent.
Definition: common/fvproblem.hh:369
PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
Evaluate the boundary conditions for a dirichlet control volume face.
Definition: common/fvproblem.hh:198
NumEqVector source(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: common/fvproblem.hh:327
void addSourceDerivatives(MatrixBlock &block, const Element &element, const FVElementGeometry &fvGeometry, const VolumeVariables &volVars, const SubControlVolume &scv) const
Add source term derivative to the Jacobian.
Definition: common/fvproblem.hh:423
BoundaryTypes boundaryTypes(const Element &element, const SubControlVolumeFace &scvf) const
Specifies which kind of boundary condition should be used for which equation on a given boundary segm...
Definition: common/fvproblem.hh:162
const PointSourceMap & pointSourceMap() const
Get the point source map. It stores the point sources per scv.
Definition: common/fvproblem.hh:505
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvproblem.hh:588
Implementation & asImp_()
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:597
PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:238
BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
Specifies which kind of boundary condition should be used for which equation on a given boundary segm...
Definition: common/fvproblem.hh:179
void pointSourceAtPos(PointSource &pointSource, const GlobalPosition &globalPos) const
Evaluate the point sources (added by addPointSources) for all phases within a given sub-control-volum...
Definition: common/fvproblem.hh:415
void pointSource(PointSource &source, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Evaluate the point sources (added by addPointSources) for all phases within a given sub-control-volum...
Definition: common/fvproblem.hh:390
NumEqVector neumann(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Evaluate the boundary conditions for a neumann boundary segment.
Definition: common/fvproblem.hh:283
const GridGeometry & fvGridGeometry() const
The finite volume grid geometry.
Definition: common/fvproblem.hh:584
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
Evaluate the initial value for a control volume.
Definition: common/fvproblem.hh:537
static constexpr bool enableInternalDirichletConstraints()
If internal Dirichlet contraints are enabled Enables / disables internal (non-boundary) Dirichlet con...
Definition: common/fvproblem.hh:264
Scalar extrusionFactorAtPos(const GlobalPosition &globalPos) const
Return how much the domain is extruded at a given position.
Definition: common/fvproblem.hh:573
BoundaryTypes boundaryTypes(const Element &element, const SubControlVolume &scv) const
Specifies which kind of boundary condition should be used for which equation on a given boundary segm...
Definition: common/fvproblem.hh:144
export traits of this problem
Definition: common/fvproblem.hh:86
FVProblem::PrimaryVariables PrimaryVariables
Definition: common/fvproblem.hh:88
FVProblem::BoundaryTypes BoundaryTypes
Definition: common/fvproblem.hh:90
FVProblem::Scalar Scalar
Definition: common/fvproblem.hh:87
FVProblem::NumEqVector NumEqVector
Definition: common/fvproblem.hh:89
Declares all properties used in Dumux.