IMEXSfloW  1.0
templategithubproject
 All Classes Files Functions Variables Pages
inpout.f90
Go to the documentation of this file.
1 !********************************************************************************
3 !
6 !
10 !
11 !********************************************************************************
12 
13 MODULE inpout
14 
15  ! -- Variables for the namelist RUN_PARAMETERS
16  USE parameters, ONLY : solver_scheme , max_dt , t_start , t_end , &
17  dt_output , cfl, limiter , theta , reconstr_coeff , reconstr_variables , &
18  interfaces_relaxation , n_rk , batimetry_function_flag , riemann_flag
19 
20  USE solver, ONLY : verbose_level
21 
22  ! -- Variables for the namelist NEWRUN_PARAMETERS
23  USE geometry, ONLY : x0 , xn , comp_cells
24  USE geometry, ONLY : batimetry_profile , n_batimetry_profile
25  USE init, ONLY : riemann_interface
26 
27  ! -- Variables for the namelist LEFT_STATE
28  USE init, ONLY : hb_l , u_l
29 
30  ! -- Variables for the namelist RIGHT_STATE
31  USE init, ONLY : hb_r , u_r
32 
33  ! -- Variables for the namelists LEFT/RIGHT_BOUNDARY_CONDITIONS
34  USE parameters, ONLY : bc
35 
36  ! -- Variables for the namelist SOURCE_PARAMETERS
37  USE constitutive, ONLY : grav
38 
39  IMPLICIT NONE
40 
41  CHARACTER(LEN=40) :: run_name
42  CHARACTER(LEN=40) :: bak_name
43  CHARACTER(LEN=40) :: input_file
44  CHARACTER(LEN=40) :: output_file
45  CHARACTER(LEN=40) :: restart_file
46  CHARACTER(LEN=40) :: batimetry_file
47  CHARACTER(LEN=40) :: dakota_file
48 
49  INTEGER, PARAMETER :: input_unit = 7
50  INTEGER, PARAMETER :: backup_unit = 8
51  INTEGER, PARAMETER :: output_unit = 9
52  INTEGER, PARAMETER :: restart_unit = 10
53  INTEGER, PARAMETER :: dakota_unit = 11
54 
55 
56  INTEGER :: output_idx
57 
62  LOGICAL :: restart
63 
64  ! -- Variables for the namelists LEFT_BOUNDARY_CONDITIONS
65  TYPE(bc) :: hB_bcL , u_bcL
66 
67  ! -- Variables for the namelists RIGHT_BOUNDARY_CONDITIONS
68  TYPE(bc) :: hB_bcR , u_bcR
69 
70 
71  namelist / run_parameters / run_name , restart , batimetry_function_flag , &
72  riemann_flag , max_dt , t_start , t_end , dt_output , solver_scheme , &
73  cfl , limiter , theta , reconstr_coeff , reconstr_variables , n_rk , &
74  verbose_level
75 
76  namelist / restart_parameters / restart_file
77 
78  namelist / newrun_parameters / x0 , xn , comp_cells , riemann_interface
79 
80  namelist / left_state / hb_l , u_l
81 
82  namelist / right_state / hb_r , u_r
83 
84  namelist / left_boundary_conditions / hb_bcl , u_bcl
85 
86  namelist / right_boundary_conditions / hb_bcr , u_bcr
87 
88  namelist / source_parameters / grav
89 
90 CONTAINS
91 
92  !******************************************************************************
94  !
98  !
102  !
103  !******************************************************************************
104 
105  SUBROUTINE init_param
106 
107  USE parameters , ONLY : n_vars
108 
109  IMPLICIT none
110 
111  LOGICAL :: lexist
112 
113  INTEGER :: i
114 
115  !-- Inizialization of the Variables for the namelist RUN_PARAMETERS
116  run_name = 'default'
117  restart = .false.
118  batimetry_function_flag=.false.
119  riemann_flag=.true.
120  max_dt = 1.d-3
121  t_start = 0.0
122  t_end = 5.0d-4
123  dt_output = 1.d-4
124  solver_scheme = 'LxF'
125  n_rk = 2
126  verbose_level = 0
127 
128 
129  cfl = 0.5
130  limiter(1:n_vars) = 0
131  theta=1.0
132  reconstr_coeff = 1.0
133  reconstr_variables = 0
134  !-- Inizialization of the Variables for the namelist restart parameters
135  restart_file = ''
136 
137  !-- Inizialization of the Variables for the namelist newrun_parameters
138  x0 = 0.d0
139  xn = 1.d0
140  comp_cells = 500
141  riemann_interface = 0.5d0
142 
143  !-- Inizialization of the Variables for the namelist left_state
144  hb_l = 1.d0
145  u_l = 0.d0
146 
147  !-- Inizialization of the Variables for the namelist right_state
148  hb_r = 0.5d0
149  u_r = 0.d0
150 
151  !-- Inizialization of the Variables for the namelist left boundary conditions
152 
153  hb_bcl%flag = 1
154  hb_bcl%value = 0.d0
155 
156  u_bcl%flag = 1
157  u_bcl%value = 0.d0
158 
159  !-- Inizialization of the Variables for the namelist right boundary conditions
160 
161  hb_bcr%flag = 1
162  hb_bcr%value = 0.d0
163 
164  u_bcr%flag = 1
165  u_bcr%value = 0.d0
166 
167  !-- Inizialization of the Variables for the namelist source_parameters
168  grav = -9.81d0
169 
170  input_file = 'shallow_water.inp'
171 
172  INQUIRE (file=input_file,exist=lexist)
173 
174  IF (lexist .EQV. .false.) THEN
175 
176  OPEN(input_unit,file=input_file,status='NEW')
177 
178  WRITE(input_unit, run_parameters )
179  WRITE(input_unit, restart_parameters )
180  WRITE(input_unit, newrun_parameters )
181  WRITE(input_unit, left_state )
182  WRITE(input_unit, right_state )
183  WRITE(input_unit, left_boundary_conditions )
184  WRITE(input_unit, right_boundary_conditions )
185  WRITE(input_unit, source_parameters )
186 
187  n_batimetry_profile = 2
188 
189  ALLOCATE( batimetry_profile(2,n_batimetry_profile) )
190 
191  batimetry_profile(1,1) = 0.d0
192  batimetry_profile(2,1) = 1.d0
193 
194  batimetry_profile(2,2) = 0.d0
195  batimetry_profile(2,2) = 10.d0
196 
197 
198  WRITE(input_unit,*) '''BATIMETRY_PROFILE'''
199  WRITE(input_unit,*) n_batimetry_profile
200 
201  DO i = 1, n_batimetry_profile
202 
203  WRITE(input_unit,108) batimetry_profile(1:2,i)
204 
205 108 FORMAT(2(1x,e14.7))
206 
207 
208  END DO
209 
210  CLOSE(input_unit)
211 
212  WRITE(*,*) 'Input file shallow_water.inp not found'
213  WRITE(*,*) 'A new one with default values has been created'
214  stop
215 
216  ELSE
217 
218  END IF
219 
220  ! output file index
221  output_idx = 0
222 
223  END SUBROUTINE init_param
224 
225  !******************************************************************************
227  !
232  !
236  !
237  !******************************************************************************
238 
239  SUBROUTINE read_param
240 
241  USE parameters, ONLY : bcl , bcr
242 
243  IMPLICIT none
244 
245  REAL*8 :: max_cfl
246 
247  LOGICAL :: tend1
248  CHARACTER(LEN=80) :: card
249 
250  INTEGER :: i
251 
252  CHARACTER(LEN=4) :: idx_string
253 
254  OPEN(input_unit,file=input_file,status='old')
255 
256 
257  ! ------- READ run_parameters NAMELIST -----------------------------------
258  READ(input_unit, run_parameters )
259 
260  IF ( ( solver_scheme .NE. 'LxF' ) .AND. ( solver_scheme .NE. 'KT' ) .AND. &
261  ( solver_scheme .NE. 'GFORCE' ) ) THEN
262 
263  WRITE(*,*) 'WARNING: no correct solver scheme selected',solver_scheme
264  WRITE(*,*) 'Chose between: LxF, GFORCE or KT'
265  stop
266 
267  END IF
268 
269  IF ( ( solver_scheme.EQ.'LxF' ) .OR. ( solver_scheme.EQ.'GFORCE' ) ) THEN
270 
271  max_cfl = 1.0
272 
273  ELSEIF ( solver_scheme .EQ. 'KT' ) THEN
274 
275  max_cfl = 0.5
276 
277  END IF
278 
279 
280  IF ( ( cfl .GT. max_cfl ) .OR. ( cfl .LT. 0.d0 ) ) THEN
281 
282  WRITE(*,*) 'WARNING: wrong value of cfl ',cfl
283  WRITE(*,*) 'Choose a value between 0.0 and ',max_cfl
284  READ(*,*)
285 
286  END IF
287 
288 
289  WRITE(*,*) 'Limiters',limiter
290 
291  IF ( ( maxval(limiter) .GT. 3 ) .OR. ( minval(limiter) .LT. 0 ) ) THEN
292 
293  WRITE(*,*) 'WARNING: wrong limiter ',limiter
294  WRITE(*,*) 'Choose among: none, minmod,superbee,van_leer'
295  stop
296 
297  END IF
298 
299  IF ( ( reconstr_coeff .GT. 1.0d0 ) .OR. ( reconstr_coeff .LT. 0.d0 ) ) THEN
300 
301  WRITE(*,*) 'WARNING: wrong value of reconstr_coeff ',reconstr_coeff
302  WRITE(*,*) 'Change the value between 0.0 and 1.0 in the input file'
303  READ(*,*)
304 
305  END IF
306 
307  IF ( ( reconstr_variables .GT. 2 ) .OR. ( reconstr_variables .LT. 0 ) ) THEN
308 
309  WRITE(*,*)'WARNING: wrong value of reconstr_variables ',reconstr_variables
310  WRITE(*,*)'Choose the value among: 0, 1 and 2'
311  READ(*,*)
312 
313  END IF
314 
315 
316  IF ( restart ) THEN
317 
318  READ(input_unit,restart_parameters)
319 
320  ELSE
321 
322  READ(input_unit,newrun_parameters)
323 
324  IF ( riemann_flag ) THEN
325 
326  READ(input_unit,left_state)
327  READ(input_unit,right_state)
328 
329  END IF
330 
331  END IF
332 
333  READ(input_unit,left_boundary_conditions)
334 
335  bcl(1) = hb_bcl
336  bcl(2) = u_bcl
337 
338  READ(input_unit,right_boundary_conditions)
339 
340  bcr(1) = hb_bcr
341  bcr(2) = u_bcr
342 
343  READ(input_unit, source_parameters )
344 
345  tend1 = .false.
346 
347  WRITE(*,*) 'search batimetry_profile'
348 
349  batimetry_profile_search: DO
350 
351  READ(input_unit,*, END = 200 ) card
352 
353  IF( trim(card) == 'BATIMETRY_PROFILE' ) THEN
354 
355  EXIT batimetry_profile_search
356 
357  END IF
358 
359  END DO batimetry_profile_search
360 
361  READ(input_unit,*) n_batimetry_profile
362 
363  IF ( verbose_level .GE. 1 ) WRITE(*,*) 'n_batimetry_profile' , &
364  n_batimetry_profile
365 
366  ALLOCATE( batimetry_profile(2,n_batimetry_profile) )
367 
368  DO i = 1, n_batimetry_profile
369 
370  READ(input_unit,*) batimetry_profile(1:2,i)
371 
372  IF ( verbose_level .GE. 1 ) WRITE(*,*) i,batimetry_profile(1:2,i)
373 
374  END DO
375 
376  goto 210
377 200 tend1 = .true.
378 210 CONTINUE
379 
380 
381  CLOSE( input_unit )
382 
383  bak_name = trim(run_name)//'.bak'
384 
385  OPEN(backup_unit,file=bak_name,status='unknown')
386 
387  WRITE(backup_unit, run_parameters )
388 
389  IF ( restart ) THEN
390 
391  WRITE(backup_unit,restart_parameters)
392 
393  ELSE
394 
395  WRITE(backup_unit,newrun_parameters)
396 
397  IF ( riemann_flag ) THEN
398 
399  WRITE(backup_unit,left_state)
400  WRITE(backup_unit,right_state)
401 
402  END IF
403 
404  END IF
405 
406  WRITE(backup_unit,left_boundary_conditions)
407  WRITE(backup_unit,right_boundary_conditions)
408 
409  WRITE(backup_unit, source_parameters )
410 
411  WRITE(backup_unit,*) '''BATIMETRY_PROFILE'''
412  WRITE(backup_unit,*) n_batimetry_profile
413 
414  DO i = 1, n_batimetry_profile
415 
416  WRITE(backup_unit,107) batimetry_profile(1:2,i)
417 
418 107 FORMAT(2(1x,e14.7))
419 
420 
421  END DO
422 
423 
424  CLOSE(backup_unit)
425 
426 
427  END SUBROUTINE read_param
428 
429 
430  !******************************************************************************
432  !
435  !
439  !
440  !******************************************************************************
441 
442  SUBROUTINE read_solution
443 
444  USE geometry, ONLY : init_grid
446 
447  USE geometry , ONLY : comp_cells , x0 , dx
448  USE parameters, ONLY : n_vars
449  USE parameters, ONLY : t_start
450  USE solver, ONLY : q
451 
452  IMPLICIT none
453 
454  INTEGER :: j
455  INTEGER :: i
456 
457  CHARACTER(LEN=30) :: string
458 
459  OPEN(restart_unit,file=restart_file,status='old')
460 
461  READ(restart_unit,1001) x0,dx,comp_cells,t_start
462 1001 FORMAT(e18.8,' x0', /, e18.8,' dx', /, i18,' cells', /, e18.8,' t', /)
463 
464 
465  CALL init_grid
466 
468 
469 
470  DO i = 1,n_vars
471 
472  DO j = 1,comp_cells
473 
474  ! Exponents with more than 2 digits cause problems reading
475  ! into matlab... reset tiny values to zero:
476  IF ( dabs(q(i,j)) .LT. 1d-99) q(i,j) = 0.d0
477 
478  END DO
479 
480  READ(restart_unit,1003) (q(i,j), j=1,n_vars)
481 1003 FORMAT(4e20.12)
482 
483  END DO
484 
485  j = scan(restart_file, '.' , .true. )
486 
487  string = trim(restart_file(j+2:j+5))
488 
489  READ( string,* ) output_idx
490 
491  END SUBROUTINE read_solution
492 
493  !******************************************************************************
495  !
500  !
502  !
506  !
507  !******************************************************************************
508 
509  SUBROUTINE output_solution(t)
510 
511  ! external procedures
512  USE constitutive, ONLY : qc_to_qp
513 
514  ! external variables
515  USE constitutive, ONLY : h , u
516  USE geometry , ONLY : comp_cells , x0 , dx , x_comp , b_cent
517  USE parameters, ONLY : n_vars
518  USE parameters, ONLY : t_output , dt_output
519  USE solver, ONLY : q
520 
521  IMPLICIT none
522 
523  REAL*8, INTENT(IN) :: t
524 
525  CHARACTER(LEN=4) :: idx_string
526 
527  REAL*8 :: qp(n_vars)
528 
529  INTEGER :: j
530  INTEGER :: i
531 
532  output_idx = output_idx + 1
533 
534  idx_string = lettera(output_idx-1)
535 
536  output_file = trim(run_name)//'.q'//idx_string
537 
538  WRITE(*,*) 'WRITING ',output_file
539 
540  OPEN(output_unit,file=output_file,status='unknown',form='formatted')
541 
542  WRITE(output_unit,1002) x0,dx,comp_cells,t
543 
544  DO j = 1,comp_cells
545 
546  DO i = 1,n_vars
547 
548  ! Exponents with more than 2 digits cause problems reading
549  ! into matlab... reset tiny values to zero:
550  IF ( dabs(q(i,j)) .LT. 1d-99) q(i,j) = 0.d0
551 
552  END DO
553 
554  WRITE(output_unit,*) (q(i,j), i=1,n_vars)
555 
556  END DO
557 
558  WRITE(output_unit,*) ' '
559  WRITE(output_unit,*) ' '
560 
561  CLOSE(output_unit)
562 
563  output_file = trim(run_name)//'.p'//idx_string
564 
565  WRITE(*,*) 'WRITING ',output_file
566 
567  OPEN(output_unit,file=output_file,status='unknown',form='formatted')
568 
569  WRITE(output_unit,1002) x0,dx,comp_cells,t
570 
571  DO j = 1,comp_cells
572 
573  DO i = 1,n_vars
574 
575  ! Exponents with more than 2 digits cause problems reading
576  ! into matlab... reset tiny values to zero:
577  IF ( dabs(q(i,j)) .LT. 1d-99) q(i,j) = 0.d0
578 
579  END DO
580 
581  CALL qc_to_qp(q(:,j),b_cent(j),qp(:))
582 
583  IF ( REAL(h) .LT. 1d-99) h = 0.d0
584  IF ( abs(REAL(u)) .LT. 1d-99) u = 0.d0
585 
586 
587  WRITE(output_unit,1005) x_comp(j), REAL(h) , REAL(u) , b_cent(j) , &
588  REAL(h) + b_cent(j)
589 
590  END DO
591 
592  WRITE(output_unit,*) ' '
593  WRITE(output_unit,*) ' '
594 
595  CLOSE(output_unit)
596 
597 1002 FORMAT(e18.8,' x0', /, e18.8,' dx', /, i18,' cells', /, e18.8,' t', /)
598 
599 
600 1005 FORMAT(5e20.12)
601 
602 
603  t_output = t + dt_output
604 
605  END SUBROUTINE output_solution
606 
607 
608  SUBROUTINE close_units
609 
610  IMPLICIT NONE
611 
612  END SUBROUTINE close_units
613 
614  !******************************************************************************
616  !
619  !
621  !
625  !
626  !******************************************************************************
627 
628  CHARACTER*4 FUNCTION lettera(k)
629  IMPLICIT NONE
630  CHARACTER ones,tens,hund,thou
631  !
632  INTEGER :: k
633  !
634  INTEGER :: iten, ione, ihund, ithou
635  !
636  ithou=int(k/1000)
637  ihund=int((k-(ithou*1000))/100)
638  iten=int((k-(ithou*1000)-(ihund*100))/10)
639  ione=k-ithou*1000-ihund*100-iten*10
640  ones=char(ione+48)
641  tens=char(iten+48)
642  hund=char(ihund+48)
643  thou=char(ithou+48)
644  lettera=thou//hund//tens//ones
645  !
646  RETURN
647  END FUNCTION lettera
648 
649  SUBROUTINE output_dakota
650 
651  IMPLICIT NONE
652 
653  dakota_file = 'shallow_water.out'
654 
655  OPEN(dakota_unit,file=dakota_file,status='unknown',form='formatted')
656 
657  CLOSE(dakota_unit)
658 
659  END SUBROUTINE output_dakota
660 
661 
662 END MODULE inpout
663 
subroutine read_param
Read the input file.
Definition: inpout.f90:239
Numerical solver.
Definition: solver.f90:12
subroutine init_param
Initialization of the variables read from the input file.
Definition: inpout.f90:105
subroutine read_solution
Read the solution from the restart unit.
Definition: inpout.f90:442
character *4 function lettera(k)
Numeric to String conversion.
Definition: inpout.f90:628
Grid module.
Definition: geometry.f90:7
Initial solution.
Definition: init.f90:8
subroutine output_dakota
Definition: inpout.f90:649
Parameters.
Definition: parameters.f90:7
Constitutive equations.
Definition: constitutive.f90:4
subroutine allocate_solver_variables
Memory allocation.
Definition: solver.f90:112
subroutine qc_to_qp(qc, B, qp)
Conservative to physical variables.
Input/Output module.
Definition: inpout.f90:13
subroutine output_solution(t)
Write the solution on the output unit.
Definition: inpout.f90:509
subroutine close_units
Definition: inpout.f90:608
subroutine init_grid
Finite volume grid initialization.
Definition: geometry.f90:47