version 3.8
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_NONEQUILIBRIUM_GRID_VARIABLES_HH
14#define DUMUX_NONEQUILIBRIUM_GRID_VARIABLES_HH
15
16#include <memory>
17#include <dune/common/fvector.hh>
18#include <dune/grid/common/partitionset.hh>
19
25
26namespace Dumux {
27
33template<class TypeTag>
35: public FVGridVariables<GetPropType<TypeTag, Properties::GridGeometry>,
36 GetPropType<TypeTag, Properties::GridVolumeVariables>,
37 GetPropType<TypeTag, Properties::GridFluxVariablesCache>>
38{
43
45
46 static constexpr auto dim = ParentType::GridGeometry::GridView::dimension; // Grid and world dimension
47 static constexpr auto dimWorld = ParentType::GridGeometry::GridView::dimensionworld;
48 static constexpr int numPhases = ParentType::VolumeVariables::numFluidPhases();
49 static constexpr bool isBox = ParentType::GridGeometry::discMethod == DiscretizationMethods::box;
50
51public:
53 using typename ParentType::Scalar;
54 using typename ParentType::GridGeometry;
55
57 template<class Problem>
58 NonEquilibriumGridVariables(std::shared_ptr<Problem> problem,
59 std::shared_ptr<const GridGeometry> gridGeometry)
60 : ParentType(problem, gridGeometry)
61 {
62 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
63 velocityNorm_[phaseIdx].assign(gridGeometry->numDofs(), 0.0);
64
65 velocityBackend_ = std::make_unique<VelocityBackend>(*this);
66 }
67
68 template<class SolutionVector>
69 void calcVelocityAverage(const SolutionVector& curSol)
70 {
71 using Scalar = typename SolutionVector::field_type;
72 using VelocityVector = typename Dune::FieldVector<Scalar, dimWorld>;
73
74 std::array<std::vector<VelocityVector>, numPhases> velocity;
75
76 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
77 {
78 if(isBox && dim == 1)
79 velocity[phaseIdx].resize(this->gridGeometry_->gridView().size(0));
80 else
81 velocity[phaseIdx].resize(this->gridGeometry_->numDofs());
82 }
83
84 auto fvGeometry = localView(*this->gridGeometry_);
85 auto elemVolVars = localView(this->curGridVolVars());
86 auto elemFluxVarsCache = localView(this->gridFluxVarsCache());
87
88 for (const auto& element : elements(this->gridGeometry_->gridView(), Dune::Partitions::interior))
89 {
90 const auto eIdxGlobal = this->gridGeometry_->elementMapper().index(element);
91 fvGeometry.bind(element);
92 elemVolVars.bind(element, fvGeometry, curSol);
93 elemFluxVarsCache.bind(element, fvGeometry, elemVolVars);
94
95 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
96 {
97 velocityBackend_->calculateVelocity(velocity[phaseIdx], element, fvGeometry, elemVolVars, elemFluxVarsCache, phaseIdx);
98
99 for (auto&& scv : scvs(fvGeometry))
100 {
101 const auto dofIdxGlobal = scv.dofIndex();
102 if (isBox && dim == 1)
103 velocityNorm_[phaseIdx][dofIdxGlobal] = velocity[phaseIdx][eIdxGlobal].two_norm();
104 else
105 velocityNorm_[phaseIdx][dofIdxGlobal] = velocity[phaseIdx][dofIdxGlobal].two_norm();
106 }
107 } //end phases
108 } //end elements
109 } // end calcVelocity
110
117 const Scalar volumeDarcyMagVelocity(const unsigned int phaseIdx,
118 const unsigned int dofIdxGlobal) const
119 { return velocityNorm_[phaseIdx][dofIdxGlobal]; }
120
121private:
122 std::array<std::vector<Dune::FieldVector<Scalar, 1> > , numPhases> velocityNorm_;
123 std::unique_ptr<VelocityBackend> velocityBackend_;
124};
125
126} // end namespace Dumux
127
128#endif
The grid variable class for finite volume schemes storing variables on scv and scvf (volume and flux ...
Definition: discretization/fvgridvariables.hh:30
GetPropType< TypeTag, Properties::GridGeometry > GridGeometry
export type of the finite volume grid geometry
Definition: discretization/fvgridvariables.hh:33
std::decay_t< decltype(std::declval< PrimaryVariables >()[0])> Scalar
export scalar type (TODO get it directly from the volvars)
Definition: discretization/fvgridvariables.hh:45
This class stores the velocities which are used to compute Reynolds numbers for the source terms of n...
Definition: porousmediumflow/nonequilibrium/gridvariables.hh:38
void calcVelocityAverage(const SolutionVector &curSol)
Definition: porousmediumflow/nonequilibrium/gridvariables.hh:69
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:117
NonEquilibriumGridVariables(std::shared_ptr< Problem > problem, std::shared_ptr< const GridGeometry > gridGeometry)
Constructor.
Definition: porousmediumflow/nonequilibrium/gridvariables.hh:58
Velocity computation for implicit (porous media) models.
Definition: velocity.hh:59
Defines all properties used in Dumux.
The grid variable class for finite volume schemes, storing variables on scv and scvf (volume and flux...
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
The available discretization methods in Dumux.
void assign(To &to, const From &from)
Definition: nonlinear/newtonsolver.hh:130
constexpr Box box
Definition: method.hh:147
Definition: adapt.hh:17
Base class for the flux variables in porous medium models.
Velocity computation for implicit (porous media) models.