From 6109d9dba1cd232ad64cdec83b42158f27ad89f2 Mon Sep 17 00:00:00 2001 From: JeroBnd <135150267+JeroBnd@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:57:35 -0300 Subject: [PATCH 1/2] Fixed the source of the dt=0 error when using adaptive time step in idealized cases Restrict the remaining time until the next boundary control to be greater than 0 in order to correct the dtInterval. --- dyn_em/adapt_timestep_em.F | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dyn_em/adapt_timestep_em.F b/dyn_em/adapt_timestep_em.F index 2de49b12d7..23ab732794 100644 --- a/dyn_em/adapt_timestep_em.F +++ b/dyn_em/adapt_timestep_em.F @@ -287,8 +287,10 @@ RECURSIVE SUBROUTINE adapt_timestep(grid, config_flags) num = INT(time_to_bc * precision + 0.5) den = precision CALL WRFU_TimeIntervalSet(tmpTimeInterval, Sn=num, Sd=den) - - if ( ( tmpTimeInterval .LT. dtInterval * 2 ) .and. & + +if (num .LE. 0) then + stepping_to_bc = .false. + elseif ( ( tmpTimeInterval .LT. dtInterval * 2 ) .and. & ( tmpTimeInterval .GT. dtInterval ) ) then dtInterval = tmpTimeInterval / 2 From aed98f6a93360940e08f57d8797796403b237ff2 Mon Sep 17 00:00:00 2001 From: JeroBnd <135150267+JeroBnd@users.noreply.github.com> Date: Thu, 12 Sep 2024 12:52:32 -0300 Subject: [PATCH 2/2] Fix the dtInterval adjunstment on output time using adaptive Problems with the precision of the time_to_output calculation cause errors in setting the correct time step at output time and final time in the em_b_wave ideal test --- dyn_em/adapt_timestep_em.F | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/dyn_em/adapt_timestep_em.F b/dyn_em/adapt_timestep_em.F index 23ab732794..d96bfb037c 100644 --- a/dyn_em/adapt_timestep_em.F +++ b/dyn_em/adapt_timestep_em.F @@ -288,7 +288,7 @@ RECURSIVE SUBROUTINE adapt_timestep(grid, config_flags) den = precision CALL WRFU_TimeIntervalSet(tmpTimeInterval, Sn=num, Sd=den) -if (num .LE. 0) then + if (num .LE. 0) then stepping_to_bc = .false. elseif ( ( tmpTimeInterval .LT. dtInterval * 2 ) .and. & ( tmpTimeInterval .GT. dtInterval ) ) then @@ -327,34 +327,26 @@ RECURSIVE SUBROUTINE adapt_timestep(grid, config_flags) history_interval_sec = grid%history_interval_s + grid%history_interval_m*60 + & grid%history_interval_h*3600 + grid%history_interval_d*86400 - time_to_output = history_interval_sec - & - mod( curr_secs, REAL(history_interval_sec) ) - num = INT(time_to_output * precision + 0.5) + num = INT(history_interval_sec * precision + 0.5) den = precision - call WRFU_TimeIntervalSet(tmpTimeInterval, Sn=num, Sd=den) + CALL WRFU_TimeIntervalSet(tmpTimeInterval, Sn=num, Sd=den) + + !Calc the time to output + tmpTimeInterval = tmpTimeInterval * (INT(curr_secs / REAL(history_interval_sec))+1) - & + (domain_get_current_time ( grid ) - domain_get_start_time ( grid ) ) if ( ( tmpTimeInterval .LT. dtInterval * 2 ) .and. & ( tmpTimeInterval .GT. dtInterval ) ) then - dtInterval = tmpTimeInterval / 2 + + num = INT(( real_time(tmpTimeInterval) * precision)/2 + 0.5) + den = precision + call WRFU_TimeIntervalSet(dtInterval, Sn=num, Sd=den) + use_last2 = .TRUE. grid%stepping_to_time = .TRUE. elseif (tmpTimeInterval .LE. dtInterval) then - ! - ! We will do some tricks here to assure that we fall exactly on an - ! output time. Without the tricks, round-off error causes problems! - ! - - ! - ! Calculate output time. We round to nearest history time to assure - ! we don't have any rounding error. - ! - output_time = NINT ( (curr_secs + time_to_output) / & - (history_interval_sec) ) * (history_interval_sec) - CALL WRFU_TimeIntervalSet(tmpTimeInterval, S=output_time) - dtInterval = tmpTimeInterval - & - (domain_get_current_time(grid) - domain_get_start_time(grid)) - + dtInterval = tmpTimeInterval use_last2 = .TRUE. grid%stepping_to_time = .TRUE. endif