All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
quantitycallbacks.hh
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 */
29 #ifndef EWOMS_QUANTITY_CALLBACKS_HH
30 #define EWOMS_QUANTITY_CALLBACKS_HH
31 
33 
34 #include <opm/material/common/MathToolbox.hpp>
35 #include <opm/common/Valgrind.hpp>
36 
37 #include <type_traits>
38 #include <utility>
39 
40 namespace Ewoms {
46 template <class TypeTag>
48 {
49  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
50  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
51 
52  typedef decltype(std::declval<IntensiveQuantities>().fluidState()) IQFluidState;
53  typedef decltype(std::declval<IQFluidState>().temperature(0)) ResultRawType;
54 
55 public:
56  typedef typename std::remove_const<typename std::remove_reference<ResultRawType>::type>::type ResultType;
57  typedef typename Opm::MathToolbox<ResultType>::ValueType ResultValueType;
58 
59  TemperatureCallback(const ElementContext& elemCtx)
60  : elemCtx_(elemCtx)
61  {}
62 
70  ResultType operator()(unsigned dofIdx) const
71  { return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().temperature(/*phaseIdx=*/0); }
72 
73 private:
74  const ElementContext& elemCtx_;
75 };
76 
82 template <class TypeTag>
84 {
85  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
86  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
87 
88  typedef decltype(std::declval<IntensiveQuantities>().fluidState()) IQFluidState;
89  typedef decltype(std::declval<IQFluidState>().pressure(0)) ResultRawType;
90 
91 public:
92  typedef typename std::remove_const<typename std::remove_reference<ResultRawType>::type>::type ResultType;
93  typedef typename Opm::MathToolbox<ResultType>::ValueType ResultValueType;
94 
95  PressureCallback(const ElementContext& elemCtx)
96  : elemCtx_(elemCtx)
97  { Opm::Valgrind::SetUndefined(phaseIdx_); }
98 
99  PressureCallback(const ElementContext& elemCtx, unsigned phaseIdx)
100  : elemCtx_(elemCtx)
101  , phaseIdx_(static_cast<unsigned short>(phaseIdx))
102  {}
103 
108  void setPhaseIndex(unsigned phaseIdx)
109  { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
110 
115  ResultType operator()(unsigned dofIdx) const
116  {
117  Opm::Valgrind::CheckDefined(phaseIdx_);
118  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().pressure(phaseIdx_);
119  }
120 
121 private:
122  const ElementContext& elemCtx_;
123  unsigned short phaseIdx_;
124 };
125 
131 template <class TypeTag, class FluidState>
133 {
134  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
135  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
136  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
137 
138  typedef decltype(std::declval<IntensiveQuantities>().fluidState()) IQRawFluidState;
139  typedef typename std::remove_const<typename std::remove_reference<IQRawFluidState>::type>::type IQFluidState;
140  typedef typename IQFluidState::Scalar IQScalar;
141  typedef Opm::MathToolbox<IQScalar> Toolbox;
142 
143 public:
144  typedef IQScalar ResultType;
145 
146  BoundaryPressureCallback(const ElementContext& elemCtx, const FluidState& boundaryFs)
147  : elemCtx_(elemCtx)
148  , boundaryFs_(boundaryFs)
149  { Opm::Valgrind::SetUndefined(phaseIdx_); }
150 
151  BoundaryPressureCallback(const ElementContext& elemCtx,
152  const FluidState& boundaryFs,
153  unsigned phaseIdx)
154  : elemCtx_(elemCtx)
155  , boundaryFs_(boundaryFs)
156  , phaseIdx_(static_cast<unsigned short>(phaseIdx))
157  {}
158 
163  void setPhaseIndex(unsigned phaseIdx)
164  { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
165 
170  ResultType operator()(unsigned dofIdx) const
171  {
172  Opm::Valgrind::CheckDefined(phaseIdx_);
173  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().pressure(phaseIdx_);
174  }
175 
176  IQScalar boundaryValue() const
177  {
178  Opm::Valgrind::CheckDefined(phaseIdx_);
179  return boundaryFs_.pressure(phaseIdx_);
180  }
181 
182 private:
183  const ElementContext& elemCtx_;
184  const FluidState& boundaryFs_;
185  unsigned short phaseIdx_;
186 };
187 
193 template <class TypeTag>
195 {
196  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
197  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
198 
199  typedef decltype(std::declval<IntensiveQuantities>().fluidState()) IQFluidState;
200  typedef decltype(std::declval<IQFluidState>().density(0)) ResultRawType;
201 
202 public:
203  typedef typename std::remove_const<typename std::remove_reference<ResultRawType>::type>::type ResultType;
204  typedef typename Opm::MathToolbox<ResultType>::ValueType ResultValueType;
205 
206  DensityCallback(const ElementContext& elemCtx)
207  : elemCtx_(elemCtx)
208  { Opm::Valgrind::SetUndefined(phaseIdx_); }
209 
210  DensityCallback(const ElementContext& elemCtx, unsigned phaseIdx)
211  : elemCtx_(elemCtx)
212  , phaseIdx_(static_cast<unsigned short>(phaseIdx))
213  {}
214 
219  void setPhaseIndex(unsigned phaseIdx)
220  { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
221 
226  ResultType operator()(unsigned dofIdx) const
227  {
228  Opm::Valgrind::CheckDefined(phaseIdx_);
229  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().density(phaseIdx_);
230  }
231 
232 private:
233  const ElementContext& elemCtx_;
234  unsigned short phaseIdx_;
235 };
236 
242 template <class TypeTag>
244 {
245  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
246  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
247 
248  typedef decltype(std::declval<IntensiveQuantities>().fluidState()) IQFluidState;
249 
250 public:
251  typedef decltype(std::declval<IQFluidState>().molarDensity(0)) ResultType;
252  typedef typename Opm::MathToolbox<ResultType>::ValueType ResultValueType;
253 
254  MolarDensityCallback(const ElementContext& elemCtx)
255  : elemCtx_(elemCtx)
256  { Opm::Valgrind::SetUndefined(phaseIdx_); }
257 
258  MolarDensityCallback(const ElementContext& elemCtx, unsigned phaseIdx)
259  : elemCtx_(elemCtx)
260  , phaseIdx_(static_cast<unsigned short>(phaseIdx))
261  {}
262 
267  void setPhaseIndex(unsigned phaseIdx)
268  { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
269 
274  ResultType operator()(unsigned dofIdx) const
275  {
276  Opm::Valgrind::CheckDefined(phaseIdx_);
277  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().molarDensity(phaseIdx_);
278  }
279 
280 private:
281  const ElementContext& elemCtx_;
282  unsigned short phaseIdx_;
283 };
284 
290 template <class TypeTag>
292 {
293  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
294  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
295 
296  typedef decltype(std::declval<IntensiveQuantities>().fluidState()) IQFluidState;
297  typedef decltype(std::declval<IQFluidState>().viscosity(0)) ResultRawType;
298 
299 public:
300  typedef typename std::remove_const<typename std::remove_reference<ResultRawType>::type>::type ResultType;
301  typedef typename Opm::MathToolbox<ResultType>::ValueType ResultValueType;
302 
303  ViscosityCallback(const ElementContext& elemCtx)
304  : elemCtx_(elemCtx)
305  { Opm::Valgrind::SetUndefined(phaseIdx_); }
306 
307  ViscosityCallback(const ElementContext& elemCtx, unsigned phaseIdx)
308  : elemCtx_(elemCtx)
309  , phaseIdx_(static_cast<unsigned short>(phaseIdx))
310  {}
311 
316  void setPhaseIndex(unsigned phaseIdx)
317  { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
318 
323  ResultType operator()(unsigned dofIdx) const
324  {
325  Opm::Valgrind::CheckDefined(phaseIdx_);
326  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().viscosity(phaseIdx_);
327  }
328 
329 private:
330  const ElementContext& elemCtx_;
331  unsigned short phaseIdx_;
332 };
333 
339 template <class TypeTag>
341 {
342  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
343  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
344  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
345 
346  typedef decltype(IntensiveQuantities().velocityCenter()) ResultRawType;
347 
348  enum { dim = GridView::dimensionworld };
349 
350 public:
351  typedef typename std::remove_const<typename std::remove_reference<ResultRawType>::type>::type ResultType;
352  typedef typename ResultType::field_type ResultFieldType;
353  typedef typename Opm::MathToolbox<ResultFieldType>::ValueType ResultFieldValueType;
354 
355  VelocityCallback(const ElementContext& elemCtx)
356  : elemCtx_(elemCtx)
357  {}
358 
363  ResultType operator()(unsigned dofIdx) const
364  { return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).velocityCenter(); }
365 
366 private:
367  const ElementContext& elemCtx_;
368 };
369 
375 template <class TypeTag>
377 {
378  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
379  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
380 
381  typedef decltype(IntensiveQuantities().velocityCenter()[0]) ResultRawType;
382 
383 public:
384  typedef typename std::remove_const<typename std::remove_reference<ResultRawType>::type>::type ResultType;
385  typedef typename Opm::MathToolbox<ResultType>::ValueType ResultValueType;
386 
387  VelocityComponentCallback(const ElementContext& elemCtx)
388  : elemCtx_(elemCtx)
389  { Opm::Valgrind::SetUndefined(dimIdx_); }
390 
391  VelocityComponentCallback(const ElementContext& elemCtx, unsigned dimIdx)
392  : elemCtx_(elemCtx)
393  , dimIdx_(dimIdx)
394  {}
395 
400  void setDimIndex(unsigned dimIdx)
401  { dimIdx_ = dimIdx; }
402 
407  ResultType operator()(unsigned dofIdx) const
408  {
409  Opm::Valgrind::CheckDefined(dimIdx_);
410  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).velocityCenter()[dimIdx_];
411  }
412 
413 private:
414  const ElementContext& elemCtx_;
415  unsigned dimIdx_;
416 };
417 
423 template <class TypeTag>
425 {
426  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
427  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
428 
429  typedef decltype(std::declval<IntensiveQuantities>().fluidState()) IQFluidState;
430  typedef decltype(std::declval<IQFluidState>().moleFraction(0, 0)) ResultRawType;
431 
432 public:
433  typedef typename std::remove_const<typename std::remove_reference<ResultRawType>::type>::type ResultType;
434  typedef typename Opm::MathToolbox<ResultType>::ValueType ResultValueType;
435 
436  MoleFractionCallback(const ElementContext& elemCtx)
437  : elemCtx_(elemCtx)
438  {
439  Opm::Valgrind::SetUndefined(phaseIdx_);
440  Opm::Valgrind::SetUndefined(compIdx_);
441  }
442 
443  MoleFractionCallback(const ElementContext& elemCtx, unsigned phaseIdx, unsigned compIdx)
444  : elemCtx_(elemCtx)
445  , phaseIdx_(static_cast<unsigned short>(phaseIdx))
446  , compIdx_(static_cast<unsigned short>(compIdx))
447  {}
448 
453  void setPhaseIndex(unsigned phaseIdx)
454  { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
455 
460  void setComponentIndex(unsigned compIdx)
461  { compIdx_ = static_cast<unsigned short>(compIdx); }
462 
467  ResultType operator()(unsigned dofIdx) const
468  {
469  Opm::Valgrind::CheckDefined(phaseIdx_);
470  Opm::Valgrind::CheckDefined(compIdx_);
471  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().moleFraction(phaseIdx_, compIdx_);
472  }
473 
474 private:
475  const ElementContext& elemCtx_;
476  unsigned short phaseIdx_;
477  unsigned short compIdx_;
478 };
479 
480 } // namespace Ewoms
481 
482 #endif
ResultType operator()(unsigned dofIdx) const
Return the mole fraction of a component in a phase given the index of a degree of freedom within an e...
Definition: quantitycallbacks.hh:467
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the viscosity should be returned.
Definition: quantitycallbacks.hh:316
ResultType operator()(unsigned dofIdx) const
Return the pressure of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:170
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the pressure should be returned.
Definition: quantitycallbacks.hh:163
Callback class for the molar density of a phase.
Definition: quantitycallbacks.hh:243
ResultType operator()(unsigned dofIdx) const
Return the density of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:226
ResultType operator()(unsigned dofIdx) const
Return the temperature given the index of a degree of freedom within an element context.
Definition: quantitycallbacks.hh:70
ResultType operator()(unsigned dofIdx) const
Return the velocity of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:363
Callback class for a phase pressure.
Definition: quantitycallbacks.hh:132
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the molar density should be returned.
Definition: quantitycallbacks.hh:267
Callback class for the viscosity of a phase.
Definition: quantitycallbacks.hh:291
ResultType operator()(unsigned dofIdx) const
Return the viscosity of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:323
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the density should be returned.
Definition: quantitycallbacks.hh:219
Declare the properties used by the infrastructure code of the finite volume discretizations.
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the pressure should be returned.
Definition: quantitycallbacks.hh:108
ResultType operator()(unsigned dofIdx) const
Return the molar density of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:274
ResultType operator()(unsigned dofIdx) const
Return the velocity of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:407
ResultType operator()(unsigned dofIdx) const
Return the pressure of the specified phase given the index of a degree of freedom within an element c...
Definition: quantitycallbacks.hh:115
Callback class for a phase pressure.
Definition: quantitycallbacks.hh:83
void setComponentIndex(unsigned compIdx)
Set the index of the component for which the mole fraction should be returned.
Definition: quantitycallbacks.hh:460
Callback class for the density of a phase.
Definition: quantitycallbacks.hh:194
Callback class for temperature.
Definition: quantitycallbacks.hh:47
Callback class for the velocity of a phase at the center of a DOF.
Definition: quantitycallbacks.hh:376
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which a mole fraction should be returned.
Definition: quantitycallbacks.hh:453
Callback class for a mole fraction of a component in a phase.
Definition: quantitycallbacks.hh:424
void setDimIndex(unsigned dimIdx)
Set the index of the component of the velocity which should be returned.
Definition: quantitycallbacks.hh:400
Callback class for the velocity of a phase at the center of a DOF.
Definition: quantitycallbacks.hh:340