Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 38 additions & 2 deletions driver/fire_behavior.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ program fire_behavior
use initialize_mod, only : Init_fire_state, Init_atm_state
use advance_mod, only : Advance_state
use wrfdata_mod, only : wrfdata_t
use datetime_mod, only : datetime_t
use stderrout_mod, only : Stop_simulation
use, intrinsic :: iso_fortran_env, only : ERROR_UNIT, OUTPUT_UNIT

implicit none

integer :: ierr, rank, mpi_comm_cfbm
integer :: restart_step_interval
real :: restart_interval_seconds, restart_interval_error
type (state_fire_t) :: grid
type (wrfdata_t) :: atm_state
type (namelist_t) :: config_flags
type (datetime_t) :: datetime_check
character (len = 256) :: msg
logical, parameter :: DEBUG_LOCAL = .false.
real, parameter :: RESTART_INTERVAL_TOL = 1.0e-6


if (DEBUG_LOCAL) write (OUTPUT_UNIT, *) 'Running fire_behavior...'
Expand Down Expand Up @@ -71,14 +78,43 @@ program fire_behavior

end select

if (DEBUG_LOCAL) write (OUTPUT_UNIT, *) ' Saving fire state...'
call grid%Save_state ()
if (config_flags%restart) then
if (DEBUG_LOCAL) write (OUTPUT_UNIT, *) ' Reading restart state...'
call grid%Read_restart (config_flags)

else
if (DEBUG_LOCAL) write (OUTPUT_UNIT, *) ' Saving fire state...'
call grid%Save_state ()
end if

restart_step_interval = -1
if (config_flags%restart_interval > 0) then
restart_step_interval = nint (real (config_flags%restart_interval) / grid%dt)
restart_interval_seconds = restart_step_interval * grid%dt
restart_interval_error = abs (restart_interval_seconds - real (config_flags%restart_interval))

if (restart_step_interval <= 0 .or. &
restart_interval_error > max (RESTART_INTERVAL_TOL, abs (real (config_flags%restart_interval)) * RESTART_INTERVAL_TOL)) then
write (msg, '(a, i0, a, f12.6)') 'restart_interval must map to an integer number of time steps: restart_interval = ', &
config_flags%restart_interval, ', dt = ', grid%dt
call Stop_simulation (msg)
end if
end if

if (DEBUG_LOCAL) write (OUTPUT_UNIT, *) ' Starting temporal loop...'
do while (grid%datetime_now < grid%datetime_end)
call Advance_state (grid, config_flags)

datetime_check = grid%datetime_start
call datetime_check%Add_seconds (grid%itimestep * grid%dt)
if (datetime_check /= grid%datetime_now) call Stop_simulation ('Model clock is inconsistent with itimestep and dt')

call grid%Handle_output (config_flags)
if (config_flags%ideal_opt == 0) call grid%Handle_wrfdata_update (atm_state, config_flags)

if (restart_step_interval > 0) then
if (mod (grid%itimestep, restart_step_interval) == 0) call grid%Write_restart (config_flags)
end if
end do
if (DEBUG_LOCAL) write (OUTPUT_UNIT, *) ' Completed temporal loop'

Expand Down
38 changes: 35 additions & 3 deletions driver/initialize_mod.F90
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module initialize_mod

use state_mod, only : state_fire_t
use state_mod, only : state_fire_t, Build_restart_file_name
use namelist_mod, only : namelist_t
use geogrid_mod, only : geogrid_t
use wrfdata_mod, only : wrfdata_t
use fire_driver_mod, only : Init_fire_components
use datetime_mod, only : datetime_t
use stderrout_mod, only: Print_message, Stop_simulation
#ifdef DM_PARALLEL
use mpi_mod, only : Convert_mpi_comm_to_f08
Expand Down Expand Up @@ -59,7 +60,11 @@ subroutine Init_fire_state (grid, config_flags, wrf)
if (DEBUG_LOCAL) call Print_message (' Entering subroutine Init_state')

if (DEBUG_LOCAL) call Print_message (' Initialization...')
if (config_flags%ideal_opt == 0) then
if (config_flags%ideal_opt == 0 .and. config_flags%restart) then
! Real world, restart run: the grid metadata comes from the restart file
call Init_fire_state_from_restart (grid, config_flags)

else if (config_flags%ideal_opt == 0) then
! Real world
if (DEBUG_LOCAL) call Print_message (' Reading geogrid file')
#ifdef DM_PARALLEL
Expand Down Expand Up @@ -110,7 +115,7 @@ subroutine Init_fire_state (grid, config_flags, wrf)

call Init_fire_components (grid, config_flags)

