-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathm_bubbles_EL.fpp
More file actions
2099 lines (1765 loc) · 96.5 KB
/
Copy pathm_bubbles_EL.fpp
File metadata and controls
2099 lines (1765 loc) · 96.5 KB
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!>
!! @file
!! @brief Contains module @ref m_bubbles_el "m_bubbles_EL"
#:include 'macros.fpp'
!> @brief Tracks Lagrangian bubbles and couples their dynamics to the Eulerian flow via volume averaging
module m_bubbles_EL
use m_global_parameters
use m_mpi_proxy
use m_bubbles_EL_kernels
use m_bubbles
use m_variables_conversion
use m_compile_specific
use m_boundary_common
use m_helper_basic
use m_sim_helpers
use m_helper
use m_mpi_common
use m_ibm
use m_finite_differences
use m_constants, only: time_stepper_rk1, time_stepper_rk2, time_stepper_rk3, precision_single
implicit none
! (nBub)
integer, allocatable, dimension(:,:) :: lag_id !< Global and local IDs
real(wp), allocatable, dimension(:) :: bub_R0 !< Initial bubble radius
real(wp), allocatable, dimension(:) :: Rmax_stats !< Maximum radius
real(wp), allocatable, dimension(:) :: Rmin_stats !< Minimum radius
$:GPU_DECLARE(create='[lag_id, bub_R0, Rmax_stats, Rmin_stats]')
real(wp), allocatable, dimension(:) :: gas_mg !< Bubble's gas mass
real(wp), allocatable, dimension(:) :: gas_betaT !< heatflux model (Preston et al., 2007)
real(wp), allocatable, dimension(:) :: gas_betaC !< massflux model (Preston et al., 2007)
real(wp), allocatable, dimension(:) :: bub_dphidt !< subgrid velocity potential (Maeda & Colonius, 2018)
$:GPU_DECLARE(create='[gas_mg, gas_betaT, gas_betaC, bub_dphidt]')
! (nBub, 1 -> actual val or 2 -> temp val)
real(wp), allocatable, dimension(:,:) :: gas_p !< Pressure in the bubble
real(wp), allocatable, dimension(:,:) :: gas_mv !< Vapor mass in the bubble
real(wp), allocatable, dimension(:,:) :: intfc_rad !< Bubble radius
real(wp), allocatable, dimension(:,:) :: intfc_vel !< Velocity of the bubble interface
$:GPU_DECLARE(create='[gas_p, gas_mv, intfc_rad, intfc_vel]')
! (nBub, 1-> x or 2->y or 3 ->z, 1 -> actual or 2 -> temporal val)
real(wp), allocatable, dimension(:,:,:) :: mtn_pos !< Bubble's position
real(wp), allocatable, dimension(:,:,:) :: mtn_posPrev !< Bubble's previous position
real(wp), allocatable, dimension(:,:,:) :: mtn_vel !< Bubble's velocity
real(wp), allocatable, dimension(:,:,:) :: mtn_s !< Bubble's computational cell position in real format
$:GPU_DECLARE(create='[mtn_pos, mtn_posPrev, mtn_vel, mtn_s]')
! (nBub, 1-> x or 2->y or 3 ->z, time-stage)
real(wp), allocatable, dimension(:,:) :: intfc_draddt !< Time derivative of bubble's radius
real(wp), allocatable, dimension(:,:) :: intfc_dveldt !< Time derivative of bubble's interface velocity
real(wp), allocatable, dimension(:,:) :: gas_dpdt !< Time derivative of gas pressure
real(wp), allocatable, dimension(:,:) :: gas_dmvdt !< Time derivative of the vapor mass in the bubble
real(wp), allocatable, dimension(:,:,:) :: mtn_dposdt !< Time derivative of the bubble's position
real(wp), allocatable, dimension(:,:,:) :: mtn_dveldt !< Time derivative of the bubble's velocity
$:GPU_DECLARE(create='[intfc_draddt, intfc_dveldt, gas_dpdt, gas_dmvdt, mtn_dposdt, mtn_dveldt]')
integer, private :: lag_num_ts !< Number of time stages in the time-stepping scheme
$:GPU_DECLARE(create='[lag_num_ts]')
real(wp) :: Rmax_glb, Rmin_glb !< Maximum and minimum bubbe size in the local domain
!> Projection of the lagrangian particles in the Eulerian framework
type(scalar_field), dimension(:), allocatable :: q_beta
type(scalar_field), dimension(:), allocatable :: kahan_comp !< Kahan compensation for q_beta accumulation
integer :: q_beta_idx !< Size of the q_beta vector field
$:GPU_DECLARE(create='[Rmax_glb, Rmin_glb, q_beta, kahan_comp, q_beta_idx]')
integer, parameter :: LAG_EVOL_ID = 11 ! File id for lag_bubbles_evol_*.dat
integer, parameter :: LAG_STATS_ID = 12 ! File id for stats_lag_bubbles_*.dat
integer, parameter :: LAG_VOID_ID = 13 ! File id for voidfraction.dat
integer, allocatable, dimension(:) :: keep_bubble
integer, allocatable, dimension(:,:) :: wrap_bubble_loc, wrap_bubble_dir
$:GPU_DECLARE(create='[keep_bubble]')
$:GPU_DECLARE(create='[wrap_bubble_loc, wrap_bubble_dir]')
contains
!> Initializes the lagrangian subgrid bubble solver
impure subroutine s_initialize_bubbles_EL_module(q_cons_vf, bc_type)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
integer :: nBubs_glb, i
! Setting number of time-stages for selected time-stepping scheme
lag_num_ts = time_stepper
! Allocate space for the Eulerian fields needed to map the effect of the bubbles
if (lag_params%solver_approach == 1) then
! One-way coupling
q_beta_idx = 3
else if (lag_params%solver_approach == 2) then
! Two-way coupling
q_beta_idx = 4
if (p == 0) then
! Subgrid noise model for 2D approximation
q_beta_idx = 6
end if
else
call s_mpi_abort('Please check the lag_params%solver_approach input')
end if
pcomm_coords(1)%beg = x_cb(-1)
pcomm_coords(1)%end = x_cb(m)
$:GPU_UPDATE(device='[pcomm_coords(1)]')
if (n > 0) then
pcomm_coords(2)%beg = y_cb(-1)
pcomm_coords(2)%end = y_cb(n)
$:GPU_UPDATE(device='[pcomm_coords(2)]')
if (p > 0) then
pcomm_coords(3)%beg = z_cb(-1)
pcomm_coords(3)%end = z_cb(p)
$:GPU_UPDATE(device='[pcomm_coords(3)]')
end if
end if
$:GPU_UPDATE(device='[lag_num_ts, q_beta_idx]')
@:ALLOCATE(q_beta(1:q_beta_idx))
if (lag_params%kahan_summation) then
@:ALLOCATE(kahan_comp(1:q_beta_idx))
end if
do i = 1, q_beta_idx
@:ALLOCATE(q_beta(i)%sf(idwbuff(1)%beg:idwbuff(1)%end, idwbuff(2)%beg:idwbuff(2)%end, idwbuff(3)%beg:idwbuff(3)%end))
@:ACC_SETUP_SFs(q_beta(i))
if (lag_params%kahan_summation) then
@:ALLOCATE(kahan_comp(i)%sf(idwbuff(1)%beg:idwbuff(1)%end, idwbuff(2)%beg:idwbuff(2)%end, &
& idwbuff(3)%beg:idwbuff(3)%end))
@:ACC_SETUP_SFs(kahan_comp(i))
end if
end do
! Allocating space for lagrangian variables
nBubs_glb = lag_params%nBubs_glb
@:ALLOCATE(bub_R0(1:nBubs_glb))
@:ALLOCATE(Rmax_stats(1:nBubs_glb))
@:ALLOCATE(Rmin_stats(1:nBubs_glb))
@:ALLOCATE(gas_mg(1:nBubs_glb))
@:ALLOCATE(gas_betaT(1:nBubs_glb))
@:ALLOCATE(gas_betaC(1:nBubs_glb))
@:ALLOCATE(bub_dphidt(1:nBubs_glb))
@:ALLOCATE(lag_id(1:nBubs_glb, 1:2))
@:ALLOCATE(gas_p(1:nBubs_glb, 1:2))
@:ALLOCATE(gas_mv(1:nBubs_glb, 1:2))
@:ALLOCATE(intfc_rad(1:nBubs_glb, 1:2))
@:ALLOCATE(intfc_vel(1:nBubs_glb, 1:2))
@:ALLOCATE(mtn_pos(1:nBubs_glb, 1:3, 1:2))
@:ALLOCATE(mtn_posPrev(1:nBubs_glb, 1:3, 1:2))
@:ALLOCATE(mtn_vel(1:nBubs_glb, 1:3, 1:2))
@:ALLOCATE(mtn_s(1:nBubs_glb, 1:3, 1:2))
@:ALLOCATE(intfc_draddt(1:nBubs_glb, 1:lag_num_ts))
@:ALLOCATE(intfc_dveldt(1:nBubs_glb, 1:lag_num_ts))
@:ALLOCATE(gas_dpdt(1:nBubs_glb, 1:lag_num_ts))
@:ALLOCATE(gas_dmvdt(1:nBubs_glb, 1:lag_num_ts))
@:ALLOCATE(mtn_dposdt(1:nBubs_glb, 1:3, 1:lag_num_ts))
@:ALLOCATE(mtn_dveldt(1:nBubs_glb, 1:3, 1:lag_num_ts))
@:ALLOCATE(keep_bubble(1:nBubs_glb))
@:ALLOCATE(wrap_bubble_loc(1:nBubs_glb, 1:num_dims), wrap_bubble_dir(1:nBubs_glb, 1:num_dims))
if (adap_dt .and. f_is_default(adap_dt_tol)) adap_dt_tol = dflt_adap_dt_tol
if (num_procs > 1) call s_initialize_particles_mpi(lag_num_ts)
! Starting bubbles
if (lag_params%write_void_evol) call s_open_void_evol
if (lag_params%write_bubbles) call s_open_lag_bubble_evol()
if (lag_params%write_bubbles_stats) call s_open_lag_bubble_stats()
if (lag_params%vel_model > 0) then
moving_lag_bubbles = .true.
lag_pressure_force = lag_params%pressure_force
lag_gravity_force = lag_params%gravity_force
lag_vel_model = lag_params%vel_model
lag_drag_model = lag_params%drag_model
end if
$:GPU_UPDATE(device='[moving_lag_bubbles, lag_pressure_force, lag_gravity_force, lag_vel_model, lag_drag_model]')
if (lag_params%vel_model > 0 .and. lag_params%pressure_force) then
@:ALLOCATE(grad_p_x(0:m, 0:n, 0:p))
! s_compute_finite_difference_coefficients always extends fd_number beyond the interior on each side
@:ALLOCATE(fd_coeff_x_pgrad(-fd_number:fd_number,-fd_number:m + fd_number))
call s_compute_finite_difference_coefficients(m, x_cc, fd_coeff_x_pgrad, buff_size, fd_number, fd_order)
$:GPU_UPDATE(device='[fd_coeff_x_pgrad]')
if (n > 0) then
@:ALLOCATE(grad_p_y(0:m, 0:n, 0:p))
@:ALLOCATE(fd_coeff_y_pgrad(-fd_number:fd_number,-fd_number:n + fd_number))
call s_compute_finite_difference_coefficients(n, y_cc, fd_coeff_y_pgrad, buff_size, fd_number, fd_order)
$:GPU_UPDATE(device='[fd_coeff_y_pgrad]')
end if
if (p > 0) then
@:ALLOCATE(grad_p_z(0:m, 0:n, 0:p))
@:ALLOCATE(fd_coeff_z_pgrad(-fd_number:fd_number,-fd_number:p + fd_number))
call s_compute_finite_difference_coefficients(p, z_cc, fd_coeff_z_pgrad, buff_size, fd_number, fd_order)
$:GPU_UPDATE(device='[fd_coeff_z_pgrad]')
end if
end if
@:ALLOCATE(cell_list_start(0:m, 0:n, 0:p))
@:ALLOCATE(cell_list_count(0:m, 0:n, 0:p))
@:ALLOCATE(cell_list_idx(1:lag_params%nBubs_glb))
call s_read_input_bubbles(q_cons_vf, bc_type)
end subroutine s_initialize_bubbles_EL_module
!> Read initial bubble data from input files
impure subroutine s_read_input_bubbles(q_cons_vf, bc_type)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
real(wp), dimension(8) :: inputBubble
real(wp) :: qtime
integer :: id, bub_id, save_count
integer :: i, ios
logical :: file_exist, indomain
integer, dimension(3) :: cell
character(LEN=path_len + 2*name_len) :: path_D_dir
! Initialize number of particles
bub_id = 0
id = 0
! Read the input lag_bubble file or restart point
if (cfl_dt) then
save_count = n_start
qtime = n_start*t_save
else
save_count = t_step_start
qtime = t_step_start*dt
end if
if (save_count == 0) then
if (proc_rank == 0) print *, 'Reading lagrange bubbles input file.'
call my_inquire(trim(lag_params%input_path), file_exist)
if (file_exist) then
open (94, file=trim(lag_params%input_path), form='formatted', iostat=ios)
do while (ios == 0)
read (94, *, iostat=ios) (inputBubble(i), i=1, 8)
if (ios /= 0) cycle
indomain = particle_in_domain_physical(inputBubble(1:3))
id = id + 1
if (id > lag_params%nBubs_glb .and. proc_rank == 0) then
call s_mpi_abort("Current number of bubbles is larger than nBubs_glb")
end if
if (indomain) then
bub_id = bub_id + 1
call s_add_bubbles(inputBubble, q_cons_vf, bub_id)
lag_id(bub_id, 1) = id ! global ID
lag_id(bub_id, 2) = bub_id ! local ID
n_el_bubs_loc = bub_id ! local number of bubbles
end if
end do
close (94)
else
call s_mpi_abort("Initialize the lagrange bubbles in " // trim(lag_params%input_path))
end if
else
if (proc_rank == 0) print *, 'Restarting lagrange bubbles at save_count: ', save_count
call s_restart_bubbles(bub_id, save_count)
end if
print *, " Lagrange bubbles running, in proc", proc_rank, "number:", bub_id, "/", id
if (num_procs > 1) then
call s_mpi_reduce_int_sum(n_el_bubs_loc, n_el_bubs_glb)
else
n_el_bubs_glb = n_el_bubs_loc
end if
if (proc_rank == 0) then
if (n_el_bubs_glb == 0) call s_mpi_abort('No bubbles in the domain. Check ' // trim(lag_params%input_path))
end if
$:GPU_UPDATE(device='[bubbles_lagrange, lag_params]')
$:GPU_UPDATE(device='[lag_id, bub_R0, Rmax_stats, Rmin_stats, gas_mg, gas_betaT, gas_betaC, bub_dphidt, gas_p, gas_mv, &
& intfc_rad, intfc_vel, mtn_pos, mtn_posPrev, mtn_vel, mtn_s, intfc_draddt, intfc_dveldt, gas_dpdt, &
& gas_dmvdt, mtn_dposdt, mtn_dveldt, n_el_bubs_loc]')
Rmax_glb = min(dflt_real, -dflt_real)
Rmin_glb = max(dflt_real, -dflt_real)
$:GPU_UPDATE(device='[Rmax_glb, Rmin_glb]')
$:GPU_UPDATE(device='[dx, dy, dz, x_cb, x_cc, y_cb, y_cc, z_cb, z_cc]')
! Populate temporal variables
call s_transfer_data_to_tmp()
call s_smear_voidfraction(bc_type)
if (save_count == 0) then
! Create ./D directory
if (proc_rank == 0) then
write (path_D_dir, '(A,I0,A,I0)') trim(case_dir) // '/D'
call my_inquire(trim(path_D_dir), file_exist)
if (.not. file_exist) call s_create_directory(trim(path_D_dir))
end if
call s_mpi_barrier()
call s_write_restart_lag_bubbles(save_count) ! Needed for post_processing
if (lag_params%write_void_evol) call s_write_void_evol(qtime)
end if
if (lag_params%write_bubbles) call s_write_lag_bubble_evol(qtime)
end subroutine s_read_input_bubbles
!> Add a new bubble from input data for a fresh start
impure subroutine s_add_bubbles(inputBubble, q_cons_vf, bub_id)
type(scalar_field), dimension(sys_size), intent(in) :: q_cons_vf
real(wp), dimension(8), intent(in) :: inputBubble
integer, intent(in) :: bub_id
integer :: i
real(wp) :: pliq, volparticle, concvap, totalmass, kparticle, cpparticle
real(wp) :: omegaN_local, PeG, PeT, rhol, qv, gamma, pi_inf, dynP
integer, dimension(3) :: cell
real(wp), dimension(2) :: Re
real(wp) :: massflag, heatflag, Re_trans, Im_trans
massflag = 0._wp
heatflag = 0._wp
if (lag_params%massTransfer_model) massflag = 1._wp
if (lag_params%heatTransfer_model) heatflag = 1._wp
bub_R0(bub_id) = inputBubble(7)
Rmax_stats(bub_id) = min(dflt_real, -dflt_real)
Rmin_stats(bub_id) = max(dflt_real, -dflt_real)
bub_dphidt(bub_id) = 0._wp
intfc_rad(bub_id, 1) = inputBubble(7)
intfc_vel(bub_id, 1) = inputBubble(8)
mtn_pos(bub_id,1:3,1) = inputBubble(1:3)
mtn_posPrev(bub_id,1:3,1) = mtn_pos(bub_id,1:3,1)
mtn_vel(bub_id,1:3,1) = inputBubble(4:6)
if (cyl_coord .and. p == 0) then
mtn_pos(bub_id, 2, 1) = sqrt(mtn_pos(bub_id, 2, 1)**2._wp + mtn_pos(bub_id, 3, 1)**2._wp)
! Storing azimuthal angle (-Pi to Pi)) into the third coordinate variable
mtn_pos(bub_id, 3, 1) = atan2(inputBubble(3), inputBubble(2))
mtn_posPrev(bub_id,1:3,1) = mtn_pos(bub_id,1:3,1)
end if
cell = fd_number - buff_size
call s_locate_cell(mtn_pos(bub_id,1:3,1), cell, mtn_s(bub_id,1:3,1))
! Check if the bubble is located in the ghost cell of a symmetric, or wall boundary
if ((any(bc_x%beg == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, &
& BC_NO_SLIP_WALL/)) .and. cell(1) < 0) .or. (any(bc_x%end == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, &
& BC_NO_SLIP_WALL/)) .and. cell(1) > m) .or. (any(bc_y%beg == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, &
& BC_NO_SLIP_WALL/)) .and. cell(2) < 0) .or. (any(bc_y%end == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, &
& BC_NO_SLIP_WALL/)) .and. cell(2) > n)) then
call s_mpi_abort("Lagrange bubble is in the ghost cells of a symmetric or wall boundary.")
end if
if (p > 0) then
if ((any(bc_z%beg == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, &
& BC_NO_SLIP_WALL/)) .and. cell(3) < 0) .or. (any(bc_z%end == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, &
& BC_NO_SLIP_WALL/)) .and. cell(3) > p)) then
call s_mpi_abort("Lagrange bubble is in the ghost cells of a symmetric or wall boundary.")
end if
end if
call s_convert_to_mixture_variables(q_cons_vf, cell(1), cell(2), cell(3), rhol, gamma, pi_inf, qv, Re)
dynP = 0._wp
do i = 1, num_dims
dynP = dynP + 0.5_wp*q_cons_vf(eqn_idx%cont%end + i)%sf(cell(1), cell(2), cell(3))**2/rhol
end do
pliq = f_pressure(q_cons_vf(eqn_idx%E)%sf(cell(1), cell(2), cell(3)) - dynP, gamma, pi_inf, qv)
if (pliq < 0) print *, "Negative pressure", proc_rank, q_cons_vf(eqn_idx%E)%sf(cell(1), cell(2), cell(3)), pi_inf, gamma, &
& pliq, cell, dynP
! Initial particle pressure
gas_p(bub_id, 1) = pliq + 2._wp*(1._wp/Web)/bub_R0(bub_id)
! Initial particle mass
volparticle = 4._wp/3._wp*pi*bub_R0(bub_id)**3._wp ! volume
gas_mv(bub_id, 1) = pv*volparticle*(1._wp/(R_v*Tw))*(massflag) ! vapermass
gas_mg(bub_id) = (gas_p(bub_id, 1) - pv*(massflag))*volparticle*(1._wp/(R_g*Tw)) ! gasmass
if (gas_mg(bub_id) <= 0._wp) then
call s_mpi_abort("The initial mass of gas inside the bubble is negative. Check the initial conditions.")
end if
totalmass = gas_mg(bub_id) + gas_mv(bub_id, 1) ! totalmass
! Bubble natural frequency
concvap = gas_mv(bub_id, 1)/(gas_mv(bub_id, 1) + gas_mg(bub_id))
omegaN_local = (3._wp*(gas_p(bub_id, 1) - pv*(massflag)) + 4._wp*(1._wp/Web)/bub_R0(bub_id))/rhol
if (pv*(massflag) > gas_p(bub_id, 1)) then
call s_mpi_abort("Lagrange bubble initially located in a region with pressure below the vapor pressure.")
end if
omegaN_local = sqrt(omegaN_local/bub_R0(bub_id)**2._wp)
cpparticle = concvap*cp_v + (1._wp - concvap)*cp_g
kparticle = concvap*k_vl + (1._wp - concvap)*k_gl
! Mass and heat transfer coefficients (based on Preston 2007)
PeT = totalmass/volparticle*cpparticle*bub_R0(bub_id)**2._wp*omegaN_local/kparticle
call s_transcoeff(1._wp, PeT, Re_trans, Im_trans)
gas_betaT(bub_id) = Re_trans*(heatflag)*kparticle
PeG = bub_R0(bub_id)**2._wp*omegaN_local/vd
call s_transcoeff(1._wp, PeG, Re_trans, Im_trans)
gas_betaC(bub_id) = Re_trans*(massflag)*vd
if (gas_mg(bub_id) <= 0._wp) then
call s_mpi_abort("Negative gas mass in the bubble, check if the bubble is in the domain.")
end if
end subroutine s_add_bubbles
!> Restore bubble data from a restart file
impure subroutine s_restart_bubbles(bub_id, save_count)
integer, intent(inout) :: bub_id, save_count
character(LEN=path_len + 2*name_len) :: file_loc
real(wp) :: file_time, file_dt
integer :: file_num_procs, file_tot_part, tot_part
#ifdef MFC_MPI
real(wp), dimension(20) :: inputvals
integer, dimension(MPI_STATUS_SIZE) :: status
integer(kind=MPI_OFFSET_KIND) :: disp
integer :: view
integer, dimension(3) :: cell
logical :: indomain, particle_file, file_exist
integer, dimension(2) :: gsizes, lsizes, start_idx_part
integer :: ifile, ierr, tot_data, id
integer :: i
integer, dimension(:), allocatable :: proc_bubble_counts
real(wp), dimension(1:1,1:lag_io_vars) :: dummy
dummy = 0._wp
! Construct file path
write (file_loc, '(A,I0,A)') 'lag_bubbles_', save_count, '.dat'
file_loc = trim(case_dir) // '/restart_data' // trim(mpiiofs) // trim(file_loc)
! Check if file exists
inquire (FILE=trim(file_loc), EXIST=file_exist)
if (.not. file_exist) then
call s_mpi_abort('Restart file ' // trim(file_loc) // ' does not exist!')
end if
if (.not. parallel_io) return
if (proc_rank == 0) then
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
call MPI_FILE_READ(ifile, file_tot_part, 1, MPI_INTEGER, status, ierr)
call MPI_FILE_READ(ifile, file_time, 1, mpi_p, status, ierr)
call MPI_FILE_READ(ifile, file_dt, 1, mpi_p, status, ierr)
call MPI_FILE_READ(ifile, file_num_procs, 1, MPI_INTEGER, status, ierr)
call MPI_FILE_CLOSE(ifile, ierr)
end if
call MPI_BCAST(file_tot_part, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
call MPI_BCAST(file_time, 1, mpi_p, 0, MPI_COMM_WORLD, ierr)
call MPI_BCAST(file_dt, 1, mpi_p, 0, MPI_COMM_WORLD, ierr)
call MPI_BCAST(file_num_procs, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
allocate (proc_bubble_counts(file_num_procs))
if (proc_rank == 0) then
call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
! Skip to processor counts position
disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs), MPI_OFFSET_KIND)
call MPI_FILE_SEEK(ifile, disp, MPI_SEEK_SET, ierr)
call MPI_FILE_READ(ifile, proc_bubble_counts, file_num_procs, MPI_INTEGER, status, ierr)
call MPI_FILE_CLOSE(ifile, ierr)
end if
call MPI_BCAST(proc_bubble_counts, file_num_procs, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
! Set time variables from file
mytime = file_time
dt = file_dt
bub_id = proc_bubble_counts(proc_rank + 1)
start_idx_part(1) = 0
do i = 1, proc_rank
start_idx_part(1) = start_idx_part(1) + proc_bubble_counts(i)
end do
start_idx_part(2) = 0
lsizes(1) = bub_id
lsizes(2) = lag_io_vars
gsizes(1) = file_tot_part
gsizes(2) = lag_io_vars
if (bub_id > 0) then
allocate (MPI_IO_DATA_lag_bubbles(bub_id,1:lag_io_vars))
call MPI_TYPE_CREATE_SUBARRAY(2, gsizes, lsizes, start_idx_part, MPI_ORDER_FORTRAN, mpi_p, view, ierr)
call MPI_TYPE_COMMIT(view, ierr)
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
! Skip extended header
disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs) &
& + file_num_procs*sizeof(proc_bubble_counts(1)), MPI_OFFSET_KIND)
call MPI_FILE_SET_VIEW(ifile, disp, mpi_p, view, 'native', mpi_info_int, ierr)
call MPI_FILE_READ_ALL(ifile, MPI_IO_DATA_lag_bubbles, lag_io_vars*bub_id, mpi_p, status, ierr)
call MPI_FILE_CLOSE(ifile, ierr)
call MPI_TYPE_FREE(view, ierr)
n_el_bubs_loc = bub_id
do i = 1, bub_id
lag_id(i, 1) = int(MPI_IO_DATA_lag_bubbles(i, 1))
mtn_pos(i,1:3,1) = MPI_IO_DATA_lag_bubbles(i,2:4)
mtn_posPrev(i,1:3,1) = MPI_IO_DATA_lag_bubbles(i,5:7)
mtn_vel(i,1:3,1) = MPI_IO_DATA_lag_bubbles(i,8:10)
intfc_rad(i, 1) = MPI_IO_DATA_lag_bubbles(i, 11)
intfc_vel(i, 1) = MPI_IO_DATA_lag_bubbles(i, 12)
bub_R0(i) = MPI_IO_DATA_lag_bubbles(i, 13)
Rmax_stats(i) = MPI_IO_DATA_lag_bubbles(i, 14)
Rmin_stats(i) = MPI_IO_DATA_lag_bubbles(i, 15)
bub_dphidt(i) = MPI_IO_DATA_lag_bubbles(i, 16)
gas_p(i, 1) = MPI_IO_DATA_lag_bubbles(i, 17)
gas_mv(i, 1) = MPI_IO_DATA_lag_bubbles(i, 18)
gas_mg(i) = MPI_IO_DATA_lag_bubbles(i, 19)
gas_betaT(i) = MPI_IO_DATA_lag_bubbles(i, 20)
gas_betaC(i) = MPI_IO_DATA_lag_bubbles(i, 21)
cell = -buff_size
call s_locate_cell(mtn_pos(i,1:3,1), cell, mtn_s(i,1:3,1))
end do
deallocate (MPI_IO_DATA_lag_bubbles)
else
n_el_bubs_loc = 0
call MPI_TYPE_CONTIGUOUS(0, mpi_p, view, ierr)
call MPI_TYPE_COMMIT(view, ierr)
call MPI_FILE_OPEN(MPI_COMM_WORLD, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
! Skip extended header
disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs) &
& + file_num_procs*sizeof(proc_bubble_counts(1)), MPI_OFFSET_KIND)
call MPI_FILE_SET_VIEW(ifile, disp, mpi_p, view, 'native', mpi_info_int, ierr)
call MPI_FILE_READ_ALL(ifile, dummy, 0, mpi_p, status, ierr)
call MPI_FILE_CLOSE(ifile, ierr)
call MPI_TYPE_FREE(view, ierr)
end if
if (proc_rank == 0) then
write (*, '(A,I0,A,I0)') 'Read ', file_tot_part, ' particles from restart file at t_step = ', save_count
write (*, '(A,E15.7,A,E15.7)') 'Restart time = ', mytime, ', dt = ', dt
end if
deallocate (proc_bubble_counts)
#endif
end subroutine s_restart_bubbles
!> Contains the bubble dynamics subroutines.
subroutine s_compute_bubble_EL_dynamics(q_prim_vf, bc_type, stage)
type(scalar_field), dimension(sys_size), intent(inout) :: q_prim_vf
type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
integer, intent(in) :: stage
real(wp) :: myVapFlux
real(wp) :: preterm1, term2, paux, pint, Romega, term1_fac
real(wp) :: myR_m, mygamma_m, myPb, myMass_n, myMass_v
real(wp) :: myR, myV, myBeta_c, myBeta_t, myR0, myPbdot, myMvdot
real(wp) :: myPinf, aux1, aux2, myCson, myRho
real(wp), dimension(3) :: myPos, myVel
real(wp) :: gamma, pi_inf, qv, f_b, myRe
#:if not MFC_CASE_OPTIMIZATION and USING_AMD
real(wp), dimension(3) :: myalpha_rho, myalpha
#:else
real(wp), dimension(num_fluids) :: myalpha_rho, myalpha
#:endif
real(wp), dimension(2) :: Re
integer, dimension(3) :: cell
integer :: adap_dt_stop_sum, adap_dt_stop !< Fail-safe exit if max iteration count reached
real(wp) :: dmalf, dmntait, dmBtait, dm_bub_adv_src, dm_divu !< Dummy variables for unified subgrid bubble subroutines
integer :: k, l
! Subgrid p_inf model based on Maeda and Colonius (2018).
if (lag_params%pressure_corrector) then
call nvtxStartRange("LAGRANGE-BUBBLE-PINF-CORRECTION")
! Calculate velocity potentials (valid for one bubble per cell)
$:GPU_PARALLEL_LOOP(private='[k, cell, paux, preterm1, term2, Romega, myR0, myR, myV, myPb, pint, term1_fac]')
do k = 1, n_el_bubs_loc
call s_get_pinf(k, q_prim_vf, 2, paux, cell, preterm1, term2, Romega)
myR0 = bub_R0(k)
myR = intfc_rad(k, 2)
myV = intfc_vel(k, 2)
myPb = gas_p(k, 2)
pint = f_cpbw_KM(myR0, myR, myV, myPb)
pint = pint + 0.5_wp*myV**2._wp
if (lag_params%cluster_type == 2) then
bub_dphidt(k) = (paux - pint) + term2
! Accounting for the potential induced by the bubble averaged over the control volume Note that this is based on
! the incompressible flow assumption near the bubble.
term1_fac = 3._wp/2._wp*(myR*(Romega**2._wp - myR**2._wp))/(Romega**3._wp - myR**3._wp)
bub_dphidt(k) = bub_dphidt(k)/(1._wp - term1_fac)
end if
end do
$:END_GPU_PARALLEL_LOOP()
call nvtxEndRange()
end if
! Precompute cell-centered pressure gradients for translational motion
if (moving_lag_bubbles .and. lag_pressure_force) then
call nvtxStartRange("LAGRANGE-BUBBLE-PRESSURE-GRADIENT")
call s_compute_pressure_gradients(q_prim_vf)
call nvtxEndRange()
end if
call nvtxStartRange("LAGRANGE-BUBBLE-DYNAMICS")
! Radial motion model
adap_dt_stop_sum = 0
$:GPU_PARALLEL_LOOP(private='[k, myalpha_rho, myalpha, Re, cell, myVapFlux, preterm1, term2, paux, pint, Romega, &
& term1_fac, myR_m, mygamma_m, myPb, myMass_n, myMass_v, myR, myV, myBeta_c, myBeta_t, myR0, myPbdot, &
& myMvdot, myPinf, aux1, aux2, myCson, myRho, gamma, pi_inf, qv, dmalf, dmntait, dmBtait, &
& dm_bub_adv_src, dm_divu, adap_dt_stop, myPos, myVel]', copy='[adap_dt_stop_sum]',copyin='[stage]')
do k = 1, n_el_bubs_loc
! Keller-Miksis model
! Current bubble state
myPb = gas_p(k, 2)
myMass_n = gas_mg(k)
myMass_v = gas_mv(k, 2)
myR = intfc_rad(k, 2)
myV = intfc_vel(k, 2)
myBeta_c = gas_betaC(k)
myBeta_t = gas_betaT(k)
myR0 = bub_R0(k)
myPos = mtn_pos(k,:,2)
myVel = mtn_vel(k,:,2)
! Vapor and heat fluxes
call s_vflux(myR, myV, myPb, myMass_v, k, myVapFlux, myMass_n, myBeta_c, myR_m, mygamma_m)
myPbdot = f_bpres_dot(myVapFlux, myR, myV, myPb, myMass_v, k, myBeta_t, myR_m, mygamma_m)
myMvdot = 4._wp*pi*myR**2._wp*myVapFlux
! Obtaining driving pressure
call s_get_pinf(k, q_prim_vf, 1, myPinf, cell, aux1, aux2)
! Obtain liquid density and computing speed of sound from pinf
call s_compute_species_fraction(q_prim_vf, cell(1), cell(2), cell(3), myalpha_rho, myalpha)
call s_convert_species_to_mixture_variables_kernel(myRho, gamma, pi_inf, qv, myalpha, myalpha_rho, Re)
myCson = sqrt(f_bulk_modulus(myPinf, gamma, pi_inf)/myRho)
! Adaptive time stepping
adap_dt_stop = 0
if (adap_dt) then
mtn_posPrev(k,:,1) = myPos
myRe = Re(1)
adap_dt_stop = f_advance_step(myRho, myPinf, myR, myV, myR0, myPb, myPbdot, dmalf, dmntait, dmBtait, &
& dm_bub_adv_src, dm_divu, k, myMass_v, myMass_n, myBeta_c, myBeta_t, myCson, myRe, &
& myPos, myVel, cell, q_prim_vf)
! Update bubble state
intfc_rad(k, 1) = myR
intfc_vel(k, 1) = myV
gas_p(k, 1) = myPb
gas_mv(k, 1) = myMass_v
mtn_pos(k,:,1) = myPos
mtn_vel(k,:,1) = myVel
else
! Radial acceleration from bubble models
intfc_dveldt(k, stage) = f_rddot(myRho, myPinf, myR, myV, myR0, myPb, myPbdot, dmalf, dmntait, dmBtait, &
& dm_bub_adv_src, dm_divu, myCson)
intfc_draddt(k, stage) = myV
gas_dmvdt(k, stage) = myMvdot
gas_dpdt(k, stage) = myPbdot
if (moving_lag_bubbles) then
do l = 1, num_dims
mtn_dposdt(k, l, stage) = 0._wp
mtn_dveldt(k, l, stage) = 0._wp
select case (lag_vel_model)
case (1)
mtn_dposdt(k, l, stage) = f_interpolate_velocity(myPos(l), cell, l, q_prim_vf)
mtn_dveldt(k, l, stage) = 0._wp
mtn_vel(k, l, 1) = mtn_dposdt(k, l, stage)
case (2)
mtn_dposdt(k, l, stage) = myVel(l)
f_b = f_get_bubble_force(myPos(l), myR, myV, myVel(l), myMass_n, myMass_v, Re(1), myRho, cell, l, &
& q_prim_vf)
mtn_dveldt(k, l, stage) = f_b/(myMass_n + myMass_v)
case default
mtn_dposdt(k, l, stage) = 0._wp
mtn_dveldt(k, l, stage) = 0._wp
end select
end do
end if
end if
$:GPU_ATOMIC(atomic='update')
adap_dt_stop_sum = adap_dt_stop_sum + adap_dt_stop
end do
$:END_GPU_PARALLEL_LOOP()
call nvtxEndRange
if (adap_dt .and. adap_dt_stop_sum > 0) call s_mpi_abort("Adaptive time stepping failed to converge.")
if (adap_dt) then
call s_transfer_data_to_tmp()
if (moving_lag_bubbles) call s_enforce_EL_bubbles_boundary_conditions(q_prim_vf)
call s_smear_voidfraction(bc_type)
end if
end subroutine s_compute_bubble_EL_dynamics
!> Compute the Lagrangian bubble source terms and add them to the RHS
subroutine s_compute_bubbles_EL_source(q_cons_vf, q_prim_vf, rhs_vf)
type(scalar_field), dimension(sys_size), intent(inout) :: q_cons_vf
type(scalar_field), dimension(sys_size), intent(inout) :: q_prim_vf
type(scalar_field), dimension(sys_size), intent(inout) :: rhs_vf
integer :: i, j, k, l
call nvtxStartRange("LAGRANGE-BUBBLE-EL-SOURCE")
! (q / (1 - beta)) * d(beta)/dt source
if (lag_params%cluster_type >= 4) then
$:GPU_PARALLEL_LOOP(private='[i, j, k, l]', collapse=4)
do k = idwint(3)%beg, idwint(3)%end
do j = idwint(2)%beg, idwint(2)%end
do i = idwint(1)%beg, idwint(1)%end
do l = 1, eqn_idx%E
if (q_beta(1)%sf(i, j, k) > (1._wp - lag_params%valmaxvoid)) then
rhs_vf(l)%sf(i, j, k) = rhs_vf(l)%sf(i, j, k) + q_cons_vf(l)%sf(i, j, k)*(q_beta(2)%sf(i, j, &
& k) + q_beta(5)%sf(i, j, k))
end if
end do
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
else
$:GPU_PARALLEL_LOOP(private='[i, j, k, l]', collapse=4)
do k = idwint(3)%beg, idwint(3)%end
do j = idwint(2)%beg, idwint(2)%end
do i = idwint(1)%beg, idwint(1)%end
do l = 1, eqn_idx%E
if (q_beta(1)%sf(i, j, k) > (1._wp - lag_params%valmaxvoid)) then
rhs_vf(l)%sf(i, j, k) = rhs_vf(l)%sf(i, j, k) + (q_cons_vf(l)%sf(i, j, k)/q_beta(1)%sf(i, j, &
& k))*q_beta(2)%sf(i, j, k)
end if
end do
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
end if
do l = 1, num_dims
call s_gradient_dir(q_prim_vf(eqn_idx%E)%sf, q_beta(3)%sf, l)
! (q / (1 - beta)) * d(beta)/dt source
$:GPU_PARALLEL_LOOP(private='[i, j, k]', collapse=3)
do k = idwint(3)%beg, idwint(3)%end
do j = idwint(2)%beg, idwint(2)%end
do i = idwint(1)%beg, idwint(1)%end
if (q_beta(1)%sf(i, j, k) > (1._wp - lag_params%valmaxvoid)) then
rhs_vf(eqn_idx%cont%end + l)%sf(i, j, k) = rhs_vf(eqn_idx%cont%end + l)%sf(i, j, &
& k) - (1._wp - q_beta(1)%sf(i, j, k))/q_beta(1)%sf(i, j, k)*q_beta(3)%sf(i, j, k)
end if
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
! source in energy
$:GPU_PARALLEL_LOOP(private='[i, j, k]', collapse=3)
do k = idwbuff(3)%beg, idwbuff(3)%end
do j = idwbuff(2)%beg, idwbuff(2)%end
do i = idwbuff(1)%beg, idwbuff(1)%end
q_beta(3)%sf(i, j, k) = q_prim_vf(eqn_idx%E)%sf(i, j, k)*q_prim_vf(eqn_idx%cont%end + l)%sf(i, j, k)
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
call s_gradient_dir(q_beta(3)%sf, q_beta(4)%sf, l)
! (beta / (1 - beta)) * d(Pu)/dl source
$:GPU_PARALLEL_LOOP(private='[i, j, k]', collapse=3)
do k = idwint(3)%beg, idwint(3)%end
do j = idwint(2)%beg, idwint(2)%end
do i = idwint(1)%beg, idwint(1)%end
if (q_beta(1)%sf(i, j, k) > (1._wp - lag_params%valmaxvoid)) then
rhs_vf(eqn_idx%E)%sf(i, j, k) = rhs_vf(eqn_idx%E)%sf(i, j, k) - q_beta(4)%sf(i, j, &
& k)*(1._wp - q_beta(1)%sf(i, j, k))/q_beta(1)%sf(i, j, k)
end if
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
end do
call nvtxEndRange
end subroutine s_compute_bubbles_EL_source
!> Smear the bubble effects onto the Eulerian grid
subroutine s_smear_voidfraction(bc_type)
type(integer_field), dimension(1:num_dims,1:2), intent(in) :: bc_type
integer :: i, j, k, l
call nvtxStartRange("BUBBLES-LAGRANGE-SMEARING")
$:GPU_PARALLEL_LOOP(private='[i, j, k, l]', collapse=4)
do i = 1, q_beta_idx
do l = idwbuff(3)%beg, idwbuff(3)%end
do k = idwbuff(2)%beg, idwbuff(2)%end
do j = idwbuff(1)%beg, idwbuff(1)%end
q_beta(i)%sf(j, k, l) = 0._wp
if (lag_params%kahan_summation) kahan_comp(i)%sf(j, k, l) = 0._wp
end do
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
! Build cell list before smearing (CPU-side counting sort)
call s_build_cell_list(n_el_bubs_loc, mtn_s)
call s_smoothfunction(n_el_bubs_loc, intfc_rad, intfc_vel, mtn_s, mtn_pos, q_beta, kahan_comp)
call nvtxStartRange("BUBBLES-LAGRANGE-BETA-COMM")
if (lag_params%cluster_type >= 4) then
call s_populate_beta_buffers(q_beta, kahan_comp, bc_type, 3)
else
call s_populate_beta_buffers(q_beta, kahan_comp, bc_type, 2)
end if
call nvtxEndRange
! Store 1-beta
$:GPU_PARALLEL_LOOP(private='[j, k, l]', collapse=3)
do l = idwbuff(3)%beg, idwbuff(3)%end
do k = idwbuff(2)%beg, idwbuff(2)%end
do j = idwbuff(1)%beg, idwbuff(1)%end
q_beta(1)%sf(j, k, l) = 1._wp - q_beta(1)%sf(j, k, l)
! Limiting void fraction given max value
q_beta(1)%sf(j, k, l) = max(q_beta(1)%sf(j, k, l), 1._wp - lag_params%valmaxvoid)
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
call nvtxEndRange ! BUBBLES-LAGRANGE-SMEARING
end subroutine s_smear_voidfraction
!> Compute the bubble driving pressure p_inf
subroutine s_get_pinf(bub_id, q_prim_vf, ptype, f_pinfl, cell, preterm1, term2, Romega)
$:GPU_ROUTINE(function_name='s_get_pinf',parallelism='[seq]', cray_inline=True)
integer, intent(in) :: bub_id, ptype
type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf
real(wp), intent(out) :: f_pinfl
integer, dimension(3), intent(out) :: cell
real(wp), intent(out), optional :: preterm1, term2, Romega
real(wp), dimension(3) :: scoord, psi_pos, psi_x, psi_y, psi_z
real(wp) :: xi, eta, zeta
real(wp) :: dc, vol, aux
real(wp) :: volgas, term1, Rbeq, denom
real(wp) :: charvol, charpres, charvol2, charpres2
integer, dimension(3) :: cellaux
integer :: i, j, k
integer :: smearGrid, smearGridz
f_pinfl = 0._wp
if (moving_lag_bubbles) then
cell = fd_number - buff_size
call s_locate_cell(mtn_pos(bub_id,1:3,2), cell, mtn_s(bub_id,1:3,2))
scoord = mtn_s(bub_id,1:3,2)
else
scoord = mtn_s(bub_id,1:3,2)
cell(:) = int(scoord(:))
$:GPU_LOOP(parallelism='[seq]')
do i = 1, num_dims
if (scoord(i) < 0._wp) cell(i) = cell(i) - 1
end do
end if
if ((lag_params%cluster_type == 1)) then
!> Getting p_cell in terms of only the current cell by interpolation
if (fd_order == 2) then ! Bilinear interpolation
if (p > 0) then
vol = dx(cell(1))*dy(cell(2))*dz(cell(3))
else
if (cyl_coord) then
vol = dx(cell(1))*dy(cell(2))*y_cc(cell(2))*2._wp*pi
else
vol = dx(cell(1))*dy(cell(2))*lag_params%charwidth
end if
end if
!> Obtain bilinear interpolation coefficients, based on the current location of the bubble.
psi_pos(1) = (scoord(1) - real(cell(1)))*dx(cell(1)) + x_cb(cell(1) - 1)
psi_pos(1) = abs((psi_pos(1) - x_cc(cell(1)))/(x_cc(cell(1) + 1) - x_cc(cell(1))))
psi_pos(2) = (scoord(2) - real(cell(2)))*dy(cell(2)) + y_cb(cell(2) - 1)
psi_pos(2) = abs((psi_pos(2) - y_cc(cell(2)))/(y_cc(cell(2) + 1) - y_cc(cell(2))))
if (p > 0) then
psi_pos(3) = (scoord(3) - real(cell(3)))*dz(cell(3)) + z_cb(cell(3) - 1)
psi_pos(3) = abs((psi_pos(3) - z_cc(cell(3)))/(z_cc(cell(3) + 1) - z_cc(cell(3))))
else
psi_pos(3) = 0._wp
end if
! Calculate bilinear basis functions for each direction For normalized coordinate xi in [0, 1], the two basis
! functions are: phi_0(xi) = 1 - xi, phi_1(xi) = xi
! X-direction basis functions
psi_x(1) = 1._wp - psi_pos(1) ! Left basis function
psi_x(2) = psi_pos(1) ! Right basis function
! Y-direction basis functions
psi_y(1) = 1._wp - psi_pos(2) ! Left basis function
psi_y(2) = psi_pos(2) ! Right basis function
if (p > 0) then
! Z-direction basis functions
psi_z(1) = 1._wp - psi_pos(3) ! Left basis function
psi_z(2) = psi_pos(3) ! Right basis function
else ! 3D
psi_z(1) = 1._wp
psi_z(2) = 0._wp
end if
!> Perform bilinear interpolation
f_pinfl = 0._wp
if (p == 0) then
do j = 1, 2
do i = 1, 2
f_pinfl = f_pinfl + q_prim_vf(eqn_idx%E)%sf(cell(1) + i - 1, cell(2) + j - 1, cell(3))*psi_x(i)*psi_y(j)
end do
end do
else
do k = 1, 2
do j = 1, 2
do i = 1, 2
f_pinfl = f_pinfl + q_prim_vf(eqn_idx%E)%sf(cell(1) + i - 1, cell(2) + j - 1, &
& cell(3) + k - 1)*psi_x(i)*psi_y(j)*psi_z(k)
end do
end do
end do
end if
else if (fd_order == 4) then ! Biquadratic interpolation
if (p > 0) then
vol = dx(cell(1))*dy(cell(2))*dz(cell(3))
else
if (cyl_coord) then
vol = dx(cell(1))*dy(cell(2))*y_cc(cell(2))*2._wp*pi
else
vol = dx(cell(1))*dy(cell(2))*lag_params%charwidth
end if
end if
!> Obtain biquadratic interpolation coefficients, based on the current location of the bubble.
! For biquadratic interpolation, we need coefficients for 3 points in each direction
psi_pos(1) = (scoord(1) - real(cell(1)))*dx(cell(1)) + x_cb(cell(1) - 1)
psi_pos(1) = (psi_pos(1) - x_cc(cell(1)))/(x_cc(cell(1) + 1) - x_cc(cell(1)))
psi_pos(2) = (scoord(2) - real(cell(2)))*dy(cell(2)) + y_cb(cell(2) - 1)
psi_pos(2) = (psi_pos(2) - y_cc(cell(2)))/(y_cc(cell(2) + 1) - y_cc(cell(2)))
if (p > 0) then
psi_pos(3) = (scoord(3) - real(cell(3)))*dz(cell(3)) + z_cb(cell(3) - 1)
psi_pos(3) = (psi_pos(3) - z_cc(cell(3)))/(z_cc(cell(3) + 1) - z_cc(cell(3)))
else
psi_pos(3) = 0._wp
end if
! Calculate biquadratic basis functions for each direction For normalized coordinate xi in [-1, 1], the three basis
! functions are: phi_0(xi) = xi*(xi-1)/2, phi_1(xi) = (1-xi)*(1+xi), phi_2(xi) = xi*(xi+1)/2
! X-direction basis functions
xi = 2._wp*psi_pos(1) - 1._wp ! Convert to [-1, 1] range
psi_x(1) = xi*(xi - 1._wp)/2._wp ! Left basis function
psi_x(2) = (1._wp - xi)*(1._wp + xi) ! Center basis function