25#ifndef DUMUX_DISCRETIZATION_BOX_MAXWELL_STEFAN_LAW_HH
26#define DUMUX_DISCRETIZATION_BOX_MAXWELL_STEFAN_LAW_HH
28#include <dune/common/float_cmp.hh>
29#include <dune/common/fmatrix.hh>
43template <
class TypeTag, DiscretizationMethod discMethod, ReferenceSystemFormulation referenceSystem>
44class MaxwellStefansLawImplementation;
50template <
class TypeTag, ReferenceSystemFormulation referenceSystem>
58 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
62 using Element =
typename GridView::template Codim<0>::Entity;
67 using ComponentFluxVector = Dune::FieldVector<Scalar, numComponents>;
68 using ReducedComponentVector = Dune::FieldVector<Scalar, numComponents-1>;
69 using ReducedComponentMatrix = Dune::FieldMatrix<Scalar, numComponents-1, numComponents-1>;
78 {
return referenceSystem; }
80 static ComponentFluxVector
flux(
const Problem& problem,
81 const Element& element,
82 const FVElementGeometry& fvGeometry,
83 const ElementVolumeVariables& elemVolVars,
84 const SubControlVolumeFace& scvf,
86 const ElementFluxVariablesCache& elemFluxVarsCache)
90 ComponentFluxVector componentFlux(0.0);
91 ReducedComponentMatrix reducedDiffusionMatrix(0.0);
92 ReducedComponentVector reducedFlux(0.0);
93 ComponentFluxVector moleFrac(0.0);
94 ReducedComponentVector normalX(0.0);
97 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
98 const auto& shapeValues = fluxVarsCache.shapeValues();
101 Scalar avgMolarMass(0.0);
102 for (
auto&& scv : scvs(fvGeometry))
104 const auto& volVars = elemVolVars[scv];
107 rho += volVars.density(phaseIdx)*shapeValues[scv.indexInElement()][0];
109 avgMolarMass += volVars.averageMolarMass(phaseIdx)*shapeValues[scv.indexInElement()][0];
111 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
113 moleFrac[compIdx] += volVars.moleFraction(phaseIdx, compIdx)*shapeValues[scv.indexInElement()][0];
117 reducedDiffusionMatrix = setupMSMatrix_(problem, element, fvGeometry, elemVolVars, scvf, phaseIdx, moleFrac, avgMolarMass);
119 for (
int compIdx = 0; compIdx < numComponents-1; compIdx++)
121 Dune::FieldVector<Scalar, GridView::dimensionworld> gradX(0.0);
122 for (
auto&& scv : scvs(fvGeometry))
124 const auto& volVars = elemVolVars[scv];
127 gradX.axpy(volVars.moleFraction(phaseIdx, compIdx), fluxVarsCache.gradN(scv.indexInElement()));
130 normalX[compIdx] = gradX *scvf.unitOuterNormal();
132 reducedDiffusionMatrix.solve(reducedFlux,normalX);
133 reducedFlux *= -1.0*rho*scvf.area();
135 for (
int compIdx = 0; compIdx < numComponents-1; compIdx++)
137 componentFlux[compIdx] = reducedFlux[compIdx];
138 componentFlux[numComponents-1] -= reducedFlux[compIdx];
140 return componentFlux ;
145 static ReducedComponentMatrix setupMSMatrix_(
const Problem& problem,
146 const Element& element,
147 const FVElementGeometry& fvGeometry,
148 const ElementVolumeVariables& elemVolVars,
149 const SubControlVolumeFace& scvf,
151 const ComponentFluxVector moleFrac,
152 const Scalar avgMolarMass)
155 ReducedComponentMatrix reducedDiffusionMatrix(0.0);
157 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
158 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
159 const auto insideScvIdx = scvf.insideScvIdx();
160 const auto outsideScvIdx = scvf.outsideScvIdx();
163 if(Dune::FloatCmp::eq<Scalar>(insideVolVars.saturation(phaseIdx), 0) || Dune::FloatCmp::eq<Scalar>(outsideVolVars.saturation(phaseIdx), 0))
164 return reducedDiffusionMatrix;
166 for (
int compIIdx = 0; compIIdx < numComponents-1; compIIdx++)
169 const auto xi = moleFrac[compIIdx];
170 const auto Mn = FluidSystem::molarMass(numComponents-1);
172 auto tinInside = Deprecated::template effectiveMSDiffusionCoefficient<EffDiffModel, FluidSystem>(insideVolVars, phaseIdx, compIIdx, numComponents-1, problem, element, fvGeometry.scv(insideScvIdx));
173 auto tinOutside = Deprecated::template effectiveMSDiffusionCoefficient<EffDiffModel, FluidSystem>(outsideVolVars, phaseIdx, compIIdx, numComponents-1, problem, element, fvGeometry.scv(outsideScvIdx));
176 tinInside *= insideVolVars.extrusionFactor();
177 tinOutside *= outsideVolVars.extrusionFactor();
180 const auto tin = problem.spatialParams().harmonicMean(tinInside, tinOutside, scvf.unitOuterNormal());
183 reducedDiffusionMatrix[compIIdx][compIIdx] += xi*avgMolarMass/(tin*Mn);
186 for (
int compJIdx = 0; compJIdx < numComponents; compJIdx++)
189 if (compIIdx == compJIdx)
193 const auto xj = moleFrac[compJIdx];
194 const auto Mi = FluidSystem::molarMass(compIIdx);
195 const auto Mj = FluidSystem::molarMass(compJIdx);
198 auto tijInside = Deprecated::template effectiveMSDiffusionCoefficient<EffDiffModel, FluidSystem>(insideVolVars, phaseIdx, compIIdx, compJIdx, problem, element, fvGeometry.scv(insideScvIdx));
200 auto tijOutside = Deprecated::template effectiveMSDiffusionCoefficient<EffDiffModel, FluidSystem>(outsideVolVars, phaseIdx, compIIdx, compJIdx, problem, element, fvGeometry.scv(outsideScvIdx));
203 tijInside *= insideVolVars.extrusionFactor();
204 tijOutside *= outsideVolVars.extrusionFactor();
207 const auto tij = problem.spatialParams().harmonicMean(tijInside, tijOutside, scvf.unitOuterNormal());
209 reducedDiffusionMatrix[compIIdx][compIIdx] += xj*avgMolarMass/(tij*Mi);
210 if (compJIdx < numComponents-1)
211 reducedDiffusionMatrix[compIIdx][compJIdx] +=xi*(avgMolarMass/(tin*Mn) - avgMolarMass/(tij*Mj));
214 return reducedDiffusionMatrix;
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
The reference frameworks and formulations available for splitting total fluxes into a advective and d...
Classes related to flux variables caching.
Container storing the diffusion coefficients required by the Maxwell- Stefan diffusion law....
DiscretizationMethod
The available discretization methods in Dumux.
Definition: method.hh:37
ReferenceSystemFormulation
The formulations available for Fick's law related to the reference system.
Definition: referencesystemformulation.hh:45
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:149
Definition: maxwellstefanslaw.hh:37
static constexpr ReferenceSystemFormulation referenceSystemFormulation()
Definition: box/maxwellstefanslaw.hh:77
static ComponentFluxVector flux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const ElementFluxVariablesCache &elemFluxVarsCache)
Definition: box/maxwellstefanslaw.hh:80
Container storing the diffusion coefficients required by the Maxwell- Stefan diffusion law....
Definition: maxwellstefandiffusioncoefficients.hh:45
Declares all properties used in Dumux.