opm-upscaling
setupGridAndProps.hpp
1 //===========================================================================
2 //
3 // File: setupGridAndProps.hpp
4 //
5 // Created: Tue Aug 11 14:47:35 2009
6 //
7 // Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
8 // Bård Skaflestad <bard.skaflestad@sintef.no>
9 //
10 // $Date$
11 //
12 // $Revision$
13 //
14 //===========================================================================
15 
16 /*
17  Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
18  Copyright 2009, 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 OPM_SETUPGRIDANDPROPS_HEADER
37 #define OPM_SETUPGRIDANDPROPS_HEADER
38 
39 #include <opm/common/utility/parameters/ParameterGroup.hpp>
40 #include <opm/input/eclipse/Units/Units.hpp>
41 #include <opm/grid/CpGrid.hpp>
42 #include <opm/porsol/common/ReservoirPropertyCapillary.hpp>
43 
44 #include <opm/input/eclipse/Deck/Deck.hpp>
45 #include <opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp>
46 #include <opm/input/eclipse/Parser/Parser.hpp>
47 
48 #include <opm/common/utility/platform_dependent/disable_warnings.h>
49 
50 #include <opm/common/utility/FileSystem.hpp>
51 
52 #include <opm/common/utility/platform_dependent/reenable_warnings.h>
53 
54 namespace Opm
55 {
56 
58  template <class RP>
59  bool useJ()
60  {
61  return false;
62  }
63 
64  template<>
65  bool useJ< ReservoirPropertyCapillary<3> >();
66 
70  template <template <int> class ResProp>
71  inline void setupGridAndProps(const Opm::ParameterGroup& param,
72  Dune::CpGrid& grid,
73  ResProp<3>& res_prop)
74  {
75  // Initialize grid and reservoir properties.
76  // Parts copied from Dune::CpGrid::init().
77  std::string fileformat = param.getDefault<std::string>("fileformat", "cartesian");
78  if (fileformat == "eclipse") {
79  std::string ecl_file = param.get<std::string>("filename");
80 
81  Opm::Parser parser;
82  auto deck = parser.parseFile(ecl_file);
83  if (param.has("z_tolerance")) {
84  std::cerr << "****** Warning: z_tolerance parameter is obsolete, use PINCH in deck input instead\n";
85  }
86  bool periodic_extension = param.getDefault<bool>("periodic_extension", false);
87  bool clip_z = param.getDefault<bool>("clip_z", false);
88  bool turn_normals = param.getDefault<bool>("turn_normals", false);
89  {
90  Opm::EclipseGrid inputGrid(deck);
91  grid.processEclipseFormat(&inputGrid, /* ecl_state = */ nullptr,
92  periodic_extension,
93  turn_normals,
94  clip_z,
95  /* pinchActive = */ true,
96  /* edge_conformal = */ false);
97  }
98  // Save EGRID file in case we are writing ECL output.
99  if (param.getDefault("output_ecl", false)) {
100  OPM_THROW(std::runtime_error, "Saving to EGRID files is not yet implemented");
101  /*
102  Opm::filesystem::path ecl_path(ecl_file);
103  const std::vector<int>& globalCell = grid.globalCell();
104  ecl_path.replace_extension(".EGRID");
105  parser.saveEGRID(ecl_path.string() , (int) globalCell.size() , &globalCell[0]);
106  */
107  }
108  double perm_threshold_md = param.getDefault("perm_threshold_md", 0.0);
109  double perm_threshold = Opm::unit::convert::from(perm_threshold_md, Opm::prefix::milli*Opm::unit::darcy);
110  std::string rock_list = param.getDefault<std::string>("rock_list", "no_list");
111  std::string* rl_ptr = (rock_list == "no_list") ? 0 : &rock_list;
112  bool use_j = param.getDefault("use_jfunction_scaling", useJ<ResProp<3> >());
113  double sigma = 1.0;
114  double theta = 0.0;
115  if (use_j) {
116  sigma = param.getDefault("sigma", sigma);
117  theta = param.getDefault("theta", theta);
118  }
119  if (param.has("viscosity1") || param.has("viscosity2")) {
120  double v1 = param.getDefault("viscosity1", 0.001);
121  double v2 = param.getDefault("viscosity2", 0.003);
122  res_prop.setViscosities(v1, v2);
123  }
124  res_prop.init(deck, grid.globalCell(), perm_threshold, rl_ptr,
125  use_j, sigma, theta);
126  } else if (fileformat == "cartesian") {
127  std::array<int, 3> dims = {{ param.getDefault<int>("nx", 1),
128  param.getDefault<int>("ny", 1),
129  param.getDefault<int>("nz", 1) }};
130  std::array<double, 3> cellsz = {{ param.getDefault<double>("dx", 1.0),
131  param.getDefault<double>("dy", 1.0),
132  param.getDefault<double>("dz", 1.0) }};
133  grid.createCartesian(dims, cellsz);
134  double default_poro = param.getDefault("default_poro", 0.2);
135  double default_perm_md = param.getDefault("default_perm_md", 100.0);
136  double default_perm = Opm::unit::convert::from(default_perm_md, Opm::prefix::milli*Opm::unit::darcy);
137  OPM_MESSAGE("Warning: For generated cartesian grids, we use uniform reservoir properties.");
138  res_prop.init(grid.size(0), default_poro, default_perm);
139  } else {
140  OPM_THROW(std::runtime_error,
141  "Unknown file format string: " + fileformat);
142  }
143  if (param.getDefault("use_unique_boundary_ids", false)) {
144  grid.setUniqueBoundaryIds(true);
145  }
146  }
147 
151  template <template <int> class ResProp>
152  inline void setupGridAndPropsEclipse(const Opm::Deck& deck,
153  bool periodic_extension,
154  bool turn_normals,
155  bool clip_z,
156  bool unique_bids,
157  double perm_threshold,
158  const std::string& rock_list,
159  bool use_jfunction_scaling,
160  double sigma,
161  double theta,
162  Dune::CpGrid& grid,
163  ResProp<3>& res_prop)
164  {
165  const Opm::EclipseGrid eg(deck);
166  const std::string* rl_ptr = (rock_list == "no_list") ? 0 : &rock_list;
167 
168  grid.processEclipseFormat(&eg, /* ecl_state = */ nullptr,
169  periodic_extension,
170  turn_normals,
171  clip_z,
172  /* pinchActive = */ true,
173  /* edge_conformal = */ false);
174 
175  res_prop.init(deck, grid.globalCell(), perm_threshold, rl_ptr, use_jfunction_scaling, sigma, theta);
176 
177  if (unique_bids) {
178  grid.setUniqueBoundaryIds(true);
179  }
180  }
181 
182 } // namespace Opm
183 
184 
185 #endif // OPENRS_SETUPGRIDANDPROPS_HEADER
void setupGridAndPropsEclipse(const Opm::Deck &deck, bool periodic_extension, bool turn_normals, bool clip_z, bool unique_bids, double perm_threshold, const std::string &rock_list, bool use_jfunction_scaling, double sigma, double theta, Dune::CpGrid &grid, ResProp< 3 > &res_prop)
Definition: setupGridAndProps.hpp:152
Inverting small matrices.
Definition: ImplicitAssembly.hpp:43
void setupGridAndProps(const Opm::ParameterGroup &param, Dune::CpGrid &grid, ResProp< 3 > &res_prop)
Definition: setupGridAndProps.hpp:71
bool useJ()
Helper for determining whether we should.
Definition: setupGridAndProps.hpp:59