CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFD-Wiki (https://www.cfd-online.com/Forums/cfd-wiki/)
-   -   Sample code for SIMPLE-algorithm and solving Lid-Driven Cavity flow test is uploaded (https://www.cfd-online.com/Forums/cfd-wiki/75702-sample-code-simple-algorithm-solving-lid-driven-cavity-flow-test-uploaded.html)

 Michail May 3, 2010 11:05

Sample code for SIMPLE-algorithm and solving Lid-Driven Cavity flow test is uploaded

Dear colleagues!

I uploaded sample code for SIMPLE-algorithm and solving lid-driven cavity flow test (Re=1000).

It has a lot of shortcomings, but I think that it will be useful for all newcomers. I intend to develop it further, but now it very slowly converges. All notes will be useful, and hope it can be discussed.

The code can be found here:

http://www.cfd-online.com/Wiki/Sampl...9_-_Fortran_90

It predecessor - the code for solving Smith-Hutton test can be found here:

http://www.cfd-online.com/Wiki/Appro...s_and_examples

http://www.cfd-online.com/Wiki/Sampl...t_-_Fortran_90

 Mijail May 18, 2010 12:05

Simple-Algorithm

HI, I started programming a SIMPLE-algorithm myself based on Malalaskera's book on a staggered grid for a 1-d constant density permanent flow. It's not working properly, velocities converge in 2 or 3 iterations but pressures don't, I think I have a problem with BC's treatment (constant known velocity on one side and constant known pressure on the other). Do you know any book that shows a clear example on boundary conditions treatment?, I mean, all books, from Patankar, Anderson, Versteg, etc talk about it, but no one has a clear example.
The code you wrote is on a colocated grid, do you think it has advantages over a staggered grid for the 1-d problem I'm trying to solve?

 Michail May 18, 2010 12:23

Hi! Look here, may be this will be useful http://www.cfd-online.com/Forums/mai...flow-pipe.html

 bikash89 June 14, 2010 13:38

SIMPLE Algortihm in Matlab

Hi all..I have been trying to code for viscous incompressible flows using SIMPLE algorithm in Matlab using a staggered grid approach. The code worked really well for Couette flow. However for lid driven cavity, it is not showing required results. I have tried using different Reynolds number like 10, 100, 1000. Initially the code seems as if it will give the required result, however after a few iterations, oscillations begin and the solution fails. Is there any stability criteria for this flow problem? The time step I had used was 0.001 secs. Any kind of help in this regards will be highly appreciated. Thanks a lot.

 hamza dg October 12, 2018 08:14

hi,
1- in boundary conditions, the velocity in the wall is Up or Uface?
2- or we need to define the boundary conditions for both velocities? and how?

 Michail October 12, 2018 16:52

Hi Hamza

We specify both velocity components on the wall u and v (0,0 for solid walls, 1,0 for moving wall)

Just fixed them (they are not corrected during solution).

U_face calculated inside program. check the code,it's quite simple.

 hamza dg December 27, 2018 12:28

Hi, thank you Michail for your answers they are very useful, i realized the code for Newtonian and Non-Newtionian fluids.
Now i am trayin the viscoelastic case, but i have a problem of numerical stability when increasing WE (WE is a parameter in the equations), i want to know if you have an idea about this.
you can find the problem and equations in the article "Finite volume simulation of viscoelastic laminar flow in a lid-driven cavity" (Kerim Yapici, Bulent Karasozen, Yusuf Uludag) (2009)

 Michail December 28, 2018 20:30

hallo Hamza

I took a glance through the paper You referred.

First of all I would like to ask - how many equations do You solve?

If 3 You are wrong. There are 3 additional equations for stresses.

They are solving the same way as momentum equations.

so if You want to apply my code for this problem You should:

1) Add to solver 3 equations for stresses, likewise for scalar here

https://www.cfd-online.com/Wiki/Samp...t_-_Fortran_90

(the same scheme i used here for momentum equations U,V)

2) Modify source term in momentum equations
3) Modify boundary conditions (eq. 7 in that paper)

so there is some work here. But not too complicated :))

 hamza dg December 29, 2018 11:42

Hi michail,

yes i see, we have three unknowns added so automatically we need 3 others equations which are given in the constitutive equations.

i have applied all your remarks, and when i take WE=0 (newtonian case) the results are good, but for WE#0 here the convergence problem occurs, I think i need a special treatment of source term !!

 Michail December 29, 2018 15:09

Hallo

the source term in equations of motion (for U and V) summarized from pressure gradient and stresses.]

I guess, You should implement underrelaxation for stresses' equations:

(look in S. Patankar)

!---------------------------- under-relaxation ---------------------------------
Alfa = 0.8
Urf = 1. / Alfa

Ap(1:NXmaxC,1:NYmaxC,1) = Ap(1:NXmaxC,1:NYmaxC,1) * Urf
Sp(1:NXmaxC,1:NYmaxC,1) = Sp(1:NXmaxC,1:NYmaxC,1) + (1. - Alfa )* &
Ap(1:NXmaxC,1:NYmaxC,1)*F(1:NXmaxC,1:NYmaxC,1) ! / Alfa
Ap(1:NXmaxC,1:NYmaxC,2) = Ap(1:NXmaxC,1:NYmaxC,2) * Urf
Sp(1:NXmaxC,1:NYmaxC,2) = Sp(1:NXmaxC,1:NYmaxC,2) + (1. - Alfa )* &
Ap(1:NXmaxC,1:NYmaxC,2)*F(1:NXmaxC,1:NYmaxC,2) ! / Alfa
!---------------------------------------------------------------------------------

I would make relaxation koeffitient alfa=0.2..0.3 in stress equations.

and...

Check for bugs.
Check for bugs.

sleep a night and again: Check for bugs

Good luck!

 hamza dg December 30, 2018 14:20

Hi Michail, I hope you had a good day,

Yes i am used the underrelaxation for stresses equations.
and now i am trying again...

thank you for your encouragement :)

 Michail December 30, 2018 21:37

Okay, then let's take it more seriously:

1) First of all, check all math in Your code.
For this:
a) go through all possible references-issues - at least 20, better 30.
a0) the solution of the problem is already found, search it in publications
b) make yourself sure, that you have complete understanding of mathematical formulation
of governing equations and solution algorithm
c) check all signs and coefficients in your code, write out all math with pencil and paper, compare them.

a) make UDS scheme for momentum ans stresses equations
b) make the lowest possible underrelaxation coefficients - 0.5-0.7 for velocities, 0.1 for pressure.
c) search for suitable relaxation coefficients for stresses - vary them from 0.01 till 0.99
d) get convergence.

then you can go for improvement

 usman nazir January 29, 2019 01:14

Boundary Condition Treatment

Hello Mijail,
I am solving the lid driven cavity using SIMPLE algorithm in C++. I am facing same problem as yours, the treatment of boundary condition as no clear example is available in Patankar and Malalaskera's Book.