version 3.8
common/fvproblem.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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_COMMON_FV_PROBLEM_HH
13#define DUMUX_COMMON_FV_PROBLEM_HH
14
15#include <memory>
16#include <map>
17
18#include <dune/common/fvector.hh>
19#include <dune/grid/common/gridenums.hh>
20
27
29
30namespace Dumux {
31
41template<class TypeTag>
43{
44 using Implementation = GetPropType<TypeTag, Properties::Problem>;
45
47 using FVElementGeometry = typename GridGeometry::LocalView;
48 using GridView = typename GridGeometry::GridView;
49 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
50 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
51 using Extrusion = Extrusion_t<GridGeometry>;
52 using Element = typename GridView::template Codim<0>::Entity;
53 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
54
55 enum { dim = GridView::dimension };
56
59 using PointSourceMap = std::map< std::pair<std::size_t, std::size_t>,
60 std::vector<PointSource> >;
61
62 static constexpr bool isCVFE = DiscretizationMethods::isCVFE<typename GridGeometry::DiscretizationMethod>;
63 static constexpr bool isStaggered = GridGeometry::discMethod == DiscretizationMethods::staggered;
64
68 using BoundaryTypes = Dumux::BoundaryTypes<PrimaryVariables::size()>;
69
70public:
72 struct Traits
73 {
74 using Scalar = FVProblem::Scalar;
75 using PrimaryVariables = FVProblem::PrimaryVariables;
76 using NumEqVector = FVProblem::NumEqVector;
77 };
78
84 FVProblem(std::shared_ptr<const GridGeometry> gridGeometry, const std::string& paramGroup = "")
85 : gridGeometry_(gridGeometry)
86 , paramGroup_(paramGroup)
87 {
88 // set a default name for the problem
89 problemName_ = getParamFromGroup<std::string>(paramGroup, "Problem.Name");
90 }
91
99 const std::string& name() const
100 {
101 return problemName_;
102 }
103
113 void setName(const std::string& newName)
114 {
115 problemName_ = newName;
116 }
117
121 // \{
122
130 auto boundaryTypes(const Element &element,
131 const SubControlVolume &scv) const
132 {
133 if (!isCVFE)
134 DUNE_THROW(Dune::InvalidStateException,
135 "boundaryTypes(..., scv) called for non-CVFE method.");
136
137 // forward it to the method which only takes the global coordinate
138 return asImp_().boundaryTypesAtPos(scv.dofPosition());
139 }
140
148 auto boundaryTypes(const Element &element,
149 const SubControlVolumeFace &scvf) const
150 {
151 if (isCVFE)
152 DUNE_THROW(Dune::InvalidStateException,
153 "boundaryTypes(..., scvf) called for CVFE method.");
154
155 // forward it to the method which only takes the global coordinate
156 return asImp_().boundaryTypesAtPos(scvf.ipGlobal());
157 }
158
165 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
166 {
169 BoundaryTypes bcTypes;
170 bcTypes.setAllDirichlet();
171 return bcTypes;
172 }
173
182 PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
183 {
184 // forward it to the method which only takes the global coordinate
185 if (isCVFE)
186 {
187 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scvf) called for CVFE method.");
188 }
189 else
190 return asImp_().dirichletAtPos(scvf.ipGlobal());
191 }
192
201 PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
202 {
203 // forward it to the method which only takes the global coordinate
204 if (!isCVFE && !isStaggered)
205 {
206 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scv) called for other than CVFE or staggered method.");
207 }
208 else
209 return asImp_().dirichletAtPos(scv.dofPosition());
210 }
211
220 PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
221 {
222 // Throw an exception (there is no reasonable default value
223 // for Dirichlet conditions)
224 DUNE_THROW(Dune::InvalidStateException,
225 "The problem specifies that some boundary "
226 "segments are dirichlet, but does not provide "
227 "a dirichlet() or a dirichletAtPos() method.");
228 }
229
247 { return false; }
248
265 template<class ElementVolumeVariables, class ElementFluxVariablesCache>
266 NumEqVector neumann(const Element& element,
267 const FVElementGeometry& fvGeometry,
268 const ElementVolumeVariables& elemVolVars,
269 const ElementFluxVariablesCache& elemFluxVarsCache,
270 const SubControlVolumeFace& scvf) const
271 {
272 // forward it to the interface with only the global position
273 return asImp_().neumannAtPos(scvf.ipGlobal());
274 }
275
285 NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
286 {
289 return NumEqVector(0.0);
290 }
291
310 template<class ElementVolumeVariables>
311 NumEqVector source(const Element &element,
312 const FVElementGeometry& fvGeometry,
313 const ElementVolumeVariables& elemVolVars,
314 const SubControlVolume &scv) const
315 {
316 // forward to solution independent, fully-implicit specific interface
317 return asImp_().sourceAtPos(scv.center());
318 }
319
333 NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
334 {
337 return NumEqVector(0.0);
338 }
339
353 void addPointSources(std::vector<PointSource>& pointSources) const {}
354
374 template<class ElementVolumeVariables>
375 void pointSource(PointSource& source,
376 const Element &element,
377 const FVElementGeometry& fvGeometry,
378 const ElementVolumeVariables& elemVolVars,
379 const SubControlVolume &scv) const
380 {
381 // forward to space dependent interface method
382 asImp_().pointSourceAtPos(source, source.position());
383 }
384
400 void pointSourceAtPos(PointSource& pointSource,
401 const GlobalPosition &globalPos) const {}
402
407 template<class MatrixBlock, class VolumeVariables>
408 void addSourceDerivatives(MatrixBlock& block,
409 const Element& element,
410 const FVElementGeometry& fvGeometry,
411 const VolumeVariables& volVars,
412 const SubControlVolume& scv) const {}
413
420 template<class ElementVolumeVariables>
421 NumEqVector scvPointSources(const Element &element,
422 const FVElementGeometry& fvGeometry,
423 const ElementVolumeVariables& elemVolVars,
424 const SubControlVolume &scv) const
425 {
426 NumEqVector source(0);
427 auto scvIdx = scv.indexInElement();
428 auto key = std::make_pair(gridGeometry_->elementMapper().index(element), scvIdx);
429 if (pointSourceMap_.count(key))
430 {
431 // Add the contributions to the dof source values
432 // We divide by the volume. In the local residual this will be multiplied with the same
433 // factor again. That's because the user specifies absolute values in kg/s.
434 const auto volume = Extrusion::volume(fvGeometry, scv)*elemVolVars[scv].extrusionFactor();
435
436 for (const auto& ps : pointSourceMap_.at(key))
437 {
438 // we make a copy of the local point source here
439 auto pointSource = ps;
440
441 // Note: two concepts are implemented here. The PointSource property can be set to a
442 // customized point source function achieving variable point sources,
443 // see TimeDependentPointSource for an example. The second imitated the standard
444 // dumux source interface with solDependentPointSource / pointSourceAtPos, methods
445 // that can be overloaded in the actual problem class also achieving variable point sources.
446 // The first one is more convenient for simple function like a time dependent source.
447 // The second one might be more convenient for e.g. a solution dependent point source.
448
449 // we do an update e.g. used for TimeDependentPointSource
450 pointSource.update(asImp_(), element, fvGeometry, elemVolVars, scv);
451 // call convenience problem interface function
452 asImp_().pointSource(pointSource, element, fvGeometry, elemVolVars, scv);
453 // at last take care about multiplying with the correct volume
454 pointSource /= volume*pointSource.embeddings();
455 // add the point source values to the local residual
456 source += pointSource.values();
457 }
458 }
459
460 return source;
461 }
462
469 {
470 // clear the given point source maps in case it's not empty
471 pointSourceMap_.clear();
472
473 // get and apply point sources if any given in the problem
474 std::vector<PointSource> sources;
475 asImp_().addPointSources(sources);
476
477 // if there are point sources calculate point source locations and save them in a map
478 if (!sources.empty())
479 PointSourceHelper::computePointSourceMap(*gridGeometry_, sources, pointSourceMap_, paramGroup());
480 }
481
485 const PointSourceMap& pointSourceMap() const
486 { return pointSourceMap_; }
487
492 template<class SolutionVector>
493 void applyInitialSolution(SolutionVector& sol) const
494 {
496 }
497
503 template<class Entity>
504 PrimaryVariables initial(const Entity& entity) const
505 {
506 return asImp_().initialAtPos(entity.geometry().center());
507 }
508
514 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
515 {
516 // Throw an exception (there is no reasonable default value
517 // for initial values)
518 DUNE_THROW(Dune::InvalidStateException,
519 "The problem does not provide "
520 "an initial() or an initialAtPos() method.");
521 }
522
524 const GridGeometry& gridGeometry() const
525 { return *gridGeometry_; }
526
528 const std::string& paramGroup() const
529 { return paramGroup_; }
530
531protected:
533 Implementation &asImp_()
534 { return *static_cast<Implementation *>(this); }
535
537 const Implementation &asImp_() const
538 { return *static_cast<const Implementation *>(this); }
539
540private:
542 std::shared_ptr<const GridGeometry> gridGeometry_;
543
545 std::string paramGroup_;
546
548 std::string problemName_;
549
551 PointSourceMap pointSourceMap_;
552};
553
554} // end namespace Dumux
555
556#endif
Class to specify the type of a boundary.
Definition: common/boundarytypes.hh:26
void setAllDirichlet()
Set all boundary conditions to Dirichlet.
Definition: common/boundarytypes.hh:99
Base class for all finite-volume problems.
Definition: common/fvproblem.hh:43
void computePointSourceMap()
Compute the point source map, i.e. which scvs have point source contributions.
Definition: common/fvproblem.hh:468
const std::string & name() const
The problem name.
Definition: common/fvproblem.hh:99
const std::string & paramGroup() const
The parameter group in which to retrieve runtime parameters.
Definition: common/fvproblem.hh:528
void applyInitialSolution(SolutionVector &sol) const
Applies the initial solution for all degrees of freedom of the grid.
Definition: common/fvproblem.hh:493
NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a neumann boundary segment.
Definition: common/fvproblem.hh:285
void setName(const std::string &newName)
Set the problem name.
Definition: common/fvproblem.hh:113
PrimaryVariables initial(const Entity &entity) const
Evaluate the initial value for a entity.
Definition: common/fvproblem.hh:504
NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: common/fvproblem.hh:333
const Implementation & asImp_() const
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:537
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:408
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:266
auto 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:148
PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:201
FVProblem(std::shared_ptr< const GridGeometry > gridGeometry, const std::string &paramGroup="")
Constructor.
Definition: common/fvproblem.hh:84
void addPointSources(std::vector< PointSource > &pointSources) const
Applies a vector of point sources. The point sources are possibly solution dependent.
Definition: common/fvproblem.hh:353
PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
Evaluate the boundary conditions for a dirichlet control volume face.
Definition: common/fvproblem.hh:182
const PointSourceMap & pointSourceMap() const
Get the point source map. It stores the point sources per scv.
Definition: common/fvproblem.hh:485
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvproblem.hh:524
auto 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:130
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:311
Implementation & asImp_()
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:533
PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:220
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:165
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:400
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:375
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
Evaluate the initial value for a control volume.
Definition: common/fvproblem.hh:514
static constexpr bool enableInternalDirichletConstraints()
If internal Dirichlet constraints are enabled Enables / disables internal (non-boundary) Dirichlet co...
Definition: common/fvproblem.hh:246
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:421
Class to specify the type of a boundary.
Defines all properties used in Dumux.
Helper classes to compute the integration elements.
void assembleInitialSolution(SolutionVector &sol, const Problem &problem)
Set a solution vector to the initial solution provided by the problem.
Definition: initialsolution.hh:27
typename NumEqVectorTraits< PrimaryVariables >::type NumEqVector
A vector with the same size as numbers of equations This is the default implementation and has to be ...
Definition: numeqvector.hh:34
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:159
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
Function to create initial solution vectors.
The available discretization methods in Dumux.
constexpr Staggered staggered
Definition: method.hh:149
Definition: adapt.hh:17
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:166
A helper to deduce a vector with the same size as numbers of equations.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
export traits of this problem
Definition: common/fvproblem.hh:73
FVProblem::PrimaryVariables PrimaryVariables
Definition: common/fvproblem.hh:75
FVProblem::Scalar Scalar
Definition: common/fvproblem.hh:74
FVProblem::NumEqVector NumEqVector
Definition: common/fvproblem.hh:76