fvCorrectPhi: Wrapper for CorrectPhi to simplify solvers

This commit is contained in:
Henry Weller
2023-04-01 16:23:57 +01:00
parent de174c2b82
commit e66484a82d
22 changed files with 339 additions and 168 deletions

View File

@ -3,12 +3,12 @@ phic = mesh.Sf() & Ucf();
correctUphiBCs(Uc, phic, true);
CorrectPhi
fv::correctPhi
(
phic,
Uc,
p,
dimensionedScalar("rAUf", dimTime, 1),
autoPtr<volScalarField>(),
autoPtr<volScalarField>(),
pressureReference,
pimple

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -80,7 +80,7 @@ namespace Foam
#include "phaseIncompressibleMomentumTransportModel.H"
#include "pimpleControl.H"
#include "pressureReference.H"
#include "CorrectPhi.H"
#include "fvCorrectPhi.H"
#include "fvModels.H"
#include "fvConstraints.H"
#include "parcelClouds.H"

View File

@ -50,6 +50,28 @@ void Foam::solvers::VoFSolver::continuityErrors()
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::solvers::VoFSolver::setrAU(const fvVectorMatrix& UEqn)
{
if (rAU.valid())
{
rAU() = 1.0/UEqn.A();
}
else
{
rAU = (1.0/UEqn.A()).ptr();
}
}
void Foam::solvers::VoFSolver::clearrAU()
{
if (!(correctPhi || mesh.topoChanging()))
{
rAU.clear();
}
}
void Foam::solvers::VoFSolver::correctCoNum()
{
fluidSolver::correctCoNum(phi);

View File

@ -125,7 +125,9 @@ protected:
// Cached temporary fields
tmp<volScalarField> rAU;
//- Inverse momentum equation diagonal
// Used to correct phi following mesh changes
autoPtr<volScalarField> rAU;
//- Pointer to the surface momentum field
// used to recreate the flux after mesh-change
@ -157,6 +159,12 @@ protected:
// Protected Member Functions
//- Set or update the cached rAU
void setrAU(const fvVectorMatrix& UEqn);
//- Clear the cached rAU is no longer needed
void clearrAU();
//- Correct the cached Courant numbers
virtual void correctCoNum() = 0;

View File

@ -24,8 +24,9 @@ License
\*---------------------------------------------------------------------------*/
#include "VoFSolver.H"
#include "CorrectPhi.H"
#include "geometricZeroField.H"
#include "fvCorrectPhi.H"
#include "fvcMeshPhi.H"
#include "fvcDiv.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
@ -67,12 +68,12 @@ void Foam::solvers::VoFSolver::moveMesh()
if (incompressible())
{
CorrectPhi
fv::correctPhi
(
phi,
U,
p_rgh,
surfaceScalarField("rAUf", fvc::interpolate(rAU())),
rAU,
divU,
pressureReference(),
pimple
@ -80,12 +81,12 @@ void Foam::solvers::VoFSolver::moveMesh()
}
else
{
CorrectPhi
fv::correctPhi
(
phi,
p_rgh,
psiByRho(),
surfaceScalarField("rAUf", fvc::interpolate(rAU())),
rAU,
divU(),
pimple
);

View File

@ -44,15 +44,7 @@ void Foam::solvers::compressibleMultiphaseVoF::pressureCorrector()
volVectorField& U = U_;
fvVectorMatrix& UEqn = tUEqn.ref();
if (rAU.valid())
{
rAU.ref() = 1.0/UEqn.A();
}
else
{
rAU = 1.0/UEqn.A();
}
setrAU(UEqn);
const surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU()));
@ -173,6 +165,7 @@ void Foam::solvers::compressibleMultiphaseVoF::pressureCorrector()
K = 0.5*magSqr(U);
clearrAU();
tUEqn.clear();
}

View File

@ -49,15 +49,7 @@ void Foam::solvers::compressibleVoF::pressureCorrector()
const volScalarField& psi2 = mixture.thermo2().psi();
fvVectorMatrix& UEqn = tUEqn.ref();
if (rAU.valid())
{
rAU.ref() = 1.0/UEqn.A();
}
else
{
rAU = 1.0/UEqn.A();
}
setrAU(UEqn);
const surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU()));
@ -233,6 +225,7 @@ void Foam::solvers::compressibleVoF::pressureCorrector()
K = 0.5*magSqr(U);
clearrAU();
tUEqn.clear();
}

View File

