Skip to content

Commit

Permalink
Fixed multiple bugs in the implementation, and added a logical variable
Browse files Browse the repository at this point in the history
(use_huestis_eff_cosz) that allows switching between the use of the "effective" cosine of
zenith angle and the actual value (ED-2.2 default).
  • Loading branch information
mpaiao committed Jan 9, 2024
1 parent 83f6c70 commit 2a0ff4d
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 136 deletions.
28 changes: 12 additions & 16 deletions ED/build/make/include.mk.macosx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


#----- Define make (gnu make works best). -------------------------------------------------#
MAKE=/usr/bin/make
MAKE=/usr/local/bin/make
#------------------------------------------------------------------------------------------#

#----- Libraries. -------------------------------------------------------------------------#
Expand All @@ -20,8 +20,8 @@ BASE=$(ED_ROOT)/build/
# libraries compiled with the same compiler you set for F_COMP and C_COMP. You may still #
# be able to compile without HDF5 but it will not run. #
#------------------------------------------------------------------------------------------#
ZLIB_PATH=/Users/mlongo/Util/ED2_Libs/zlib-1.2.11
HDF5_PATH=/Users/mlongo/Util/ED2_Libs/hdf5-1.10.2
ZLIB_PATH=/usr/local
HDF5_PATH=/usr/local
HDF5_INCS=-I$(HDF5_PATH)/include
HDF5C_INCS=$(HDF5_INCS)
HDF5_LIBS=-L$(ZLIB_PATH)/lib -lz -L$(HDF5_PATH)/lib -lhdf5_fortran -lhdf5 -lhdf5_hl
Expand Down Expand Up @@ -51,10 +51,9 @@ USE_INTERF=1
#################################### COMPILER SETTINGS #####################################
CMACH=MAC_OS_X
FC_TYPE=GNU
F_COMP=gfortran
C_COMP=gcc
LOADER=gfortran
C_LOADER=gcc
F_COMP=/usr/local/bin/gfortran-13
C_COMP=/usr/local/bin/gcc-13
LOADER=/usr/local/bin/gfortran-13
LIBS=
MOD_EXT=mod
############################################################################################
Expand Down Expand Up @@ -88,20 +87,17 @@ endif
ifeq ($(KIND_COMP),A)
F_OPTS= -O0 -ffree-line-length-none -g -fimplicit-none -Wall -finit-real=snan \
-finit-integer=-2147483648 -ffpe-trap=invalid,zero,overflow,underflow \
-fcheck=all -frecursive -fsignaling-nans -Werror -mmacosx-version-min=10.12 \
-fopenmp -static
C_OPTS= -O0 -DLITTLE -g -static
-fcheck=all -frecursive -fsignaling-nans -Werror -fopenmp -fbacktrace -static
C_OPTS= -O0 -DLITTLE -g -fbacktrace -static
LOADER_OPTS= -O0 -ffree-line-length-none -g -fimplicit-none -Wall -finit-real=snan \
-finit-integer=-2147483648 -ffpe-trap=invalid,zero,overflow,underflow \
-fcheck=all -frecursive -fsignaling-nans -Werror \
-mmacosx-version-min=10.12 -fopenmp
-fcheck=all -frecursive -fsignaling-nans -Werror -fopenmp -fbacktrace
#---------------------------------------------------------------------------------------#
endif
ifeq ($(KIND_COMP),E)
F_OPTS= -O3 -ffree-line-length-none -frecursive -mmacosx-version-min=10.12 -fopenmp \
-static
C_OPTS= -O0 -DLITTLE -g -static
LOADER_OPTS= -O3 -ffree-line-length-none -frecursive -mmacosx-version-min=10.12 -fopenmp
F_OPTS= -O3 -ffree-line-length-none -frecursive -fopenmp -fbacktrace -static
C_OPTS= -O3 -DLITTLE -g -fbacktrace -static
LOADER_OPTS= -O3 -ffree-line-length-none -frecursive -fopenmp -fbacktrace
#---------------------------------------------------------------------------------------#
endif
#------------------------------------------------------------------------------------------#
Expand Down
2 changes: 1 addition & 1 deletion ED/src/driver/ed_met_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ subroutine update_met_drivers(cgrid)
case default
chapman_prev = &
mean_chapman(cgrid%lon(ipy),cgrid%lat(ipy),prevmet_timea &
,dt_radinterp,met_frq(iformat,iv))
,dt_radinterp,met_frq(iformat,iv),.true.)
end select
!---------------------------------------------------------------!

