3.5-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 isStaggered = GridGeometry::discMethod == DiscretizationMethods::staggered;
76
80 using BoundaryTypes = Dumux::BoundaryTypes<PrimaryVariables::size()>;
81
82public:
84 struct Traits
85 {
86 using Scalar = FVProblem::Scalar;
87 using PrimaryVariables = FVProblem::PrimaryVariables;
88 using NumEqVector = FVProblem::NumEqVector;
89 };
90
96 FVProblem(std::shared_ptr<const GridGeometry> gridGeometry, const std::string& paramGroup = "")
97 : gridGeometry_(gridGeometry)
98 , paramGroup_(paramGroup)
99 {
100 // set a default name for the problem
101 problemName_ = getParamFromGroup<std::string>(paramGroup, "Problem.Name");
102 }
103
111 const std::string& name() const
112 {
113 return problemName_;
114 }
115
125 void setName(const std::string& newName)
126 {
127 problemName_ = newName;
128 }
129
133 // \{
134
142 auto boundaryTypes(const Element &element,
143 const SubControlVolume &scv) const
144 {
145 if (!isBox)
146 DUNE_THROW(Dune::InvalidStateException,
147 "boundaryTypes(..., scv) called for cell-centered method.");
148
149 // forward it to the method which only takes the global coordinate
150 return asImp_().boundaryTypesAtPos(scv.dofPosition());
151 }
152
160 auto boundaryTypes(const Element &element,
161 const SubControlVolumeFace &scvf) const
162 {
163 if (isBox)
164 DUNE_THROW(Dune::InvalidStateException,
165 "boundaryTypes(..., scvf) called for box method.");
166
167 // forward it to the method which only takes the global coordinate
168 return asImp_().boundaryTypesAtPos(scvf.ipGlobal());
169 }
170
177 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
178 {
181 BoundaryTypes bcTypes;
182 bcTypes.setAllDirichlet();
183 return bcTypes;
184 }
185
194 PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
195 {
196 // forward it to the method which only takes the global coordinate
197 if (isBox)
198 {
199 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scvf) called for box method.");
200 }
201 else
202 return asImp_().dirichletAtPos(scvf.ipGlobal());
203 }
204
213 PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
214 {
215 // forward it to the method which only takes the global coordinate
216 if (!isBox && !isStaggered)
217 {
218 DUNE_THROW(Dune::InvalidStateException, "dirichlet(scv) called for other than box or staggered method.");
219 }
220 else
221 return asImp_().dirichletAtPos(scv.dofPosition());
222 }
223
232 PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
233 {
234 // Throw an exception (there is no reasonable default value
235 // for Dirichlet conditions)
236 DUNE_THROW(Dune::InvalidStateException,
237 "The problem specifies that some boundary "
238 "segments are dirichlet, but does not provide "
239 "a dirichlet() or a dirichletAtPos() method.");
240 }
241
259 { return false; }
260
277 template<class ElementVolumeVariables, class ElementFluxVariablesCache>
278 NumEqVector neumann(const Element& element,
279 const FVElementGeometry& fvGeometry,
280 const ElementVolumeVariables& elemVolVars,
281 const ElementFluxVariablesCache& elemFluxVarsCache,
282 const SubControlVolumeFace& scvf) const
283 {
284 // forward it to the interface with only the global position
285 return asImp_().neumannAtPos(scvf.ipGlobal());
286 }
287
297 NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
298 {
301 return NumEqVector(0.0);
302 }
303
322 template<class ElementVolumeVariables>
323 NumEqVector source(const Element &element,
324 const FVElementGeometry& fvGeometry,
325 const ElementVolumeVariables& elemVolVars,
326 const SubControlVolume &scv) const
327 {
328 // forward to solution independent, fully-implicit specific interface
329 return asImp_().sourceAtPos(scv.center());
330 }
331
345 NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
346 {
349 return NumEqVector(0.0);
350 }
351
365 void addPointSources(std::vector<PointSource>& pointSources) const {}
366
386 template<class ElementVolumeVariables>
387 void pointSource(PointSource& source,
388 const Element &element,
389 const FVElementGeometry& fvGeometry,
390 const ElementVolumeVariables& elemVolVars,
391 const SubControlVolume &scv) const
392 {
393 // forward to space dependent interface method
394 asImp_().pointSourceAtPos(source, source.position());
395 }
396
412 void pointSourceAtPos(PointSource& pointSource,
413 const GlobalPosition &globalPos) const {}
414
419 template<class MatrixBlock, class VolumeVariables>
420 void addSourceDerivatives(MatrixBlock& block,
421 const Element& element,
422 const FVElementGeometry& fvGeometry,
423 const VolumeVariables& volVars,
424 const SubControlVolume& scv) const {}
425
432 template<class ElementVolumeVariables>
433 NumEqVector scvPointSources(const Element &element,
434 const FVElementGeometry& fvGeometry,
435 const ElementVolumeVariables& elemVolVars,
436 const SubControlVolume &scv) const
437 {
438 NumEqVector source(0);
439 auto scvIdx = scv.indexInElement();
440 auto key = std::make_pair(gridGeometry_->elementMapper().index(element), scvIdx);
441 if (pointSourceMap_.count(key))
442 {
443 // Add the contributions to the dof source values
444 // We divide by the volume. In the local residual this will be multiplied with the same
445 // factor again. That's because the user specifies absolute values in kg/s.
446 const auto volume = Extrusion::volume(scv)*elemVolVars[scv].extrusionFactor();
447
448 for (const auto& ps : pointSourceMap_.at(key))
449 {
450 // we make a copy of the local point source here
451 auto pointSource = ps;
452
453 // Note: two concepts are implemented here. The PointSource property can be set to a
454 // customized point source function achieving variable point sources,
455 // see TimeDependentPointSource for an example. The second imitated the standard
456 // dumux source interface with solDependentPointSource / pointSourceAtPos, methods
457 // that can be overloaded in the actual problem class also achieving variable point sources.
458 // The first one is more convenient for simple function like a time dependent source.
459 // The second one might be more convenient for e.g. a solution dependent point source.
460
461 // we do an update e.g. used for TimeDependentPointSource
462 pointSource.update(asImp_(), element, fvGeometry, elemVolVars, scv);
463 // call convienience problem interface function
464 asImp_().pointSource(pointSource, element, fvGeometry, elemVolVars, scv);
465 // at last take care about multiplying with the correct volume
466 pointSource /= volume*pointSource.embeddings();
467 // add the point source values to the local residual
468 source += pointSource.values();
469 }
470 }
471
472 return source;
473 }
474
481 {
482 // clear the given point source maps in case it's not empty
483 pointSourceMap_.clear();
484
485 // get and apply point sources if any given in the problem
486 std::vector<PointSource> sources;
487 asImp_().addPointSources(sources);
488
489 // if there are point sources calculate point source locations and save them in a map
490 if (!sources.empty())
491 PointSourceHelper::computePointSourceMap(*gridGeometry_, sources, pointSourceMap_, paramGroup());
492 }
493
497 const PointSourceMap& pointSourceMap() const
498 { return pointSourceMap_; }
499
504 template<class SolutionVector>
505 void applyInitialSolution(SolutionVector& sol) const
506 {
508 }
509
517 template<class Entity>
518 PrimaryVariables initial(const Entity& entity) const
519 {
520 static_assert(int(Entity::codimension) == 0 || int(Entity::codimension) == dim, "Entity must be element or vertex");
521 return asImp_().initialAtPos(entity.geometry().center());
522 }
523
529 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
530 {
531 // Throw an exception (there is no reasonable default value
532 // for initial values)
533 DUNE_THROW(Dune::InvalidStateException,
534 "The problem does not provide "
535 "an initial() or an initialAtPos() method.");
536 }
537
549 template<class ElementSolution>
550 [[deprecated("extrusionFactor() should now be defined in the spatial params. This interface will be removed after 3.5.")]]
551 Scalar extrusionFactor(const Element& element,
552 const SubControlVolume& scv,
553 const ElementSolution& elemSol,
554 double defaultValue = 1.0) const
555 {
556 // forward to generic interface
557 return asImp_().extrusionFactorAtPos(scv.center());
558 }
559
571 [[deprecated("extrusionFactorAtPos() should now be defined in the spatial params. This interface will be removed after 3.5.")]]
572 Scalar extrusionFactorAtPos(const GlobalPosition &globalPos, double defaultValue = 1.0) const
573 {
574 // As a default, i.e. if the user's problem does not overload
575 // any extrusion factor method, return 1.0
576 return 1.0;
577 }
578
579 // \}
580
582 const GridGeometry& gridGeometry() const
583 { return *gridGeometry_; }
584
586 const std::string& paramGroup() const
587 { return paramGroup_; }
588
589protected:
591 Implementation &asImp_()
592 { return *static_cast<Implementation *>(this); }
593
595 const Implementation &asImp_() const
596 { return *static_cast<const Implementation *>(this); }
597
598private:
600 std::shared_ptr<const GridGeometry> gridGeometry_;
601
603 std::string paramGroup_;
604
606 std::string problemName_;
607
609 PointSourceMap pointSourceMap_;
610};
611
612} // end namespace Dumux
613
614#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.
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
Definition: adapt.hh:29
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:177
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:150
constexpr Box box
Definition: method.hh:139
constexpr Staggered staggered
Definition: method.hh:140
Scalar volume(Shape shape, Scalar inscribedRadius)
Returns the volume of a given geometry based on the inscribed radius.
Definition: poreproperties.hh:73
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:480
const std::string & name() const
The problem name.
Definition: common/fvproblem.hh:111
const std::string & paramGroup() const
The parameter group in which to retrieve runtime parameters.
Definition: common/fvproblem.hh:586
void applyInitialSolution(SolutionVector &sol) const
Applies the initial solution for all degrees of freedom of the grid.
Definition: common/fvproblem.hh:505
NumEqVector neumannAtPos(const GlobalPosition &globalPos) const
Evaluate the boundary conditions for a neumann boundary segment.
Definition: common/fvproblem.hh:297
void setName(const std::string &newName)
Set the problem name.
Definition: common/fvproblem.hh:125
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:518
NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: common/fvproblem.hh:345
const Implementation & asImp_() const
Returns the implementation of the problem (i.e. static polymorphism)
Definition: common/fvproblem.hh:595
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:420
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:278
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:160
PrimaryVariables dirichlet(const Element &element, const SubControlVolume &scv) const
Evaluate the boundary conditions for a dirichlet control volume.
Definition: common/fvproblem.hh:213
Scalar extrusionFactorAtPos(const GlobalPosition &globalPos, double defaultValue=1.0) const
Return how much the domain is extruded at a given position.
Definition: common/fvproblem.hh:572
FVProblem(std::shared_ptr< const GridGeometry > gridGeometry, const std::string &paramGroup="")
Constructor.
Definition: common/fvproblem.hh:96
void addPointSources(std::vector< PointSource > &pointSources) const
Applies a vector of point sources. The point sources are possibly solution dependent.
Definition: common/fvproblem.hh:365
PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
Evaluate the boundary conditions for a dirichlet control volume face.
Definition: common/fvproblem.hh:194
const PointSourceMap & pointSourceMap() const
Get the point source map. It stores the point sources per scv.
Definition: common/fvproblem.hh:497
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition: common/fvproblem.hh:582
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:142
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:323
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:232
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:177
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:412
Scalar extrusionFactor(const Element &element, const SubControlVolume &scv, const ElementSolution &elemSol, double defaultValue=1.0) const
Return how much the domain is extruded at a given sub-control volume.
Definition: common/fvproblem.hh:551
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:387
PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
Evaluate the initial value for a control volume.
Definition: common/fvproblem.hh:529
static constexpr bool enableInternalDirichletConstraints()
If internal Dirichlet contraints are enabled Enables / disables internal (non-boundary) Dirichlet con...
Definition: common/fvproblem.hh:258
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:433
export traits of this problem
Definition: common/fvproblem.hh:85
FVProblem::PrimaryVariables PrimaryVariables
Definition: common/fvproblem.hh:87
FVProblem::Scalar Scalar
Definition: common/fvproblem.hh:86
FVProblem::NumEqVector NumEqVector
Definition: common/fvproblem.hh:88
Class to specify the type of a boundary.
Declares all properties used in Dumux.