3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
discretization/cellcentered/subcontrolvolume.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_DISCRETIZATION_CC_SUBCONTROLVOLUME_HH
25#define DUMUX_DISCRETIZATION_CC_SUBCONTROLVOLUME_HH
26
27#include <memory>
28
29#include <dune/common/fvector.hh>
30
33
34namespace Dumux {
35
42template<class GridView>
44{
45 using Geometry = typename GridView::template Codim<0>::Geometry;
48 using Scalar = typename GridView::ctype;
49 using Element = typename GridView::template Codim<0>::Entity;
50 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
51};
52
59template<class GV,
62: public SubControlVolumeBase<CCSubControlVolume<GV, T>, T>
63{
66 using Geometry = typename T::Geometry;
67 using GridIndexType = typename T::GridIndexType;
68 using LocalIndexType = typename T::LocalIndexType;
69 using Scalar = typename T::Scalar;
70
71 // In the following, the correct parameter type for the geometry passed to
72 // the constructor below is determined. It depends upon whether the
73 // `geometry()` method of the `Element` returns a copy or a reference.
74 // In the first case, the correct type is `Geometry&&`, while it is
75 // `Geometry` for the second case. Although returning by copy is prescribed
76 // by the Dune interface, the grid implementation CpGrid uses a const
77 // reference as of Opm 2018.04. Once this is fixed, the parameter type can
78 // be hardcoded to `Geometry&&` again.
79 using Element = typename GV::template Codim<0>::Entity;
80 using GeometryRT = decltype(std::declval<Element>().geometry());
81 static constexpr bool grtIsReference = std::is_lvalue_reference<GeometryRT>::value;
82 using GeometryParamType = std::conditional_t<grtIsReference, Geometry, Geometry&&>;
83public:
85 using GlobalPosition = typename T::GlobalPosition;
87 using Traits = T;
88
89 CCSubControlVolume() = default;
90
91 // See the explanation above for deriving `GeometryParamType`.
92 CCSubControlVolume(GeometryParamType geometry,
93 GridIndexType elementIndex)
94 : ParentType()
95 , geometry_(std::make_unique<Geometry>(std::move(geometry)))
96 , center_(geometry_->center())
97 , elementIndex_(elementIndex)
98 {}
99
102 { deepCopy_(other); }
103
106
109 {
110 deepCopy_(other);
111 return *this;
112 }
113
116
118 const GlobalPosition& center() const
119 {
120 return center_;
121 }
122
124 Scalar volume() const
125 {
126 return geometry().volume();
127 }
128
130 // e.g. for integration
131 const Geometry& geometry() const
132 {
133 return *geometry_;
134 }
135
137 GridIndexType dofIndex() const
138 {
139 return elementIndex();
140 }
141
143 LocalIndexType localDofIndex() const
144 {
145 return 0;
146 }
147
150 LocalIndexType indexInElement() const
151 {
152 return 0;
153 }
154
155 // The position of the dof this scv is embedded in
157 {
158 return center_;
159 }
160
162 GridIndexType elementIndex() const
163 {
164 return elementIndex_;
165 }
166
168 GlobalPosition corner(LocalIndexType localIdx) const
169 {
170 assert(localIdx < geometry().corners() && "provided index exceeds the number of corners");
171 return geometry().corner(localIdx);
172 }
173
174private:
175 void deepCopy_(const CCSubControlVolume& other)
176 {
177 if (other.geometry_)
178 geometry_ = std::make_unique<Geometry>(other.geometry());
179 else
180 geometry_.reset();
181 center_ = other.center_;
182 elementIndex_ = other.elementIndex_;
183 }
184
185 // Work around the fact that geometry is not default-constructible and not copy-assignable
186 std::unique_ptr<Geometry> geometry_;
187 GlobalPosition center_;
188 GridIndexType elementIndex_;
189};
190
191} // end namespace Dumux
192
193#endif
Defines the index types used for grid and local indices.
Base class for a sub control volume.
Definition: adapt.hh:29
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
unsigned int LocalIndex
Definition: indextraits.hh:40
Default traits class to be used for the sub-control volumes for the cell-centered finite volume schem...
Definition: discretization/cellcentered/subcontrolvolume.hh:44
typename IndexTraits< GridView >::GridIndex GridIndexType
Definition: discretization/cellcentered/subcontrolvolume.hh:46
typename GridView::template Codim< 0 >::Geometry Geometry
Definition: discretization/cellcentered/subcontrolvolume.hh:45
typename IndexTraits< GridView >::LocalIndex LocalIndexType
Definition: discretization/cellcentered/subcontrolvolume.hh:47
typename GridView::template Codim< 0 >::Entity Element
Definition: discretization/cellcentered/subcontrolvolume.hh:49
typename Element::Geometry::GlobalCoordinate GlobalPosition
Definition: discretization/cellcentered/subcontrolvolume.hh:50
typename GridView::ctype Scalar
Definition: discretization/cellcentered/subcontrolvolume.hh:48
Sub control volumes for cell-centered discretization schemes.
Definition: discretization/cellcentered/subcontrolvolume.hh:63
GridIndexType elementIndex() const
The global index of the element this scv is embedded in.
Definition: discretization/cellcentered/subcontrolvolume.hh:162
CCSubControlVolume & operator=(const CCSubControlVolume &other)
The copy assignment operator.
Definition: discretization/cellcentered/subcontrolvolume.hh:108
Scalar volume() const
The volume of the sub control volume.
Definition: discretization/cellcentered/subcontrolvolume.hh:124
LocalIndexType localDofIndex() const
The element-local index of the dof this scv is embedded in.
Definition: discretization/cellcentered/subcontrolvolume.hh:143
LocalIndexType indexInElement() const
Definition: discretization/cellcentered/subcontrolvolume.hh:150
CCSubControlVolume(const CCSubControlVolume &other)
The copy constrcutor.
Definition: discretization/cellcentered/subcontrolvolume.hh:101
GlobalPosition corner(LocalIndexType localIdx) const
Return the corner for the given local index.
Definition: discretization/cellcentered/subcontrolvolume.hh:168
T Traits
state the traits public and thus export all types
Definition: discretization/cellcentered/subcontrolvolume.hh:87
typename T::GlobalPosition GlobalPosition
export the type used for global coordinates
Definition: discretization/cellcentered/subcontrolvolume.hh:85
const Geometry & geometry() const
The geometry of the sub control volume.
Definition: discretization/cellcentered/subcontrolvolume.hh:131
CCSubControlVolume(CCSubControlVolume &&other)=default
The move constrcutor.
const GlobalPosition & dofPosition() const
Definition: discretization/cellcentered/subcontrolvolume.hh:156
CCSubControlVolume(GeometryParamType geometry, GridIndexType elementIndex)
Definition: discretization/cellcentered/subcontrolvolume.hh:92
GridIndexType dofIndex() const
The index of the dof this scv is embedded in (the global index of this scv)
Definition: discretization/cellcentered/subcontrolvolume.hh:137
const GlobalPosition & center() const
The center of the sub control volume.
Definition: discretization/cellcentered/subcontrolvolume.hh:118
CCSubControlVolume & operator=(CCSubControlVolume &&other)=default
The move assignment operator.
Base class for a sub control volume, i.e a part of the control volume we are making the balance for....
Definition: subcontrolvolumebase.hh:38