miscUtilities_impl.hpp
Go to the documentation of this file.
1#include <opm/core/grid/GridHelpers.hpp>
2#include <opm/core/wells.h>
4
5namespace Opm
6{
15 template<class CC, class FC, class FC1, class CV>
16 void estimateCellVelocity(int number_of_cells,
17 int number_of_faces,
18 FC begin_face_centroids,
19 FC1 face_cells,
20 CC begin_cell_centroids,
21 CV begin_cell_volumes,
22 int dimension,
23 const std::vector<double>& face_flux,
24 std::vector<double>& cell_velocity)
25 {
26 cell_velocity.clear();
27 cell_velocity.resize(number_of_cells*dimension, 0.0);
28 for (int face = 0; face < number_of_faces; ++face) {
29 int c[2] = { face_cells(face, 0), face_cells(face, 1) };
30 FC fc = UgGridHelpers::increment(begin_face_centroids, face, dimension);
31 double flux = face_flux[face];
32 for (int i = 0; i < 2; ++i) {
33 if (c[i] >= 0) {
34 CC cc = UgGridHelpers::increment(begin_cell_centroids, c[i], dimension);
35 for (int d = 0; d < dimension; ++d) {
36 double v_contrib = UgGridHelpers::getCoordinate(fc, d) - UgGridHelpers::getCoordinate(cc, d);
37 v_contrib *= flux/begin_cell_volumes[c[i]];
38 cell_velocity[c[i]*dimension + d] += (i == 0) ? v_contrib : -v_contrib;
39 }
40 }
41 }
42 }
43 }
44
45 template<class T>
46 void computePorevolume(int number_of_cells,
47 T begin_cell_volume,
48 const double* porosity,
49 std::vector<double>& porevol)
50 {
51 porevol.resize(number_of_cells);
52 std::transform(porosity, porosity + number_of_cells,
53 begin_cell_volume,
54 porevol.begin(),
55 std::multiplies<double>());
56 }
57
64 template<class T>
65 void computePorevolume(int number_of_cells,
66 T begin_cell_volumes,
67 const double* porosity,
68 const RockCompressibility& rock_comp,
69 const std::vector<double>& pressure,
70 std::vector<double>& porevol)
71 {
72 porevol.resize(number_of_cells);
73 for (int i = 0; i < number_of_cells; ++i) {
74 porevol[i] = porosity[i]*begin_cell_volumes[i]*rock_comp.poroMult(pressure[i]);
75 }
76 }
77
78 template<class T>
79 void computeWDP(const Wells& wells, int number_of_cells, T begin_cell_centroids, const std::vector<double>& saturations,
80 const double* densities, const double gravity, const bool per_grid_cell,
81 std::vector<double>& wdp)
82 {
83 const int nw = wells.number_of_wells;
84 const size_t np = per_grid_cell ?
85 saturations.size()/number_of_cells
86 : saturations.size()/wells.well_connpos[nw];
87 // Simple for now:
88 for (int i = 0; i < nw; i++) {
89 double depth_ref = wells.depth_ref[i];
90 for (int j = wells.well_connpos[i]; j < wells.well_connpos[i + 1]; j++) {
91 int cell = wells.well_cells[j];
92
93 // Is this correct wrt. depth_ref?
94 double cell_depth = UgGridHelpers
95 ::getCoordinate(UgGridHelpers::increment(begin_cell_centroids, cell, 3), 2);
96
97 double saturation_sum = 0.0;
98 for (size_t p = 0; p < np; p++) {
99 if (!per_grid_cell) {
100 saturation_sum += saturations[j * np + p];
101 } else {
102 saturation_sum += saturations[np * cell + p];
103 }
104 }
105 if (saturation_sum == 0) {
106 saturation_sum = 1.0;
107 }
108 double density = 0.0;
109 for (size_t p = 0; p < np; p++) {
110 if (!per_grid_cell) {
111 density += saturations[j * np + p] * densities[p] / saturation_sum;
112 } else {
113 // Is this a smart way of doing it?
114 density += saturations[np * cell + p] * densities[p] / saturation_sum;
115 }
116 }
117
118 // Is the sign correct?
119 wdp.push_back(density * (cell_depth - depth_ref) * gravity);
120 }
121 }
122 }
123}
Definition: RockCompressibility.hpp:33
double poroMult(double pressure) const
Porosity multiplier.
Definition: AnisotropicEikonal.hpp:44
void computeWDP(const Wells &wells, const UnstructuredGrid &grid, const std::vector< double > &saturations, const double *densities, const double gravity, const bool per_grid_cell, std::vector< double > &wdp)
void estimateCellVelocity(const UnstructuredGrid &grid, const std::vector< double > &face_flux, std::vector< double > &cell_velocity)
Estimates a scalar cell velocity from face fluxes.
void computePorevolume(const UnstructuredGrid &grid, const double *porosity, std::vector< double > &porevol)
Computes pore volume of all cells in a grid.
Definition: wells.h:51
double * depth_ref
Definition: wells.h:63
int * well_connpos
Definition: wells.h:81
int number_of_wells
Definition: wells.h:52
int * well_cells
Definition: wells.h:87