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

Clean up CanopyHydrology #503

Closed
billsacks opened this issue Sep 6, 2018 · 2 comments · Fixed by #769
Closed

Clean up CanopyHydrology #503

billsacks opened this issue Sep 6, 2018 · 2 comments · Fixed by #769
Assignees
Labels
type: code cleanup improving internal code structure

Comments

@billsacks
Copy link
Member

Before implementing water isotopes in CanopyHydrology (#360 ), there is some general cleanup that needs to be done.

First, we should probably separate this into at least three routines:

  • Snow cover fraction
  • Snow initialization
  • Canopy Hydrology (though it does more than that)

We'll separate flux calculations from state updates so that we can make tracer update calls at the appropriate points.

For now, we'll keep state updates in this module, done at the point where they are currently done (though in separate subroutines). Later, we might merge some state updates (which would change answers).

@billsacks billsacks added the type: enhancement new capability or improved behavior of existing capability label Sep 6, 2018
@billsacks billsacks self-assigned this Sep 6, 2018
@billsacks billsacks added this to To Do in Water isotopes Sep 6, 2018
@billsacks
Copy link
Member Author

billsacks commented Sep 6, 2018

Refactoring snow cover fraction calculations in CanopyHydrology

We'll keep in place the original fsca formulation (n&y 07) - probably giving it a better name than just origfflag [edit (2019-04-24) I think this meant 'oldfflag' rather than 'origfflag']. Note that that is the form used in Noah-MP.

Note that, the way things are currently structured, it does the new frac_sno calculation, then possibly overwrites it with the old.

And note that there are order differences for the new vs. old: New needs to compute frac_sno, then update snow_depth based on that; old needs to first update snow_depth, then compute frac_sno based on that. So we should have a routine that updates both frac_sno and snow_depth, and let individual parameterizations do that in whatever order they want.

Then this will be lumped with the FSCA block above it:

https://github.com/ESCOMP/ctsm/blob/5295f61ed21bd6b9ff0d7770d064b1328f030058/src/biogeophys/CanopyHydrologyMod.F90#L548-L554

whereas this will be lumped with the "original fsca formulation" below it:

https://github.com/ESCOMP/ctsm/blob/5295f61ed21bd6b9ff0d7770d064b1328f030058/src/biogeophys/CanopyHydrologyMod.F90#L555-L558

i.e., it is currently assumed that subgridflag==1 is combined with oldfflag==0, and vice versa (see also #502 ).

So we'll end up with code that looks like this:

select case (snow_cover_frac_method)
case (method_snow_cover_frac_clm5)
   call snow_cover_frac_clm5(..., frac_sno, snow_depth)
case (method_snow_cover_frac_niu)
   call snow_cover_frac_niu(..., frac_sno, snow_depth)
end select

subroutine snow_cover_frac_clm5(..., frac_sno, snow_depth)
  ! First, compute frac_sno

  ! Hmmmm, need to determine what to do about the lun%urbpoi check in the current code.
  ! (I feel like we had to deal with something similar for soil hydrology - i.e., urban
  ! always working the old way. Check how we handled that.)
  if (frac_sno(c) > 0._r8)then
     snow_depth(c)=snow_depth(c) + newsnow(c)/(bifall(c) * frac_sno(c))
  else
     snow_depth(c)=0._r8
  end if
end subroutine snow_cover_frac_clm5

subroutine snow_cover_frac_niu(..., frac_sno, snow_depth)
  snow_depth(c)=snow_depth(c)+newsnow(c)/bifall(c)

  ! Then compute frac_sno
end subroutine snow_cover_frac_niu

@billsacks
Copy link
Member Author

The part that actually deals with canopy hydrology is done (will come to master in ctsm1.0.dev041). The other pieces (fractions and snow initialization) still need to be done.

billsacks added a commit that referenced this issue May 17, 2019
Add water tracers to CanopyHydrologyMod

Major overhaul of CanopyHydrologyMod in order to support water tracers.

The part of CanopyHydrology that was actually dealing with canopy
hydrology has now been broken out into a number of small routines in
order to separate flux calculations from state updates. This is needed
in order to calculate tracer versions of the relevant variables, which
is now done here.

The parts of CanopyHydrology that were NOT dealing with canopy hydrology
have been moved to more appropriate homes. They have not yet been
tracerized, but will be soon.

This also makes some minor changes to diagnostic fields related to
canopy hydrology. Of particular note: QDRIP now has a different meaning:
it now corresponds to the excess liquid water that runs off from the
canopy (and is inactive by default).

The design of this broken-out code was developed in consultation with
Mike Barlage, Erik Kluzek, Negin Sobhani, Sean Swenson and Mariana
Vertenstein. We plan to apply this design moving forward to other parts
of the code that need tracerization. See also
<https://github.com/billsacks/prototypes-ctsm-canopyhydrology_tracers>.

- Resolves #360 - Implement water isotopes for
  CanopyHydrology
- Resolves #709 - QDRIP diagnostic field misleadingly named
- Partially addresses #503 - Clean up CanopyHydrology
  (We still need to clean up / tracerize the parts that have now been
  moved elsewhere.)
slevis-lmwg pushed a commit to slevis-lmwg/ctsm that referenced this issue May 18, 2019
Add water tracers to CanopyHydrologyMod

Major overhaul of CanopyHydrologyMod in order to support water tracers.

The part of CanopyHydrology that was actually dealing with canopy
hydrology has now been broken out into a number of small routines in
order to separate flux calculations from state updates. This is needed
in order to calculate tracer versions of the relevant variables, which
is now done here.

The parts of CanopyHydrology that were NOT dealing with canopy hydrology
have been moved to more appropriate homes. They have not yet been
tracerized, but will be soon.

This also makes some minor changes to diagnostic fields related to
canopy hydrology. Of particular note: QDRIP now has a different meaning:
it now corresponds to the excess liquid water that runs off from the
canopy (and is inactive by default).

The design of this broken-out code was developed in consultation with
Mike Barlage, Erik Kluzek, Negin Sobhani, Sean Swenson and Mariana
Vertenstein. We plan to apply this design moving forward to other parts
of the code that need tracerization. See also
<https://github.com/billsacks/prototypes-ctsm-canopyhydrology_tracers>.

- Resolves ESCOMP#360 - Implement water isotopes for
  CanopyHydrology
- Resolves ESCOMP#709 - QDRIP diagnostic field misleadingly named
- Partially addresses ESCOMP#503 - Clean up CanopyHydrology
  (We still need to clean up / tracerize the parts that have now been
  moved elsewhere.)

Conflicts:
	src/biogeophys/CanopyHydrologyMod.F90
@billsacks billsacks added type: code cleanup improving internal code structure and removed type: enhancement new capability or improved behavior of existing capability labels May 24, 2019
@billsacks billsacks moved this from In progress to Done but not on master in Water isotopes Jul 27, 2019
Water isotopes automation moved this from Done but not on master to Done Aug 6, 2019
billsacks added a commit that referenced this issue Aug 6, 2019
Modularize snow cover fraction method

This tag moves the calculation of frac_sno - and the related updates of
snow_depth - into a new set of classes, with one class for each
parameterization (Niu & Yang 2007 and Swenson & Lawrence 2012).

Previously, the code always calculated frac_sno the new way, but then
possibly overwrote it if using the older Niu & Yang method. The new code
cleans this up, only doing the calculations that are needed for each
method.

In addition, other code that is specific to one of the two methods is
now moved to a home that makes this dependence on method explicit. This
includes the addition of newsnow to int_snow: previously, int_snow was
always updated using an equation specific to the newer CLM5
parameterization of frac_sno, which was not appropriate if using the Niu
& Yang parameterization; this doesn't make a difference currently, since
int_snow is only referenced if using the Swenson & Lawrence
parameterization, but this clears up some confusion. Also, time-constant
parameters read from namelist or the netCDF parameter file now reside in
the appropriate class rather than being more global.

This tag also renames two namelist options to increase clarity:
- subgridflag is renamed to use_subgrid_fluxes, and is now a logical
- oldfflag is renamed to snow_cover_fraction_method, and is now a string

Resolves #502
Resolves #503
Resolves #571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: code cleanup improving internal code structure
Projects
Development

Successfully merging a pull request may close this issue.

2 participants