Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 3 hourly frequency update in go-cart to allow start/stop regression in less than 3 hour chances #224

Merged
merged 6 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- To do: remove hooks to old (legacy) GOCART.data instances in CHEM and setup scripts
- Fixed rc file in legacy O3 component.
- Fixed issue #223 where Global dimension was being used for allocating a local array
-
-
### Added

### Changed
Expand Down
67 changes: 38 additions & 29 deletions ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_GridCompMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ subroutine Initialize (GC, IMPORT, EXPORT, CLOCK, RC)

type(ESMF_Calendar) :: calendar
type(ESMF_Time) :: currentTime
type(ESMF_Alarm) :: alarm_HNO3
type(ESMF_Time) :: ringTime
type(ESMF_TimeInterval) :: ringInterval
integer :: year, month, day, hh, mm, ss
Expand Down Expand Up @@ -400,25 +399,6 @@ subroutine Initialize (GC, IMPORT, EXPORT, CLOCK, RC)
call ESMF_AttributeGet(field, name='fnum', valueList=self%fnumSS, __RC__)
end if

! Se HNO3 recycle alarm
if (.not. data_driven) then
call ESMF_ClockGet(clock, calendar=calendar, currTime=currentTime, __RC__)
call ESMF_TimeGet(currentTime, YY=year, MM=month, DD=day, H=hh, M=mm, S=ss, __RC__)
call ESMF_TimeSet(ringTime, YY=year, MM=month, DD=day, H=0, M=0, S=0, __RC__)
call ESMF_TimeIntervalSet(ringInterval, H=3, calendar=calendar, __RC__)

do while (ringTime < currentTime)! DO WE NEED THIS?
ringTime = currentTime + ringInterval
end do

alarm_HNO3 = ESMF_AlarmCreate(Clock = clock, &
Name = 'HNO3_RECYCLE_ALARM', &
RingInterval = ringInterval, &
RingTime = currentTime, &
Enabled = .true. , &
Sticky = .false. , __RC__)
end if

! If this is a data component, the data is provided in the import
! state via ExtData instead of the actual GOCART children
! ----------------------------------------------------------------
Expand Down Expand Up @@ -731,7 +711,6 @@ subroutine Run2 (GC, import, export, clock, RC)
real, pointer, dimension(:,:) :: flux_ptr
real, pointer, dimension(:,:,:) :: fluxWT_ptr

type (ESMF_ALARM) :: alarm
logical :: alarm_is_ringing
integer :: i1, j1, i2, j2, km
real, target,allocatable, dimension(:,:,:) :: RH20,RH80
Expand Down Expand Up @@ -771,23 +750,20 @@ subroutine Run2 (GC, import, export, clock, RC)
allocate(dqa, mold=lwi, __STAT__)
allocate(drydepositionfrequency, mold=lwi, __STAT__)

! check hno3 alarm
call ESMF_ClockGetAlarm(clock, 'HNO3_RECYCLE_ALARM', alarm, __RC__)
alarm_is_ringing = ESMF_AlarmIsRinging(alarm, __RC__)
alarm_is_ringing = daily_alarm(clock,30000,_RC)

! Save local copy of HNO3 for first pass through run method regardless
thread = MAPL_get_current_thread()
workspace => self%workspaces(thread)

if (workspace%first) then
xhno3 = MAPL_UNDEF
workspace%first = .false.
end if
!if (workspace%first) then
!xhno3 = MAPL_UNDEF
!workspace%first = .false.
!end if

! Recycle HNO3 every 3 hours
if (alarm_is_ringing) then
xhno3 = NITRATE_HNO3
!call ESMF_AlarmRingerOff(alarm, __RC__)
end if

if (associated(NIPNO3AQ)) NIPNO3AQ(:,:) = 0.
Expand Down Expand Up @@ -1376,5 +1352,38 @@ subroutine monochromatic_aerosol_optics(state, rc)

end subroutine monochromatic_aerosol_optics

function daily_alarm(clock,freq,rc) result(is_ringing)
logical :: is_ringing
type(ESMF_Clock), intent(in) :: clock
integer, intent(in) :: freq
integer, optional, intent(out) :: rc

