version 3.11-dev
Loading...
Searching...
No Matches
facecentered/staggered/elementvolumevariables.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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_FACECENTERED_ELEMENTVOLUMEVARIABLES_HH
13#define DUMUX_DISCRETIZATION_FACECENTERED_ELEMENTVOLUMEVARIABLES_HH
14
15#include <algorithm>
16#include <cassert>
17#include <vector>
18#include <utility>
19
22
23namespace Dumux {
24
29template<class GridVolumeVariables, bool cachingEnabled>
31
36template<class GVV>
37class FaceCenteredStaggeredElementVolumeVariables<GVV, /*cachingEnabled*/true>
38{
39 using ThisType = FaceCenteredStaggeredElementVolumeVariables<GVV, /*cachingEnabled*/true>;
40 using Problem = std::decay_t<decltype(std::declval<GVV>().problem())>;
41 using GridGeometry = typename ProblemTraits<Problem>::GridGeometry;
42 using FVElementGeometry = typename GridGeometry::LocalView;
43 using SubControlVolume = typename GridGeometry::SubControlVolume;
44
45public:
48
50 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
51
53 : gridVolumeVariablesPtr_(&gridVolumeVariables)
54 , numScv_(gridVolumeVariables.problem().gridGeometry().numScv())
55 {}
56
58 const VolumeVariables& operator [](const SubControlVolume& scv) const
59 {
60 if (scv.index() < numScv_)
61 return gridVolVars().volVars(scv.index());
62 else
63 return boundaryVolumeVariables_[getLocalIdx_(scv.index())];
64 }
65
68 const VolumeVariables& operator [](const std::size_t scvIdx) const
69 {
70 if (scvIdx < numScv_)
71 return gridVolVars().volVars(scvIdx);
72 else
73 return boundaryVolumeVariables_[getLocalIdx_(scvIdx)];
74 }
75
81 template<class SolutionVector>
82 ThisType bind(const typename FVElementGeometry::Element& element,
83 const FVElementGeometry& fvGeometry,
84 const SolutionVector& sol) &&
85 {
86 this->bind(element, fvGeometry, sol);
87 return std::move(*this);
88 }
89
92 template<class SolutionVector>
93 void bind(const typename FVElementGeometry::Element& element,
94 const FVElementGeometry& fvGeometry,
95 const SolutionVector& sol) &
96 {
97 if (!fvGeometry.hasBoundaryScvf())
98 return;
99
100 clear_();
101 // upper bound of size is the number of all scvfs minus frontal scvfs
102 boundaryVolVarIndices_.reserve(fvGeometry.numScvf()-element.subEntities(1));
103 boundaryVolumeVariables_.reserve(fvGeometry.numScvf()-element.subEntities(1));
104
105 for (const auto& scvf : scvfs(fvGeometry))
106 {
107 if (!scvf.boundary() || scvf.isFrontal() || scvf.processorBoundary())
108 continue;
109
110 // check if boundary is a pure dirichlet boundary
111 const auto& problem = gridVolVars().problem();
112 const auto bcTypes = problem.boundaryTypes(element, scvf);
113
114 auto addBoundaryVolVars = [&](const auto& scvFace)
115 {
116 const auto& scvI = fvGeometry.scv(scvFace.insideScvIdx());
117 typename VolumeVariables::PrimaryVariables pv(
118 problem.dirichlet(element, scvFace)[scvI.dofAxis()]
119 );
120 const auto dirichletPriVars = elementSolution<FVElementGeometry>(pv);
121
122 VolumeVariables volVars;
123 volVars.update(dirichletPriVars, problem, element, scvI);
124
125 boundaryVolumeVariables_.emplace_back(std::move(volVars));
126 boundaryVolVarIndices_.push_back(scvFace.outsideScvIdx());
127 };
128
129 if (bcTypes.hasDirichlet())
130 {
131 addBoundaryVolVars(scvf);
132 continue;
133 }
134
135 // treat domain corners
136 if (const auto& orthogonalScvf = fvGeometry.lateralOrthogonalScvf(scvf); orthogonalScvf.boundary())
137 if (problem.boundaryTypes(element, orthogonalScvf).hasDirichlet())
138 addBoundaryVolVars(scvf);
139
140 }
141
142 assert(boundaryVolumeVariables_.size() == boundaryVolVarIndices_.size());
143 }
144
150 template<class SolutionVector>
151 ThisType bindElement(const typename FVElementGeometry::Element& element,
152 const FVElementGeometry& fvGeometry,
153 const SolutionVector& sol) &&
154 {
155 this->bindElement(element, fvGeometry, sol);
156 return std::move(*this);
157 }
158
160 template<class SolutionVector>
161 void bindElement(const typename FVElementGeometry::Element& element,
162 const FVElementGeometry& fvGeometry,
163 const SolutionVector& sol) &
164 {}
165
166
169 { return *gridVolumeVariablesPtr_; }
170
172 bool hasVolVars(const std::size_t scvIdx) const
173 {
174 if (scvIdx < numScv_)
175 return true;
176 else
177 {
178 const auto it = std::find(boundaryVolVarIndices_.begin(), boundaryVolVarIndices_.end(), scvIdx);
179 return it != boundaryVolVarIndices_.end();
180 }
181 }
182
183private:
185 void clear_()
186 {
187 boundaryVolVarIndices_.clear();
188 boundaryVolumeVariables_.clear();
189 }
190
192 int getLocalIdx_(const std::size_t volVarIdx) const
193 {
194 const auto it = std::find(boundaryVolVarIndices_.begin(), boundaryVolVarIndices_.end(), volVarIdx);
195 assert(it != boundaryVolVarIndices_.end() && "Could not find the current volume variables for volVarIdx!");
196 return std::distance(boundaryVolVarIndices_.begin(), it);
197 }
198
199 const GridVolumeVariables* gridVolumeVariablesPtr_;
200 const std::size_t numScv_;
201 std::vector<std::size_t> boundaryVolVarIndices_;
202 std::vector<VolumeVariables> boundaryVolumeVariables_;
203};
204
209template<class GVV>
210class FaceCenteredStaggeredElementVolumeVariables<GVV, /*cachingEnabled*/false>
211{
212 using ThisType = FaceCenteredStaggeredElementVolumeVariables<GVV, /*cachingEnabled*/false>;
213 using Problem = std::decay_t<decltype(std::declval<GVV>().problem())>;
214 using GridGeometry = typename ProblemTraits<Problem>::GridGeometry;
215 using FVElementGeometry = typename GridGeometry::LocalView;
216 using SubControlVolume = typename GridGeometry::SubControlVolume;
217
218 static constexpr auto dim = GridGeometry::GridView::dimension;
219 static constexpr auto numInsideVolVars = dim * 2;
220 static constexpr auto numOutsideVolVars = numInsideVolVars * 2 * (dim - 1);
221
222public:
225
227 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
228
230 : gridVolumeVariablesPtr_(&globalFacesVars) {}
231
233 const VolumeVariables& operator [](const SubControlVolume& scv) const
234 { return volumeVariables_[getLocalIdx_(scv.index())]; }
235
237 const VolumeVariables& operator [](const std::size_t scvIdx) const
238 { return volumeVariables_[getLocalIdx_(scvIdx)]; }
239
241 VolumeVariables& operator [](const SubControlVolume& scv)
242 { return volumeVariables_[getLocalIdx_(scv.index())]; }
243
244 // operator for the access with an index
245 VolumeVariables& operator [](const std::size_t scvIdx)
246 { return volumeVariables_[getLocalIdx_(scvIdx)]; }
247
253 template<class SolutionVector>
254 ThisType bind(const typename FVElementGeometry::Element& element,
255 const FVElementGeometry& fvGeometry,
256 const SolutionVector& sol) &&
257 {
258 this->bind_(element, fvGeometry, sol);
259 return std::move(*this);
260 }
261
262 template<class SolutionVector>
263 void bind(const typename FVElementGeometry::Element& element,
264 const FVElementGeometry& fvGeometry,
265 const SolutionVector& sol) &
266 {
267 this->bind_(element, fvGeometry, sol);
268 }
269
275 template<class SolutionVector>
276 ThisType bindElement(const typename FVElementGeometry::Element& element,
277 const FVElementGeometry& fvGeometry,
278 const SolutionVector& sol) &&
279 {
280 this->bindElement_(element, fvGeometry, sol);
281 return std::move(*this);
282 }
283
284 template<class SolutionVector>
285 void bindElement(const typename FVElementGeometry::Element& element,
286 const FVElementGeometry& fvGeometry,
287 const SolutionVector& sol) &
288 { this->bindElement_(element, fvGeometry, sol); }
289
292 { return *gridVolumeVariablesPtr_; }
293
295 bool hasVolVars(const std::size_t scvIdx) const
296 { return volVarsInserted_(scvIdx); }
297
298private:
301 template<class SolutionVector>
302 void bind_(const typename FVElementGeometry::Element& element,
303 const FVElementGeometry& fvGeometry,
304 const SolutionVector& sol)
305 {
306 clear_();
307
308 const auto& problem = gridVolVars().problem();
309 const auto& gridGeometry = fvGeometry.gridGeometry();
310
311 volVarIndices_.reserve(numInsideVolVars + numInsideVolVars);
312 volumeVariables_.reserve(numInsideVolVars + numInsideVolVars);
313
314 for (const auto& scv : scvs(fvGeometry))
315 {
316 for (const auto otherScvIdx : gridGeometry.connectivityMap()[scv.index()])
317 {
318 if (!volVarsInserted_(otherScvIdx))
319 {
320 const auto& otherScv = fvGeometry.scv(otherScvIdx);
321 volVarIndices_.push_back(otherScvIdx);
322 volumeVariables_.emplace_back();
323 const auto& otherElement = gridGeometry.element(otherScv.elementIndex());
324 volumeVariables_.back().update(
325 elementSolution(otherElement, sol, gridGeometry),
326 problem, otherElement, otherScv
327 );
328 }
329 }
330 }
331
332 if (fvGeometry.hasBoundaryScvf())
333 {
334 for (const auto& scvf : scvfs(fvGeometry))
335 {
336 if (!scvf.boundary() || scvf.isFrontal())
337 continue;
338
339 // check if boundary is a pure dirichlet boundary
340 const auto& problem = gridVolVars().problem();
341 const auto bcTypes = problem.boundaryTypes(element, scvf);
342
343 auto addBoundaryVolVars = [&](const auto& scvFace)
344 {
345 const auto& scvI = fvGeometry.scv(scvFace.insideScvIdx());
346 typename VolumeVariables::PrimaryVariables pv(
347 problem.dirichlet(element, scvFace)[scvI.dofAxis()]
348 );
349 const auto dirichletPriVars = elementSolution<FVElementGeometry>(pv);
350
351 VolumeVariables volVars;
352 volVars.update(dirichletPriVars,
353 problem,
354 element,
355 scvI);
356
357 volumeVariables_.emplace_back(std::move(volVars));
358 volVarIndices_.push_back(scvFace.outsideScvIdx());
359 };
360
361 if (bcTypes.hasDirichlet())
362 {
363 addBoundaryVolVars(scvf);
364 continue;
365 }
366
367 // treat domain corners
368 if (const auto& orthogonalScvf = fvGeometry.lateralOrthogonalScvf(scvf); orthogonalScvf.boundary())
369 if (problem.boundaryTypes(element, orthogonalScvf).hasDirichlet())
370 addBoundaryVolVars(scvf);
371
372 }
373 }
374 }
375
378 template<class SolutionVector>
379 void bindElement_(const typename FVElementGeometry::Element& element,
380 const FVElementGeometry& fvGeometry,
381 const SolutionVector& sol)
382 {
383 clear_();
384 const auto& problem = gridVolVars().problem();
385 const auto& gridGeometry = fvGeometry.gridGeometry();
386 volVarIndices_.reserve(numInsideVolVars);
387
388 for (const auto& scv : scvs(fvGeometry))
389 {
390 volVarIndices_.push_back(scv.index());
391 volumeVariables_.emplace_back();
392 volumeVariables_.back().update(
393 elementSolution(element, sol, gridGeometry),
394 problem, element, scv
395 );
396 }
397 }
398
400 void clear_()
401 {
402 volVarIndices_.clear();
403 volumeVariables_.clear();
404 }
405
406 bool volVarsInserted_(const std::size_t scvIdx) const
407 {
408 return std::find(volVarIndices_.begin(), volVarIndices_.end(), scvIdx) != volVarIndices_.end();
409 }
410
411 int getLocalIdx_(const int scvfIdx) const
412 {
413 const auto it = std::find(volVarIndices_.begin(), volVarIndices_.end(), scvfIdx);
414 assert(it != volVarIndices_.end() && "Could not find the current face variables for scvfIdx!");
415 return std::distance(volVarIndices_.begin(), it);
416 }
417
418 const GridVolumeVariables* gridVolumeVariablesPtr_;
419 std::vector<std::size_t> volVarIndices_;
420 std::vector<VolumeVariables> volumeVariables_;
421};
422
423} // end namespace Dumux
424
425#endif
GVV GridVolumeVariables
export type of the grid volume variables
Definition facecentered/staggered/elementvolumevariables.hh:224
ThisType bindElement(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition facecentered/staggered/elementvolumevariables.hh:276
void bind(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition facecentered/staggered/elementvolumevariables.hh:263
ThisType bind(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition facecentered/staggered/elementvolumevariables.hh:254
bool hasVolVars(const std::size_t scvIdx) const
Returns true if volVars exist for the given scv index.
Definition facecentered/staggered/elementvolumevariables.hh:295
void bindElement(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition facecentered/staggered/elementvolumevariables.hh:285
FaceCenteredStaggeredElementVolumeVariables(const GridVolumeVariables &globalFacesVars)
Definition facecentered/staggered/elementvolumevariables.hh:229
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition facecentered/staggered/elementvolumevariables.hh:227
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition facecentered/staggered/elementvolumevariables.hh:291
void bindElement(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition facecentered/staggered/elementvolumevariables.hh:161
GVV GridVolumeVariables
export type of the grid volume variables
Definition facecentered/staggered/elementvolumevariables.hh:47
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition facecentered/staggered/elementvolumevariables.hh:168
ThisType bindElement(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition facecentered/staggered/elementvolumevariables.hh:151
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition facecentered/staggered/elementvolumevariables.hh:50
bool hasVolVars(const std::size_t scvIdx) const
Returns true if volVars exist for the given scv index.
Definition facecentered/staggered/elementvolumevariables.hh:172
FaceCenteredStaggeredElementVolumeVariables(const GridVolumeVariables &gridVolumeVariables)
Definition facecentered/staggered/elementvolumevariables.hh:52
void bind(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition facecentered/staggered/elementvolumevariables.hh:93
ThisType bind(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition facecentered/staggered/elementvolumevariables.hh:82
Base class for the face variables vector.
Definition facecentered/staggered/elementvolumevariables.hh:30
Type traits for problem classes.
Element solution classes and factory functions.
void addBoundaryVolVars(std::vector< VolumeVariables > &volVars, std::vector< IndexType > &volVarIndices, const Problem &problem, const typename FVElemGeom::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElemGeom &fvGeometry)
Adds the boundary volume variables found within the stencil to the provided containers and stores the...
Definition cellcentered/mpfa/elementvolumevariables.hh:124
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::cctpfa||GridGeometry::discMethod==DiscretizationMethods::ccmpfa, CCElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for cell-centered schemes.
Definition cellcentered/elementsolution.hh:101
Definition adapt.hh:17
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition localdof.hh:82
Detail::ProblemGridGeometry< Problem > GridGeometry
Definition common/typetraits/problem.hh:50