Skip to content

Commit

Permalink
organized memory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Jun 3, 2024
1 parent 1025a47 commit 38fe628
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 35 deletions.
57 changes: 38 additions & 19 deletions tests/memtest.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,46 @@
program memtest
use photochem, only: Atmosphere, dp
implicit none

type(Atmosphere) :: pcs

call test_badfile(pcs)
call test_twoinitializations(pcs)
call test_photochemical_equilibrium(pcs)
call test_out2atmosphere(pcs)
call test_gas_fluxes(pcs)
call test_set_lower_bc(pcs)
call test_set_upper_bc(pcs)
call test_production_and_loss(pcs)
call test_redox_conservation(pcs)
call test_atom_conservation(pcs)
call test_evolve(pcs)
call test_set_temperature(pcs)
call test_custom_binary_diffusion(pcs)
call test_update_vertical_grid(pcs)
call test_press_temp_edd(pcs)
call test_autodiff(pcs)
call test()

contains

subroutine test()
type(Atmosphere) :: pcs

call test_badfile(pcs)
call test_twoinitializations(pcs)

! prep_atm_background_gas : test_gas_fluxes
! prep_atmosphere : test_gas_fluxes
! right_hand_side_chem : test_gas_fluxes
call test_production_and_loss(pcs)
! right_hand_side : test_photochemical_equilibrium
! jacobian : test_photochemical_equilibrium
call test_evolve(pcs)
! check_for_convergence : test_photochemical_equilibrium
call test_photochemical_equilibrium(pcs)
! initialize_stepper : test_photochemical_equilibrium
! step : test_photochemical_equilibrium
! destory_stepper : test_photochemical_equilibrium
call test_out2atmosphere(pcs)
! out2in : NOT TESTED
call test_gas_fluxes(pcs)
call test_atom_conservation(pcs)
call test_redox_conservation(pcs)
call test_set_lower_bc(pcs)
call test_set_upper_bc(pcs)
call test_set_temperature(pcs)
call test_set_press_temp_edd(pcs)
! set_rate_fcn :: NOT TESTED
call test_update_vertical_grid(pcs)

! Other tests
call test_custom_binary_diffusion(pcs)
call test_autodiff(pcs)

end subroutine

subroutine test_badfile(pc)
type(Atmosphere), intent(inout) :: pc
Expand Down Expand Up @@ -298,7 +317,7 @@ subroutine test_update_vertical_grid(pc)

end subroutine

subroutine test_press_temp_edd(pc)
subroutine test_set_press_temp_edd(pc)
type(Atmosphere), intent(inout) :: pc
character(:), allocatable :: err

Expand Down
86 changes: 70 additions & 16 deletions tests/memtest_evo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,44 @@ program memtest_evo
use photochem, only: EvoAtmosphere, dp
implicit none

type(EvoAtmosphere) :: pcs

call test_climate()
call test_twoinitializations(pcs)
call test_out2atmosphere(pcs)
call test_gas_fluxes(pcs)
call test_set_lower_bc(pcs)
call test_set_upper_bc(pcs)
call test_production_and_loss(pcs)
call test_set_temperature(pcs)
call test_update_vertical_grid(pcs)
call test_press_temp_edd(pcs)
call test_autodiff(pcs)
call test_evolve(pcs)
call test()

contains

subroutine test()
type(EvoAtmosphere) :: pcs

call test_climate() ! Test climate version
call test_twoinitializations(pcs) ! Test initialization

! Test all functions in code. Comments indicates if function is already
! tested in another test.

! set_trop_ind : test_climate
! prep_atm_evo_gas : test_production_and_loss
! prep_atmosphere : test_production_and_loss
! right_hand_side_chem : gas_fluxes
call test_production_and_loss(pcs)
! right_hand_side : test_step
! jacobian : test_step
call test_evolve(pcs)
! check_for_convergence : test_step
! initialize_stepper : test_step
call test_step(pcs)
! destroy_stepper : test_step
call test_out2atmosphere(pcs)
call test_gas_fluxes(pcs)
call test_set_lower_bc(pcs)
call test_set_upper_bc(pcs)
! set_rate_fcn : NOT TESTED
call test_set_temperature(pcs)
call test_set_press_temp_edd(pcs)
call test_update_vertical_grid(pcs)
! rebin_update_vertical_grid : NOT TESTED
! regrid_prep_atmosphere : NOT TESTED

end subroutine

subroutine make_new_mechanism(err)
use fortran_yaml_c, only: YamlFile, type_dictionary, type_list, type_error, type_list_item
character(:), allocatable, intent(out) :: err
Expand Down Expand Up @@ -254,7 +275,7 @@ subroutine test_update_vertical_grid(pc)

end subroutine

subroutine test_press_temp_edd(pc)
subroutine test_set_press_temp_edd(pc)
type(EvoAtmosphere), intent(inout) :: pc
character(:), allocatable :: err

Expand All @@ -266,11 +287,12 @@ subroutine test_press_temp_edd(pc)

end subroutine

subroutine test_autodiff(pc)
subroutine test_step(pc)
type(EvoAtmosphere), intent(inout) :: pc

character(:), allocatable :: err
real(dp) :: tn
logical :: converged

pc%var%autodiff = .true.
pc%var%atol = 1.0e-20_dp
Expand All @@ -287,6 +309,38 @@ subroutine test_autodiff(pc)
stop 1
endif

converged = pc%check_for_convergence(err)
if (allocated(err)) then
print*,trim(err)
stop 1
endif

call pc%destroy_stepper(err)
if (allocated(err)) then
print*,trim(err)
stop 1
endif

pc%var%autodiff = .false.

call pc%initialize_stepper(pc%var%usol_init, err)
if (allocated(err)) then
print*,trim(err)
stop 1
endif

tn = pc%step(err)
if (allocated(err)) then
print*,trim(err)
stop 1
endif

converged = pc%check_for_convergence(err)
if (allocated(err)) then
print*,trim(err)
stop 1
endif

call pc%destroy_stepper(err)
if (allocated(err)) then
print*,trim(err)
Expand Down

0 comments on commit 38fe628

Please sign in to comment.