type(ESMF_Time) :: current_time
integer :: status,year,month,day,hour,minute,second,initial_time,int_seconds
integer :: nhh,nmm,nss,freq_sec

type(ESMF_TimeInterval) :: new_diff,esmf_freq
type(ESMF_Time) :: reff_time,new_esmf_time

call ESMF_ClockGet(clock,currTIme=current_time,_RC)
call ESMF_TimeGet(current_time,yy=year,mm=month,dd=day,h=hour,m=minute,s=second,_RC)

int_seconds = 0
call MAPL_UnpackTIme(freq,nhh,nmm,nss)
is_ringing = .false.
call ESMF_TimeSet(reff_time,yy=year,mm=month,dd=day,h=0,m=0,s=0,_RC)
new_esmf_time = reff_time
call ESMF_TimeIntervalSet(esmf_freq,h=nhh,m=nmm,s=nss ,_RC)
do while (int_seconds < 86400)
if ( new_esmf_time == current_time) then
is_ringing = .true.
exit
end if
new_esmf_time = new_esmf_time + esmf_freq
new_diff = new_esmf_time - reff_time
call ESMF_TimeIntervalGet(new_diff,s=int_seconds,_RC)
enddo
_RETURN(_SUCCESS)
end function

end module NI2G_GridCompMod
2 changes: 1 addition & 1 deletion ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_StateSpecs.rc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ category: INTERNAL
NO3an1 |kg kg-1 | xyz | C | MAPL_RestartOptional | T | DYNAMICS:TURBULENCE:MOIST | Nitrate size bin 001
NO3an2 |kg kg-1 | xyz | C | MAPL_RestartOptional | T | DYNAMICS:TURBULENCE:MOIST | Nitrate size bin 002
NO3an3 |kg kg-1 | xyz | C | MAPL_RestartOptional | T | DYNAMICS:TURBULENCE:MOIST | Nitrate size bin 003
XHNO3 |kg m-2 s-1| xyz | C | MAPL_RestartSkip | F | | buffer for NITRATE_HNO3
XHNO3 |kg m-2 s-1| xyz | C | | F | | buffer for NITRATE_HNO3

#********************************************************
#
Expand Down
76 changes: 42 additions & 34 deletions ESMF/GOCART2G_GridComp/SU2G_GridComp/SU2G_GridCompMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ subroutine Initialize (GC, IMPORT, EXPORT, CLOCK, RC)
type (ESMF_FieldBundle) :: Bundle_DP
type (wrap_) :: wrap
type (SU2G_GridComp), pointer :: self
type (ESMF_Alarm) :: alarm_H2O2

integer, allocatable :: mieTable_pointer(:)
integer :: i, dims(3), km
Expand Down Expand Up @@ -487,26 +486,6 @@ subroutine Initialize (GC, IMPORT, EXPORT, CLOCK, RC)
! ------------------
call determine_data_driven (COMP_NAME, data_driven, __RC__)

! Set H2O2 recycle alarm
! ----------------------
if (.not. data_driven) then
call ESMF_ClockGet(clock, calendar=calendar, currTime=currentTime, __RC__)
call ESMF_TimeGet(currentTime, YY=year, MM=month, DD=day, H=hh, M=mm, S=ss, __RC__)
call ESMF_TimeSet(ringTime, YY=year, MM=month, DD=day, H=0, M=0, S=0, __RC__)
call ESMF_TimeIntervalSet(ringInterval, H=3, calendar=calendar, __RC__)

do while (ringTime < currentTime)! DO WE NEED THIS?
ringTime = currentTime + ringInterval
end do

alarm_H2O2 = ESMF_AlarmCreate(Clock = clock, &
Name = 'H2O2_RECYCLE_ALARM', &
RingInterval = ringInterval, &
RingTime = currentTime, &
Enabled = .true. , &
Sticky = .false. , __RC__)
end if

! If this is a data component, the data is provided in the import
! state via ExtData instead of the actual GOCART children
! ----------------------------------------------------------------
Expand Down Expand Up @@ -980,7 +959,6 @@ subroutine Run2 (GC, import, export, clock, RC)
type (wrap_) :: wrap
type (SU2G_GridComp), pointer :: self
type (ESMF_Time) :: time
type (ESMF_Alarm) :: ALARM
type(MAPL_VarSpec), pointer :: InternalSpec(:)

