Skip to content

Commit

Permalink
settings file can adjust default condensation params
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Jun 3, 2024
1 parent c3b590f commit b572494
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 408 deletions.
3 changes: 3 additions & 0 deletions examples/ModernEarth/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ planet:
# If true, then water will condense.
water-condensation: false

particles:
- {name: H2Oaer, RH-condensation: 0.5}

# Specifies boundary conditions. If a species is not specified, then
# the model assumes zero-flux boundary conditions at the top and
# bottom of the atmosphere
Expand Down
3 changes: 3 additions & 0 deletions examples/ModernEarth/settings_Atmosphere.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ planet:
# If true, then water will condense.
water-condensation: false

particles:
- {name: H2Oaer, RH-condensation: 0.5}

# Specifies boundary conditions. If a species is not specified, then
# the model assumes zero-flux boundary conditions at the top and
# bottom of the atmosphere
Expand Down
390 changes: 0 additions & 390 deletions examples/using_VULCAN_reactions.ipynb

This file was deleted.

11 changes: 11 additions & 0 deletions src/input/photochem_input_read.f90
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,17 @@ subroutine unpack_settings(infile, s, dat, var, err)
!!!!!!!!!!!!!!!!!
! Condensation rate parameters. size is zero when there are no particles
allocate(var%cond_params(dat%np))
! Replace default values with values from settings file, if needed
if (allocated(s%particles) .and. dat%there_are_particles) then
do i = 1,size(s%particles)
ind = findloc(dat%species_names(1:dat%np),s%particles(i)%name)
if (ind(1) == 0) then
err = 'Particle '//s%particles(i)%name//' in the settings file is not a particle in the reaction file.'
return
endif
var%cond_params(ind(1)) = s%particles(i)%params
enddo
endif

!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! boundary-conditions !!!
Expand Down
26 changes: 17 additions & 9 deletions src/photochem_types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ module photochem_types ! make a giant IO object
real(dp) :: den
real(dp) :: press
end type

!> Condensation parameters
type :: CondensationParameters
real(dp) :: k_cond = 100.0_dp !! rate coefficient for condensation
real(dp) :: k_evap = 10.0_dp !! rate coefficient for evaporation
real(dp) :: RHc = 1.0_dp !! RH where condensation occurs
real(dp) :: smooth_factor = 0.2_dp !! A factor that smooths condensation/evaporation
!! rate to prevents stiffness
end type

type :: SettingsParticle
character(:), allocatable :: name
type(CondensationParameters) :: params
endtype

type :: PhotoSettings
character(:), allocatable :: filename

Expand Down Expand Up @@ -69,6 +83,9 @@ module photochem_types ! make a giant IO object
real(dp) :: rainfall_rate
character(s_str_len), allocatable :: rainout_species(:)
real(dp) :: trop_alt

! particles
type(SettingsParticle), allocatable :: particles(:)

! boundary-conditions
type(SettingsBC), allocatable :: ubcs(:)
Expand Down Expand Up @@ -367,15 +384,6 @@ subroutine time_dependent_rate_fcn(tn, nz, rate)
integer :: LH !! H index

end type

!> Condensation parameters
type :: CondensationParameters
real(dp) :: k_cond = 100.0_dp !! rate coefficient for condensation
real(dp) :: k_evap = 10.0_dp !! rate coefficient for evaporation
real(dp) :: RHc = 1.0_dp !! RH where condensation occurs
real(dp) :: smooth_factor = 0.2_dp !! A factor that smooths condensation/evaporation
!! rate to prevents stiffness
end type

type :: PhotochemVars
! PhotochemVars contains information that can change between
Expand Down
57 changes: 57 additions & 0 deletions src/photochem_types_create.f90
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function unpack_PhotoSettings(root, filename, err) result(s)
character(:), allocatable :: temp_char
logical :: success
integer :: i, j
real(dp) :: tmp_real

! filename
s%filename = filename
Expand Down Expand Up @@ -233,6 +234,7 @@ function unpack_PhotoSettings(root, filename, err) result(s)
if (s%gas_rainout) then
nullify(list)
list => tmp2%get_list('rainout-species', required = .false., error = io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif
if (associated(list)) then
call unpack_string_list(list, s%rainout_species, err)
if (allocated(err)) return
Expand All @@ -257,6 +259,61 @@ function unpack_PhotoSettings(root, filename, err) result(s)
endif

endif

! Particles
nullify(list)
list => root%get_list('particles',.false.,error=io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif
if (associated(list)) then
allocate(s%particles(list%size()))
i = 1
item => list%first
do while (associated(item))

select type (e => item%node)
class is (type_dictionary)
s%particles(i)%name = e%get_string('name', error=io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif

tmp_real = s%particles(i)%params%k_cond
s%particles(i)%params%k_cond = e%get_real('condensation-rate', default=tmp_real, error=io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif

tmp_real = s%particles(i)%params%k_evap
s%particles(i)%params%k_evap = e%get_real('evaporation-rate', default=tmp_real, error=io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif

tmp_real = s%particles(i)%params%RHc
s%particles(i)%params%RHc = e%get_real('RH-condensation', default=tmp_real, error=io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif

tmp_real = s%particles(i)%params%smooth_factor
s%particles(i)%params%smooth_factor = e%get_real('smooth-factor', default=tmp_real, error=io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif

class default
err = "IOError: Particles must be a list of dictionaries"
return
end select

i = i + 1
item => item%next
enddo

block
character(s_str_len), allocatable :: names(:)
allocate(names(size(s%particles)))
do i = 1,size(names)
names(i) = s%particles(i)%name
enddo
i = check_for_duplicates(names)
if (i /= 0) then
err = '"'//trim(names(i))//'" is a duplicate particle in '//trim(filename)
return
endif
endblock

endif

!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! boundary-conditions !!!
Expand Down
6 changes: 1 addition & 5 deletions tests/testevo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ subroutine main_()
print*,trim(err)
stop 1
endif

! Change RH to 0.5.
ind = findloc(pc%dat%species_names, 'H2Oaer', 1)
pc%var%cond_params(ind)%RHc = 0.5_dp


! Initialize stepper
call pc%initialize_stepper(pc%var%usol_init, err)
if (allocated(err)) then
Expand Down
4 changes: 0 additions & 4 deletions tests/testrun.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ subroutine main_()
stop 1
endif

! Change RH to 0.5.
ind = findloc(pc%dat%species_names, 'H2Oaer', 1)
pc%var%cond_params(ind)%RHc = 0.5_dp

! Initialize stepper
call pc%initialize_stepper(pc%var%usol_init, err)
if (allocated(err)) then
Expand Down

0 comments on commit b572494

Please sign in to comment.