Expand Down
12 changes: 0 additions & 12 deletions ED/src/dynamics/farq_katul.f90
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,6 @@ subroutine optimization_solver8(ib,ipft,lambda,
real(kind=8) :: test_dcidg
real(kind=8) :: test_dfcdg
real(kind=8) :: test_dfedg
real(kind=8) :: test_fc_light
real(kind=8) :: test_fc_rubp
real(kind=8) :: test_fc_3rd
real(kind=8) :: opt_ci_light
real(kind=8) :: opt_ci_rubp
real(kind=8) :: opt_ci_3rd
Expand Down Expand Up @@ -852,15 +849,6 @@ subroutine photosynthesis_stomata_solver8(ib,gsc,limit_case,
real(kind=8) :: a,b,c !! Coefficients of the quadratic equation to solve ci
real(kind=8) :: rad !! sqrt(b2-4ac)
real(kind=8) :: dbdg,dcdg !! derivatives of b,c wrt. gsc
real(kind=8) :: ci_rubp !! ci for rubp-limited scenario
real(kind=8) :: dcidg_rubp !! derivative of ci wrt. gsc for rubp-limited scenario
real(kind=8) :: dfcdg_rubp !! derivative of fc wrt. gsc for rubp-limited scenario
real(kind=8) :: ci_light !! ci for light-limited scenario
real(kind=8) :: dcidg_light !! derivative of ci wrt. gsc for light-limited scenario
real(kind=8) :: dfcdg_light !! derivative of fc wrt. gsc for light-limited scenario
real(kind=8) :: ci_3rd !! ci for TPU/CO2-limited scenario
real(kind=8) :: dcidg_3rd !! derivative of ci wrt. gsc for TPU/CO2-limited scenario
real(kind=8) :: dfcdg_3rd !! derivative of fc wrt. gsc for TPU/CO2-limited scenario

!------------------------------------------------------------------------------------!

Expand Down
17 changes: 11 additions & 6 deletions ED/src/dynamics/radiate_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ subroutine canopy_radiation(cgrid)
, patchtype ! ! structure
use ed_para_coms , only : nthreads ! ! intent(in)
use canopy_radiation_coms , only : cosz_min & ! intent(in)
, use_huestis_eff_cosz & ! intent(in)
, rshort_twilight_min & ! intent(in)
, find_eff_cosz ! ! intent(in)
use consts_coms , only : pio180 ! ! intent(in)
Expand Down Expand Up @@ -91,12 +92,16 @@ subroutine canopy_radiation(cgrid)
! Find the two logicals, that will tell whether the time exceeds the !
! (lower) thresholds for twilight and daytime. !
!---------------------------------------------------------------------------!
daytime = cgrid%cosz (ipy) > cosz_min .and. &
cpoly%cosaoi (isi) > cosz_min .and. &
cpoly%met(isi)%rshort > rshort_twilight_min
twilight = cgrid%eff_cosz(ipy) > cosz_min .and. &
cpoly%cosaoi (isi) > cosz_min .and. &
cpoly%met(isi)%rshort > rshort_twilight_min
if (use_huestis_eff_cosz) then
daytime = cgrid%cosz (ipy) > cosz_min .and. &
cpoly%met(isi)%rshort > rshort_twilight_min
twilight = cpoly%cosaoi (isi) > cosz_min .and. &
cpoly%met(isi)%rshort > rshort_twilight_min
else
daytime = cpoly%cosaoi (isi) > cosz_min .and. &
cpoly%met(isi)%rshort > rshort_twilight_min
twilight = cpoly%met(isi)%rshort > rshort_twilight_min
end if
!---------------------------------------------------------------------------!


Expand Down
26 changes: 17 additions & 9 deletions ED/src/init/ed_params.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7305,13 +7305,13 @@ subroutine init_can_rad_params()
, wood_emiss_tir & ! intent(out)
, fvis_beam_def & ! intent(out)
, fvis_diff_def & ! intent(out)
, fnir_beam_def & ! intent(out)
, fnir_diff_def & ! intent(out)
, snow_albedo_vis & ! intent(out)
, snow_albedo_nir & ! intent(out)
, snow_emiss_tir & ! intent(out)
, rshort_twilight_min & ! intent(out)
, cosz_min ! ! intent(out)
, cosz_min & ! intent(out)
, use_huestis_eff_cosz & ! intent(out)
, dzen_ref ! ! intent(out)
use pft_coms , only : is_grass & ! intent(in)
, is_tropical & ! intent(in)
, is_conifer ! ! intent(in)
Expand Down Expand Up @@ -7496,18 +7496,26 @@ subroutine init_can_rad_params()
! Also rshort_twilight_min provides an extra threshold for when twilight conditions are !
! met or exceeded. !
!---------------------------------------------------------------------------------------!
cosz_min = cos(89.9*pio180) ! cos(89.5*pio180)
cosz_min = cos(89.95*pio180) ! cos(89.5*pio180)
rshort_twilight_min = 0.5
!---------------------------------------------------------------------------------------!


!---------------------------------------------------------------------------------------!
! Flag to determine whether or not to use the modified Chapman function to find the !
! "effective" cosine of zenith angle that accounts for the Earth's curvature (and so !
! it allows solving twilight irradiance). To fall back to ED-2.2 default, set this !
! flag to .false. !
!---------------------------------------------------------------------------------------!
use_huestis_eff_cosz = .true.
!---------------------------------------------------------------------------------------!


!---------------------------------------------------------------------------------------!
! This variable is the resolution (in degrees) for deriving the look-up table for !
! the modified Chapman's function. !
!---------------------------------------------------------------------------------------!
dzen_ref = 5.0d-2
dzen_ref = 1.0d-2
!---------------------------------------------------------------------------------------!


Expand Down Expand Up @@ -8303,7 +8311,7 @@ subroutine init_derived_params_after_xml()
, fnir_diff_def & ! intent(out)
, cosz_min8 & ! intent(out)
, nzen_ref & ! intent(out)
, zend_ref & ! intent(out)
, zen_ref & ! intent(out)
, huestis_ref & ! intent(out)
, leaf_scatter_vis & ! intent(out)
, leaf_backscatter_vis & ! intent(out)
Expand Down Expand Up @@ -9024,10 +9032,10 @@ subroutine init_derived_params_after_xml()
! Assign the dimensions for the modified Chapman function look-up table, and !
! set the reference zenith angles and modified Chapman function values. !
!---------------------------------------------------------------------------------------!
nzen_ref = ceiling( 1.80d2 / dzen_ref)
allocate(zend_ref (nzen_ref))
nzen_ref = 1 + ceiling( 1.80d2 / dzen_ref)
allocate(zen_ref (nzen_ref))
allocate(huestis_ref(nzen_ref))
call set_huestis_lut(nzen_ref,dzen_ref,zend_ref,huestis_ref)
call set_huestis_lut()
!---------------------------------------------------------------------------------------!


Expand Down
42 changes: 25 additions & 17 deletions ED/src/io/ed_xml_config.f90
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,24 @@ recursive subroutine read_ed_xml_config(filename)
do i=1,ntag
call libxml2f90__ll_selecttag('DOWN','can_rad',i)

call getConfigREAL ('fvis_beam_def' ,'can_rad',i,rval,texist)
if (texist) fvis_beam_def = sngloff(rval,tiny_offset)
call getConfigREAL ('fvis_diff_def' ,'can_rad',i,rval,texist)
if (texist) fvis_diff_def = sngloff(rval,tiny_offset)
call getConfigREAL ('snow_albedo_vis' ,'can_rad',i,rval,texist)
if (texist) snow_albedo_vis = sngloff(rval,tiny_offset)
call getConfigREAL ('snow_albedo_nir' ,'can_rad',i,rval,texist)
if (texist) snow_albedo_nir = sngloff(rval,tiny_offset)
call getConfigREAL ('snow_emiss_tir' ,'can_rad',i,rval,texist)
if (texist) snow_emiss_tir = sngloff(rval,tiny_offset)
call getConfigREAL ('cosz_min' ,'can_rad',i,rval,texist)
if (texist) cosz_min = sngloff(rval,tiny_offset)
call getConfigREAL ('rshort_twilight_min','can_rad',i,rval,texist)
if (texist) rshort_twilight_min = sngloff(rval,tiny_offset)
call getConfigREAL ('chap_dzen' ,'can_rad',i,rval,texist)
if (texist) chap_dzen = rval
call getConfigREAL ('fvis_beam_def' ,'can_rad',i,rval,texist)
if (texist) fvis_beam_def = sngloff(rval,tiny_offset)
call getConfigREAL ('fvis_diff_def' ,'can_rad',i,rval,texist)
if (texist) fvis_diff_def = sngloff(rval,tiny_offset)
call getConfigREAL ('snow_albedo_vis' ,'can_rad',i,rval,texist)
if (texist) snow_albedo_vis = sngloff(rval,tiny_offset)
call getConfigREAL ('snow_albedo_nir' ,'can_rad',i,rval,texist)
if (texist) snow_albedo_nir = sngloff(rval,tiny_offset)
call getConfigREAL ('snow_emiss_tir' ,'can_rad',i,rval,texist)
if (texist) snow_emiss_tir = sngloff(rval,tiny_offset)
call getConfigREAL ('cosz_min' ,'can_rad',i,rval,texist)
if (texist) cosz_min = sngloff(rval,tiny_offset)
call getConfigREAL ('rshort_twilight_min' ,'can_rad',i,rval,texist)
if (texist) rshort_twilight_min = sngloff(rval,tiny_offset)
call getConfigINT ('use_huestis_eff_cosz','can_rad',i,ival,texist)
if (texist) use_huestis_eff_cosz = ival == 1
call getConfigREAL ('dzen_ref' ,'can_rad',i,rval,texist)
if (texist) dzen_ref = rval
call libxml2f90__ll_selecttag('UP','config',1) !move back up to top level

end do
Expand Down Expand Up @@ -1906,7 +1908,13 @@ subroutine write_ed_xml_config
call putConfigREAL ("snow_emiss_tir" , snow_emiss_tir )
call putConfigREAL ("cosz_min" , cosz_min )
call putConfigREAL ("rshort_twilight_min" , rshort_twilight_min )
call putConfigREAL8("chap_dzen" , chap_dzen )
if (use_huestis_eff_cosz) then
ival = 1
else
ival = 0
end if
call putConfigINT ("use_huestis_eff_cosz", ival )
call putConfigREAL8("dzen_ref" , dzen_ref )
call libxml2f90_ll_closetag("can_read")


Expand Down
Loading

0 comments on commit 2a0ff4d

Please sign in to comment.