CorrectPhi.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015-2017 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "CorrectPhi.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
31 #include "fvScalarMatrix.H"
32 #include "fvmDdt.H"
33 #include "fvmLaplacian.H"
34 #include "fvcDiv.H"
37 #include "adjustPhi.H"
38 #include "fvcMeshPhi.H"
39 #include "pimpleControl.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 template<class RAUfType, class DivUType>
45 (
48  const volScalarField& p,
49  const RAUfType& rAUf,
50  const DivUType& divU,
52 )
53 {
54  const fvMesh& mesh = U.mesh();
55  const Time& runTime = mesh.time();
56 
58 
59  // Initialize BCs list for pcorr to zero-gradient
61  (
62  p.boundaryField().size(),
63  zeroGradientFvPatchScalarField::typeName
64  );
65 
66  // Set BCs of pcorr to fixed-value for patches at which p is fixed
67  forAll(p.boundaryField(), patchi)
68  {
69  if (p.boundaryField()[patchi].fixesValue())
70  {
71  pcorrTypes[patchi] = fixedValueFvPatchScalarField::typeName;
72  }
73  }
74 
76  (
77  IOobject
78  (
79  "pcorr",
80  runTime.timeName(),
81  mesh
82  ),
83  mesh,
84  dimensionedScalar(p.dimensions(), Zero),
86  );
87 
88  if (pcorr.needReference())
89  {
91  adjustPhi(phi, U, pcorr);
93  }
94 
95  mesh.setFluxRequired(pcorr.name());
96 
97  while (pimple.correctNonOrthogonal())
98  {
99  // Solve for pcorr such that the divergence of the corrected flux
100  // matches the divU provided (from previous iteration, time-step...)
101  fvScalarMatrix pcorrEqn
102  (
104  );
105 
106  pcorrEqn.setReference(0, 0);
107 
108  pcorrEqn.solve
109  (
110  mesh.solver(pcorr.select(pimple.finalNonOrthogonalIter()))
111  );
112 
113  if (pimple.finalNonOrthogonalIter())
114  {
115  phi -= pcorrEqn.flux();
116  }
117  }
118 }
119 
120 
121 template<class RAUfType, class DivRhoUType>
122 void Foam::CorrectPhi
123 (
124  volVectorField& U,
126  const volScalarField& p,
127  const volScalarField& rho,
128  const volScalarField& psi,
129  const RAUfType& rAUf,
130  const DivRhoUType& divRhoU,
132 )
133 {
134  const fvMesh& mesh = U.mesh();
135  const Time& runTime = mesh.time();
136 
137  correctUphiBCs(rho, U, phi);
138 
139  // Initialize BCs list for pcorr to zero-gradient
141  (
142  p.boundaryField().size(),
143  zeroGradientFvPatchScalarField::typeName
144  );
145 
146  // Set BCs of pcorr to fixed-value for patches at which p is fixed
147  forAll(p.boundaryField(), patchi)
148  {
149  if (p.boundaryField()[patchi].fixesValue())
150  {
151  pcorrTypes[patchi] = fixedValueFvPatchScalarField::typeName;
152  }
153  }
154 
156  (
157  IOobject
158  (
159  "pcorr",
160  runTime.timeName(),
161  mesh
162  ),
163  mesh,
164  dimensionedScalar(p.dimensions(), Zero),
165  pcorrTypes
166  );
167 
168  mesh.setFluxRequired(pcorr.name());
169 
170  while (pimple.correctNonOrthogonal())
171  {
172  // Solve for pcorr such that the divergence of the corrected flux
173  // matches the divRhoU provided (from previous iteration, time-step...)
174  fvScalarMatrix pcorrEqn
175  (
176  fvm::ddt(psi, pcorr)
177  + fvc::div(phi)
179  ==
180  divRhoU
181  );
182 
183  pcorrEqn.solve
184  (
185  mesh.solver(pcorr.select(pimple.finalNonOrthogonalIter()))
186  );
187 
188  if (pimple.finalNonOrthogonalIter())
189  {
190  phi += pcorrEqn.flux();
191  }
192  }
193 }
194 
195 
196 // ************************************************************************* //
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::pimpleControl
PIMPLE control class to supply convergence information/checks for the PIMPLE loop.
Definition: pimpleControl.H:55
Foam::adjustPhi
bool adjustPhi(surfaceScalarField &phi, const volVectorField &U, volScalarField &p)
Adjust the balance of fluxes to obey continuity.
Definition: adjustPhi.C:37
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
fvcMeshPhi.H
Calculate the mesh motion flux and convert fluxes from absolute to relative and back.
fvcDiv.H
Calculate the divergence of the given field.
surfaceFields.H
Foam::surfaceFields.
Foam::fvMatrix::setReference
void setReference(const label celli, const Type &value, const bool forceReference=false)
Set reference level for solution.
Definition: fvMatrix.C:1092
Foam::fac::div
tmp< GeometricField< Type, faPatchField, areaMesh > > div(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facDiv.C:50
rho
rho
Definition: readInitialConditions.H:88
adjustPhi.H
For cases which do no have a pressure boundary adjust the balance of fluxes to obey continuity....
pcorr
volScalarField pcorr(IOobject("pcorr", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE), mesh, dimensionedScalar(p.dimensions(), Zero), pcorrTypes)
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
pimpleControl.H
Foam::fvc::makeRelative
void makeRelative(surfaceScalarField &phi, const volVectorField &U)
Make the given flux relative.
Definition: fvcMeshPhi.C:77
pimple
pimpleControl & pimple
Definition: setRegionFluidFields.H:56
fvmLaplacian.H
Calculate the matrix for the laplacian of the field.
pcorrTypes
wordList pcorrTypes(p.boundaryField().size(), zeroGradientFvPatchScalarField::typeName)
correctUphiBCs
correctUphiBCs(U, phi)
divU
zeroField divU
Definition: alphaSuSp.H:3
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
fvScalarMatrix.H
A scalar instance of fvMatrix.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
U
U
Definition: pEqn.H:72
Foam::List< word >
Foam::CorrectPhi
void CorrectPhi(volVectorField &U, surfaceScalarField &phi, const volScalarField &p, const RAUfType &rAUf, const DivUType &divU, pimpleControl &pimple)
Definition: CorrectPhi.C:45
Foam::fac::ddt
tmp< GeometricField< Type, faPatchField, areaMesh > > ddt(const dimensioned< Type > dt, const faMesh &mesh)
Definition: facDdt.C:47
fixedValueFvPatchFields.H
CorrectPhi.H
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::fvMatrix::solve
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
Definition: fvMatrixSolve.C:319
Foam::fac::laplacian
tmp< GeometricField< Type, faPatchField, areaMesh > > laplacian(const GeometricField< Type, faPatchField, areaMesh > &vf, const word &name)
Definition: facLaplacian.C:47
Foam::fvc::makeAbsolute
void makeAbsolute(surfaceScalarField &phi, const volVectorField &U)
Make the given flux absolute.
Definition: fvcMeshPhi.C:116
Foam::GeometricField< vector, fvPatchField, volMesh >
psi
const volScalarField & psi
Definition: createFieldRefs.H:1
zeroGradientFvPatchFields.H
Foam::fvMatrix::flux
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > flux() const
Return the face-flux field from the matrix.
Definition: fvMatrix.C:1534
fvmDdt.H
Calculate the matrix for the first temporal derivative.
rAUf
surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU))