LAHARS-MODEL  0.1
templategithubproject
init_2d.f90
Go to the documentation of this file.
1 !********************************************************************************
3 !
6 !********************************************************************************
7 
8 MODULE init_2d
9 
12 
13  IMPLICIT none
14 
15  REAL*8, ALLOCATABLE :: q_init(:,:,:)
16 
17  REAL*8, ALLOCATABLE :: thickness_init(:,:)
18 
21  REAL*8 :: riemann_interface
22 
23  REAL*8 :: hb_w
24  REAL*8 :: u_w
25  REAL*8 :: v_w
26  REAL*8 :: alphas_w
27  REAL*8 :: t_w
28 
29  REAL*8 :: hb_e
30  REAL*8 :: u_e
31  REAL*8 :: v_e
32  REAL*8 :: alphas_e
33  REAL*8 :: t_e
34 
35 
36 CONTAINS
37 
38 
39  !******************************************************************************
41  !
46  !******************************************************************************
47 
48  SUBROUTINE riemann_problem
49 
50  USE constitutive_2d, ONLY : qp_to_qc
51 
53 
54  ! USE geometry_2d, ONLY : x0 , xN , y0 , yN
55 
56  USE parameters_2d, ONLY : n_vars , verbose_level
57 
58  USE solver_2d, ONLY : q
59 
60  IMPLICIT none
61 
62  ! REAL*8 :: hB !< height + topography
63  ! REAL*8 :: u !< velocity
64  ! REAL*8 :: v !< velocity
65 
66  REAL*8 :: qp(n_vars,comp_cells_x,comp_cells_y) , qj(n_vars)
67 
68  INTEGER :: j,k
69  INTEGER :: i1
70 
71  REAL*8 :: eps
72 
73  IF ( verbose_level .GE. 1 ) THEN
74 
75  WRITE(*,*) 'Riemann problem initialization'
76  WRITE(*,*) 'x_comp(1)',x_comp(1)
77  WRITE(*,*) 'x_comp(comp_cells_x)',x_comp(comp_cells_x)
78  WRITE(*,*) 'riemann_interface',riemann_interface
79 
80  END IF
81 
82 
83  i1 = 0
84 
85  riemann_int_search:DO j = 1,comp_cells_x
86 
87  IF ( x_comp(j) .LT. riemann_interface ) THEN
88 
89  i1 = j
90 
91  ELSE
92 
93  EXIT riemann_int_search
94 
95  END IF
96 
97  END DO riemann_int_search
98 
99  eps = 1.d-10
100 
101  ! Left initial state
102  qp(1,1:i1,:) = hb_w
103  qp(2,1:i1,:) = u_w
104  qp(3,1:i1,:) = v_w
105 
106  IF ( solid_transport_flag ) THEN
107 
108  qp(4,1:i1,:) = alphas_w
109 
110  IF ( temperature_flag ) qp(5,1:i1,:) = t_w
111 
112  ELSE
113 
114  IF ( temperature_flag ) qp(4,1:i1,:) = t_w
115 
116  END IF
117 
118 
119  IF ( verbose_level .GE. 1 ) WRITE(*,*) 'Left state'
120 
121  DO j = 1,i1
122 
123  DO k = 1,comp_cells_y
124 
125  ! evaluate the vector of conservative variables
126  CALL qp_to_qc( qp(:,j,k) , b_cent(j,k) , qj )
127 
128  q(1:n_vars,j,k) = qj
129 
130  IF ( verbose_level .GE. 1 ) THEN
131 
132  WRITE(*,*) j,k,b_cent(j,k)
133  WRITE(*,*) qp(:,j,k)
134  WRITE(*,*) q(1:n_vars,j,k)
135 
136  END IF
137 
138  ENDDO
139 
140  END DO
141 
142  IF ( verbose_level .GE. 1 ) READ(*,*)
143 
144  ! Right initial state
145  qp(1,i1+1:comp_cells_x,:) = hb_e
146  qp(2,i1+1:comp_cells_x,:) = u_e
147  qp(3,i1+1:comp_cells_x,:) = v_e
148 
149  IF ( solid_transport_flag ) THEN
150 
151  qp(4,i1+1:comp_cells_x,:) = alphas_e
152 
153  IF ( temperature_flag ) qp(5,i1+1:comp_cells_x,:) = t_e
154 
155  ELSE
156 
157  IF ( temperature_flag ) qp(4,i1+1:comp_cells_x,:) = t_e
158 
159  END IF
160 
161 
162  IF ( verbose_level .GE. 1 ) WRITE(*,*) 'Right state'
163 
164  DO j = i1+1,comp_cells_x
165 
166  DO k = 1,comp_cells_y
167 
168  ! evaluate the vector of conservative variables
169  CALL qp_to_qc( qp(:,j,k) , b_cent(j,k) , qj )
170 
171  q(1:n_vars,j,k) = qj
172 
173  IF ( verbose_level .GE. 1 ) THEN
174 
175  WRITE(*,*) j,k,b_cent(j,k)
176  WRITE(*,*) qp(:,j,k)
177  WRITE(*,*) q(1:n_vars,j,k)
178 
179  END IF
180 
181  END DO
182 
183  ENDDO
184 
185  IF ( verbose_level .GE. 1 ) READ(*,*)
186 
187  RETURN
188 
189  END SUBROUTINE riemann_problem
190 
191  !******************************************************************************
193  !
197  !******************************************************************************
198 
199  SUBROUTINE initial_conditions
201  USE constitutive_2d, ONLY : qp_to_qc
202 
203  USE geometry_2d, ONLY : x_comp , comp_cells_x, y_comp , comp_cells_y , &
204  b_cent
205 
206  USE geometry_2d, ONLY : dx , dy
207 
210 
211  USE solver_2d, ONLY : q
212 
213  IMPLICIT none
214 
215  REAL*8 :: qp(n_vars,comp_cells_x,comp_cells_y) , qj(n_vars)
216 
217  INTEGER :: j,k
218 
219  DO j=1,comp_cells_x
220 
221  DO k=1,comp_cells_y
222 
223  qp(1,j,k) = thickness_function(x_comp(j),y_comp(k),b_cent(j,k))
224 
225  qp(2,j,k) = velocity_u_function(x_comp(j),y_comp(k))
226 
227  qp(3,j,k) = velocity_v_function(x_comp(j),y_comp(k))
228 
229  IF ( solid_transport_flag ) THEN
230 
231  qp(4,j,k) = sediment_function(x_comp(j),y_comp(k))
232 
233  IF ( temperature_flag ) THEN
234 
235  qp(5,j,k) = temperature_function(x_comp(j),y_comp(k))
236 
237  END IF
238 
239  ELSE
240 
241  IF ( temperature_flag ) THEN
242 
243  qp(4,j,k) = temperature_function(x_comp(j),y_comp(k))
244 
245  END IF
246 
247  END IF
248 
249  ENDDO
250 
251  ENDDO
252 
253  IF ( released_volume .GT. ( dx * dy * sum( qp(1,:,:)-b_cent(:,:) ) ) ) THEN
254 
255  ! Correction for the released volume
256  qp(1,:,:) = b_cent(:,:) + ( qp(1,:,:)-b_cent(:,:) ) * released_volume &
257  / ( dx * dy * sum( qp(1,:,:)-b_cent(:,:) ) )
258 
259  END IF
260 
261  WRITE(*,*) 'Initial volume =',dx * dy * sum( qp(1,:,:)-b_cent(:,:) )
262 
263 
264  DO j = 1,comp_cells_x
265 
266  DO k = 1,comp_cells_y
267 
268  ! evaluate the vector of conservative variables
269  CALL qp_to_qc( qp(:,j,k) , b_cent(j,k) , qj )
270 
271  q(1:n_vars,j,k) = qj
272 
273  IF ( verbose_level .GE. 1 ) WRITE(*,*) j,k,b_cent(j,k),qp(:,j,k)
274 
275  END DO
276 
277  ENDDO
278 
279  IF ( verbose_level .GE. 1 ) READ(*,*)
280 
281  IF ( source_flag ) CALL init_source
282 
283  RETURN
284 
285  END SUBROUTINE initial_conditions
286 
287  !******************************************************************************
289  !
292  !******************************************************************************
293 
294  SUBROUTINE init_source
297  USE geometry_2d, ONLY : dx , dy
298 
299  USE parameters_2d, ONLY : x_source , y_source , r_source
300  USE parameters_2d, ONLY : vfr_source , vel_source
301 
302  USE solver_2d, ONLY : source_xy
303 
304  IMPLICIT NONE
305 
306  INTEGER :: h,j,k
307 
308  REAL*8, ALLOCATABLE :: x_subgrid(:) , y_subgrid(:)
309  INTEGER, ALLOCATABLE :: check_subgrid(:)
310 
311  INTEGER n_points , n_points2
312  REAL*8 :: source_area
313 
314  n_points = 200
315  n_points2 = n_points**2
316 
317  ALLOCATE( x_subgrid(n_points2) )
318  ALLOCATE( y_subgrid(n_points2) )
319  ALLOCATE( check_subgrid(n_points2) )
320 
321  x_subgrid = 0.d0
322  y_subgrid = 0.d0
323 
324  DO h = 1,n_points
325 
326  x_subgrid(h:n_points2:n_points) = h
327  y_subgrid((h-1)*n_points+1:h*n_points) = h
328 
329  END DO
330 
331  x_subgrid = x_subgrid / ( n_points +1 )
332  y_subgrid = y_subgrid / ( n_points +1 )
333 
334  x_subgrid = ( x_subgrid - 0.5d0 ) * dx
335  y_subgrid = ( y_subgrid - 0.5d0 ) * dy
336 
337  source_xy(:,:) = 0.d0
338 
339  DO j=1,comp_cells_x
340 
341  DO k=1,comp_cells_y
342 
343  check_subgrid = 0
344 
345  WHERE ( ( x_comp(j) + x_subgrid - x_source )**2 &
346  + ( y_comp(k) + y_subgrid - y_source )**2 < r_source**2 )
347 
348  check_subgrid = 1
349 
350  END WHERE
351 
352  ! WRITE(*,*) x_comp(j),y_comp(k),REAL(SUM(check_subgrid))/10201.D0
353 
354  source_xy(j,k) = REAL(sum(check_subgrid))/n_points2
355 
356  ENDDO
357 
358  ENDDO
359 
360  source_area = dx*dy*sum(source_xy)
361 
362  WRITE(*,*) 'Source area =',source_area,' Error =',abs( 1.d0 - &
363  dx*dy*sum(source_xy) / ( 4.d0*atan(1.d0)*r_source**2 ) )
364 
365  vel_source = vfr_source / source_area
366 
367  WRITE(*,*) 'Vel source =',vel_source
368 
369  END SUBROUTINE init_source
370 
371  !******************************************************************************
373  !
380  !******************************************************************************
381 
382  REAL*8 FUNCTION thickness_function(x,y,Bj)
385 
386  IMPLICIT NONE
387 
388  REAL*8, INTENT(IN) :: x,y
389  REAL*8, INTENT(IN) :: Bj
390 
391  REAL*8, PARAMETER :: pig = 4.d0*atan(1.d0)
392  REAL*8 :: R
393 
394  ! example 1D from Kurganov and Petrova 2007
395  !IF(y.LE.0.d0)THEN
396  ! thickness_function=0.4d0+Bj
397  !ELSE
398  ! thickness_function=Bj
399  !ENDIF
400 
401  ! example 2D from Kurganov and Petrova 2007
402  ! thickness_function=MAX(0.25,Bj)
403 
404  r = ( released_volume / pig )**(1.0/3.0)
405 
406  IF ( dsqrt( (x-x_release)**2 + (y-y_release)**2 ) .LE. r ) THEN
407 
408  thickness_function = bj + r
409 
410  ELSE
411 
412  thickness_function = bj
413 
414  ENDIF
415 
416  END FUNCTION thickness_function
417 
418  !******************************************************************************
420  !
426  !******************************************************************************
427 
428  REAL*8 FUNCTION velocity_u_function(x,y)
429 
432 
433  USE geometry_2d, ONLY : x0 , y0 , dx , dy
434  USE geometry_2d, ONLY : x_stag , y_stag , b_ver
435 
436  IMPLICIT NONE
437 
438  REAL*8, INTENT(IN) :: x,y
439 
440  REAL*8, PARAMETER :: pig = 4.0*atan(1.0)
441  REAL*8 :: R
442 
443  INTEGER :: idx1 , idy1
444  REAL*8 :: coeff_x , coeff_y
445 
446  REAL*8 :: dBdx1 , dBdx2 , dBdx
447  REAL*8 :: dBdy1 , dBdy2 , dBdy
448 
449  REAL*8 :: max_slope_angle_rad
450  REAL*8 :: velocity_ang_release_rad
451 
452 
453  r = ( released_volume / pig )**(1.d0/3.d0)
454 
455  ! indexes of the lower-left vertex of the cell in the computational grid
456  idx1 = ceiling( ( x_release - x0 ) / dx )
457  idy1 = ceiling( ( y_release - y0 ) / dy )
458 
459  ! relative coordinates of (x_release,y_release) within the cell
460  coeff_x = ( x_release - x_stag(idx1) ) / dx
461  coeff_y = ( y_release - y_stag(idy1) ) / dy
462 
463 
464  ! x-derivatives at bottom and top edges of the cell
465  dbdx1 = ( b_ver(idx1+1,idy1) - b_ver(idx1,idy1) ) / dx
466  dbdx2 = ( b_ver(idx1+1,idy1+1) - b_ver(idx1,idy1+1) ) / dx
467 
468  ! x-derivative of terrain at (x_release,y_release)
469  dbdx = coeff_y * dbdx2 + ( 1.d0 - coeff_y ) * dbdx1
470 
471  ! y-derivatives at left and right edges of the cell
472  dbdy1 = ( b_ver(idx1,idy1+1) - b_ver(idx1,idy1) ) / dy
473  dbdy2 = ( b_ver(idx1+1,idy1+1) - b_ver(idx1+1,idy1) ) / dx
474 
475  ! y-derivative of terrain at (x_release,y_release)
476  dbdy = coeff_x * dbdy2 + ( 1.d0 - coeff_x ) * dbdy1
477 
478 
479  ! direction of maximum slope in radians
480  max_slope_angle_rad = datan2(dbdy,dbdx)
481 
482  IF ( verbose_level .GE. 1 ) THEN
483 
484  WRITE(*,*) x0,x_stag(1),y0,y_stag(1),dx,dy
485  WRITE(*,*) '---',x_stag(idx1),x_release,x_stag(idx1+1),coeff_x
486  WRITE(*,*) '---',y_stag(idy1),y_release,y_stag(idy1+1),coeff_y
487 
488  WRITE(*,*) b_ver(idx1,idy1),b_ver(idx1+1,idy1)
489  WRITE(*,*) b_ver(idx1,idy1+1),b_ver(idx1+1,idy1+1)
490  WRITE(*,*) 'dbdx,dbdy,angle',dbdx,dbdy,max_slope_angle_rad*180.d0/pig
491 
492  READ(*,*)
493 
494  END IF
495 
496  IF ( dsqrt( (x-x_release)**2 + (y-y_release)**2 ) .LE. r ) THEN
497 
498  velocity_ang_release_rad = velocity_ang_release * pig / 180.d0
499 
500  IF ( velocity_ang_release .GE. 0.d0 ) THEN
501 
502  ! angle departing from positive x-axis
504  * cos( velocity_ang_release * ( 2.d0 * pig / 360.d0 ) )
505 
506  ELSE
507 
508  ! angle departing from maximum slope direction
510  * cos( max_slope_angle_rad + velocity_ang_release_rad )
511 
512  END IF
513 
514  ELSE
515 
516  velocity_u_function = 0.d0
517 
518  ENDIF
519 
520  END FUNCTION velocity_u_function
521 
522  !******************************************************************************
524  !
530  !******************************************************************************
531 
532  REAL*8 FUNCTION velocity_v_function(x,y)
533 
536 
537  USE geometry_2d, ONLY : x0 , y0 , dx , dy
538  USE geometry_2d, ONLY : x_stag , y_stag , b_ver
539 
540  IMPLICIT NONE
541 
542  REAL*8, INTENT(IN) :: x,y
543 
544  REAL*8, PARAMETER :: pig = 4.0*atan(1.0)
545  REAL*8 :: R
546 
547  INTEGER :: idx1 , idy1
548  REAL*8 :: coeff_x , coeff_y
549 
550  REAL*8 :: dBdx1 , dBdx2 , dBdx
551  REAL*8 :: dBdy1 , dBdy2 , dBdy
552 
553  REAL*8 :: max_slope_angle_rad
554  REAL*8 :: velocity_ang_release_rad
555 
556 
557  r = ( released_volume / pig )**(1.0/3.0)
558 
559  ! indexes of the lower-left vertex of the cell in the computational grid
560  idx1 = ceiling( ( x_release - x0 ) / dx )
561  idy1 = ceiling( ( y_release - y0 ) / dy )
562 
563  ! relative coordinates of (x_release,y_release) within the cell
564  coeff_x = ( x_release - x_stag(idx1) ) / dx
565  coeff_y = ( y_release - y_stag(idy1) ) / dy
566 
567 
568  ! x-derivatives at bottom and top edges of the cell
569  dbdx1 = ( b_ver(idx1+1,idy1) - b_ver(idx1,idy1) ) / dx
570  dbdx2 = ( b_ver(idx1+1,idy1+1) - b_ver(idx1,idy1+1) ) / dx
571 
572  ! x-derivative of terrain at (x_release,y_release)
573  dbdx = coeff_y * dbdx2 + ( 1.d0 - coeff_y ) * dbdx1
574 
575  ! y-derivatives at left and right edges of the cell
576  dbdy1 = ( b_ver(idx1,idy1+1) - b_ver(idx1,idy1) ) / dy
577  dbdy2 = ( b_ver(idx1+1,idy1+1) - b_ver(idx1+1,idy1) ) / dx
578 
579  ! y-derivative of terrain at (x_release,y_release)
580  dbdy = coeff_x * dbdy2 + ( 1.d0 - coeff_x ) * dbdy1
581 
582 
583 
584  IF ( dsqrt( (x-x_release)**2 + (y-y_release)**2 ) .LE. r ) THEN
585 
586  velocity_ang_release_rad = velocity_ang_release * pig / 180.d0
587 
588  IF ( velocity_ang_release .GE. 0.d0 ) THEN
589 
590  ! angle departing from positive x-axis
592  * sin( velocity_ang_release * ( 2.d0 * pig / 360.d0 ) )
593 
594  ELSE
595 
596  ! angle departing from maximum slope direction
598  * sin( max_slope_angle_rad + velocity_ang_release_rad )
599 
600  END IF
601 
602  ELSE
603 
604  velocity_v_function = 0.d0
605 
606  ENDIF
607 
608  END FUNCTION velocity_v_function
609 
610  !******************************************************************************
612  !
618  !******************************************************************************
619 
620  REAL*8 FUNCTION sediment_function(x,y)
621 
624 
625  IMPLICIT NONE
626 
627  REAL*8, INTENT(IN) :: x,y
628 
629  REAL*8, PARAMETER :: pig = 4.0*atan(1.0)
630  REAL*8 :: R
631 
632  r = ( released_volume / pig )**(1.0/3.0)
633 
634  IF ( dsqrt( (x-x_release)**2 + (y-y_release)**2 ) .LE. r ) THEN
635 
637 
638  ELSE
639 
641 
642  ENDIF
643 
644  END FUNCTION sediment_function
645 
646 
647 
648  !******************************************************************************
650  !
656  !******************************************************************************
657 
658  REAL*8 FUNCTION temperature_function(x,y)
659 
661  USE parameters_2d, ONLY : t_init , t_ambient
662 
663  IMPLICIT NONE
664 
665  REAL*8, INTENT(IN) :: x,y
666 
667  REAL*8, PARAMETER :: pig = 4.0*atan(1.0)
668  REAL*8 :: R
669 
670  r = ( released_volume / pig )**(1.0/3.0)
671 
672  IF ( dsqrt( (x-x_release)**2 + (y-y_release)**2 ) .LE. r ) THEN
673 
675 
676  ELSE
677 
679 
680  ENDIF
681 
682  END FUNCTION temperature_function
683 
684 END MODULE init_2d
real *8 dy
Control volumes size.
Definition: geometry_2d.f90:71
real *8, dimension(:), allocatable x_comp
Location of the centers (x) of the control volume of the domain.
Definition: geometry_2d.f90:14
real *8 y0
Bottom of the physical domain.
Definition: geometry_2d.f90:72
real *8, dimension(:,:), allocatable b_cent
Topography at the centers of the control volumes.
Definition: geometry_2d.f90:47
integer comp_cells_x
Number of control volumes x in the comp. domain.
Definition: geometry_2d.f90:76
real *8 vel_source
real *8, dimension(:,:), allocatable thickness_init
Definition: init_2d.f90:17
real *8, dimension(:), allocatable y_comp
Location of the centers (y) of the control volume of the domain.
Definition: geometry_2d.f90:20
logical temperature_flag
Flag to choose if we model temperature transport.
real *8, dimension(:,:), allocatable source_xy
Array defining fraction of cells affected by source term.
Definition: solver_2d.f90:78
real *8 t_init
Initial temperature of the pile of material.
real *8 alphas_e
Right sediment concentration.
Definition: init_2d.f90:32
real *8 u_e
Right velocity x.
Definition: init_2d.f90:30
real *8 v_w
Left velocity y.
Definition: init_2d.f90:25
Parameters.
real *8 dx
Control volumes size.
Definition: geometry_2d.f90:68
real *8 y_release
Initial y-coordinate of the pile.
integer comp_cells_y
Number of control volumes y in the comp. domain.
Definition: geometry_2d.f90:78
Numerical solver.
Definition: solver_2d.f90:12
real *8 function sediment_function(x, y)
Sediment function.
Definition: init_2d.f90:621
real *8 riemann_interface
Riemann problem interface relative position. It is a value between 0 and 1.
Definition: init_2d.f90:21
Initial solution.
Definition: init_2d.f90:8
real *8 u_w
Left velocity x.
Definition: init_2d.f90:24
real *8 function thickness_function(x, y, Bj)
Thickness function.
Definition: init_2d.f90:383
real *8 velocity_ang_release
Initial velocity direction (angle in degree): .
real *8 alphas_init
Initial sediment concentration in the pile of material.
real *8 velocity_mod_release
Initial velocity module of the pile.
real *8 released_volume
Initial volume of the flow.
integer n_vars
Number of conservative variables.
real *8 alphas_ambient
Ambient sediment concentration.
real *8 t_ambient
Ambient temperature.
subroutine initial_conditions
Problem initialization.
Definition: init_2d.f90:200
logical source_flag
Flag to choose if there is a source of mass within the domain.
real *8 vfr_source
Constitutive equations.
real *8 x_release
Initial x-coordiante of the pile.
real *8 x0
Left of the physical domain.
Definition: geometry_2d.f90:69
real *8, dimension(:,:), allocatable b_ver
Topography at the vertices of the control volumes.
Definition: geometry_2d.f90:44
Grid module.
Definition: geometry_2d.f90:7
real *8 t_w
Left temperature.
Definition: init_2d.f90:27
real *8 v_e
Right velocity y.
Definition: init_2d.f90:31
real *8 function velocity_u_function(x, y)
Velocity u function.
Definition: init_2d.f90:429
integer verbose_level
real *8, dimension(:), allocatable x_stag
Location of the boundaries (x) of the control volumes of the domain.
Definition: geometry_2d.f90:17
real *8 function temperature_function(x, y)
Temperature function.
Definition: init_2d.f90:659
real *8 function velocity_v_function(x, y)
Velocity v function.
Definition: init_2d.f90:533
real *8 t_e
Right temperature.
Definition: init_2d.f90:33
subroutine qp_to_qc(qp, B, qc)
Physical to conservative variables.
subroutine riemann_problem
Riemann problem initialization.
Definition: init_2d.f90:49
real *8, dimension(:), allocatable y_stag
Location of the boundaries (x) of the control volumes of the domain.
Definition: geometry_2d.f90:23
real *8, dimension(:,:,:), allocatable q_init
Definition: init_2d.f90:15
real *8 alphas_w
Left sediment concentration.
Definition: init_2d.f90:26
logical solid_transport_flag
Flag to choose if we model solid phase transport.
real *8 hb_w
Left height.
Definition: init_2d.f90:23
real *8 hb_e
Right height.
Definition: init_2d.f90:29
subroutine init_source
Source initialization.
Definition: init_2d.f90:295
real *8, dimension(:,:,:), allocatable q
Conservative variables.
Definition: solver_2d.f90:35