Skip to content

Commit 988a6f6

Browse files
committed
Rephrased comments in the code and added a reference to the README
1 parent 497052a commit 988a6f6

File tree

2 files changed

+37
-54
lines changed

2 files changed

+37
-54
lines changed

OFtutorial14_SIMPLE_algorithm/OFtutorial14.C

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,19 @@ Description
3636
Equations". it is one of the algorithms used in solving incompressible
3737
Navier-Stokes equations.
3838
39-
this tutorial requires the following prerequisite
40-
1) basic knowledge in computational fluid dynamics, specifically to
41-
incompressible flow solutions.
42-
2) basic knowledge in Finite Volume Methods in discretizing partial
43-
differential equations.
44-
3) it is HIGHLY RECOMMENDED to go through this video on youtube
45-
46-
https://www.youtube.com/watch?v=ahdW5TKacok
47-
48-
it explains about Matrix notations/operations and the same is
49-
used in this tutorial.
50-
5139
\*---------------------------------------------------------------------------*/
5240

5341
// including basic functions and objects needed for OpenFOAM to run
5442
#include "fvCFD.H"
5543

5644
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
5745

58-
// incompressible flows are governed by 4 PDEs, 3 momentum equations and 1
46+
// Incompressible flows are governed by 4 PDEs, 3 momentum equations and 1
5947
// continuity equation. The field variables involved in computation are also
6048
// 4, Ux,Uy,Uz and P. So we have 4 equations and 4 unknowns, but we dont have
6149
// an explicit equation for pressure P, hence the continuity equation is
62-
// modified to involve pressure and thus solved it as pressure correction
63-
// equation. the details of derivation and matrix notations are explained well
64-
// on the youtube video just shared above.
65-
66-
// main function declaration
50+
// modified to involve pressure and thus solved as a pressure correction
51+
// equation.
6752

