pressureCorrector.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "compressibleVoF.H"
27 #include "constrainHbyA.H"
28 #include "constrainPressure.H"
29 #include "adjustPhi.H"
30 #include "fvcMeshPhi.H"
31 #include "fvcFlux.H"
32 #include "fvcDdt.H"
33 #include "fvcSnGrad.H"
34 #include "fvcReconstruct.H"
35 #include "fvmDiv.H"
36 #include "fvmSup.H"
37 #include "fvmLaplacian.H"
38 
39 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
40 
42 {
43  volVectorField& U = U_;
45 
46  const volScalarField& rho1 = mixture.rho1();
47  const volScalarField& rho2 = mixture.rho2();
48 
49  const volScalarField& psi1 = mixture.thermo1().psi();
50  const volScalarField& psi2 = mixture.thermo2().psi();
51 
52  fvVectorMatrix& UEqn = tUEqn.ref();
53  setrAU(UEqn);
54 
55  const surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU()));
56 
57  const surfaceScalarField alphaPhi2("alphaPhi2", phi - alphaPhi1);
58 
59  while (pimple.correct())
60  {
63  (
64  "phiHbyA",
67  );
68 
70 
71  const surfaceScalarField phig
72  (
73  (
76  )*rAUf*mesh.magSf()
77  );
78 
79  phiHbyA += phig;
80 
81  // Update the pressure BCs to ensure flux consistency
83 
84  // Cache the phase change pressure source
85  fvScalarMatrix Sp_rgh
86  (
87  fvModels().source
88  (
90  (
91  "1",
92  mesh,
94  ),
95  p_rgh
96  )
97  );
98 
99  // Make the fluxes relative to the mesh motion
101 
102  tmp<fvScalarMatrix> p_rghEqnComp1;
103  tmp<fvScalarMatrix> p_rghEqnComp2;
104 
105  if (pimple.transonic())
106  {
107  const surfaceScalarField rho1f(fvc::interpolate(rho1));
108  const surfaceScalarField rho2f(fvc::interpolate(rho2));
109 
110  surfaceScalarField phid1("phid1", fvc::interpolate(psi1)*phi);
111  surfaceScalarField phid2("phid2", fvc::interpolate(psi2)*phi);
112 
113  p_rghEqnComp1 =
114  (
115  (fvc::ddt(alpha1, rho1) + fvc::div(alphaPhi1*rho1f))/rho1
117  + (alpha1/rho1)
118  *correction
119  (
120  psi1*fvm::ddt(p_rgh)
121  + fvm::div(phid1, p_rgh) - fvm::Sp(fvc::div(phid1), p_rgh)
122  )
123  );
124 
125  p_rghEqnComp2 =
126  (
127  (fvc::ddt(alpha2, rho2) + fvc::div(alphaPhi2*rho2f))/rho2
128  - fvc::ddt(alpha2) - fvc::div(alphaPhi2)
129  + (alpha2/rho2)
130  *correction
131  (
132  psi2*fvm::ddt(p_rgh)
133  + fvm::div(phid2, p_rgh) - fvm::Sp(fvc::div(phid2), p_rgh)
134  )
135  );
136  }
137  else
138  {
139  const surfaceScalarField rho1f(fvc::interpolate(rho1));
140  const surfaceScalarField rho2f(fvc::interpolate(rho2));
141 
142  p_rghEqnComp1 =
143  (
144  (fvc::ddt(alpha1, rho1) + fvc::div(alphaPhi1*rho1f))/rho1
146  + (alpha1*psi1/rho1)*correction(fvm::ddt(p_rgh))
147  );
148 
149  p_rghEqnComp2 =
150  (
151  (fvc::ddt(alpha2, rho2) + fvc::div(alphaPhi2*rho2f))/rho2
152  - fvc::ddt(alpha2) - fvc::div(alphaPhi2)
153  + (alpha2*psi2/rho2)*correction(fvm::ddt(p_rgh))
154  );
155  }
156 
157  if (mesh.moving())
158  {
159  p_rghEqnComp1.ref() += fvc::div(mesh.phi())*alpha1;
160  p_rghEqnComp2.ref() += fvc::div(mesh.phi())*alpha2;
161  }
162 
163  p_rghEqnComp1.ref() *= pos(alpha1);
164  p_rghEqnComp2.ref() *= pos(alpha2);
165 
166  p_rghEqnComp1.ref() -=
167  (fvModels().source(alpha1, mixture_.thermo1().rho())&rho1)/rho1;
168  p_rghEqnComp2.ref() -=
169  (fvModels().source(alpha2, mixture_.thermo2().rho())&rho2)/rho2;
170 
171  if (pimple.transonic())
172  {
173  p_rghEqnComp1.ref().relax();
174  p_rghEqnComp2.ref().relax();
175  }
176 
177  // Cache p_rgh prior to solve for density update
178  const volScalarField p_rgh_0(p_rgh);
179 
180  while (pimple.correctNonOrthogonal())
181  {
182  fvScalarMatrix p_rghEqnIncomp
183  (
185  == Sp_rgh
186  );
187 
188  {
189  fvScalarMatrix p_rghEqn
190  (
191  p_rghEqnComp1() + p_rghEqnComp2() + p_rghEqnIncomp
192  );
193 
194  fvConstraints().constrain(p_rghEqn);
195 
196  p_rghEqn.solve();
197  }
198 
200  {
201  dgdt =
202  (
203  alpha1*(p_rghEqnComp2 & p_rgh)
204  - alpha2*(p_rghEqnComp1 & p_rgh)
205  );
206 
207  phi = phiHbyA + p_rghEqnIncomp.flux();
208 
209  p = p_rgh + rho*buoyancy.gh;
211  p_rgh = p - rho*buoyancy.gh;
213 
214  U = HbyA
215  + rAU()*fvc::reconstruct((phig + p_rghEqnIncomp.flux())/rAUf);
218  }
219  }
220 
221  // Update densities from change in p_rgh
222  mixture_.thermo1().correctRho(psi1*(p_rgh - p_rgh_0));
223  mixture_.thermo2().correctRho(psi2*(p_rgh - p_rgh_0));
224  mixture_.correct();
225 
226  // Correct p_rgh for consistency with p and the updated densities
227  p_rgh = p - rho*buoyancy.gh;
229  }
230 
231  // Correct Uf if the mesh is moving
233 
234  K = 0.5*magSqr(U);
235 
236  clearrAU();
237  tUEqn.clear();
238 }
239 
240 
241 // ************************************************************************* //
For cases which do no have a pressure boundary adjust the balance of fluxes to obey continuity....
Generic GeometricField class.
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Internal &, const PtrList< PatchField< Type >> &)
Return a temporary field constructed from name,.
void correctBoundaryConditions()
Correct boundary field.
void makeRelative(volVectorField &U) const
Make the given absolute velocity relative within the MRF region.
Definition: MRFZoneList.C:157
virtual void correct()
Update mixture properties.
const rhoThermo & thermo1() const
Return the thermo for phase 1.
const rhoThermo & thermo2() const
Return the thermo for phase 2.
bool transonic() const
Flag to indicate to solve using transonic algorithm.
bool constrain(fvMatrix< Type > &eqn) const
Apply constraints to an equation.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
SolverPerformance< Type > solve(const dictionary &)
Solve segregated or coupled returning the solution statistics.
Definition: fvMatrixSolve.C:58
tmp< SurfaceField< Type > > flux() const
Return the face-flux field from the matrix.
Definition: fvMatrix.C:963
const surfaceScalarField & phi() const
Return cell face motion fluxes.
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
bool finalNonOrthogonalIter() const
Flag to indicate the last non-orthogonal iteration.
bool correct()
Piso loop within outer loop.
bool correctNonOrthogonal()
Non-orthogonal corrector loop.
bool moving() const
Is mesh moving.
Definition: polyMesh.H:475
virtual void correctRho(const volScalarField &deltaRho)=0
Add the given density correction to the density field.
virtual tmp< volScalarField > rho() const =0
Density [kg/m^3].
Foam::fvModels & fvModels() const
Return the fvModels that are created on demand.
Definition: solver.C:85
pimpleNoLoopControl pimple
PIMPLE inner-loop controls.
Definition: solver.H:100
Foam::fvConstraints & fvConstraints() const
Return the fvConstraints that are created on demand.
Definition: solver.C:96
const fvMesh & mesh
Region mesh.
Definition: solver.H:94
volScalarField & p_rgh
Reference to the buoyant pressure for buoyant cases.
Definition: VoFSolver.H:107
const surfaceScalarField & phi
Reference to the mass-flux field.
Definition: VoFSolver.H:212
volVectorField U_
Velocity field.
Definition: VoFSolver.H:94
tmp< fvVectorMatrix > tUEqn
Cached momentum matrix.
Definition: VoFSolver.H:145
autoPtr< surfaceVectorField > Uf
Pointer to the surface momentum field.
Definition: VoFSolver.H:133
autoPtr< volScalarField > rAU
Inverse momentum equation diagonal.
Definition: VoFSolver.H:129
const volVectorField & U
Reference to the velocity field.
Definition: VoFSolver.H:209
void clearrAU()
Clear the cached rAU is no longer needed.
Definition: VoFSolver.C:66
IOMRFZoneList MRF
MRF zone list.
Definition: VoFSolver.H:122
surfaceScalarField phi_
Volumetric flux field.
Definition: VoFSolver.H:97
const volScalarField & rho
Reference to the mixture continuity density field.
Definition: VoFSolver.H:110
void setrAU(const fvVectorMatrix &UEqn)
Set or update the cached rAU.
Definition: VoFSolver.C:53
Buoyancy related data for the Foam::solvers::isothermalFluid solver module when solving buoyant cases...
Definition: buoyancy.H:70
volScalarField gh
(g & h) - ghRef
Definition: buoyancy.H:95
surfaceScalarField ghf
(g & hf) - ghRef
Definition: buoyancy.H:98
volScalarField & p
Reference to the mixture static pressure field.
volScalarField K
Kinetic energy field.
volScalarField::Internal dgdt
Compressibility source.
virtual void pressureCorrector()
Construct and solve the pressure equation in the PISO loop.
compressibleTwoPhaseVoFMixture & mixture_
The compressible two-phase mixture.
surfaceScalarField alphaPhi1
volScalarField & alpha1
Reference to the phase1-fraction.
volScalarField & alpha2
Reference to the phase2-fraction.
virtual tmp< surfaceScalarField > surfaceTensionForce() const
Return the interface surface tension force for the momentum equation.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
fvVectorMatrix & UEqn
Definition: UEqn.H:11
Calculate the first temporal derivative.
Calculate the face-flux of the given field.
Calculate the mesh motion flux and convert fluxes from absolute to relative and back.
Reconstruct volField from a face flux field.
Calculate the snGrad of the given volField.
Calculate the matrix for the divergence of the given field and flux.
Calculate the matrix for the laplacian of the field.
Calculate the matrix for implicit and explicit sources.
volVectorField & HbyA
Definition: pEqn.H:13
surfaceScalarField phiHbyA("phiHbyA", fvc::interpolate(rho) *fvc::flux(HbyA))
tmp< SurfaceField< typename innerProduct< vector, Type >::type > > flux(const VolField< Type > &vf)
Return the face-flux field obtained from the given volVectorField.
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
tmp< VolField< Type > > ddt(const dimensioned< Type > dt, const fvMesh &mesh)
Definition: fvcDdt.C:45
tmp< VolField< typename outerProduct< vector, Type >::type > > reconstruct(const SurfaceField< Type > &ssf)
void correctUf(autoPtr< surfaceVectorField > &Uf, const volVectorField &U, const surfaceScalarField &phi, const MRFType &MRF)
tmp< VolField< Type > > div(const SurfaceField< Type > &ssf)
Definition: fvcDiv.C:47
tmp< surfaceScalarField > absolute(const tmp< surfaceScalarField > &tphi, const volVectorField &U)
Return the given relative flux in absolute form.
Definition: fvcMeshPhi.C:202
void makeRelative(surfaceScalarField &phi, const volVectorField &U)
Make the given flux relative.
Definition: fvcMeshPhi.C:89
tmp< SurfaceField< Type > > snGrad(const VolField< Type > &vf, const word &name)
Definition: fvcSnGrad.C:45
tmp< SurfaceField< typename Foam::flux< Type >::type > > ddtCorr(const VolField< Type > &U, const SurfaceField< Type > &Uf)
Definition: fvcDdt.C:196
tmp< fvMatrix< Type > > laplacian(const VolField< Type > &vf, const word &name)
Definition: fvmLaplacian.C:47
tmp< fvMatrix< Type > > Sp(const volScalarField::Internal &, const VolField< Type > &)
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const VolField< Type > &vf, const word &name)
Definition: fvmDiv.C:48
tmp< fvMatrix< Type > > ddt(const VolField< Type > &vf)
Definition: fvmDdt.C:46
void constrainPressure(volScalarField &p, const RhoType &rho, const volVectorField &U, const surfaceScalarField &phiHbyA, const RAUType &rhorAU, const MRFType &MRF)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensionedScalar pos(const dimensionedScalar &ds)
const dimensionSet dimPressure
const dimensionSet dimless
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix.
tmp< volVectorField > constrainHbyA(const tmp< volVectorField > &tHbyA, const volVectorField &U, const volScalarField &p)
Definition: constrainHbyA.C:34
dimensioned< scalar > magSqr(const dimensioned< Type > &)