3.6-git
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
39
41
42namespace Dumux {
43
53template<class TypeTag>
55{
56 using Implementation = GetPropType<TypeTag, Properties::Problem>;
57
59 using FVElementGeometry = typename GridGeometry::LocalView;
60 using GridView = typename GridGeometry::GridView;
61 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
62 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
63 using Extrusion = Extrusion_t<GridGeometry>;
64 using Element = typename GridView::template Codim<0>::Entity;
65 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
66
67 enum { dim = GridView::dimension };
68
71 using PointSourceMap = std::map< std::pair<std::size_t, std::size_t>,
72 std::vector<PointSource> >;
73
74 static constexpr bool isBox = GridGeometry::discMethod == DiscretizationMethods::box;
75 static constexpr bool isPQ1Bubble = GridGeometry::discMethod == DiscretizationMethods::pq1bubble;
76 static constexpr bool isStaggered = GridGeometry::discMethod == DiscretizationMethods::staggered;
77
81 using BoundaryTypes = Dumux::BoundaryTypes<PrimaryVariables::size()>;
82
83public:
85 struct Traits
86 {
87 using Scalar = FVProblem::Scalar;
88 using PrimaryVariables = FVProblem::PrimaryVariables;
89 using NumEqVector = FVProblem::NumEqVector;
90 };
91
97 FVProblem(std::shared_ptr<const GridGeometry> gridGeometry, const std::string& paramGroup = "")
98 : gridGeometry_(gridGeometry)
99 , paramGroup_(paramGroup)
100 {
101 // set a default name for the problem
102 problemName_ = getParamFromGroup<std::string>(paramGroup, "Problem.Name");
103 }
104
112 const std::string& name() const
113 {
114 return problemName_;
115 }
116
126 void setName(const std::string& newName)
127 {
128 problemName_ = newName;
129 }
130
134 // \{
135
143 auto boundaryTypes(const Element &element,
144 const SubControlVolume &scv) const
145 {
146 if (!isBox && !isPQ1Bubble)
147 DUNE_THROW(Dune::InvalidStateException,
148 "boundaryTypes(..., scv) called for cell-centered method.");
149
150 // forward it to the method which only takes the global coordinate
151 return asImp_().boundaryTypesAtPos(scv.dofPosition());
152 }
153
161 auto boundaryTypes(const Element &element,
162 const SubControlVolumeFace &scvf) const
163 {
164 if (isBox || isPQ1Bubble)
165 DUNE_THROW(Dune::InvalidStateException,
166 "boundaryTypes(..., scvf) called for box method.");
167
168 // forward it to the method which only takes the global coordinate
169 return asImp_().boundaryTypesAtPos(scvf.ipGlobal());
170 }
171
178 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
179 {
182 BoundaryTypes bcTypes;
183 bcTypes.setAllDirichlet();
184 return bcTypes;
185 }
186
195 PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
196 {
197 // forward it to the method which only takes the global coordinate
198 if (isBox || isPQ1Bubble)
199 {
200 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scvf) called for box method.");
201 }
202 else
203 return asImp_().dirichletAtPos(scvf.ipGlobal());
204 }
205
214 PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
215 {
216 // forward it to the method which only takes the global coordinate
217 if (!isBox && !isStaggered && !isPQ1Bubble)
218 {
219 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scv) called for other than box or staggered method.");
220 }
221 else
222 return asImp_().dirichletAtPos(scv.dofPosition());
223 }
224
233 PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
234 {
235 // Throw an exception (there is no reasonable default value
236 // for Dirichlet conditions)
237 DUNE_THROW(Dune::InvalidStateException,
238 "The problem specifies that some boundary "
239 "segments are dirichlet, but does not provide "
240 "a dirichlet() or a dirichletAtPos() method.");
241 }
242
260 { return false; }
261
278 template<class ElementVolumeVariables, class ElementFluxVariablesCache>
279 NumEqVector neumann(const Element& element,
280 const FVElementGeometry& fvGeometry,
281 const ElementVolumeVariables& elemVolVars,
282 const ElementFluxVariablesCache& elemFluxVarsCache,
283 const SubControlVolumeFace& scvf) const
284 {
285 // forward it to the interface with only the global position
286 return asImp_().neumannAtPos(scvf.ipGlobal());
287 }
288
298 NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
299 {
302 return NumEqVector(0.0);
303 }
304
323 template<class ElementVolumeVariables>
324 NumEqVector source(const Element &element,
325 const FVElementGeometry& fvGeometry,
326 const ElementVolumeVariables& elemVolVars,
327 const SubControlVolume &scv) const
328 {
329 // forward to solution independent, fully-implicit specific interface
330 return asImp_().sourceAtPos(scv.center());
331 }
332
346 NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
347 {
350 return NumEqVector(0.0);
351 }
352
366 void addPointSources(std::vector<PointSource>& pointSources) const {}
367
387 template<class ElementVolumeVariables>
388 void pointSource(PointSource& source,
389 const Element &element,
390 const FVElementGeometry& fvGeometry,
391 const ElementVolumeVariables& elemVolVars,
392 const SubControlVolume &scv) const
393 {
394 // forward to space dependent interface method
395 asImp_().pointSourceAtPos(source, source.position());
396 }
397
413 void pointSourceAtPos(PointSource& pointSource,
414 const GlobalPosition &globalPos) const {}
415
420 template<class MatrixBlock, class VolumeVariables>
421 void addSourceDerivatives(MatrixBlock& block,
422 const Element& element,
423 const FVElementGeometry& fvGeometry,
424 const VolumeVariables& volVars,
425 const SubControlVolume& scv) const {}
426
433 template<class ElementVolumeVariables>
434 NumEqVector scvPointSources(const Element &element,
435 const FVElementGeometry& fvGeometry,
436 const ElementVolumeVariables& elemVolVars,
437 const SubControlVolume &scv) const
438 {
439 NumEqVector source(0);
440 auto scvIdx = scv.indexInElement();
441 auto key = std::make_pair(gridGeometry_->elementMapper().index(element), scvIdx);
442 if (pointSourceMap_.count(key))
443 {
444 // Add the contributions to the dof source values
445 // We divide by the volume. In the local residual this will be multiplied with the same
446 // factor again. That's because the user specifies absolute values in kg/s.
447 const auto volume = Extrusion::volume(fvGeometry, scv)*elemVolVars[scv].extrusionFactor();
448
449 for (const auto& ps : pointSourceMap_.at(key))
450 {
451 // we make a copy of the local point source here
452 auto pointSource = ps;
453
454 // Note: two concepts are implemented here. The PointSource property can be set to a
455 // customized point source function achieving variable point sources,
456 // see TimeDependentPointSource for an example. The second imitated the standard
457 // dumux source interface with solDependentPointSource / pointSourceAtPos, methods
458 // that can be overloaded in the actual problem class also achieving variable point sources.
459 // The first one is more convenient for simple function like a time dependent source.
460 // The second one might be more convenient for e.g. a solution dependent point source.
461
462 // we do an update e.g. used for TimeDependentPointSource
463 pointSource.update(asImp_(), element, fvGeometry, elemVolVars, scv);
464 // call convenience problem interface function
465 asImp_().pointSource(pointSource, element, fvGeometry, elemVolVars, scv);
466 // at last take care about multiplying with the correct volume
467 pointSource /= volume*pointSource.embeddings();
468 // add the point source values to the local residual
469 source += pointSource.values();
470 }
471 }
472
473 return source;
474 }
475
482 {
483 // clear the given point source maps in case it's not empty
484 pointSourceMap_.clear();
485
486 // get and apply point sources if any given in the problem
487 std::vector<PointSource> sources;
488 asImp_().addPointSources(sources);
489
490 // if there are point sources calculate point source locations and save them in a map
491 if (!sources.empty())
492 PointSourceHelper::computePointSourceMap(*gridGeometry_, sources, pointSourceMap_, paramGroup());
493 }
494
498 const PointSourceMap& pointSourceMap() const
499 { return pointSourceMap_; }
500
505 template<class SolutionVector>
506 void applyInitialSolution(SolutionVector& sol) const
507 {
509 }
510
518 template<class Entity>
519 PrimaryVariables initial(const Entity& entity) const
520 {
521 static_assert(int(Entity::codimension) == 0 || int(Entity::codimension) == dim, "Entity must be element or vertex");
522 return asImp_().initialAtPos(entity.geometry().center());
523 }
524
530 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
531 {
532 // Throw an exception (there is no reasonable default value
533 // for initial values)
534 DUNE_THROW(Dune::InvalidStateException,
535 "The problem does not provide "
536 "an initial() or an initialAtPos() method.");
537 }
538
540 const GridGeometry& gridGeometry() const
541 { return *gridGeometry_; }
542
544 const std::string& paramGroup() const
545 { return paramGroup_; }
546
547protected:
549 Implementation &asImp_()
550 { return *static_cast<Implementation *>(this); }
551
553 const Implementation &asImp_() const
554 { return *static_cast<const Implementation *>(this); }
555
556private:
558 std::shared_ptr<const GridGeometry> gridGeometry_;
559
561 std::string paramGroup_;
562
564 std::string problemName_;
565
567 PointSourceMap pointSourceMap_;
568};
569
570} // end namespace Dumux
571
572#endif
Function to create initial solution vectors.
A helper to deduce a vector with the same size as numbers of equations.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Helper classes to compute the integration elements.
The available discretization methods in Dumux.
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:171
void assembleInitialSolution(SolutionVector &sol, const Problem &problem)
Set a solution vector to the initial solution provided by the problem.
Definition: initialsolution.hh:39
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:46
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:251
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:180
constexpr Box box
Definition: method.hh:136
constexpr Staggered staggered
Definition: method.hh:138
constexpr PQ1Bubble pq1bubble
Definition: method.hh:137
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:55
void computePointSourceMap()
Compute the point source map, i.e. which scvs have point source contributions.
Definition: common/fvproblem.hh:481
const std::string & name() const
The problem name.
Definition: common/fvproblem.hh:112
const std::string & paramGroup() const
The parameter group in which to retrieve runtime parameters.
Definition: common/fvproblem.hh:544
void applyInitialSolution(SolutionVector &sol) const
Applies the initial solution for all degrees of freedom of the grid.
Definition: common/fvproblem.hh:506
NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a neumann boundary segment.
Definition: common/fvproblem.hh:298
void setName(const std::string &newName)
Set the problem name.
Definition: common/fvproblem.hh:126
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:519
NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: common/fvproblem.hh:346
const Implementation & asImp_() const
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:553
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:421
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:279
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:161
PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:214
FVProblem(std::shared_ptr< const GridGeometry > gridGeometry, const std::string &paramGroup="")
Constructor.
Definition: common/fvproblem.hh:97
void addPointSources(std::vector< PointSource > &pointSources) const
Applies a vector of point sources. The point sources are possibly solution dependent.
Definition: common/fvproblem.hh:366
PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
Evaluate the boundary conditions for a dirichlet control volume face.
Definition: common/fvproblem.hh:195
const PointSourceMap & pointSourceMap() const
Get the point source map. It stores the point sources per scv.
Definition: common/fvproblem.hh:498
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvproblem.hh:540
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:143
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:324
Implementation & asImp_()
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:549
PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:233
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:178
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:413
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:388
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
Evaluate the initial value for a control volume.
Definition: common/fvproblem.hh:530
static constexpr bool enableInternalDirichletConstraints()
If internal Dirichlet constraints are enabled Enables / disables internal (non-boundary) Dirichlet co...
Definition: common/fvproblem.hh:259
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:434
export traits of this problem
Definition: common/fvproblem.hh:86
FVProblem::PrimaryVariables PrimaryVariables
Definition: common/fvproblem.hh:88
FVProblem::Scalar Scalar
Definition: common/fvproblem.hh:87
FVProblem::NumEqVector NumEqVector
Definition: common/fvproblem.hh:89
Class to specify the type of a boundary.
Declares all properties used in Dumux.