Skip to content

Commit 1fe925a

Browse files
author
Diego Vaca
committed
solving adapt dt rkck
1 parent 9f0c644 commit 1fe925a

File tree

6 files changed

+68
-61
lines changed

6 files changed

+68
-61
lines changed

src/common/m_constants.fpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ module m_constants
6666
! Adaptive rkck constants
6767
real(kind(0d0)), parameter :: verysmall_dt = 1.d-14 !< Very small dt, stop stepper
6868
real(kind(0d0)), parameter :: SAFETY = 0.9d0 !< Next dt will be maximum 0.9*dt if truncation error is above tolerance.
69-
real(kind(0d0)), parameter :: RNDDEC = 1.0d05 !< Need to round the relative truncation error (5th decimal) to avoid the inclusion of random decimals
70-
! after dividing calculated tolerance by a very small number (rkck_tolerance)
69+
real(kind(0d0)), parameter :: RNDDEC = 1.0d8 !< Round calculated dt (16th digit) to avoid the inclusion of random decimals
7170
real(kind(0d0)), parameter :: PSHRNK = -0.25d0 !< Factor to reduce dt when truncation error above tolerance
7271
real(kind(0d0)), parameter :: SHRNKDT = 0.5d0 !< Factor to reduce dt due to negative bubble radius
7372
real(kind(0d0)), parameter :: ERRCON = 1.89d-4 !< Limit to slightly increase dt when truncation error is between ERRCON and 1

src/simulation/m_bubbles_EL.fpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,24 +1354,32 @@ contains
13541354

13551355
if ((rkck_errmax > 1d0)) then ! Truncation error too large, reduce dt and restart time step
13561356
restart_rkck_step = .true.
1357-
htemp = SAFETY*dt*((floor(rkck_errmax*RNDDEC)/RNDDEC)**PSHRNK)
1357+
htemp = SAFETY*dt*(rkck_errmax**PSHRNK)
13581358
dt = sign(max(abs(htemp), (1d0 - SAFETY)*abs(dt)), dt) ! No more than a factor of 10.
1359-
if (proc_rank == 0) print *, '>>>>> WARNING: Truncation error found. Reducing dt and restaring time step, now dt: ', dt
13601359
else ! Step succeeded. Compute size of next step.
13611360
if (rkck_errmax > ERRCON) then
1362-
dt = SAFETY*dt*((floor(rkck_errmax*RNDDEC)/RNDDEC)**PGROW) ! No more than a factor of 5 increase.
1361+
dt = SAFETY*dt*(rkck_errmax**PGROW) ! No more than a factor of 5 increase.
13631362
else
13641363
dt = (1d0/SHRNKDT)*dt ! Truncation error too small (< 1.89e-4), increase time step
13651364
end if
13661365
end if
13671366

1367+
!dt precision accuracy is 16 digits
1368+
dt = (ceiling(dt*RNDDEC)*RNDDEC + ceiling(dt*(RNDDEC**2d0) - ceiling(dt*RNDDEC)*RNDDEC))/(RNDDEC**2d0)
13681369
dt = min(dt, dt_max)
1370+
1371+
if (dt < 0) call s_mpi_abort('dt must not be negative')
13691372
if (num_procs > 1) then
13701373
call s_mpi_allreduce_min(dt, aux_glb)
13711374
dt = aux_glb
13721375
end if
13731376
!$acc update device(dt)
13741377

1378+
if (restart_rkck_step) then
1379+
if (proc_rank == 0) print '("WARNING: Truncation error found. Restaring time step, and now dt = "ES16.6"")', &
1380+
dt
1381+
end if
1382+
13751383
end if
13761384

13771385
end subroutine s_compute_rkck_dt

tests/1A1D02B7/golden-metadata.txt

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/1A1D02B7/golden.txt

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/E282C393/golden-metadata.txt

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/E282C393/golden.txt

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)