@ -24,7 +24,8 @@ License
\*---------------------------------------------------------------------------*/
#include "incompressibleFluid.H"
#include "CorrectPhi.H"
#include "fvCorrectPhi.H"
#include "fvcMeshPhi.H"
#include "geometricZeroField.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
@ -48,12 +49,12 @@ void Foam::solvers::incompressibleFluid::moveMesh()
correctUphiBCs(U, phi, true);
CorrectPhi
fv::correctPhi
(
phi,
U,
p,
dimensionedScalar("rAUf", dimTime, 1),
autoPtr<volScalarField>(),
autoPtr<volScalarField>(),
pressureReference,
pimple

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "incompressibleMultiphaseVoF.H"
#include "CorrectPhi.H"
#include "fvCorrectPhi.H"
#include "geometricZeroField.H"
#include "addToRunTimeSelectionTable.H"
@ -123,32 +123,16 @@ Foam::solvers::incompressibleMultiphaseVoF::incompressibleMultiphaseVoF
{
correctUphiBCs(U_, phi, true);
if (correctPhi)
{
CorrectPhi
(
phi,
U,
p_rgh,
surfaceScalarField("rAUf", fvc::interpolate(rAU())),
autoPtr<volScalarField>(),
pressureReference(),
pimple
);
}
else
{
CorrectPhi
(
phi,
U,
p_rgh,
dimensionedScalar(dimTime/rho.dimensions(), 1),
autoPtr<volScalarField>(),
pressureReference(),
pimple
);
}
fv::correctPhi
(
phi,
U,
p_rgh,
rAU,
autoPtr<volScalarField>(),
pressureReference(),
pimple
);
}
}

View File

@ -43,17 +43,9 @@ void Foam::solvers::incompressibleMultiphaseVoF::pressureCorrector()
volVectorField& U = U_;
fvVectorMatrix& UEqn = tUEqn.ref();
setrAU(UEqn);
if (rAU.valid())
{
rAU.ref() = 1.0/UEqn.A();
}
else
{
rAU = 1.0/UEqn.A();
}
surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU()));
const surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU()));
while (pimple.correct())
{
@ -154,11 +146,7 @@ void Foam::solvers::incompressibleMultiphaseVoF::pressureCorrector()
}
}
if (!correctPhi)
{
rAU.clear();
}
clearrAU();
tUEqn.clear();
}

View File

@ -25,7 +25,7 @@ License
#include "incompressibleVoF.H"
#include "localEulerDdtScheme.H"
#include "CorrectPhi.H"
#include "fvCorrectPhi.H"
#include "geometricZeroField.H"
#include "addToRunTimeSelectionTable.H"
@ -108,32 +108,16 @@ Foam::solvers::incompressibleVoF::incompressibleVoF(fvMesh& mesh)
{
correctUphiBCs(U_, phi, true);
if (correctPhi)
{
CorrectPhi
(
phi,
U,
p_rgh,
surfaceScalarField("rAUf", fvc::interpolate(rAU())),
autoPtr<volScalarField>(),
pressureReference(),
pimple
);
}
else
{
CorrectPhi
(
phi,
U,
p_rgh,
dimensionedScalar(dimTime/rho.dimensions(), 1),
autoPtr<volScalarField>(),
pressureReference(),
pimple
);
}
fv::correctPhi
(
phi,
U,
p_rgh,
rAU,
autoPtr<volScalarField>(),
pressureReference(),
pimple
);
}
}

View File

@ -43,17 +43,9 @@ void Foam::solvers::incompressibleVoF::pressureCorrector()
volVectorField& U = U_;
fvVectorMatrix& UEqn = tUEqn.ref();
setrAU(UEqn);
if (rAU.valid())
{
rAU.ref() = 1.0/UEqn.A();
}
else
{
rAU = 1.0/UEqn.A();
}
surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU()));
const surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU()));
while (pimple.correct())
{
@ -154,11 +146,7 @@ void Foam::solvers::incompressibleVoF::pressureCorrector()
}
}
if (!correctPhi)
{
rAU.clear();
}
clearrAU();
tUEqn.clear();
}

View File

@ -24,7 +24,8 @@ License
\*---------------------------------------------------------------------------*/
#include "isothermalFluid.H"
#include "CorrectPhi.H"
#include "fvCorrectPhi.H"
#include "fvcMeshPhi.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
@ -57,12 +58,12 @@ void Foam::solvers::isothermalFluid::moveMesh()
correctUphiBCs(rho, U, phi, true);
CorrectPhi
fv::correctPhi
(
phi,
buoyancy.valid() ? p_rgh : p,
thermo.psi(),
dimensionedScalar("rAUf", dimTime, 1),
autoPtr<volScalarField>(),
divrhoU(),
pimple
);

