All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
CompressedPropertyAccess.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2014 SINTEF ICT, Applied Mathematics.
3  Copyright 2014 Statoil ASA.
4 
5  This file is part of the Open Porous Media Project (OPM).
6 
7  OPM is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  OPM is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with OPM. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef OPM_COMPRESSEDPROPERTYACCESS_HPP_HEADER
22 #define OPM_COMPRESSEDPROPERTYACCESS_HPP_HEADER
23 
37 #include <opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp>
38 
39 #include <cassert>
40 #include <cstddef>
41 #include <memory>
42 #include <string>
43 #include <vector>
44 
45 namespace Opm {
50  namespace GridPropertyAccess {
55  namespace Details {
60  namespace EclPropImpl {
68  template <typename T>
69  struct HasProperty;
70 
78  template <typename T>
79  struct GetProperty;
80 
85  template <>
86  struct HasProperty<int> {
102  template <class PropertyContainer>
103  static bool
104  p(PropertyContainer& ecl,
105  const std::string& kw);
106  };
107 
108  template <class PropertyContainer>
109  bool
110  HasProperty<int>::p(PropertyContainer& ecl,
111  const std::string& kw)
112  {
113  return ecl.get3DProperties().hasDeckIntGridProperty(kw);
114  }
115 
120  template <>
121  struct HasProperty<double> {
137  template <class PropertyContainer>
138  static bool
139  p(PropertyContainer& ecl,
140  const std::string& kw);
141  };
142 
143  template <class PropertyContainer>
144  bool
145  HasProperty<double>::p(PropertyContainer& ecl,
146  const std::string& kw)
147  {
148  return ecl.get3DProperties().hasDeckDoubleGridProperty(kw);
149  }
150 
155  template <>
156  struct GetProperty<int> {
171  template <class PropertyContainer>
172  static const GridProperty<int>*
173  value(PropertyContainer& ecl,
174  const std::string& kw);
175  };
176 
177  template <class PropertyContainer>
178  const GridProperty<int>*
179  GetProperty<int>::value(PropertyContainer& ecl,
180  const std::string& kw)
181  {
182  assert (HasProperty<int>::p(ecl, kw));
183 
184  return &ecl.get3DProperties().getIntGridProperty(kw);
185  }
186 
191  template <>
192  struct GetProperty<double> {
207  template <class PropertyContainer>
208  static const GridProperty<double>*
209  value(PropertyContainer& ecl,
210  const std::string& kw);
211  };
212 
213  template <class PropertyContainer>
214  const GridProperty<double>*
215  GetProperty<double>::value(PropertyContainer& ecl,
216  const std::string& kw)
217  {
218  assert (HasProperty<double>::p(ecl, kw));
219 
220  return &ecl.get3DProperties().getDoubleGridProperty(kw);
221  }
222  } // namespace EclPropImpl
223 
232  template <typename T>
247  template <class PropertyContainer>
248  static const GridProperty<T>*
249  value(PropertyContainer& ecl,
250  const std::string& kw);
251  };
252 
253  template <typename T>
254  template <class PropertyContainer>
255  const GridProperty<T>*
256  EclipsePropertyArray<T>::value(PropertyContainer& ecl,
257  const std::string& kw)
258  {
259  if (! EclPropImpl::HasProperty<T>::p(ecl, kw)) {
260  return nullptr;
261  }
262  return EclPropImpl::GetProperty<T>::value(ecl, kw);
263  }
264  } // namespace Details
265 
270  namespace ArrayPolicy {
282  template <typename T>
284  public:
304  template <class PropertyContainer>
305  ExtractFromDeck(PropertyContainer& ecl,
306  const std::string& kw,
307  const T dflt)
308  : x_ (Details::EclipsePropertyArray<T>::value(ecl, kw))
309  , dflt_(dflt)
310  {}
311 
315  typedef T value_type;
316 
320  typedef std::size_t size_type;
321 
332  value_type
333  operator[](const size_type i) const
334  {
335  if (x_) {
336  return x_->iget(i);
337  }
338  else {
339  return dflt_;
340  }
341  }
342 
343  private:
349  const GridProperty<T>* x_ = nullptr;
350 
354  T dflt_;
355  };
356 
365  template <typename T>
366  class Constant {
367  public:
374  Constant(const T c)
375  : c_(c)
376  {}
377 
381  typedef T value_type;
382 
386  typedef std::size_t size_type;
387 
397  value_type
398  operator[](const size_type i) const
399  {
400  static_cast<void>(i); // Suppress "unused parameter"
401 
402  return c_;
403  }
404 
405  private:
409  T c_;
410  };
411  } // namespace ArrayPolicy
412 
417  namespace Tag {
421  struct Any {};
422 
427  struct NTG : public Any {};
428  } // namespace Tag
429 
447  template <class DataArray, class PropertyTag = Tag::Any>
448  class Compressed {
449  public:
462  Compressed(const DataArray& x,
463  const int* gc)
464  : x_ (x)
465  , gc_(gc)
466  {}
467 
471  typedef typename DataArray::value_type value_type;
472 
480  value_type
481  operator[](const int c) const
482  {
483  return x_[ (gc_ == 0) ? c : gc_[c] ];
484  }
485 
486  private:
493  DataArray x_;
494 
499  const int* gc_;
500  };
501  } // namespace GridPropertyAccess
502 } // namespace Opm
503 
504 #endif /* OPM_COMPRESSEDPROPERTYACCESS_HPP_HEADER */
Tag that restricts usage to NTG (net-to-gross) contexts.
Definition: CompressedPropertyAccess.hpp:427
Data array policy that returns a single, constant user specified value for every global cell...
Definition: CompressedPropertyAccess.hpp:366
std::size_t size_type
Index type for accessing data array.
Definition: CompressedPropertyAccess.hpp:320
Compressed(const DataArray &x, const int *gc)
Constructor.
Definition: CompressedPropertyAccess.hpp:462
value_type operator[](const size_type i) const
Read-only data array access.
Definition: CompressedPropertyAccess.hpp:333
Provide compressed (active cell) read-only access to globally defined data array. ...
Definition: CompressedPropertyAccess.hpp:448
static const GridProperty< T > * value(PropertyContainer &ecl, const std::string &kw)
Retrieve property values if present in container.
Definition: CompressedPropertyAccess.hpp:256
DataArray::value_type value_type
Property value type.
Definition: CompressedPropertyAccess.hpp:471
Constant(const T c)
Constructor.
Definition: CompressedPropertyAccess.hpp:374
Property value retrieval.
Definition: CompressedPropertyAccess.hpp:79
T value_type
Publicly accessible data array element type.
Definition: CompressedPropertyAccess.hpp:381
value_type operator[](const size_type i) const
Read-only data array access.
Definition: CompressedPropertyAccess.hpp:398
std::size_t size_type
Index type for accessing data array.
Definition: CompressedPropertyAccess.hpp:386
ExtractFromDeck(PropertyContainer &ecl, const std::string &kw, const T dflt)
Constructor.
Definition: CompressedPropertyAccess.hpp:305
Conditional retrieval of property values from an ECLIPSE input deck.
Definition: CompressedPropertyAccess.hpp:233
Data array policy that extracts the array values from an ECLIPSE input deck or returns a user specifi...
Definition: CompressedPropertyAccess.hpp:283
value_type operator[](const int c) const
Read-only data array access.
Definition: CompressedPropertyAccess.hpp:481
Property existence predicate.
Definition: CompressedPropertyAccess.hpp:69
T value_type
Publicly accessible data array element type.
Definition: CompressedPropertyAccess.hpp:315
Default tag that implies no restriction.
Definition: CompressedPropertyAccess.hpp:421