-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhydro_bc.f90
495 lines (399 loc) · 18.1 KB
/
hydro_bc.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
! ----------------------------------------------------------------
! file: hydro_bc.f90
! ----------------------------------------------------------------
! ----------------------------------------------------------------
! Battelle Memorial Institute
! Pacific Northwest Laboratory
! ----------------------------------------------------------------
! ----------------------------------------------------------------
! Created December 30, 2010 by William A. Perkins
! Last Change: 2014-04-24 13:05:55 d3g096
! ----------------------------------------------------------------
! ----------------------------------------------------------------
! MODULE hydro_bc_module
! ----------------------------------------------------------------
MODULE hydro_bc
USE utility
USE config
USE table_boundary_conditions
IMPLICIT NONE
CHARACTER (LEN=80), PRIVATE, SAVE :: rcsid = "$Id$"
! ----------------------------------------------------------------
! TYPE bc_spec_struct
! ----------------------------------------------------------------
TYPE bc_spec_struct
CHARACTER (LEN=10) :: bc_loc
CHARACTER (LEN=10) :: bc_type, bc_kind, bc_extent
INTEGER :: block, table_num != 0
INTEGER :: con_block, con_start_cell(max_cell_values), con_end_cell(max_cell_values)
INTEGER :: start_cell(max_cell_values), end_cell(max_cell_values)
INTEGER :: num_cell_pairs != 0
DOUBLE PRECISION, POINTER :: flux_area(:)
END TYPE bc_spec_struct
! ----------------------------------------------------------------
! block_bc_struct
! ----------------------------------------------------------------
TYPE block_bc_struct
INTEGER :: num_bc != 0
TYPE(bc_spec_struct) :: bc_spec(200)
END TYPE block_bc_struct
TYPE(block_bc_struct), ALLOCATABLE :: block_bc(:)
CHARACTER (LEN=80), PRIVATE :: bcspecs_name = "bcspecs.dat"
INTEGER, PARAMETER, PRIVATE :: bcspec_iounit = 18
CONTAINS
! ----------------------------------------------------------------
! SUBROUTINE allocate_block_bc
! ----------------------------------------------------------------
SUBROUTINE allocate_block_bc(max_blocks)
IMPLICIT NONE
INTEGER :: max_blocks, alloc_stat, i
ALLOCATE(block_bc(max_blocks), STAT = alloc_stat)
IF(alloc_stat /= 0)THEN
CALL error_message('allocation failed for the array of block bc ', fatal=.TRUE.)
END IF
CALL status_message('allocation successful for array of block bc')
block_bc%num_bc = 0
DO i=1,max_blocks
block_bc(i)%bc_spec%table_num = 0
block_bc(i)%bc_spec%num_cell_pairs = 0
END DO
END SUBROUTINE allocate_block_bc
!##########################################################################
SUBROUTINE read_bcspecs(max_blocks, xmax, ymax)
! reads the bc spec file
! format: block# bc_loc bc_type bc_kind bc_extent 'connect_block OR filename' 'cell pairs'
IMPLICIT NONE
INTEGER, INTENT(IN) :: max_blocks, xmax(:), ymax(:)
INTEGER :: junk1, block, num_bc, con_block, cells(2*max_cell_values) = -999
INTEGER :: table_count = 0, num_cells, num_cell_pairs
CHARACTER (LEN=10) :: junk_char1, junk_char2
CHARACTER (LEN=10) :: bc_loc, bc_type, bc_kind, bc_extent
CHARACTER (LEN=80) :: file_name
CHARACTER (LEN=1024) :: msg
INTEGER :: line, lerr, ierr, maxidx
INTEGER :: cmin, cmax, p
CALL open_existing(bcspecs_name, bcspec_iounit)
! first we need to count how many TABLE bc types
DO WHILE(.TRUE.)
READ(bcspec_iounit,*,END=100)junk1,junk_char1,junk_char2
SELECT CASE (junk_char2)
CASE ("TABLE", "SOURCE", "SINK")
max_tables = max_tables + 1
END SELECT
END DO
! now allocate the number of table bc structs that we need
100 CALL allocate_table_bc(max_tables)
! now start over to fill and parse
REWIND(bcspec_iounit)
line = 0
ierr = 0
DO WHILE(.TRUE.)
READ(bcspec_iounit,*,END=200)block, bc_loc, bc_type, bc_kind, bc_extent
line = line + 1
lerr = 0
block_bc(block)%num_bc = block_bc(block)%num_bc + 1
num_bc = block_bc(block)%num_bc
block_bc(block)%bc_spec(num_bc)%bc_loc = bc_loc
block_bc(block)%bc_spec(num_bc)%bc_type = bc_type
block_bc(block)%bc_spec(num_bc)%bc_kind = bc_kind
block_bc(block)%bc_spec(num_bc)%bc_extent = bc_extent
NULLIFY(block_bc(block)%bc_spec(num_bc)%flux_area)
! check block number
IF (block .GT. max_blocks .OR. block .LT. 1) THEN
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": block number out of range: ", block
CALL error_message(msg, fatal=.FALSE.)
ierr = ierr + lerr
CYCLE
END IF
block_bc(block)%bc_spec(num_bc)%block = block
! make sure we understand the BC
! location
SELECT CASE(bc_loc)
CASE ("US", "DS")
maxidx = ymax(block) - 1
CASE ("LB", "RB")
maxidx = xmax(block) - 1
CASE ("IN")
! decide maxidx below
CASE DEFAULT
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": ", TRIM(bc_loc), "?"
CALL error_message(msg, fatal=.FALSE.)
END SELECT
! make sure we understand the BC kind
SELECT CASE (bc_kind)
CASE ("FLUX", "VELO", "ELEV", "ELEVELO")
CASE ("UVEL", "VVEL")
CASE ("CELL")
CASE DEFAULT
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": ", TRIM(bc_kind), "?"
CALL error_message(msg, fatal=.FALSE.)
END SELECT
IF (lerr .EQ. 0) THEN
! reread BC specific information from the line
BACKSPACE(bcspec_iounit)
SELECT CASE(bc_type)
CASE("BLOCK")
SELECT CASE(bc_extent)
CASE("ALL")
READ(bcspec_iounit,*)block,bc_loc,bc_type,bc_kind,bc_extent,con_block
block_bc(block)%bc_spec(num_bc)%con_block = con_block
block_bc(block)%bc_spec(num_bc)%num_cell_pairs = 1
block_bc(block)%bc_spec(num_bc)%start_cell(1) = 1
block_bc(block)%bc_spec(num_bc)%end_cell(1) = maxidx
CASE("PART")
cells = -999
READ(bcspec_iounit,*)block,bc_loc,bc_type,bc_kind,bc_extent,con_block,cells(:)
block_bc(block)%bc_spec(num_bc)%con_block = con_block
CALL set_bc_part(bcspec_iounit, block_bc(block)%bc_spec(num_bc), &
&cells, maxidx, line, lerr)
! num_cells = COUNT(cells /= -999)
! num_cell_pairs = num_cells/2
! block_bc(block)%bc_spec(num_bc)%num_cell_pairs = num_cells/2
! block_bc(block)%bc_spec(num_bc)%start_cell(1:num_cell_pairs) = cells(1:num_cells:2)
! block_bc(block)%bc_spec(num_bc)%end_cell(1:num_cell_pairs) = cells(2:num_cells:2)
CASE DEFAULT
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": ", TRIM(bc_extent), "?"
CALL error_message(msg, fatal=.FALSE.)
READ (bcspec_iounit, *)
END SELECT
CASE("TABLE")
SELECT CASE(bc_extent)
CASE("ALL")
READ(bcspec_iounit,*)block,bc_loc,bc_type,bc_kind,bc_extent,file_name
table_count = table_count + 1 ! keep a running count of the number of tables
block_bc(block)%bc_spec(num_bc)%table_num = table_count
table_bc(table_count)%file_name = file_name ! associate file and table number
block_bc(block)%bc_spec(num_bc)%num_cell_pairs = 1
block_bc(block)%bc_spec(num_bc)%start_cell(1) = 1
block_bc(block)%bc_spec(num_bc)%end_cell(1) = maxidx
CASE("PART")
cells = -999
READ(bcspec_iounit,*)block,bc_loc,bc_type,bc_kind,bc_extent,file_name,cells(:)
table_count = table_count + 1 ! keep a running count of the number of tables
block_bc(block)%bc_spec(num_bc)%table_num = table_count
table_bc(table_count)%file_name = file_name ! associate file and table number
CALL set_bc_part(bcspec_iounit, block_bc(block)%bc_spec(num_bc), &
&cells, maxidx, line, lerr)
CASE DEFAULT
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": ", TRIM(bc_extent), "?"
CALL error_message(msg, fatal=.FALSE.)
READ (bcspec_iounit, *)
END SELECT
SELECT CASE (block_bc(block)%bc_spec(num_bc)%bc_kind)
CASE ("FLUX")
p = block_bc(block)%bc_spec(num_bc)%num_cell_pairs
cmin = MINVAL(block_bc(block)%bc_spec(num_bc)%start_cell(1:p))+1
cmax = MAXVAL(block_bc(block)%bc_spec(num_bc)%end_cell(1:p))+1
ALLOCATE(block_bc(block)%bc_spec(num_bc)%flux_area(cmin:cmax))
END SELECT
CASE ("SOURCE","SINK")
cells = -999
READ(bcspec_iounit,*)block,bc_loc,bc_type,bc_kind,bc_extent,file_name, cells
table_count = table_count + 1 ! keep a running count of the number of tables
block_bc(block)%bc_spec(num_bc)%table_num = table_count
table_bc(table_count)%file_name = file_name ! associate file and table number
SELECT CASE(bc_extent)
CASE ("PART")
CALL set_bc_area(block_bc(block)%bc_spec(num_bc), cells, &
&xmax(block) - 1, ymax(block) - 1, line, lerr)
CASE ("ALL")
block_bc(block)%bc_spec(num_bc)%start_cell(1) = 1
block_bc(block)%bc_spec(num_bc)%end_cell(1) = xmax(block) - 1
block_bc(block)%bc_spec(num_bc)%start_cell(2) = 1
block_bc(block)%bc_spec(num_bc)%end_cell(2) = ymax(block) - 1
CASE DEFAULT
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": ", TRIM(bc_extent), "?"
CALL error_message(msg, fatal=.FALSE.)
READ (bcspec_iounit, *)
END SELECT
CASE ("WALL")
cells = -999
READ(bcspec_iounit,*)block,bc_loc,bc_type,bc_kind,junk1,cells(:)
! the first number indicates the row
! (uvel) or column (vvel) cell
block_bc(block)%bc_spec(num_bc)%con_block = junk1
! the remaining numbers indicate the
! range of cells over which the wall
! is to be placed.
SELECT CASE (bc_kind)
CASE ("UVEL")
maxidx = ymax(block) - 1
IF (junk1 .GT. xmax(block) - 1) THEN
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": x (up/down) index out of range: ", junk1
CALL error_message(msg, fatal=.FALSE.)
END IF
CASE ("VVEL")
maxidx = xmax(block) - 1
IF (junk1 .GT. ymax(block) - 1) THEN
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": y (left/right) index out of range: ", junk1
CALL error_message(msg, fatal=.FALSE.)
END IF
CASE DEFAULT
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": this should not happen (fix me!)"
CALL error_message(msg, fatal=.FALSE.)
END SELECT
CALL set_bc_part(bcspec_iounit, block_bc(block)%bc_spec(num_bc), &
&cells, maxidx, line, lerr)
CASE ("DEAD")
! whatever is in bc_kind is not used
cells = -999
READ(bcspec_iounit,*)block,bc_loc,bc_type,bc_kind,cells(:)
!
! the dead zone is specified as a
! rectangle of cells: imin, jmin,
! imax, jmax (like src/sink)
CALL set_bc_area(block_bc(block)%bc_spec(num_bc), cells, &
&xmax(block) - 1, ymax(block) - 1, line, lerr)
do_rptdead = .TRUE.
CASE ("ZEROG")
! whatever is in bc_kind is ignored
SELECT CASE(bc_extent)
CASE("ALL")
READ(bcspec_iounit,*)block,bc_loc,bc_type,bc_kind,bc_extent
block_bc(block)%bc_spec(num_bc)%num_cell_pairs = 1
block_bc(block)%bc_spec(num_bc)%start_cell(1) = 1
block_bc(block)%bc_spec(num_bc)%end_cell(1) = maxidx
CASE("PART")
cells = -999
READ(bcspec_iounit,*)block,bc_loc,bc_type,bc_kind,bc_extent,cells(:)
CALL set_bc_part(bcspec_iounit, block_bc(block)%bc_spec(num_bc), &
&cells, maxidx, line, lerr)
CASE DEFAULT
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": ", TRIM(bc_extent), "?"
CALL error_message(msg, fatal=.FALSE.)
READ (bcspec_iounit, *)
END SELECT
CASE DEFAULT
lerr = lerr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": ", TRIM(bc_type), "?"
CALL error_message(msg, fatal=.FALSE.)
READ (bcspec_iounit, *)
END SELECT
END IF
ierr = ierr + lerr
END DO
200 CLOSE(bcspec_iounit)
IF (ierr .GT. 0) THEN
WRITE(msg, *) TRIM(bcspecs_name), ": ", ierr, " errors"
CALL error_message(msg, fatal=.TRUE.)
END IF
CALL status_message("done reading bc specifications file")
END SUBROUTINE read_bcspecs
! ----------------------------------------------------------------
! SUBROUTINE set_bc_part
! ----------------------------------------------------------------
SUBROUTINE set_bc_part(iounit, spec, cells, maxidx, line, ierr)
IMPLICIT NONE
INTEGER, INTENT(IN) :: iounit, cells(:), maxidx, line
TYPE (bc_spec_struct), INTENT(INOUT) :: spec
INTEGER, INTENT(INOUT) :: ierr
INTEGER :: num_cells, num_cell_pairs, i
CHARACTER (LEN=1024) :: msg
num_cells = COUNT(cells .NE. -999)
num_cell_pairs = num_cells/2
spec%num_cell_pairs = num_cell_pairs
spec%start_cell(1:num_cell_pairs) = cells(1:num_cells:2)
spec%end_cell(1:num_cell_pairs) = cells(2:num_cells:2)
! check the cell numbers
DO i = 1, spec%num_cell_pairs
IF (spec%start_cell(i) .LT. 1 .OR. spec%start_cell(i) .GT. maxidx) THEN
ierr = ierr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": start index ", spec%start_cell(i), ' out of range'
CALL error_message(msg, fatal=.FALSE.)
END IF
IF (spec%end_cell(i) .LT. 1 .OR. spec%end_cell(i) .GT. maxidx) THEN
ierr = ierr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": end index ", spec%end_cell(i), ' out of range'
CALL error_message(msg, fatal=.FALSE.)
END IF
END DO
END SUBROUTINE set_bc_part
! ----------------------------------------------------------------
! SUBROUTINE set_bc_area
! ----------------------------------------------------------------
SUBROUTINE set_bc_area(spec, cells, xmax, ymax, line, ierr)
IMPLICIT NONE
INTEGER, INTENT(IN) :: cells(:), xmax, ymax, line
TYPE (bc_spec_struct), INTENT(INOUT) :: spec
INTEGER, INTENT(INOUT) :: ierr
INTEGER :: num_cells, num_cell_pairs, i
CHARACTER (LEN=1024) :: msg
num_cells = COUNT(cells /= -999)
IF (num_cells .NE. 4) THEN
ierr = ierr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": four indices expected, got ", num_cells
CALL error_message(msg, fatal=.FALSE.)
ELSE
num_cell_pairs = num_cells/2
spec%num_cell_pairs = num_cells/2
spec%start_cell(1:num_cell_pairs) = cells(1:num_cells:2)
spec%end_cell(1:num_cell_pairs) = cells(2:num_cells:2)
IF (spec%start_cell(1) .LT. 1 .OR. &
&spec%start_cell(1) .GT. xmax) THEN
ierr = ierr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": minimum x index out of range: ", spec%start_cell(1)
CALL error_message(msg, fatal=.FALSE.)
END IF
IF (spec%end_cell(1) .LT. 1 .OR. &
&spec%end_cell(1) .GT. xmax) THEN
ierr = ierr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": maximum x index out of range: ", spec%end_cell(1)
CALL error_message(msg, fatal=.FALSE.)
END IF
IF (spec%end_cell(1) .LT. spec%start_cell(1)) THEN
ierr = ierr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": invalid x index range: ", spec%start_cell(1), " to ", &
&spec%end_cell(1)
CALL error_message(msg, fatal=.FALSE.)
END IF
IF (spec%start_cell(2) .LT. 1 .OR. &
&spec%start_cell(2) .GT. ymax) THEN
ierr = ierr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": minimum y index out of range: ", spec%start_cell(2)
CALL error_message(msg, fatal=.FALSE.)
END IF
IF (spec%end_cell(2) .LT. 1 .OR. &
&spec%end_cell(2) .GT. ymax) THEN
ierr = ierr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": maximum y index out of range: ", spec%end_cell(2)
CALL error_message(msg, fatal=.FALSE.)
END IF
IF (spec%end_cell(2) .LT. spec%start_cell(2)) THEN
ierr = ierr + 1
WRITE(msg, *) TRIM(bcspecs_name), ": error: line ", line, &
&": invalid y index range: ", spec%start_cell(2), " to ", &
&spec%end_cell(2)
CALL error_message(msg, fatal=.FALSE.)
END IF
END IF
END SUBROUTINE set_bc_area
END MODULE hydro_bc