Skip to content

Commit

Permalink
Merge pull request #321 from NCAR/bug-fix_inf-namelist
Browse files Browse the repository at this point in the history
bug-fix inf_flavor namelist option reverted to integer only
  • Loading branch information
hkershaw-brown committed Jan 11, 2022
2 parents 83b239f + 74fd3d1 commit 2caa99d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 125 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ individual files.

The changes are now listed with the most recent at the top.

**January 11 2022 :: Bug fix for inflation namelist options. Tag: v9.12.1**

- reverted inf_flavor namelist option to be integer only to conform to Fortran
standards.

**December 7 2021 :: Refactored filter_assim. Tag: v9.12.0**

- Filter_assim refactored so each process calcuates increments
Expand Down
69 changes: 8 additions & 61 deletions assimilation_code/modules/assimilation/filter_mod.dopplerfold.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module filter_mod
operator(-), print_time

use utilities_mod, only : error_handler, E_ERR, E_MSG, E_DBG, &
logfileunit, nmlfileunit, timestamp, get_value_from_string, &
logfileunit, nmlfileunit, timestamp, &
do_output, find_namelist_in_file, check_namelist_read, &
open_file, close_file, do_nml_file, do_nml_term, to_upper, &
set_multiple_filename_lists, find_textfile_dims
Expand Down Expand Up @@ -237,11 +237,8 @@ module filter_mod
! The inflation algorithm variables are defined in adaptive_inflate_mod.
! We use the integer parameters for PRIOR_INF and POSTERIOR_INF from
! adaptive_inflate_mod to index these 'length 2' arrays.
! To support more flexible methods of specifying the inflation algorithm,
! inf_flavor must be a character string whose value is converted to an
! integer to be backward compatible.

character(len=32) :: inf_flavor(2) = (/ 'none', 'none' /)
integer :: inf_flavor(2) = 0
logical :: inf_initial_from_restart(2) = .false.
logical :: inf_sd_initial_from_restart(2) = .false.
logical :: inf_deterministic(2) = .true.
Expand Down Expand Up @@ -315,7 +312,6 @@ module filter_mod
! during the computation? e.g. Folded doppler intensities.
logical :: observations_updateable = .true.

integer :: inflation_flavor(2)

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

Expand Down Expand Up @@ -404,18 +400,13 @@ subroutine filter_main()

call trace_message('Before initializing inflation')

! inf_flavor from the namelist is now a character string.
! the inflation-related subroutines require an integer so the
! variable inflation_flavor is added and is type integer.
inflation_flavor = set_inflation_flavor(inf_flavor)

