3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_COMMON_FV_PROBLEM_HH
25#define DUMUX_COMMON_FV_PROBLEM_HH
26
27#include <memory>
28#include <map>
29
30#include <dune/common/fvector.hh>
31#include <dune/grid/common/gridenums.hh>
32
38
40
41namespace Dumux {
42
52template<class TypeTag>
54{
55 using Implementation = GetPropType<TypeTag, Properties::Problem>;
56
58 using FVElementGeometry = typename GridGeometry::LocalView;
59 using GridView = typename GridGeometry::GridView;
60 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
61 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
62 using Extrusion = Extrusion_t<GridGeometry>;
63 using Element = typename GridView::template Codim<0>::Entity;
64 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
65
66 enum { dim = GridView::dimension };
67
70 using PointSourceMap = std::map< std::pair<std::size_t, std::size_t>,
71 std::vector<PointSource> >;
72
73 static constexpr bool isBox = GridGeometry::discMethod == DiscretizationMethod::box;
74 static constexpr bool isStaggered = GridGeometry::discMethod == DiscretizationMethod::staggered;
75
79 using BoundaryTypes = Dumux::BoundaryTypes<PrimaryVariables::size()>;
80
81public:
83 struct Traits
84 {
85 using Scalar = FVProblem::Scalar;
86 using PrimaryVariables = FVProblem::PrimaryVariables;
87 using NumEqVector = FVProblem::NumEqVector;
88 };
89
95 FVProblem(std::shared_ptr<const GridGeometry> gridGeometry, const std::string& paramGroup = "")
96 : gridGeometry_(gridGeometry)
97 , paramGroup_(paramGroup)
98 {
99 // set a default name for the problem
100 problemName_ = getParamFromGroup<std::string>(paramGroup, "Problem.Name");
101 }
102
110 const std::string& name() const
111 {
112 return problemName_;
113 }
114
124 void setName(const std::string& newName)
125 {
126 problemName_ = newName;
127 }
128
132 // \{
133
141 auto boundaryTypes(const Element &element,
142 const SubControlVolume &scv) const
143 {
144 if (!isBox)
145 DUNE_THROW(Dune::InvalidStateException,
146 "boundaryTypes(..., scv) called for cell-centered method.");
147
148 // forward it to the method which only takes the global coordinate
149 return asImp_().boundaryTypesAtPos(scv.dofPosition());
150 }
151
159 auto boundaryTypes(const Element &element,
160 const SubControlVolumeFace &scvf) const
161 {
162 if (isBox)
163 DUNE_THROW(Dune::InvalidStateException,
164 "boundaryTypes(..., scvf) called for box method.");
165
166 // forward it to the method which only takes the global coordinate
167 return asImp_().boundaryTypesAtPos(scvf.ipGlobal());
168 }
169
176 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
177 {
180 BoundaryTypes bcTypes;
181 bcTypes.setAllDirichlet();
182 return bcTypes;
183 }
184
193 PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
194 {
195 // forward it to the method which only takes the global coordinate
196 if (isBox)
197 {
198 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scvf) called for box method.");
199 }
200 else
201 return asImp_().dirichletAtPos(scvf.ipGlobal());
202 }
203
212 PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
213 {
214 // forward it to the method which only takes the global coordinate
215 if (!isBox && !isStaggered)
216 {
217 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scv) called for other than box or staggered method.");
218 }
219 else
220 return asImp_().dirichletAtPos(scv.dofPosition());
221 }
222
231 PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
232 {
233 // Throw an exception (there is no reasonable default value
234 // for Dirichlet conditions)
235 DUNE_THROW(Dune::InvalidStateException,
236 "The problem specifies that some boundary "
237 "segments are dirichlet, but does not provide "
238 "a dirichlet() or a dirichletAtPos() method.");
239 }
240
258 { return false; }
259
276 template<class ElementVolumeVariables, class ElementFluxVariablesCache>
277 NumEqVector neumann(const Element& element,
278 const FVElementGeometry& fvGeometry,
279 const ElementVolumeVariables& elemVolVars,
280 const ElementFluxVariablesCache& elemFluxVarsCache,
281 const SubControlVolumeFace& scvf) const
282 {
283 // forward it to the interface with only the global position
284 return asImp_().neumannAtPos(scvf.ipGlobal());
285 }
286
296 NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
297 {
300 return NumEqVector(0.0);
301 }
302
321 template<class ElementVolumeVariables>
322 NumEqVector source(const Element &element,
323 const FVElementGeometry& fvGeometry,
324 const ElementVolumeVariables& elemVolVars,
325 const SubControlVolume &scv) const
326 {
327 // forward to solution independent, fully-implicit specific interface
328 return asImp_().sourceAtPos(scv.center());
329 }
330
344 NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
345 {
348 return NumEqVector(0.0);
349 }
350
364 void addPointSources(std::vector<PointSource>& pointSources) const {}
365
385 template<class ElementVolumeVariables>
386 void pointSource(PointSource& source,
387 const Element &element,
388 const FVElementGeometry& fvGeometry,
389 const ElementVolumeVariables& elemVolVars,
390 const SubControlVolume &scv) const
391 {
392 // forward to space dependent interface method
393 asImp_().pointSourceAtPos(source, source.position());
394 }
395
411 void pointSourceAtPos(PointSource& pointSource,
412 const GlobalPosition &globalPos) const {}
413
418 template<class MatrixBlock, class VolumeVariables>
419 void addSourceDerivatives(MatrixBlock& block,
420 const Element& element,
421 const FVElementGeometry& fvGeometry,
422 const VolumeVariables& volVars,
423 const SubControlVolume& scv) const {}
424
431 template<class ElementVolumeVariables>
432 NumEqVector scvPointSources(const Element &element,
433 const FVElementGeometry& fvGeometry,
434 const ElementVolumeVariables& elemVolVars,
435 const SubControlVolume &scv) const
436 {
437 NumEqVector source(0);
438 auto scvIdx = scv.indexInElement();
439 auto key = std::make_pair(gridGeometry_->elementMapper().index(element), scvIdx);
440 if (pointSourceMap_.count(key))
441 {
442 // Add the contributions to the dof source values
443 // We divide by the volume. In the local residual this will be multiplied with the same
444 // factor again. That's because the user specifies absolute values in kg/s.
445 const auto volume = Extrusion::volume(scv)*elemVolVars[scv].extrusionFactor();
446
447 for (const auto& ps : pointSourceMap_.at(key))
448 {
449 // we make a copy of the local point source here
450 auto pointSource = ps;
451
452 // Note: two concepts are implemented here. The PointSource property can be set to a
453 // customized point source function achieving variable point sources,
454 // see TimeDependentPointSource for an example. The second imitated the standard
455 // dumux source interface with solDependentPointSource / pointSourceAtPos, methods
456 // that can be overloaded in the actual problem class also achieving variable point sources.
457 // The first one is more convenient for simple function like a time dependent source.
458 // The second one might be more convenient for e.g. a solution dependent point source.
459
460 // we do an update e.g. used for TimeDependentPointSource
461 pointSource.update(asImp_(), element, fvGeometry, elemVolVars, scv);
462 // call convienience problem interface function
463 asImp_().pointSource(pointSource, element, fvGeometry, elemVolVars, scv);
464 // at last take care about multiplying with the correct volume
465 pointSource /= volume*pointSource.embeddings();
466 // add the point source values to the local residual
467 source += pointSource.values();
468 }
469 }
470
471 return source;
472 }
473
480 {
481 // clear the given point source maps in case it's not empty
482 pointSourceMap_.clear();
483
484 // get and apply point sources if any given in the problem
485 std::vector<PointSource> sources;
486 asImp_().addPointSources(sources);
487
488 // if there are point sources calculate point source locations and save them in a map
489 if (!sources.empty())
490 PointSourceHelper::computePointSourceMap(*gridGeometry_, sources, pointSourceMap_, paramGroup());
491 }
492
496 const PointSourceMap& pointSourceMap() const
497 { return pointSourceMap_; }
498
503 template<class SolutionVector>
504 void applyInitialSolution(SolutionVector& sol) const
505 {
507 }
508
516 template<class Entity>
517 PrimaryVariables initial(const Entity& entity) const
518 {
519 static_assert(int(Entity::codimension) == 0 || int(Entity::codimension) == dim, "Entity must be element or vertex");
520 return asImp_().initialAtPos(entity.geometry().center());
521 }
522
528 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
529 {
530 // Throw an exception (there is no reasonable default value
531 // for initial values)
532 DUNE_THROW(Dune::InvalidStateException,
533 "The problem does not provide "
534 "an initial() or an initialAtPos() method.");
535 }
536
546 template<class ElementSolution>
547 Scalar extrusionFactor(const Element& element,
548 const SubControlVolume& scv,
549 const ElementSolution& elemSol) const
550 {
551 // forward to generic interface
552 return asImp_().extrusionFactorAtPos(scv.center());
553 }
554
564 Scalar extrusionFactorAtPos(const GlobalPosition &globalPos) const
565 {
566 // As a default, i.e. if the user's problem does not overload
567 // any extrusion factor method, return 1.0
568 return 1.0;
569 }
570
571 // \}
572
574 const GridGeometry& gridGeometry() const
575 { return *gridGeometry_; }
576
578 const std::string& paramGroup() const
579 { return paramGroup_; }
580
581protected:
583 Implementation &asImp_()
584 { return *static_cast<Implementation *>(this); }
585
587 const Implementation &asImp_() const
588 { return *static_cast<const Implementation *>(this); }
589
590private:
592 std::shared_ptr<const GridGeometry> gridGeometry_;
593
595 std::string paramGroup_;
596
598 std::string problemName_;
599
601 PointSourceMap pointSourceMap_;
602};
603
604} // end namespace Dumux
605
606#endif
Function to create initial solution vectors.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
Helper classes to compute the integration elements.
Definition: adapt.hh:29
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:177
void assembleInitialSolution(SolutionVector &sol, const Problem &problem)
Definition: initialsolution.hh:40
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
Class to specify the type of a boundary.
Definition: common/boundarytypes.hh:38
void setAllDirichlet()
Set all boundary conditions to Dirichlet.
Definition: common/boundarytypes.hh:111
Base class for all finite-volume problems.
Definition: common/fvproblem.hh:54
void computePointSourceMap()
Compute the point source map, i.e. which scvs have point source contributions.
Definition: common/fvproblem.hh:479
const std::string & name() const
The problem name.
Definition: common/fvproblem.hh:110
const std::string & paramGroup() const
The parameter group in which to retrieve runtime parameters.
Definition: common/fvproblem.hh:578
void applyInitialSolution(SolutionVector &sol) const
Applies the initial solution for all degrees of freedom of the grid.
Definition: common/fvproblem.hh:504
NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a neumann boundary segment.
Definition: common/fvproblem.hh:296
void setName(const std::string &newName)
Set the problem name.
Definition: common/fvproblem.hh:124
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:517
NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: common/fvproblem.hh:344
const Implementation & asImp_() const
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:587
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:419
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:277
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:159
PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:212
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:547
FVProblem(std::shared_ptr< const GridGeometry > gridGeometry, const std::string &paramGroup="")
Constructor.
Definition: common/fvproblem.hh:95
void addPointSources(std::vector< PointSource > &pointSources) const
Applies a vector of point sources. The point sources are possibly solution dependent.
Definition: common/fvproblem.hh:364
PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
Evaluate the boundary conditions for a dirichlet control volume face.
Definition: common/fvproblem.hh:193
const PointSourceMap & pointSourceMap() const
Get the point source map. It stores the point sources per scv.
Definition: common/fvproblem.hh:496
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvproblem.hh:574
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:141
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:322
Implementation & asImp_()
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:583
PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:231
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:176
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:411
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:386
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
Evaluate the initial value for a control volume.
Definition: common/fvproblem.hh:528
static constexpr bool enableInternalDirichletConstraints()
If internal Dirichlet contraints are enabled Enables / disables internal (non-boundary) Dirichlet con...
Definition: common/fvproblem.hh:257
Scalar extrusionFactorAtPos(const GlobalPosition &globalPos) const
Return how much the domain is extruded at a given position.
Definition: common/fvproblem.hh:564
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:432
export traits of this problem
Definition: common/fvproblem.hh:84
FVProblem::PrimaryVariables PrimaryVariables
Definition: common/fvproblem.hh:86
FVProblem::Scalar Scalar
Definition: common/fvproblem.hh:85
FVProblem::NumEqVector NumEqVector
Definition: common/fvproblem.hh:87
Class to specify the type of a boundary.
Declares all properties used in Dumux.