3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
box/elementsolution.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_BOX_ELEMENT_SOLUTION_HH
25#define DUMUX_BOX_ELEMENT_SOLUTION_HH
26
27#include <type_traits>
28#include <dune/istl/bvector.hh>
30
31namespace Dumux {
32
37template<class FVElementGeometry, class PV>
39{
40 using GridGeometry = typename FVElementGeometry::GridGeometry;
41 using GridView = typename GridGeometry::GridView;
42 using Element = typename GridView::template Codim<0>::Entity;
43
44public:
46 using PrimaryVariables = PV;
47
49 BoxElementSolution() = default;
50
52 template<class SolutionVector>
53 BoxElementSolution(const Element& element, const SolutionVector& sol,
54 const GridGeometry& gridGeometry)
55 {
56 update(element, sol, gridGeometry);
57 }
58
60 template<class ElementVolumeVariables>
61 BoxElementSolution(const Element& element, const ElementVolumeVariables& elemVolVars,
62 const FVElementGeometry& fvGeometry)
63 {
64 const auto numVert = element.subEntities(GridView::dimension);
65 priVars_.resize(numVert);
66 for (const auto& scv : scvs(fvGeometry))
67 priVars_[scv.localDofIndex()] = elemVolVars[scv].priVars();
68 }
69
71 template<class SolutionVector>
72 void update(const Element& element, const SolutionVector& sol,
73 const GridGeometry& gridGeometry)
74 {
75 const auto numVert = element.subEntities(GridView::dimension);
76 priVars_.resize(numVert);
77 for (int vIdx = 0; vIdx < numVert; ++vIdx)
78 priVars_[vIdx] = sol[gridGeometry.vertexMapper().subIndex(element, vIdx, GridView::dimension)];
79 }
80
82 template<class SolutionVector>
83 void update(const Element& element, const SolutionVector& sol,
84 const FVElementGeometry& fvGeometry)
85 {
86 const auto numVert = element.subEntities(GridView::dimension);
87 priVars_.resize(numVert);
88 for (const auto& scv : scvs(fvGeometry))
89 priVars_[scv.localDofIndex()] = sol[scv.dofIndex()];
90 }
91
93 std::size_t size() const
94 { return priVars_.size(); }
95
97 template<typename IndexType>
98 const PrimaryVariables& operator [](IndexType i) const
99 { return priVars_[i]; }
100
102 template<typename IndexType>
104 { return priVars_[i]; }
105
106private:
107 Dune::BlockVector<PrimaryVariables> priVars_;
108};
109
114template<class Element, class SolutionVector, class GridGeometry>
115auto elementSolution(const Element& element, const SolutionVector& sol, const GridGeometry& gg)
116-> std::enable_if_t<GridGeometry::discMethod == DiscretizationMethod::box,
117 BoxElementSolution<typename GridGeometry::LocalView,
118 std::decay_t<decltype(std::declval<SolutionVector>()[0])>>
119 >
120{
121 using PrimaryVariables = std::decay_t<decltype(std::declval<SolutionVector>()[0])>;
123}
124
129template<class Element, class ElementVolumeVariables, class FVElementGeometry>
130auto elementSolution(const Element& element, const ElementVolumeVariables& elemVolVars, const FVElementGeometry& gg)
131-> std::enable_if_t<FVElementGeometry::GridGeometry::discMethod == DiscretizationMethod::box,
132 BoxElementSolution<FVElementGeometry,
133 typename ElementVolumeVariables::VolumeVariables::PrimaryVariables>>
134{
135 using PrimaryVariables = typename ElementVolumeVariables::VolumeVariables::PrimaryVariables;
136 return BoxElementSolution<FVElementGeometry, PrimaryVariables>(element, elemVolVars, gg);
137}
138
139} // end namespace Dumux
140
141#endif
The available discretization methods in Dumux.
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethod::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:115
Definition: adapt.hh:29
The element solution vector.
Definition: box/elementsolution.hh:39
PV PrimaryVariables
export the primary variables type
Definition: box/elementsolution.hh:46
void update(const Element &element, const SolutionVector &sol, const FVElementGeometry &fvGeometry)
extract the element solution from the solution vector using a local fv geometry
Definition: box/elementsolution.hh:83
std::size_t size() const
return the size of the element solution
Definition: box/elementsolution.hh:93
BoxElementSolution(const Element &element, const ElementVolumeVariables &elemVolVars, const FVElementGeometry &fvGeometry)
Constructor with element and elemVolVars and fvGeometry.
Definition: box/elementsolution.hh:61
BoxElementSolution()=default
Default constructor.
BoxElementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gridGeometry)
Constructor with element and solution and grid geometry.
Definition: box/elementsolution.hh:53
const PrimaryVariables & operator[](IndexType i) const
bracket operator const access
Definition: box/elementsolution.hh:98
void update(const Element &element, const SolutionVector &sol, const GridGeometry &gridGeometry)
extract the element solution from the solution vector using a mapper
Definition: box/elementsolution.hh:72