integer :: nymd, nhms, iyr, imm, idd, ihr, imn, isc
Expand Down Expand Up @@ -1044,12 +1022,10 @@ subroutine Run2 (GC, import, export, clock, RC)
thread = MAPL_get_current_thread()
workspace => self%workspaces(thread)

call ESMF_ClockGetAlarm(clock, 'H2O2_RECYCLE_ALARM', alarm, __RC__)
alarm_is_ringing = ESMF_AlarmIsRinging(alarm, __RC__)
alarm_is_ringing = daily_alarm(clock,30000,_RC)
! recycle H2O2 every 3 hours
if (alarm_is_ringing) then
workspace%recycle_h2o2 = ESMF_AlarmIsRinging(alarm, __RC__)
!call ESMF_AlarmRingerOff(alarm, __RC__)
workspace%recycle_h2o2 = .true.
end if

allocate(xoh, mold=airdens, __STAT__)
Expand All @@ -1058,11 +1034,11 @@ subroutine Run2 (GC, import, export, clock, RC)
xoh = 0.0
xno3 = 0.0

if (workspace%firstRun) then
xh2o2 = MAPL_UNDEF
h2o2_init = MAPL_UNDEF
workspace%firstRun = .false.
end if
!if (workspace%firstRun) then
!xh2o2 = MAPL_UNDEF
!h2o2_init = MAPL_UNDEF
!workspace%firstRun = .false.
!end if

xh2o2 = h2o2_init

Expand Down Expand Up @@ -1484,6 +1460,38 @@ subroutine monochromatic_aerosol_optics(state, rc)

end subroutine monochromatic_aerosol_optics


end module SU2G_GridCompMod

function daily_alarm(clock,freq,rc) result(is_ringing)
logical :: is_ringing
type(ESMF_Clock), intent(in) :: clock
integer, intent(in) :: freq
integer, optional, intent(out) :: rc

type(ESMF_Time) :: current_time
integer :: status,year,month,day,hour,minute,second,initial_time,int_seconds
integer :: nhh,nmm,nss,freq_sec

type(ESMF_TimeInterval) :: new_diff,esmf_freq
type(ESMF_Time) :: reff_time,new_esmf_time

call ESMF_ClockGet(clock,currTIme=current_time,_RC)
call ESMF_TimeGet(current_time,yy=year,mm=month,dd=day,h=hour,m=minute,s=second,_RC)

int_seconds = 0
call MAPL_UnpackTIme(freq,nhh,nmm,nss)
is_ringing = .false.
call ESMF_TimeSet(reff_time,yy=year,mm=month,dd=day,h=0,m=0,s=0,_RC)
new_esmf_time = reff_time
call ESMF_TimeIntervalSet(esmf_freq,h=nhh,m=nmm,s=nss ,_RC)
do while (int_seconds < 86400)
if ( new_esmf_time == current_time) then
is_ringing = .true.
exit
end if
new_esmf_time = new_esmf_time + esmf_freq
new_diff = new_esmf_time - reff_time
call ESMF_TimeIntervalGet(new_diff,s=int_seconds,_RC)
enddo
_RETURN(_SUCCESS)
end function

end module SU2G_GridCompMod
2 changes: 1 addition & 1 deletion ESMF/GOCART2G_GridComp/SU2G_GridComp/SU2G_StateSpecs.rc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ category: INTERNAL
SO2 |kg kg-1| xyz | C | MAPL_RestartOptional | T | DYNAMICS:TURBULENCE:MOIST | Sulphur dioxide
SO4 |kg kg-1| xyz | C | MAPL_RestartOptional | T | DYNAMICS:TURBULENCE:MOIST | Sulphate aerosol
MSA |kg kg-1| xyz | C | MAPL_RestartOptional | T | DYNAMICS:TURBULENCE:MOIST | Methanesulphonic acid
H2O2_INIT |kg kg-1| xyz | C | MAPL_RestartSkip | F | | private H2O2 that is saved and used to initialize
H2O2_INIT |kg kg-1| xyz | C | | F | | private H2O2 that is saved and used to initialize


#********************************************************
Expand Down