Skip to content

Commit 8ffc20c

Browse files
committed
added options and drag models
1 parent 60375fb commit 8ffc20c

File tree

10 files changed

+121
-68
lines changed

10 files changed

+121
-68
lines changed

src/common/m_constants.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module m_constants
2222
integer, parameter :: fourier_rings = 5 !< Fourier filter ring limit
2323
integer, parameter :: num_fluids_max = 10 !< Maximum number of fluids in the simulation
2424
integer, parameter :: num_probes_max = 10 !< Maximum number of flow probes in the simulation
25-
integer, parameter :: num_patches_max = 10
25+
integer, parameter :: num_patches_max = 20
2626
integer, parameter :: num_bc_patches_max = 10
2727
integer, parameter :: pathlen_max = 400
2828
integer, parameter :: nnode = 4 !< Number of QBMM nodes

src/common/m_derived_types.fpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ module m_derived_types
434434
integer :: nBubs_glb !< Global number of bubbles
435435
integer :: vel_model !< Particle velocity model
436436
integer :: drag_model !< Particle drag model
437+
logical :: pressure_force !< Include pressure force translational motion
438+
logical :: gravity_force !< Include gravity force in translational motion
439+
logical :: momentum_transfer_force !< Include momentum transfer from radial dynamics in translational motion
437440
real(wp) :: c_d !< Drag coefficient
438441
real(wp) :: epsilonb !< Standard deviation scaling for the gaussian function
439442
real(wp) :: charwidth !< Domain virtual depth (z direction, for 2D simulations)

