Loading...
Searching...
No Matches
quantitycallbacks.hh
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef EWOMS_QUANTITY_CALLBACKS_HH
#define EWOMS_QUANTITY_CALLBACKS_HH
#include <opm/models/discretization/common/fvbaseproperties.hh>
#include <opm/material/common/MathToolbox.hpp>
#include <opm/material/common/Valgrind.hpp>
#include <type_traits>
#include <utility>
namespace Opm {
template <class TypeTag>
class TemperatureCallback
{
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
using ResultRawType = decltype(std::declval<IQFluidState>().temperature(0));
public:
using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
using ResultValueType = typename MathToolbox<ResultType>::ValueType;
explicit TemperatureCallback(const ElementContext& elemCtx)
: elemCtx_(elemCtx)
{}
ResultType operator()(unsigned dofIdx) const
{ return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().temperature(/*phaseIdx=*/0); }
private:
const ElementContext& elemCtx_;
};
template <class TypeTag>
class PressureCallback
{
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
using ResultRawType = decltype(std::declval<IQFluidState>().pressure(0));
public:
using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
using ResultValueType = typename MathToolbox<ResultType>::ValueType;
explicit PressureCallback(const ElementContext& elemCtx)
: elemCtx_(elemCtx)
{ Valgrind::SetUndefined(phaseIdx_); }
PressureCallback(const ElementContext& elemCtx, unsigned phaseIdx)
: elemCtx_(elemCtx)
, phaseIdx_(static_cast<unsigned short>(phaseIdx))
{}
void setPhaseIndex(unsigned phaseIdx)
{ phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
ResultType operator()(unsigned dofIdx) const
{
Valgrind::CheckDefined(phaseIdx_);
return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().pressure(phaseIdx_);
}
private:
const ElementContext& elemCtx_;
unsigned short phaseIdx_;
};
template <class TypeTag, class FluidState>
class BoundaryPressureCallback
{
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using IQRawFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
using IQFluidState = std::remove_const_t<std::remove_reference_t<IQRawFluidState>>;
using IQScalar = typename IQFluidState::Scalar;
public:
using ResultType = IQScalar;
BoundaryPressureCallback(const ElementContext& elemCtx, const FluidState& boundaryFs)
: elemCtx_(elemCtx)
, boundaryFs_(boundaryFs)
{ Valgrind::SetUndefined(phaseIdx_); }
BoundaryPressureCallback(const ElementContext& elemCtx,
const FluidState& boundaryFs,
unsigned phaseIdx)
: elemCtx_(elemCtx)
, boundaryFs_(boundaryFs)
, phaseIdx_(static_cast<unsigned short>(phaseIdx))
{}
void setPhaseIndex(unsigned phaseIdx)
{ phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
ResultType operator()(unsigned dofIdx) const
{
Valgrind::CheckDefined(phaseIdx_);
return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().pressure(phaseIdx_);
}
IQScalar boundaryValue() const
{
Valgrind::CheckDefined(phaseIdx_);
return boundaryFs_.pressure(phaseIdx_);
}
private:
const ElementContext& elemCtx_;
const FluidState& boundaryFs_;
unsigned short phaseIdx_;
};
template <class TypeTag>
class DensityCallback
{
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
using ResultRawType = decltype(std::declval<IQFluidState>().density(0));
public:
using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
using ResultValueType = typename MathToolbox<ResultType>::ValueType;
explicit DensityCallback(const ElementContext& elemCtx)
: elemCtx_(elemCtx)
{ Valgrind::SetUndefined(phaseIdx_); }
DensityCallback(const ElementContext& elemCtx, unsigned phaseIdx)
: elemCtx_(elemCtx)
, phaseIdx_(static_cast<unsigned short>(phaseIdx))
{}
void setPhaseIndex(unsigned phaseIdx)
{ phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
ResultType operator()(unsigned dofIdx) const
{
Valgrind::CheckDefined(phaseIdx_);
return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().density(phaseIdx_);
}
private:
const ElementContext& elemCtx_;
unsigned short phaseIdx_;
};
template <class TypeTag>
class MolarDensityCallback
{
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
public:
using ResultType = decltype(std::declval<IQFluidState>().molarDensity(0));
using ResultValueType = typename MathToolbox<ResultType>::ValueType;
explicit MolarDensityCallback(const ElementContext& elemCtx)
: elemCtx_(elemCtx)
{ Valgrind::SetUndefined(phaseIdx_); }
MolarDensityCallback(const ElementContext& elemCtx, unsigned phaseIdx)
: elemCtx_(elemCtx)
, phaseIdx_(static_cast<unsigned short>(phaseIdx))
{}
void setPhaseIndex(unsigned phaseIdx)
{ phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
ResultType operator()(unsigned dofIdx) const
{
Valgrind::CheckDefined(phaseIdx_);
return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().molarDensity(phaseIdx_);
}
private:
const ElementContext& elemCtx_;
unsigned short phaseIdx_;
};
template <class TypeTag>
class ViscosityCallback
{
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
using ResultRawType = decltype(std::declval<IQFluidState>().viscosity(0));
public:
using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
using ResultValueType = typename MathToolbox<ResultType>::ValueType;
explicit ViscosityCallback(const ElementContext& elemCtx)
: elemCtx_(elemCtx)
{ Valgrind::SetUndefined(phaseIdx_); }
ViscosityCallback(const ElementContext& elemCtx, unsigned phaseIdx)
: elemCtx_(elemCtx)
, phaseIdx_(static_cast<unsigned short>(phaseIdx))
{}
void setPhaseIndex(unsigned phaseIdx)
{ phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
ResultType operator()(unsigned dofIdx) const
{
Valgrind::CheckDefined(phaseIdx_);
return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().viscosity(phaseIdx_);
}
private:
const ElementContext& elemCtx_;
unsigned short phaseIdx_;
};
template <class TypeTag>
class VelocityCallback
{
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using ResultRawType = decltype(IntensiveQuantities().velocityCenter());
public:
using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
using ResultFieldType = typename ResultType::field_type;
using ResultFieldValueType = typename MathToolbox<ResultFieldType>::ValueType;
explicit VelocityCallback(const ElementContext& elemCtx)
: elemCtx_(elemCtx)
{}
ResultType operator()(unsigned dofIdx) const
{ return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).velocityCenter(); }
private:
const ElementContext& elemCtx_;
};
template <class TypeTag>
class VelocityComponentCallback
{
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using ResultRawType = decltype(IntensiveQuantities().velocityCenter()[0]);
public:
using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
using ResultValueType = typename MathToolbox<ResultType>::ValueType;
explicit VelocityComponentCallback(const ElementContext& elemCtx)
: elemCtx_(elemCtx)
{ Valgrind::SetUndefined(dimIdx_); }
VelocityComponentCallback(const ElementContext& elemCtx, unsigned dimIdx)
: elemCtx_(elemCtx)
, dimIdx_(dimIdx)
{}
void setDimIndex(unsigned dimIdx)
{ dimIdx_ = dimIdx; }
ResultType operator()(unsigned dofIdx) const
{
Valgrind::CheckDefined(dimIdx_);
return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).velocityCenter()[dimIdx_];
}
private:
const ElementContext& elemCtx_;
unsigned dimIdx_;
};
template <class TypeTag>
class MoleFractionCallback
{
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using IQFluidState = decltype(std::declval<IntensiveQuantities>().fluidState());
using ResultRawType = decltype(std::declval<IQFluidState>().moleFraction(0, 0));
public:
using ResultType = std::remove_const_t<std::remove_reference_t<ResultRawType>>;
using ResultValueType = typename MathToolbox<ResultType>::ValueType;
explicit MoleFractionCallback(const ElementContext& elemCtx)
: elemCtx_(elemCtx)
{
Valgrind::SetUndefined(phaseIdx_);
Valgrind::SetUndefined(compIdx_);
}
MoleFractionCallback(const ElementContext& elemCtx, unsigned phaseIdx, unsigned compIdx)
: elemCtx_(elemCtx)
, phaseIdx_(static_cast<unsigned short>(phaseIdx))
, compIdx_(static_cast<unsigned short>(compIdx))
{}
void setPhaseIndex(unsigned phaseIdx)
{ phaseIdx_ = static_cast<unsigned short>(phaseIdx); }
void setComponentIndex(unsigned compIdx)
{ compIdx_ = static_cast<unsigned short>(compIdx); }
ResultType operator()(unsigned dofIdx) const
{
Valgrind::CheckDefined(phaseIdx_);
Valgrind::CheckDefined(compIdx_);
return elemCtx_.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState().moleFraction(phaseIdx_, compIdx_);
}
private:
const ElementContext& elemCtx_;
unsigned short phaseIdx_;
unsigned short compIdx_;
};
} // namespace Opm
#endif
Opm::BoundaryPressureCallback::setPhaseIndex
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the pressure should be returned.
Definition quantitycallbacks.hh:163
Opm::BoundaryPressureCallback::operator()
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
Opm::DensityCallback::setPhaseIndex
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the density should be returned.
Definition quantitycallbacks.hh:219
Opm::DensityCallback::operator()
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
Opm::MolarDensityCallback::setPhaseIndex
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the molar density should be returned.
Definition quantitycallbacks.hh:267
Opm::MolarDensityCallback::operator()
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
Opm::MoleFractionCallback::setComponentIndex
void setComponentIndex(unsigned compIdx)
Set the index of the component for which the mole fraction should be returned.
Definition quantitycallbacks.hh:457
Opm::MoleFractionCallback::setPhaseIndex
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which a mole fraction should be returned.
Definition quantitycallbacks.hh:450
Opm::MoleFractionCallback::operator()
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:464
Opm::PressureCallback::operator()
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
Opm::PressureCallback::setPhaseIndex
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the pressure should be returned.
Definition quantitycallbacks.hh:109
Opm::TemperatureCallback::operator()
ResultType operator()(unsigned dofIdx) const
Return the temperature given the index of a degree of freedom within an element context.
Definition quantitycallbacks.hh:71
Opm::VelocityCallback::operator()
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:360
Opm::VelocityComponentCallback::setDimIndex
void setDimIndex(unsigned dimIdx)
Set the index of the component of the velocity which should be returned.
Definition quantitycallbacks.hh:397
Opm::VelocityComponentCallback::operator()
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:404
Opm::ViscosityCallback::operator()
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
Opm::ViscosityCallback::setPhaseIndex
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the viscosity should be returned.
Definition quantitycallbacks.hh:316
fvbaseproperties.hh
Declare the properties used by the infrastructure code of the finite volume discretizations.
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::GetPropType
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