AshFlow  0.1
ashflowmodel
 All Classes Files Functions Variables Pages
flow.f90
Go to the documentation of this file.
1 !********************************************************************************
8 !********************************************************************************
9 
10 MODULE pdcflow
11 
12  IMPLICIT NONE
13  SAVE
14 
15 CONTAINS
16 
17  !******************************************************************************
21  !******************************************************************************
22 
23  SUBROUTINE pdc(run_name)
24 
25  ! External variables
26  USE envi_module, ONLY: zmet, alpha
27  USE mixture_module, ONLY: beta , beta_old, beta_new
28  USE mixture_module, ONLY: ri
29  USE current_module, ONLY: r, r0, r_old, r_new, u, h_old, h_new, h,t
30  USE solver_module, ONLY: dr, dr0, dr_old, f, ftemp, rhs, rhstemp
31  USE solver_module, ONLY: f_stepold, f_oldold
32 
33  USE solver_module, ONLY: f_new
34  USE solver_module, ONLY: f_rk
35  USE solver_module, ONLY: n_rk
36  USE solver_module, ONLY: rhs_rk
37  USE solver_module, ONLY: rhs4
38  USE solver_module, ONLY: f_err
39 
40  USE solver_module, ONLY: eps_rel , eps_abs
41 
42  ! External procedures
44  USE mixture_module, ONLY: compute_mixture, flow_regime
46  USE solver_module, ONLY: rate, lump, unlump, marching
47 
48  USE inpout, ONLY: write_output , write_dakota
49 
50  IMPLICIT NONE
51 
52  CHARACTER(LEN=80), INTENT(IN) :: run_name
53 
54  CHARACTER(LEN=4) :: idx_string
55 
56  REAL*8 :: volume_flux
57 
58  REAL*8 :: eps_step
59  REAL*8 :: convergence
60 
61  REAL*8 :: ri_old
62  REAL*8 :: ri_new
63 
64  INTEGER :: i_rk
65  LOGICAL :: rk_fail
66 
67  INTEGER :: i_sum
68 
69  REAL*8 :: a_rk(6,6)
70  REAL*8 :: b_rk(6)
71  REAL*8 :: c_rk(6)
72 
73  REAL*8 :: b4_rk(6)
74 
75  REAL*8 :: dr_rk
76 
77  REAL*8 :: err_check
78 
79  ! define the coefficients for the RK 4-5 order scheme
80 
81  a_rk = 0.d0
82 
83  a_rk(2,1) = 1.d0 / 5.d0
84 
85  a_rk(3,1) = 3.d0 / 40.d0
86  a_rk(3,2) = 9.d0 / 40.d0
87 
88  a_rk(4,1) = 3.d0 / 10.d0
89  a_rk(4,2) = -9.d0 / 10.d0
90  a_rk(4,3) = 6.d0 / 5.d0
91 
92  a_rk(5,1) = -11.d0 / 54.d0
93  a_rk(5,2) = 5.d0 / 2.d0
94  a_rk(5,3) = -70.d0 / 27.d0
95  a_rk(5,4) = 35.d0 / 27.d0
96 
97  a_rk(6,1) = 1631.d0 / 55296.d0
98  a_rk(6,2) = 175.d0 / 512.d0
99  a_rk(6,3) = 575.d0 / 13824.d0
100  a_rk(6,4) = 44275.d0 / 110592.d0
101  a_rk(6,5) = 253.d0 / 4096.d0
102 
103  c_rk = 0.d0
104 
105  c_rk(2) = 1.d0 / 5.d0
106  c_rk(3) = 3.d0 / 10.d0
107  c_rk(4) = 3.d0 / 5.d0
108  c_rk(5) = 1.d0
109  c_rk(6) = 7.d0 / 8.d0
110 
111  ! coefficients for the 5th order RK
112 
113  b_rk = 0.d0
114 
115  b_rk(1) = 37.d0 / 378.d0
116  b_rk(2) = 0.d0
117  b_rk(3) = 250.d0 / 621.d0
118  b_rk(4) = 125.d0 / 594.d0
119  b_rk(5) = 0.d0
120  b_rk(6) = 512.d0 / 1771.d0
121 
122  ! coefficient for the 4th order
123 
124  b4_rk = 0.d0
125 
126  b4_rk(1) = 2825.d0 / 27648.d0
127  b4_rk(2) = 0.d0
128  b4_rk(3) = 18575.d0 / 48384.d0
129  b4_rk(4) = 13525.d0 / 55296.d0
130  b4_rk(5) = 277.d0 / 14336.d0
131  b4_rk(6) = 1.d0 / 4.d0
132  !
133  ! ... Set initial conditions at initial radius
134  !
135  CALL initialize_current
136  !
137  ! ... Get meteorological variables
138  CALL zmet
139  CALL compute_mixture
140  !
141  ! ... Lump physical variables
142  CALL lump(f)
143  !
144  ! ----------------------------------------------------
145  ! ... assign initial stepping length and start marching loop
146  ! ----------------------------------------------------
147  dr = dr0
148  dr_old = 0
149 
150  CALL write_output
151 
152  f_oldold = f
153 
154  main_loop: DO
155 
156  r = r - dr_old
157  CALL unlump(f_oldold)
158 
159  h_old = h
160  r_old = r
161  beta_old = beta
162  ri_old = ri
163 
164  f_stepold = f
165 
166  r = r + dr_old
167 
168  CALL unlump(f)
169 
170  h_new = h
171  r_new = r
172  beta_new = beta
173  ri_new = ri
174 
175  !-------------- evaluate the terms for the RK scheme --------------------!
176 
177  ! first step
178  CALL zmet
179  CALL rate( rhs_rk(1,:) )
180 
181  h_old = h_new
182  r_old = r_new
183  beta_old = beta_new
184  ri_old = ri_new
185 
186  rk_fail = .false.
187 
188  rk_loop: DO i_rk=2,n_rk
189 
190  rhs(:) = 0.d0
191 
192  DO i_sum=1,i_rk-1
193 
194  rhs = rhs + a_rk(i_rk,i_sum) * rhs_rk(i_sum,:)
195 
196  END DO
197 
198  CALL marching( f_stepold , f_rk , rhs , dr )
199 
200  dr_rk = c_rk(i_rk)*dr
201 
202  r = r_old + dr_rk
203 
204  CALL unlump(f_rk)
205 
206  IF ( ( beta < alpha) .OR. ( h < 0 ) .OR. ( u < 0 ) .OR. &
207  ( minval(f) < 0 ) ) THEN
208 
209  rk_fail = .true.
210 
211  exit rk_loop
212 
213  END IF
214 
215  ! new values to evaluate the terms dh_dr and d_beta_dr
216  h_new = h
217  r_new = r
218  beta_new = beta
219 
220  CALL zmet
221  CALL rate( rhs_rk(i_rk,:) )
222 
223 
224  END DO rk_loop
225 
226  rhs(:) = 0.d0
227  rhs4(:) = 0.d0
228 
229  DO i_rk=1,n_rk
230 
231  rhs = rhs + b_rk(i_rk) * rhs_rk(i_rk,:)
232  rhs4 = rhs4 + b4_rk(i_rk) * rhs_rk(i_rk,:)
233 
234  END DO
235 
236  ! update the solution with the 5th order RK scheme
237  CALL marching(f_stepold,f,rhs,dr)
238 
239  r = r_old + dr
240 
241  CALL unlump(f)
242 
243  ! check if the solution cannot be accepted
244  IF ( ( beta < alpha) .OR. ( h < 0 ) .OR. ( u < 0 ) .OR. &
245  ( minval(f) < 0 ) ) THEN
246 
247  rk_fail = .true.
248 
249  END IF
250 
251  IF ( rk_fail ) THEN
252 
253  ! repeat the RK integration with a smaller integration step
254  r = r_old
255  dr = 0.5 * dr
256  f = f_stepold
257 
258  ELSE
259 
260  ! accept the solution and advance
261  f_oldold = f_stepold
262 
263  dr_old = dr
264 
265  ! check the error 4th-5th and compute the adaptive step
266  f_err(:) = dr * ( rhs(:) - rhs4(:) )
267 
268  err_check = maxval( abs(f_err) / ( eps_abs + eps_rel * abs(f) ) )
269 
270  dr = min( dr0 , dr/err_check**0.2d0 )
271 
272  CALL write_output
273 
274  IF ( ri .gt. 1.d0 .and. ri_old .lt. 1.d0) THEN
275 
276  WRITE(*,*) 'hydraulicjump'
277 
278  flow_regime = 3
279 
280  CALL write_dakota
281  EXIT main_loop
282 
283  ELSE
284 
285  IF ( ri_new < 1.d0 ) THEN
286 
287  flow_regime = 1
288 
289  ELSE
290 
291  flow_regime = 2
292 
293  END IF
294 
295  END IF
296 
297  IF ( ( (beta - alpha) < 1.d-5) .OR. ( dr .LE. 1.d-11 ) ) THEN
298 
299  ! exit condition
300  CALL write_dakota
301 
302  EXIT main_loop
303 
304  END IF
305 
306  END IF
307 
308  END DO main_loop
309 
310  ! ----------------------------------------------------
311  ! ... End of marching loop
312  ! ----------------------------------------------------
313  !
314 
315  RETURN
316 
317  END SUBROUTINE pdc
318 
319 END MODULE pdcflow
320 !----------------------------------------------------------------------
subroutine initialize_current
Initialising current This subroutine allocates conditions at flow source to those assigned in input f...
Definition: current.f90:76
subroutine rate(rhs_)
Right hand side equations This subroutine contains the right-hand side of the equations that are comp...
Definition: solver_flow.f90:99
subroutine initialize_particles
Allocating particles variables This subroutine allocates the variables defining the particle sediment...
Definition: particles.f90:147
subroutine marching(fold, fnew, rat, delta_r)
Marching r one step.
subroutine write_output
Definition: inpout.f90:276
subroutine write_dakota
Definition: inpout.f90:422
Current module This module contains descriptors for the initial conditions of the flow...
Definition: current.f90:7
Mixture module This module contains all the variables required for describing and calculating the cha...
Definition: mixture.f90:10
subroutine compute_mixture
Computing conditions within mixture This subroutine calculates the characteristics of the mixture by ...
Definition: mixture.f90:102
PDC flow model This module calls subroutines required from other modules for solving the model and de...
Definition: flow.f90:10
Solver Module This module contains the differential equations that are solved at each iteration...
Definition: solver_flow.f90:10
subroutine unlump(f_)
Unlumping variable Lumped variables defined in subroutine 'lump' are unlumped to calculate physical v...
subroutine lump(f_)
Lump variables Variables are grouped together to calculate the lumped variables.
Input/Output module.
Definition: inpout.f90:8
Particles module This module contains the procedures and the variables related to the solid particles...
Definition: particles.f90:6
subroutine pdc(run_name)
PDC run_name This subroutine calls all subroutines required from other modules for solving the model...
Definition: flow.f90:23
environment module This module contains all the variables related to the background environmental con...
Definition: environment.f90:8
subroutine zmet
Meteorological conditions This subroutine is used to calculate atmospheric density, alpha.
Definition: environment.f90:33