initialize Subroutine

private subroutine initialize(self)

Initialize test: set Command Line Interface, parse it and check its validity.

Arguments

Type IntentOptional AttributesName
class(test_object), intent(inout) :: self

Test.


Source Code


Source Code

   subroutine initialize(self)
   !< Initialize test: set Command Line Interface, parse it and check its validity.
   class(test_object), 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_tester',                                           &
                       authors     = 'Fortran-FOSS-Programmers',                                &
                       license     = 'GNU GPLv3',                                               &
                       description = 'Tester factory of FOODIE integrators',                    &
                       examples    = ["foodie_tester test --scheme euler_explicit --save_results  ", &
                                      "foodie_tester test --scheme all -r                         "])
         call cli%add_group(description='general test settings', group='test')
         call cli%add(group='test', switch='--scheme', switch_ab='-s', help='integrator scheme used', required=.false., def='all', &
                      act='store')
         call cli%add(group='test', switch='--time_step', switch_ab='-Dt', nargs='+', help='time step', required=.false., &
                      def='1e2', act='store')
         call cli%add(group='test', switch='--fast', help='activate fast solvers', required=.false., act='store_true', &
                      def='.false.')
         call cli%add(group='test', switch='--iterations', help='iterations number for implicit schemes', required=.false., &
                      act='store', def='5')
         call cli%add(group='test', switch='--stages', help='stages number', required=.false., def='2', act='store')
         call cli%add(group='test', switch='--final_time', switch_ab='-ft', help='integration time', required=.false., def='1', &
                      act='store')
         call cli%add(group='test', switch='--save_results', switch_ab='-r',help='save result', required=.false., &
                      act='store_true', def='.false.')
         call cli%add(group='test', switch='--output', help='output file basename', required=.false., act='store', &
                      def='foodie_test')
         call cli%add(group='test', switch='--save_frequency', help='save frequency', required=.false., act='store', &
                      def='1')
      endassociate
      call self%lcce_0%set_cli(cli=self%cli)
      call self%ladvection_0%set_cli(cli=self%cli)
      call self%oscillation_0%set_cli(cli=self%cli)
      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.
      real(R_P), allocatable     :: initial_state(:)          !< Initial integrand state.
      integer(I_P)               :: i                         !< Counter.

      call self%cli%parse(error=self%error)
      call self%cli%get(group='test', switch='-s', val=self%scheme, error=self%error) ; if (self%error/=0) stop
      call self%cli%get_varying(group='test', switch='-Dt', val=self%Dt, error=self%error) ; if (self%error/=0) stop
      call self%cli%get(group='test', switch='--fast', val=self%is_fast, error=self%error) ; if (self%error/=0) stop
      call self%cli%get(group='test', switch='--iterations',val=self%implicit_iterations,error=self%error) ; if (self%error/=0) stop
      call self%cli%get(group='test', switch='--stages', val=self%stages, error=self%error) ; if (self%error/=0) stop
      call self%cli%get(group='test', switch='-ft', val=self%final_time, error=self%error) ; if (self%error/=0) stop
      call self%cli%get(group='test', switch='-r', val=self%save_results, error=self%error) ; if (self%error/=0) stop
      call self%cli%get(group='test', switch='--output', val=self%output, error=self%error) ; if (self%error/=0) stop
      call self%cli%get(group='test', switch='--save_frequency',val=self%save_frequency,error=self%error) ; if (self%error/=0) stop
      call self%lcce_0%parse_cli(cli=self%cli)
      call self%ladvection_0%parse_cli(cli=self%cli)
      call self%oscillation_0%parse_cli(cli=self%cli)

      if     (self%cli%run_command('lcce')) then
         allocate(integrand_lcce :: self%integrand_0)
         select type(integrand_0=>self%integrand_0)
         type is(integrand_lcce)
            integrand_0 = self%lcce_0
         endselect
      elseif (self%cli%run_command('linear_advection')) then
         allocate(integrand_ladvection :: self%integrand_0)
         select type(integrand_0=>self%integrand_0)
         type is(integrand_ladvection)
            integrand_0 = self%ladvection_0
         endselect
      elseif (self%cli%run_command('oscillation')) then
         allocate(integrand_oscillation :: self%integrand_0)
         select type(integrand_0=>self%integrand_0)
         type is(integrand_oscillation)
            integrand_0 = self%oscillation_0
         endselect
      else
         allocate(integrand_oscillation :: self%integrand_0)
         select type(integrand_0=>self%integrand_0)
         type is(integrand_oscillation)
            integrand_0 = self%oscillation_0
         endselect
      endif

      if (.not.is_dt_valid()) then
         write(stderr, '(A)') 'error: the final integration time must be an exact multiple of the time step used'
         write(stderr, '(A)') '       and time step must respect CFL condition, if any'
         write(stderr, '(A)') 'Final integration time: '//str(self%final_time, .true.)
         write(stderr, '(A)') 'Time step: '//str(self%Dt, .true.)
         stop
      endif

      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()
            write(stderr, '(A)') 'error: the scheme "'//trim(adjustl(self%scheme))//'" is unknown!'
            write(stderr, '(A)') 'Supported classes of schemes are:'
            do i=1, size(integrator_class_names, dim=1)
               write(stderr, '(A)') '  '//trim(integrator_class_names(i))
            enddo
            write(stderr, '(A)') 'Supported schemes are:'
            do i=1, size(integrator_schemes, dim=1)
               write(stderr, '(A)') '  '//trim(integrator_schemes(i))
            enddo
            stop
         endif
      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 (is_dt_valid) then
         !    select type(integrand=>self%integrand_0)
         !    type is(integrand_ladvection)
         !       is_dt_valid = is_dt_valid .and. self%Dt(t) <= integrand%Dt(final_time=self%final_time)
         !       if (.not.is_dt_valid) then
         !          write(stderr, '(A)') 'error: Dt violates CFL condition, Dt_max = '//str(integrand%Dt(final_time=self%final_time))
         !       endif
         !    endselect
         ! endif
         if (.not.is_dt_valid) exit
      enddo
      endfunction is_dt_valid
   endsubroutine initialize


