quadraturegeometries.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  Copyright (C) 2012-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
25 #ifndef EWOMS_QUADRATURE_GEOMETRIES_HH
26 #define EWOMS_QUADRATURE_GEOMETRIES_HH
27 
28 #include <dune/common/fvector.hh>
29 #include <dune/common/fmatrix.hh>
30 #include <dune/geometry/type.hh>
31 
32 namespace Ewoms {
36 template <class Scalar, int dim>
38 {
39 public:
40  enum { numCorners = (1 << dim) };
41 
42  typedef Dune::FieldVector<Scalar, dim> LocalPosition;
43  typedef Dune::FieldVector<Scalar, dim> GlobalPosition;
44 
45  Dune::GeometryType type() const
46  { return Dune::GeometryType(Dune::GeometryType::cube, dim); }
47 
48  template <class CornerContainer>
49  void setCorners(const CornerContainer &corners, unsigned numCorners)
50  {
51  unsigned cornerIdx;
52  for (cornerIdx = 0; cornerIdx < numCorners; ++cornerIdx) {
53  for (int j = 0; j < dim; ++j)
54  corners_[cornerIdx][j] = corners[cornerIdx][j];
55  }
56  assert(cornerIdx == numCorners);
57 
58  center_ = 0;
59  for (cornerIdx = 0; cornerIdx < numCorners; ++cornerIdx)
60  center_ += corners_[cornerIdx];
61  center_ /= numCorners;
62  }
63 
67  const GlobalPosition &center() const
68  { return center_; }
69 
73  GlobalPosition global(const LocalPosition &localPos) const
74  {
75  GlobalPosition globalPos(0.0);
76 
77  for (int cornerIdx = 0; cornerIdx < numCorners; ++cornerIdx)
78  globalPos.axpy(cornerWeight(localPos, cornerIdx),
79  corners_[cornerIdx]);
80 
81  return globalPos;
82  }
83 
88  void jacobian(Dune::FieldMatrix<Scalar, dim, dim> &jac,
89  const LocalPosition &localPos) const
90  {
91  jac = 0.0;
92  for (int cornerIdx = 0; cornerIdx < numCorners; ++cornerIdx) {
93  for (int k = 0; k < dim; ++k) {
94  Scalar dWeight_dk = (cornerIdx & (1 << k)) ? 1 : -1;
95  for (int j = 0; j < dim; ++j) {
96  if (k != j) {
97  if (cornerIdx & (1 << j))
98  dWeight_dk *= localPos[j];
99  else
100  dWeight_dk *= 1 - localPos[j];
101  ;
102  }
103  }
104 
105  jac[k].axpy(dWeight_dk, corners_[cornerIdx]);
106  }
107  }
108  }
109 
115  Scalar integrationElement(const LocalPosition &localPos) const
116  {
117  Dune::FieldMatrix<Scalar, dim, dim> jac;
118  jacobian(jac, localPos);
119  return jac.determinant();
120  }
121 
125  const GlobalPosition &corner(int cornerIdx) const
126  { return corners_[cornerIdx]; }
127 
132  Scalar cornerWeight(const LocalPosition &localPos, int cornerIdx) const
133  {
134  GlobalPosition globalPos(0.0);
135 
136  // this code is based on the Q1 finite element code from
137  // dune-localfunctions
138  Scalar weight = 1.0;
139  for (int j = 0; j < dim; ++j)
140  weight *= (cornerIdx & (1 << j)) ? localPos[j] : (1 - localPos[j]);
141 
142  return weight;
143  }
144 
145 private:
146  GlobalPosition corners_[numCorners];
147  GlobalPosition center_;
148 };
149 
150 } // namespace Ewoms
151 
152 #endif // EWOMS_QUADRATURE_GEOMETRY_HH
Scalar integrationElement(const LocalPosition &localPos) const
Return the determinant of the Jacobian of the mapping from local to global coordinates at a given loc...
Definition: quadraturegeometries.hh:115
GlobalPosition global(const LocalPosition &localPos) const
Convert a local coordinate into a global one.
Definition: quadraturegeometries.hh:73
const GlobalPosition & center() const
Returns the center of weight of the polyhedron.
Definition: quadraturegeometries.hh:67
Quadrature geometry for quadrilaterals.
Definition: quadraturegeometries.hh:37
void setCorners(const CornerContainer &corners, unsigned numCorners)
Definition: quadraturegeometries.hh:49
Definition: baseauxiliarymodule.hh:35
Dune::FieldVector< Scalar, dim > GlobalPosition
Definition: quadraturegeometries.hh:43
void jacobian(Dune::FieldMatrix< Scalar, dim, dim > &jac, const LocalPosition &localPos) const
Returns the Jacobian matrix of the local to global mapping at a given local position.
Definition: quadraturegeometries.hh:88
const GlobalPosition & corner(int cornerIdx) const
Return the position of the corner with a given index.
Definition: quadraturegeometries.hh:125
Dune::FieldVector< Scalar, dim > LocalPosition
Definition: quadraturegeometries.hh:42
Dune::GeometryType type() const
Definition: quadraturegeometries.hh:45
Scalar cornerWeight(const LocalPosition &localPos, int cornerIdx) const
Return the weight of an individual corner for the local to global mapping.
Definition: quadraturegeometries.hh:132
Definition: quadraturegeometries.hh:40