Skip to content
Snippets Groups Projects
Commit caf7b807 authored by Klaus Mosthaf's avatar Klaus Mosthaf
Browse files

stokesncvolumevariables: introduced convenience functions for mass and mole fractions

stokesnclocalresidual: storage term is not set to zero here, this would lead to problems for a derived model model (e.g. nonisothermal stokesnc);
convenience functions are used for mass and mole fractions; small cleanup.

stokesncfluxvariables: use of convenience functions

Reviewed by Markus

git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@12138 2fb0f335-1f38-0410-981e-8018bf24f1b0
parent bd199347
No related branches found
No related tags found
No related merge requests found
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
* \brief Return the molar density \f$ \mathrm{[mol/m^3]} \f$ at the integration point. * \brief Return the molar density \f$ \mathrm{[mol/m^3]} \f$ at the integration point.
*/ */
const Scalar molarDensity() const const Scalar molarDensity() const
{ return this->molarDensity_; } { return molarDensity_; }
/*! /*!
* \brief Return the mass fraction of a transported component at the integration point. * \brief Return the mass fraction of a transported component at the integration point.
...@@ -121,9 +121,9 @@ protected: ...@@ -121,9 +121,9 @@ protected:
// loop over all components // loop over all components
for (int compIdx=0; compIdx<numComponents; compIdx++){ for (int compIdx=0; compIdx<numComponents; compIdx++){
if (phaseCompIdx!=compIdx) //no transport equationen parameters needed for the mass balance if (phaseCompIdx!=compIdx) //no transport equation parameters needed for the mass balance
{ {
this->molarDensity_ = Scalar(0.0); molarDensity_ = Scalar(0.0);
massFraction_[compIdx] = Scalar(0.0); massFraction_[compIdx] = Scalar(0.0);
diffusionCoeff_[compIdx] = Scalar(0.0); diffusionCoeff_[compIdx] = Scalar(0.0);
moleFractionGrad_[compIdx] = Scalar(0.0); moleFractionGrad_[compIdx] = Scalar(0.0);
...@@ -134,10 +134,9 @@ protected: ...@@ -134,10 +134,9 @@ protected:
scvIdx++) // loop over vertices of the element scvIdx++) // loop over vertices of the element
{ {
this->molarDensity_ += elemVolVars[scvIdx].molarDensity()* molarDensity_ += elemVolVars[scvIdx].molarDensity()*
this->face().shapeValue[scvIdx]; this->face().shapeValue[scvIdx];
massFraction_[compIdx] += elemVolVars[scvIdx].massFraction(compIdx) *
massFraction_[compIdx] += elemVolVars[scvIdx].fluidState().massFraction(phaseIdx, compIdx) *
this->face().shapeValue[scvIdx]; this->face().shapeValue[scvIdx];
diffusionCoeff_[compIdx] += elemVolVars[scvIdx].diffusionCoeff(compIdx) * diffusionCoeff_[compIdx] += elemVolVars[scvIdx].diffusionCoeff(compIdx) *
this->face().shapeValue[scvIdx]; this->face().shapeValue[scvIdx];
...@@ -147,10 +146,11 @@ protected: ...@@ -147,10 +146,11 @@ protected:
{ {
moleFractionGrad_[compIdx] += moleFractionGrad_[compIdx] +=
this->face().grad[scvIdx][dimIdx] * this->face().grad[scvIdx][dimIdx] *
elemVolVars[scvIdx].fluidState().moleFraction(phaseIdx, compIdx); elemVolVars[scvIdx].moleFraction(compIdx);
} }
} }
Valgrind::CheckDefined(molarDensity_);
Valgrind::CheckDefined(massFraction_[compIdx]); Valgrind::CheckDefined(massFraction_[compIdx]);
Valgrind::CheckDefined(diffusionCoeff_[compIdx]); Valgrind::CheckDefined(diffusionCoeff_[compIdx]);
Valgrind::CheckDefined(moleFractionGrad_[compIdx]); Valgrind::CheckDefined(moleFractionGrad_[compIdx]);
......
...@@ -100,57 +100,44 @@ public: ...@@ -100,57 +100,44 @@ public:
*/ */
void computeStorage(PrimaryVariables &storage, const int scvIdx, const bool usePrevSol) const void computeStorage(PrimaryVariables &storage, const int scvIdx, const bool usePrevSol) const
{ {
// compute the storage term for the transport equation
// if flag usePrevSol is set, the solution from the previous ParentType::computeStorage(storage, scvIdx, usePrevSol);
// if flag usePrevSol is set, the solution from the previous
// time step is used, otherwise the current solution is // time step is used, otherwise the current solution is
// used. The secondary variables are used accordingly. This // used. The secondary variables are used accordingly. This
// is required to compute the derivative of the storage term // is required to compute the derivative of the storage term
// using the implicit Euler method. // using the implicit Euler method.
const ElementVolumeVariables &elemVolVars = usePrevSol ? this->prevVolVars_() const ElementVolumeVariables &elemVolVars = usePrevSol ?
: this->curVolVars_(); this->prevVolVars_() : this->curVolVars_();
const VolumeVariables &volVars = elemVolVars[scvIdx]; const VolumeVariables &volVars = elemVolVars[scvIdx];
storage = 0.0;
if (!useMoles) if (!useMoles)
{ {
/* works for a maximum of two components, for more components /* works for a maximum of two components, for more components
mole fractions must be used (property useMoles => true) */ mole fractions must be used (property useMoles => true) */
// mass and momentum balance
ParentType::computeStorage(storage, scvIdx, usePrevSol);
//storage of transported component //storage of transported component
storage[transportEqIdx] = volVars.density() storage[transportEqIdx] = volVars.density()
* volVars.fluidState().massFraction(phaseIdx, transportCompIdx); * volVars.massFraction(transportCompIdx);
Valgrind::CheckDefined(volVars.density()); Valgrind::CheckDefined(volVars.density());
Valgrind::CheckDefined(volVars.fluidState().massFraction(phaseIdx, transportCompIdx)); Valgrind::CheckDefined(volVars.massFraction(transportCompIdx));
} }
else else
{ {
/*//TODO call parent type function
// momentum balance
for (int momentumIdx = momentumXIdx; momentumIdx <= lastMomentumIdx; ++momentumIdx)
storage[momentumIdx] = volVars.molarDensity()
* volVars.velocity()[momentumIdx-momentumXIdx];*/
// mass and momentum balance
ParentType::computeStorage(storage, scvIdx, usePrevSol);
// mass balance and transport equations // mass balance and transport equations
for (int compIdx=0; compIdx<numComponents; compIdx++) for (int compIdx=0; compIdx<numComponents; compIdx++)
{ {
if (conti0EqIdx+compIdx != massBalanceIdx) if (conti0EqIdx+compIdx != massBalanceIdx)
//storage[massBalanceIdx] = volVars.molarDensity();
//else // transport equations //else // transport equations
{ {
storage[conti0EqIdx+compIdx] = volVars.molarDensity() storage[conti0EqIdx+compIdx] = volVars.molarDensity()
* volVars.fluidState().moleFraction(phaseIdx, compIdx); * volVars.moleFraction(compIdx);
Valgrind::CheckDefined(volVars.molarDensity()); Valgrind::CheckDefined(volVars.molarDensity());
Valgrind::CheckDefined(volVars.fluidState().moleFraction(phaseIdx, compIdx)); Valgrind::CheckDefined(volVars.moleFraction(compIdx));
} }
} }
} }
...@@ -169,53 +156,46 @@ public: ...@@ -169,53 +156,46 @@ public:
void computeAdvectiveFlux(PrimaryVariables &flux, void computeAdvectiveFlux(PrimaryVariables &flux,
const FluxVariables &fluxVars) const const FluxVariables &fluxVars) const
{ {
// call ParentType function
ParentType::computeAdvectiveFlux(flux,fluxVars);
// data attached to upstream and the downstream vertices // data attached to upstream and the downstream vertices
const VolumeVariables &up = this->curVolVars_(fluxVars.upstreamIdx()); const VolumeVariables &up = this->curVolVars_(fluxVars.upstreamIdx());
const VolumeVariables &dn = this->curVolVars_(fluxVars.downstreamIdx()); const VolumeVariables &dn = this->curVolVars_(fluxVars.downstreamIdx());
Scalar tmp = 0.0;
Scalar tmp = fluxVars.normalVelocity();
if(!useMoles) if(!useMoles)
{ {
// call ParentType function
ParentType::computeAdvectiveFlux(flux,fluxVars);
// for transport equations // for transport equations
tmp = fluxVars.normalVelocity();
if (this->massUpwindWeight_ > 0.0) if (this->massUpwindWeight_ > 0.0)
tmp *= this->massUpwindWeight_ // upwind data tmp *= this->massUpwindWeight_ // upwind data
* up.density() * up.density()
* up.fluidState().massFraction(phaseIdx, transportCompIdx); * up.massFraction(transportCompIdx);
if (this->massUpwindWeight_ < 1.0) if (this->massUpwindWeight_ < 1.0)
tmp += (1.0 - this->massUpwindWeight_) // rest tmp += (1.0 - this->massUpwindWeight_) // rest
* dn.density() * dn.density()
* dn.fluidState().massFraction(phaseIdx, transportCompIdx); * dn.massFraction(transportCompIdx);
flux[transportEqIdx] += tmp; flux[transportEqIdx] += tmp;
Valgrind::CheckDefined(flux[transportEqIdx]); Valgrind::CheckDefined(flux[transportEqIdx]);
} }
else else
{ {
// call ParentType function
ParentType::computeAdvectiveFlux(flux,fluxVars);
//transport equations //transport equations
for (int compIdx=0; compIdx<numComponents; compIdx++) for (int compIdx=0; compIdx<numComponents; compIdx++)
{ {
if (conti0EqIdx+compIdx != massBalanceIdx) //mass balance is calculated above if (conti0EqIdx+compIdx != massBalanceIdx) //mass balance is calculated above
{ {
tmp = fluxVars.normalVelocity();
if (this->massUpwindWeight_ > 0.0) if (this->massUpwindWeight_ > 0.0)
tmp *= this->massUpwindWeight_ // upwind data tmp *= this->massUpwindWeight_ // upwind data
* up.molarDensity() * up.molarDensity()
* up.fluidState().moleFraction(phaseIdx, compIdx); * up.moleFraction(compIdx);
if (this->massUpwindWeight_ < 1.0) if (this->massUpwindWeight_ < 1.0)
tmp += (1.0 - this->massUpwindWeight_) // rest tmp += (1.0 - this->massUpwindWeight_) // rest
* dn.molarDensity() * dn.molarDensity()
* dn.fluidState().moleFraction(phaseIdx, compIdx); * dn.moleFraction(compIdx);
flux[conti0EqIdx+compIdx] += tmp; flux[conti0EqIdx+compIdx] += tmp;
Valgrind::CheckDefined(flux[conti0EqIdx+compIdx]); Valgrind::CheckDefined(flux[conti0EqIdx+compIdx]);
...@@ -236,15 +216,15 @@ public: ...@@ -236,15 +216,15 @@ public:
const FluxVariables &fluxVars) const const FluxVariables &fluxVars) const
{ {
// diffusive component flux // diffusive component flux
for (int dimIdx = 0; dimIdx < dim; ++dimIdx){ for (int dimIdx = 0; dimIdx < dim; ++dimIdx)
{
if(!useMoles) if(!useMoles)
{ {
flux[transportEqIdx] -= fluxVars.moleFractionGrad(transportCompIdx)[dimIdx] flux[transportEqIdx] -= fluxVars.moleFractionGrad(transportCompIdx)[dimIdx]
* fluxVars.face().normal[dimIdx] * fluxVars.face().normal[dimIdx]
*(fluxVars.diffusionCoeff(transportCompIdx) + fluxVars.eddyDiffusivity()) *(fluxVars.diffusionCoeff(transportCompIdx) + fluxVars.eddyDiffusivity())
* fluxVars.molarDensity() * fluxVars.molarDensity()
* FluidSystem::molarMass(transportCompIdx);// Multipled by molarMass [kg/mol] to convert form [mol/m^3 s] to [kg/m^3 s] * FluidSystem::molarMass(transportCompIdx);// Multiplied by molarMass [kg/mol] to convert form [mol/m^3 s] to [kg/m^3 s]
Valgrind::CheckDefined(flux[transportEqIdx]); Valgrind::CheckDefined(flux[transportEqIdx]);
} }
else else
......
...@@ -49,7 +49,7 @@ namespace Properties ...@@ -49,7 +49,7 @@ namespace Properties
// Properties // Properties
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
//!< Define that mass fractions are used in the balance equations //!< Define that mole fractions are used in the balance equations
SET_BOOL_PROP(BoxStokesnc, UseMoles, true); SET_BOOL_PROP(BoxStokesnc, UseMoles, true);
SET_PROP(BoxStokesnc, NumEq) //!< set the number of equations SET_PROP(BoxStokesnc, NumEq) //!< set the number of equations
......
...@@ -105,17 +105,20 @@ public: ...@@ -105,17 +105,20 @@ public:
typename FluidSystem::ParameterCache paramCache; typename FluidSystem::ParameterCache paramCache;
paramCache.updateAll(this->fluidState()); paramCache.updateAll(this->fluidState());
for (int compIdx=0; compIdx<numComponents; compIdx++){ for (int compIdx=0; compIdx<numComponents; compIdx++)
if (phaseCompIdx!=compIdx){ {
if (phaseCompIdx!=compIdx)
{
diffCoeff_[compIdx] = FluidSystem::binaryDiffusionCoefficient(this->fluidState(), diffCoeff_[compIdx] = FluidSystem::binaryDiffusionCoefficient(this->fluidState(),
paramCache, paramCache,
phaseIdx, phaseIdx,
compIdx, compIdx,
phaseCompIdx); phaseCompIdx);
Valgrind::CheckDefined(diffCoeff_[compIdx]);
} }
else
diffCoeff_[compIdx] = 0.0;
Valgrind::CheckDefined(diffCoeff_[compIdx]);
} }
}; };
...@@ -163,19 +166,34 @@ public: ...@@ -163,19 +166,34 @@ public:
//molefraction for the main component (no primary variable) //molefraction for the main component (no primary variable)
moleFracPhase = 1 - sumMoleFrac; moleFracPhase = 1 - sumMoleFrac;
fluidState.setMoleFraction(phaseIdx, phaseIdx, moleFracPhase); fluidState.setMoleFraction(phaseIdx, phaseCompIdx, moleFracPhase);
} }
} }
/*!
* \brief Returns the mass fraction of a given component in the
* given fluid phase within the control volume.
*
* \param compIdx The component index
*/
Scalar massFraction(const int compIdx) const
{ return this->fluidState_.massFraction(phaseIdx, compIdx); }
/*!
* \brief Returns the mass fraction of a given component in the
* given fluid phase within the control volume.
*
* \param compIdx The component index
*/
Scalar moleFraction(const int compIdx) const
{ return this->fluidState_.moleFraction(phaseIdx, compIdx); }
/*! /*!
* \brief Returns the molar density \f$\mathrm{[mol/m^3]}\f$ of the fluid within the * \brief Returns the molar density \f$\mathrm{[mol/m^3]}\f$ of the fluid within the
* sub-control volume. * sub-control volume.
*/ */
Scalar molarDensity() const Scalar molarDensity() const
{ { return this->fluidState_.density(phaseIdx) / this->fluidState_.averageMolarMass(phaseIdx); }
return this->fluidState_.density(phaseIdx) / this->fluidState_.averageMolarMass(phaseIdx);
}
/*! /*!
* \brief Returns the binary (mass) diffusion coefficient * \brief Returns the binary (mass) diffusion coefficient
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment