Skip to content

Commit 81121a7

Browse files
Diego VacaDiego Vaca
authored andcommitted
Addressing comments 3 and fixing Frontier
1 parent 2aac61a commit 81121a7

File tree

4 files changed

+76
-55
lines changed

4 files changed

+76
-55
lines changed

src/simulation/m_bubbles.fpp

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ contains
457457
!! @param fbeta_c Mass transfer coefficient (EL)
458458
!! @param fbeta_t Heat transfer coefficient (EL)
459459
!! @param fCson Speed of sound (EL)
460+
!! @param adap_dt_stop Fail-safe exit if max iteration count reached
460461
subroutine s_advance_step(fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
461462
fntait, fBtait, f_bub_adv_src, f_divu, &
462463
bub_id, fmass_v, fmass_n, fbeta_c, &
@@ -471,17 +472,18 @@ contains
471472
real(wp), intent(in) :: fntait, fBtait, f_bub_adv_src, f_divu
472473
integer, intent(in) :: bub_id
473474
real(wp), intent(in) :: fmass_n, fbeta_c, fbeta_t, fCson
474-
integer, intent(out) :: adap_dt_stop
475+
integer, intent(inout) :: adap_dt_stop
475476

476477
real(wp), dimension(5) :: err !< Error estimates for adaptive time stepping
477478
real(wp) :: t_new !< Updated time step size
478479
real(wp) :: h !< Time step size
479480
real(wp), dimension(4) :: myR_tmp1, myV_tmp1, myR_tmp2, myV_tmp2 !< Bubble radius, radial velocity, and radial acceleration for the inner loop
480481
real(wp), dimension(4) :: myPb_tmp1, myMv_tmp1, myPb_tmp2, myMv_tmp2 !< Gas pressure and vapor mass for the inner loop (EL)
482+
real(wp) :: fR2, fV2, fpb2, fmass_v2
481483
integer :: iter_count
482484

483-
h = f_initial_substep_h(fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
484-
fntait, fBtait, f_bub_adv_src, f_divu, fCson)
485+
call s_initial_substep_h(fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
486+
fntait, fBtait, f_bub_adv_src, f_divu, fCson, h)
485487

486488
! Advancing one step
487489
t_new = 0._wp
@@ -500,27 +502,30 @@ contains
500502
iter_count = iter_count + 1
501503

502504
! Advance one sub-step
503-
err(1) = f_advance_substep( &
504-
fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
505-
fntait, fBtait, f_bub_adv_src, f_divu, &
506-
bub_id, fmass_v, fmass_n, fbeta_c, &
507-
fbeta_t, fCson, h, &
508-
myR_tmp1, myV_tmp1, myPb_tmp1, myMv_tmp1)
505+
call s_advance_substep(err(1), &
506+
fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
507+
fntait, fBtait, f_bub_adv_src, f_divu, &
508+
bub_id, fmass_v, fmass_n, fbeta_c, &
509+
fbeta_t, fCson, h, &
510+
myR_tmp1, myV_tmp1, myPb_tmp1, myMv_tmp1)
509511

510512
! Advance one sub-step by advancing two half steps
511-
err(2) = f_advance_substep( &
512-
fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
513-
fntait, fBtait, f_bub_adv_src, f_divu, &
514-
bub_id, fmass_v, fmass_n, fbeta_c, &
515-
fbeta_t, fCson, 0.5_wp*h, &
516-
myR_tmp2, myV_tmp2, myPb_tmp2, myMv_tmp2)
517-
518-
err(3) = f_advance_substep( &
519-
fRho, fP, myR_tmp2(4), myV_tmp2(4), fR0, myPb_tmp2(4), fpbdot, alf, &
520-
fntait, fBtait, f_bub_adv_src, f_divu, &
521-
bub_id, myMv_tmp2(4), fmass_n, fbeta_c, &
522-
fbeta_t, fCson, 0.5_wp*h, &
523-
myR_tmp2, myV_tmp2, myPb_tmp2, myMv_tmp2)
513+
call s_advance_substep(err(2), &
514+
fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
515+
fntait, fBtait, f_bub_adv_src, f_divu, &
516+
bub_id, fmass_v, fmass_n, fbeta_c, &
517+
fbeta_t, fCson, 0.5_wp*h, &
518+
myR_tmp2, myV_tmp2, myPb_tmp2, myMv_tmp2)
519+
520+
fR2 = myR_tmp2(4); fV2 = myV_tmp2(4)
521+
fpb2 = myPb_tmp2(4); fmass_v2 = myMv_tmp2(4)
522+
523+
call s_advance_substep(err(3), &
524+
fRho, fP, fR2, fV2, fR0, fpb2, fpbdot, alf, &
525+
fntait, fBtait, f_bub_adv_src, f_divu, &
526+
bub_id, fmass_v2, fmass_n, fbeta_c, &
527+
fbeta_t, fCson, 0.5_wp*h, &
528+
myR_tmp2, myV_tmp2, myPb_tmp2, myMv_tmp2)
524529

525530
err(4) = abs((myR_tmp1(4) - myR_tmp2(4))/myR_tmp1(4))
526531
err(5) = abs((myV_tmp1(4) - myV_tmp2(4))/myV_tmp1(4))
@@ -587,15 +592,20 @@ contains
587592
!! @param f_bub_adv_src Source for bubble volume fraction
588593
!! @param f_divu Divergence of velocity
589594
!! @param fCson Speed of sound (EL)
590-
function f_initial_substep_h(fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
591-
fntait, fBtait, f_bub_adv_src, f_divu, &
592-
fCson)
595+
!! @param h Time step size
596+
subroutine s_initial_substep_h(fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
597+
fntait, fBtait, f_bub_adv_src, f_divu, &
598+
fCson, h)
599+
#ifdef _CRAYFTN
600+
!DIR$ INLINEALWAYS s_initial_substep_h
601+
#else
593602
!$acc routine seq
603+
#endif
594604
real(wp), intent(IN) :: fRho, fP, fR, fV, fR0, fpb, fpbdot, alf
595605
real(wp), intent(IN) :: fntait, fBtait, f_bub_adv_src, f_divu
596606
real(wp), intent(IN) :: fCson
607+
real(wp), intent(OUT) :: h
597608

598-
real(wp) :: f_initial_substep_h
599609
real(wp), dimension(2) :: h_size !< Time step size (h0, h1)
600610
real(wp), dimension(3) :: d_norms !< norms (d_0, d_1, d_2)
601611
real(wp), dimension(2) :: myR_tmp, myV_tmp, myA_tmp !< Bubble radius, radial velocity, and radial acceleration
@@ -637,12 +647,13 @@ contains
637647
h_size(2) = (scale_guess/max(d_norms(2), d_norms(3)))**(1._wp/3._wp)
638648
end if
639649

640-
f_initial_substep_h = min(h_size(1)/scale_guess, h_size(2))
650+
h = min(h_size(1)/scale_guess, h_size(2))
641651

642-
end function f_initial_substep_h
652+
end subroutine s_initial_substep_h
643653

644654
!> Integrate bubble variables over the given time step size, h, using a
645655
!! third-order accurate embedded Runge–Kutta scheme.
656+
!! @param err Estimated error
646657
!! @param fRho Current density
647658
!! @param fP Current driving pressure
648659
!! @param fR Current bubble radius
@@ -666,20 +677,24 @@ contains
666677
!! @param myV_tmp Bubble radial velocity at each stage
667678
!! @param myPb_tmp Internal bubble pressure at each stage (EL)
668679
!! @param myMv_tmp Mass of vapor in the bubble at each stage (EL)
669-
function f_advance_substep(fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
670-
fntait, fBtait, f_bub_adv_src, f_divu, &
671-
bub_id, fmass_v, fmass_n, fbeta_c, &
672-
fbeta_t, fCson, h, &
673-
myR_tmp, myV_tmp, myPb_tmp, myMv_tmp)
680+
subroutine s_advance_substep(err, fRho, fP, fR, fV, fR0, fpb, fpbdot, alf, &
681+
fntait, fBtait, f_bub_adv_src, f_divu, &
682+
bub_id, fmass_v, fmass_n, fbeta_c, &
683+
fbeta_t, fCson, h, &
684+
myR_tmp, myV_tmp, myPb_tmp, myMv_tmp)
685+
#ifdef _CRAYFTN
686+
!DIR$ INLINEALWAYS s_advance_substep
687+
#else
674688
!$acc routine seq
689+
#endif
690+
real(wp), intent(OUT) :: err
675691
real(wp), intent(IN) :: fRho, fP, fR, fV, fR0, fpb, fpbdot, alf
676692
real(wp), intent(IN) :: fntait, fBtait, f_bub_adv_src, f_divu, h
677693
integer, intent(IN) :: bub_id
678694
real(wp), intent(IN) :: fmass_v, fmass_n, fbeta_c, fbeta_t, fCson
679695
real(wp), dimension(4), intent(OUT) :: myR_tmp, myV_tmp, myPb_tmp, myMv_tmp
680696

681697
real(wp), dimension(4) :: myA_tmp, mydPbdt_tmp, mydMvdt_tmp
682-
real(wp) :: f_advance_substep
683698
real(wp) :: err_R, err_V
684699

685700
myPb_tmp(1:4) = fpb
@@ -751,9 +766,9 @@ contains
751766
f_approx_equal(myA_tmp(3), 0._wp) .and. f_approx_equal(myA_tmp(4), 0._wp)) then
752767
err_V = 0._wp
753768
end if
754-
f_advance_substep = sqrt((err_R**2._wp + err_V**2._wp)/2._wp)
769+
err = sqrt((err_R**2._wp + err_V**2._wp)/2._wp)
755770

