Thursday, April 17, 2014

CFD: Non-uniform grid mesh for 2D Rectangular - Fortran code


Result:

Here's part of the code I used to generate a non-uniform grid using fortran. To understand meaning of exp_x & exp_y powers, you need a piece of paper to sketch and calculate it by yourself.



exp_x=1.05 !x-axis expansion factor
exp_y=1.10 !y-axis expansion factor

a=0.
b=1.
c=0.
d=1.

!***********************************
! Constructing non-uniform grid !
!***********************************
! del_x & del_y : Uniform step size in X & Y direction
! eta_x & eta_y : First non-uniform step size in X & Y direction
! i_th step size is : eta_x*expansion_factor^step
del_x=(b-a)/n_x
del_y=(d-c)/n_y
eta_x=(b-a)*(1-exp_x)/(2*(1-exp_x**(n_x/2)))
eta_y=(d-c)*(1-exp_y)/(2*(1-exp_y**(n_y/2)))

PRINT *, "Uniform X-Step:", del_x
PRINT *, "Uniform Y-Step:", del_y
PRINT *, "First Non-uniform X-Step:", eta_x
PRINT *, "First Non-uniform Y-Step:", eta_y

x(1)=a
y(1)=c
! X_START to Middle_X
DO i=2,n_x/2+1
       x(i)=x(i-1)+eta_x*exp_x**(i-2)
END DO
! Middle_X to End
DO i=n_x/2+2,n_x+1
       x(i)=x(i-1)+eta_x*exp_x**(n_x+1-i)
END DO
! Y_START to Middle_Y
DO j=2,n_y/2+1
       y(j)=y(j-1)+eta_y*exp_y**(j-2)
END DO
! Middle_Y to Y_END
DO j=n_y/2+2,n_y+1
       y(j)=y(j-1)+eta_y*exp_y**(n_y+1-j)
END DO
!***********************************
! non-uniform grid done !
!***********************************
 

No comments:

Post a Comment