3.1-git
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 <dune/common/fvector.hh>
28
32
33namespace Dumux {
34
41template<class GridView>
43{
44 using Geometry = typename GridView::template Codim<0>::Geometry;
47 using Scalar = typename GridView::ctype;
48 using Element = typename GridView::template Codim<0>::Entity;
49 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
50};
51
58template<class GV,
61: public SubControlVolumeBase<CCSubControlVolume<GV, T>, T>
62{
65 using Geometry = typename T::Geometry;
66 using GridIndexType = typename T::GridIndexType;
67 using LocalIndexType = typename T::LocalIndexType;
68 using Scalar = typename T::Scalar;
69
70 // In the following, the correct parameter type for the geometry passed to
71 // the constructor below is determined. It depends upon whether the
72 // `geometry()` method of the `Element` returns a copy or a reference.
73 // In the first case, the correct type is `Geometry&&`, while it is
74 // `Geometry` for the second case. Although returning by copy is prescribed
75 // by the Dune interface, the grid implementation CpGrid uses a const
76 // reference as of Opm 2018.04. Once this is fixed, the parameter type can
77 // be hardcoded to `Geometry&&` again.
78 using Element = typename GV::template Codim<0>::Entity;
79 using GeometryRT = decltype(std::declval<Element>().geometry());
80 static constexpr bool grtIsReference = std::is_lvalue_reference<GeometryRT>::value;
81 using GeometryParamType = std::conditional_t<grtIsReference, Geometry, Geometry&&>;
82public:
84 using GlobalPosition = typename T::GlobalPosition;
86 using Traits = T;
87
88 CCSubControlVolume() = default;
89
90 // See the explanation above for deriving `GeometryParamType`.
91 CCSubControlVolume(GeometryParamType geometry,
92 GridIndexType elementIndex)
93 : ParentType()
94 , geometry_(std::move(geometry))
95 , center_(geometry_.value().center())
96 , elementIndex_(elementIndex)
97 {}
98
100 CCSubControlVolume(const CCSubControlVolume& other) = default;
101
104
107 {
108 // We want to use the default copy/move assignment.
109 // But since geometry is not copy assignable :( we
110 // have to construct it again
111 geometry_.release();
112 geometry_.emplace(other.geometry_.value());
113 center_ = other.center_;
114 elementIndex_ = other.elementIndex_;
115 return *this;
116 }
117
120 {
121 // We want to use the default copy/move assignment.
122 // But since geometry is not copy assignable :( we
123 // have to construct it again
124 geometry_.release();
125 geometry_.emplace(std::move(other.geometry_.value()));
126 center_ = std::move(other.center_);
127 elementIndex_ = std::move(other.elementIndex_);
128 return *this;
129 }
130
132 const GlobalPosition& center() const
133 {
134 return center_;
135 }
136
138 Scalar volume() const
139 {
140 return geometry().volume();
141 }
142
144 // e.g. for integration
145 const Geometry& geometry() const
146 {
147 assert((geometry_));
148 return geometry_.value();
149 }
150
152 GridIndexType dofIndex() const
153 {
154 return elementIndex();
155 }
156
158 LocalIndexType localDofIndex() const
159 {
160 return 0;
161 }
162
165 LocalIndexType indexInElement() const
166 {
167 return 0;
168 }
169
170 // The position of the dof this scv is embedded in
172 {
173 return center_;
174 }
175
177 GridIndexType elementIndex() const
178 {
179 return elementIndex_;
180 }
181
183 GlobalPosition corner(LocalIndexType localIdx) const
184 {
185 assert(localIdx < geometry().corners() && "provided index exceeds the number of corners");
186 return geometry().corner(localIdx);
187 }
188
189private:
190 // Work around the fact that geometry is not default constructible
191 Optional<Geometry> geometry_;
192 GlobalPosition center_;
193 GridIndexType elementIndex_;
194};
195
196} // end namespace Dumux
197
198#endif
Defines the index types used for grid and local indices.
A wrapper that can either contain an object of T or be empty. This might be used as a workaround for ...
Base class for a sub control volume.
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
unsigned int LocalIndex
Definition: indextraits.hh:40
const T & value() const
Definition: optional.hh:117
void emplace(Args &&... args)
Definition: optional.hh:128
void release()
Definition: optional.hh:135
Default traits class to be used for the sub-control volumes for the cell-centered finite volume schem...
Definition: discretization/cellcentered/subcontrolvolume.hh:43
typename IndexTraits< GridView >::GridIndex GridIndexType
Definition: discretization/cellcentered/subcontrolvolume.hh:45
typename GridView::template Codim< 0 >::Geometry Geometry
Definition: discretization/cellcentered/subcontrolvolume.hh:44
typename IndexTraits< GridView >::LocalIndex LocalIndexType
Definition: discretization/cellcentered/subcontrolvolume.hh:46
typename GridView::template Codim< 0 >::Entity Element
Definition: discretization/cellcentered/subcontrolvolume.hh:48
typename Element::Geometry::GlobalCoordinate GlobalPosition
Definition: discretization/cellcentered/subcontrolvolume.hh:49
typename GridView::ctype Scalar
Definition: discretization/cellcentered/subcontrolvolume.hh:47
Sub control volumes for cell-centered discretization schemes.
Definition: discretization/cellcentered/subcontrolvolume.hh:62
GridIndexType elementIndex() const
The global index of the element this scv is embedded in.
Definition: discretization/cellcentered/subcontrolvolume.hh:177
CCSubControlVolume & operator=(const CCSubControlVolume &other)
The copy assignment operator.
Definition: discretization/cellcentered/subcontrolvolume.hh:106
Scalar volume() const
The volume of the sub control volume.
Definition: discretization/cellcentered/subcontrolvolume.hh:138
LocalIndexType localDofIndex() const
The element-local index of the dof this scv is embedded in.
Definition: discretization/cellcentered/subcontrolvolume.hh:158
LocalIndexType indexInElement() const
Definition: discretization/cellcentered/subcontrolvolume.hh:165
CCSubControlVolume(const CCSubControlVolume &other)=default
The copy constrcutor.
GlobalPosition corner(LocalIndexType localIdx) const
Return the corner for the given local index.
Definition: discretization/cellcentered/subcontrolvolume.hh:183
T Traits
state the traits public and thus export all types
Definition: discretization/cellcentered/subcontrolvolume.hh:86
typename T::GlobalPosition GlobalPosition
export the type used for global coordinates
Definition: discretization/cellcentered/subcontrolvolume.hh:84
const Geometry & geometry() const
The geometry of the sub control volume.
Definition: discretization/cellcentered/subcontrolvolume.hh:145
CCSubControlVolume(CCSubControlVolume &&other)=default
The move constrcutor.
const GlobalPosition & dofPosition() const
Definition: discretization/cellcentered/subcontrolvolume.hh:171
CCSubControlVolume(GeometryParamType geometry, GridIndexType elementIndex)
Definition: discretization/cellcentered/subcontrolvolume.hh:91
GridIndexType dofIndex() const
The index of the dof this scv is embedded in (the global index of this scv)
Definition: discretization/cellcentered/subcontrolvolume.hh:152
const GlobalPosition & center() const
The center of the sub control volume.
Definition: discretization/cellcentered/subcontrolvolume.hh:132
CCSubControlVolume & operator=(CCSubControlVolume &&other) noexcept
The move assignment operator.
Definition: discretization/cellcentered/subcontrolvolume.hh:119
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