My Project
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 <cassert>
36 #include <memory>
37 #include <type_traits>
38 
40 
41 namespace Opm {
42 
43 enum class EclMultiplexerApproach {
44  EclDefaultApproach,
45  EclStone1Approach,
46  EclStone2Approach,
47  EclTwoPhaseApproach,
48  EclOnePhaseApproach
49 };
50 
58 template<class Traits, class GasOilMaterialLawT, class OilWaterMaterialLawT, class GasWaterMaterialLawT>
59 class EclMultiplexerMaterialParams : public Traits, public EnsureFinalized
60 {
61  using Scalar = typename Traits::Scalar;
62  enum { numPhases = 3 };
63 
68 
69  using Stone1Params = typename Stone1Material::Params;
70  using Stone2Params = typename Stone2Material::Params;
71  using DefaultParams = typename DefaultMaterial::Params;
72  using TwoPhaseParams = typename TwoPhaseMaterial::Params;
73 
74  template <class ParamT>
75  struct Deleter
76  {
77  inline void operator () ( void* ptr )
78  {
79  delete static_cast< ParamT* > (ptr);
80  }
81  };
82 
83  using ParamPointerType = std::shared_ptr<void>;
84 
85 public:
87 
91  EclMultiplexerMaterialParams() : realParams_()
92  {
93  }
94 
96  : realParams_()
97  {
98  setApproach( other.approach() );
99  }
100 
102  {
103  realParams_.reset();
104  setApproach( other.approach() );
105  return *this;
106  }
107 
108  void setApproach(EclMultiplexerApproach newApproach)
109  {
110  assert(realParams_ == 0);
111  approach_ = newApproach;
112 
113  switch (approach()) {
114  case EclMultiplexerApproach::EclStone1Approach:
115  realParams_ = ParamPointerType(new Stone1Params, Deleter< Stone1Params > () );
116  break;
117 
118  case EclMultiplexerApproach::EclStone2Approach:
119  realParams_ = ParamPointerType(new Stone2Params, Deleter< Stone2Params > () );
120  break;
121 
122  case EclMultiplexerApproach::EclDefaultApproach:
123  realParams_ = ParamPointerType(new DefaultParams, Deleter< DefaultParams > () );
124  break;
125 
126  case EclMultiplexerApproach::EclTwoPhaseApproach:
127  realParams_ = ParamPointerType(new TwoPhaseParams, Deleter< TwoPhaseParams > () );
128  break;
129 
130  case EclMultiplexerApproach::EclOnePhaseApproach:
131  // Do nothing, no parameters.
132  break;
133  }
134  }
135 
136  EclMultiplexerApproach approach() const
137  { return approach_; }
138 
139  // get the parameter object for the Stone1 case
140  template <EclMultiplexerApproach approachV>
141  typename std::enable_if<approachV == EclMultiplexerApproach::EclStone1Approach, Stone1Params>::type&
142  getRealParams()
143  {
144  assert(approach() == approachV);
145  return this->template castTo<Stone1Params>();
146  }
147 
148  template <EclMultiplexerApproach approachV>
149  typename std::enable_if<approachV == EclMultiplexerApproach::EclStone1Approach, const Stone1Params>::type&
150  getRealParams() const
151  {
152  assert(approach() == approachV);
153  return this->template castTo<Stone1Params>();
154  }
155 
156  // get the parameter object for the Stone2 case
157  template <EclMultiplexerApproach approachV>
158  typename std::enable_if<approachV == EclMultiplexerApproach::EclStone2Approach, Stone2Params>::type&
159  getRealParams()
160  {
161  assert(approach() == approachV);
162  return this->template castTo<Stone2Params>();
163  }
164 
165  template <EclMultiplexerApproach approachV>
166  typename std::enable_if<approachV == EclMultiplexerApproach::EclStone2Approach, const Stone2Params>::type&
167  getRealParams() const
168  {
169  assert(approach() == approachV);
170  return this->template castTo<Stone2Params>();
171  }
172 
173  // get the parameter object for the default case
174  template <EclMultiplexerApproach approachV>
175  typename std::enable_if<approachV == EclMultiplexerApproach::EclDefaultApproach, DefaultParams>::type&
176  getRealParams()
177  {
178  assert(approach() == approachV);
179  return this->template castTo<DefaultParams>();
180  }
181 
182  template <EclMultiplexerApproach approachV>
183  typename std::enable_if<approachV == EclMultiplexerApproach::EclDefaultApproach, const DefaultParams>::type&
184  getRealParams() const
185  {
186  assert(approach() == approachV);
187  return this->template castTo<DefaultParams>();
188  }
189 
190  // get the parameter object for the twophase case
191  template <EclMultiplexerApproach approachV>
192  typename std::enable_if<approachV == EclMultiplexerApproach::EclTwoPhaseApproach, TwoPhaseParams>::type&
193  getRealParams()
194  {
195  assert(approach() == approachV);
196  return this->template castTo<TwoPhaseParams>();
197  }
198 
199  template <EclMultiplexerApproach approachV>
200  typename std::enable_if<approachV == EclMultiplexerApproach::EclTwoPhaseApproach, const TwoPhaseParams>::type&
201  getRealParams() const
202  {
203  assert(approach() == approachV);
204  return this->template castTo<TwoPhaseParams>();
205  }
206 
207 private:
208  template <class ParamT>
209  ParamT& castTo()
210  {
211  return *(static_cast<ParamT *> (realParams_.operator->()));
212  }
213 
214  template <class ParamT>
215  const ParamT& castTo() const
216  {
217  return *(static_cast<const ParamT *> (realParams_.operator->()));
218  }
219 
220  EclMultiplexerApproach approach_;
221  ParamPointerType realParams_;
222 };
223 } // namespace Opm
224 
225 #endif
Implements the default three phase capillary pressure law used by the ECLipse simulator.
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 ...
Implements a multiplexer class that provides ECL saturation functions for twophase simulations.
Default implementation for asserting finalization of parameter objects.
Implements the default three phase capillary pressure law used by the ECLipse simulator.
Definition: EclDefaultMaterial.hpp:61
Multiplexer implementation for the parameters required by the multiplexed three-phase material law.
Definition: EclMultiplexerMaterialParams.hpp:60
EclMultiplexerMaterialParams()
The multiplexer constructor.
Definition: EclMultiplexerMaterialParams.hpp:91
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Definition: EclStone1Material.hpp:60
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Definition: EclStone2Material.hpp:61
Implements a multiplexer class that provides ECL saturation functions for twophase simulations.
Definition: EclTwoPhaseMaterial.hpp:57
Default implementation for asserting finalization of parameter objects.
Definition: EnsureFinalized.hpp:47
void finalize()
Mark the object as finalized.
Definition: EnsureFinalized.hpp:75