/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2015-2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM 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 3 of the License, or
(at your option) any later version.
OpenFOAM 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 OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "momentumTransferSystem.H"
#include "dragModel.H"
#include "virtualMassModel.H"
#include "liftModel.H"
#include "wallLubricationModel.H"
#include "turbulentDispersionModel.H"
#include "generateBlendedInterfacialModels.H"
#include "fvmDdt.H"
#include "fvmDiv.H"
#include "fvmSup.H"
#include "fvcDdt.H"
#include "fvcDiv.H"
#include "fvcFlux.H"
#include "fvcSnGrad.H"
#include "fvcMeshPhi.H"
#include "fvcReconstruct.H"
#include "scalarMatrices.H"
#include "pimpleNoLoopControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(momentumTransferSystem, 0);
}
const Foam::word Foam::momentumTransferSystem::propertiesName
(
"momentumTransfer"
);
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::IOobject Foam::momentumTransferSystem::io(const phaseSystem& fluid)
{
typeIOobject result
(
propertiesName,
fluid.mesh().time().constant(),
fluid.mesh(),
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
);
// Check for and warn about momentum transfer models being in the old
// location in constant/phaseProperties
const wordList modelEntries
({
modelName(),
modelName(),
modelName(),
modelName(),
modelName()
});
OStringStream modelEntriesString;
forAll(modelEntries, i)
{
modelEntriesString<< modelEntries[i];
if (i < modelEntries.size() - 2) modelEntriesString<< ", ";
if (i == modelEntries.size() - 2) modelEntriesString<< " and ";
}
if (!result.headerOk())
{
result.readOpt() = IOobject::NO_READ;
WarningInFunction
<< "Specifying momentum transfer model entries - "
<< modelEntriesString.str().c_str() << " - in "
<< fluid.relativeObjectPath() << " is deprecated. These "
<< "entries should now be specified in "
<< result.relativeObjectPath() << "." << endl;
}
else
{
forAll(modelEntries, i)
{
if (!fluid.found(modelEntries[i])) continue;
WarningInFunction
<< "Momentum transfer model entries - "
<< modelEntriesString.str().c_str() << " - in "
<< fluid.relativeObjectPath() << " are no longer used. These "
<< "entries are now read from " << result.relativeObjectPath()
<< "." << endl;
break;
}
}
return result;
}
template
const Foam::dictionary& Foam::momentumTransferSystem::modelsDict() const
{
const word key = modelName();
return
readOpt() == IOobject::NO_READ && fluid_.found(key)
? fluid_.subDict(key)
: subDict(key);
}
void Foam::momentumTransferSystem::readModels()
{
dragModels_ =
generateBlendedInterfacialModels
(
fluid_,
modelsDict()
);
virtualMassModels_ =
generateBlendedInterfacialModels
(
fluid_,
modelsDict()
);
liftModels_ =
generateBlendedInterfacialModels
(
fluid_,
modelsDict()
);
wallLubricationModels_ =
generateBlendedInterfacialModels
(
fluid_,
modelsDict()
);
turbulentDispersionModels_ =
generateBlendedInterfacialModels
(
fluid_,
modelsDict()
);
}
void Foam::momentumTransferSystem::addTmpField
(
tmp& result,
const tmp& field
) const
{
if (result.valid())
{
result.ref() += field;
}
else
{
if (field.isTmp())
{
result = field;
}
else
{
result = field().clone();
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::momentumTransferSystem::momentumTransferSystem(const phaseSystem& fluid)
:
IOdictionary(io(fluid)),
fluid_(fluid)
{
Info<< indentOrNl << "Constructing " << typeName << " from "
<< relativeObjectPath().c_str() << endl;
printDictionary print(*this);
readModels();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::momentumTransferSystem::~momentumTransferSystem()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::PtrList
Foam::momentumTransferSystem::Fs() const
{
PtrList Fs(fluid_.phases().size());
// Add the lift force
forAllConstIter
(
liftModelTable,
liftModels_,
liftModelIter
)
{
const phaseInterface& interface = liftModelIter()->interface();
const volVectorField F(liftModelIter()->F());
addField
(
interface.phase1(),
"F",
fvc::flux(F),
Fs
);
addField
(
interface.phase2(),
"F",
-fvc::flux(F),
Fs
);
}
// Add the wall lubrication force
forAllConstIter
(
wallLubricationModelTable,
wallLubricationModels_,
wallLubricationModelIter
)
{
const phaseInterface& interface =
wallLubricationModelIter()->interface();
const volVectorField F(wallLubricationModelIter()->F());
addField
(
interface.phase1(),
"F",
fvc::flux(F),
Fs
);
addField
(
interface.phase2(),
"F",
-fvc::flux(F),
Fs
);
}
// Add the phase pressure
forAll(fluid_.movingPhases(), movingPhasei)
{
const phaseModel& phase = fluid_.movingPhases()[movingPhasei];
addField
(
phase,
"F",
phase.pPrimef()*fvc::snGrad(phase)*fluid_.mesh().magSf(),
Fs
);
}
// Add the turbulent dispersion force
forAllConstIter
(
turbulentDispersionModelTable,
turbulentDispersionModels_,
turbulentDispersionModelIter
)
{
const phaseInterface& interface =
turbulentDispersionModelIter()->interface();
const surfaceScalarField Df
(
fvc::interpolate(turbulentDispersionModelIter()->D())
);
const volScalarField alpha12
(
interface.phase1().alpha() + interface.phase2().alpha()
);
const surfaceScalarField snGradAlpha1By12
(
fvc::snGrad
(
interface.phase1().alpha()
/max(alpha12, interface.phase1().residualAlpha())
)*fluid_.mesh().magSf()
);
const surfaceScalarField snGradAlpha2By12
(
fvc::snGrad
(
interface.phase2().alpha()
/max(alpha12, interface.phase2().residualAlpha())
)*fluid_.mesh().magSf()
);
addField(interface.phase1(), "F", Df*snGradAlpha1By12, Fs);
addField(interface.phase2(), "F", Df*snGradAlpha2By12, Fs);
}
return Fs;
}
Foam::PtrList
Foam::momentumTransferSystem::Ffs() const
{
PtrList Ffs(fluid_.phases().size());
// Add the lift force
forAllConstIter
(
liftModelTable,
liftModels_,
liftModelIter
)
{
const phaseInterface& interface = liftModelIter()->interface();
const surfaceScalarField Ff(liftModelIter()->Ff());
addField
(
interface.phase1(),
"Ff",
Ff,
Ffs
);
addField
(
interface.phase2(),
"Ff",
-Ff,
Ffs
);
}
// Add the wall lubrication force
forAllConstIter
(
wallLubricationModelTable,
wallLubricationModels_,
wallLubricationModelIter
)
{
const phaseInterface& interface =
wallLubricationModelIter()->interface();
const surfaceScalarField Ff(wallLubricationModelIter()->Ff());
addField
(
interface.phase1(),
"Ff",
Ff,
Ffs
);
addField
(
interface.phase2(),
"Ff",
-Ff,
Ffs
);
}
// Add the phase pressure
forAll(fluid_.movingPhases(), movingPhasei)
{
const phaseModel& phase = fluid_.movingPhases()[movingPhasei];
addField
(
phase,
"Ff",
phase.pPrimef()*fvc::snGrad(phase)*fluid_.mesh().magSf(),
Ffs
);
}
// Add the turbulent dispersion force
forAllConstIter
(
turbulentDispersionModelTable,
turbulentDispersionModels_,
turbulentDispersionModelIter
)
{
const phaseInterface& interface =
turbulentDispersionModelIter()->interface();
const surfaceScalarField Df
(
fvc::interpolate(turbulentDispersionModelIter()->D())
);
const volScalarField alpha12
(
interface.phase1().alpha() + interface.phase2().alpha()
);
const surfaceScalarField snGradAlpha1By12
(
fvc::snGrad
(
interface.phase1().alpha()
/max(alpha12, interface.phase1().residualAlpha())
)*fluid_.mesh().magSf()
);
const surfaceScalarField snGradAlpha2By12
(
fvc::snGrad
(
interface.phase2().alpha()
/max(alpha12, interface.phase2().residualAlpha())
)*fluid_.mesh().magSf()
);
addField(interface.phase1(), "F", Df*snGradAlpha1By12, Ffs);
addField(interface.phase2(), "F", Df*snGradAlpha2By12, Ffs);
}
return Ffs;
}
void Foam::momentumTransferSystem::invADVs
(
List>& ADVs
) const
{
const label n = ADVs.size();
scalarSquareMatrix AD(n);
scalarField source(n);
labelList pivotIndices(n);
forAll(ADVs[0][0], ci)
{
for (label i=0; i
void Foam::momentumTransferSystem::invADVs
(
PtrList>>& ADVs
) const
{
const label n = ADVs.size();
List> ADps(n);
for (label i=0; i& As,
PtrList& HVms,
PtrList>& invADVs,
PtrList>& invADVfs
) const
{
const label n = As.size();
invADVs.setSize(n);
invADVfs.setSize(n);
forAll(invADVs, i)
{
invADVs.set(i, new PtrList(n));
invADVs[i].set(i, As[i].clone());
invADVfs.set(i, new PtrList(n));
invADVfs[i].set(i, fvc::interpolate(As[i]));
}
labelList movingPhases(fluid_.phases().size(), -1);
forAll(fluid_.movingPhases(), movingPhasei)
{
movingPhases[fluid_.movingPhases()[movingPhasei].index()] =
movingPhasei;
}
Kds_.clear();
// Update the drag coefficients
forAllConstIter
(
dragModelTable,
dragModels_,
dragModelIter
)
{
const phaseInterface& interface = dragModelIter()->interface();
tmp tKd(dragModelIter()->K());
volScalarField& Kd = tKd.ref();
Kds_.insert(dragModelIter.key(), tKd.ptr());
// Zero-gradient the drag coefficient to boundaries with fixed velocity
forAll(Kd.boundaryField(), patchi)
{
if
(
(
!interface.phase1().stationary()
&& interface.phase1().U()()
.boundaryField()[patchi].fixesValue()
)
&& (
!interface.phase2().stationary()
&& interface.phase2().U()()
.boundaryField()[patchi].fixesValue()
)
)
{
Kd.boundaryFieldRef()[patchi] =
Kd.boundaryField()[patchi].patchInternalField();
}
}
forAllConstIter(phaseInterface, interface, iter)
{
const phaseModel& phase = iter();
const phaseModel& otherPhase = iter.otherPhase();
const label i = movingPhases[phase.index()];
if (i != -1)
{
const volScalarField Kdij
(
(
otherPhase.alpha()
/max(otherPhase.alpha(), otherPhase.residualAlpha())
)*Kd
);
const surfaceScalarField Kdijf(fvc::interpolate(Kdij));
invADVs[i][i] += Kdij;
invADVfs[i][i] += Kdijf;
const label j = movingPhases[otherPhase.index()];
if (j != -1)
{
invADVs[i].set(j, -Kdij);
invADVfs[i].set(j, -Kdijf);
}
}
}
}
// Clear the Kds_ if they are not needed for the optional dragCorrection
const pimpleNoLoopControl& pimple = fluid_.pimple();
if (!pimple.dict().lookupOrDefault("dragCorrection", false))
{
Kds_.clear();
}
for (label i=0; i ADUDts(movingPhases.size());
PtrList HDUDts(movingPhases.size());
forAllConstIter
(
virtualMassModelTable,
virtualMassModels_,
VmIter
)
{
const phaseInterface& interface = VmIter()->interface();
forAllConstIter(phaseInterface, interface, iter)
{
const phaseModel& phase = iter();
const label i = movingPhases[phase.index()];
if (i != -1 && !ADUDts.set(i))
{
const fvVectorMatrix DUDt(phase.DUDt());
ADUDts.set(i, DUDt.A());
HDUDts.set(i, DUDt.H());
}
}
}
// Add the virtual mass contributions
forAllConstIter
(
virtualMassModelTable,
virtualMassModels_,
VmIter
)
{
const phaseInterface& interface = VmIter()->interface();
const volScalarField Vm(VmIter()->K());
forAllConstIter(phaseInterface, interface, iter)
{
const phaseModel& phase = iter();
const phaseModel& otherPhase = iter.otherPhase();
const label i = movingPhases[phase.index()];
if (i != -1)
{
const volScalarField VmPhase
(
(
otherPhase.alpha()
/max(otherPhase.alpha(), otherPhase.residualAlpha())
)*Vm
);
{
const volScalarField AVm(VmPhase*ADUDts[i]);
invADVs[i][i] += AVm;
invADVfs[i][i] += fvc::interpolate(AVm);
addField
(
i,
IOobject::groupName("HVm", phase.name()),
VmPhase*HDUDts[i],
HVms
);
}
const label j = movingPhases[otherPhase.index()];
if (j != -1)
{
const volScalarField AVm(VmPhase*ADUDts[j]);
invADVs[i][j] -= AVm;
invADVfs[i][j] -= fvc::interpolate(AVm);
addField
(
i,
IOobject::groupName("HVm", phase.name()),
-VmPhase*HDUDts[j],
HVms
);
}
}
}
}
momentumTransferSystem::invADVs(invADVs);
momentumTransferSystem::invADVs(invADVfs);
}
Foam::PtrList>
Foam::momentumTransferSystem::invADVfs
(
const PtrList& Afs,
PtrList& HVmfs
) const
{
const label n = Afs.size();
PtrList> invADVfs(n);
forAll(invADVfs, i)
{
invADVfs.set(i, new PtrList(n));
invADVfs[i].set(i, Afs[i].clone());
}
labelList movingPhases(fluid_.phases().size(), -1);
forAll(fluid_.movingPhases(), movingPhasei)
{
movingPhases[fluid_.movingPhases()[movingPhasei].index()] =
movingPhasei;
}
forAllConstIter
(
dragModelTable,
dragModels_,
dragModelIter
)
{
const phaseInterface& interface = dragModelIter()->interface();
const surfaceScalarField Kdf(dragModelIter()->Kf());
forAllConstIter(phaseInterface, interface, iter)
{
const phaseModel& phase = iter();
const phaseModel& otherPhase = iter.otherPhase();
const label i = movingPhases[phase.index()];
if (i != -1)
{
const surfaceScalarField alphaf
(
fvc::interpolate(otherPhase)
);
const surfaceScalarField Kdfij
(
(alphaf/max(alphaf, otherPhase.residualAlpha()))*Kdf
);
invADVfs[i][i] += Kdfij;
const label j = movingPhases[otherPhase.index()];
if (j != -1)
{
invADVfs[i].set(j, -Kdfij);
}
}
}
}
for (label i=0; i AUgradUs(movingPhases.size());
PtrList HUgradUs(movingPhases.size());
forAllConstIter
(
virtualMassModelTable,
virtualMassModels_,
VmIter
)
{
const phaseInterface& interface = VmIter()->interface();
forAllConstIter(phaseInterface, interface, iter)
{
const phaseModel& phase = iter();
const label i = movingPhases[phase.index()];
if (i != -1 && !AUgradUs.set(i))
{
const fvVectorMatrix UgradU(phase.UgradU());
AUgradUs.set(i, UgradU.A());
HUgradUs.set(i, UgradU.H());
}
}
}
// Add the virtual mass contributions
forAllConstIter
(
virtualMassModelTable,
virtualMassModels_,
VmIter
)
{
const phaseInterface& interface = VmIter()->interface();
const volScalarField Vm(VmIter()->K());
forAllConstIter(phaseInterface, interface, iter)
{
const phaseModel& phase = iter();
const phaseModel& otherPhase = iter.otherPhase();
const label i = movingPhases[phase.index()];
if (i != -1)
{
const volScalarField VmPhase
(
(
otherPhase.alpha()
/max(otherPhase.alpha(), otherPhase.residualAlpha())
)*Vm
);
const surfaceScalarField VmPhasef(fvc::interpolate(VmPhase));
invADVfs[i][i] +=
byDt(VmPhasef) + fvc::interpolate(VmPhase*AUgradUs[i]);
addField
(
i,
IOobject::groupName("HVmf", phase.name()),
VmPhasef
*byDt
(
fvc::absolute
(
fluid_.MRF().absolute
(
phase.phi()().oldTime()
),
phase.U()
)
)
+ fvc::flux(VmPhase*HUgradUs[i]),
HVmfs
);
const label j = movingPhases[otherPhase.index()];
if (j != -1)
{
invADVfs[i][j] -=
byDt(VmPhasef) + fvc::interpolate(VmPhase*AUgradUs[j]);
addField
(
i,
IOobject::groupName("HVmf", phase.name()),
-VmPhasef
*byDt
(
fvc::absolute
(
fluid_.MRF().absolute
(
otherPhase.phi()().oldTime()
),
otherPhase.U()
)
)
- fvc::flux(VmPhase*HUgradUs[j]),
HVmfs
);
}
}
}
}
invADVs(invADVfs);
return invADVfs;
}
Foam::tmp
Foam::momentumTransferSystem::alphaDByAf
(
const PtrList& rAs
) const
{
tmp alphaDByAf;
// Add the phase pressure
forAll(fluid_.movingPhases(), movingPhasei)
{
const phaseModel& phase = fluid_.movingPhases()[movingPhasei];
addTmpField
(
alphaDByAf,
fvc::interpolate(max(phase.alpha(), scalar(0)))
*fvc::interpolate(rAs[phase.index()])
*phase.pPrimef()
);
}
// Add the turbulent dispersion
forAllConstIter
(
turbulentDispersionModelTable,
turbulentDispersionModels_,
turbulentDispersionModelIter
)
{
const phaseInterface& interface =
turbulentDispersionModelIter()->interface();
const surfaceScalarField alpha1f
(
fvc::interpolate(max(interface.phase1().alpha(), scalar(0)))
);
const surfaceScalarField alpha2f
(
fvc::interpolate(max(interface.phase2().alpha(), scalar(0)))
);
addTmpField
(
alphaDByAf,
alpha1f*alpha2f
/max(alpha1f + alpha2f, interface.phase1().residualAlpha())
*fvc::interpolate
(
max
(
rAs[interface.phase1().index()],
rAs[interface.phase2().index()]
)
*turbulentDispersionModelIter()->D()
)
);
}
return alphaDByAf;
}
Foam::PtrList
Foam::momentumTransferSystem::ddtCorrs() const
{
PtrList ddtCorrs(fluid_.phases().size());
// Add correction
forAll(fluid_.movingPhases(), movingPhasei)
{
const phaseModel& phase = fluid_.movingPhases()[movingPhasei];
addField
(
phase,
"ddtCorr",
fvc::ddtCorr
(
phase,
phase.rho(),
phase.U()(),
phase.phi()(),
phase.Uf()
),
ddtCorrs
);
}
const pimpleNoLoopControl& pimple = fluid_.pimple();
const Switch VmDdtCorr
(
pimple.dict().lookupOrDefault("VmDdtCorrection", false)
);
// Optionally ddd virtual mass correction
if (VmDdtCorr)
{
PtrList VmDdtCoeffs(fluid_.phases().size());
PtrList VmDdtCorrs(fluid_.phases().size());
forAll(fluid_.movingPhases(), movingPhasei)
{
const phaseModel& phase = fluid_.movingPhases()[movingPhasei];
const label phasei = phase.index();
VmDdtCorrs.set
(
phasei,
fvc::ddtCorr
(
phase.U()(),
phase.phi()(),
phase.Uf()
)
);
}
forAllConstIter
(
virtualMassModelTable,
virtualMassModels_,
VmIter
)
{
const phaseInterface& interface = VmIter()->interface();
const volScalarField Vm(VmIter()->K());
forAllConstIter(phaseInterface, interface, iter)
{
const phaseModel& phase = iter();
const label phasei = phase.index();
const phaseModel& otherPhase = iter.otherPhase();
const label otherPhasei = otherPhase.index();
const volScalarField VmPhase
(
(
otherPhase.alpha()
/max(otherPhase.alpha(), otherPhase.residualAlpha())
)*Vm
);
addField
(
phase,
"ddtCorr",
fvc::interpolate(VmPhase)
*(VmDdtCorrs[phasei] - VmDdtCorrs[otherPhasei]),
ddtCorrs
);
}
}
}
return ddtCorrs;
}
void Foam::momentumTransferSystem::dragCorrs
(
PtrList& dragCorrs,
PtrList& dragCorrfs
) const
{
labelList movingPhases(fluid_.phases().size(), -1);
forAll(fluid_.movingPhases(), movingPhasei)
{
movingPhases[fluid_.movingPhases()[movingPhasei].index()] =
movingPhasei;
}
PtrList Uphis(fluid_.movingPhases().size());
forAll(fluid_.movingPhases(), movingPhasei)
{
Uphis.set
(
movingPhasei,
fvc::reconstruct(fluid_.movingPhases()[movingPhasei].phi())
);
}
forAllConstIter(KdTable, Kds_, KdIter)
{
const volScalarField& K(*KdIter());
const phaseInterface interface(fluid_, KdIter.key());
forAllConstIter(phaseInterface, interface, iter)
{
const phaseModel& phase = iter();
const phaseModel& otherPhase = iter.otherPhase();
const label i = movingPhases[phase.index()];
const label j = movingPhases[otherPhase.index()];
if (i != -1)
{
const volScalarField K1
(
(
otherPhase.alpha()
/max(otherPhase.alpha(), otherPhase.residualAlpha())
)*K
);
addField
(
i,
IOobject::groupName("dragCorr", phase.name()),
K1*(j == -1 ? eval(-Uphis[i]) : eval(Uphis[j] - Uphis[i])),
dragCorrs
);
addField
(
i,
IOobject::groupName("dragCorrf", phase.name()),
fvc::interpolate(K1)
*(
j == -1
? eval(-phase.phi())
: eval(otherPhase.phi() - phase.phi())
),
dragCorrfs
);
}
}
}
}
bool Foam::momentumTransferSystem::read()
{
if (regIOobject::read())
{
Kds_.clear();
readModels();
return true;
}
else
{
return false;
}
}
// ************************************************************************* //