DAFoam
v4.0.2
Discrete Adjoint with OpenFOAM
dafoam
src
adjoint
DASolver
DASimpleFoam
pEqnSimple.H
Go to the documentation of this file.
1
{
2
volScalarField
rAU
(1.0 /
UEqn
.A());
3
//***************** NOTE *******************
4
// constrainHbyA has been used since OpenFOAM-v1606; however, it may degrade the accuracy of derivatives
5
// because constraining variables will create discontinuity. Here we have a option to use the old
6
// implementation in OpenFOAM-3.0+ and before (no constraint for HbyA)
7
autoPtr<volVectorField>
HbyAPtr
=
nullptr
;
8
label
useConstrainHbyA
= daOptionPtr_->getOption<label>(
"useConstrainHbyA"
);
9
if
(
useConstrainHbyA
)
10
{
11
HbyAPtr
.reset(
new
volVectorField(constrainHbyA(
rAU
*
UEqn
.H(),
U
,
p
)));
12
}
13
else
14
{
15
HbyAPtr
.reset(
new
volVectorField(
"HbyA"
,
U
));
16
HbyAPtr
() =
rAU
*
UEqn
.H();
17
}
18
volVectorField&
HbyA
=
HbyAPtr
();
19
surfaceScalarField
phiHbyA
(
"phiHbyA"
, fvc::flux(
HbyA
));
20
21
MRF
.makeRelative(
phiHbyA
);
22
23
adjustPhi
(
phiHbyA
,
U
,
p
);
24
25
tmp<volScalarField>
rAtU
(
rAU
);
26
27
if
(
simple
.consistent())
28
{
29
rAtU
= 1.0 / (1.0 /
rAU
-
UEqn
.H1());
30
phiHbyA
+=
31
fvc::interpolate(
rAtU
() -
rAU
) * fvc::snGrad(
p
) *
mesh
.magSf();
32
HbyA
-= (
rAU
-
rAtU
()) * fvc::grad(
p
);
33
}
34
35
tUEqn
.clear();
36
37
// Update the pressure BCs to ensure flux consistency
38
constrainPressure
(
p
,
U
,
phiHbyA
,
rAtU
(),
MRF
);
39
40
// Non-orthogonal pressure corrector loop
41
while
(
simple
.correctNonOrthogonal())
42
{
43
fvScalarMatrix pEqn(
44
fvm::laplacian(
rAtU
(),
p
) == fvc::div(
phiHbyA
));
45
46
pEqn.setReference(
pRefCell
,
pRefValue
);
47
48
// get the solver performance info such as initial
49
// and final residuals
50
SolverPerformance<scalar> solverP = pEqn.solve();
51
52
DAUtility::primalResidualControl(solverP, printToScreen_,
"p"
, daGlobalVarPtr_->primalMaxRes);
53
54
if
(
simple
.finalNonOrthogonalIter())
55
{
56
phi
=
phiHbyA
- pEqn.flux();
57
}
58
}
59
60
if
(printToScreen_)
61
{
62
#include "
continuityErrsPython.H
"
63
}
64
65
// Explicitly relax pressure for momentum corrector
66
p
.relax();
67
68
// bound p
69
DAUtility::boundVar(
allOptions
,
p
, printToScreen_);
70
71
// Momentum corrector
72
U
=
HbyA
-
rAtU
() * fvc::grad(
p
);
73
// bound U
74
DAUtility::boundVar(
allOptions
,
U
, printToScreen_);
75
U
.correctBoundaryConditions();
76
fvOptions.correct(
U
);
77
}
useConstrainHbyA
label useConstrainHbyA
Definition:
pEqnSimple.H:8
pRefValue
scalar & pRefValue
Definition:
createRefsPimpleDyM.H:12
simple
simpleControl & simple
Definition:
createRefsRhoSimpleC.H:5
U
U
Definition:
pEqnSimple.H:72
UEqn
fvVectorMatrix & UEqn
Definition:
UEqnPimpleDyM.H:15
phiHbyA
surfaceScalarField phiHbyA("phiHbyA", fvc::flux(HbyA))
MRF
IOMRFZoneListDF & MRF
Definition:
createRefsRhoSimple.H:18
continuityErrsPython.H
pRefCell
label & pRefCell
Definition:
createRefsPimpleDyM.H:11
mesh
fvMesh & mesh
Definition:
createRefsHeatTransfer.H:4
p
volScalarField & p
Definition:
createRefsPimpleDyM.H:6
phi
surfaceScalarField & phi
Definition:
createRefsPimpleDyM.H:8
tUEqn
tmp< fvVectorMatrix > tUEqn(fvm::ddt(U)+fvm::div(phi, U)+turbulencePtr_->divDevReff(U) - fvSource)
HbyAPtr
autoPtr< volVectorField > HbyAPtr
Definition:
pEqnSimple.H:7
allOptions
const dictionary & allOptions
Definition:
createRefsPimpleDyM.H:14
adjustPhi
adjustPhi(phiHbyA, U, p)
constrainPressure
constrainPressure(p, U, phiHbyA, rAtU(), MRF)
HbyA
volVectorField & HbyA
Definition:
pEqnSimple.H:18
rAU
volScalarField rAU(1.0/UEqn.A())
rAtU
tmp< volScalarField > rAtU(rAU)
Generated by
1.8.17