756-
end function f_advance_substep
771+
end subroutine s_advance_substep
757772

758773
!> Changes of pressure and vapor mass in the lagrange bubbles.
759774
!! @param bub_id Bubble identifier
@@ -766,8 +781,8 @@ contains
766781
!! @param fMv_tmp Mass of vapor in the bubble
767782
!! @param fdPbdt_tmp Rate of change of the internal bubble pressure
768783
!! @param fdMvdt_tmp Rate of change of the mass of vapor in the bubble
769-
function f_advance_EL(fR_tmp, fV_tmp, fPb_tmp, fMv_tmp, bub_id, fmass_n, fbeta_c, fbeta_t, &
770-
fdPbdt_tmp)
784+
function f_advance_EL(fR_tmp, fV_tmp, fPb_tmp, fMv_tmp, bub_id, &
785+
fmass_n, fbeta_c, fbeta_t, fdPbdt_tmp)
771786
!$acc routine seq
772787
real(wp), intent(IN) :: fR_tmp, fV_tmp, fPb_tmp, fMv_tmp
773788
real(wp), intent(IN) :: fmass_n, fbeta_c, fbeta_t

src/simulation/m_bubbles_EE.fpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ contains
168168

169169
integer :: i, j, k, l, q, ii !< Loop variables
170170

