Skip to content

Commit 92dcd48

Browse files
Andy StokelyAndy Stokely
authored andcommitted
Updated tests
1 parent ba66a5a commit 92dcd48

File tree

2 files changed

+32
-52
lines changed

2 files changed

+32
-52
lines changed

src/core_test/mpas_test_core_timekeeping_tests.F

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,29 @@ subroutine test_window_alarm(case_idx, ierr)
505505
end if
506506

507507
!-----------------------------------------------------------------------
508-
! Case 16: Outside window after direction change (D → E → backward)
509-
! Alarm should not ring outside window when clock direction flips.
508+
! Case 16: Reset at window start and reverse direction to exit window
509+
!> Alarm should not ring when moving backward out of the window after
510+
!> being reset at the window start.
510511
!-----------------------------------------------------------------------
511512
case(16)
513+
call advance_clock_n_times(f%clock, f%steps_to_window_start)
514+
call mpas_reset_clock_alarm(f%clock, f%alarm_id)
515+
call mpas_set_clock_direction(f%clock, MPAS_BACKWARD)
516+
call advance_clock_n_times(f%clock, f%steps_to_window_start/2)
517+
518+
ringing = mpas_is_alarm_ringing(f%clock, f%alarm_id)
519+
if (ringing) then
520+
call mpas_log_write('FAIL: Alarm rang after reset when moving backward out of window')
521+
ierr = ierr + 1
522+
else
523+
call mpas_log_write('PASS: Alarm did not ring after reset when moving backward out of window')
524+
end if
525+
526+
!-----------------------------------------------------------------------
527+
! Case 17: Outside window after direction change (D → E → backward)
528+
! Alarm should not ring outside window when clock direction flips.
529+
!-----------------------------------------------------------------------
530+
case(17)
512531
call advance_clock_n_times(f%clock, f%steps_to_window_end + f%num_steps_post_window/2)
513532
call mpas_set_clock_direction(f%clock, MPAS_BACKWARD)
514533
ringing = mpas_is_alarm_ringing(f%clock, f%alarm_id)
@@ -540,7 +559,7 @@ integer function mpas_window_alarm_tests(domain) result(ierr)
540559
integer :: i, ierr_local
541560

542561
ierr = 0
543-
do i = 1, 16
562+
do i = 1, 17
544563
ierr_local = 0
545564
call test_window_alarm(i, ierr_local)
546565
ierr = ierr + ierr_local

src/framework/mpas_timekeeping.F

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -831,19 +831,17 @@ end subroutine mpas_print_alarm
831831
!> within the active start and stop times of the given alarm. If so,
832832
!> it returns `.true.`. An optional error code may also be returned.
833833
!-----------------------------------------------------------------------
834-
logical function mpas_is_alarm_active(clock, alarm, ierr)
834+
logical function mpas_is_alarm_active(clock, alarm, time, ierr)
835835
implicit none
836836
type(MPAS_Clock_type), intent(in) :: clock
837-
type(MPAS_Alarm_type), pointer :: alarm
838-
integer, intent(out), optional :: ierr
839-
type(MPAS_Time_type) :: now
837+
type(MPAS_Alarm_type), pointer :: alarm
838+
type(MPAS_Time_type), intent(in) :: time
839+
integer, intent(out), optional :: ierr
840840

841841
if (present(ierr)) ierr = 0
842842

843-
now = mpas_get_clock_time(clock, MPAS_NOW, ierr=ierr)
844-
mpas_is_alarm_active = mpas_time_in_interval( &
845-
alarm%activeStartTime, alarm%activeStopTime, now)
846-
843+
mpas_is_alarm_active = (alarm % activeStartTime <= time &
844+
.and. time <= alarm % activeStopTime)
847845
end function mpas_is_alarm_active
848846

849847

@@ -866,48 +864,11 @@ logical function mpas_prev_ring_in_window(alarm)
866864
implicit none
867865
type(MPAS_Alarm_type), pointer :: alarm
868866

869-
mpas_prev_ring_in_window = mpas_time_in_interval( &
870-
alarm%activeStartTime, alarm%activeStopTime, &
871-
alarm%prevRingTime, is_open_interval=.true.)
872-
867+
mpas_prev_ring_in_window = (alarm % activeStartTime <= alarm % prevRingTime &
868+
.and. alarm % prevRingTime < alarm % activeStopTime)
873869
end function mpas_prev_ring_in_window
874870

875871

876-
!-----------------------------------------------------------------------
877-
! function mpas_time_in_interval
878-
!
879-
!> \brief Test if a time lies within a start/stop interval.
880-
!> \author Andy Stokely
881-
!> \date 10/01/2025
882-
!> \details Returns `.true.` if `time` falls between `start_time` and
883-
!> `end_time`. By default, the interval is closed `[start,end]`.
884-
!> If the optional `is_open_interval` flag is present and `.true.`,
885-
!> the interval is treated as open `(start,end)`, excluding the boundaries.
886-
!-----------------------------------------------------------------------
887-
logical function mpas_time_in_interval(start_time, end_time, time, is_open_interval)
888-
implicit none
889-
type(MPAS_Time_type), intent(in) :: start_time
890-
type(MPAS_Time_type), intent(in) :: end_time
891-
type(MPAS_Time_type), intent(in) :: time
892-
logical, intent(in), optional :: is_open_interval
893-
logical :: open_interval
894-
895-
mpas_time_in_interval = .false.
896-
open_interval = .false.
897-
if (present(is_open_interval)) then
898-
open_interval = is_open_interval
899-
end if
900-
if (time > start_time .and. time < end_time) then
901-
mpas_time_in_interval = .true.
902-
else if (.not. open_interval) then
903-
if (time == start_time .or. time == end_time) then
904-
mpas_time_in_interval = .true.
905-
end if
906-
end if
907-
908-
end function mpas_time_in_interval
909-
910-
911872
logical function mpas_is_alarm_ringing(clock, alarmID, interval, ierr)
912873

913874
implicit none
@@ -997,7 +958,7 @@ logical function mpas_in_ringing_envelope(clock, alarmPtr, interval, ierr)
997958
end if
998959

999960
if (alarmThreshold <= alarmNow) then
1000-
if (mpas_is_alarm_active(clock, alarmPtr, ierr) &
961+
if (mpas_is_alarm_active(clock, alarmPtr, alarmNow, ierr) &
1001962
.or. mpas_prev_ring_in_window(alarmPtr)) then
1002963
mpas_in_ringing_envelope = .true.
1003964
end if
@@ -1013,7 +974,7 @@ logical function mpas_in_ringing_envelope(clock, alarmPtr, interval, ierr)
1013974
end if
1014975

1015976
if (alarmThreshold >= alarmNow) then
1016-
if (mpas_is_alarm_active(clock, alarmPtr, ierr) &
977+
if (mpas_is_alarm_active(clock, alarmPtr, alarmNow, ierr) &
1017978
.or. mpas_prev_ring_in_window(alarmPtr)) then
1018979
mpas_in_ringing_envelope = .true.
1019980
end if

0 commit comments

Comments
 (0)