Skip to content

Commit edbe781

Browse files
Merge pull request #20 from andrew-c-ross/runoff-addition-fix
Keep track of whether runoff has been added to stf
2 parents 1cf5f21 + 389e8de commit edbe781

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

generic_tracers/generic_tracer_utils.F90

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ module g_tracer_utils
257257
logical :: flux_drydep = .false. !Is there a dry deposition?
258258
logical :: flux_bottom = .false. !Is there a flux through bottom?
259259
logical :: has_btm_reservoir = .false. !Is there a flux bottom reservoir?
260+
logical :: runoff_added_to_stf = .false. ! Has flux in from runoff been added to stf?
260261

261262
! Flux identifiers to be set by aof_set_coupler_flux()
262263
integer :: flux_gas_ind = -1
@@ -2089,7 +2090,16 @@ subroutine g_tracer_set_2D(g_tracer_list,name,member,array,isd,jsd,weight)
20892090
case ('sc_no')
20902091
g_tracer%sc_no = w0*g_tracer%sc_no + w1*array
20912092
case ('stf')
2092-
g_tracer%stf = w0*g_tracer%stf + w1*array
2093+
! Check for edge case where the new value is a weighted combination of old and new values
2094+
! and the old value had runoff added to it later. In this case, the result would be
2095+
! invalid if the new value did not also have runoff added to it (which is not known).
2096+
if (w1 < 1 .and. g_tracer%runoff_added_to_stf) then
2097+
call mpp_error(FATAL, trim(sub_name)//&
2098+
": Cannot set stf to a weighted combination of values with and without runoff.")
2099+
else
2100+
g_tracer%stf = w0*g_tracer%stf + w1*array
2101+
g_tracer%runoff_added_to_stf = .false.
2102+
endif
20932103
case ('stf_gas')
20942104
g_tracer%stf_gas= w0*g_tracer%stf_gas + w1*array
20952105
case ('deltap')
@@ -2234,6 +2244,7 @@ subroutine g_tracer_set_real(g_tracer_list,name,member,value)
22342244
g_tracer%sc_no = value
22352245
case ('stf')
22362246
g_tracer%stf = value
2247+
g_tracer%runoff_added_to_stf = .false.
22372248
case ('stf_gas')
22382249
g_tracer%stf_gas = value
22392250
case ('deltap')

0 commit comments

Comments
 (0)