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  Copyright (C) 2010-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
27 #ifndef EWOMS_QUANTITY_CALLBACKS_HH
28 #define EWOMS_QUANTITY_CALLBACKS_HH
29 
30 #include <ewoms/common/declval.hh>
32 
33 #include <opm/material/common/MathToolbox.hpp>
34 
35 #include <type_traits>
36 
37 namespace Ewoms {
43 template <class TypeTag>
45 {
46  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
47  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
48 
49  typedef decltype(Ewoms::declval<IntensiveQuantities>().fluidState()) IQFluidState;
50 
51 public:
52  typedef decltype(Ewoms::declval<IQFluidState>().temperature(0)) ResultType;
53 
54  TemperatureCallback(const ElementContext& elemCtx)
55  : elemCtx_(elemCtx)
56  {}
57 
65  ResultType operator()(int dofIdx) const
66  { return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().temperature(/*phaseIdx=*/0); }
67 
68 private:
69  const ElementContext& elemCtx_;
70 };
71 
77 template <class TypeTag>
79 {
80  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
81  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
82 
83  typedef decltype(Ewoms::declval<IntensiveQuantities>().fluidState()) IQFluidState;
84 
85 public:
86  typedef decltype(Ewoms::declval<IQFluidState>().pressure(0)) ResultType;
87 
88  PressureCallback(const ElementContext& elemCtx)
89  : elemCtx_(elemCtx)
90  { Valgrind::SetUndefined(phaseIdx_); }
91 
92  PressureCallback(const ElementContext& elemCtx, short phaseIdx)
93  : elemCtx_(elemCtx)
94  , phaseIdx_(phaseIdx)
95  {}
96 
101  void setPhaseIndex(short phaseIdx)
102  { phaseIdx_ = phaseIdx; }
103 
108  ResultType operator()(int dofIdx) const
109  {
110  Valgrind::CheckDefined(phaseIdx_);
111  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().pressure(phaseIdx_);
112  }
113 
114 private:
115  const ElementContext& elemCtx_;
116  short phaseIdx_;
117 };
118 
124 template <class TypeTag, class FluidState>
126 {
127  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
128  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
129  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
130 
131  typedef decltype(Ewoms::declval<IntensiveQuantities>().fluidState()) IQFluidState;
132  typedef typename std::remove_reference<IQFluidState>::type::Scalar IQScalar;
133  typedef Opm::MathToolbox<IQScalar> Toolbox;
134 
135 public:
136  typedef IQScalar ResultType;
137 
138  BoundaryPressureCallback(const ElementContext& elemCtx, const FluidState& boundaryFs)
139  : elemCtx_(elemCtx)
140  , boundaryFs_(boundaryFs)
141  { Valgrind::SetUndefined(phaseIdx_); }
142 
143  BoundaryPressureCallback(const ElementContext& elemCtx,
144  const FluidState& boundaryFs,
145  short phaseIdx)
146  : elemCtx_(elemCtx)
147  , boundaryFs_(boundaryFs)
148  , phaseIdx_(phaseIdx)
149  {}
150 
155  void setPhaseIndex(short phaseIdx)
156  { phaseIdx_ = phaseIdx; }
157 
162  ResultType operator()(int dofIdx) const
163  {
164  Valgrind::CheckDefined(phaseIdx_);
165  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().pressure(phaseIdx_);
166  }
167 
168  IQScalar boundaryValue() const
169  {
170  Valgrind::CheckDefined(phaseIdx_);
171  return Toolbox::passThroughOrCreateConstant(boundaryFs_.pressure(phaseIdx_));
172  }
173 
174 private:
175  const ElementContext& elemCtx_;
176  const FluidState& boundaryFs_;
177  short phaseIdx_;
178 };
179 
185 template <class TypeTag>
187 {
188  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
189  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
190 
191  typedef decltype(Ewoms::declval<IntensiveQuantities>().fluidState()) IQFluidState;
192 
193 public:
194  typedef decltype(Ewoms::declval<IQFluidState>().density(0)) ResultType;
195 
196  DensityCallback(const ElementContext& elemCtx)
197  : elemCtx_(elemCtx)
198  { Valgrind::SetUndefined(phaseIdx_); }
199 
200  DensityCallback(const ElementContext& elemCtx, short phaseIdx)
201  : elemCtx_(elemCtx)
202  , phaseIdx_(phaseIdx)
203  {}
204 
209  void setPhaseIndex(short phaseIdx)
210  { phaseIdx_ = phaseIdx; }
211 
216  ResultType operator()(int dofIdx) const
217  {
218  Valgrind::CheckDefined(phaseIdx_);
219  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().density(phaseIdx_);
220  }
221 
222 private:
223  const ElementContext& elemCtx_;
224  short phaseIdx_;
225 };
226 
232 template <class TypeTag>
234 {
235  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
236  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
237 
238  typedef decltype(Ewoms::declval<IntensiveQuantities>().fluidState()) IQFluidState;
239 
240 public:
241  typedef decltype(Ewoms::declval<IQFluidState>().molarDensity(0)) ResultType;
242 
243  MolarDensityCallback(const ElementContext& elemCtx)
244  : elemCtx_(elemCtx)
245  { Valgrind::SetUndefined(phaseIdx_); }
246 
247  MolarDensityCallback(const ElementContext& elemCtx, short phaseIdx)
248  : elemCtx_(elemCtx)
249  , phaseIdx_(phaseIdx)
250  {}
251 
256  void setPhaseIndex(short phaseIdx)
257  { phaseIdx_ = phaseIdx; }
258 
263  ResultType operator()(int dofIdx) const
264  {
265  Valgrind::CheckDefined(phaseIdx_);
266  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().molarDensity(phaseIdx_);
267  }
268 
269 private:
270  const ElementContext& elemCtx_;
271  short phaseIdx_;
272 };
273 
279 template <class TypeTag>
281 {
282  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
283  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
284 
285  typedef decltype(Ewoms::declval<IntensiveQuantities>().fluidState()) IQFluidState;
286 
287 public:
288  typedef decltype(Ewoms::declval<IQFluidState>().viscosity(0)) ResultType;
289 
290  ViscosityCallback(const ElementContext& elemCtx)
291  : elemCtx_(elemCtx)
292  { Valgrind::SetUndefined(phaseIdx_); }
293 
294  ViscosityCallback(const ElementContext& elemCtx, short phaseIdx)
295  : elemCtx_(elemCtx)
296  , phaseIdx_(phaseIdx)
297  {}
298 
303  void setPhaseIndex(short phaseIdx)
304  { phaseIdx_ = phaseIdx; }
305 
310  ResultType operator()(int dofIdx) const
311  {
312  Valgrind::CheckDefined(phaseIdx_);
313  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().viscosity(phaseIdx_);
314  }
315 
316 private:
317  const ElementContext& elemCtx_;
318  short phaseIdx_;
319 };
320 
326 template <class TypeTag>
328 {
329  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
330  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
331  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
332 
333 public:
334  typedef decltype(IntensiveQuantities().velocityCenter()) ResultType;
335 
336  VelocityCallback(const ElementContext& elemCtx)
337  : elemCtx_(elemCtx)
338  {}
339 
344  ResultType operator()(int dofIdx) const
345  { return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).velocityCenter(); }
346 
347 private:
348  const ElementContext& elemCtx_;
349 };
350 
356 template <class TypeTag>
358 {
359  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
360  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
361 
362 public:
363  typedef decltype(IntensiveQuantities().velocityCenter()[0]) ResultType;
364 
365  VelocityComponentCallback(const ElementContext& elemCtx)
366  : elemCtx_(elemCtx)
367  { Valgrind::SetUndefined(dimIdx_); }
368 
369  VelocityComponentCallback(const ElementContext& elemCtx, short dimIdx)
370  : elemCtx_(elemCtx)
371  , dimIdx_(dimIdx)
372  {}
373 
378  void setDimIndex(short dimIdx)
379  { dimIdx_ = dimIdx; }
380 
385  ResultType operator()(int dofIdx) const
386  {
387  Valgrind::CheckDefined(dimIdx_);
388  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).velocityCenter()[dimIdx_];
389  }
390 
391 private:
392  const ElementContext& elemCtx_;
393  short dimIdx_;
394 };
395 
401 template <class TypeTag>
403 {
404  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
405  typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
406 
407  typedef decltype(Ewoms::declval<IntensiveQuantities>().fluidState()) IQFluidState;
408 
409 public:
410  typedef decltype(Ewoms::declval<IQFluidState>().moleFraction(0, 0)) ResultType;
411 
412  MoleFractionCallback(const ElementContext& elemCtx)
413  : elemCtx_(elemCtx)
414  {
415  Valgrind::SetUndefined(phaseIdx_);
416  Valgrind::SetUndefined(compIdx_);
417  }
418 
419  MoleFractionCallback(const ElementContext& elemCtx, short phaseIdx, short compIdx)
420  : elemCtx_(elemCtx)
421  , phaseIdx_(phaseIdx)
422  , compIdx_(compIdx)
423  {}
424 
429  void setPhaseIndex(short phaseIdx)
430  { phaseIdx_ = phaseIdx; }
431 
436  void setComponentIndex(short compIdx)
437  { compIdx_ = compIdx; }
438 
444  ResultType operator()(int dofIdx) const
445  {
446  Valgrind::CheckDefined(phaseIdx_);
447  Valgrind::CheckDefined(compIdx_);
448  return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().moleFraction(phaseIdx_, compIdx_);
449  }
450 
451 private:
452  const ElementContext& elemCtx_;
453  short phaseIdx_;
454  short compIdx_;
455 };
456 
457 } // namespace Ewoms
458 
459 #endif
Callback class for the molar density of a phase.
Definition: quantitycallbacks.hh:233
decltype(Ewoms::declval< IQFluidState >().density(0)) typedef ResultType
Definition: quantitycallbacks.hh:194
ResultType operator()(int dofIdx) const
Return the temperature given the index of a degree of freedom within an element context.
Definition: quantitycallbacks.hh:65
IQScalar ResultType
Definition: quantitycallbacks.hh:136
void setPhaseIndex(short phaseIdx)
Set the index of the fluid phase for which the pressure should be returned.
Definition: quantitycallbacks.hh:155
ResultType operator()(int dofIdx) const
Return the density of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:216
DensityCallback(const ElementContext &elemCtx, short phaseIdx)
Definition: quantitycallbacks.hh:200
ResultType operator()(int dofIdx) const
Return the velocity of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:344
Declare the properties used by the infrastructure code of the finite volume discretizations.
VelocityComponentCallback(const ElementContext &elemCtx, short dimIdx)
Definition: quantitycallbacks.hh:369
Callback class for temperature.
Definition: quantitycallbacks.hh:44
ResultType operator()(int dofIdx) const
Return the pressure of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:162
MolarDensityCallback(const ElementContext &elemCtx, short phaseIdx)
Definition: quantitycallbacks.hh:247
BoundaryPressureCallback(const ElementContext &elemCtx, const FluidState &boundaryFs, short phaseIdx)
Definition: quantitycallbacks.hh:143
void setPhaseIndex(short phaseIdx)
Set the index of the fluid phase for which a mole fraction should be returned.
Definition: quantitycallbacks.hh:429
Callback class for a mole fraction of a component in a phase.
Definition: quantitycallbacks.hh:402
IQScalar boundaryValue() const
Definition: quantitycallbacks.hh:168
Provides a std::declval equivalent.
void setPhaseIndex(short phaseIdx)
Set the index of the fluid phase for which the molar density should be returned.
Definition: quantitycallbacks.hh:256
void setDimIndex(short dimIdx)
Set the index of the component of the velocity which should be returned.
Definition: quantitycallbacks.hh:378
void setPhaseIndex(short phaseIdx)
Set the index of the fluid phase for which the pressure should be returned.
Definition: quantitycallbacks.hh:101
void setPhaseIndex(short phaseIdx)
Set the index of the fluid phase for which the viscosity should be returned.
Definition: quantitycallbacks.hh:303
PressureCallback(const ElementContext &elemCtx, short phaseIdx)
Definition: quantitycallbacks.hh:92
decltype(Ewoms::declval< IQFluidState >().molarDensity(0)) typedef ResultType
Definition: quantitycallbacks.hh:241
Callback class for a phase pressure.
Definition: quantitycallbacks.hh:125
Callback class for the density of a phase.
Definition: quantitycallbacks.hh:186
Definition: baseauxiliarymodule.hh:35
ResultType operator()(int 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:444
Callback class for a phase pressure.
Definition: quantitycallbacks.hh:78
decltype(Ewoms::declval< IQFluidState >().temperature(0)) typedef ResultType
Definition: quantitycallbacks.hh:52
ViscosityCallback(const ElementContext &elemCtx, short phaseIdx)
Definition: quantitycallbacks.hh:294
Callback class for the velocity of a phase at the center of a DOF.
Definition: quantitycallbacks.hh:327
Callback class for the viscosity of a phase.
Definition: quantitycallbacks.hh:280
decltype(Ewoms::declval< IQFluidState >().pressure(0)) typedef ResultType
Definition: quantitycallbacks.hh:86
void setPhaseIndex(short phaseIdx)
Set the index of the fluid phase for which the density should be returned.
Definition: quantitycallbacks.hh:209
ResultType operator()(int dofIdx) const
Return the viscosity of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:310
ResultType operator()(int dofIdx) const
Return the molar density of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:263
decltype(IntensiveQuantities().velocityCenter()) typedef ResultType
Definition: quantitycallbacks.hh:334
ResultType operator()(int dofIdx) const
Return the velocity of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:385
BoundaryPressureCallback(const ElementContext &elemCtx, const FluidState &boundaryFs)
Definition: quantitycallbacks.hh:138
decltype(Ewoms::declval< IQFluidState >().viscosity(0)) typedef ResultType
Definition: quantitycallbacks.hh:288
MoleFractionCallback(const ElementContext &elemCtx, short phaseIdx, short compIdx)
Definition: quantitycallbacks.hh:419
decltype(IntensiveQuantities().velocityCenter()[0]) typedef ResultType
Definition: quantitycallbacks.hh:363
ResultType operator()(int dofIdx) const
Return the pressure of a phase given the index of a degree of freedom within an element context...
Definition: quantitycallbacks.hh:108
Callback class for the velocity of a phase at the center of a DOF.
Definition: quantitycallbacks.hh:357
decltype(Ewoms::declval< IQFluidState >().moleFraction(0, 0)) typedef ResultType
Definition: quantitycallbacks.hh:410
void setComponentIndex(short compIdx)
Set the index of the component for which the mole fraction should be returned.
Definition: quantitycallbacks.hh:436