3.5-git
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/common/reservedvector.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
44 static constexpr int dim = GridView::dimension;
45 static constexpr int numCubeCorners = 1 << dim;
46
47public:
49 using PrimaryVariables = PV;
50
52 BoxElementSolution() = default;
53
55 template<class SolutionVector>
56 BoxElementSolution(const Element& element, const SolutionVector& sol,
57 const GridGeometry& gridGeometry)
58 {
59 update(element, sol, gridGeometry);
60 }
61
63 template<class ElementVolumeVariables>
64 BoxElementSolution(const Element& element, const ElementVolumeVariables& elemVolVars,
65 const FVElementGeometry& fvGeometry)
66 {
67 const auto numVert = element.subEntities(GridView::dimension);
68 priVars_.resize(numVert);
69 for (const auto& scv : scvs(fvGeometry))
70 priVars_[scv.localDofIndex()] = elemVolVars[scv].priVars();
71 }
72
74 template<class SolutionVector>
75 void update(const Element& element, const SolutionVector& sol,
76 const GridGeometry& gridGeometry)
77 {
78 const auto numVert = element.subEntities(GridView::dimension);
79 priVars_.resize(numVert);
80 for (int vIdx = 0; vIdx < numVert; ++vIdx)
81 priVars_[vIdx] = sol[gridGeometry.vertexMapper().subIndex(element, vIdx, GridView::dimension)];
82 }
83
85 template<class SolutionVector>
86 void update(const Element& element, const SolutionVector& sol,
87 const FVElementGeometry& fvGeometry)
88 {
89 const auto numVert = element.subEntities(GridView::dimension);
90 priVars_.resize(numVert);
91 for (const auto& scv : scvs(fvGeometry))
92 priVars_[scv.localDofIndex()] = sol[scv.dofIndex()];
93 }
94
96 std::size_t size() const
97 { return priVars_.size(); }
98
100 template<typename IndexType>
101 const PrimaryVariables& operator [](IndexType i) const
102 { return priVars_[i]; }
103
105 template<typename IndexType>
107 { return priVars_[i]; }
108
109private:
110 Dune::ReservedVector<PrimaryVariables, numCubeCorners> priVars_;
111};
112
117template<class Element, class SolutionVector, class GridGeometry>
118auto elementSolution(const Element& element, const SolutionVector& sol, const GridGeometry& gg)
119-> std::enable_if_t<GridGeometry::discMethod == DiscretizationMethods::box,
120 BoxElementSolution<typename GridGeometry::LocalView,
121 std::decay_t<decltype(std::declval<SolutionVector>()[0])>>
122 >
123{
124 using PrimaryVariables = std::decay_t<decltype(std::declval<SolutionVector>()[0])>;
126}
127
132template<class Element, class ElementVolumeVariables, class FVElementGeometry>
133auto elementSolution(const Element& element, const ElementVolumeVariables& elemVolVars, const FVElementGeometry& gg)
134-> std::enable_if_t<FVElementGeometry::GridGeometry::discMethod == DiscretizationMethods::box,
135 BoxElementSolution<FVElementGeometry,
136 typename ElementVolumeVariables::VolumeVariables::PrimaryVariables>>
137{
138 using PrimaryVariables = typename ElementVolumeVariables::VolumeVariables::PrimaryVariables;
139 return BoxElementSolution<FVElementGeometry, PrimaryVariables>(element, elemVolVars, gg);
140}
141
142} // end namespace Dumux
143
144#endif
The available discretization methods in Dumux.
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:118
Definition: adapt.hh:29
constexpr Box box
Definition: method.hh:139
The element solution vector.
Definition: box/elementsolution.hh:39
PV PrimaryVariables
export the primary variables type
Definition: box/elementsolution.hh:49
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:86
std::size_t size() const
return the size of the element solution
Definition: box/elementsolution.hh:96
BoxElementSolution(const Element &element, const ElementVolumeVariables &elemVolVars, const FVElementGeometry &fvGeometry)
Constructor with element and elemVolVars and fvGeometry.
Definition: box/elementsolution.hh:64
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:56
const PrimaryVariables & operator[](IndexType i) const
bracket operator const access
Definition: box/elementsolution.hh:101
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:75