version 3.7
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_CC_SUBCONTROLVOLUME_HH
13#define DUMUX_DISCRETIZATION_CC_SUBCONTROLVOLUME_HH
14
15#include <memory>
16
17#include <dune/common/fvector.hh>
18
21
22namespace Dumux {
23
30template<class GridView>
32{
33 using Geometry = typename GridView::template Codim<0>::Geometry;
36 using Scalar = typename GridView::ctype;
37 using Element = typename GridView::template Codim<0>::Entity;
38 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
39};
40
47template<class GV,
50: public SubControlVolumeBase<CCSubControlVolume<GV, T>, T>
51{
54 using Geometry = typename T::Geometry;
55 using GridIndexType = typename T::GridIndexType;
56 using LocalIndexType = typename T::LocalIndexType;
57 using Scalar = typename T::Scalar;
58
59 // In the following, the correct parameter type for the geometry passed to
60 // the constructor below is determined. It depends upon whether the
61 // `geometry()` method of the `Element` returns a copy or a reference.
62 // In the first case, the correct type is `Geometry&&`, while it is
63 // `Geometry` for the second case. Although returning by copy is prescribed
64 // by the Dune interface, the grid implementation CpGrid uses a const
65 // reference as of Opm 2018.04. Once this is fixed, the parameter type can
66 // be hardcoded to `Geometry&&` again.
67 using Element = typename GV::template Codim<0>::Entity;
68 using GeometryRT = decltype(std::declval<Element>().geometry());
69 static constexpr bool grtIsReference = std::is_lvalue_reference<GeometryRT>::value;
70 using GeometryParamType = std::conditional_t<grtIsReference, Geometry, Geometry&&>;
71public:
73 using GlobalPosition = typename T::GlobalPosition;
75 using Traits = T;
76
77 CCSubControlVolume() = default;
78
79 // See the explanation above for deriving `GeometryParamType`.
80 CCSubControlVolume(GeometryParamType geometry,
81 GridIndexType elementIndex)
82 : ParentType()
83 , geometry_(std::make_unique<Geometry>(std::move(geometry)))
84 , center_(geometry_->center())
85 , elementIndex_(elementIndex)
86 {}
87
90 { deepCopy_(other); }
91
94
97 {
98 deepCopy_(other);
99 return *this;
100 }
101
104
106 const GlobalPosition& center() const
107 {
108 return center_;
109 }
110
112 Scalar volume() const
113 {
114 return geometry_->volume();
115 }
116
118 // e.g. for integration
119 [[deprecated("Will be removed after 3.7. Use fvGeometry.geometry(scv).")]]
120 const Geometry& geometry() const
121 {
122 return *geometry_;
123 }
124
126 GridIndexType dofIndex() const
127 {
128 return elementIndex();
129 }
130
132 LocalIndexType localDofIndex() const
133 {
134 return 0;
135 }
136
139 LocalIndexType indexInElement() const
140 {
141 return 0;
142 }
143
144 // The position of the dof this scv is embedded in
146 {
147 return center_;
148 }
149
151 GridIndexType elementIndex() const
152 {
153 return elementIndex_;
154 }
155
157 [[deprecated("Will be removed after 3.7. Use fvGeometry.geometry(scv).corner(i).")]]
158 GlobalPosition corner(LocalIndexType localIdx) const
159 {
160 return geometry_->corner(localIdx);
161 }
162
163private:
164 void deepCopy_(const CCSubControlVolume& other)
165 {
166 if (other.geometry_)
167 geometry_ = std::make_unique<Geometry>(*other.geometry_);
168 else
169 geometry_.reset();
170 center_ = other.center_;
171 elementIndex_ = other.elementIndex_;
172 }
173
174 // Work around the fact that geometry is not default-constructible and not copy-assignable
175 std::unique_ptr<Geometry> geometry_;
176 GlobalPosition center_;
177 GridIndexType elementIndex_;
178};
179
180} // end namespace Dumux
181
182#endif
Sub control volumes for cell-centered discretization schemes.
Definition: discretization/cellcentered/subcontrolvolume.hh:51
GridIndexType elementIndex() const
The global index of the element this scv is embedded in.
Definition: discretization/cellcentered/subcontrolvolume.hh:151
CCSubControlVolume & operator=(const CCSubControlVolume &other)
The copy assignment operator.
Definition: discretization/cellcentered/subcontrolvolume.hh:96
Scalar volume() const
The volume of the sub control volume.
Definition: discretization/cellcentered/subcontrolvolume.hh:112
LocalIndexType localDofIndex() const
The element-local index of the dof this scv is embedded in.
Definition: discretization/cellcentered/subcontrolvolume.hh:132
LocalIndexType indexInElement() const
Definition: discretization/cellcentered/subcontrolvolume.hh:139
CCSubControlVolume(const CCSubControlVolume &other)
The copy constructor.
Definition: discretization/cellcentered/subcontrolvolume.hh:89
GlobalPosition corner(LocalIndexType localIdx) const
Return the corner for the given local index.
Definition: discretization/cellcentered/subcontrolvolume.hh:158
T Traits
state the traits public and thus export all types
Definition: discretization/cellcentered/subcontrolvolume.hh:75
typename T::GlobalPosition GlobalPosition
export the type used for global coordinates
Definition: discretization/cellcentered/subcontrolvolume.hh:73
const Geometry & geometry() const
The geometry of the sub control volume.
Definition: discretization/cellcentered/subcontrolvolume.hh:120
CCSubControlVolume(CCSubControlVolume &&other)=default
The move constructor.
const GlobalPosition & dofPosition() const
Definition: discretization/cellcentered/subcontrolvolume.hh:145
CCSubControlVolume(GeometryParamType geometry, GridIndexType elementIndex)
Definition: discretization/cellcentered/subcontrolvolume.hh:80
GridIndexType dofIndex() const
The index of the dof this scv is embedded in (the global index of this scv)
Definition: discretization/cellcentered/subcontrolvolume.hh:126
const GlobalPosition & center() const
The center of the sub control volume.
Definition: discretization/cellcentered/subcontrolvolume.hh:106
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:26
Defines the index types used for grid and local indices.
Definition: adapt.hh:17
Default traits class to be used for the sub-control volumes for the cell-centered finite volume schem...
Definition: discretization/cellcentered/subcontrolvolume.hh:32
typename IndexTraits< GridView >::GridIndex GridIndexType
Definition: discretization/cellcentered/subcontrolvolume.hh:34
typename GridView::template Codim< 0 >::Geometry Geometry
Definition: discretization/cellcentered/subcontrolvolume.hh:33
typename IndexTraits< GridView >::LocalIndex LocalIndexType
Definition: discretization/cellcentered/subcontrolvolume.hh:35
typename GridView::template Codim< 0 >::Entity Element
Definition: discretization/cellcentered/subcontrolvolume.hh:37
typename Element::Geometry::GlobalCoordinate GlobalPosition
Definition: discretization/cellcentered/subcontrolvolume.hh:38
typename GridView::ctype Scalar
Definition: discretization/cellcentered/subcontrolvolume.hh:36
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27
unsigned int LocalIndex
Definition: indextraits.hh:28
Base class for a sub control volume.