Skip to content

Commit e590107

Browse files
authored
Merge pull request #1 from JeroBnd/JeroBnd-patch-1
Fix the dtInterval adjunstment on output time using adaptive and
2 parents 6109d9d + aed98f6 commit e590107

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

dyn_em/adapt_timestep_em.F

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ RECURSIVE SUBROUTINE adapt_timestep(grid, config_flags)
288288
den = precision
289289
CALL WRFU_TimeIntervalSet(tmpTimeInterval, Sn=num, Sd=den)
290290

291-
if (num .LE. 0) then
291+
if (num .LE. 0) then
292292
stepping_to_bc = .false.
293293
elseif ( ( tmpTimeInterval .LT. dtInterval * 2 ) .and. &
294294
( tmpTimeInterval .GT. dtInterval ) ) then
@@ -327,34 +327,26 @@ RECURSIVE SUBROUTINE adapt_timestep(grid, config_flags)
327327
history_interval_sec = grid%history_interval_s + grid%history_interval_m*60 + &
328328
grid%history_interval_h*3600 + grid%history_interval_d*86400
329329

330-
time_to_output = history_interval_sec - &
331-
mod( curr_secs, REAL(history_interval_sec) )
332-
num = INT(time_to_output * precision + 0.5)
330+
num = INT(history_interval_sec * precision + 0.5)
333331
den = precision
334-
call WRFU_TimeIntervalSet(tmpTimeInterval, Sn=num, Sd=den)
332+
CALL WRFU_TimeIntervalSet(tmpTimeInterval, Sn=num, Sd=den)
333+
334+
!Calc the time to output
335+
tmpTimeInterval = tmpTimeInterval * (INT(curr_secs / REAL(history_interval_sec))+1) - &
336+
(domain_get_current_time ( grid ) - domain_get_start_time ( grid ) )
335337

336338
if ( ( tmpTimeInterval .LT. dtInterval * 2 ) .and. &
337339
( tmpTimeInterval .GT. dtInterval ) ) then
338-
dtInterval = tmpTimeInterval / 2
340+
341+
num = INT(( real_time(tmpTimeInterval) * precision)/2 + 0.5)
342+
den = precision
343+
call WRFU_TimeIntervalSet(dtInterval, Sn=num, Sd=den)
344+
339345
use_last2 = .TRUE.
340346
grid%stepping_to_time = .TRUE.
341347

342348
elseif (tmpTimeInterval .LE. dtInterval) then
343-
!
344-
! We will do some tricks here to assure that we fall exactly on an
345-
! output time. Without the tricks, round-off error causes problems!
346-
!
347-
348-
!
349-
! Calculate output time. We round to nearest history time to assure
350-
! we don't have any rounding error.
351-
!
352-
output_time = NINT ( (curr_secs + time_to_output) / &
353-
(history_interval_sec) ) * (history_interval_sec)
354-
CALL WRFU_TimeIntervalSet(tmpTimeInterval, S=output_time)
355-
dtInterval = tmpTimeInterval - &
356-
(domain_get_current_time(grid) - domain_get_start_time(grid))
357-
349+
dtInterval = tmpTimeInterval
358350
use_last2 = .TRUE.
359351
grid%stepping_to_time = .TRUE.
360352
endif

0 commit comments

Comments
 (0)