Closed awlostowski-noaa closed 2 months ago
subroutine c_muskingcungenwm(dt, qup, quc, qdp, ql, dx, bw, tw, twcc,&
n, ncc, cs, s0, velp, depthp, qdc, velc, depthc, ck, cn, X) bind(c) # adjust args
real(c_float), intent(in) :: dt
real(c_float), intent(in) :: qup, quc, qdp, ql
real(c_float), intent(in) :: dx, bw, tw, twcc, n, ncc, cs, s0
real(c_float), intent(in) :: velp, depthp
real(c_float), intent(out) :: qdc, velc, depthc
real(c_float), intent(out) :: ck, cn, X # change these to intent out
call muskingcungenwm(dt, qup, quc, qdp, ql, dx, bw, tw, twcc,&
n, ncc, cs, s0, velp, depthp, qdc, velc, depthc, ck, cn, X)
@cython.boundscheck(False)
cdef void muskingcunge(float dt,
float qup,
float quc,
float qdp,
float ql,
float dx,
float bw,
float tw,
float twcc,
float n,
float ncc,
float cs,
float s0,
float velp,
float depthp,
QVD *rv) nogil:
cdef:
float qdc = 0.0
float depthc = 0.0
float velc = 0.0
c_muskingcungenwm(
&dt,
&qup,
&quc,
&qdp,
&ql,
&dx,
&bw,
&tw,
&twcc,
&n,
&ncc,
&cs,
&s0,
&velp,
&depthp,
&qdc,
&velc,
&depthc) # three additional returns in here.
rv.qdc = qdc
rv.depthc = depthc
rv.velc = velc
@awlostowski-noaa to help clarify some of your questions:
*rv
is a C level pointer. It points to a struct to hold output values. It is there to avoid allocating memory for every call to muskingcunge (this was a critical optimization early on). We allocate the struct once, and reuse it for all computations, copying the values when needed.Addressed in PRs 226, 380
Courant metrics are not immediately available in the v02 framework and we need to change this. While the Fortran Muskingum-Cunge routing subroutine
muskingcungenwm
inMCsingleSegStime_f2py_NOLOOP.f90
calculates and outputs Courant metrics (cn
,ck
, andX
), these variables are silently dropped in the subroutinec_muskingcungenwm
inpyMCsingleSegStime_NoLoop.f90
.Proposed solution steps
pyMCsingleSegStime_NoLoop.f90
such thatc_muskingcungenwm
returnsck
,cn
, andX
. Specifically, designate these variables as intent out and expand the subroutine argument list accordingly.fortran_wrappers.pyx
such thatc_muskingcungenwm
arguments includeck
,cn
, andX
.reach.pyx
as above. not sure what*rv
means, but seems important in packaging return variables. Should we add Courant metrics to this grouping?mc_reach.compute_reach_kernel
to handle additional returns. Perhapsoutput_buf
can carry additional Courant metric returns?mc_reach.compute_network
. Expand size ofout_view
to accept Courant metrics? Create a new array, likeflowveldepth
, to store network-wide Courant results.mc_reach.compute_network
to optionally return Courant metrics.ping @jameshalgren