opm-common
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  Default,
45  Stone1,
46  Stone2,
47  TwoPhase,
48  OnePhase
49 };
50 
51 template <EclMultiplexerApproach ApproachArg>
53 {
54  static constexpr auto approach = ApproachArg;
55 };
56 
57 // Helper struct to tell if a parameter pack starts with EclMultiplexerDispatch.
58 template <typename ...Args>
59 struct FrontIsEclMultiplexerDispatch : public std::false_type {};
60 template <EclMultiplexerApproach Value, typename ...Args>
61 struct FrontIsEclMultiplexerDispatch<EclMultiplexerDispatch<Value>, Args...> : public std::true_type {};
62 template <typename ...Args>
63 constexpr bool FrontIsEclMultiplexerDispatchV = FrontIsEclMultiplexerDispatch<Args...>::value;
64 
65 
73 template<class Traits, class GasOilMaterialLawT, class OilWaterMaterialLawT, class GasWaterMaterialLawT>
74 class EclMultiplexerMaterialParams : public Traits, public EnsureFinalized
75 {
76  using Scalar = typename Traits::Scalar;
77  enum { numPhases = 3 };
78 
83 
84  using Stone1Params = typename Stone1Material::Params;
85  using Stone2Params = typename Stone2Material::Params;
86  using DefaultParams = typename DefaultMaterial::Params;
87  using TwoPhaseParams = typename TwoPhaseMaterial::Params;
88 
89  template <class ParamT>
90  struct Deleter
91  {
92  inline void operator () ( void* ptr )
93  {
94  delete static_cast< ParamT* > (ptr);
95  }
96  };
97 
98  using ParamPointerType = std::shared_ptr<void>;
99 
100 public:
102 
107  {
108  }
109 
111  : realParams_()
112  {
113  setApproach( other.approach() );
114  }
115 
117  {
118  realParams_.reset();
119  setApproach( other.approach() );
120  return *this;
121  }
122 
123  void setApproach(EclMultiplexerApproach newApproach)
124  {
125  assert(realParams_ == 0);
126  approach_ = newApproach;
127 
128  switch (approach()) {
129  case EclMultiplexerApproach::Stone1:
130  realParams_ = ParamPointerType(new Stone1Params, Deleter< Stone1Params > () );
131  break;
132 
133  case EclMultiplexerApproach::Stone2:
134  realParams_ = ParamPointerType(new Stone2Params, Deleter< Stone2Params > () );
135  break;
136 
137  case EclMultiplexerApproach::Default:
138  realParams_ = ParamPointerType(new DefaultParams, Deleter< DefaultParams > () );
139  break;
140 
141  case EclMultiplexerApproach::TwoPhase:
142  realParams_ = ParamPointerType(new TwoPhaseParams, Deleter< TwoPhaseParams > () );
143  break;
144 
145  case EclMultiplexerApproach::OnePhase:
146  // Do nothing, no parameters.
147  break;
148  }
149  }
150 
151  EclMultiplexerApproach approach() const
152  { return approach_; }
153 
154  // get the parameter object for the Stone1 case
155  template <EclMultiplexerApproach approachV>
156  typename std::enable_if<approachV == EclMultiplexerApproach::Stone1, Stone1Params>::type&
157  getRealParams()
158  {
159  assert(approach() == approachV);
160  return this->template castTo<Stone1Params>();
161  }
162 
163  template <EclMultiplexerApproach approachV>
164  typename std::enable_if<approachV == EclMultiplexerApproach::Stone1, const Stone1Params>::type&
165  getRealParams() const
166  {
167  assert(approach() == approachV);
168  return this->template castTo<Stone1Params>();
169  }
170 
171  // get the parameter object for the Stone2 case
172  template <EclMultiplexerApproach approachV>
173  typename std::enable_if<approachV == EclMultiplexerApproach::Stone2, Stone2Params>::type&
174  getRealParams()
175  {
176  assert(approach() == approachV);
177  return this->template castTo<Stone2Params>();
178  }
179 
180  template <EclMultiplexerApproach approachV>
181  typename std::enable_if<approachV == EclMultiplexerApproach::Stone2, const Stone2Params>::type&
182  getRealParams() const
183  {
184  assert(approach() == approachV);
185  return this->template castTo<Stone2Params>();
186  }
187 
188  // get the parameter object for the default case
189  template <EclMultiplexerApproach approachV>
190  typename std::enable_if<approachV == EclMultiplexerApproach::Default, DefaultParams>::type&
191  getRealParams()
192  {
193  assert(approach() == approachV);
194  return this->template castTo<DefaultParams>();
195  }
196 
197  template <EclMultiplexerApproach approachV>
198  typename std::enable_if<approachV == EclMultiplexerApproach::Default, const DefaultParams>::type&
199  getRealParams() const
200  {
201  assert(approach() == approachV);
202  return this->template castTo<DefaultParams>();
203  }
204 
205  // get the parameter object for the twophase case
206  template <EclMultiplexerApproach approachV>
207  typename std::enable_if<approachV == EclMultiplexerApproach::TwoPhase, TwoPhaseParams>::type&
208  getRealParams()
209  {
210  assert(approach() == approachV);
211  return this->template castTo<TwoPhaseParams>();
212  }
213 
214  template <EclMultiplexerApproach approachV>
215  typename std::enable_if<approachV == EclMultiplexerApproach::TwoPhase, const TwoPhaseParams>::type&
216  getRealParams() const
217  {
218  assert(approach() == approachV);
219  return this->template castTo<TwoPhaseParams>();
220  }
221 
222  template<class Serializer>
223  void serializeOp(Serializer& serializer)
224  {
225  switch (approach()) {
226  case EclMultiplexerApproach::Stone1:
227  serializer(castTo<Stone1Params>());
228  break;
229 
230  case EclMultiplexerApproach::Stone2:
231  serializer(castTo<Stone2Params>());
232  break;
233 
234  case EclMultiplexerApproach::Default:
235  serializer(castTo<DefaultParams>());
236  break;
237 
238  case EclMultiplexerApproach::TwoPhase:
239  serializer(castTo<TwoPhaseParams>());
240  break;
241 
242  case EclMultiplexerApproach::OnePhase:
243  // Do nothing, no parameters.
244  break;
245  }
246  }
247 
248 private:
249  template <class ParamT>
250  ParamT& castTo()
251  {
252  return *(static_cast<ParamT *> (realParams_.operator->()));
253  }
254 
255  template <class ParamT>
256  const ParamT& castTo() const
257  {
258  return *(static_cast<const ParamT *> (realParams_.operator->()));
259  }
260 
261  EclMultiplexerApproach approach_{EclMultiplexerApproach::Default};
262  ParamPointerType realParams_;
263 };
264 } // namespace Opm
265 
266 #endif
Implements a multiplexer class that provides ECL saturation functions for twophase simulations...
Definition: EclMultiplexerMaterialParams.hpp:59
Multiplexer implementation for the parameters required by the multiplexed three-phase material law...
Definition: EclMultiplexerMaterialParams.hpp:74
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 ...
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Definition: EclStone2Material.hpp:60
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.
Definition: EclMultiplexerMaterialParams.hpp:52
OPM_HOST_DEVICE void finalize()
Mark the object as finalized.
Definition: EnsureFinalized.hpp:82
EclMultiplexerMaterialParams()
The multiplexer constructor.
Definition: EclMultiplexerMaterialParams.hpp:106
Default implementation for asserting finalization of parameter objects.
Definition: EnsureFinalized.hpp:48
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:56
Implements the default three phase capillary pressure law used by the ECLipse simulator.