3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porenetwork/common/velocityoutput.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_PNM_VELOCITYOUTPUT_HH
25#define DUMUX_PNM_VELOCITYOUTPUT_HH
26
27#include <string>
29
30namespace Dumux::PoreNetwork {
31
36template<class GridVariables, class FluxVariables>
37class VelocityOutput : public Dumux::VelocityOutput<GridVariables>
38{
40 using Scalar = typename GridVariables::Scalar;
41 using GridGeometry = typename GridVariables::GridGeometry;
42 using ElementVolumeVariables = typename GridVariables::GridVolumeVariables::LocalView;
43 using VolumeVariables = typename GridVariables::VolumeVariables;
44 using FluidSystem = typename VolumeVariables::FluidSystem;
45 using ElementFluxVariablesCache = typename GridVariables::GridFluxVariablesCache::LocalView;
46 using FVElementGeometry = typename GridGeometry::LocalView;
47 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
48 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
49
50public:
53
55 std::string phaseName(int phaseIdx) const override { return FluidSystem::phaseName(phaseIdx); }
56
58 int numFluidPhases() const override { return VolumeVariables::numFluidPhases(); }
59
61 VelocityOutput(const GridVariables& gridVariables)
62 : gridVariables_(gridVariables)
63 {
64 velocityOutput_ = getParamFromGroup<bool>(problem_().paramGroup(), "Vtk.AddVelocity");
65 }
66
68 bool enableOutput() const override
69 { return velocityOutput_; }
70
74 const Element& element,
75 const FVElementGeometry& fvGeometry,
76 const ElementVolumeVariables& elemVolVars,
77 const ElementFluxVariablesCache& elemFluxVarsCache,
78 int phaseIdx) const override
79 {
80 if (!velocityOutput_)
81 return;
82
83 const auto geometry = element.geometry();
84
85 auto tmpVelocity = (geometry.corner(1) - geometry.corner(0));
86 tmpVelocity /= tmpVelocity.two_norm();
87
88 const auto eIdxGlobal = fvGeometry.gridGeometry().elementMapper().index(element);
89 velocity[eIdxGlobal] = 0.0;
90
91 for (auto&& scvf : scvfs(fvGeometry))
92 {
93 if (scvf.boundary())
94 continue;
95
96 // get the volume flux divided by the area of the
97 // subcontrolvolume face in the reference element
98 // TODO: Divide by extrusion factor!!?
99 const Scalar flux = getFlux_(element, fvGeometry, scvf, elemVolVars, elemFluxVarsCache, phaseIdx);
100
101 tmpVelocity *= flux;
102 velocity[eIdxGlobal] = tmpVelocity;
103 }
104 }
105
106private:
107
108 Scalar getFlux_(const Element& element,
109 const FVElementGeometry& fvGeometry,
110 const SubControlVolumeFace& scvf,
111 const ElementVolumeVariables& elemVolVars,
112 const ElementFluxVariablesCache& elemFluxVarsCache,
113 const int phaseIdx) const
114 {
115 const Scalar localArea = elemFluxVarsCache[scvf].throatCrossSectionalArea(phaseIdx);
116
117 // make sure the phase is actually present (2p)
118 if (localArea > 0.0)
119 {
120 // instantiate the flux variables
121 FluxVariables fluxVars;
122 fluxVars.init(problem_(), element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
123
124 // the upwind term to be used for the volume flux evaluation
125 auto upwindTerm = [phaseIdx](const auto& volVars) { return volVars.mobility(phaseIdx); };
126 return fluxVars.advectiveFlux(phaseIdx, upwindTerm) / localArea;
127 }
128 else
129 return 0.0;
130 }
131
132 const auto& problem_() const { return gridVariables_.curGridVolVars().problem(); }
133
134 bool velocityOutput_;
135
136 const GridVariables& gridVariables_;
137};
138
139} // end namespace Dumux::PoreNetwork
140
141#endif
Definition: discretization/porenetwork/fvelementgeometry.hh:34
Velocity output for implicit (porous media) models.
Definition: io/velocityoutput.hh:41
std::vector< Dune::FieldVector< Scalar, dimWorld > > VelocityVector
Definition: io/velocityoutput.hh:50
Velocity output for pore-network models.
Definition: porenetwork/common/velocityoutput.hh:38
std::string phaseName(int phaseIdx) const override
Returns the phase name of a given phase index.
Definition: porenetwork/common/velocityoutput.hh:55
void calculateVelocity(VelocityVector &velocity, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, int phaseIdx) const override
Definition: porenetwork/common/velocityoutput.hh:73
int numFluidPhases() const override
Returns the number of phases.
Definition: porenetwork/common/velocityoutput.hh:58
bool enableOutput() const override
Returns true if velocity output is enabled.
Definition: porenetwork/common/velocityoutput.hh:68
VelocityOutput(const GridVariables &gridVariables)
Constructor.
Definition: porenetwork/common/velocityoutput.hh:61
Default velocity output policy for porous media models.