MatchSaturatedVolumeFunctor.hpp
Go to the documentation of this file.
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 <boost/bind.hpp>
41 #include <utility>
42 #include <vector>
43 #include <algorithm>
44 
45 
46 namespace Opm
47 {
48 
49  template <class GridInterface, class ReservoirProperties>
50  std::pair<double, double> poreSatVolumes(const GridInterface& grid,
51  const ReservoirProperties& rp,
52  const std::vector<double>& sat)
53  {
54  typedef typename GridInterface::CellIterator CellIter;
55  double pore_vol = 0.0;
56  double sat_vol = 0.0;
57  for (CellIter c = grid.cellbegin(); c != grid.cellend(); ++c) {
58  double cell_pore_vol = c->volume()*rp.porosity(c->index());
59  pore_vol += cell_pore_vol;
60  sat_vol += cell_pore_vol*sat[c->index()];
61  }
62  // Dividing by pore volume gives average saturations.
63  return std::make_pair(pore_vol, sat_vol);
64  }
65 
66 
67  template <class GridInterface, class ReservoirProperties>
69  {
70  public:
71  MatchSaturatedVolumeFunctor(const GridInterface& grid,
72  const ReservoirProperties& rp,
73  const std::vector<double>& orig_sat,
74  const std::vector<double>& cap_press)
75  : grid_(grid),
76  rp_(rp),
77  cap_press_(cap_press),
78  orig_satvol_(0.0)
79  {
80  std::pair<double, double> vols = poreSatVolumes(grid, rp, orig_sat);
81  orig_satvol_ = vols.second;
82  int num_cells = orig_sat.size();
83  cp_new_.resize(num_cells);
84  sat_.resize(num_cells);
85  }
86 
87 
88  double operator()(double dp) const
89  {
90  std::transform(cap_press_.begin(), cap_press_.end(), cp_new_.begin(),
91  boost::bind(std::plus<double>(), dp, _1));
92  computeSaturations();
93  std::pair<double, double> vols = poreSatVolumes(grid_, rp_, sat_);
94  return (vols.second - orig_satvol_)/vols.first;
95  }
96 
97  const std::vector<double>& lastSaturations() const
98  {
99  return sat_;
100  }
101 
102  private:
103  void computeSaturations() const
104  {
105  int num_cells = grid_.numberOfCells();
106  for (int c = 0; c < num_cells; ++c) {
107  sat_[c] = rp_.saturationFromCapillaryPressure(c, cp_new_[c]);
108  }
109  }
110 
111  const GridInterface& grid_;
112  const ReservoirProperties& rp_;
113  const std::vector<double>& cap_press_;
114  double orig_satvol_;
115  mutable std::vector<double> cp_new_;
116  mutable std::vector<double> sat_;
117  };
118 
119 } // namespace Opm
120 
121 
122 #endif // OPENRS_MATCHSATURATEDVOLUMEFUNCTOR_HEADER
Definition: BlackoilFluid.hpp:31
std::pair< double, double > poreSatVolumes(const GridInterface &grid, const ReservoirProperties &rp, const std::vector< double > &sat)
Definition: MatchSaturatedVolumeFunctor.hpp:50
double operator()(double dp) const
Definition: MatchSaturatedVolumeFunctor.hpp:88
Definition: MatchSaturatedVolumeFunctor.hpp:68
MatchSaturatedVolumeFunctor(const GridInterface &grid, const ReservoirProperties &rp, const std::vector< double > &orig_sat, const std::vector< double > &cap_press)
Definition: MatchSaturatedVolumeFunctor.hpp:71
const std::vector< double > & lastSaturations() const
Definition: MatchSaturatedVolumeFunctor.hpp:97