Initialize test: set Command Line Interface, parse it and check its validity.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(lcce_test), | intent(inout) | :: | self | Test. |
subroutine initialize(self)
!< Initialize test: set Command Line Interface, parse it and check its validity.
class(lcce_test), intent(inout) :: self !< Test.
call set_cli
call parse_cli
contains
subroutine set_cli()
!< Set Command Line Interface.
associate(cli => self%cli)
call cli%init(progname = 'foodie_test_lcce', &
authors = 'Fortran-FOSS-Programmers', &
license = 'GNU GPLv3', &
description = 'Test FOODIE library on linear constant coefficients equation integration', &
examples = ["foodie_test_lcce --scheme euler_explicit --save_results ", &
"foodie_test_lcce --scheme all -r "])
call cli%add(switch='--scheme', switch_ab='-s', help='integrator scheme used', required=.false., def='all', act='store')
call cli%add(switch='--fast', help='activate fast solvers', required=.false., act='store_true', def='.false.')
call cli%add(switch='--iterations', help='iterations number for implicit schemes', required=.false., act='store', def='5')
call cli%add(switch='--stages', help='stages number', required=.false., def='4', act='store')
call cli%add(switch='--time_step', switch_ab='-Dt', nargs='+', help='time step', required=.false., def='0.01', act='store')
call cli%add(switch='--a', switch_ab='-a', help='"a" coefficient', required=.false., def='-1.0', act='store')
call cli%add(switch='--b', switch_ab='-b', help='"b" coefficient', required=.false., def='0.0', act='store')
call cli%add(switch='--U0', switch_ab='-U0', help='initial state', required=.false., def='1.0', act='store')
call cli%add(switch='--t_final', switch_ab='-tf', help='final integration time', required=.false., def='1.0', act='store')
call cli%add(switch='--save_results', switch_ab='-r', help='save result', required=.false., act='store_true', def='.false.')
call cli%add(switch='--output', help='output files basename', required=.false., act='store', def='foodie_test_lcce')
call cli%add(switch='--exact_solution', help='save exact solutiion', required=.false., act='store_true', def='.false.')
call cli%add(switch='--errors_analysis', help='peform errors analysis', required=.false., act='store_true', def='.false.')
endassociate
endsubroutine set_cli
subroutine parse_cli()
!< Parse Command Line Interface and check its validity.
character(99), allocatable :: integrator_class_names(:) !< Name of FOODIE integrator classes.
character(99), allocatable :: integrator_schemes(:) !< Name of FOODIE integrator schemes.
integer(I_P) :: i !< Counter.
call self%cli%parse(error=self%error)
call self%cli%get(switch='-s', val=self%scheme, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='--fast', val=self%is_fast, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='--iterations', val=self%implicit_iterations, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='--stages', val=self%stages, error=self%error) ; if (self%error/=0) stop
call self%cli%get_varying(switch='-Dt', val=self%Dt, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='-a', val=self%a, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='-b', val=self%b, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='-U0', val=self%U0, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='-tf', val=self%final_time, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='-r', val=self%results, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='--output', val=self%output, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='--exact_solution', val=self%exact_solution, error=self%error) ; if (self%error/=0) stop
call self%cli%get(switch='--errors_analysis', val=self%errors_analysis, error=self%error) ; if (self%error/=0) stop
if (trim(adjustl(self%scheme)) /= 'all') then
if (.not.is_available(scheme=self%scheme)) then
integrator_class_names = foodie_integrator_class_names()
integrator_schemes = foodie_integrator_schemes()
print '(A)', 'Error: the scheme "'//trim(adjustl(self%scheme))//'" is unknown!'
print '(A)', 'Supported classes of schemes are:'
do i=1, size(integrator_class_names, dim=1)
print '(A)', ' '//trim(integrator_class_names(i))
enddo
print '(A)', 'Supported schemes are:'
do i=1, size(integrator_schemes, dim=1)
print '(A)', ' '//trim(integrator_schemes(i))
enddo
stop
endif
endif
if (.not.is_dt_valid()) then
print "(A)", 'Error: the final integration time must be an exact multiple of the time step used!'
print "(A)", 'Final integration time: '//str(self%final_time, .true.)
print "(A)", 'Time step: '//str(self%Dt, .true.)
stop
endif
if (self%errors_analysis) then
if (.not.(size(self%Dt, dim=1) > 1)) self%errors_analysis = .false.
endif
endsubroutine parse_cli
function is_dt_valid()
!< Verify if the selected time step Dt is valid.
logical :: is_dt_valid !< Return true is the selected time step Dt is valid.
integer(I_P) :: t !< Counter.
is_dt_valid = .true.
do t=1, size(self%Dt)
is_dt_valid = ((self%final_time - int(self%final_time/self%Dt(t), I_P)*self%Dt(t))==0)
if (.not.is_dt_valid) exit
enddo
endfunction is_dt_valid
endsubroutine initialize