call validate_inflate_options(inflation_flavor, inf_damping, inf_initial_from_restart, &
call validate_inflate_options(inf_flavor, inf_damping, inf_initial_from_restart, &
inf_sd_initial_from_restart, inf_deterministic, inf_sd_max_change, &
do_prior_inflate, do_posterior_inflate, output_inflation, compute_posterior)

! Initialize the adaptive inflation module
call adaptive_inflate_init(prior_inflate, &
inflation_flavor(PRIOR_INF), &
inf_flavor(PRIOR_INF), &
inf_initial_from_restart(PRIOR_INF), &
inf_sd_initial_from_restart(PRIOR_INF), &
output_inflation, &
Expand All @@ -430,7 +421,7 @@ subroutine filter_main()
allow_missing, 'Prior')

call adaptive_inflate_init(post_inflate, &
inflation_flavor(POSTERIOR_INF), &
inf_flavor(POSTERIOR_INF), &
inf_initial_from_restart(POSTERIOR_INF), &
inf_sd_initial_from_restart(POSTERIOR_INF), &
output_inflation, &
Expand All @@ -445,13 +436,13 @@ subroutine filter_main()
allow_missing, 'Posterior')

if (do_output()) then
if (inflation_flavor(PRIOR_INF) > NO_INFLATION .and. &
if (inf_flavor(PRIOR_INF) > NO_INFLATION .and. &
inf_damping(PRIOR_INF) < 1.0_r8) then
write(msgstring, '(A,F12.6,A)') 'Prior inflation damping of ', &
inf_damping(PRIOR_INF), ' will be used'
call error_handler(E_MSG,'filter_main:', msgstring)
endif
if (inflation_flavor(POSTERIOR_INF) > NO_INFLATION .and. &
if (inf_flavor(POSTERIOR_INF) > NO_INFLATION .and. &
inf_damping(POSTERIOR_INF) < 1.0_r8) then
write(msgstring, '(A,F12.6,A)') 'Posterior inflation damping of ', &
inf_damping(POSTERIOR_INF), ' will be used'
Expand Down Expand Up @@ -2407,7 +2398,7 @@ function count_state_ens_copies(ens_size, post_inflate, prior_inflate) result(nu
! then we need an extra copy to hold (save) the prior ensemble spread
! ENS_SD_COPY will be overwritten with the posterior spread before
! applying the inflation algorithm; must save the prior ensemble spread in a different copy
if ( inflation_flavor(POSTERIOR_INF) == RELAXATION_TO_PRIOR_SPREAD ) then
if ( inf_flavor(POSTERIOR_INF) == RELAXATION_TO_PRIOR_SPREAD ) then
SPARE_PRIOR_SPREAD = next_copy_number(cnum)
endif

Expand Down Expand Up @@ -2775,50 +2766,6 @@ subroutine set_copies(cnum, STAGE_COPIES)

end subroutine set_copies


!-------------------------------------------------------------------------------
!> The infl_flavor namelist is a string, and specifies the inflation algorithm.
!> The character string can either be the name associated with the type of inflation
!> or the integer associated with the type of inflation. The string names of the
!> inflation algorithms is based on what is declared in the adaptive_inflate_mod.f90
!> which is repeated here for reference.
!>
!> NO_INFLATION = 0
!> OBS_INFLATION = 1 observation-space inflation (deprecated)
!> VARYING_SS_INFLATION = 2 spatially-varying state-space inflation
!> SINGLE_SS_INFLATION = 3 spatially-constant state-space inflation
!> RELAXATION_TO_PRIOR_SPREAD = 4 (available only with posterior inflation)
!> ENHANCED_SS_INFLATION = 5 Inverse Gamma version of VARYING_SS_INFLATION

function set_inflation_flavor(flavor_string) result(flavors)

character(len=*), intent(in) :: flavor_string(2)
integer :: flavors(2)

integer :: int_options(7) = (/ NO_INFLATION, &
OBS_INFLATION, &
VARYING_SS_INFLATION, &
SINGLE_SS_INFLATION, &
RELAXATION_TO_PRIOR_SPREAD, &
RELAXATION_TO_PRIOR_SPREAD, &
ENHANCED_SS_INFLATION /)

character(len=32) :: string_options(7) = (/ 'NO_INFLATION ',&
'OBS_INFLATION ',&
'VARYING_SS_INFLATION ',&
'SINGLE_SS_INFLATION ',&
'RELAXATION_TO_PRIOR_SPREAD',&
'RTPS ',&
'ENHANCED_SS_INFLATION ' /)

flavors(PRIOR_INF) = get_value_from_string(flavor_string(PRIOR_INF), &
int_options, string_options, 'input_nml:inf_flavor(1)')
flavors(POSTERIOR_INF) = get_value_from_string(flavor_string(POSTERIOR_INF), &
int_options, string_options, 'input_nml:inf_flavor(2)')

end function set_inflation_flavor


!==================================================================
! TEST FUNCTIONS BELOW THIS POINT
!------------------------------------------------------------------
Expand Down
71 changes: 8 additions & 63 deletions assimilation_code/modules/assimilation/filter_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module filter_mod
operator(-), print_time

use utilities_mod, only : error_handler, E_ERR, E_MSG, E_DBG, &
logfileunit, nmlfileunit, timestamp, get_value_from_string, &
logfileunit, nmlfileunit, timestamp, &
do_output, find_namelist_in_file, check_namelist_read, &
open_file, close_file, do_nml_file, do_nml_term, to_upper, &
set_multiple_filename_lists, find_textfile_dims
Expand Down Expand Up @@ -237,11 +237,8 @@ module filter_mod
! The inflation algorithm variables are defined in adaptive_inflate_mod.
! We use the integer parameters for PRIOR_INF and POSTERIOR_INF from
! adaptive_inflate_mod to index these 'length 2' arrays.
! To support more flexible methods of specifying the inflation algorithm,
! inf_flavor must be a character string whose value is converted to an
! integer to be backward compatible.

character(len=32) :: inf_flavor(2) = (/ 'none', 'none' /)
integer :: inf_flavor(2) = 0
logical :: inf_initial_from_restart(2) = .false.
logical :: inf_sd_initial_from_restart(2) = .false.
logical :: inf_deterministic(2) = .true.
Expand Down Expand Up @@ -311,9 +308,6 @@ module filter_mod
write_obs_every_cycle, &
allow_missing_clm


integer :: inflation_flavor(2)

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

contains
Expand Down Expand Up @@ -401,18 +395,13 @@ subroutine filter_main()

call trace_message('Before initializing inflation')

! inf_flavor from the namelist is now a character string.
! the inflation-related subroutines require an integer so the
! variable inflation_flavor is added and is type integer.
inflation_flavor = set_inflation_flavor(inf_flavor)

call validate_inflate_options(inflation_flavor, inf_damping, inf_initial_from_restart, &
call validate_inflate_options(inf_flavor, inf_damping, inf_initial_from_restart, &
inf_sd_initial_from_restart, inf_deterministic, inf_sd_max_change, &
do_prior_inflate, do_posterior_inflate, output_inflation, compute_posterior)

! Initialize the adaptive inflation module
call adaptive_inflate_init(prior_inflate, &
inflation_flavor(PRIOR_INF), &
inf_flavor(PRIOR_INF), &
inf_initial_from_restart(PRIOR_INF), &
inf_sd_initial_from_restart(PRIOR_INF), &
output_inflation, &
Expand All @@ -427,7 +416,7 @@ subroutine filter_main()
allow_missing, 'Prior')

call adaptive_inflate_init(post_inflate, &
inflation_flavor(POSTERIOR_INF), &
inf_flavor(POSTERIOR_INF), &
inf_initial_from_restart(POSTERIOR_INF), &
inf_sd_initial_from_restart(POSTERIOR_INF), &
output_inflation, &
Expand All @@ -442,13 +431,13 @@ subroutine filter_main()
allow_missing, 'Posterior')

if (do_output()) then
if (inflation_flavor(PRIOR_INF) > NO_INFLATION .and. &
if (inf_flavor(PRIOR_INF) > NO_INFLATION .and. &
inf_damping(PRIOR_INF) < 1.0_r8) then
write(msgstring, '(A,F12.6,A)') 'Prior inflation damping of ', &
inf_damping(PRIOR_INF), ' will be used'
call error_handler(E_MSG,'filter_main:', msgstring)
endif
if (inflation_flavor(POSTERIOR_INF) > NO_INFLATION .and. &
if (inf_flavor(POSTERIOR_INF) > NO_INFLATION .and. &
inf_damping(POSTERIOR_INF) < 1.0_r8) then
write(msgstring, '(A,F12.6,A)') 'Posterior inflation damping of ', &
inf_damping(POSTERIOR_INF), ' will be used'
Expand Down Expand Up @@ -2394,7 +2383,7 @@ function count_state_ens_copies(ens_size, post_inflate, prior_inflate) result(nu
! then we need an extra copy to hold (save) the prior ensemble spread
! ENS_SD_COPY will be overwritten with the posterior spread before
! applying the inflation algorithm; must save the prior ensemble spread in a different copy
if ( inflation_flavor(POSTERIOR_INF) == RELAXATION_TO_PRIOR_SPREAD ) then
if ( inf_flavor(POSTERIOR_INF) == RELAXATION_TO_PRIOR_SPREAD ) then
SPARE_PRIOR_SPREAD = next_copy_number(cnum)
endif

Expand Down Expand Up @@ -2762,50 +2751,6 @@ subroutine set_copies(cnum, STAGE_COPIES)

end subroutine set_copies


!-------------------------------------------------------------------------------
!> The infl_flavor namelist is a string, and specifies the inflation algorithm.
!> The character string can either be the name associated with the type of inflation
!> or the integer associated with the type of inflation. The string names of the
!> inflation algorithms is based on what is declared in the adaptive_inflate_mod.f90
!> which is repeated here for reference.
!>
!> NO_INFLATION = 0
!> OBS_INFLATION = 1 observation-space inflation (deprecated)
!> VARYING_SS_INFLATION = 2 spatially-varying state-space inflation
!> SINGLE_SS_INFLATION = 3 spatially-constant state-space inflation
!> RELAXATION_TO_PRIOR_SPREAD = 4 (available only with posterior inflation)
!> ENHANCED_SS_INFLATION = 5 Inverse Gamma version of VARYING_SS_INFLATION

function set_inflation_flavor(flavor_string) result(flavors)

character(len=*), intent(in) :: flavor_string(2)
integer :: flavors(2)

integer :: int_options(7) = (/ NO_INFLATION, &
OBS_INFLATION, &
VARYING_SS_INFLATION, &
SINGLE_SS_INFLATION, &
RELAXATION_TO_PRIOR_SPREAD, &
RELAXATION_TO_PRIOR_SPREAD, &
ENHANCED_SS_INFLATION /)

character(len=32) :: string_options(7) = (/ 'NO_INFLATION ',&
'OBS_INFLATION ',&
'VARYING_SS_INFLATION ',&
'SINGLE_SS_INFLATION ',&
'RELAXATION_TO_PRIOR_SPREAD',&
'RTPS ',&
'ENHANCED_SS_INFLATION ' /)

flavors(PRIOR_INF) = get_value_from_string(flavor_string(PRIOR_INF), &
int_options, string_options, 'input_nml:inf_flavor(1)')
flavors(POSTERIOR_INF) = get_value_from_string(flavor_string(POSTERIOR_INF), &
int_options, string_options, 'input_nml:inf_flavor(2)')

end function set_inflation_flavor


!==================================================================
! TEST FUNCTIONS BELOW THIS POINT
!------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
author = 'Data Assimilation Research Section'

# The full version, including alpha/beta/rc tags
release = '9.12.0'
release = '9.12.1'
master_doc = 'README'

# -- General configuration ---------------------------------------------------
Expand Down

0 comments on commit 2caa99d

Please sign in to comment.