My Project
MatchSaturatedVolumeFunctor.hpp
1 //===========================================================================
2 //
3 // File: MatchSaturatedVolumeFunctor.hpp
4 //
5 // Created: Thu May 6 21:28:31 2010
6 //
7 // Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
8 // Jostein R Natvig <jostein.r.natvig@sintef.no>
9 //
10 // $Date$
11 //
12 // $Revision$
13 //
14 //===========================================================================
15 
16 /*
17  Copyright 2010 SINTEF ICT, Applied Mathematics.
18  Copyright 2010 Statoil ASA.
19 
20  This file is part of The Open Reservoir Simulator Project (OpenRS).
21 
22  OpenRS is free software: you can redistribute it and/or modify
23  it under the terms of the GNU General Public License as published by
24  the Free Software Foundation, either version 3 of the License, or
25  (at your option) any later version.
26 
27  OpenRS is distributed in the hope that it will be useful,
28  but WITHOUT ANY WARRANTY; without even the implied warranty of
29  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  GNU General Public License for more details.
31 
32  You should have received a copy of the GNU General Public License
33  along with OpenRS. If not, see <http://www.gnu.org/licenses/>.
34 */
35 
36 #ifndef OPENRS_MATCHSATURATEDVOLUMEFUNCTOR_HEADER
37 #define OPENRS_MATCHSATURATEDVOLUMEFUNCTOR_HEADER
38 
39 
40 #include <utility>
41 #include <vector>
42 #include <algorithm>
43 
44 
45 namespace Opm
46 {
47 
48  template <class GridInterface, class ReservoirProperties>
49  std::pair<double, double> poreSatVolumes(const GridInterface& grid,
50  const ReservoirProperties& rp,
51  const std::vector<double>& sat)
52  {
53  typedef typename GridInterface::CellIterator CellIter;
54  double pore_vol = 0.0;
55  double sat_vol = 0.0;
56  for (CellIter c = grid.cellbegin(); c != grid.cellend(); ++c) {
57  double cell_pore_vol = c->volume()*rp.porosity(c->index());
58  pore_vol += cell_pore_vol;
59  sat_vol += cell_pore_vol*sat[c->index()];
60  }
61  // Dividing by pore volume gives average saturations.
62  return std::make_pair(pore_vol, sat_vol);
63  }
64 
65 
66  template <class GridInterface, class ReservoirProperties>
68  {
69  public:
70  MatchSaturatedVolumeFunctor(const GridInterface& grid,
71  const ReservoirProperties& rp,
72  const std::vector<double>& orig_sat,
73  const std::vector<double>& cap_press)
74  : grid_(grid),
75  rp_(rp),
76  cap_press_(cap_press),
77  orig_satvol_(0.0)
78  {
79  std::pair<double, double> vols = poreSatVolumes(grid, rp, orig_sat);
80  orig_satvol_ = vols.second;
81  int num_cells = orig_sat.size();
82  cp_new_.resize(num_cells);
83  sat_.resize(num_cells);
84  }
85 
86 
87  double operator()(double dp) const
88  {
89  std::transform(cap_press_.begin(), cap_press_.end(), cp_new_.begin(),
90  [dp](const double& input) { return input + dp; });
91  computeSaturations();
92  std::pair<double, double> vols = poreSatVolumes(grid_, rp_, sat_);
93  return (vols.second - orig_satvol_)/vols.first;
94  }
95 
96  const std::vector<double>& lastSaturations() const
97  {
98  return sat_;
99  }
100 
101  private:
102  void computeSaturations() const
103  {
104  int num_cells = grid_.numberOfCells();
105  for (int c = 0; c < num_cells; ++c) {
106  sat_[c] = rp_.saturationFromCapillaryPressure(c, cp_new_[c]);
107  }
108  }
109 
110  const GridInterface& grid_;
111  const ReservoirProperties& rp_;
112  const std::vector<double>& cap_press_;
113  double orig_satvol_;
114  mutable std::vector<double> cp_new_;
115  mutable std::vector<double> sat_;
116  };
117 
118 } // namespace Opm
119 
120 
121 #endif // OPENRS_MATCHSATURATEDVOLUMEFUNCTOR_HEADER
Inverting small matrices.
Definition: ImplicitAssembly.hpp:43
Definition: MatchSaturatedVolumeFunctor.hpp:68