a a a a a add_burgers add_euler add_euler add_euler add_lorenz allocate_integrand_members allocate_integrand_members allocate_integrand_members allocate_integrand_members allocate_integrand_members amplitude_phase assign_abstract assign_integrand assign_integrand assign_integrand assign_multistage assign_multistage_multistep assign_multistep assign_real assign_real assign_real average_solution burgers_assign_burgers burgers_assign_real burgers_local_error burgers_multiply_burgers burgers_multiply_real check_error check_scheme_has_fast_mode check_scheme_has_fast_mode check_scheme_has_fast_mode class_name class_name class_name class_name class_name class_name class_name class_name class_name class_name class_name class_name class_name compute_dt compute_dt compute_dt compute_dt compute_dt compute_dt compute_dt compute_dx compute_inter_states compute_inter_states compute_inter_states compute_inter_states compute_inter_states conservative2primitive conservative2primitive conservative2primitive conservative2primitive conservative2primitive d2Burgers_dx2 dBurgers_dt dBurgers_dx description description description description destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy_abstract destroy_multistage destroy_multistage_multistep destroy_multistep destroy_rk destroy_rk dEuler_dt dEuler_dt dEuler_dt dEuler_dt dEuler_dt dLorenz_dt dt_ratio dU_dt dU_dt dU_dt E E E E E error error error euler_assign_euler euler_assign_euler euler_assign_euler euler_assign_euler euler_assign_euler euler_assign_real euler_assign_real euler_assign_real euler_local_error euler_local_error euler_local_error euler_multiply_euler euler_multiply_euler euler_multiply_euler euler_multiply_real euler_multiply_real euler_multiply_real exact_solution exact_solution exact_solution execute execute execute export_tecplot export_tecplot export_tecplot foodie_integrator_class_names foodie_integrator_factory foodie_integrator_schemes H H H H H has_fast_mode has_fast_mode has_fast_mode has_fast_mode has_fast_mode has_fast_mode has_fast_mode has_fast_mode has_fast_mode has_fast_mode has_fast_mode has_fast_mode has_fast_mode impose_boundary_conditions impose_boundary_conditions impose_boundary_conditions impose_boundary_conditions impose_boundary_conditions impose_boundary_conditions init init init init init init init init init init init init init init_rk init_rk initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize initialize_order_s initialize_order_s_1 integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integr_assign_integr integrand_add_integrand integrand_add_integrand integrand_add_integrand integrand_add_integrand_fast integrand_add_integrand_fast integrand_add_integrand_fast integrand_add_real integrand_add_real integrand_add_real integrand_dimension integrand_dimension integrand_dimension integrand_multiply_integrand integrand_multiply_integrand integrand_multiply_integrand integrand_multiply_integrand_fast integrand_multiply_integrand_fast integrand_multiply_integrand_fast integrand_multiply_real integrand_multiply_real integrand_multiply_real integrand_multiply_real_scalar integrand_multiply_real_scalar integrand_multiply_real_scalar integrand_multiply_real_scalar_fast integrand_multiply_real_scalar_fast integrand_multiply_real_scalar_fast integrand_sub_integrand integrand_sub_integrand integrand_sub_integrand integrand_sub_real integrand_sub_real integrand_sub_real integrand_subtract_integrand_fast integrand_subtract_integrand_fast integrand_subtract_integrand_fast integrate integrate integrate integrate integrate integrate integrate integrate integrate integrate integrate integrate integrate integrate integrate integrate integrate_fast integrate_fast integrate_fast integrate_fast integrate_fast integrate_fast integrate_fast integrate_fast integrate_fast integrate_fast integrate_fast integrate_fast integrate_fast integrate_order_2 integrate_order_2_fast integrate_order_3 integrate_order_3_fast integrate_order_s integrate_order_s_1 integrate_order_s_1_fast integrate_order_s_fast integrate_rk integrate_rk is_admissible is_available is_class_available is_multistage is_multistage is_multistage is_multistep is_multistep is_multistep is_scheme_available is_supported is_supported is_supported is_supported is_supported is_supported is_supported is_supported is_supported is_supported is_supported is_supported is_supported local_error local_error local_error lorenz_assign_lorenz lorenz_assign_real lorenz_local_error lorenz_multiply_lorenz lorenz_multiply_real new_Dt observed_order observed_order observed_order omega output output output output output output output output output output p p p p p parse_cli parse_cli parse_cli previous_step previous_step previous_step primitive2conservative primitive2conservative primitive2conservative primitive2conservative primitive2conservative r r r r r real_add_integrand real_add_integrand real_add_integrand real_multiply_burgers real_multiply_euler real_multiply_euler real_multiply_euler real_multiply_integrand real_multiply_integrand real_multiply_integrand real_multiply_lorenz real_scalar_multiply_integrand real_scalar_multiply_integrand real_scalar_multiply_integrand real_sub_integrand real_sub_integrand real_sub_integrand reconstruct_interfaces reconstruct_interfaces_states reconstruct_interfaces_states reconstruct_interfaces_states reconstruct_interfaces_states reconstruct_interfaces_states registers_number riemann_solver riemann_solver riemann_solver riemann_solver riemann_solver save_results save_results save_results save_results save_results save_results save_results save_results save_results save_time_serie save_time_serie save_time_serie save_time_serie save_time_serie scheme_number set_cli set_cli set_cli set_sin_wave_initial_state set_square_wave_initial_state stages_number stages_number stages_number steps_number steps_number steps_number sub_burgers sub_euler sub_euler sub_euler sub_lorenz supported_schemes supported_schemes supported_schemes supported_schemes supported_schemes supported_schemes supported_schemes supported_schemes supported_schemes supported_schemes supported_schemes supported_schemes supported_schemes synchronize synchronize synchronize synchronize t_fast t_fast t_fast test test test_ab test_ab test_ab test_euler test_euler test_euler test_leapfrog test_leapfrog test_leapfrog test_ls_rk test_ls_rk test_ls_rk test_tvd_rk test_tvd_rk test_tvd_rk tokenize trigger_error update_previous update_previous update_previous_steps update_previous_steps update_previous_steps