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->hasIntGridProperty(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->hasDoubleGridProperty(kw);
149  }
150 
155  template <>
156  struct GetProperty<int> {
171  template <class PropertyContainer>
172  static std::shared_ptr< GridProperty<int> >
173  value(PropertyContainer& ecl,
174  const std::string& kw);
175  };
176 
177  template <class PropertyContainer>
178  std::shared_ptr< 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->getIntGridProperty(kw);
185  }
186 
191  template <>
192  struct GetProperty<double> {
207  template <class PropertyContainer>
208  static std::shared_ptr< GridProperty<double> >
209  value(PropertyContainer& ecl,
210  const std::string& kw);
211  };
212 
213  template <class PropertyContainer>
214  std::shared_ptr< 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->getDoubleGridProperty(kw);
221  }
222  } // namespace EclPropImpl
223 
232  template <typename T>
247  template <class PropertyContainer>
248  static std::shared_ptr< GridProperty<T> >
249  value(PropertyContainer& ecl,
250  const std::string& kw);
251  };
252 
253  template <typename T>
254  template <class PropertyContainer>
255  std::shared_ptr< GridProperty<T> >
256  EclipsePropertyArray<T>::value(PropertyContainer& ecl,
257  const std::string& kw)
258  {
259  std::shared_ptr< GridProperty<T> > x;
260 
261  if (EclPropImpl::HasProperty<T>::p(ecl, kw)) {
263  }
264 
265  return x;
266  }
267  } // namespace Details
268 
273  namespace ArrayPolicy {
285  template <typename T>
287  public:
307  template <class PropertyContainer>
308  ExtractFromDeck(PropertyContainer& ecl,
309  const std::string& kw,
310  const T dflt)
311  : x_ (Details::EclipsePropertyArray<T>::value(ecl, kw))
312  , dflt_(dflt)
313  {}
314 
318  typedef T value_type;
319 
323  typedef std::size_t size_type;
324 
335  value_type
336  operator[](const size_type i) const
337  {
338  if (x_) {
339  return x_->iget(i);
340  }
341  else {
342  return dflt_;
343  }
344  }
345 
346  private:
352  std::shared_ptr< GridProperty<T> > x_;
353 
357  T dflt_;
358  };
359 
368  template <typename T>
369  class Constant {
370  public:
377  Constant(const T c)
378  : c_(c)
379  {}
380 
384  typedef T value_type;
385 
389  typedef std::size_t size_type;
390 
400  value_type
401  operator[](const size_type i) const
402  {
403  static_cast<void>(i); // Suppress "unused parameter"
404 
405  return c_;
406  }
407 
408  private:
412  T c_;
413  };
414  } // namespace ArrayPolicy
415 
420  namespace Tag {
424  struct Any {};
425 
430  struct NTG : public Any {};
431  } // namespace Tag
432 
450  template <class DataArray, class PropertyTag = Tag::Any>
451  class Compressed {
452  public:
465  Compressed(const DataArray& x,
466  const int* gc)
467  : x_ (x)
468  , gc_(gc)
469  {}
470 
474  typedef typename DataArray::value_type value_type;
475 
483  value_type
484  operator[](const int c) const
485  {
486  return x_[ (gc_ == 0) ? c : gc_[c] ];
487  }
488 
489  private:
496  DataArray x_;
497 
502  const int* gc_;
503  };
504  } // namespace GridPropertyAccess
505 } // namespace Opm
506 
507 #endif /* OPM_COMPRESSEDPROPERTYACCESS_HPP_HEADER */
Definition: AnisotropicEikonal.hpp:43
Definition: CompressedPropertyAccess.hpp:451
Constant(const T c)
Definition: CompressedPropertyAccess.hpp:377
DataArray::value_type value_type
Definition: CompressedPropertyAccess.hpp:474
T value_type
Definition: CompressedPropertyAccess.hpp:318
Compressed(const DataArray &x, const int *gc)
Definition: CompressedPropertyAccess.hpp:465
Definition: CompressedPropertyAccess.hpp:430
Definition: CompressedPropertyAccess.hpp:69
static std::shared_ptr< GridProperty< T > > value(PropertyContainer &ecl, const std::string &kw)
Definition: CompressedPropertyAccess.hpp:256
std::size_t size_type
Definition: CompressedPropertyAccess.hpp:323
T value_type
Definition: CompressedPropertyAccess.hpp:384
Definition: CompressedPropertyAccess.hpp:233
Definition: CompressedPropertyAccess.hpp:369
std::size_t size_type
Definition: CompressedPropertyAccess.hpp:389
ExtractFromDeck(PropertyContainer &ecl, const std::string &kw, const T dflt)
Definition: CompressedPropertyAccess.hpp:308
Definition: CompressedPropertyAccess.hpp:424
value_type operator[](const size_type i) const
Definition: CompressedPropertyAccess.hpp:401
value_type operator[](const int c) const
Definition: CompressedPropertyAccess.hpp:484
Definition: CompressedPropertyAccess.hpp:286
Definition: CompressedPropertyAccess.hpp:79
value_type operator[](const size_type i) const
Definition: CompressedPropertyAccess.hpp:336