Skip to content

Commit

Permalink
Extend CNFireMethodMod with a FATESFireData class
Browse files Browse the repository at this point in the history
Following @ekluzek's recommendations in ESCOMP#982.
Purpose: Allow FATES access to CTSM's infrastructure that reads lightning and
human population data sets for use in SPITFIRE.
  • Loading branch information
slevis-lmwg committed Apr 24, 2020
1 parent 0d93237 commit 51f3107
Show file tree
Hide file tree
Showing 11 changed files with 478 additions and 8 deletions.
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
7 changes: 6 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,19 @@ 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="clm5_0" >360x720</light_res>

<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." >nn</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 +2644,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
6 changes: 3 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,9 @@ 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 for modeling fire (only relevant if FATES is being used) by setting > 0. 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
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

0 comments on commit 51f3107

Please sign in to comment.