All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
EclMultiplexerMaterialParams.hpp
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 
19  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
27 #ifndef OPM_ECL_MULTIPLEXER_MATERIAL_PARAMS_HPP
28 #define OPM_ECL_MULTIPLEXER_MATERIAL_PARAMS_HPP
29 
30 #include "EclStone1Material.hpp"
31 #include "EclStone2Material.hpp"
32 #include "EclDefaultMaterial.hpp"
33 #include "EclTwoPhaseMaterial.hpp"
34 
35 #include <type_traits>
36 #include <cassert>
37 #include <memory>
38 
40 
41 namespace Opm {
42 
43 enum EclMultiplexerApproach {
44  EclDefaultApproach,
45  EclStone1Approach,
46  EclStone2Approach,
47  EclTwoPhaseApproach
48 };
49 
57 template<class Traits, class GasOilMaterialLawT, class OilWaterMaterialLawT>
58 class EclMultiplexerMaterialParams : public Traits, public EnsureFinalized
59 {
60  typedef typename Traits::Scalar Scalar;
61  enum { numPhases = 3 };
62 
67 
68  typedef typename Stone1Material::Params Stone1Params;
69  typedef typename Stone2Material::Params Stone2Params;
70  typedef typename DefaultMaterial::Params DefaultParams;
71  typedef typename TwoPhaseMaterial::Params TwoPhaseParams;
72 
73  template <class ParamT>
74  struct Deleter
75  {
76  inline void operator () ( void* ptr )
77  {
78  delete static_cast< ParamT* > (ptr);
79  }
80  };
81 
82  typedef std::shared_ptr< void > ParamPointerType;
83 
84 public:
86 
90  EclMultiplexerMaterialParams() : realParams_()
91  {
92  }
93 
95  : realParams_()
96  {
97  setApproach( other.approach() );
98  }
99 
101  {
102  realParams_.reset();
103  setApproach( other.approach() );
104  return *this;
105  }
106 
107  void setApproach(EclMultiplexerApproach newApproach)
108  {
109  assert(realParams_ == 0);
110  approach_ = newApproach;
111 
112  switch (approach()) {
113  case EclStone1Approach:
114  realParams_ = ParamPointerType(new Stone1Params, Deleter< Stone1Params > () );
115  break;
116 
117  case EclStone2Approach:
118  realParams_ = ParamPointerType(new Stone2Params, Deleter< Stone2Params > () );
119  break;
120 
121  case EclDefaultApproach:
122  realParams_ = ParamPointerType(new DefaultParams, Deleter< DefaultParams > () );
123  break;
124 
125  case EclTwoPhaseApproach:
126  realParams_ = ParamPointerType(new TwoPhaseParams, Deleter< TwoPhaseParams > () );
127  break;
128  }
129  }
130 
131  EclMultiplexerApproach approach() const
132  { return approach_; }
133 
134  // get the parameter object for the Stone1 case
135  template <EclMultiplexerApproach approachV>
136  typename std::enable_if<approachV == EclStone1Approach, Stone1Params>::type&
137  getRealParams()
138  {
139  assert(approach() == approachV);
140  return this->template castTo<Stone1Params>();
141  }
142 
143  template <EclMultiplexerApproach approachV>
144  typename std::enable_if<approachV == EclStone1Approach, const Stone1Params>::type&
145  getRealParams() const
146  {
147  assert(approach() == approachV);
148  return this->template castTo<Stone1Params>();
149  }
150 
151  // get the parameter object for the Stone2 case
152  template <EclMultiplexerApproach approachV>
153  typename std::enable_if<approachV == EclStone2Approach, Stone2Params>::type&
154  getRealParams()
155  {
156  assert(approach() == approachV);
157  return this->template castTo<Stone2Params>();
158  }
159 
160  template <EclMultiplexerApproach approachV>
161  typename std::enable_if<approachV == EclStone2Approach, const Stone2Params>::type&
162  getRealParams() const
163  {
164  assert(approach() == approachV);
165  return this->template castTo<Stone2Params>();
166  }
167 
168  // get the parameter object for the default case
169  template <EclMultiplexerApproach approachV>
170  typename std::enable_if<approachV == EclDefaultApproach, DefaultParams>::type&
171  getRealParams()
172  {
173  assert(approach() == approachV);
174  return this->template castTo<DefaultParams>();
175  }
176 
177  template <EclMultiplexerApproach approachV>
178  typename std::enable_if<approachV == EclDefaultApproach, const DefaultParams>::type&
179  getRealParams() const
180  {
181  assert(approach() == approachV);
182  return this->template castTo<DefaultParams>();
183  }
184 
185  // get the parameter object for the twophase case
186  template <EclMultiplexerApproach approachV>
187  typename std::enable_if<approachV == EclTwoPhaseApproach, TwoPhaseParams>::type&
188  getRealParams()
189  {
190  assert(approach() == approachV);
191  return this->template castTo<TwoPhaseParams>();
192  }
193 
194  template <EclMultiplexerApproach approachV>
195  typename std::enable_if<approachV == EclTwoPhaseApproach, const TwoPhaseParams>::type&
196  getRealParams() const
197  {
198  assert(approach() == approachV);
199  return this->template castTo<TwoPhaseParams>();
200  }
201 
202 private:
203  template <class ParamT>
204  ParamT& castTo()
205  {
206  return *(static_cast<ParamT *> (realParams_.operator->()));
207  }
208 
209  template <class ParamT>
210  const ParamT& castTo() const
211  {
212  return *(static_cast<const ParamT *> (realParams_.operator->()));
213  }
214 
215  EclMultiplexerApproach approach_;
216  ParamPointerType realParams_;
217 };
218 } // namespace Opm
219 
220 #endif
Implements a multiplexer class that provides ECL saturation functions for twophase simulations...
Multiplexer implementation for the parameters required by the multiplexed three-phase material law...
Definition: EclMultiplexerMaterialParams.hpp:58
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
EclMultiplexerMaterialParams()
The multiplexer constructor.
Definition: EclMultiplexerMaterialParams.hpp:90
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Definition: EclStone2Material.hpp:61
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Definition: EclStone1Material.hpp:60
Default implementation for asserting finalization of parameter objects.
void finalize()
Mark the object as finalized.
Definition: EnsureFinalized.hpp:77
Default implementation for asserting finalization of parameter objects.
Definition: EnsureFinalized.hpp:46
Implements the default three phase capillary pressure law used by the ECLipse simulator.
Definition: EclDefaultMaterial.hpp:61
Implements a multiplexer class that provides ECL saturation functions for twophase simulations...
Definition: EclTwoPhaseMaterial.hpp:57
Implements the default three phase capillary pressure law used by the ECLipse simulator.