3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/nonequilibrium/gridvariables.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 *****************************************************************************/
25#ifndef DUMUX_NONEQUILIBRIUM_GRID_VARIABLES_HH
26#define DUMUX_NONEQUILIBRIUM_GRID_VARIABLES_HH
27
28#include <memory>
29#include <dune/common/fvector.hh>
30#include <dune/grid/common/partitionset.hh>
31
37
38namespace Dumux {
39
45template<class TypeTag>
47: public FVGridVariables<GetPropType<TypeTag, Properties::GridGeometry>,
48 GetPropType<TypeTag, Properties::GridVolumeVariables>,
49 GetPropType<TypeTag, Properties::GridFluxVariablesCache>>
50{
55
57
58 static constexpr auto dim = ParentType::GridGeometry::GridView::dimension; // Grid and world dimension
59 static constexpr auto dimWorld = ParentType::GridGeometry::GridView::dimensionworld;
60 static constexpr int numPhases = ParentType::VolumeVariables::numFluidPhases();
61 static constexpr bool isBox = ParentType::GridGeometry::discMethod == DiscretizationMethod::box;
62
63public:
65 using typename ParentType::Scalar;
66 using typename ParentType::GridGeometry;
67
69 template<class Problem>
70 NonEquilibriumGridVariables(std::shared_ptr<Problem> problem,
71 std::shared_ptr<const GridGeometry> gridGeometry)
72 : ParentType(problem, gridGeometry)
73 {
74 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
75 velocityNorm_[phaseIdx].assign(gridGeometry->numDofs(), 0.0);
76
77 velocityBackend_ = std::make_unique<VelocityBackend>(*this);
78 }
79
80 template<class SolutionVector>
81 void calcVelocityAverage(const SolutionVector& curSol)
82 {
83 using Scalar = typename SolutionVector::field_type;
84 using VelocityVector = typename Dune::FieldVector<Scalar, dimWorld>;
85
86 std::array<std::vector<VelocityVector>, numPhases> velocity;
87
88 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
89 {
90 if(isBox && dim == 1)
91 velocity[phaseIdx].resize(this->gridGeometry_->gridView().size(0));
92 else
93 velocity[phaseIdx].resize(this->gridGeometry_->numDofs());
94 }
95 for (const auto& element : elements(this->gridGeometry_->gridView(), Dune::Partitions::interior))
96 {
97 const auto eIdxGlobal = this->gridGeometry_->elementMapper().index(element);
98
99 auto fvGeometry = localView(*this->gridGeometry_);
100 auto elemVolVars = localView(this->curGridVolVars());
101 auto elemFluxVarsCache = localView(this->gridFluxVarsCache());
102
103 fvGeometry.bind(element);
104 elemVolVars.bind(element, fvGeometry, curSol);
105 elemFluxVarsCache.bind(element, fvGeometry, elemVolVars);
106
107 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
108 {
109 velocityBackend_->calculateVelocity(velocity[phaseIdx], element, fvGeometry, elemVolVars, elemFluxVarsCache, phaseIdx);
110
111 for (auto&& scv : scvs(fvGeometry))
112 {
113 const auto dofIdxGlobal = scv.dofIndex();
114 if (isBox && dim == 1)
115 velocityNorm_[phaseIdx][dofIdxGlobal] = velocity[phaseIdx][eIdxGlobal].two_norm();
116 else
117 velocityNorm_[phaseIdx][dofIdxGlobal] = velocity[phaseIdx][dofIdxGlobal].two_norm();
118 }
119 } //end phases
120 } //end elements
121 } // end calcVelocity
122
129 const Scalar volumeDarcyMagVelocity(const unsigned int phaseIdx,
130 const unsigned int dofIdxGlobal) const
131 { return velocityNorm_[phaseIdx][dofIdxGlobal]; }
132
133private:
134 std::array<std::vector<Dune::FieldVector<Scalar, 1> > , numPhases> velocityNorm_;
135 std::unique_ptr<VelocityBackend> velocityBackend_;
136};
137
138} // end namespace Dumux
139
140#endif
The available discretization methods in Dumux.
Velocity computation for implicit (porous media) models.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
Definition: adapt.hh:29
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
void assign(To &to, const From &from)
Definition: nonlinear/newtonsolver.hh:134
The grid variable class for finite volume schemes storing variables on scv and scvf (volume and flux ...
Definition: discretization/fvgridvariables.hh:42
GetPropType< TypeTag, Properties::GridGeometry > GridGeometry
export type of the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:45
std::decay_t< decltype(std::declval< PrimaryVariables >()[0])> Scalar
export scalar type (TODO get it directly from the volvars)
Definition: discretization/fvgridvariables.hh:57
This class stores the velocities which are used to compute Reynolds numbers for the source terms of n...
Definition: porousmediumflow/nonequilibrium/gridvariables.hh:50
void calcVelocityAverage(const SolutionVector &curSol)
Definition: porousmediumflow/nonequilibrium/gridvariables.hh:81
const Scalar volumeDarcyMagVelocity(const unsigned int phaseIdx, const unsigned int dofIdxGlobal) const
Access to the averaged (magnitude of) velocity for each vertex.
Definition: porousmediumflow/nonequilibrium/gridvariables.hh:129
NonEquilibriumGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry)
Constructor.
Definition: porousmediumflow/nonequilibrium/gridvariables.hh:70
Velocity computation for implicit (porous media) models.
Definition: velocity.hh:69
Declares all properties used in Dumux.
The grid variable class for finite volume schemes storing variables on scv and scvf (volume and flux ...
Base class for the flux variables in porous medium models.