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))
448 const auto volume = scv.volume()*elemVolVars[scv].extrusionFactor();
450 for (
const auto& ps : pointSourceMap_.at(key))
485 pointSourceMap_.clear();
488 std::vector<PointSource> sources;
489 asImp_().addPointSources(sources);
492 if (!sources.empty())
495 PointSourceHelper::computePointSourceMap(*gridGeometry_,
505 {
return pointSourceMap_; }
514 applyInitialSolutionImpl_(sol, std::integral_constant<bool, isBox>());
524 template<
class Entity>
525 PrimaryVariables
initial(
const Entity& entity)
const
527 static_assert(int(Entity::codimension) == 0 || int(Entity::codimension) == dim,
"Entity must be element or vertex");
528 return asImp_().initialAtPos(entity.geometry().center());
540 DUNE_THROW(Dune::InvalidStateException,
541 "The problem does not provide "
542 "an initial() or an initialAtPos() method.");
554 template<
class ElementSolution>
556 const SubControlVolume& scv,
557 const ElementSolution& elemSol)
const
560 return asImp_().extrusionFactorAtPos(scv.center());
583 {
return *gridGeometry_; }
587 {
return paramGroup_; }
592 {
return *
static_cast<Implementation *
>(
this); }
596 {
return *
static_cast<const Implementation *
>(
this); }
602 void applyInitialSolutionImpl_(SolutionVector& sol, std::true_type)
const
604 const auto numDofs = gridGeometry_->vertexMapper().size();
605 const auto numVert = gridGeometry_->gridView().size(dim);
610 if (numDofs != numVert)
612 std::vector<bool> dofVisited(numDofs,
false);
613 for (
const auto& element : elements(gridGeometry_->gridView()))
615 for (
int i = 0; i < element.subEntities(dim); ++i)
617 const auto dofIdxGlobal = gridGeometry_->vertexMapper().subIndex(element, i, dim);
620 if (!dofVisited[dofIdxGlobal])
622 sol[dofIdxGlobal] =
asImp_().initial(element.template subEntity<dim>(i));
623 dofVisited[dofIdxGlobal] =
true;
632 for (
const auto& vertex : vertices(gridGeometry_->gridView()))
634 const auto dofIdxGlobal = gridGeometry_->vertexMapper().index(vertex);
635 sol[dofIdxGlobal] =
asImp_().initial(vertex);
643 void applyInitialSolutionImpl_(SolutionVector& sol, std::false_type)
const
645 sol.resize(gridGeometry_->numDofs());
646 for (
const auto& element : elements(gridGeometry_->gridView()))
648 const auto dofIdxGlobal = gridGeometry_->elementMapper().index(element);
649 sol[dofIdxGlobal] =
asImp_().initial(element);
654 std::shared_ptr<const GridGeometry> gridGeometry_;
657 std::string paramGroup_;
660 std::string problemName_;
663 PointSourceMap pointSourceMap_;
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
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:482
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:586
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:525
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:595
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:555
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:511
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:504
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvproblem.hh:582
Implementation & asImp_()
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:591
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
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
Evaluate the initial value for a control volume.
Definition: common/fvproblem.hh:536
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:572
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.