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/material/common/Valgrind.hpp>
36
37#include <type_traits>
38#include <utility>
39
40namespace Opm {
41
47template <class TypeTag>
49{
52
53 using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
54 using ResultRawType = decltype(std::declval<IQFluidState>().temperature(0));
55
56public:
57 using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
58 using ResultValueType = typename MathToolbox<ResultType>::ValueType;
59
60 explicit TemperatureCallback(const ElementContext& elemCtx)
61 : elemCtx_(elemCtx)
62 {}
63
71 ResultType operator()(unsigned dofIdx) const
72 { return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().temperature(/*phaseIdx=*/0); }
73
74private:
75 const ElementContext& elemCtx_;
76};
77
83template <class TypeTag>
85{
88
89 using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
90 using ResultRawType = decltype(std::declval<IQFluidState>().pressure(0));
91
92public:
93 using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
94 using ResultValueType = typename MathToolbox<ResultType>::ValueType;
95
96 explicit PressureCallback(const ElementContext& elemCtx)
97 : elemCtx_(elemCtx)
98 { Valgrind::SetUndefined(phaseIdx_); }
99
100 PressureCallback(const ElementContext& elemCtx, unsigned phaseIdx)
101 : elemCtx_(elemCtx)
102 , phaseIdx_(static_cast<unsigned short>(phaseIdx))
103 {}
104
109 void setPhaseIndex(unsigned phaseIdx)
110 { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
111
116 ResultType operator()(unsigned dofIdx) const
117 {
118 Valgrind::CheckDefined(phaseIdx_);
119 return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().pressure(phaseIdx_);
120 }
121
122private:
123 const ElementContext& elemCtx_;
124 unsigned short phaseIdx_;
125};
126
132template <class TypeTag, class FluidState>
134{
138
139 using IQRawFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
140 using IQFluidState = std::remove_const_t<std::remove_reference_t<IQRawFluidState>>;
141 using IQScalar = typename IQFluidState::Scalar;
142 using Toolbox = MathToolbox<IQScalar>;
143
144public:
145 using ResultType = IQScalar;
146
147 BoundaryPressureCallback(const ElementContext& elemCtx, const FluidState& boundaryFs)
148 : elemCtx_(elemCtx)
149 , boundaryFs_(boundaryFs)
150 { Valgrind::SetUndefined(phaseIdx_); }
151
152 BoundaryPressureCallback(const ElementContext& elemCtx,
153 const FluidState& boundaryFs,
154 unsigned phaseIdx)
155 : elemCtx_(elemCtx)
156 , boundaryFs_(boundaryFs)
157 , phaseIdx_(static_cast<unsigned short>(phaseIdx))
158 {}
159
164 void setPhaseIndex(unsigned phaseIdx)
165 { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
166
171 ResultType operator()(unsigned dofIdx) const
172 {
173 Valgrind::CheckDefined(phaseIdx_);
174 return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().pressure(phaseIdx_);
175 }
176
177 IQScalar boundaryValue() const
178 {
179 Valgrind::CheckDefined(phaseIdx_);
180 return boundaryFs_.pressure(phaseIdx_);
181 }
182
183private:
184 const ElementContext& elemCtx_;
185 const FluidState& boundaryFs_;
186 unsigned short phaseIdx_;
187};
188
194template <class TypeTag>
196{
199
200 using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
201 using ResultRawType = decltype(std::declval<IQFluidState>().density(0));
202
203public:
204 using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
205 using ResultValueType = typename MathToolbox<ResultType>::ValueType;
206
207 explicit DensityCallback(const ElementContext& elemCtx)
208 : elemCtx_(elemCtx)
209 { Valgrind::SetUndefined(phaseIdx_); }
210
211 DensityCallback(const ElementContext& elemCtx, unsigned phaseIdx)
212 : elemCtx_(elemCtx)
213 , phaseIdx_(static_cast<unsigned short>(phaseIdx))
214 {}
215
220 void setPhaseIndex(unsigned phaseIdx)
221 { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
222
227 ResultType operator()(unsigned dofIdx) const
228 {
229 Valgrind::CheckDefined(phaseIdx_);
230 return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().density(phaseIdx_);
231 }
232
233private:
234 const ElementContext& elemCtx_;
235 unsigned short phaseIdx_;
236};
237
243template <class TypeTag>
245{
248
249 using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
250
251public:
252 using ResultType = decltype(std::declval<IQFluidState>().molarDensity(0));
253 using ResultValueType = typename MathToolbox<ResultType>::ValueType;
254
255 explicit MolarDensityCallback(const ElementContext& elemCtx)
256 : elemCtx_(elemCtx)
257 { Valgrind::SetUndefined(phaseIdx_); }
258
259 MolarDensityCallback(const ElementContext& elemCtx, unsigned phaseIdx)
260 : elemCtx_(elemCtx)
261 , phaseIdx_(static_cast<unsigned short>(phaseIdx))
262 {}
263
268 void setPhaseIndex(unsigned phaseIdx)
269 { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
270
275 ResultType operator()(unsigned dofIdx) const
276 {
277 Valgrind::CheckDefined(phaseIdx_);
278 return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().molarDensity(phaseIdx_);
279 }
280
281private:
282 const ElementContext& elemCtx_;
283 unsigned short phaseIdx_;
284};
285
291template <class TypeTag>
293{
296
297 using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
298 using ResultRawType = decltype(std::declval<IQFluidState>().viscosity(0));
299
300public:
301 using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
302 using ResultValueType = typename MathToolbox<ResultType>::ValueType;
303
304 explicit ViscosityCallback(const ElementContext& elemCtx)
305 : elemCtx_(elemCtx)
306 { Valgrind::SetUndefined(phaseIdx_); }
307
308 ViscosityCallback(const ElementContext& elemCtx, unsigned phaseIdx)
309 : elemCtx_(elemCtx)
310 , phaseIdx_(static_cast<unsigned short>(phaseIdx))
311 {}
312
317 void setPhaseIndex(unsigned phaseIdx)
318 { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
319
324 ResultType operator()(unsigned dofIdx) const
325 {
326 Valgrind::CheckDefined(phaseIdx_);
327 return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().viscosity(phaseIdx_);
328 }
329
330private:
331 const ElementContext& elemCtx_;
332 unsigned short phaseIdx_;
333};
334
340template <class TypeTag>
342{
346
347 using ResultRawType = decltype(IntensiveQuantities().velocityCenter());
348
349 enum { dim = GridView::dimensionworld };
350
351public:
352 using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
353 using ResultFieldType = typename ResultType::field_type;
354 using ResultFieldValueType = typename MathToolbox<ResultFieldType>::ValueType;
355
356 explicit VelocityCallback(const ElementContext& elemCtx)
357 : elemCtx_(elemCtx)
358 {}
359
364 ResultType operator()(unsigned dofIdx) const
365 { return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).velocityCenter(); }
366
367private:
368 const ElementContext& elemCtx_;
369};
370
376template <class TypeTag>
378{
381
382 using ResultRawType = decltype(IntensiveQuantities().velocityCenter()[0]);
383
384public:
385 using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
386 using ResultValueType = typename MathToolbox<ResultType>::ValueType;
387
388 explicit VelocityComponentCallback(const ElementContext& elemCtx)
389 : elemCtx_(elemCtx)
390 { Valgrind::SetUndefined(dimIdx_); }
391
392 VelocityComponentCallback(const ElementContext& elemCtx, unsigned dimIdx)
393 : elemCtx_(elemCtx)
394 , dimIdx_(dimIdx)
395 {}
396
401 void setDimIndex(unsigned dimIdx)
402 { dimIdx_ = dimIdx; }
403
408 ResultType operator()(unsigned dofIdx) const
409 {
410 Valgrind::CheckDefined(dimIdx_);
411 return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).velocityCenter()[dimIdx_];
412 }
413
414private:
415 const ElementContext& elemCtx_;
416 unsigned dimIdx_;
417};
418
424template <class TypeTag>
426{
429
430 using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
431 using ResultRawType = decltype(std::declval<IQFluidState>().moleFraction(0, 0));
432
433public:
434 using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
435 using ResultValueType = typename MathToolbox<ResultType>::ValueType;
436
437 explicit MoleFractionCallback(const ElementContext& elemCtx)
438 : elemCtx_(elemCtx)
439 {
440 Valgrind::SetUndefined(phaseIdx_);
441 Valgrind::SetUndefined(compIdx_);
442 }
443
444 MoleFractionCallback(const ElementContext& elemCtx, unsigned phaseIdx, unsigned compIdx)
445 : elemCtx_(elemCtx)
446 , phaseIdx_(static_cast<unsigned short>(phaseIdx))
447 , compIdx_(static_cast<unsigned short>(compIdx))
448 {}
449
454 void setPhaseIndex(unsigned phaseIdx)
455 { phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
456
461 void setComponentIndex(unsigned compIdx)
462 { compIdx_ = static_cast<unsigned short>(compIdx); }
463
468 ResultType operator()(unsigned dofIdx) const
469 {
470 Valgrind::CheckDefined(phaseIdx_);
471 Valgrind::CheckDefined(compIdx_);
472 return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().moleFraction(phaseIdx_, compIdx_);
473 }
474
475private:
476 const ElementContext& elemCtx_;
477 unsigned short phaseIdx_;
478 unsigned short compIdx_;
479};
480
481} // namespace Opm
482
483#endif
Callback class for a phase pressure.
Definition: quantitycallbacks.hh:134
IQScalar ResultType
Definition: quantitycallbacks.hh:145
BoundaryPressureCallback(const ElementContext &elemCtx, const FluidState &boundaryFs, unsigned phaseIdx)
Definition: quantitycallbacks.hh:152
BoundaryPressureCallback(const ElementContext &elemCtx, const FluidState &boundaryFs)
Definition: quantitycallbacks.hh:147
IQScalar boundaryValue() const
Definition: quantitycallbacks.hh:177
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the pressure should be returned.
Definition: quantitycallbacks.hh:164
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:171
Callback class for the density of a phase.
Definition: quantitycallbacks.hh:196
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the density should be returned.
Definition: quantitycallbacks.hh:220
DensityCallback(const ElementContext &elemCtx, unsigned phaseIdx)
Definition: quantitycallbacks.hh:211
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:227
typename MathToolbox< ResultType >::ValueType ResultValueType
Definition: quantitycallbacks.hh:205
std::remove_const_t< std::remove_reference_t< ResultRawType > > ResultType
Definition: quantitycallbacks.hh:204
DensityCallback(const ElementContext &elemCtx)
Definition: quantitycallbacks.hh:207
Callback class for the molar density of a phase.
Definition: quantitycallbacks.hh:245
typename MathToolbox< ResultType >::ValueType ResultValueType
Definition: quantitycallbacks.hh:253
decltype(std::declval< IQFluidState >().molarDensity(0)) ResultType
Definition: quantitycallbacks.hh:252
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the molar density should be returned.
Definition: quantitycallbacks.hh:268
MolarDensityCallback(const ElementContext &elemCtx, unsigned phaseIdx)
Definition: quantitycallbacks.hh:259
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:275
MolarDensityCallback(const ElementContext &elemCtx)
Definition: quantitycallbacks.hh:255
Callback class for a mole fraction of a component in a phase.
Definition: quantitycallbacks.hh:426
void setComponentIndex(unsigned compIdx)
Set the index of the component for which the mole fraction should be returned.
Definition: quantitycallbacks.hh:461
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which a mole fraction should be returned.
Definition: quantitycallbacks.hh:454
MoleFractionCallback(const ElementContext &elemCtx, unsigned phaseIdx, unsigned compIdx)
Definition: quantitycallbacks.hh:444
typename MathToolbox< ResultType >::ValueType ResultValueType
Definition: quantitycallbacks.hh:435
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:468
std::remove_const_t< std::remove_reference_t< ResultRawType > > ResultType
Definition: quantitycallbacks.hh:434
MoleFractionCallback(const ElementContext &elemCtx)
Definition: quantitycallbacks.hh:437
Callback class for a phase pressure.
Definition: quantitycallbacks.hh:85
PressureCallback(const ElementContext &elemCtx, unsigned phaseIdx)
Definition: quantitycallbacks.hh:100
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:116
PressureCallback(const ElementContext &elemCtx)
Definition: quantitycallbacks.hh:96
typename MathToolbox< ResultType >::ValueType ResultValueType
Definition: quantitycallbacks.hh:94
std::remove_const_t< std::remove_reference_t< ResultRawType > > ResultType
Definition: quantitycallbacks.hh:93
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the pressure should be returned.
Definition: quantitycallbacks.hh:109
Callback class for temperature.
Definition: quantitycallbacks.hh:49
ResultType operator()(unsigned dofIdx) const
Return the temperature given the index of a degree of freedom within an element context.
Definition: quantitycallbacks.hh:71
TemperatureCallback(const ElementContext &elemCtx)
Definition: quantitycallbacks.hh:60
std::remove_const_t< std::remove_reference_t< ResultRawType > > ResultType
Definition: quantitycallbacks.hh:57
typename MathToolbox< ResultType >::ValueType ResultValueType
Definition: quantitycallbacks.hh:58
Callback class for the velocity of a phase at the center of a DOF.
Definition: quantitycallbacks.hh:342
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:364
std::remove_const_t< std::remove_reference_t< ResultRawType > > ResultType
Definition: quantitycallbacks.hh:352
typename ResultType::field_type ResultFieldType
Definition: quantitycallbacks.hh:353
typename MathToolbox< ResultFieldType >::ValueType ResultFieldValueType
Definition: quantitycallbacks.hh:354
VelocityCallback(const ElementContext &elemCtx)
Definition: quantitycallbacks.hh:356
Callback class for the velocity of a phase at the center of a DOF.
Definition: quantitycallbacks.hh:378
void setDimIndex(unsigned dimIdx)
Set the index of the component of the velocity which should be returned.
Definition: quantitycallbacks.hh:401
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:408
std::remove_const_t< std::remove_reference_t< ResultRawType > > ResultType
Definition: quantitycallbacks.hh:385
typename MathToolbox< ResultType >::ValueType ResultValueType
Definition: quantitycallbacks.hh:386
VelocityComponentCallback(const ElementContext &elemCtx)
Definition: quantitycallbacks.hh:388
VelocityComponentCallback(const ElementContext &elemCtx, unsigned dimIdx)
Definition: quantitycallbacks.hh:392
Callback class for the viscosity of a phase.
Definition: quantitycallbacks.hh:293
typename MathToolbox< ResultType >::ValueType ResultValueType
Definition: quantitycallbacks.hh:302
ViscosityCallback(const ElementContext &elemCtx, unsigned phaseIdx)
Definition: quantitycallbacks.hh:308
std::remove_const_t< std::remove_reference_t< ResultRawType > > ResultType
Definition: quantitycallbacks.hh:301
ViscosityCallback(const ElementContext &elemCtx)
Definition: quantitycallbacks.hh:304
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:324
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the viscosity should be returned.
Definition: quantitycallbacks.hh:317
Declare the properties used by the infrastructure code of the finite volume discretizations.
Definition: blackoilboundaryratevector.hh:39
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233