TransTpfa_impl.hpp
Go to the documentation of this file.
4 
5 #include <cmath>
6 
7 namespace Dune
8 {
9 class CpGrid;
10 }
11 
12 namespace Opm
13 {
14 namespace UgGridHelpers
15 {
16 int dimensions(const Dune::CpGrid&);
17 
18 double faceArea(const Dune::CpGrid&, int);
19 }
20 }
21 
22 namespace
23 {
24 #ifdef HAVE_DUNE_CORNERPOINT
25 inline const double* multiplyFaceNormalWithArea(const Dune::CpGrid& grid, int face_index, const double* in)
26 {
28  double* out=new double[d];
29  double area=Opm::UgGridHelpers::faceArea(grid, face_index);
30 
31  for(int i=0;i<d;++i)
32  out[i]=in[i]*area;
33  return out;
34 }
35 
36 inline void maybeFreeFaceNormal(const Dune::CpGrid&, const double* array)
37 {
38  delete[] array;
39 }
40 #endif // HAVE_DUNE_CORNERPOINT
41 
42 inline const double* multiplyFaceNormalWithArea(const UnstructuredGrid&, int, const double* in)
43 {
44  return in;
45 }
46 
47 inline void maybeFreeFaceNormal(const UnstructuredGrid&, const double*)
48 {}
49 }
50 
51 /* ---------------------------------------------------------------------- */
52 /* htrans <- sum(C(:,i) .* K(cellNo,:) .* N(:,j), 2) ./ sum(C.*C, 2) */
53 /* ---------------------------------------------------------------------- */
54 template<class Grid>
55 void
56 tpfa_htrans_compute(const Grid* G, const double *perm, double *htrans)
57 /* ---------------------------------------------------------------------- */
58 {
59  using namespace Opm::UgGridHelpers;
60  int d, j;
61  double s, dist, denom;
62 
63  double Kn[3];
65  typename Cell2FacesTraits<Grid>::Type c2f = cell2Faces(*G);
66  typename FaceCellTraits<Grid>::Type face_cells = faceCells(*G);
67 
68  const double *n;
69  const double *K;
70 
71  MAT_SIZE_T nrows, ncols, ldA, incx, incy;
72  double a1, a2;
73 
74  d = dimensions(*G);
75 
76  nrows = ncols = ldA = d;
77  incx = incy = 1 ;
78  a1 = 1.0; a2 = 0.0 ;
79 
80  for (int c =0, i = 0; c < numCells(*G); c++) {
81  K = perm + (c * d * d);
82 
83  typedef typename Cell2FacesTraits<Grid>::Type::row_type FaceRow;
84  FaceRow faces = c2f[c];
85 
86  for(typename FaceRow::const_iterator f=faces.begin(), end=faces.end();
87  f!=end; ++f, ++i)
88  {
89  s = 2.0*(face_cells(*f, 0) == c) - 1.0;
90  n = faceNormal(*G, *f);
91  const double* nn=multiplyFaceNormalWithArea(*G, *f, n);
92  const double* fc = &(faceCentroid(*G, *f)[0]);
93  dgemv_("No Transpose", &nrows, &ncols,
94  &a1, K, &ldA, nn, &incx, &a2, &Kn[0], &incy);
95  maybeFreeFaceNormal(*G, nn);
96 
97  htrans[i] = denom = 0.0;
98  for (j = 0; j < d; j++) {
99  dist = fc[j] - getCoordinate(cc, j);
100 
101  htrans[i] += s * dist * Kn[j];
102  denom += dist * dist;
103  }
104 
105  assert (denom > 0);
106  htrans[i] /= denom;
107  htrans[i] = std::abs(htrans[i]);
108  }
109  // Move to next cell centroid.
110  cc = increment(cc, 1, d);
111  }
112 }
113 
114 
115 /* ---------------------------------------------------------------------- */
116 template<class Grid>
117 void
118 tpfa_trans_compute(const Grid* G, const double *htrans, double *trans)
119 /* ---------------------------------------------------------------------- */
120 {
121  using namespace Opm::UgGridHelpers;
122 
123  for (int f = 0; f < numFaces(*G); f++) {
124  trans[f] = 0.0;
125  }
126 
127  typename Cell2FacesTraits<Grid>::Type c2f = cell2Faces(*G);
128 
129  for (int c = 0, i = 0; c < numCells(*G); c++) {
130  typedef typename Cell2FacesTraits<Grid>::Type::row_type FaceRow;
131  FaceRow faces = c2f[c];
132 
133  for(typename FaceRow::const_iterator f=faces.begin(), end=faces.end();
134  f!=end; ++f, ++i)
135  {
136  trans[*f] += 1.0 / htrans[i];
137  }
138  }
139 
140  for (int f = 0; f < numFaces(*G); f++) {
141  trans[f] = 1.0 / trans[f];
142  }
143 }
144 
145 
146 /* ---------------------------------------------------------------------- */
147  template<class Grid>
148 void
150  const double *totmob,
151  const double *htrans,
152  double *trans)
153 /* ---------------------------------------------------------------------- */
154 {
155  using namespace Opm::UgGridHelpers;
156 
157  for (int f = 0; f < numFaces(*G); f++) {
158  trans[f] = 0.0;
159  }
160 
161  typename Cell2FacesTraits<Grid>::Type c2f = cell2Faces(*G);
162 
163  for (int c = 0, i = 0; c < numCells(*G); c++) {
164  typedef typename Cell2FacesTraits<Grid>::Type::row_type FaceRow;
165  FaceRow faces = c2f[c];
166 
167  for(typename FaceRow::const_iterator f=faces.begin(), end=faces.end();
168  f!=end; ++f, ++i)
169  {
170  trans[*f] += 1.0 / (totmob[c] * htrans[i]);
171  }
172  }
173 
174  for (int f = 0; f < numFaces(*G); f++) {
175  trans[f] = 1.0 / trans[f];
176  }
177 }
Definition: grid.h:98
void dgemv_(const char *trans, const MAT_SIZE_T *m, const MAT_SIZE_T *n, const double *a1, const double *A, const MAT_SIZE_T *ldA, const double *x, const MAT_SIZE_T *incX, const double *a2, double *y, const MAT_SIZE_T *incY)
double getCoordinate(T *cc, int i)
Get the i-th corrdinate of a centroid.
Definition: GridHelpers.hpp:337
FaceCellTraits< UnstructuredGrid >::Type faceCells(const UnstructuredGrid &grid)
Get the face to cell mapping of a grid.
Definition: AnisotropicEikonal.hpp:43
void tpfa_trans_compute(const Grid *G, const double *htrans, double *trans)
Definition: TransTpfa_impl.hpp:118
const double * faceNormal(const UnstructuredGrid &grid, int face_index)
Get the normal of a face.
int numCells(const UnstructuredGrid &grid)
Get the number of cells of a grid.
int numFaces(const UnstructuredGrid &grid)
Get the number of faces of a grid.
Definition: TransTpfa_impl.hpp:7
Traits of the cell centroids of a grid.
Definition: GridHelpers.hpp:122
Definition: GridHelpers.hpp:28
const double area
Definition: Units.hpp:149
CellCentroidTraits< UnstructuredGrid >::IteratorType beginCellCentroids(const UnstructuredGrid &grid)
Get an iterator over the cell centroids positioned at the first cell.
void tpfa_htrans_compute(const Grid *G, const double *perm, double *htrans)
Definition: TransTpfa_impl.hpp:56
int dimensions(const UnstructuredGrid &grid)
Get the dimensions of a grid.
Maps the grid type to the associated type of the cell to faces mapping.
Definition: GridHelpers.hpp:243
T * increment(T *cc, int i, int dim)
Increment an iterator over an array that reresents a dense row-major matrix with dims columns...
Definition: GridHelpers.hpp:318
const UnstructuredGrid & grid
Definition: ColumnExtract.hpp:31
#define MAT_SIZE_T
Definition: blas_lapack.h:34
Cell2FacesTraits< UnstructuredGrid >::Type cell2Faces(const UnstructuredGrid &grid)
Get the cell to faces mapping of a grid.
const double * faceCentroid(const UnstructuredGrid &grid, int face_index)
Get the cell centroid of a face.
Traits of the face to attached cell mappping of a grid.
Definition: GridHelpers.hpp:300
void tpfa_eff_trans_compute(const Grid *G, const double *totmob, const double *htrans, double *trans)
Definition: TransTpfa_impl.hpp:149
double faceArea(const UnstructuredGrid &grid, int face_index)
Get the area of a face.