Skip to content

Commit b4c3d9d

Browse files
authored
Merge pull request #347 from fvitt/cmeps0.14.18_lightning_coupling
Cloud-to-ground lightning flash frequency coupling
2 parents 26f997c + ac4d591 commit b4c3d9d

File tree

4 files changed

+144
-2
lines changed

4 files changed

+144
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
module shr_lightning_coupling_mod
2+
3+
!========================================================================
4+
! Module for handling namelist variables related to lightning coupling
5+
!========================================================================
6+
7+
use ESMF , only : ESMF_VMGetCurrent, ESMF_VM, ESMF_VMGet
8+
use ESMF , only : ESMF_LOGERR_PASSTHRU, ESMF_SUCCESS
9+
use ESMF , only : ESMF_VMBroadCast, ESMF_Logical, assignment(=)
10+
use shr_sys_mod , only : shr_sys_abort
11+
use shr_log_mod , only : shr_log_getLogUnit
12+
use shr_nl_mod , only : shr_nl_find_group_name
13+
use nuopc_shr_methods, only : chkerr
14+
15+
implicit none
16+
private
17+
18+
! !PUBLIC MEMBER FUNCTIONS
19+
public shr_lightning_coupling_readnl ! Read namelist
20+
21+
character(len=*), parameter :: &
22+
u_FILE_u=__FILE__
23+
24+
!====================================================================================
25+
CONTAINS
26+
!====================================================================================
27+
28+
subroutine shr_lightning_coupling_readnl(NLFilename, atm_provides_lightning_out)
29+
30+
!========================================================================
31+
! reads lightning_coupling_nl namelist and returns a variable specifying
32+
! if atmosphere model provides lightning flash frequency field to mediator
33+
!========================================================================
34+
35+
! input/output variables
36+
character(len=*), intent(in) :: NLFilename ! Namelist filename
37+
logical, intent(out) :: atm_provides_lightning_out ! if TRUE atm will provide lightning flash frequency
38+
39+
!----- local -----
40+
logical :: atm_provides_lightning
41+
type(ESMF_VM) :: vm
42+
integer :: unitn ! namelist unit number
43+
integer :: ierr ! error code
44+
logical :: exists ! if file exists or not
45+
type(ESMF_Logical):: ltmp(1)
46+
integer :: rc
47+
integer :: localpet
48+
integer :: mpicom
49+
integer :: s_logunit
50+
character(len=*), parameter :: atm_ozone_frequency_not_present = 'NOT_PRESENT'
51+
character(len=*), parameter :: subname = '(shr_lightning_coupling_readnl) '
52+
! ------------------------------------------------------------------
53+
54+
namelist /lightning_coupling_nl/ atm_provides_lightning
55+
56+
rc = ESMF_SUCCESS
57+
58+
atm_provides_lightning_out = .false.
59+
ltmp(1) = .false.
60+
61+
!--- Open and read namelist ---
62+
if ( len_trim(NLFilename) == 0 ) then
63+
call shr_sys_abort( subname//'ERROR: nlfilename not set' )
64+
end if
65+
call shr_log_getLogUnit(s_logunit)
66+
call ESMF_VMGetCurrent(vm, rc=rc)
67+
if (chkerr(rc,__LINE__,u_FILE_u)) return
68+
69+
call ESMF_VMGet(vm, localPet=localpet, mpiCommunicator=mpicom, rc=rc)
70+
if (chkerr(rc,__LINE__,u_FILE_u)) return
71+
72+
if (localpet==0) then
73+
! ------------------------------------------------------------------------
74+
! Set default values in case namelist file doesn't exist, lightning_coupling_nl group
75+
! doesn't exist within the file, or a given variable isn't present in the namelist
76+
! group in the file.
77+
! ------------------------------------------------------------------------
78+
atm_provides_lightning = .false.
79+
80+
! ------------------------------------------------------------------------
81+
! Read namelist file
82+
! ------------------------------------------------------------------------
83+
inquire( file=trim(NLFileName), exist=exists)
84+
if ( exists ) then
85+
open(newunit=unitn, file=trim(NLFilename), status='old' )
86+
write(s_logunit,'(a)') subname,'Read in lightning_coupling_nl namelist from: ', trim(NLFilename)
87+
call shr_nl_find_group_name(unitn, 'lightning_coupling_nl', ierr)
88+
if (ierr == 0) then
89+
! Note that ierr /= 0 means no namelist is present.
90+
read(unitn, lightning_coupling_nl, iostat=ierr)
91+
if (ierr > 0) then
92+
call shr_sys_abort(subname//'problem reading lightning_coupling_nl')
93+
end if
94+
end if
95+
close( unitn )
96+
end if
97+
98+
ltmp(1) = atm_provides_lightning
99+
100+
end if
101+
102+
! ------------------------------------------------------------------------
103+
! Broadcast values to all tasks
104+
! ------------------------------------------------------------------------
105+
call ESMF_VMBroadcast(vm, ltmp, count=1, rootPet=0, rc=rc)
106+
if (chkerr(rc,__LINE__,u_FILE_u)) return
107+
108+
atm_provides_lightning_out = ltmp(1)
109+
110+
end subroutine shr_lightning_coupling_readnl
111+
112+
end module shr_lightning_coupling_mod

cime_config/namelist_definition_drv_flds.xml

+14-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
</entry>
143143

144144
<!-- ======================================================================================== -->
145-
<!-- Ozone control -->
145+
<!-- Ozone control -->
146146
<!-- ======================================================================================== -->
147147

148148
<entry id="atm_ozone_frequency">
@@ -157,4 +157,17 @@
157157
</desc>
158158
</entry>
159159

160+
<!-- ======================================================================================== -->
161+
<!-- Lightning -->
162+
<!-- ======================================================================================== -->
163+
164+
<entry id="atm_provides_lightning">
165+
<type>logical</type>
166+
<category>lightning_coupling</category>
167+
<group>lightning_coupling_nl</group>
168+
<desc>
169+
If TRUE atmosphere model will provide prognosed lightning flash frequency (flashes per minute).
170+
</desc>
171+
</entry>
172+
160173
</entry_id>

mediator/esmFldsExchange_cesm_mod.F90

+13
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,19 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
399399
end if
400400
end if
401401
! ---------------------------------------------------------------------
402+
! to lnd: cld to grnd lightning flash freq
403+
! ---------------------------------------------------------------------
404+
if (phase == 'advertise') then
405+
call addfld_from(compatm, 'Sa_lightning')
406+
call addfld_to(complnd, 'Sa_lightning')
407+
else
408+
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_lightning', rc=rc) .and. &
409+
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_lightning', rc=rc)) then
410+
call addmap_from(compatm, 'Sa_lightning', complnd, mapbilnr, 'one', atm2lnd_map)
411+
call addmrg_to(complnd, 'Sa_lightning', mrg_from=compatm, mrg_fld='Sa_lightning', mrg_type='copy')
412+
end if
413+
end if
414+
! ---------------------------------------------------------------------
402415
! to lnd: temperature at the lowest model level from atm
403416
! ---------------------------------------------------------------------
404417
if (phase == 'advertise') then

mediator/fd_cesm.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@
325325
canonical_units: mol/mol
326326
description: atmosphere export - O3 in the lowest model layer (prognosed or prescribed)
327327
#
328+
- standard_name: Sa_lightning
329+
canonical_units: /min
330+
description: atmosphere export - lightning flash freqency
331+
#
328332
- standard_name: Sa_topo
329333
alias: inst_surface_height
330334
canonical_units: m
@@ -745,7 +749,7 @@
745749
description: sea-ice export - ice thickness
746750
#
747751
- standard_name: Si_floediam
748-
canonical_units: m
752+
canonical_units: m
749753
description: sea-ice export - ice floe diameter
750754
#
751755
#-----------------------------------

0 commit comments

Comments
 (0)