src/common/m_mpi_common.fpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,22 +479,19 @@ contains
479479
!! @param var_loc holds the local value to be reduced among
480480
!! all the processors in communicator. On output, the variable holds
481481
!! the sum, reduced amongst all of the local values.
482-
subroutine s_mpi_reduce_int_sum(var_loc)
482+
subroutine s_mpi_reduce_int_sum(var_loc, sum)
483483
484484
integer, intent(inout) :: var_loc
485+
integer, intent(inout) :: sum
485486
486487
#ifdef MFC_MPI
487488
integer :: ierr !< Generic flag used to identify and report MPI errors
488489
489-
! Temporary storage variable that holds the reduced sum value
490-
integer :: var_glb
491-
492490
! Performing reduction procedure and eventually storing its result
493491
! into the variable that was initially inputted into the subroutine
494-
call MPI_REDUCE(var_loc, var_glb, 1, MPI_INTEGER, &
492+
call MPI_REDUCE(var_loc, sum, 1, MPI_INTEGER, &
495493
MPI_SUM, 0, MPI_COMM_WORLD, ierr)
496494
497-
var_loc = var_glb
498495
#endif
499496
500497
end subroutine s_mpi_reduce_int_sum

src/simulation/m_body_forces.fpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@ contains
5656
subroutine s_compute_acceleration(t)
5757

5858
real(wp), intent(in) :: t
59+
accel_bf(:) = 0._wp
5960

60-
if (m > 0) then
61-
accel_bf(1) = g_x + k_x*sin(w_x*t - p_x)
62-
if (n > 0) then
63-
accel_bf(2) = g_y + k_y*sin(w_y*t - p_y)
64-
if (p > 0) then
65-
accel_bf(3) = g_z + k_z*sin(w_z*t - p_z)
66-
end if
61+
#:for DIR, XYZ in [(1, 'x'), (2, 'y'), (3, 'z')]
62+
if (bf_${XYZ}$) then
63+
accel_bf(${DIR}$) = g_${XYZ}$ + k_${XYZ}$*sin(w_${XYZ}$*t - p_${XYZ}$)
6764
end if
68-
end if
65+
#:endfor
6966

7067
$:GPU_UPDATE(device='[accel_bf]')
7168

src/simulation/m_bubbles.fpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ contains
450450
!! @param fRho Current density
451451
!! @param fP Current driving pressure
452452
!! @param fR Current bubble radius
453-
!! @param fV Current bubble velocity
453+
!! @param fV Current bubble radial velocity
454454
!! @param fR0 Equilibrium bubble radius
455455
!! @param fpb Internal bubble pressure
456456
!! @param fpbdot Time-derivative of internal bubble pressure
@@ -490,7 +490,7 @@ contains
490490
real(wp) :: h !< Time step size
491491
real(wp), dimension(4) :: myR_tmp1, myV_tmp1, myR_tmp2, myV_tmp2 !< Bubble radius, radial velocity, and radial acceleration for the inner loop
492492
real(wp), dimension(4) :: myPb_tmp1, myMv_tmp1, myPb_tmp2, myMv_tmp2 !< Gas pressure and vapor mass for the inner loop (EL)
493-
real(wp) :: fR2, fV2, fpb2, fmass_v2, vTemp, aTemp
493+
real(wp) :: fR2, fV2, fpb2, fmass_v2, vTemp, aTemp, f_bTemp
494494
integer :: l, iter_count
495495

496496
call s_initial_substep_h(fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
@@ -571,10 +571,19 @@ contains
571571
end do
572572
elseif (lag_params%vel_model == 2) then
573573
do l = 1, num_dims
574-
aTemp = f_get_acceleration(fPos(l), fR, fVel(l), fmass_n, fmass_v, &
574+
f_bTemp = f_get_bubble_force(fPos(l), fR, fV, fVel, fmass_n, fmass_v, &
575+
fRe, fRho, cell, l, q_prim_vf)
576+
aTemp = f_bTemp/(fmass_n + fmass_v)
577+
fPos(l) = fPos(l) + h * fVel(l)
578+
fVel(l) = fVel(l) + h * aTemp
579+
end do
580+
elseif (lag_params%vel_model == 3) then
581+
do l = 1, num_dims
582+
f_bTemp = f_get_bubble_force(fPos(l), fR, fV, fVel, fmass_n, fmass_v, &
575583
fRe, fRho, cell, l, q_prim_vf)
576-
fPos(l) = fPos(l) + h*fVel(l)
577-
fVel(l) = fVel(l) + h*aTemp
584+
aTemp = 2._wp * f_bTemp / (fmass_n + fmass_v) - 3 * fV * fVel(l) / fR
585+
fPos(l) = fPos(l) + h * fVel(l)
586+
fVel(l) = fVel(l) + h * aTemp
578587
end do
579588
end if
580589
end if

src/simulation/m_bubbles_EL.fpp

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ contains
279279

280280
print *, " Lagrange bubbles running, in proc", proc_rank, "number:", bub_id, "/", id
281281

282-
call s_mpi_reduce_int_sum(bub_id)
282+
call s_mpi_reduce_int_sum(bub_id, bub_id)
283283

284284
if (proc_rank == 0) then
285285
if (bub_id == 0) call s_mpi_abort('No bubbles in the domain. Check input/lag_bubbles.dat')
@@ -621,7 +621,7 @@ contains
621621
real(wp) :: myR, myV, myBeta_c, myBeta_t, myR0, myPbdot, myMvdot
622622
real(wp) :: myPinf, aux1, aux2, myCson, myRho
623623
real(wp), dimension(3) :: myPos, myVel
624-
real(wp) :: gamma, pi_inf, qv
624+
real(wp) :: gamma, pi_inf, qv, f_b
625625
real(wp), dimension(contxe) :: myalpha_rho, myalpha
626626
real(wp), dimension(2) :: Re
627627
integer, dimension(3) :: cell
@@ -734,10 +734,18 @@ contains
734734
mtn_dveldt(k, l, stage) = 0._wp
735735
elseif (lag_params%vel_model == 2) then
736736
mtn_dposdt(k, l, stage) = myVel(l)
737-
mtn_dveldt(k, l, stage) = f_get_acceleration(myPos(l), &
738-
myR, myVel(l), &
739-
myMass_n, myMass_v, &
740-
Re(1), myRho, cell, l, q_prim_vf)
737+
f_b = f_get_bubble_force(myPos(l), &
738+
myR, myV, myVel, &
739+
myMass_n, myMass_v, &
740+
Re(1), myRho, cell, l, q_prim_vf)
741+
mtn_dveldt(k, l, stage) = f_b / (myMass_n + myMass_v)
742+
elseif (lag_params%vel_model == 3) then
743+
mtn_dposdt(k, l, stage) = myVel(l)
744+
f_b = f_get_bubble_force(myPos(l), &
745+
myR, myV, myVel, &
746+
myMass_n, myMass_v, &
747+
Re(1), myRho, cell, l, q_prim_vf)
748+
mtn_dveldt(k, l, stage) = 2._wp * f_b / (myMass_n + myMass_v) - 3._wp * myV * myVel(l) / myR
741749
else
742750
mtn_dposdt(k, l, stage) = 0._wp
743751
mtn_dveldt(k, l, stage) = 0._wp
@@ -776,6 +784,7 @@ contains
776784

777785
if (lag_params%solver_approach == 2) then
778786

787+
! (q / (1 - beta)) * d(beta)/dt source
779788
if (p == 0) then
780789
$:GPU_PARALLEL_LOOP(collapse=4)
781790
do k = 0, p
@@ -813,6 +822,7 @@ contains
813822

814823
call s_gradient_dir(q_prim_vf(E_idx), q_beta%vf(3), l)
815824

825+
! (beta / (1 - beta)) * dP/dl source
816826
$:GPU_PARALLEL_LOOP(collapse=3)
817827
do k = 0, p
818828
do j = 0, n
@@ -839,6 +849,7 @@ contains
839849

840850
call s_gradient_dir(q_beta%vf(3), q_beta%vf(4), l)
841851

852+
! (beta / (1 - beta)) * d(Pu)/dl source
842853
$:GPU_PARALLEL_LOOP(collapse=3)
843854
do k = 0, p
844855
do j = 0, n
@@ -852,7 +863,6 @@ contains
852863
end do
853864
end do
854865
end do
855-
856866
end if
857867

858868
end subroutine s_compute_bubbles_EL_source
@@ -1541,6 +1551,13 @@ contains
15411551
nBubs = nBubs + newBubs
15421552
end if
15431553

1554+
if (run_time_info) then
1555+
call s_mpi_reduce_int_sum(nBubs, active_bubs)
1556+
if (proc_rank == 0 .and. active_bubs == 0) then
1557+
call s_mpi_abort('No bubbles remain in the domain. Simulation ending.')
1558+
end if
1559+
end if
1560+
15441561
! Handle MPI transfer of bubbles going to another processor's local domain
15451562
if (num_procs > 1) then
15461563
call nvtxStartRange("LAG-BC-TRANSFER-LIST")
@@ -1745,36 +1762,34 @@ contains
17451762
end do
17461763
end do
17471764
end do
1748-
else
1749-
if (dir == 2) then
1750-
! Gradient in y dir.
1751-
$:GPU_PARALLEL_LOOP(collapse=3)
1752-
do k = 0, p
1753-
do j = 0, n
1754-
do i = 0, m
1755-
dq%sf(i, j, k) = q%sf(i, j, k)*(dy(j + 1) - dy(j - 1)) &
1756-
+ q%sf(i, j + 1, k)*(dy(j) + dy(j - 1)) &
1757-
- q%sf(i, j - 1, k)*(dy(j) + dy(j + 1))
1758-
dq%sf(i, j, k) = dq%sf(i, j, k)/ &
1759-
((dy(j) + dy(j - 1))*(dy(j) + dy(j + 1)))
1760-
end do
1765+
elseif (dir == 2) then
1766+
! Gradient in y dir.
1767+
$:GPU_PARALLEL_LOOP(collapse=3)
1768+
do k = 0, p
1769+
do j = 0, n
1770+
do i = 0, m
1771+
dq%sf(i, j, k) = q%sf(i, j, k)*(dy(j + 1) - dy(j - 1)) &
1772+
+ q%sf(i, j + 1, k)*(dy(j) + dy(j - 1)) &
1773+
- q%sf(i, j - 1, k)*(dy(j) + dy(j + 1))
1774+
dq%sf(i, j, k) = dq%sf(i, j, k)/ &
1775+
((dy(j) + dy(j - 1))*(dy(j) + dy(j + 1)))
17611776
end do
17621777
end do
1763-
else
1764-
! Gradient in z dir.
1765-
$:GPU_PARALLEL_LOOP(collapse=3)
1766-
do k = 0, p
1767-
do j = 0, n
1768-
do i = 0, m
1769-
dq%sf(i, j, k) = q%sf(i, j, k)*(dz(k + 1) - dz(k - 1)) &
1770-
+ q%sf(i, j, k + 1)*(dz(k) + dz(k - 1)) &
1771-
- q%sf(i, j, k - 1)*(dz(k) + dz(k + 1))
1772-
dq%sf(i, j, k) = dq%sf(i, j, k)/ &
1773-
((dz(k) + dz(k - 1))*(dz(k) + dz(k + 1)))
1774-
end do
1778+
end do
1779+
elseif (dir == 3) then
1780+
! Gradient in z dir.
1781+
$:GPU_PARALLEL_LOOP(collapse=3)
1782+
do k = 0, p
1783+
do j = 0, n
1784+
do i = 0, m
1785+
dq%sf(i, j, k) = q%sf(i, j, k)*(dz(k + 1) - dz(k - 1)) &
1786+
+ q%sf(i, j, k + 1)*(dz(k) + dz(k - 1)) &
1787+
- q%sf(i, j, k - 1)*(dz(k) + dz(k + 1))
1788+
dq%sf(i, j, k) = dq%sf(i, j, k)/ &
1789+
((dz(k) + dz(k - 1))*(dz(k) + dz(k + 1)))
17751790
end do
17761791
end do
1777-
end if
1792+
end do
17781793
end if
17791794
17801795
end subroutine s_gradient_dir

src/simulation/m_bubbles_EL_kernels.fpp

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,11 @@ contains
523523

524524
end function f_interpolate_velocity
525525

526-
!! This function calculates the acceleration of the bubble
526+
!! This function calculates the force on a bubble
527527
!! based on the pressure gradient, velocity, and drag model.
528528
!! @param pos Position of the bubble in direction i
529529
!! @param rad Radius of the bubble
530+
!! @param rdot Radial velocity of the bubble
530531
!! @param vel Velocity of the bubble
531532
!! @param mg Mass of the gas in the bubble
532533
!! @param mv Mass of the liquid in the bubble
@@ -536,16 +537,18 @@ contains
536537
!! @param i Direction of the velocity (1: x, 2: y, 3: z)
537538
!! @param q_prim_vf Eulerian field with primitive variables
538539
!! @return a Acceleration of the bubble in direction i
539-
pure function f_get_acceleration(pos, rad, vel, mg, mv, Re, rho, cell, i, q_prim_vf) result(a)
540+
pure function f_get_bubble_force(pos, rad, rdot, vel, mg, mv, Re, rho, cell, i, q_prim_vf) result(force)
540541
$:GPU_ROUTINE(parallelism='[seq]')
541-
real(wp), intent(in) :: pos, rad, vel, mg, mv, Re, rho
542+
real(wp), intent(in) :: pos, rad, rdot, mg, mv, Re, rho
543+
real(wp), intent(in), dimension(3) :: vel
542544
integer, dimension(3), intent(in) :: cell
543545
integer, intent(in) :: i
544546
type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf
545547

546-
real(wp) :: a
547-
real(wp) :: dp, vol, force, v_rel
548+
real(wp) :: a, dp, vol, force, Re_b, C_d, v_rel_mag, rho_b
549+
real(wp), dimension(3) :: v_rel
548550
real(wp), dimension(fd_order - 1) :: xi, eta, L
551+
integer :: j
549552

550553
if (fd_order == 2) then
551554
if (i == 1) then
@@ -610,19 +613,43 @@ contains
610613
dp = L(1)*eta(1) + L(2)*eta(2) + L(3)*eta(3)
611614
end if
612615

613-
vol = (4._wp/3._wp)*pi*rad**3._wp
614-
force = -1._wp*vol*dp
616+
vol = (4._wp/3._wp) * pi * (rad**3._wp)
617+
v_rel_mag = 0._wp
615618

616-
v_rel = vel - f_interpolate_velocity(pos, cell, i, q_prim_vf)
619+
do j = 1, num_dims
620+
v_rel(j) = vel(j) - f_interpolate_velocity(pos, cell, j, q_prim_vf)
621+
v_rel_mag = v_rel_mag + v_rel(j)**2._wp
622+
end do
623+
624+
force = 0._wp
617625

618626
if (lag_params%drag_model == 1) then ! Free slip Stokes drag
619-
force = force - (4._wp*pi*rad*v_rel)/Re
627+
force = force - (4._wp*pi*rad*v_rel(i))/Re
620628
else if (lag_params%drag_model == 2) then ! No slip Stokes drag
621-
force = force - (6._wp*pi*rad*v_rel)/Re
629+
force = force - (6._wp*pi*rad*v_rel(i))/Re
630+
else if (lag_params%drag_model == 3) then ! Levich drag
631+
force = force - (12._wp*pi*rad*v_rel(i))/Re
632+
else if (lag_params%drag_model > 0) then ! Drag coefficient model
633+
v_rel_mag = sqrt(v_rel_mag)
634+
Re_b = max(1e-3, rho * v_rel_mag * 2._wp * rad * Re)
635+
if (lag_params%drag_model == 4) then ! Mei et al. 1994
636+
C_d = 16._wp / Re_b * (1._wp + (8._wp / Re_b + 0.5_wp * (1._wp + 3.315_wp * Re_b**(-0.5_wp))) ** -1._wp)
637+
end if
638+
force = force - 0.5_wp * C_d * rho * pi * rad**2._wp * v_rel(i) * v_rel_mag
639+
end if
640+
641+
if (lag_params%pressure_force) then
642+
force = force - vol * dp
643+
end if
644+
645+
if (lag_params%gravity_force) then
646+
force = force + (mg + mv) * accel_bf(i)
622647
end if
623648

624-
a = force/(mg + mv)
649+
if (lag_params%momentum_transfer_force) then
650+
force = force - 4._wp * pi * rho * rad**2._wp * v_rel(i) * rdot
651+
end if
625652

626-
end function f_get_acceleration
653+
end function f_get_bubble_force
627654

628655
end module m_bubbles_EL_kernels

src/simulation/m_global_parameters.fpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,9 @@ contains
816816
lag_params%nBubs_glb = dflt_int
817817
lag_params%vel_model = dflt_int
818818
lag_params%drag_model = dflt_int
819+
lag_params%pressure_force = .true.
820+
lag_params%gravity_force = .false.
821+
lag_params%momentum_transfer_force = .false.
819822
lag_params%c_d = dflt_real
820823
lag_params%epsilonb = 1._wp
821824
lag_params%charwidth = dflt_real

src/simulation/m_mpi_proxy.fpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ contains
188188
189189
if (bubbles_lagrange) then
190190
#:for VAR in [ 'heatTransfer_model', 'massTransfer_model', 'pressure_corrector', &
191-
& 'write_bubbles', 'write_bubbles_stats', 'vel_model', 'drag_model']
191+
& 'write_bubbles', 'write_bubbles_stats', 'vel_model', 'drag_model', &
192+
& 'pressure_force', 'gravity_force', 'momentum_transfer_force']
192193
call MPI_BCAST(lag_params%${VAR}$, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr)
193194
#:endfor
194195

toolchain/mfc/run/case_dicts.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def analytic(self):
163163

164164
PRE_PROCESS[f"patch_bc({bc_p_id})%radius"] = ParamType.REAL
165165

166-
for p_id in range(1, 10+1):
166+
for p_id in range(1, 20+1):
167167
for attribute, ty in [("geometry", ParamType.INT), ("smoothen", ParamType.LOG),
168168
("smooth_patch_id", ParamType.INT), ("hcid", ParamType.INT)]:
169169
PRE_PROCESS[f"patch_icpp({p_id})%{attribute}"] = ty
@@ -326,7 +326,8 @@ def analytic(self):
326326
})
327327

328328
for var in [ 'heatTransfer_model', 'massTransfer_model', 'pressure_corrector',
329-
'write_bubbles', 'write_bubbles_stats' ]:
329+
'write_bubbles', 'write_bubbles_stats', 'pressure_force',
330+
'gravity_force', 'momentum_transfer_force']:
330331
SIMULATION[f'lag_params%{var}'] = ParamType.LOG
331332

332333
for var in [ 'solver_approach', 'cluster_type', 'smooth_type', 'nBubs_glb',

0 commit comments

Comments
 (0)