IMEXSfloW  1.0
templategithubproject
 All Classes Files Functions Variables Pages
geometry.f90
Go to the documentation of this file.
1 !*********************************************************************
3 !
6 !*********************************************************************
7 MODULE geometry
8 
9  USE parameters, ONLY : verbose_level
10 
11  IMPLICIT NONE
12 
14  REAL*8, ALLOCATABLE :: x_comp(:)
15 
17  REAL*8, ALLOCATABLE :: x_stag(:)
18 
20  REAL*8, ALLOCATABLE :: B_stag(:)
21 
23  REAL*8, ALLOCATABLE :: B_cent(:)
24 
26  REAL*8, ALLOCATABLE :: B_prime(:)
27 
28  REAL*8, ALLOCATABLE :: batimetry_profile(:,:)
29 
30  INTEGER :: n_batimetry_profile
31 
32  REAL*8 :: dx
33  REAL*8 :: x0
34  REAL*8 :: xN
35  INTEGER :: comp_cells
36  INTEGER :: comp_interfaces
37 
38 CONTAINS
39 
40  !*********************************************************************
42  !
45  !*********************************************************************
46 
47  SUBROUTINE init_grid
48 
49  USE parameters, ONLY: eps_sing, batimetry_function_flag
50 
51  IMPLICIT none
52 
53  INTEGER j !> loop counter
54 
55  comp_interfaces = comp_cells+1
56 
57  ALLOCATE( x_comp(comp_cells) )
58  ALLOCATE( x_stag(comp_interfaces) )
59 
60  ALLOCATE( b_cent(comp_cells) )
61  ALLOCATE( b_prime(comp_cells) )
62  ALLOCATE( b_stag(comp_interfaces) )
63 
64  dx = ( xn - x0 ) / comp_cells
65 
66  eps_sing = dx ** 4
67 
68  WRITE(*,*) 'eps_sing = ',eps_sing
69 
70  x_comp(1) = x0 + 0.5d0 * dx
71  x_stag(1) = x0
72 
73  ! rescaling in the case of batimetry defined in input file
74  IF(batimetry_function_flag.EQV..false.)THEN
75 
76  batimetry_profile(1,:) = x0 + ( xn - x0 ) * batimetry_profile(1,:)
77 
78  ENDIF
79 
80  ! definition of batimetry by input file
81  IF(batimetry_function_flag.EQV..false.)THEN
82 
83  b_stag(1) = batimetry_profile(2,1)
84 
85  DO j=1,comp_cells
86 
87  x_stag(j+1) = x_stag(j) + dx
88 
89  x_comp(j) = 0.5 * ( x_stag(j) + x_stag(j+1) )
90 
91  CALL interp_1d_scalar( batimetry_profile(1,:) , batimetry_profile(2,:) , &
92  x_stag(j+1) , b_stag(j+1) )
93 
94 
95  b_cent(j) = 0.5 * ( b_stag(j) + b_stag(j+1) )
96 
97  b_prime(j) = ( b_stag(j+1) - b_stag(j) ) / ( x_stag(j+1) - x_stag(j) )
98 
99  IF ( verbose_level .GE. 2 ) THEN
100 
101  WRITE(*,*) batimetry_profile(1,:)
102  WRITE(*,*) batimetry_profile(2,:)
103  WRITE(*,*) x_stag(j+1) , b_stag(j+1) ,x_comp(j) , b_cent(j) , b_prime(j)
104  READ(*,*)
105 
106  END IF
107 
108  END DO
109 
110  ! definition of batimetry by a function
111  ELSE
112 
113  b_stag(1) = batimetry_function(x_stag(1))
114 
115  DO j=1,comp_cells
116 
117  x_stag(j+1) = x_stag(j) + dx
118 
119  x_comp(j) = 0.5 * ( x_stag(j) + x_stag(j+1) )
120 
121  b_stag(j+1) = batimetry_function(x_stag(j+1))
122 
123  b_cent(j) = 0.5 * ( b_stag(j) + b_stag(j+1) )
124 
125  b_prime(j) = ( b_stag(j+1) - b_stag(j) ) / ( x_stag(j+1) - x_stag(j) )
126 
127  IF ( verbose_level .GE. 2 ) THEN
128 
129  WRITE(*,*) batimetry_profile(1,:)
130  WRITE(*,*) batimetry_profile(2,:)
131  WRITE(*,*) x_stag(j+1) , b_stag(j+1) ,x_comp(j) , b_cent(j) , b_prime(j)
132  READ(*,*)
133 
134  END IF
135 
136  END DO
137 
138  ENDIF
139 
140  END SUBROUTINE init_grid
141 
142 !---------------------------------------------------------------------------
144 !
152 !---------------------------------------------------------------------------
153 
154  SUBROUTINE interp_1d_scalar(x1, f1, x2, f2)
155  IMPLICIT NONE
156 
157  REAL*8, INTENT(IN), DIMENSION(:) :: x1, f1
158  REAL*8, INTENT(IN) :: x2
159  REAL*8, INTENT(OUT) :: f2
160  INTEGER :: n, n1x, t
161  REAL*8 :: grad , rel_pos
162 
163  n1x = SIZE(x1)
164 
165  !
166  ! ... locate the grid points near the topographic points
167  ! ... and interpolate linearly the profile
168  !
169  t = 1
170 
171  search:DO n = 1, n1x-1
172 
173  rel_pos = ( x2 - x1(n) ) / ( x1(n+1) - x1(n) )
174 
175  IF ( ( rel_pos .GE. 0.d0 ) .AND. ( rel_pos .LE. 1.d0 ) ) THEN
176 
177  grad = ( f1(n+1)-f1(n) ) / ( x1(n+1)-x1(n) )
178  f2 = f1(n) + ( x2-x1(n) ) * grad
179 
180  EXIT search
181 
182  ELSEIF ( rel_pos .LT. 0.d0 ) THEN
183 
184  f2 = f1(n)
185 
186  ELSE
187 
188  f2 = f1(n+1)
189 
190  END IF
191 
192  END DO search
193 
194  RETURN
195 
196  END SUBROUTINE interp_1d_scalar
197 
198 
199 !---------------------------------------------------------------------------
201 !
205 !---------------------------------------------------------------------------
206  REAL*8 FUNCTION batimetry_function(x)
207  IMPLICIT NONE
208 
209  REAL*8, INTENT(IN) :: x
210 
211  REAL*8, PARAMETER :: pig = 4.0*atan(1.0)
212  REAL*8, PARAMETER :: eps_dis = 10.0**(-8)
213 
214  ! example from Kurganov and Petrova 2007
215  IF(x.LT.0.0)THEN
216 
217  batimetry_function = 1.d0
218 
219  ELSEIF(x.GE.0.0.AND.x.LE.0.4)THEN
220 
221  batimetry_function = cos(pig*x)**2
222 
223  ELSEIF(x.GT.0.4.AND.x.LE.0.5)THEN
224 
225  batimetry_function = cos(pig*x)**2+0.25*(cos(10.0*pig*(x-0.5))+1)
226 
227  ELSEIF(x.GT.0.5.AND.x.LE.0.6)THEN
228 
229  batimetry_function = 0.5*cos(pig*x)**4+0.25*(cos(10.0*pig*(x-0.5))+1)
230 
231  ELSEIF(x.GT.0.6.AND.x.LT.1.0-eps_dis)THEN
232 
233  batimetry_function = 0.5*cos(pig*x)**4
234 
235  ELSEIF(x.GE.1.0-eps_dis.AND.x.LE.1.0+eps_dis)THEN
236 
237  batimetry_function = 0.25
238 
239  ELSEIF(x.GT.1.0+eps_dis.AND.x.LE.1.5)THEN
240 
241  batimetry_function = 0.25*sin(2*pig*(x-1))
242 
243  ELSE
244 
245  batimetry_function = 0.d0
246 
247  ENDIF
248 
249  END FUNCTION batimetry_function
250 
251 
252 END MODULE geometry
real *8 function batimetry_function(x)
Batimetry function.
Definition: geometry.f90:206
Grid module.
Definition: geometry.f90:7
Parameters.
Definition: parameters.f90:7
subroutine interp_1d_scalar(x1, f1, x2, f2)
Scalar interpolation.
Definition: geometry.f90:154
subroutine init_grid
Finite volume grid initialization.
Definition: geometry.f90:47