View File

@ -31,7 +31,7 @@ License
#include "fvcDiv.H"
#include "fvcGrad.H"
#include "fvcSnGrad.H"
#include "CorrectPhi.H"
#include "fvCorrectPhi.H"
#include "fvcMeshPhi.H"
#include "correctContactAngle.H"
#include "dragModel.H"
@ -778,12 +778,12 @@ void Foam::phaseSystem::correctPhi
if (incompressible())
{
CorrectPhi
fv::correctPhi
(
phi_,
movingPhases()[0].U(),
p_rgh,
dimensionedScalar(dimTime/dimDensity, 1),
autoPtr<volScalarField>(),
divU,
pressureReference,
pimple
@ -809,12 +809,12 @@ void Foam::phaseSystem::correctPhi
psi += alpha*phase.thermo().psi()/phase.thermo().rho();
}
CorrectPhi
fv::correctPhi
(
phi_,
p_rgh,
psi,
dimensionedScalar(dimTime/dimDensity, 1),
autoPtr<volScalarField>(),
divU(),
pimple
);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -36,7 +36,7 @@ Description
#include "fvCFD.H"
#include "cavitatingTwoPhaseMixture.H"
#include "incompressibleMomentumTransportModels.H"
#include "CorrectPhi.H"
#include "fvCorrectPhi.H"
#include "pimpleControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -452,7 +452,8 @@ $(general)/findRefCell/findRefCell.C
$(general)/constrainHbyA/constrainHbyA.C
$(general)/adjustPhi/adjustPhi.C
$(general)/bound/bound.C
$(general)/CorrectPhi/correctUphiBCs.C
$(general)/correctPhi/fvCorrectPhi.C
$(general)/correctPhi/correctUphiBCs.C
$(general)/pressureReference/pressureReference.C
$(general)/levelSet/levelSet.C
$(general)/surfaceToVolVelocity/surfaceToVolVelocity.C

View File

@ -26,7 +26,6 @@ License
#include "CorrectPhi.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "fvScalarMatrix.H"
#include "fvmDdt.H"
#include "fvmLaplacian.H"
#include "fvcDiv.H"
@ -40,12 +39,12 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class RAUfType>
void Foam::CorrectPhi
void Foam::fv::CorrectPhi
(
surfaceScalarField& phi,
const volVectorField& U,
const volScalarField& p,
const RAUfType& rAUf,
const RAUfType& rAU,
const autoPtr<volScalarField>& divU,
const pressureReference& pressureReference,
nonOrthogonalSolutionControl& pcorrControl
@ -98,7 +97,7 @@ void Foam::CorrectPhi
// matches the divU provided (from previous iteration, time-step...)
fvScalarMatrix pcorrEqn
(
fvm::laplacian(rAUf, pcorr)
fvm::laplacian(rAU, pcorr)
==
(
divU.valid()
@ -120,12 +119,12 @@ void Foam::CorrectPhi
template<class RAUfType>
void Foam::CorrectPhi
void Foam::fv::CorrectPhi
(
surfaceScalarField& phi,
const volScalarField& p,
const volScalarField& psi,
const RAUfType& rAUf,
const RAUfType& rAU,
const volScalarField& divRhoU,
nonOrthogonalSolutionControl& pcorrControl
)
@ -172,7 +171,7 @@ void Foam::CorrectPhi
(
fvm::ddt(psi, pcorr)
+ fvc::div(phi)
- fvm::laplacian(rAUf, pcorr)
- fvm::laplacian(rAU, pcorr)
==
divRhoU
);

View File

@ -0,0 +1,91 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2015-2023 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 <http://www.gnu.org/licenses/>.
Function
Foam::fv::CorrectPhi
Description
Flux correction functions to ensure continuity.
Required during start-up, restart, mesh-motion etc. when non-conservative
fluxes may adversely affect the prediction-part of the solution algorithm
(the part before the first pressure solution which would ensure continuity).
This is particularly important for VoF and other multi-phase solver in
which non-conservative fluxes cause unboundedness of the phase-fraction.
SourceFiles
CorrectPhi.C
\*---------------------------------------------------------------------------*/
#ifndef CorrectPhi_H
#define CorrectPhi_H
#include "volFieldsFwd.H"
#include "surfaceFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class pressureReference;
class nonOrthogonalSolutionControl;
namespace fv
{
template<class RAUfType>
void CorrectPhi
(
surfaceScalarField& phi,
const volVectorField& U,
const volScalarField& p,
const RAUfType& rAU,
const autoPtr<volScalarField>& divU,
const pressureReference& pressureReference,
nonOrthogonalSolutionControl& pcorrControl
);
template<class RAUfType>
void CorrectPhi
(
surfaceScalarField& phi,
const volScalarField& p,
const volScalarField& psi,
const RAUfType& rAU,
const volScalarField& divRhoU,
nonOrthogonalSolutionControl& pcorrControl
);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "CorrectPhi.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2015-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,7 +23,9 @@ License
\*---------------------------------------------------------------------------*/
#include "CorrectPhi.H"
#include "fvCorrectPhi.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,118 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2023 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fvCorrectPhi.H"
#include "CorrectPhi.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::fv::correctPhi
(
surfaceScalarField& phi,
const volVectorField& U,
const volScalarField& p,
const autoPtr<volScalarField>& rAU,
const autoPtr<volScalarField>& divU,
const pressureReference& pressureReference,
nonOrthogonalSolutionControl& pcorrControl
)
{
if (rAU.valid())
{
CorrectPhi
(
phi,
U,
p,
rAU(),
divU,
pressureReference,
pcorrControl
);
}
else
{
CorrectPhi
(
phi,
U,
p,
dimensionedScalar
(
"rAU",
phi.dimensions()/p.dimensions()/dimLength,
1
),
divU,
pressureReference,
pcorrControl
);
}
}
void Foam::fv::correctPhi
(
surfaceScalarField& phi,
const volScalarField& p,
const volScalarField& psi,
const autoPtr<volScalarField>& rAU,
const volScalarField& divRhoU,
nonOrthogonalSolutionControl& pcorrControl
)
{
if (rAU.valid())
{
CorrectPhi
(
phi,
p,
psi,
rAU(),
divRhoU,
pcorrControl
);
}
else
{
CorrectPhi
(
phi,
p,
psi,
dimensionedScalar
(
"rAU",
phi.dimensions()/p.dimensions()/dimLength,
1
),
divRhoU,
pcorrControl
);
}
}
// ************************************************************************* //

View File

@ -21,8 +21,8 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::CorrectPhi
Function
Foam::fv::correctPhi
Description
Flux correction functions to ensure continuity.
@ -34,12 +34,13 @@ Description
which non-conservative fluxes cause unboundedness of the phase-fraction.
SourceFiles
CorrectPhi.C
fvCorrectPhi.C
correctUphiBCs.C
\*---------------------------------------------------------------------------*/
#ifndef CorrectPhi_H
#define CorrectPhi_H
#ifndef fvCorrectPhi_H
#define fvCorrectPhi_H
#include "volFieldsFwd.H"
#include "surfaceFieldsFwd.H"
@ -70,35 +71,31 @@ namespace Foam
const bool evaluateUBCs
);
template<class RAUfType>
void CorrectPhi
(
surfaceScalarField& phi,
const volVectorField& U,
const volScalarField& p,
const RAUfType& rAUf,
const autoPtr<volScalarField>& divU,
const pressureReference& pressureReference,
nonOrthogonalSolutionControl& pcorrControl
);
namespace fv
{
void correctPhi
(
surfaceScalarField& phi,
const volVectorField& U,
const volScalarField& p,
const autoPtr<volScalarField>& rAU,
const autoPtr<volScalarField>& divU,
const pressureReference& pressureReference,
nonOrthogonalSolutionControl& pcorrControl
);
template<class RAUfType>
void CorrectPhi
(
surfaceScalarField& phi,
const volScalarField& p,
const volScalarField& psi,
const RAUfType& rAUf,
const volScalarField& divRhoU,
nonOrthogonalSolutionControl& pcorrControl
);
void correctPhi
(
surfaceScalarField& phi,
const volScalarField& p,
const volScalarField& psi,
const autoPtr<volScalarField>& rAU,
const volScalarField& divRhoU,
nonOrthogonalSolutionControl& pcorrControl
);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "CorrectPhi.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -30,7 +30,7 @@ deltaT 0.001;
writeControl adjustableRunTime;
writeInterval 0.02;
writeInterval 0.1;
purgeWrite 0;