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

Extend CNFireMethodMod with a FATESFireData class #991

Merged
merged 34 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
51f3107
Extend CNFireMethodMod with a FATESFireData class
slevis-lmwg Apr 24, 2020
af1f812
Revisions based on code review by @ekluzek
slevis-lmwg Apr 27, 2020
4e7a95a
Revisions part 2 based on comments by @ekluzek @jkshuman @lmkueppers
slevis-lmwg Apr 29, 2020
fb2119b
Revisions part 3 based on @ekluzek's review
slevis-lmwg Apr 29, 2020
78fb2db
Move InterpFileInputs and Init2 to clmfates_interfaceMod
slevis-lmwg May 7, 2020
67b82a1
Added if (use_cn) around reading/interpolating population density
slevis-lmwg May 7, 2020
2fc0ede
Corrections that reduce the number of compilation errors to two
slevis-lmwg May 8, 2020
49d2ee6
Corrections for the code to compile
slevis-lmwg May 8, 2020
c6fdf8c
Changes needed so that fates_fire_data_method is local to clmfates_in…
ekluzek May 8, 2020
261a01c
Update to Sam's FATES branch for the lightning reading
ekluzek May 8, 2020
35ec07f
Make lnfm24 data private add an get method for it
ekluzek May 8, 2020
9866d97
Get everything consistent and building
ekluzek May 29, 2020
8446296
Use integer value for use_fates_spitfire now
ekluzek May 29, 2020
f530c99
Add FATES fire base class
ekluzek May 29, 2020
754b1dc
Minor corrections for clm-fates to run with a lightning dataset
slevis-lmwg Jun 4, 2020
3f643ef
Merge branch 'fates_next_api' into lightning_v2_ctsm
slevis-lmwg Jun 5, 2020
e3c4bc7
Additional conflicts resolved; revisions in response to rgknox's review
slevis-lmwg Jun 5, 2020
d6c9b70
Merge branch 'fates_next_api' into lightning_v2_ctsm
slevis-lmwg Jun 6, 2020
0629073
Correction to part of a previous conflict resolution
slevis-lmwg Jun 6, 2020
e542dfe
Added new FATES test that exercises the lightning dataset code
slevis-lmwg Jun 7, 2020
ffd5edb
Minor corrections from self-reviewing the PR
slevis-lmwg Jun 8, 2020
e011c10
Reassigned expected test fail to issue #667
slevis-lmwg Jun 8, 2020
35c9b8a
Updates needed for anthropogenic ignitions in FATES-SPITFIRE
slevis-lmwg Jul 11, 2020
ee8a91d
Minor clean-up
slevis-lmwg Jul 11, 2020
e125730
Small corrections to get test simulation to run
slevis-lmwg Jul 12, 2020
b583b4f
Added some comments to the code
slevis-lmwg Jul 12, 2020
3a08127
Changed walltime on new test to avoid timeout
slevis-lmwg Jul 12, 2020
4cd75f6
Update bld/namelist_files/namelist_definition_clm4_5.xml
slevis-lmwg Jul 14, 2020
d1b7f16
Update cime_config/testdefs/testmods_dirs/clm/Fates_nat_and_anthro_ig…
slevis-lmwg Jul 14, 2020
f68ac40
Update src/main/clm_varctl.F90
slevis-lmwg Jul 14, 2020
89cdc67
Update src/main/clm_varctl.F90
slevis-lmwg Jul 15, 2020
8f3d430
Made spitfire_mode flags public for use throughout CTSM-FATES
slevis-lmwg Jul 18, 2020
4596717
updating externals_clm configuration
glemieux Jul 22, 2020
4bed6e2
Merge pull request #2 from glemieux/lightning_v2_ctsm-externals
slevis-lmwg Jul 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,9 @@ sub setup_cmdl_fire_light_res {
} else {
$nl_flags->{$var} = ".false.";
}
if ( $nl_flags->{'use_fates_spitfire'} > 1 ) {
$nl_flags->{$var} = ".true.";
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion bld/namelist_files/namelist_defaults_clm4_5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1134,14 +1134,20 @@ lnd/clm2/surfdata_map/landuse.timeseries_ne30np4_hist_16pfts_Irrig_CMIP6_simyr18
<light_res use_cn=".true." fire_method="nofire" >none</light_res>
<light_res use_cn=".true." phys="clm4_5" >94x192</light_res>
<light_res use_cn=".true." phys="clm5_0" >94x192</light_res>
<light_res use_fates=".true." phys="clm4_5" >360x720</light_res>
<light_res use_fates=".true." phys="clm5_0" >360x720</light_res>
ekluzek marked this conversation as resolved.
Show resolved Hide resolved

<stream_year_first_lightng use_cn=".true." >0001</stream_year_first_lightng>
<stream_year_last_lightng use_cn=".true." >0001</stream_year_last_lightng>
<stream_year_first_lightng use_fates=".true.">0001</stream_year_first_lightng>
<stream_year_last_lightng use_fates=".true.">0001</stream_year_last_lightng>

<stream_fldfilename_lightng hgrid="94x192" use_cn=".true." >atm/datm7/NASA_LIS/clmforc.Li_2012_climo1995-2011.T62.lnfm_Total_c140423.nc</stream_fldfilename_lightng>
<stream_fldfilename_lightng hgrid="360x720" use_cn=".true." >atm/datm7/NASA_LIS/clmforc.Li_2016_climo1995-2013.360x720.lnfm_Total_c160825.nc</stream_fldfilename_lightng>
<stream_fldfilename_lightng use_fates=".true." >atm/datm7/NASA_LIS/clmforc.Li_2016_climo1995-2013.360x720.lnfm_Total_c160825.nc</stream_fldfilename_lightng>

<lightngmapalgo use_cn=".true." >bilinear</lightngmapalgo>
<lightngmapalgo use_fates=".true." >bilinear</lightngmapalgo>

<lightngmapalgo use_cn=".true." hgrid="1x1_brazil" >nn</lightngmapalgo>
<lightngmapalgo use_cn=".true." hgrid="1x1_mexicocityMEX" >nn</lightngmapalgo>
Expand Down Expand Up @@ -2639,7 +2645,7 @@ lnd/clm2/surfdata_map/landuse.timeseries_ne30np4_hist_16pfts_Irrig_CMIP6_simyr18
<use_nitrif_denitrif bgc_mode="fates" >.false.</use_nitrif_denitrif>

<!-- ===== FATES DEFAULTS =========== -->
<use_fates_spitfire use_fates=".true.">.false.</use_fates_spitfire>
<use_fates_spitfire use_fates=".true.">0</use_fates_spitfire>
<use_fates_planthydro use_fates=".true.">.false.</use_fates_planthydro>
<use_fates_cohort_age_tracking use_fates=".true.">.false.</use_fates_cohort_age_tracking>
<use_fates_ed_st3 use_fates=".true.">.false.</use_fates_ed_st3>
Expand Down
9 changes: 6 additions & 3 deletions bld/namelist_files/namelist_definition_clm4_5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,12 @@ Toggle to turn on the FATES model
Switch deciding which nutrient model to use in FATES.
</entry>

<entry id="use_fates_spitfire" type="logical" category="physics"
group="clm_inparm" valid_values="" value=".false.">
Toggle to turn on spitfire module for modeling fire (only relevant if FATES is being used).
<entry id="use_fates_spitfire" type="integer" category="physics"
group="clm_inparm" valid_values="0,1,2,3" value=".false.">
Turn on spitfire module to simulate fire by setting use_fates_spitfire > 0.
Relevant only if use_fates = .true.. Values of 1, 2, and 3 correspond to
no external inputs, external lightning data, and external confirmed ignition
data, respectively.
</entry>

<entry id="use_fates_logging" type="logical" category="physics"
Expand Down
15 changes: 12 additions & 3 deletions src/biogeochem/CNFireBaseMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ subroutine CNFireInit( this, bounds, NLFilename )
! Initialize CN Fire module
! !USES:
use shr_infnan_mod , only : nan => shr_infnan_nan, assignment(=)
use clm_varctl , only : use_cn
!
! !ARGUMENTS:
class(cnfire_base_type) :: this
Expand All @@ -130,8 +131,11 @@ subroutine CNFireInit( this, bounds, NLFilename )
allocate( this%forc_hdm(bounds%begg:bounds%endg) )
this%forc_hdm(bounds%begg:) = nan

call this%hdm_init(bounds, NLFilename)
call this%hdm_interp(bounds)
if (use_cn) then
call this%hdm_init(bounds, NLFilename)
call this%hdm_interp(bounds)
end if
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkshuman removing this if (use_cn) will give SPITFIRE access to the human pop. density dataset.


call this%lnfm_init(bounds, NLFilename)
call this%lnfm_interp(bounds)
end if
Expand Down Expand Up @@ -249,13 +253,18 @@ subroutine CNFireInterp(this,bounds)
! !DESCRIPTION:
! Interpolate CN Fire datasets
!
! !USES:
use clm_varctl, only: use_cn
!
! !ARGUMENTS:
class(cnfire_base_type) :: this
type(bounds_type), intent(in) :: bounds
!-----------------------------------------------------------------------

if ( this%need_lightning_and_popdens ) then
call this%hdm_interp(bounds)
if (use_cn) then
call this%hdm_interp(bounds)
end if
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkshuman this is another if (use_cn) that would need to be removed to allow SPITFIRE access to the human pop. density dataset.

call this%lnfm_interp(bounds)
end if

Expand Down
40 changes: 40 additions & 0 deletions src/biogeochem/CNFireFactoryMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module CNFireFactoryMod
! !PUBLIC ROUTINES:
public :: CNFireReadNML ! read the fire namelist
public :: create_cnfire_method ! create an object of class cnfire_method_type
public :: create_fates_fire_data_method ! create an object of class cnfire_method_type

! !PRIVATE DATA MEMBERS:
character(len=80), private :: fire_method = "li2014qianfrc"
Expand Down Expand Up @@ -121,5 +122,44 @@ function create_cnfire_method( NLFilename ) result(cnfire_method)
call cnfire_method%CNFireReadNML( NLFilename )

end function create_cnfire_method
!-----------------------------------------------------------------------

!-----------------------------------------------------------------------
function create_fates_fire_data_method() result(fates_fire_data_method)
!
! !DESCRIPTION:
! Create and return an object of fates_fire_data_method_type.
! The particular type is determined based on a namelist parameter.
!
! !USES:
use clm_varctl, only: use_fates_spitfire
use CNFireMethodMod, only: cnfire_method_type
use FATESFireNoDataMod, only: fates_fire_no_data_type
use FATESFireDataMod, only: fates_fire_data_type
!
! !ARGUMENTS:
class(cnfire_method_type), allocatable :: fates_fire_data_method ! function result
!
! !LOCAL VARIABLES:
integer :: current_case
character(len=*), parameter :: subname = 'create_fates_fire_data_method'
!-----------------------------------------------------------------------

current_case = use_fates_spitfire

select case (current_case)

case (0:1)
allocate(fates_fire_data_method, source=fates_fire_no_data_type())
case (2:3)
allocate(fates_fire_data_method, source=fates_fire_data_type())

case default
write(iulog,*) subname//' ERROR: unknown method: ', use_fates_spitfire
call endrun(msg=errMsg(sourcefile, __LINE__))

end select

end function create_fates_fire_data_method

end module CNFireFactoryMod
176 changes: 176 additions & 0 deletions src/biogeochem/FATESFireDataMod.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
module FATESFireDataMod

#include "shr_assert.h"

!-----------------------------------------------------------------------
! !DESCRIPTION:
! module for FATES to obtain fire inputs from data
!
! !USES:
use shr_kind_mod, only: r8 => shr_kind_r8, CL => shr_kind_CL
use shr_log_mod, only: errmsg => shr_log_errMsg
use abortutils, only: endrun
use clm_varctl, only: iulog
use decompMod, only: bounds_type
use CNFireMethodMod, only: cnfire_method_type
use CNFireBaseMod, only: cnfire_base_type
!
implicit none
private
!
! !PUBLIC TYPES:
public :: fates_fire_data_type
!
type, extends(cnfire_base_type) :: fates_fire_data_type
! !PRIVATE MEMBER DATA:
real(r8), public, pointer :: lnfm24(:) ! Daily avg lightning by grid cell (#/km2/hr)
contains
! !PUBLIC MEMBER FUNCTIONS:
procedure, public :: InitAccBuffer ! Initialize accumulation processes
procedure, public :: InitAccVars ! Initialize accumulation variables
procedure, public :: UpdateAccVars ! Update/extract accumulations vars

end type fates_fire_data_type

character(len=*), parameter, private :: sourcefile = __FILE__
!
! !PRIVATE MEMBER DATA:
!-----------------------------------------------------------------------

interface fates_fire_data_type
! initialize a new cnfire_base object
module procedure constructor
end interface fates_fire_data_type
!-----------------------------------------------------------------------

contains

!------------------------------------------------------------------------
type(fates_fire_data_type) function constructor()
!
! !DESCRIPTION:
! Creates an object of type fates_fire_data_type
! !ARGUMENTS:
constructor%need_lightning_and_popdens = .true.
end function constructor

!-----------------------------------------------------------------------
subroutine InitAccBuffer (this, bounds)
!
! !DESCRIPTION:
! Initialize accumulation buffer for all required module accumulated fields
! This routine set defaults values that are then overwritten by the
! restart file for restart or branch runs
!
! !USES
use clm_varcon, only : spval
use accumulMod, only : init_accum_field
!
! !ARGUMENTS:
class(fates_fire_data_type) :: this
type(bounds_type), intent(in) :: bounds

! !LOCAL VARIABLES:
integer :: begg, endg
integer :: ier
!---------------------------------------------------------------------

begg = bounds%begg; endg = bounds%endg

allocate(this%lnfm24(begg:endg), stat=ier)
if (ier/=0) then
call endrun(msg="allocation error for lnfm24"//&
errmsg(sourcefile, __LINE__))
endif
this%lnfm24(:) = spval
call init_accum_field (name='lnfm24', units='strikes/km2/hr', &
desc='24hr average of lightning strikes', accum_type='runmean', &
accum_period=-1, subgrid_type='gridcell', numlev=1, init_value=0._r8)

end subroutine InitAccBuffer

!-----------------------------------------------------------------------
subroutine InitAccVars(this, bounds)
!
! !DESCRIPTION:
! Initialize module variables that are associated with
! time accumulated fields. This routine is called for both an initial run
! and a restart run (and must therefore must be called after the restart
! file is read in and the accumulation buffer is obtained)
!
! !USES
use accumulMod , only : extract_accum_field
use clm_time_manager , only : get_nstep
!
! !ARGUMENTS:
class(fates_fire_data_type) :: this
type(bounds_type), intent(in) :: bounds
!
! !LOCAL VARIABLES:
integer :: begg, endg
integer :: nstep
integer :: ier
real(r8), pointer :: rbufslg(:) ! temporary
!---------------------------------------------------------------------

begg = bounds%begg; endg = bounds%endg

! Allocate needed dynamic memory for single level patch field
allocate(rbufslg(begg:endg), stat=ier)
if (ier/=0) then
call endrun(msg="allocation error for rbufslg"//&
errmsg(sourcefile, __LINE__))
endif

! Determine time step
nstep = get_nstep()

call extract_accum_field ('lnfm24', rbufslg, nstep)
this%lnfm24(begg:endg) = rbufslg(begg:endg)

deallocate(rbufslg)

end subroutine InitAccVars

!-----------------------------------------------------------------------
subroutine UpdateAccVars (this, bounds)
!
! USES
use clm_time_manager, only: get_nstep
use accumulMod, only: update_accum_field, extract_accum_field
use abortutils, only: endrun
!
! !ARGUMENTS:
class(fates_fire_data_type) :: this
type(bounds_type), intent(in) :: bounds
!
! !LOCAL VARIABLES:
integer :: dtime ! timestep size [seconds]
integer :: nstep ! timestep number
integer :: ier ! error status
integer :: begg, endg
real(r8), pointer :: rbufslg(:) ! temporary single level - gridcell level
!---------------------------------------------------------------------

begg = bounds%begg; endg = bounds%endg

nstep = get_nstep()

! Allocate needed dynamic memory for single level gridcell field

allocate(rbufslg(begg:endg), stat=ier)
if (ier/=0) then
write(iulog,*)'UpdateAccVars allocation error for rbuf1dg'
call endrun(msg=errmsg(sourcefile, __LINE__))
endif

! Accumulate and extract lnfm24
rbufslg(begg:endg) = this%forc_lnfm(begg:endg)
call update_accum_field ('lnfm24', rbufslg, nstep)
call extract_accum_field ('lnfm24', this%lnfm24, nstep)

deallocate(rbufslg)

end subroutine UpdateAccVars

end module FATESFireDataMod
Loading