25#ifndef DUMUX_PNM_UTILITES_HH
26#define DUMUX_PNM_UTILITES_HH
38template<
class Gr
idVariables,
class SolutionVector>
41 using Scalar =
typename GridVariables::VolumeVariables::PrimaryVariables::value_type;
42 using VolumeVariables =
typename GridVariables::VolumeVariables;
44 struct AveragedQuantityInfo
46 std::function<Scalar(
const VolumeVariables&)> quantity;
47 std::function<Scalar(
const VolumeVariables&)> weight;
54 const SolutionVector& sol)
55 : gridVariables_(gridVariables)
60 std::function<Scalar(
const VolumeVariables&)>&& w,
61 const std::string& name)
63 averagedQuantityInfo_.push_back(AveragedQuantityInfo{q, w, name});
64 averagedQuantity_.push_back(Scalar());
67 void eval(
const std::vector<std::size_t>& dofsToNeglect = std::vector<std::size_t>())
69 for (
auto& q : averagedQuantity_)
72 std::vector<bool> poreVisited(problem_().gridGeometry().numDofs(),
false);
73 std::vector<Scalar> weights(averagedQuantityInfo_.size(), 0.0);
75 auto fvGeometry =
localView(problem_().gridGeometry());
76 auto elemVolVars =
localView(gridVariables_.curGridVolVars());
78 for (
const auto& element : elements(problem_().gridGeometry().gridView()))
80 fvGeometry.bind(element);
81 elemVolVars.bind(element, fvGeometry, sol_);
83 for (
int scvIdx = 0; scvIdx < fvGeometry.numScv(); ++scvIdx)
85 static constexpr auto dofCodim = std::decay_t<
decltype(problem_().gridGeometry().gridView())>::dimension;
86 const int dofIdxGlobal = problem_().gridGeometry().vertexMapper().subIndex(element, scvIdx, dofCodim);
88 if (poreVisited[dofIdxGlobal])
90 else if (!dofsToNeglect.empty() && std::any_of(dofsToNeglect.begin(), dofsToNeglect.end(), [&](
int dofIdx){ return dofIdx == dofIdxGlobal; }))
94 const auto& volVars = elemVolVars[scvIdx];
95 for (
int i = 0; i < averagedQuantityInfo_.size(); ++i)
97 const Scalar weight = averagedQuantityInfo_[i].weight(volVars);
98 averagedQuantity_[i] += averagedQuantityInfo_[i].quantity(volVars) * weight;
101 poreVisited[dofIdxGlobal] =
true;
106 for (
int i = 0; i < averagedQuantityInfo_.size(); ++i)
107 averagedQuantity_[i] /= weights[i];
112 for (
int i = 0; i < averagedQuantityInfo_.size(); ++i)
113 if (averagedQuantityInfo_[i].name == name)
114 return averagedQuantity_[i];
116 DUNE_THROW(Dune::InvalidStateException, name +
" not found");
121 std::vector<AveragedQuantityInfo> averagedQuantityInfo_;
122 std::vector<Scalar> averagedQuantity_;
124 const auto& problem_()
125 {
return gridVariables_.curGridVolVars().problem(); }
127 const GridVariables& gridVariables_;
128 const SolutionVector& sol_;
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
Definition: discretization/porenetwork/fvelementgeometry.hh:34
Calculates averaged values of the network solution.
Definition: utilities.hh:40
AveragedValues(const GridVariables &gridVariables, const SolutionVector &sol)
Definition: utilities.hh:53
void addAveragedQuantity(std::function< Scalar(const VolumeVariables &)> &&q, std::function< Scalar(const VolumeVariables &)> &&w, const std::string &name)
Definition: utilities.hh:59
void eval(const std::vector< std::size_t > &dofsToNeglect=std::vector< std::size_t >())
Definition: utilities.hh:67
const Scalar & operator[](const std::string &name) const
Definition: utilities.hh:110