Skip to content

Commit

Permalink
Merge pull request #161 from niklaswr/CLM35TileApproach
Browse files Browse the repository at this point in the history
Enable maxpft>1
  • Loading branch information
niklaswr authored Mar 28, 2023
2 parents fab9263 + 85359a2 commit cbca8ec
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
13 changes: 8 additions & 5 deletions bldsva/build_tsmp.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ getDefaults(){
def_mode="0" #0: let flags decide, 1:batch, 2:interactive
def_cplscheme="true"
def_readCLM="false"
def_maxpft="1" # (CLM default is 4)
def_freeDrain="false"

#compiler optimization
Expand Down Expand Up @@ -94,6 +95,7 @@ setDefaults(){

freeDrain=$def_freeDrain
readCLM=$def_readCLM
maxpft=${def_maxpft}
cplscheme=$def_cplscheme
mode=$def_mode

Expand Down Expand Up @@ -563,9 +565,10 @@ printState(){
print "${cred}(25)${cnormal} profiling (default=$def_profiling): ${cgreen}$profiling ${cnormal}"
print "${cred}(26)${cnormal} Couple-Scheme (default=$def_cplscheme): ${cgreen}$cplscheme ${cnormal}"
print "${cred}(27)${cnormal} readCLM: Consistently read CLM-mask (default=$def_readCLM): ${cgreen}$readCLM ${cnormal}"
print "${cred}(28)${cnormal} Compiles ParFlow with free drainage feature (default=$def_freeDrain): ${cgreen}$freeDrain ${cnormal}"
print "${cred}(29)${cnormal} compiler (default=$defaultcompiler): ${cgreen}$compiler ${cnormal}"
print "${cred}(30)${cnormal} processor (default=$defaultprocessor): ${cgreen}$processor ${cnormal}"
print "${cred}(28)${cnormal} maxpft: Set maxpft per grid cell for CLM (default=$def_maxpft): ${cgreen}$maxpft ${cnormal}"
print "${cred}(29)${cnormal} Compiles ParFlow with free drainage feature (default=$def_freeDrain): ${cgreen}$freeDrain ${cnormal}"
print "${cred}(30)${cnormal} compiler (default=$defaultcompiler): ${cgreen}$compiler ${cnormal}"
print "${cred}(31)${cnormal} processor (default=$defaultprocessor): ${cgreen}$processor ${cnormal}"
}

check(){
Expand Down Expand Up @@ -869,6 +872,7 @@ getGitInfo(){
USAGE+="[c:combination? Combination of component models.]:[combination:='$def_combination']"
USAGE+="[C:cplscheme? Couple-Scheme for CLM/COS coupling.]:[cplscheme:='$def_cplscheme']"
USAGE+="[r:readclm? Flag to consistently read in CLM mask.]:[readclm:='$def_readCLM']"
USAGE+="[f:maxpft? Flag to control maxpft per grid cell in CLM.]:[maxpft:='$def_maxpft']"
USAGE+="[d:freedrain? Compiles ParFlow with free drainage feature.]:[freedrain:='$def_freeDrain']"

USAGE+="[W:optoas?Build option for Oasis.]:[optoas:='${def_options["oas"]}']{"
Expand Down Expand Up @@ -922,6 +926,7 @@ getGitInfo(){
c) combination="$OPTARG" ; args=1 ;;
C) cplscheme="$OPTARG" ; args=1 ;;
r) readCLM="$OPTARG" ; args=1 ;;
f) maxpft="$OPTARG" ; args=1 ;;
d) freeDrain="$OPTARG" ; args=1 ;;
#DA
T) options+=(["icon"]="$OPTARG") ; args=1 ;;
Expand Down Expand Up @@ -950,8 +955,6 @@ getGitInfo(){
done




comment " source list with supported machines and configurations"
. $rootdir/bldsva/supported_versions.ksh
check
Expand Down
64 changes: 51 additions & 13 deletions bldsva/intf_oas3/clm3_5/tsmp/Biogeophysics1Mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,20 @@ subroutine Biogeophysics1(lbg, ubg, lbc, ubc, lbp, ubp, &
real(r8) :: psit !negative potential of soil
real(r8) :: hr !relative humidity
real(r8) :: wx !partial volume of ice and water of surface layer
!NOTE: Arrays can start from arbitrary index...
! So in CLM the distributed arraies (over diff. CPUs) does take the index
! from the original array.
! original_array(0:10) --> array1(0:5) and array(6:10)
! The Uper and lower index bound is stored in `lbg`, `ubg`, etc.
real(r8) :: tmp_displacement_max(lbg:ubg) !helper var
real(r8) :: tmp_displacement !helper var
!------------------------------------------------------------------------------

! Assign local pointers to derived type members (gridcell-level)

forc_hgt_t => clm_a2l%forc_hgt_t
forc_pbot => clm_a2l%forc_pbot

forc_q => clm_a2l%forc_q
forc_t => clm_a2l%forc_t
forc_th => clm_a2l%forc_th
Expand Down Expand Up @@ -398,31 +406,61 @@ subroutine Biogeophysics1(lbg, ubg, lbc, ubc, lbp, ubp, &

end do

!CPS change forc_hgt = forc_hgt + z0m + displa at PFT level, works for 1 pft max
! if (max_pft_per_col .eq. 1) then
if (maxpatch_pft .eq. 1) then
! Change forc_hgt = forc_hgt + z0m + displa at PFT level
! forc_hgt is send from COSMO to CLM via fix value. In fully coupled mode, this
! fix value can conflict with the actual canopy height, showing up as CLM error
! with the message:
! > [...] forc height is below canopy height [...]
! To workaround this, forc_hgt is adjusted (increased) according to pft types
! present within each gridcell.
! As multiple pfts could be present in one gridcell, first the displacement is
! calculated for each pft present, and second the maximum displacement is taken
! to correct the forc_hgt. This way we do not run into above error.
! However, keep in mind that this correction is still a workaround.
tmp_displacement = 0._r8 ! scalar
tmp_displacement_max(:) = 0._r8 ! same shape as forc_hgt
!
! First calculate max displacement for all columns and pfts on grid lvl
! max_pft_per_col = im code festgelegte max moeglicher pft (17)
do pi = 1,max_pft_per_col
! num_nolakec: number of column non-lake points in column filter
do fc = 1,num_nolakec
c = filter_nolakec(fc)
l = clandunit(c)
g = cgridcell(c)
if (pi <= npfts(c)) then
p = pfti(c) + pi - 1

if (frac_sno(c) > 0._r8 ) then
forc_hgt_u(p) = forc_hgt_u(g) + z0mg(c) + displa(p)
forc_hgt_t(g) = forc_hgt_t(g) + z0mg(c) + displa(p)
forc_hgt_q(g) = forc_hgt_q(g) + z0mg(c) + displa(p)
! Calculate displacement for related pft on related column
! If this displacement is higher than displacement_max overwrite
! displacement_max
tmp_displacement = z0mg(c) + displa(p)
if (tmp_displacement > tmp_displacement_max(g)) then
tmp_displacement_max(g) = tmp_displacement
end if
else
forc_hgt_u(g) = forc_hgt_u(g) + z0m(p) + displa(p)
forc_hgt_t(g) = forc_hgt_t(g) + z0m(p) + displa(p)
forc_hgt_q(g) = forc_hgt_q(g) + z0m(p) + displa(p)
! Calculate displacement for related pft on related column
! If this displacement is higher than displacement_max overwrite
! displacement_max
tmp_displacement = z0m(p) + displa(p)
if (tmp_displacement > tmp_displacement_max(g)) then
tmp_displacement_max(g) = tmp_displacement
end if
end if
end if
end do
end do
end if
!CPS
! Second increase forc_hgt on grid lvl with max displacement
! num_nolakec: number of column non-lake points in column filter
do fc = 1,num_nolakec
c = filter_nolakec(fc)
g = cgridcell(c)

! Update forc_hgt on grid lvl
forc_hgt_u(g) = forc_hgt_u(g) + tmp_displacement_max(g)
forc_hgt_t(g) = forc_hgt_t(g) + tmp_displacement_max(g)
forc_hgt_q(g) = forc_hgt_q(g) + tmp_displacement_max(g)
end do

end subroutine Biogeophysics1

Expand Down
1 change: 0 additions & 1 deletion bldsva/intf_oas3/common_build_interface.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ route "${cyellow}>>> c_configure_clm${cnormal}"
cp $rootdir/bldsva/intf_oas3/${mList[1]}/oas3/oas_clm_init.F90 $clmdir/src/oas3

spmd="on" # settings are [on | off ] (default is off)
maxpft="1" # settings are 4->17 (default is 4)
rtm="off" # settings are [on | off ] (default is off)
cps_catch="off" # settings are [on | off ] (default is off)
usr_src="$clmdir/bld/usr.src "
Expand Down

0 comments on commit cbca8ec

Please sign in to comment.