Commit c1a7b445 authored by Katharina Heck's avatar Katharina Heck Committed by Kilian Weishaupt
Browse files

[feature][tracer] make example work with vectors and with mass fractions as well

parent 65546d49
......@@ -53,8 +53,10 @@ class TracerLocalResidual: public GET_PROP_TYPE(TypeTag, BaseLocalResidual)
using ElementVolumeVariables = typename GET_PROP_TYPE(TypeTag, ElementVolumeVariables);
using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables);
using EnergyLocalResidual = typename GET_PROP_TYPE(TypeTag, EnergyLocalResidual);
using FluidSystem = typename GET_PROP_TYPE(TypeTag, FluidSystem);
static const int numComponents = GET_PROP_VALUE(TypeTag, NumComponents);
static const bool useMoles = GET_PROP_VALUE(TypeTag, UseMoles);
public:
......@@ -70,8 +72,7 @@ public:
* \param useMoles If mole or mass fractions are used
*/
PrimaryVariables computeStorage(const SubControlVolume& scv,
const VolumeVariables& volVars,
bool useMoles = true) const
const VolumeVariables& volVars) const
{
PrimaryVariables storage(0.0);
......@@ -110,15 +111,14 @@ public:
const FVElementGeometry& fvGeometry,
const ElementVolumeVariables& elemVolVars,
const SubControlVolumeFace& scvf,
const ElementFluxVariablesCache& elemFluxVarsCache,
bool useMoles = true)
const ElementFluxVariablesCache& elemFluxVarsCache)
{
FluxVariables fluxVars;
fluxVars.init(this->problem(), element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
// get upwind weights into local scope
PrimaryVariables flux(0.0);
const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(0);
// formulation with mole balances
if (useMoles)
{
......@@ -131,7 +131,7 @@ public:
// advective fluxes
flux[compIdx] += fluxVars.advectiveFlux(0, upwindTerm);
// diffusive fluxes
flux[compIdx] += fluxVars.molecularDiffusionFlux(0, compIdx);
flux[compIdx] += diffusiveFluxes[compIdx];
}
}
// formulation with mass balances
......@@ -146,7 +146,7 @@ public:
// advective fluxes
flux[compIdx] += fluxVars.advectiveFlux(0, upwindTerm);
// diffusive fluxes
flux[compIdx] += fluxVars.molecularDiffusionFlux(0, compIdx);
flux[compIdx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx);
}
}
......
......@@ -82,7 +82,16 @@ public:
for (int compIdx = 0; compIdx < numComponents; ++compIdx)
{
moleFraction_[compIdx] = this->priVars()[compIdx];
if (useMoles)
{
moleFraction_[compIdx] = this->priVars()[compIdx];
massFraction_[compIdx] = moleFraction_[compIdx]*FluidSystem::molarMass(compIdx)/fluidMolarMass_;
}
else
{
massFraction_[compIdx] = this->priVars()[compIdx];
moleFraction_[compIdx] = massFraction_[compIdx]/FluidSystem::molarMass(compIdx)*fluidMolarMass_;
}
diffCoeff_[compIdx] =
FluidSystem::binaryDiffusionCoefficient(compIdx, problem, element, scv);
}
......@@ -132,7 +141,7 @@ public:
* \param compIdx The index of the component
*/
Scalar massFraction(int pIdx, int compIdx) const
{ return moleFraction_[compIdx]*FluidSystem::molarMass(compIdx)/fluidMolarMass_; }
{ return massFraction_[compIdx]; }
/*!
* \brief Return concentration \f$\mathrm{[mol/m^3]}\f$ of a component in the phase.
......@@ -165,6 +174,7 @@ protected:
GlobalPosition dispersivity_;
std::array<Scalar, numComponents> diffCoeff_;
std::array<Scalar, numComponents> moleFraction_;
std::array<Scalar, numComponents> massFraction_;
private:
const Problem* problem_;
......
......@@ -66,6 +66,7 @@ class TracerFluidSystem
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
using Element = typename GridView::template Codim<0>::Entity;
using SubControlVolume = typename GET_PROP_TYPE(TypeTag, SubControlVolume);
public:
//! The number of components
static constexpr int numComponents = 1;
......@@ -120,6 +121,8 @@ class TracerTestProblem : public ImplicitPorousMediaProblem<TypeTag>
using TimeManager = typename GET_PROP_TYPE(TypeTag, TimeManager);
using BoundaryTypes = typename GET_PROP_TYPE(TypeTag, BoundaryTypes);
using PrimaryVariables = typename GET_PROP_TYPE(TypeTag, PrimaryVariables);
using FluidSystem = typename GET_PROP_TYPE(TypeTag, FluidSystem);
using SpatialParams = typename GET_PROP_TYPE(TypeTag, SpatialParams);
//! property that defines whether mole or mass fractions are used
static const bool useMoles = GET_PROP_VALUE(TypeTag, UseMoles);
......@@ -207,7 +210,12 @@ public:
{
PrimaryVariables initialValues(0.0);
if (globalPos[1] > 0.4 - eps_ && globalPos[1] < 0.6 + eps_)
initialValues = 1e-9;
{
if (useMoles)
initialValues = 1e-9;
else
initialValues = 1e-9*FluidSystem::molarMass(0)/this->spatialParams().fluidMolarMass(globalPos);
}
return initialValues; }
// \}
......
......@@ -88,6 +88,9 @@ public:
const SubControlVolume& scv) const
{ return 18.0; }
Scalar fluidMolarMass(const GlobalPosition &globalPos) const
{ return 18.0; }
//! velocity field
GlobalPosition velocity(const Element &element,
const SubControlVolumeFace& scvf) const
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment