opm-simulators
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  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 */
27 #ifndef EWOMS_QUADRATURE_GEOMETRIES_HH
28 #define EWOMS_QUADRATURE_GEOMETRIES_HH
29 
30 #include <dune/common/fmatrix.hh>
31 #include <dune/common/fvector.hh>
32 #include <dune/geometry/type.hh>
33 
34 #include <array>
35 #include <cassert>
36 
37 namespace Opm {
38 
42 template <class Scalar, unsigned dim>
44 {
45 public:
46  enum { numCorners = (1 << dim) };
47 
48  using LocalPosition = Dune::FieldVector<Scalar, dim>;
49  using GlobalPosition = Dune::FieldVector<Scalar, dim>;
50 
51  Dune::GeometryType type() const
52  { return Dune::GeometryType(/*topologyId=*/(1 << dim) - 1, dim); }
53 
54  template <class CornerContainer>
55  void setCorners(const CornerContainer& corners, std::size_t nCorners)
56  {
57  for (std::size_t cornerIdx = 0; cornerIdx < nCorners; ++cornerIdx) {
58  for (unsigned j = 0; j < dim; ++j) {
59  corners_[cornerIdx][j] = corners[cornerIdx][j];
60  }
61  }
62 
63  center_ = 0;
64  for (std::size_t cornerIdx = 0; cornerIdx < nCorners; ++cornerIdx) {
65  center_ += corners_[cornerIdx];
66  }
67  if (nCorners != 0) {
68  center_ /= static_cast<Scalar>(nCorners);
69  }
70  }
71 
75  const GlobalPosition& center() const
76  { return center_; }
77 
81  GlobalPosition global(const LocalPosition& localPos) const
82  {
83  GlobalPosition globalPos(0.0);
84 
85  for (unsigned cornerIdx = 0; cornerIdx < numCorners; ++cornerIdx) {
86  globalPos.axpy(cornerWeight(localPos, cornerIdx),
87  corners_[cornerIdx]);
88  }
89 
90  return globalPos;
91  }
92 
97  void jacobian(Dune::FieldMatrix<Scalar, dim, dim>& jac,
98  const LocalPosition& localPos) const
99  {
100  jac = 0.0;
101  for (unsigned cornerIdx = 0; cornerIdx < numCorners; ++cornerIdx) {
102  for (unsigned k = 0; k < dim; ++k) {
103  Scalar dWeight_dk = (cornerIdx & (1 << k)) ? 1 : -1;
104  for (unsigned j = 0; j < dim; ++j) {
105  if (k != j) {
106  if (cornerIdx & (1 << j)) {
107  dWeight_dk *= localPos[j];
108  }
109  else {
110  dWeight_dk *= 1 - localPos[j];
111  }
112  }
113  }
114 
115  jac[k].axpy(dWeight_dk, corners_[cornerIdx]);
116  }
117  }
118  }
119 
125  Scalar integrationElement(const LocalPosition& localPos) const
126  {
127  Dune::FieldMatrix<Scalar, dim, dim> jac;
128  jacobian(jac, localPos);
129  return jac.determinant();
130  }
131 
135  const GlobalPosition& corner(unsigned cornerIdx) const
136  { return corners_[cornerIdx]; }
137 
142  Scalar cornerWeight(const LocalPosition& localPos, unsigned cornerIdx) const
143  {
144  // this code is based on the Q1 finite element code from
145  // dune-localfunctions
146  Scalar weight = 1.0;
147  for (unsigned j = 0; j < dim; ++j) {
148  weight *= (cornerIdx & (1 << j)) ? localPos[j] : (1 - localPos[j]);
149  }
150 
151  return weight;
152  }
153 
154 private:
155  std::array<GlobalPosition, numCorners> corners_{};
156  GlobalPosition center_;
157 };
158 
159 } // namespace Opm
160 
161 #endif // EWOMS_QUADRATURE_GEOMETRY_HH
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
const GlobalPosition & corner(unsigned cornerIdx) const
Return the position of the corner with a given index.
Definition: quadraturegeometries.hh:135
Quadrature geometry for quadrilaterals.
Definition: quadraturegeometries.hh:43
GlobalPosition global(const LocalPosition &localPos) const
Convert a local coordinate into a global one.
Definition: quadraturegeometries.hh:81
const GlobalPosition & center() const
Returns the center of weight of the polyhedron.
Definition: quadraturegeometries.hh:75
Scalar cornerWeight(const LocalPosition &localPos, unsigned cornerIdx) const
Return the weight of an individual corner for the local to global mapping.
Definition: quadraturegeometries.hh:142
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:125
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:97