if (present (wrf)) then
if (present (wrf) .and. .not. config_flags%restart) then
if (DEBUG_LOCAL) call Print_message (' Initializing atmospheric state')
call grid%Handle_wrfdata_update (wrf, config_flags)
end if
Expand Down Expand Up @@ -143,6 +148,31 @@ subroutine Init_fire_state (grid, config_flags, wrf)

end subroutine Init_fire_state

subroutine Init_fire_state_from_restart (grid, config_flags)

implicit none

type (state_fire_t), intent (in out) :: grid
type (namelist_t), intent (in) :: config_flags

type (datetime_t) :: datetime_restart
character (len = :), allocatable :: file_restart
logical, parameter :: DEBUG_LOCAL = .false.


if (DEBUG_LOCAL) call Print_message (' Entering subroutine Init_fire_state_from_restart')

datetime_restart = datetime_t (config_flags%start_year, config_flags%start_month, config_flags%start_day, &
config_flags%start_hour, config_flags%start_minute, config_flags%start_second)
file_restart = Build_restart_file_name (datetime_restart%datetime)

if (DEBUG_LOCAL) call Print_message (' Initializing fire state from restart metadata')
call grid%Initialization (config_flags, restart_file = file_restart)

if (DEBUG_LOCAL) call Print_message (' Leaving subroutine Init_fire_state_from_restart')

end subroutine Init_fire_state_from_restart

subroutine Init_fire_state_within_wrf (state, config_flags, &
ifds, ifde, ifms, ifme, ifps, ifpe, &
jfds, jfde, jfms, jfme, jfps, jfpe, &
Expand Down Expand Up @@ -185,6 +215,8 @@ subroutine Init_fire_state_within_wrf (state, config_flags, &

call Init_fire_components (state, config_flags)

if (config_flags%restart) call state%Read_restart (config_flags)

if (DEBUG_LOCAL) call Print_message (' Leaving subroutine Init_fire_state_within_wrf...')

end subroutine Init_fire_state_within_wrf
Expand Down
18 changes: 16 additions & 2 deletions io/namelist_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ module namelist_mod
integer :: interval_output = -1 ! Frequency to save the output [s]
real :: dt = 2.0 ! Time step of the fire model [s]

! Restart controls
logical :: restart = .false. ! Read initial dynamic fire state from fire_restart_<start datetime>.nc
integer :: restart_interval = -1 ! Restart output interval [s]; -1 disables restart writes

integer :: num_tiles = 1 ! Number of tiles in each patch
integer :: tile_strategy = 0 ! Strategy for the tile decomposition: 0) ...

Expand Down Expand Up @@ -215,6 +219,8 @@ subroutine Broadcast_nml (this, mpi_comm_cfbm)

call Broadcast_integer (this%ideal_opt)
call Broadcast_integer (this%devel_opt)
call Broadcast_logical (this%restart)
call Broadcast_integer (this%restart_interval)
call Broadcast_integer (this%fuel_opt)
call Broadcast_integer (this%ros_opt)
call Broadcast_integer (this%emis_opt)
Expand Down Expand Up @@ -383,6 +389,9 @@ subroutine Check_nml (this)
if (this%ideal_opt /= 0 .and. this%fmoist_run) &
call Stop_simulation ('ideal runs do not support a FMC model')

if (this%restart_interval /= -1 .and. this%restart_interval <= 0) &
call Stop_simulation ('restart_interval must be positive or -1')

end subroutine Check_nml

subroutine Init_atm_block (this, file_name)
Expand Down Expand Up @@ -765,15 +774,16 @@ subroutine Init_time_block (this, file_name)

integer :: start_year, start_month, start_day, start_hour, start_minute, start_second, &
end_year, end_month, end_day, end_hour, end_minute, end_second, interval_output, &
num_tiles, tile_strategy
restart_interval, num_tiles, tile_strategy
real :: dt
logical :: restart

character (len = :), allocatable :: msg
integer :: unit_nml, io_stat

namelist /time/ start_year, start_month, start_day, start_hour, start_minute, start_second, &
end_year, end_month, end_day, end_hour, end_minute, end_second, dt, interval_output, &
num_tiles
restart, restart_interval, num_tiles


! Set default values
Expand All @@ -791,6 +801,8 @@ subroutine Init_time_block (this, file_name)
end_second = this%end_second
dt = this%dt
interval_output = this%interval_output
restart = this%restart
restart_interval = this%restart_interval

num_tiles = this%num_tiles
tile_strategy = this%tile_strategy
Expand Down Expand Up @@ -822,6 +834,8 @@ subroutine Init_time_block (this, file_name)
this%end_second = end_second
this%dt = dt
this%interval_output = interval_output
this%restart = restart
this%restart_interval = restart_interval

this%num_tiles = num_tiles
this%tile_strategy = tile_strategy
Expand Down
Loading
Loading