Closed billsacks closed 5 years ago
In not-quite-working code, this will look something like this:
subroutine ApplyIrrigation(this, bounds, water_inst)
...
associate( &
qflx_irrig_patch => water_inst%waterfluxbulk_inst%qflx_irrig_patch , & ! Output: [real(r8) (:)] patch irrigation flux (mm H2O/s)
qflx_irrig_col => water_inst%waterfluxbulk_inst%qflx_irrig_col & ! Output: [real(r8) (:)] col irrigation flux (mm H2O/s)
)
do p = bounds%begp, bounds%endp
g = patch%gridcell(p)
if (this%n_irrig_steps_left_patch(p) > 0) then
qflx_irrig_patch(p) = this%irrig_rate_patch(p)
this%qflx_irrig_demand_patch(p) = this%irrig_rate_demand_patch(p)
this%n_irrig_steps_left_patch(p) = this%n_irrig_steps_left_patch(p) - 1
else
qflx_irrig_patch(p) = 0._r8
this%qflx_irrig_demand_patch(p) = 0._r8
end if
end do
do i = water_inst%tracers_beg, water_inst%tracers_end
call CalcTracerFromBulkFixedRatio( &
bulk = qflx_irrig_patch(begp:endp), &
ratio = water_inst%bulk_and_tracers(i)%info%get_ratio(), & ! maybe make this easier to get, without needing to have so many levels
tracer = water_inst%bulk_and_tracers(i)%waterflux_inst%qflx_irrig_patch(begp:endp))
end do
do i = water_inst%bulk_and_tracers_beg, water_inst%bulk_and_tracers_end
call p2c (bounds = bounds, &
parr = water_inst%bulk_and_tracers(i)%waterflux_inst%qflx_irrig_patch(begp:endp), &
carr = water_inst%bulk_and_tracers(i)%waterflux_inst%qflx_irrig_col(begc:endc), &
p2c_scale_type = 'unity')
end do
end associate
With the groundwater irrigation extraction that @swensosc added in ctsm1.0.dev020, this calculation of irrigation tracer fluxes seems to be much more challenging. There are two factors leading to this challenge:
The code is written to compute the total irrigation withdrawal from groundwater, then use this to compute the application fluxes (drip/sprinkler), then later divide this total withdrawal by layer. But I think that, for tracer fluxes to be computer correctly, we need to reorder this, so that the per-layer withdrawals are determined before determining the application fluxes. This is because the application flux needs to know the tracer concentrations of the source, which requires knowing which layers the source is drawing from.
This is made more challenging because of the mix of patch-level and column-level variables at play: irrigation demand is patch-level, groundwater availability and extraction is column-level, but application is back to patch-level.
I think I see how to solve these problems, but I'll need to rework ApplyIrrigation fairly substantially to accomplish it.
ApplyIrrigation is called before CanopyHydrology, so we should get the tracer versions of variables in that routine set before moving on to CanopyHydrology.