version 3.11-dev
Loading...
Searching...
No Matches
cvfe/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// 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_CVFE_ELEMENT_SOLUTION_HH
13#define DUMUX_CVFE_ELEMENT_SOLUTION_HH
14
15#include <type_traits>
16#include <dune/common/reservedvector.hh>
17
19#include <dumux/common/typetraits/localdofs_.hh>
22
23namespace Dumux {
24
25namespace Detail {
26
27template<class ElementVariables>
28constexpr auto primaryVariablesType()
29{
30 if constexpr (requires { typename ElementVariables::Variables::PrimaryVariables; })
31 return std::type_identity<typename ElementVariables::Variables::PrimaryVariables>{};
32 else if constexpr (requires { typename ElementVariables::VolumeVariables::PrimaryVariables; })
33 return std::type_identity<typename ElementVariables::VolumeVariables::PrimaryVariables>{};
34 else
35 return std::type_identity<void>{};
36}
37
38template<class ElementVariables>
40
41} // end namespace Detail
42
47template<class FVElementGeometry, class PV>
49{
50 using GridGeometry = typename FVElementGeometry::GridGeometry;
51 using GridView = typename GridGeometry::GridView;
52 using Element = typename GridView::template Codim<0>::Entity;
53
54 static constexpr int dim = GridView::dimension;
55
56 // Maximum number of local element dofs
57 static constexpr int maxNumLocalDofs = Detail::LocalDofs::maxNumLocalDofs<FVElementGeometry>();
58
59public:
61 using PrimaryVariables = PV;
62
65
67 template<class SolutionVector>
68 CVFEElementSolution(const Element& element, const SolutionVector& sol,
69 const GridGeometry& gridGeometry)
70 {
71 update(element, sol, gridGeometry);
72 }
73
75 template<class ElementVariables>
76 CVFEElementSolution(const Element& element, const ElementVariables& elemVars,
77 const FVElementGeometry& fvGeometry)
78 {
79 priVars_.resize(Detail::LocalDofs::numLocalDofs(fvGeometry));
80 for (const auto& localDof : localDofs(fvGeometry))
81 priVars_[localDof.index()] = elemVars[localDof.index()].priVars();
82 }
83
85 template<class SolutionVector>
86 void update(const Element& element, const SolutionVector& sol,
87 const GridGeometry& gridGeometry)
88 {
89 // For schemes with multiple DOFs per entity (e.g. PQ3 with 2 DOFs per edge)
90 // the formula subIndex + localKey.index() may need an orientation flip for
91 // simplex elements (see HybridPQ3GeometryHelper::dofIndex for details).
92 // If the grid geometry exposes a flip-aware dofIndex(element, localKey)
93 // method, use it; otherwise fall back to the generic formula.
94 // As local-global mappings are provided by the grid geometry
95 // this logic should maybe become part of the grid geometry.
96 const auto& localCoeff = gridGeometry.feCache().get(element.type()).localCoefficients();
97 priVars_.resize(localCoeff.size());
98 for (int localDofIdx = 0; localDofIdx < localCoeff.size(); ++localDofIdx)
99 {
100 const auto& localKey = localCoeff.localKey(localDofIdx);
101 if constexpr (requires { gridGeometry.dofIndex(element, localKey); })
102 priVars_[localDofIdx] = sol[gridGeometry.dofIndex(element, localKey)];
103 else
104 priVars_[localDofIdx] = sol[
105 gridGeometry.dofMapper().subIndex(
106 element, localKey.subEntity(), localKey.codim()
107 ) + localKey.index()
108 ];
109 }
110 }
111
113 template<class SolutionVector>
114 void update(const Element& element, const SolutionVector& sol,
115 const FVElementGeometry& fvGeometry)
116 {
117 priVars_.resize(Detail::LocalDofs::numLocalDofs(fvGeometry));
118 for (const auto& localDof : localDofs(fvGeometry))
119 priVars_[localDof.index()] = sol[localDof.dofIndex()];
120 }
121
123 std::size_t size() const
124 { return priVars_.size(); }
125
127 template<typename IndexType>
128 const PrimaryVariables& operator [](IndexType i) const
129 { return priVars_[i]; }
130
132 template<typename IndexType>
134 { return priVars_[i]; }
135
136private:
137 Dune::ReservedVector<PrimaryVariables, maxNumLocalDofs> priVars_;
138};
139
141template<class Element, class SolutionVector, class GridGeometry>
142auto elementSolution(const Element& element, const SolutionVector& sol, const GridGeometry& gg)
143-> std::enable_if_t<DiscretizationMethods::isCVFE<typename GridGeometry::DiscretizationMethod>,
144 CVFEElementSolution<typename GridGeometry::LocalView,
145 std::decay_t<decltype(std::declval<SolutionVector>()[0])>>
146 >
147{
148 using PrimaryVariables = std::decay_t<decltype(std::declval<SolutionVector>()[0])>;
150}
151
153template<class Element, class ElementVariables, class FVElementGeometry>
154 requires ((requires { typename FVElementGeometry::GridDiscretization; }
155 || requires { typename FVElementGeometry::GridGeometry; })
157 && !std::is_void_v<Detail::PrimaryVariables_t<ElementVariables>>)
158auto elementSolution(const Element& element, const ElementVariables& elemVars, const FVElementGeometry& gg)
160{
161 using PrimaryVariables = Detail::PrimaryVariables_t<ElementVariables>;
163}
164
165} // end namespace Dumux
166
167#endif
The element solution vector.
Definition cvfe/elementsolution.hh:49
CVFEElementSolution(const Element &element, const ElementVariables &elemVars, const FVElementGeometry &fvGeometry)
Constructor with element and elemVolVars and fvGeometry.
Definition cvfe/elementsolution.hh:76
const PrimaryVariables & operator[](IndexType i) const
bracket operator const access
Definition cvfe/elementsolution.hh:128
PV PrimaryVariables
export the primary variables type
Definition cvfe/elementsolution.hh:61
CVFEElementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gridGeometry)
Constructor with element and solution and grid geometry.
Definition cvfe/elementsolution.hh:68
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 cvfe/elementsolution.hh:114
std::size_t size() const
return the size of the element solution
Definition cvfe/elementsolution.hh:123
void update(const Element &element, const SolutionVector &sol, const GridGeometry &gridGeometry)
extract the element solution from the solution vector using a mapper
Definition cvfe/elementsolution.hh:86
CVFEElementSolution()=default
Default constructor.
Type traits for classes providing a grid discretization.
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
Class representing dofs on elements for control-volume finite element schemes.
The available discretization methods in Dumux.
Definition cvfelocalresidual.hh:25
constexpr auto primaryVariablesType()
Definition cvfe/elementsolution.hh:28
typename decltype(primaryVariablesType< ElementVariables >())::type PrimaryVariables_t
Definition cvfe/elementsolution.hh:39
constexpr bool isCVFE
Definition method.hh:67
Definition adapt.hh:17
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition localdof.hh:50