CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   simpleFoam (https://www.cfd-online.com/Forums/openfoam-solving/204771-simplefoam.html)

badwalgurpreet July 31, 2018 17:02

simpleFoam
 
5 Attachment(s)
Hi Dear OpenFOAM Users,

I am trying to run steady state, incompressible and laminar flow through the circular pipe using OpenFOAM 5.0 version with “simpleFoam” solver. I made an axis-symmetric mesh using Pointwise Meshing tool. The domain is of size ( Length of the pipe=5.0 m and radius of the pipe = 0.1 m ). I gave 200 mesh points in the axial and 10 mesh points in the radial direction. I have calculated the first cell height near the wall = (Radius/38).

Input parameters: Velocity at the inlet = 1.0 m/s
Density = 1.0 kg/m^3
Dynamics Viscosity = 2.0*10^-3 kg/ms

Based on these parameters, calculated Reynolds Number = 100

I run this case for 1000 iterations and I would like to know your valuable suggestions on.....

(1): How to check whether my solution has converged or not? What parameters should I look at in the terminal?

(2): The solver stopped iterating when endTime value reaches to 1000. I want to learn how can I tell the simpleFoam solver that stop iterating when it satisfies the convergence criteria set in the “ fvSolution ” file?

(3): Why does the solver not stop iterating after reaching the Residual value equal to “ tolerance = 1e-06 ” set in the fvSolution file.

(4): What are the functions of the “ residualControl ” parameters defined in the fvSolution subdirectory “SIMPLE ”

residualControl
{
p 1e-2;
U 1e-3;
"(k|epsilon|omega|f|v2)" 1e-3;
}

I am attaching here some snapshots of simulation results.

I will be very thankful to you for your valuable suggestions on these very basic questions.

Robin.Kamenicky July 31, 2018 17:55

Hi Gurpreet,

Quote:

(1): How to check whether my solution has converged or not? What parameters should I look at in the terminal?
You can check the residuals, however also convergence of fields, pressure drop, velocity profile etc. It depends on each case.

Quote:

(2): The solver stopped iterating when endTime value reaches to 1000. I want to learn how can I tell the simpleFoam solver that stop iterating when it satisfies the convergence criteria set in the “ fvSolution ” file?
You can setup in controlDict endTime to high number and then in fvSolution setup residualControl values for your desired residual values. When initial residual of all fields will satisfy the values in residualControls your simulation stops.

Quote:

(3): Why does the solver not stop iterating after reaching the Residual value equal to “ tolerance = 1e-06 ” set in the fvSolution file.
You probably mean e.g. fvSolution.Solve.p In fact the solver stops iterate. When you have a look at the log file Time = 999 pressure solver does not perform any iteration since its initial residual is lower than 1e-6. If you would decrease the residual, it would perform some iterations.

Quote:

(4): What are the functions of the “ residualControl ” parameters defined in the fvSolution subdirectory “SIMPLE ”

residualControl
{
p 1e-2;
U 1e-3;
"(k|epsilon|omega|f|v2)" 1e-3;
}
Answered in the question 2.

Kind regards,
Robin

RobertHB August 1, 2018 03:16

Quote:

Originally Posted by badwalgurpreet (Post 701110)
(1): How to check whether my solution has converged or not? What parameters should I look at in the terminal?

I allways go by residual levels. You should aim for 1e-4 to 1e-6. The lower the more converged your solution will be. Your residuals look fine, exept for Uz (blue line) that one is higly unstable and does not converge. For a steady-state, laminar, pipe flow, this should not occur.

Quote:

Originally Posted by badwalgurpreet (Post 701110)
(2): The solver stopped iterating when endTime value reaches to 1000. I want to learn how can I tell the simpleFoam solver that stop iterating when it satisfies the convergence criteria set in the “ fvSolution ” file?

Whatever is reached first, final timestep or the residual level of _all_ parameters. If you want your solver to stop based on residual levels, just increase the endTime.

Quote:

Originally Posted by badwalgurpreet (Post 701110)
(3): Why does the solver not stop iterating after reaching the Residual value equal to “ tolerance = 1e-06 ” set in the fvSolution file.

The tolerance defines the "Final residual" per timestep. ...

Quote:

Originally Posted by badwalgurpreet (Post 701110)
(4): What are the functions of the “ residualControl ” parameters defined in the fvSolution subdirectory “SIMPLE ”

... whereas these parameters control the "Initial residual". This is your stop criterion if you so wish. Only if these settings are satisfied for all parameters the solution will stop based on residuals. In your case your simulation would stop if the residuals reached (p) 1e-2 (U) 1e-3, (rest) 1e-3. Dont consinder these converged. Aim, at least, for 1e-4.

Code:

residualControl
    {
        p              1e-2;
        U              1e-3;
        "(k|epsilon|omega|f|v2)" 1e-3;
    }


badwalgurpreet August 1, 2018 16:28

Quote:

Originally Posted by RobertHB (Post 701138)
I allways go by residual levels. You should aim for 1e-4 to 1e-6. The lower the more converged your solution will be. Your residuals look fine, exept for Uz (blue line) that one is higly unstable and does not converge. For a steady-state, laminar, pipe flow, this should not occur.


Whatever is reached first, final timestep or the residual level of _all_ parameters. If you want your solver to stop based on residual levels, just increase the endTime.


The tolerance defines the "Final residual" per timestep. ...


... whereas these parameters control the "Initial residual". This is your stop criterion if you so wish. Only if these settings are satisfied for all parameters the solution will stop based on residuals. In your case your simulation would stop if the residuals reached (p) 1e-2 (U) 1e-3, (rest) 1e-3. Dont consinder these converged. Aim, at least, for 1e-4.

Code:

residualControl
    {
        p              1e-2;
        U              1e-3;
        "(k|epsilon|omega|f|v2)" 1e-3;
    }


Hi Dear Robert,

Thanks a lot for your valuable comments on this topic. I still have a few doubts about this topic that I would like to ask...

(1): You explained in the question #1 that convergence can be checked by looking at the residual levels of each variable such as Pressure, Ux, Uy and Uz. The solver will stop iterating further when one of the condition is satisfied first like endTime set in a controlDict file or residualControl set in the fvSolution. The residualControl will set the initial residual for all the variables and is the stopping criteria for the solver. In my simulation, Ux, P, and Uy already satisfied the convergence criteria given by residualControl (p 1e-2 , U 1e-3), except Uz.

My question is as I am solving for a 2-dimensional problem in XY plane. Uz (blue line) that one is highly unstable and does not converge. Will it affect my solution as I am solving the 2d problem if Uz has not converged?

(2): As you explained in question # 3 that Tolerance defines the "Final residual" per timestep. I am unable to understand the difference between the Initial residual and the Final Residual.

Can you please explain the difference between Initial and Final Residual?

badwalgurpreet August 1, 2018 16:30

Quote:

Originally Posted by RobertHB (Post 701138)
I allways go by residual levels. You should aim for 1e-4 to 1e-6. The lower the more converged your solution will be. Your residuals look fine, exept for Uz (blue line) that one is higly unstable and does not converge. For a steady-state, laminar, pipe flow, this should not occur.


Whatever is reached first, final timestep or the residual level of _all_ parameters. If you want your solver to stop based on residual levels, just increase the endTime.


The tolerance defines the "Final residual" per timestep. ...


... whereas these parameters control the "Initial residual". This is your stop criterion if you so wish. Only if these settings are satisfied for all parameters the solution will stop based on residuals. In your case your simulation would stop if the residuals reached (p) 1e-2 (U) 1e-3, (rest) 1e-3. Dont consinder these converged. Aim, at least, for 1e-4.

Code:

residualControl
    {
        p              1e-2;
        U              1e-3;
        "(k|epsilon|omega|f|v2)" 1e-3;
    }


Hi Dear Robert,

Thanks a lot for your valuable comments on this topic. I still have a few doubts about this topic that I would like to ask...

(1): You explained in the question #1 that convergence can be checked by looking at the residual levels of each variable such as Pressure, Ux, Uy and Uz. The solver will stop iterating further when one of the condition is satisfied first like endTime set in a controlDict file or residualControl set in the fvSolution. The residualControl will set the initial residual for all the variables and is the stopping criteria for the solver. In my simulation, Ux, P, and Uy already satisfied the convergence criteria given by residualControl (p 1e-2 , U 1e-3), except Uz.

My question is as I am solving for a 2-dimensional problem in XY plane. Uz (blue line) that one is highly unstable and does not converge. Will it affect my solution as I am solving the 2d problem if Uz has not converged?

(2): As you explained in question # 3 that Tolerance defines the "Final residual" per timestep. I am unable to understand the difference between the Initial residual and the Final Residual.

Can you please explain the difference between Initial and Final Residual? As you told me that Initial residual will set the criteria for stopping the iterating process.

badwalgurpreet August 1, 2018 16:54

Quote:

Originally Posted by Robin.Kamenicky (Post 701113)
Hi Gurpreet,


You can check the residuals, however also convergence of fields, pressure drop, velocity profile etc. It depends on each case.


You can setup in controlDict endTime to high number and then in fvSolution setup residualControl values for your desired residual values. When initial residual of all fields will satisfy the values in residualControls your simulation stops.


You probably mean e.g. fvSolution.Solve.p In fact the solver stops iterate. When you have a look at the log file Time = 999 pressure solver does not perform any iteration since its initial residual is lower than 1e-6. If you would decrease the residual, it would perform some iterations.


Answered in the question 2.

Kind regards,
Robin

Hi Dear Robin,

Thanks a lot for your valuable comments on these basic questions. I still have a few doubts...


(1): You explained that when the initial residual of all fields will satisfy the values in residualControls your simulation stops. Do I always need to look at only the initial residual values of all the variables in the terminal to check convergence?

(2): It's not enough to check the convergence by looking at the initial residual. How should I proceed further to check the convergence of fields such as pressure drop, velocity profile etc? For this simulation, I plot the U_ magnitude vs radius of the pipe at different locations of the pipe. How can I know the convergence of field variables like Pressure drop, Velocity profile or shear stress?

(3): When initial residual of all fields will satisfy the values in residualControls(p 1e-3; U 1e-3) your simulation stops. But at Time =999 in the log file, the initial residuals of Ux and p are less than the defined initial residuals in the residualControl. Due to this reason, Ux and P are not iterating further. But when you look at the Uy initial residual at a terminal at Time =999, why is it iterating further though it already satisfied the initial residual stopping criteria (U 1e-3)?

Uz is still iterating as it's not satisfying the stop iterating criteria.

RobertHB August 2, 2018 02:57

Quote:

Originally Posted by badwalgurpreet (Post 701231)
(1): You explained in the question #1 that convergence can be checked by looking at the residual levels of each variable such as Pressure, Ux, Uy and Uz. [...]

Correct.

Quote:

My question is as I am solving for a 2-dimensional problem in XY plane. Uz (blue line) that one is highly unstable and does not converge. Will it affect my solution as I am solving the 2d problem if Uz has not converged?
I haven't done any 2D simulations myselft, so i cannot say for sure if this will affect your simulation. This may be normal behavious for a 2D simulation? :confused: Did you set the boundary conditions for your 2D-boundaries to empty in blockMeshDict?

Quote:

Can you please explain the difference between Initial and Final Residual? As you told me that Initial residual will set the criteria for stopping the iterating process.
I'll try by giving an example from a simulation of mine. Here is my fvSolution entry
Code:

solvers
{
    "(U|UFinal)"
    {
        tolerance      1e-8; //Final residual for the variable per interation (final res. = relTol*inti. res)
        [...]
    }
 }

SIMPLE
{
    residualControl    //Final residual for the solver to be considered converged.
    {
        p              1e-6;           
        U              1e-6;
    }
 }

The tolerance for U is set to 1e-8. It's the same for p. My convergence criterion for the residuals is 1e-6. Now let's take a look at my console output:

Code:

Starting time loop

Time = 1

smoothSolver:  Solving for Ux, Initial residual = 1, Final residual = 9.10208e-09, No Iterations 70
smoothSolver:  Solving for Uz, Initial residual = 1, Final residual = 8.67753e-09, No Iterations 64
Pressure gradient source: uncorrected Ubar = 0.000961546, pressure gradient = 9773.22
GAMG:  Solving for p, Initial residual = 1, Final residual = 9.45473e-09, No Iterations 37
time step continuity errors : sum local = 1.04551e-08, global = 5.57877e-17, cumulative = 5.57877e-17
Pressure gradient source: uncorrected Ubar = 0.862177, pressure gradient = 1348.27
ExecutionTime = 0.17 s  ClockTime = 1 s

Time = 2

smoothSolver:  Solving for Ux, Initial residual = 0.440793, Final residual = 9.80625e-09, No Iterations 83
smoothSolver:  Solving for Uz, Initial residual = 0.432395, Final residual = 8.15222e-09, No Iterations 71
Pressure gradient source: uncorrected Ubar = 2.2077, pressure gradient = -10467.9
GAMG:  Solving for p, Initial residual = 0.61368, Final residual = 6.8185e-09, No Iterations 37
time step continuity errors : sum local = 1.06108e-08, global = 8.51502e-18, cumulative = 6.43027e-17
Pressure gradient source: uncorrected Ubar = 1.13004, pressure gradient = 75.906
ExecutionTime = 0.2 s  ClockTime = 1 s

[...]

Time = 364

smoothSolver:  Solving for Ux, Initial residual = 1.00501e-08, Final residual = 6.31539e-09, No Iterations 1
smoothSolver:  Solving for Uz, Initial residual = 9.01276e-08, Final residual = 8.14041e-09, No Iterations 2
Pressure gradient source: uncorrected Ubar = 1, pressure gradient = 11.4978
GAMG:  Solving for p, Initial residual = 9.89647e-07, Final residual = 9.45194e-09, No Iterations 2
time step continuity errors : sum local = 4.58536e-09, global = -3.02712e-17, cumulative = -4.64292e-15
Pressure gradient source: uncorrected Ubar = 1, pressure gradient = 11.4978
ExecutionTime = 7.33 s  ClockTime = 8 s

SIMPLE solution converged in 364 iterations

The time loop starts. Neither the endTime, nor the residualControl 1e-6 criterion are reached. Per timeset the solver iterates until the final residual is smaller than the given tolerance setting. In my case Final res. < 1e-8. You can see that in each timestep this criterion is fulfilled, as the final residual is of order 1e-9.

The solver progresses with the next timestep:
For Time = 2 the initial residual is smaller than the one from the previous timestep but larger than my residual control setting. The solver iterates until the final residual becomes smaller than the tolerance level. Again 1e-9.
Fast foreward to my last timestep:
The Initial residual of all variables is smaller than my residualControl setting. The solver iterates one last time until the tolerance criterion is fulfilled, then terminates.


Quote:

(3): When initial residual of all fields will satisfy the values in residualControls(p 1e-3; U 1e-3) your simulation stops. But at Time =999 in the log file, the initial residuals of Ux and p are less than the defined initial residuals in the residualControl. Due to this reason, Ux and P are not iterating further. But when you look at the Uy initial residual at a terminal at Time =999, why is it iterating further though it already satisfied the initial residual stopping criteria (U 1e-3)?
Stopping the calculation only works when ALL variables reached the residualControl criterion. In any other case the solver iterates until the tolerance level is reached. At timestep 999 your solver iterates for Uy one time because the initial residual does not match the final residual. Thus telling simpleFoam: "Solve this variable".
In timestep 1000 your Initial Residual matches your tolerance level, so you don't solve for the variable any more.
Your simulation does not terminate due to the residualControl because your Uz does not match the residualControl value.

badwalgurpreet August 3, 2018 16:04

Quote:

Originally Posted by RobertHB (Post 701262)
Correct.

I haven't done any 2D simulations myselft, so i cannot say for sure if this will affect your simulation. This may be normal behavious for a 2D simulation? :confused: Did you set the boundary conditions for your 2D-boundaries to empty in blockMeshDict?

I'll try by giving an example from a simulation of mine. Here is my fvSolution entry
Code:

solvers
{
    "(U|UFinal)"
    {
        tolerance      1e-8; //Final residual for the variable per interation (final res. = relTol*inti. res)
        [...]
    }
 }

SIMPLE
{
    residualControl    //Final residual for the solver to be considered converged.
    {
        p              1e-6;           
        U              1e-6;
    }
 }

The tolerance for U is set to 1e-8. It's the same for p. My convergence criterion for the residuals is 1e-6. Now let's take a look at my console output:

Code:

Starting time loop

Time = 1

smoothSolver:  Solving for Ux, Initial residual = 1, Final residual = 9.10208e-09, No Iterations 70
smoothSolver:  Solving for Uz, Initial residual = 1, Final residual = 8.67753e-09, No Iterations 64
Pressure gradient source: uncorrected Ubar = 0.000961546, pressure gradient = 9773.22
GAMG:  Solving for p, Initial residual = 1, Final residual = 9.45473e-09, No Iterations 37
time step continuity errors : sum local = 1.04551e-08, global = 5.57877e-17, cumulative = 5.57877e-17
Pressure gradient source: uncorrected Ubar = 0.862177, pressure gradient = 1348.27
ExecutionTime = 0.17 s  ClockTime = 1 s

Time = 2

smoothSolver:  Solving for Ux, Initial residual = 0.440793, Final residual = 9.80625e-09, No Iterations 83
smoothSolver:  Solving for Uz, Initial residual = 0.432395, Final residual = 8.15222e-09, No Iterations 71
Pressure gradient source: uncorrected Ubar = 2.2077, pressure gradient = -10467.9
GAMG:  Solving for p, Initial residual = 0.61368, Final residual = 6.8185e-09, No Iterations 37
time step continuity errors : sum local = 1.06108e-08, global = 8.51502e-18, cumulative = 6.43027e-17
Pressure gradient source: uncorrected Ubar = 1.13004, pressure gradient = 75.906
ExecutionTime = 0.2 s  ClockTime = 1 s

[...]

Time = 364

smoothSolver:  Solving for Ux, Initial residual = 1.00501e-08, Final residual = 6.31539e-09, No Iterations 1
smoothSolver:  Solving for Uz, Initial residual = 9.01276e-08, Final residual = 8.14041e-09, No Iterations 2
Pressure gradient source: uncorrected Ubar = 1, pressure gradient = 11.4978
GAMG:  Solving for p, Initial residual = 9.89647e-07, Final residual = 9.45194e-09, No Iterations 2
time step continuity errors : sum local = 4.58536e-09, global = -3.02712e-17, cumulative = -4.64292e-15
Pressure gradient source: uncorrected Ubar = 1, pressure gradient = 11.4978
ExecutionTime = 7.33 s  ClockTime = 8 s

SIMPLE solution converged in 364 iterations

The time loop starts. Neither the endTime, nor the residualControl 1e-6 criterion are reached. Per timeset the solver iterates until the final residual is smaller than the given tolerance setting. In my case Final res. < 1e-8. You can see that in each timestep this criterion is fulfilled, as the final residual is of order 1e-9.

The solver progresses with the next timestep:
For Time = 2 the initial residual is smaller than the one from the previous timestep but larger than my residual control setting. The solver iterates until the final residual becomes smaller than the tolerance level. Again 1e-9.
Fast foreward to my last timestep:
The Initial residual of all variables is smaller than my residualControl setting. The solver iterates one last time until the tolerance criterion is fulfilled, then terminates.


Stopping the calculation only works when ALL variables reached the residualControl criterion. In any other case the solver iterates until the tolerance level is reached. At timestep 999 your solver iterates for Uy one time because the initial residual does not match the final residual. Thus telling simpleFoam: "Solve this variable".
In timestep 1000 your Initial Residual matches your tolerance level, so you don't solve for the variable any more.
Your simulation does not terminate due to the residualControl because your Uz does not match the residualControl value.

Thanks a lot Dear Robert for your quick reply. Now your point made me clear this concept.

I am using "Wedge"boundary condition as its is a axis symmetric problem and made this mesh on Pointwise tool. But I do not know wjy Openfoam is solving for Uz component of velocity as I gave Wedge boundary condition in Z direction and solving in xy plane. Do you have any idea?

Robin.Kamenicky August 4, 2018 12:54

Hi Gurpreet,

I am very sorry for late answer. However, it seems that Robert has answered all your questions very well.

Quote:

It's not enough to check the convergence by looking at the initial residual. How should I proceed further to check the convergence of fields such as pressure drop, velocity profile etc? For this simulation, I plot the U_ magnitude vs radius of the pipe at different locations of the pipe. How can I know the convergence of field variables like Pressure drop, Velocity profile or shear stress?
To check residuals convergence is very often satisfactory and it gives you good information about what is happening. However, when you get to more complex flows, I would definitely recommend to check convergence also of some other values. The purpose of our flow simulations can vary a bit but we are all the time interested in the flow behaviuor and its consequences. So we do not run simulation for the purpose to know residuals of the simulation but to know other physical values. Although, it definitely worth it to always plot the residuals, watch them carefully and try to get them to converge!
Printing U_magnitude vs radius and hence velocity profile is great way to be ensured that simulation converges. We can consider a simulation to be converged when nothing changes with subsequent "time" steps. Thus, if the velocity profile at defined location does not changes.
You can check quite a bit of values in paraview, use 6.2 Post-processing command line interface (CLI) or possibly pyFoam (Although I do not have much experience with it so I am not sure).

Quote:

I am using "Wedge"boundary condition as its is a axis symmetric problem and made this mesh on Pointwise tool. But I do not know wjy Openfoam is solving for Uz component of velocity as I gave Wedge boundary condition in Z direction and solving in xy plane. Do you have any idea?
When empty BC is used, the computation is clear 2D, the BC should tell to the solver in which direction not to solve the governing equations (perpendicular to the flow plane). Therefore the solver does not print any residuals for that direction. You can have a quick look at /tutorials/incompressible/simpleFoam/pitzDaily.
When the wedge BC is used it still apparently solve the governing equations in the third directions. Despite that it is claimed to be BC for 2D cases. Also other assumptions than for empty BC are used as it is a bit described in OpenFOAM guide (anlge about 1°, geometry running along the centre line straddling one of the coordinate plates, one element thick). It is axi-symmetric BC, therefore geometry, boundary conditions as well as flow should be axi-symmetric. This leads to the conclusion that perpendicular flow to the 2D plane should be minor and not influence the main flow patterns. You can have a look at the U_z in paraview. I would expect it to be a few magnitudes lower than U_y and U_x. If you still feel hesitating about the role of the U_z then make sure that the U converged. So print a few velocity profiles and make yourself sure that those do not change (or the change is negligible) as the "time" goes.

I hope I answered rest of your questions, if something is not clear let me know.
Kind regards,
Robin


All times are GMT -4. The time now is 05:45.