All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ecfvstencil.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  This file is part of the Open Porous Media project (OPM).
5 
6  OPM 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 2 of the License, or
9  (at your option) any later version.
10 
11  OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18 
19  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
28 #ifndef EWOMS_ECFV_STENCIL_HH
29 #define EWOMS_ECFV_STENCIL_HH
30 
33 
34 #include <dune/grid/common/mcmgmapper.hh>
35 #include <dune/grid/common/intersectioniterator.hh>
36 #include <dune/geometry/type.hh>
37 #include <dune/common/fvector.hh>
38 #include <dune/common/version.hh>
39 
40 #include <vector>
41 
42 namespace Ewoms {
53 template <class Scalar,
54  class GridView,
55  bool needFaceIntegrationPos = true,
56  bool needFaceNormal = true>
58 {
59  enum { dimWorld = GridView::dimensionworld };
60 
61  typedef typename GridView::ctype CoordScalar;
62  typedef typename GridView::Intersection Intersection;
63  typedef typename GridView::template Codim<0>::Entity Element;
64 
65  typedef Dune::MultipleCodimMultipleGeomTypeMapper<GridView,
66  Dune::MCMGElementLayout> ElementMapper;
67 
68  typedef Dune::FieldVector<CoordScalar, dimWorld> GlobalPosition;
69 
70  typedef Dune::FieldVector<Scalar, dimWorld> WorldVector;
71 
72 public:
73  typedef Element Entity;
74  typedef ElementMapper Mapper;
75 
76  typedef typename Element::Geometry LocalGeometry;
77 
87  {
88  public:
89  // default construct an uninitialized object.
90  // this is only here because std::vector needs it...
92  {}
93 
94  SubControlVolume(const Element& element)
95  : element_(element)
96  { update(); }
97 
98  void update(const Element& element)
99  { element_ = element; }
100 
101  void update()
102  {
103  const auto& geometry = element_.geometry();
104  centerPos_ = geometry.center();
105  volume_ = geometry.volume();
106  }
107 
111  const GlobalPosition& globalPos() const
112  { return centerPos_; }
113 
117  const GlobalPosition& center() const
118  { return centerPos_; }
119 
123  Scalar volume() const
124  { return volume_; }
125 
129  const LocalGeometry geometry() const
130  { return element_.geometry(); }
131 
132  private:
133  GlobalPosition centerPos_;
134  Scalar volume_;
135  Element element_;
136  };
137 
141  template <bool needNormal, bool needIntegrationPos>
143  {
144  public:
146  {}
147 
148  EcfvSubControlVolumeFace(const Intersection& intersection, unsigned localNeighborIdx)
149  {
150  exteriorIdx_ = static_cast<unsigned short>(localNeighborIdx);
151 
152  if (needNormal)
153  (*normal_) = intersection.centerUnitOuterNormal();
154 
155  const auto& geometry = intersection.geometry();
156  if (needIntegrationPos)
157  (*integrationPos_) = geometry.center();
158  area_ = geometry.volume();
159  }
160 
165  unsigned short interiorIndex() const
166  {
167  // The local index of the control volume in the interior
168  // of a face of the stencil in the element centered finite
169  // volume discretization is always the "central"
170  // element. In this implementation this element always has
171  // index 0....
172  return 0;
173  }
174 
179  unsigned short exteriorIndex() const
180  { return exteriorIdx_; }
181 
186  const GlobalPosition& integrationPos() const
187  { return *integrationPos_; }
188 
193  const WorldVector& normal() const
194  { return *normal_; }
195 
199  Scalar area() const
200  { return area_; }
201 
202  private:
205  Scalar area_;
206 
207  unsigned short exteriorIdx_;
208  };
209 
210  typedef EcfvSubControlVolumeFace<needFaceIntegrationPos, needFaceNormal> SubControlVolumeFace;
211 
212  EcfvStencil(const GridView& gridView, const Mapper& mapper)
213  : gridView_(gridView)
214  , elementMapper_(mapper)
215  { }
216 
217  void updateTopology(const Element& element)
218  {
219  auto isIt = gridView_.ibegin(element);
220  const auto& endIsIt = gridView_.iend(element);
221 
222  // add the "center" element of the stencil
223  subControlVolumes_.clear();
224  subControlVolumes_.emplace_back(/*SubControlVolume(*/element/*)*/);
225  elements_.clear();
226  elements_.emplace_back(element);
227 
228  interiorFaces_.clear();
229  boundaryFaces_.clear();
230 
231  for (; isIt != endIsIt; ++isIt) {
232  const auto& intersection = *isIt;
233  // if the current intersection has a neighbor, add a
234  // degree of freedom and an internal face, else add a
235  // boundary face
236  if (intersection.neighbor()) {
237  elements_.emplace_back( intersection.outside() );
238  subControlVolumes_.emplace_back(/*SubControlVolume(*/elements_.back()/*)*/);
239  interiorFaces_.emplace_back(/*SubControlVolumeFace(*/intersection, subControlVolumes_.size() - 1/*)*/);
240  }
241  else {
242  boundaryFaces_.emplace_back(/*SubControlVolumeFace(*/intersection, - 10000/*)*/);
243  }
244  }
245  }
246 
247  void updatePrimaryTopology(const Element& element)
248  {
249  // add the "center" element of the stencil
250  subControlVolumes_.clear();
251  subControlVolumes_.emplace_back(/*SubControlVolume(*/element/*)*/);
252  elements_.clear();
253  elements_.emplace_back(element);
254  }
255 
256  void update(const Element& element)
257  {
258  updateTopology(element);
259  }
260 
261  void updateCenterGradients()
262  {
263  assert(false); // not yet implemented
264  }
265 
269  const Element& element() const
270  { return element( 0 ); }
271 
276  const GridView& gridView() const
277  { return *gridView_; }
278 
283  size_t numDof() const
284  { return subControlVolumes_.size(); }
285 
295  size_t numPrimaryDof() const
296  { return 1; }
297 
302  unsigned globalSpaceIndex(unsigned dofIdx) const
303  {
304  assert(0 <= dofIdx && dofIdx < numDof());
305 
306  return static_cast<unsigned>(elementMapper_.index(element(dofIdx)));
307  }
308 
312  Dune::PartitionType partitionType(unsigned dofIdx) const
313  { return elements_[dofIdx]->partitionType(); }
314 
322  const Element& element(unsigned dofIdx) const
323  {
324  assert(0 <= dofIdx && dofIdx < numDof());
325 
326  return elements_[dofIdx];
327  }
328 
333  const Entity& entity(unsigned dofIdx) const
334  {
335  return element( dofIdx );
336  }
337 
342  const SubControlVolume& subControlVolume(unsigned dofIdx) const
343  { return subControlVolumes_[dofIdx]; }
344 
348  size_t numInteriorFaces() const
349  { return interiorFaces_.size(); }
350 
355  const SubControlVolumeFace& interiorFace(unsigned bfIdx) const
356  { return interiorFaces_[bfIdx]; }
357 
361  size_t numBoundaryFaces() const
362  { return boundaryFaces_.size(); }
363 
368  const SubControlVolumeFace& boundaryFace(unsigned bfIdx) const
369  { return boundaryFaces_[bfIdx]; }
370 
371 protected:
372  const GridView& gridView_;
373  const ElementMapper& elementMapper_;
374 
375  std::vector<Element> elements_;
376  std::vector<SubControlVolume> subControlVolumes_;
377  std::vector<SubControlVolumeFace> interiorFaces_;
378  std::vector<SubControlVolumeFace> boundaryFaces_;
379 };
380 
381 } // namespace Ewoms
382 
383 
384 #endif
385 
const GlobalPosition & integrationPos() const
Returns the global position of the face&#39;s integration point.
Definition: ecfvstencil.hh:186
size_t numDof() const
Returns the number of degrees of freedom which the current element interacts with.
Definition: ecfvstencil.hh:283
const GlobalPosition & globalPos() const
The global position associated with the sub-control volume.
Definition: ecfvstencil.hh:111
Represents the stencil (finite volume geometry) of a single element in the ECFV discretization.
Definition: ecfvstencil.hh:57
unsigned short interiorIndex() const
Returns the local index of the degree of freedom to the face&#39;s interior.
Definition: ecfvstencil.hh:165
Represents a face of a sub-control volume.
Definition: ecfvstencil.hh:142
Scalar area() const
Returns the area [m^2] of the face.
Definition: ecfvstencil.hh:199
Represents a sub-control volume.
Definition: ecfvstencil.hh:86
size_t numInteriorFaces() const
Returns the number of interior faces of the stencil.
Definition: ecfvstencil.hh:348
Dune::PartitionType partitionType(unsigned dofIdx) const
Return partition type of a given degree of freedom.
Definition: ecfvstencil.hh:312
const Entity & entity(unsigned dofIdx) const
Return the entity given the index of a degree of freedom.
Definition: ecfvstencil.hh:333
const Element & element(unsigned dofIdx) const
Return the element given the index of a degree of freedom.
Definition: ecfvstencil.hh:322
const SubControlVolumeFace & interiorFace(unsigned bfIdx) const
Returns the face object belonging to a given face index in the interior of the domain.
Definition: ecfvstencil.hh:355
const GlobalPosition & center() const
The center of the sub-control volume.
Definition: ecfvstencil.hh:117
A simple class which only stores a given member attribute if a boolean condition is true...
size_t numBoundaryFaces() const
Returns the number of boundary faces of the stencil.
Definition: ecfvstencil.hh:361
unsigned short exteriorIndex() const
Returns the local index of the degree of freedom to the face&#39;s outside.
Definition: ecfvstencil.hh:179
size_t numPrimaryDof() const
Returns the number of degrees of freedom which are contained by within the current element...
Definition: ecfvstencil.hh:295
const SubControlVolume & subControlVolume(unsigned dofIdx) const
Returns the sub-control volume object belonging to a given degree of freedom.
Definition: ecfvstencil.hh:342
const WorldVector & normal() const
Returns the outer unit normal at the face&#39;s integration point.
Definition: ecfvstencil.hh:193
Quadrature geometry for quadrilaterals.
const GridView & gridView() const
Return the grid view of the element to which the stencil refers.
Definition: ecfvstencil.hh:276
const SubControlVolumeFace & boundaryFace(unsigned bfIdx) const
Returns the boundary face object belonging to a given boundary face index.
Definition: ecfvstencil.hh:368
const LocalGeometry geometry() const
The geometry of the sub-control volume.
Definition: ecfvstencil.hh:129
Scalar volume() const
The volume [m^3] occupied by the sub-control volume.
Definition: ecfvstencil.hh:123
unsigned globalSpaceIndex(unsigned dofIdx) const
Return the global space index given the index of a degree of freedom.
Definition: ecfvstencil.hh:302
const Element & element() const
Return the element to which the stencil refers.
Definition: ecfvstencil.hh:269