solvers: Provided public constant access to state fields

This commit is contained in:
Henry Weller
2023-04-08 16:05:39 +01:00
parent 59218933a3
commit fb052b9d79
23 changed files with 126 additions and 88 deletions

View File

@ -88,8 +88,8 @@ Foam::solvers::VoFSolver::VoFSolver
:
fluidSolver(mesh),
mixture_(mixturePtr),
mixture(mixture_()),
mixturePtr_(mixturePtr),
mixture_(mixturePtr_()),
divAlphaName("div(phi,alpha)"),
@ -106,7 +106,7 @@ Foam::solvers::VoFSolver::VoFSolver
mesh
),
phi
phi_
(
IOobject
(
@ -123,7 +123,7 @@ Foam::solvers::VoFSolver::VoFSolver
p_rgh(buoyancy.p_rgh),
rho(mixture.rho()),
rho(mixture_.rho()),
rhoPhi
(
@ -140,7 +140,9 @@ Foam::solvers::VoFSolver::VoFSolver
MRF(mesh),
U(U_)
mixture(mixture_),
U(U_),
phi(phi_)
{
mesh.schemes().setFluxRequired(p_rgh.name());

View File

@ -78,9 +78,9 @@ protected:
// Phase properties
//- The compressible two-phase mixture
autoPtr<VoFMixture> mixture_;
autoPtr<VoFMixture> mixturePtr_;
VoFMixture& mixture;
VoFMixture& mixture_;
//- Name of the alpha convection scheme
const word divAlphaName;
@ -95,7 +95,7 @@ protected:
volVectorField U_;
//- Volumetric flux field
surfaceScalarField phi;
surfaceScalarField phi_;
// Thermophysical properties
@ -201,13 +201,17 @@ protected:
public:
// Access to the physical state
// Public Data
//- Velocity field
//- Reference to the VoF mixture
const VoFMixture& mixture;
//- Reference to the velocity field
const volVectorField& U;
//- Reference to the mass-flux field
const surfaceScalarField& phi;
public:
//- Runtime type information
TypeName("VoFSolver");

View File

@ -62,15 +62,15 @@ void Foam::solvers::VoFSolver::moveMesh()
{
// Calculate absolute flux
// from the mapped surface velocity
phi = mesh.Sf() & Uf();
phi_ = mesh.Sf() & Uf();
correctUphiBCs(U_, phi, true);
correctUphiBCs(U_, phi_, true);
if (incompressible())
{
fv::correctPhi
(
phi,
phi_,
U,
p_rgh,
rAU,
@ -83,7 +83,7 @@ void Foam::solvers::VoFSolver::moveMesh()
{
fv::correctPhi
(
phi,
phi_,
p_rgh,
psiByRho(),
rAU,
@ -93,7 +93,7 @@ void Foam::solvers::VoFSolver::moveMesh()
}
// Make the fluxes relative to the mesh motion
fvc::makeRelative(phi, U);
fvc::makeRelative(phi_, U);
}
meshCourantNo();

View File

@ -42,6 +42,7 @@ License
void Foam::solvers::compressibleMultiphaseVoF::pressureCorrector()
{
volVectorField& U = U_;
surfaceScalarField& phi(phi_);
fvVectorMatrix& UEqn = tUEqn.ref();
setrAU(UEqn);

View File

@ -41,6 +41,7 @@ License
void Foam::solvers::compressibleVoF::pressureCorrector()
{
volVectorField& U = U_;
surfaceScalarField& phi(phi_);
const volScalarField& rho1 = mixture.rho1();
const volScalarField& rho2 = mixture.rho2();

View File

@ -121,11 +121,11 @@ Foam::solvers::incompressibleMultiphaseVoF::incompressibleMultiphaseVoF
if (!runTime.restart() || !divergent())
{
correctUphiBCs(U_, phi, true);
correctUphiBCs(U_, phi_, true);
fv::correctPhi
(
phi,
phi_,
U,
p_rgh,
rAU,

View File

@ -41,6 +41,7 @@ License
void Foam::solvers::incompressibleMultiphaseVoF::pressureCorrector()
{
volVectorField& U = U_;
surfaceScalarField& phi(phi_);
fvVectorMatrix& UEqn = tUEqn.ref();
setrAU(UEqn);

View File

@ -106,11 +106,11 @@ Foam::solvers::incompressibleVoF::incompressibleVoF(fvMesh& mesh)
if (!runTime.restart() || !divergent())
{
correctUphiBCs(U_, phi, true);
correctUphiBCs(U_, phi_, true);
fv::correctPhi
(
phi,
phi_,
U,
p_rgh,
rAU,

View File

@ -41,6 +41,7 @@ License
void Foam::solvers::incompressibleVoF::pressureCorrector()
{
volVectorField& U = U_;
surfaceScalarField& phi(phi_);
fvVectorMatrix& UEqn = tUEqn.ref();
setrAU(UEqn);

View File

@ -43,6 +43,8 @@ License
void Foam::solvers::multiphaseEuler::cellPressureCorrector()
{
volScalarField& p(p_);
// Face volume fractions
PtrList<surfaceScalarField> alphafs(phases.size());
forAll(phases, phasei)
@ -132,7 +134,7 @@ void Foam::solvers::multiphaseEuler::cellPressureCorrector()
p_rgh = p - rho*buoyancy.gh;
// Correct fixed-flux BCs to be consistent with the velocity BCs
fluid.correctBoundaryFlux();
fluid_.correctBoundaryFlux();
// Combined buoyancy and force fluxes
PtrList<surfaceScalarField> phigFs(phases.size());
@ -334,13 +336,13 @@ void Foam::solvers::multiphaseEuler::cellPressureCorrector()
// Correct fluxes and velocities on last non-orthogonal iteration
if (pimple.finalNonOrthogonalIter())
{
phi = phiHbyA + pEqnIncomp.flux();
phi_ = phiHbyA + pEqnIncomp.flux();
surfaceScalarField mSfGradp("mSfGradp", pEqnIncomp.flux()/rAUf);
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
phaseModel& phase = fluid_.movingPhases()[movingPhasei];
phase.phiRef() =
phiHbyAs[phase.index()]
@ -359,7 +361,7 @@ void Foam::solvers::multiphaseEuler::cellPressureCorrector()
{
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
phaseModel& phase = fluid_.movingPhases()[movingPhasei];
const label phasei = phase.index();
phase.URef() =
@ -379,7 +381,7 @@ void Foam::solvers::multiphaseEuler::cellPressureCorrector()
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
phaseModel& phase = fluid_.movingPhases()[movingPhasei];
const label phasei = phase.index();
phase.URef() =
@ -395,7 +397,7 @@ void Foam::solvers::multiphaseEuler::cellPressureCorrector()
if (partialElimination)
{
fluid.partialElimination
fluid_.partialElimination
(
rAUs,
KdUs,
@ -408,7 +410,7 @@ void Foam::solvers::multiphaseEuler::cellPressureCorrector()
{
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
phaseModel& phase = fluid_.movingPhases()[movingPhasei];
MRF.makeRelative(phase.phiRef());
fvc::makeRelative(phase.phiRef(), phase.U());
@ -417,7 +419,7 @@ void Foam::solvers::multiphaseEuler::cellPressureCorrector()
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
phaseModel& phase = fluid_.movingPhases()[movingPhasei];
phase.URef().correctBoundaryConditions();
phase.correctUf();
@ -427,8 +429,8 @@ void Foam::solvers::multiphaseEuler::cellPressureCorrector()
}
// Update and limit the static pressure
p = p_rgh + rho*buoyancy.gh;
fvConstraints().constrain(p);
p_ = p_rgh + rho*buoyancy.gh;
fvConstraints().constrain(p_);
// Account for static pressure reference
if (p_rgh.needReference() && fluid.incompressible())
@ -448,7 +450,7 @@ void Foam::solvers::multiphaseEuler::cellPressureCorrector()
// Update densities from change in p_rgh
forAll(phases, phasei)
{
phaseModel& phase = phases[phasei];
phaseModel& phase = phases_[phasei];
phase.thermoRef().rho() += phase.thermo().psi()*(p_rgh - p_rgh_0);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,9 +42,9 @@ Foam::solvers::multiphaseEuler::compressibilityEqns
{
PtrList<fvScalarMatrix> pEqnComps(phases.size());
forAll(phases, phasei)
forAll(phases_, phasei)
{
phaseModel& phase = phases[phasei];
phaseModel& phase = phases_[phasei];
const volScalarField& alpha = phase;
volScalarField& rho = phase.thermoRef().rho();

View File

@ -43,12 +43,14 @@ License
void Foam::solvers::multiphaseEuler::facePressureCorrector()
{
volScalarField& p(p_);
// Face volume fractions
PtrList<surfaceScalarField> alphafs(phases.size());
PtrList<surfaceScalarField> alphaRho0fs(phases.size());
forAll(phases, phasei)
{
phaseModel& phase = phases[phasei];
const phaseModel& phase = phases[phasei];
const volScalarField& alpha = phase;
alphafs.set(phasei, fvc::interpolate(alpha).ptr());
@ -75,7 +77,7 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
const phaseModel& phase = fluid.movingPhases()[movingPhasei];
rAUfs.set
(
@ -99,7 +101,7 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
PtrList<surfaceScalarField> alpharAUfs(phases.size());
forAll(phases, phasei)
{
phaseModel& phase = phases[phasei];
const phaseModel& phase = phases[phasei];
alpharAUfs.set
(
phase.index(),
@ -126,7 +128,7 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
p_rgh = p - rho*buoyancy.gh;
// Correct fixed-flux BCs to be consistent with the velocity BCs
fluid.correctBoundaryFlux();
fluid_.correctBoundaryFlux();
// Combined buoyancy and force fluxes
PtrList<surfaceScalarField> phigFs(phases.size());
@ -139,7 +141,7 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
forAll(phases, phasei)
{
phaseModel& phase = phases[phasei];
const phaseModel& phase = phases[phasei];
phigFs.set
(
@ -166,7 +168,7 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
PtrList<surfaceScalarField> phiHbyAs(phases.size());
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
const phaseModel& phase = fluid.movingPhases()[movingPhasei];
phiHbyAs.set
(
@ -257,7 +259,7 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
forAll(phases, phasei)
{
phaseModel& phase = phases[phasei];
const phaseModel& phase = phases[phasei];
phib +=
alphafs[phasei].boundaryField()
*phase.phi()().boundaryField();
@ -312,13 +314,13 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
// Correct fluxes and velocities on last non-orthogonal iteration
if (pimple.finalNonOrthogonalIter())
{
phi = phiHbyA + pEqnIncomp.flux();
phi_ = phiHbyA + pEqnIncomp.flux();
surfaceScalarField mSfGradp("mSfGradp", pEqnIncomp.flux()/rAUf);
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
phaseModel& phase = fluid_.movingPhases()[movingPhasei];
phase.phiRef() =
phiHbyAs[phase.index()]
@ -330,13 +332,13 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
if (partialElimination)
{
fluid.partialEliminationf(rAUfs, alphafs, KdPhifs);
fluid_.partialEliminationf(rAUfs, alphafs, KdPhifs);
}
else
{
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
phaseModel& phase = fluid_.movingPhases()[movingPhasei];
MRF.makeRelative(phase.phiRef());
fvc::makeRelative(phase.phiRef(), phase.U());
@ -345,7 +347,7 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
forAll(fluid.movingPhases(), movingPhasei)
{
phaseModel& phase = fluid.movingPhases()[movingPhasei];
phaseModel& phase = fluid_.movingPhases()[movingPhasei];
phase.URef() = fvc::reconstruct
(
@ -381,7 +383,7 @@ void Foam::solvers::multiphaseEuler::facePressureCorrector()
// Update densities from change in p_rgh
forAll(phases, phasei)
{
phaseModel& phase = phases[phasei];
phaseModel& phase = phases_[phasei];
phase.thermoRef().rho() += phase.thermo().psi()*(p_rgh - p_rgh_0);
}

View File

@ -32,6 +32,8 @@ void Foam::solvers::multiphaseEuler::cellMomentumPredictor()
{
Info<< "Constructing momentum equations" << endl;
phaseSystem& fluid(fluid_);
autoPtr<phaseSystem::momentumTransferTable>
momentumTransferPtr(fluid.momentumTransfer());
@ -73,6 +75,8 @@ void Foam::solvers::multiphaseEuler::faceMomentumPredictor()
{
Info<< "Constructing face momentum equations" << endl;
phaseSystem& fluid(fluid_);
autoPtr<phaseSystem::momentumTransferTable>
momentumTransferPtr(fluid.momentumTransferf());

View File

@ -64,9 +64,9 @@ void Foam::solvers::multiphaseEuler::moveMesh()
if (correctPhi || mesh.topoChanged())
{
fluid.meshUpdate();
fluid_.meshUpdate();
fluid.correctPhi
fluid_.correctPhi
(
p_rgh,
divU,

View File

@ -156,27 +156,32 @@ Foam::solvers::multiphaseEuler::multiphaseEuler(fvMesh& mesh)
buoyancy(mesh),
fluidPtr(phaseSystem::New(mesh)),
fluidPtr_(phaseSystem::New(mesh)),
fluid(fluidPtr()),
fluid_(fluidPtr_()),
phases(fluid.phases()),
phases_(fluid_.phases()),
phi(fluid.phi()),
phi_(fluid_.phi()),
p(phases[0].thermoRef().p()),
p_(phases_[0].thermoRef().p()),
p_rgh(buoyancy.p_rgh),
pressureReference
(
p,
p_,
p_rgh,
pimple.dict(),
fluid.incompressible()
fluid_.incompressible()
),
MRF(fluid.MRF())
MRF(fluid_.MRF()),
fluid(fluid_),
phases(phases_),
p(p_),
phi(phi_)
{
// Read the controls
readControls();
@ -244,14 +249,14 @@ void Foam::solvers::multiphaseEuler::prePredictor()
if (pimple.thermophysics() || pimple.flow())
{
fluid.solve(rAUs, rAUfs);
fluid.correct();
fluid.correctContinuityError();
fluid_.solve(rAUs, rAUfs);
fluid_.correct();
fluid_.correctContinuityError();
}
if (pimple.flow() && pimple.predictTransport())
{
fluid.predictMomentumTransport();
fluid_.predictMomentumTransport();
}
}
@ -260,8 +265,8 @@ void Foam::solvers::multiphaseEuler::postCorrector()
{
if (pimple.flow() && pimple.correctTransport())
{
fluid.correctMomentumTransport();
fluid.correctThermophysicalTransport();
fluid_.correctMomentumTransport();
fluid_.correctThermophysicalTransport();
}
}

View File

@ -107,18 +107,18 @@ protected:
// Phase properties
autoPtr<phaseSystem> fluidPtr;
autoPtr<phaseSystem> fluidPtr_;
phaseSystem& fluid;
phaseSystem& fluid_;
phaseSystem::phaseModelList& phases;
phaseSystem::phaseModelList& phases_;
surfaceScalarField& phi;
surfaceScalarField& phi_;
// Thermophysical properties
volScalarField& p;
volScalarField& p_;
//- Reference to the buoyant pressure for buoyant cases
// otherwise to the pressure
@ -198,6 +198,21 @@ private:
public:
// Public Data
//- Reference to the multiphase fluid
const phaseSystem& fluid;
//- Reference to the phases
const phaseSystem::phaseModelList& phases;
//- Reference to the pressure field
const volScalarField& p;
//- Reference to the mass-flux field
const surfaceScalarField& phi;
//- Runtime type information
TypeName("multiphaseEuler");

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -40,7 +40,7 @@ void Foam::solvers::multiphaseEuler::pressureCorrector()
cellPressureCorrector();
}
fluid.correctKinematics();
fluid_.correctKinematics();
}
else
{
@ -49,9 +49,9 @@ void Foam::solvers::multiphaseEuler::pressureCorrector()
compressibilityEqns(fluid.dmdts(), fluid.d2mdtdps())
);
forAll(phases, phasei)
forAll(phases_, phasei)
{
phases[phasei].divU(-pEqnComps[phasei] & p_rgh);
phases_[phasei].divU(-pEqnComps[phasei] & p_rgh);
}
}
}

View File

@ -41,11 +41,11 @@ void Foam::solvers::multiphaseEuler::compositionPredictor()
phaseSystem::specieTransferTable&
specieTransfer(specieTransferPtr());
fluid.correctReactions();
fluid_.correctReactions();
forAll(fluid.multicomponentPhases(), multicomponentPhasei)
{
phaseModel& phase = fluid.multicomponentPhases()[multicomponentPhasei];
phaseModel& phase = fluid_.multicomponentPhases()[multicomponentPhasei];
UPtrList<volScalarField>& Y = phase.YActiveRef();
const volScalarField& alpha = phase;
@ -68,7 +68,7 @@ void Foam::solvers::multiphaseEuler::compositionPredictor()
}
}
fluid.correctSpecies();
fluid_.correctSpecies();
}
@ -81,7 +81,7 @@ void Foam::solvers::multiphaseEuler::energyPredictor()
forAll(fluid.anisothermalPhases(), anisothermalPhasei)
{
phaseModel& phase = fluid.anisothermalPhases()[anisothermalPhasei];
phaseModel& phase = fluid_.anisothermalPhases()[anisothermalPhasei];
const volScalarField& alpha = phase;
tmp<volScalarField> tRho = phase.rho();
@ -104,8 +104,8 @@ void Foam::solvers::multiphaseEuler::energyPredictor()
fvConstraints().constrain(phase.thermoRef().he());
}
fluid.correctThermo();
fluid.correctContinuityError();
fluid_.correctThermo();
fluid_.correctContinuityError();
}
@ -117,13 +117,13 @@ void Foam::solvers::multiphaseEuler::thermophysicalPredictor()
{
for (int Ecorr=0; Ecorr<nEnergyCorrectors; Ecorr++)
{
fluid.predictThermophysicalTransport();
fluid_.predictThermophysicalTransport();
compositionPredictor();
energyPredictor();
forAll(fluid.anisothermalPhases(), anisothermalPhasei)
{
phaseModel& phase =
const phaseModel& phase =
fluid.anisothermalPhases()[anisothermalPhasei];
Info<< phase.name() << " min/max T "

View File

@ -532,7 +532,7 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::KdVmfs() const
template<class BasePhaseSystem>
Foam::PtrList<Foam::surfaceScalarField>
Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::Fs()
Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::Fs() const
{
PtrList<surfaceScalarField> Fs(this->phaseModels_.size());
@ -659,7 +659,7 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::Fs()
template<class BasePhaseSystem>
Foam::PtrList<Foam::surfaceScalarField>
Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::Ffs()
Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::Ffs() const
{
PtrList<surfaceScalarField> Ffs(this->phaseModels_.size());

View File

@ -200,10 +200,10 @@ public:
// do not depend on phase mass/volume fluxes, and can therefore be
// evaluated outside the corrector loop. This includes things like
// lift, turbulent dispersion, and wall lubrication.
virtual PtrList<surfaceScalarField> Fs();
virtual PtrList<surfaceScalarField> Fs() const;
//- As Fs, but for the face-based algorithm
virtual PtrList<surfaceScalarField> Ffs();
virtual PtrList<surfaceScalarField> Ffs() const;
//- Return the explicit drag force fluxes for the cell-based algorithm.
// These depend on phase mass/volume fluxes, and must therefore be

View File

@ -526,10 +526,10 @@ public:
virtual PtrList<surfaceScalarField> KdVmfs() const = 0;
//- Return the force fluxes for the cell-based algorithm
virtual PtrList<surfaceScalarField> Fs() = 0;
virtual PtrList<surfaceScalarField> Fs() const = 0;
//- Return the force fluxes for the face-based algorithm
virtual PtrList<surfaceScalarField> Ffs() = 0;
virtual PtrList<surfaceScalarField> Ffs() const = 0;
//- Return the force fluxes for the cell-based algorithm
virtual PtrList<surfaceScalarField> KdPhis() const = 0;

View File

@ -83,7 +83,7 @@ Foam::solvers::multiphaseVoFSolver::multiphaseVoFSolver
:
VoFSolver(mesh, autoPtr<VoFMixture>(mixturePtr.ptr())),
mixture(refCast<multiphaseVoFMixture>(VoFSolver::mixture)),
mixture(refCast<multiphaseVoFMixture>(VoFSolver::mixture_)),
phases(mixture.phases())
{

View File

@ -85,7 +85,7 @@ Foam::solvers::twoPhaseVoFSolver::twoPhaseVoFSolver
:
VoFSolver(mesh, autoPtr<VoFMixture>(mixturePtr.ptr())),
mixture(refCast<twoPhaseVoFMixture>(VoFSolver::mixture)),
mixture(refCast<twoPhaseVoFMixture>(VoFSolver::mixture_)),
alpha1(mixture.alpha1()),
alpha2(mixture.alpha2()),