171-
integer :: adap_dt_stop_max, adap_dt_stop !< fail-safe exit if max iteration count reached
171+
integer :: adap_dt_stop_max, adap_dt_stop !< Fail-safe exit if max iteration count reached
172172
integer :: dmBub_id !< Dummy variables for unified subgrid bubble subroutines
173173
real(wp) :: dmMass_v, dmMass_n, dmBeta_c, dmBeta_t, dmCson
174174

@@ -320,7 +320,7 @@ contains
320320
end do
321321
end do
322322

323-
if (adap_dt .and. adap_dt_stop_max > 0) stop "Adaptive time stepping failed to converge"
323+
if (adap_dt .and. adap_dt_stop_max > 0) call s_mpi_abort("Adaptive time stepping failed to converge.")
324324

325325
if (.not. adap_dt) then
326326
!$acc parallel loop collapse(3) gang vector default(present)

src/simulation/m_bubbles_EL.fpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ contains
224224
indomain = particle_in_domain(inputBubble(1:3))
225225
id = id + 1
226226
if (id > lag_params%nBubs_glb .and. proc_rank == 0) then
227-
call s_mpi_abort('Current number of bubbles is larger than nBubs_glb')
227+
call s_mpi_abort("Current number of bubbles is larger than nBubs_glb")
228228
end if
229229
if (indomain) then
230230
bub_id = bub_id + 1
@@ -236,7 +236,7 @@ contains
236236
end do
237237
close (94)
238238
else
239-
stop "Lagrange bubbles: you have to initialize them in input/lag_bubbles.dat"
239+
call s_mpi_abort("Initialize the lagrange bubbles in input/lag_bubbles.dat")
240240
end if
241241
else
242242
if (proc_rank == 0) print *, 'Restarting lagrange bubbles at save_count: ', save_count
@@ -318,13 +318,18 @@ contains
318318
call s_locate_cell(mtn_pos(bub_id, 1:3, 1), cell, mtn_s(bub_id, 1:3, 1))
319319

320320
! Check if the bubble is located in the ghost cell of a symmetric boundary
321-
if (bc_x%beg == BC_REFLECTIVE .and. cell(1) < 0) stop "Lagrange bubble is in the ghost cells of a symmetric boundary (bc_x%beg)."
322-
if (bc_x%end == BC_REFLECTIVE .and. cell(1) > m) stop "Lagrange bubble is in the ghost cells of a symmetric boundary (bc_x%end)."
323-
if (bc_y%beg == BC_REFLECTIVE .and. cell(2) < 0) stop "Lagrange bubble is in the ghost cells of a symmetric boundary (bc_y%beg)."
324-
if (bc_y%end == BC_REFLECTIVE .and. cell(2) > n) stop "Lagrange bubble is in the ghost cells of a symmetric boundary (bc_y%end)."
321+
if ((bc_x%beg == BC_REFLECTIVE .and. cell(1) < 0) .or. &
322+
(bc_x%end == BC_REFLECTIVE .and. cell(1) > m) .or. &
323+
(bc_y%beg == BC_REFLECTIVE .and. cell(2) < 0) .or. &
324+
(bc_y%end == BC_REFLECTIVE .and. cell(2) > n)) then
325+
call s_mpi_abort("Lagrange bubble is in the ghost cells of a symmetric boundary.")
326+
end if
327+
325328
if (p > 0) then
326-
if (bc_z%beg == BC_REFLECTIVE .and. cell(3) < 0) stop "Lagrange bubble is in the ghost cells of a symmetric boundary (bc_z%beg)."
327-
if (bc_z%end == BC_REFLECTIVE .and. cell(3) > p) stop "Lagrange bubble is in the ghost cells of a symmetric boundary (bc_z%end)."
329+
if ((bc_z%beg == BC_REFLECTIVE .and. cell(3) < 0) .or. &
330+
(bc_z%end == BC_REFLECTIVE .and. cell(3) > p)) then
331+
call s_mpi_abort("Lagrange bubble is in the ghost cells of a symmetric boundary.")
332+
end if
328333
end if
329334