6853
int main(int argc, char *argv[])
6954
{
@@ -72,7 +57,6 @@ int main(int argc, char *argv[])
7257
#include "createTime.H"
7358
#include "createMesh.H"
7459

75-
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
7660
// declaring, reading and defining field values
7761
// the details on how the fields are defined/read/created can be seen
7862
// on the "createFields.H" file in the same directory
@@ -98,87 +82,83 @@ int main(int argc, char *argv[])
9882
Info << tab << "index of cell containing reference pressure \"pRefCell\" : " << pRefCell << endl;
9983
Info << tab << "reference pressure value \"pRefValue\" : " << pRefValue << endl;
10084

101-
// begining loop
102-
// the start and end times are read from the controlDict file in the
85+
// Begin the outer loops.
86+
// The start and end iterations are read from the controlDict file in the
10387
// system directory. Since this is a steadyState solver, the timeStep
10488
// value are just used as iteration count, hence it is usually started on
105-
// a round number, it can be checked on the controlDict file of case directory
89+
// a round number.
10690
while (runTime.loop())
10791
{
10892

10993
Info << nl << "Iteration: " << runTime.timeName() << endl;
11094

111-
// defining momentum equation
112-
// the momentum equation is defined in the format as
95+
// Define the momentum equations as:
11396
// <convection term> - <diffusion term> == - <pressure gradient>
97+
// Body forces, turbulence and the unsteady term are neglected (low
98+
// Reynolds number assumption, steady-state solution).
11499
fvVectorMatrix UEqn
115100
(
116101
fvm::div(phi,U) - fvm::laplacian(nu,U) == -fvc::grad(p)
117102
);
118103

119-
// solving momentum equation
104+
// Solve momentum equation for the current values of pressure.
120105
UEqn.solve();
121106

122-
// as can be seen from the youtube video, the matrix form of momentum
123-
// equation is M*U = Nab(P). And it is writen in the form of
124-
// A*U - H = Nab(P) for ease of inversion. Please see the video for
125-
// clear understanding. Those A and H matrices are received as field
126-
// values as shown below. Nab - stands for nabla operator
107+
// The matrix form of momentum equation is M*U = Nab(P). And it is writen
108+
// in the form of A*U - H = Nab(P) for ease of inversion. Those A and H
109+
// matrices are received as field values as shown below. Nab stands for
110+
// the nabla operator.
127111

128-
// getting A and H matrices as field values
112+
// Getting A and H matrices as fields.
129113
volScalarField A = UEqn.A();
130114
volVectorField H = UEqn.H();
131115

132-
// computing inverse of A matrix for ease of calculation; it is easy
133-
// as the A is a diagonal matrix.
116+
// Computing inverse of A matrix for ease of calculation; it is easy
117+
// as A is a diagonal matrix.
134118
volScalarField A_inv = 1.0/A;
135-
// and interpolating it to surface field. this is done for the way
136-
// the laplacian operator works on OpenFOAM.
119+
// Interpolating it onto grid faces. This is done becayuse of how
120+
// the laplacian operator works in OpenFOAM.
137121
surfaceScalarField A_inv_flux = fvc::interpolate(A_inv);
138-
// and computing HbyA field = H/A for ease of calculation
122+
// Computing HbyA field = H/A for ease of calculation
139123
volVectorField HbyA = A_inv * H;
140124

141-
// framing pressure correction equation
142-
// this equation can be seen on the reference youtube video as
125+
// Forming the pressure correction equation:
143126
// Nab(A^-1 Nab(p)) = Nab.(A^-1 * H)
144-
// the LHS can be defined using laplacian operator in OpenFOAM as below
127+
// The LHS can be defined using the laplacian operator in OpenFOAM as:
145128
fvScalarMatrix pEqn
146129
(
147130
fvm::laplacian(A_inv_flux, p) == fvc::div(HbyA)
148131
);
149132

150-
// setting reference pressure for equation
151-
pEqn.setReference(pRefCell,pRefValue);
133+
// Setting reference pressure for the equation.
134+
pEqn.setReference(pRefCell, pRefValue);
152135

153-
// solving pressure equation
136+
// Solving the pressure correction equation.
154137
pEqn.solve();
155138

156-
// under-relaxing pressure equation
157-
// two methods of relaxation was shown in the video, in that, the 2nd
158-
// one is implemented in here as to make things look simple
159-
p = alpha*p + (1 - alpha)*p_old;
139+
// Under-relaxing the pressure equation using explicit relaxation:
140+
p = alpha*p + (1.0 - alpha)*p_old;
160141

161-
// updating velocity field with newly computed pressure field
142+
// Updating the velocity field with newly computed pressure field.
162143
U = A_inv * H - A_inv * fvc::grad(p);
163-
// updating flux field with newly updated velocity field
144+
// Updating the flux field with newly updated velocity field.
164145
phi = fvc::interpolate(U) & mesh.Sf();
165146

166-
// updating boundary conditions for both p and U fields
147+
// Updating boundary conditions for both p and U fields.
167148
U.correctBoundaryConditions();
168149
p.correctBoundaryConditions();
169150

170-
// updating old_pressure field with new values
151+
// Updating old_pressure field with new values
171152
p_old = p;
172153

173-
// writing computed fields at the intervals insisted by controlDict
154+
// Writing computed fields at the intervals insisted by controlDict.
174155
runTime.write();
175156

176157
}
177158

178159
// printing execution time information at the end of simulation
179160
Info<< nl;
180161
Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << endl;
181-
182162
Info<< "End\n" << endl;
183163

184164
return 0;

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,17 @@ It is worth noting that the code is intended to show only how the equations are
280280
Hence, the optimization and convergence check conditions are omitted to make the
281281
code simpler to understand.
282282

283-
The test case used solves a 2D channel flow.
283+
The test case used solves a 2D channel flow. You can visualise the results
284+
using the existing Paraview state file by running: ```paraview --state=viewData.pvsm```.
284285

285286
The following are prerequisites that are required for understanding this
286287
tutorial:
287-
- CFD Online wiki entry:
288+
- CFD Online wiki entry (very brief and little detail, but succinct):
288289
https://www.cfd-online.com/Wiki/SIMPLE_algorithm
289290
- This Youtube video uses the same matrix notation as what is in the code:
290291
https://www.youtube.com/watch?v=ahdW5TKacok
292+
- A rather detailed yet concise notes:
293+
https://quickersim.com/tutorial/tutorial-2-numerics-simple-scheme
291294

292295
![Alt text](OFtutorial14_SIMPLE_algorithm/testCase/velocity_field.png?raw=true "Tutorial 14 - channel flow velocity distribution")
293296

0 commit comments

Comments
 (0)