version 3.10-dev
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", "sim");
90 }
91
99 const std::string& name() const
100 {
101 return problemName_;
102 }
103
109 void setName(const std::string& newName)
110 {
111 problemName_ = newName;
112 }
113
117 // \{
118
126 auto boundaryTypes(const Element &element,
127 const SubControlVolume &scv) const
128 {
129 if (!isCVFE)
130 DUNE_THROW(Dune::InvalidStateException,
131 "boundaryTypes(..., scv) called for non-CVFE method.");
132
133 // forward it to the method which only takes the global coordinate
134 return asImp_().boundaryTypesAtPos(scv.dofPosition());
135 }
136
144 auto boundaryTypes(const Element &element,
145 const SubControlVolumeFace &scvf) const
146 {
147 if (isCVFE)
148 DUNE_THROW(Dune::InvalidStateException,
149 "boundaryTypes(..., scvf) called for CVFE method.");
150
151 // forward it to the method which only takes the global coordinate
152 return asImp_().boundaryTypesAtPos(scvf.ipGlobal());
153 }
154
161 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
162 {
165 BoundaryTypes bcTypes;
166 bcTypes.setAllDirichlet();
167 return bcTypes;
168 }
169
178 PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
179 {
180 // forward it to the method which only takes the global coordinate
181 if (isCVFE)
182 {
183 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scvf) called for CVFE method.");
184 }
185 else
186 return asImp_().dirichletAtPos(scvf.ipGlobal());
187 }
188
197 PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
198 {
199 // forward it to the method which only takes the global coordinate
200 if (!isCVFE && !isStaggered)
201 {
202 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scv) called for other than CVFE or staggered method.");
203 }
204 else
205 return asImp_().dirichletAtPos(scv.dofPosition());
206 }
207
216 PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
217 {
218 // Throw an exception (there is no reasonable default value
219 // for Dirichlet conditions)
220 DUNE_THROW(Dune::InvalidStateException,
221 "The problem specifies that some boundary "
222 "segments are dirichlet, but does not provide "
223 "a dirichlet() or a dirichletAtPos() method.");
224 }
225
243 { return false; }
244
261 template<class ElementVolumeVariables, class ElementFluxVariablesCache>
262 NumEqVector neumann(const Element& element,
263 const FVElementGeometry& fvGeometry,
264 const ElementVolumeVariables& elemVolVars,
265 const ElementFluxVariablesCache& elemFluxVarsCache,
266 const SubControlVolumeFace& scvf) const
267 {
268 // forward it to the interface with only the global position
269 return asImp_().neumannAtPos(scvf.ipGlobal());
270 }
271
281 NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
282 {
285 return NumEqVector(0.0);
286 }
287
306 template<class ElementVolumeVariables>
307 NumEqVector source(const Element &element,
308 const FVElementGeometry& fvGeometry,
309 const ElementVolumeVariables& elemVolVars,
310 const SubControlVolume &scv) const
311 {
312 // forward to solution independent, fully-implicit specific interface
313 return asImp_().sourceAtPos(scv.center());
314 }
315
329 NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
330 {
333 return NumEqVector(0.0);
334 }
335
349 void addPointSources(std::vector<PointSource>& pointSources) const {}
350
370 template<class ElementVolumeVariables>
371 void pointSource(PointSource& source,
372 const Element &element,
373 const FVElementGeometry& fvGeometry,
374 const ElementVolumeVariables& elemVolVars,
375 const SubControlVolume &scv) const
376 {
377 // forward to space dependent interface method
378 asImp_().pointSourceAtPos(source, source.position());
379 }
380
396 void pointSourceAtPos(PointSource& pointSource,
397 const GlobalPosition &globalPos) const {}
398
403 template<class MatrixBlock, class VolumeVariables>
404 void addSourceDerivatives(MatrixBlock& block,
405 const Element& element,
406 const FVElementGeometry& fvGeometry,
407 const VolumeVariables& volVars,
408 const SubControlVolume& scv) const {}
409
416 template<class ElementVolumeVariables>
417 NumEqVector scvPointSources(const Element &element,
418 const FVElementGeometry& fvGeometry,
419 const ElementVolumeVariables& elemVolVars,
420 const SubControlVolume &scv) const
421 {
422 NumEqVector source(0);
423 auto scvIdx = scv.indexInElement();
424 auto key = std::make_pair(gridGeometry_->elementMapper().index(element), scvIdx);
425 if (pointSourceMap_.count(key))
426 {
427 // Add the contributions to the dof source values
428 // We divide by the volume. In the local residual this will be multiplied with the same
429 // factor again. That's because the user specifies absolute values in kg/s.
430 const auto volume = Extrusion::volume(fvGeometry, scv)*elemVolVars[scv].extrusionFactor();
431
432 for (const auto& ps : pointSourceMap_.at(key))
433 {
434 // we make a copy of the local point source here
435 auto pointSource = ps;
436
437 // Note: two concepts are implemented here. The PointSource property can be set to a
438 // customized point source function achieving variable point sources,
439 // see TimeDependentPointSource for an example. The second imitated the standard
440 // dumux source interface with solDependentPointSource / pointSourceAtPos, methods
441 // that can be overloaded in the actual problem class also achieving variable point sources.
442 // The first one is more convenient for simple function like a time dependent source.
443 // The second one might be more convenient for e.g. a solution dependent point source.
444
445 // we do an update e.g. used for TimeDependentPointSource
446 pointSource.update(asImp_(), element, fvGeometry, elemVolVars, scv);
447 // call convenience problem interface function
448 asImp_().pointSource(pointSource, element, fvGeometry, elemVolVars, scv);
449 // at last take care about multiplying with the correct volume
450 pointSource /= volume*pointSource.embeddings();
451 // add the point source values to the local residual
452 source += pointSource.values();
453 }
454 }
455
456 return source;
457 }
458
465 {
466 // clear the given point source maps in case it's not empty
467 pointSourceMap_.clear();
468
469 // get and apply point sources if any given in the problem
470 std::vector<PointSource> sources;
471 asImp_().addPointSources(sources);
472
473 // if there are point sources calculate point source locations and save them in a map
474 if (!sources.empty())
475 PointSourceHelper::computePointSourceMap(*gridGeometry_, sources, pointSourceMap_, paramGroup());
476 }
477
481 const PointSourceMap& pointSourceMap() const
482 { return pointSourceMap_; }
483
488 template<class SolutionVector>
489 void applyInitialSolution(SolutionVector& sol) const
490 {
492 }
493
499 template<class Entity>
500 PrimaryVariables initial(const Entity& entity) const
501 {
502 return asImp_().initialAtPos(entity.geometry().center());
503 }
504
510 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
511 {
512 // Throw an exception (there is no reasonable default value
513 // for initial values)
514 DUNE_THROW(Dune::InvalidStateException,
515 "The problem does not provide "
516 "an initial() or an initialAtPos() method.");
517 }
518
520 const GridGeometry& gridGeometry() const
521 { return *gridGeometry_; }
522
524 const std::string& paramGroup() const
525 { return paramGroup_; }
526
527protected:
529 Implementation &asImp_()
530 { return *static_cast<Implementation *>(this); }
531
533 const Implementation &asImp_() const
534 { return *static_cast<const Implementation *>(this); }
535
536private:
538 std::shared_ptr<const GridGeometry> gridGeometry_;
539
541 std::string paramGroup_;
542
544 std::string problemName_;
545
547 PointSourceMap pointSourceMap_;
548};
549
550} // end namespace Dumux
551
552#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:464
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:524
void applyInitialSolution(SolutionVector &sol) const
Applies the initial solution for all degrees of freedom of the grid.
Definition: common/fvproblem.hh:489
NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a neumann boundary segment.
Definition: common/fvproblem.hh:281
void setName(const std::string &newName)
Set the problem name.
Definition: common/fvproblem.hh:109
PrimaryVariables initial(const Entity &entity) const
Evaluate the initial value for a entity.
Definition: common/fvproblem.hh:500
NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: common/fvproblem.hh:329
const Implementation & asImp_() const
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:533
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:404
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:262
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:144
PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:197
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:349
PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
Evaluate the boundary conditions for a dirichlet control volume face.
Definition: common/fvproblem.hh:178
const PointSourceMap & pointSourceMap() const
Get the point source map. It stores the point sources per scv.
Definition: common/fvproblem.hh:481
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvproblem.hh:520
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:126
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:307
Implementation & asImp_()
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:529
PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:216
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:161
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:396
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:371
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
Evaluate the initial value for a control volume.
Definition: common/fvproblem.hh:510
static constexpr bool enableInternalDirichletConstraints()
If internal Dirichlet constraints are enabled Enables / disables internal (non-boundary) Dirichlet co...
Definition: common/fvproblem.hh:242
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:417
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