330335
! If particle is in the ghost cells, find the closest non-ghost cell
@@ -355,15 +360,15 @@ contains
355360
gas_mv(bub_id, 1) = pv*volparticle*(1._wp/(R_v*Tw))*(massflag) ! vapermass
356361
gas_mg(bub_id) = (gas_p(bub_id, 1) - pv*(massflag))*volparticle*(1._wp/(R_n*Tw)) ! gasmass
357362
if (gas_mg(bub_id) <= 0._wp) then
358-
stop 'The initial mass of gas inside the bubble is negative. Check your initial conditions'
363+
call s_mpi_abort("The initial mass of gas inside the bubble is negative. Check the initial conditions.")
359364
end if
360365
totalmass = gas_mg(bub_id) + gas_mv(bub_id, 1) ! totalmass
361366

362367
! Bubble natural frequency
363368
concvap = gas_mv(bub_id, 1)/(gas_mv(bub_id, 1) + gas_mg(bub_id))
364369
omegaN = (3._wp*(gas_p(bub_id, 1) - pv*(massflag)) + 4._wp*(1._wp/Web)/bub_R0(bub_id))/rhol
365370
if (pv*(massflag) > gas_p(bub_id, 1)) then
366-
stop "Lagrange bubble initially located in a region with pressure below the vapor pressure."
371+
call s_mpi_abort("Lagrange bubble initially located in a region with pressure below the vapor pressure.")
367372
end if
368373
omegaN = sqrt(omegaN/bub_R0(bub_id)**2._wp)
369374

@@ -379,7 +384,9 @@ contains
379384
call s_transcoeff(1._wp, PeG, Re_trans, Im_trans)
380385
gas_betaC(bub_id) = Re_trans*(massflag)*lag_params%diffcoefvap
381386

382-
if (gas_mg(bub_id) <= 0._wp) stop "Negative gas mass in the bubble, check if the bubble is in the domain."
387+
if (gas_mg(bub_id) <= 0._wp) then
388+
call s_mpi_abort("Negative gas mass in the bubble, check if the bubble is in the domain.")
389+
end if
383390

384391
end subroutine s_add_bubbles
385392

@@ -507,7 +514,7 @@ contains
507514
real(wp), dimension(2) :: Re
508515
integer, dimension(3) :: cell
509516

510-
integer :: adap_dt_stop_max, adap_dt_stop !< fail-safe exit if max iteration count reached
517+
integer :: adap_dt_stop_max, adap_dt_stop !< Fail-safe exit if max iteration count reached
511518
real(wp) :: dmalf, dmntait, dmBtait, dm_bub_adv_src, dm_divu !< Dummy variables for unified subgrid bubble subroutines
512519

513520
integer :: i, k, l
@@ -604,7 +611,7 @@ contains
604611

605612
end do
606613

607-
if (adap_dt .and. adap_dt_stop_max > 0) stop "Adaptive time stepping failed to converge"
614+
if (adap_dt .and. adap_dt_stop_max > 0) call s_mpi_abort("Adaptive time stepping failed to converge.")
608615

609616
! Bubbles remain in a fixed position
610617
!$acc parallel loop collapse(2) gang vector default(present) private(k) copyin(stage)

src/simulation/m_start_up.fpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,7 @@ contains
14311431
!$acc update host(intfc_rad)
14321432
do i = 1, nBubs
14331433
if (ieee_is_nan(intfc_rad(i, 1)) .or. intfc_rad(i, 1) <= 0._wp) then
1434-
print *, "Bubble radius is negative or NaN", proc_rank, t_step, i, intfc_rad(i, 1)
1435-
error stop "Bubble radius is negative or NaN, please reduce dt"
1434+
call s_mpi_abort("Bubble radius is negative or NaN, please reduce dt.")
14361435
end if
14371436
end do
14381437

0 commit comments

Comments
 (0)