initialize_equations Subroutine

public subroutine initialize_equations(state)

Initialize all the modules which are used to evolve the equations. After calling this function, gs2 reaches init%level = full.

Arguments

Type IntentOptional Attributes Name
type(gs2_program_state_type), intent(inout) :: state

Contents

Source Code


Source Code

  subroutine initialize_equations(state)
    use theta_grid, only: surfarea, dvdrhon
    use gs2_time, only: init_tstart
    use gs2_init, only: init
    use init_g, only: tstart
    use job_manage, only: time_message
    use mp, only: proc0, broadcast
    use parameter_scan, only: init_parameter_scan
    use run_parameters, only: nstep, do_eigsolve
    use unit_tests, only: debug_message
    use gs2_reinit, only: init_gs2_reinit
    implicit none
    type(gs2_program_state_type), intent(inout) :: state

    if (.not. state%included) return
    call debug_message(state%verb, 'gs2_main::initialize_equations starting')
    call time_message(.false.,state%timers%total,' Total')

    call debug_message(state%verb, 'gs2_main::initialize_equations calling init_parameter_scan')
    call init_parameter_scan

    call time_message(.false., state%timers%init,' Initialization')

    ! This triggers initializing of all the grids, all the physics parameters
    ! and all the modules which solve the equations
    call init(state%init, init_level_list%full)

    ! Set the initial simulation time (must be after init_fields
    ! because initial time may be read from a restart file)
    call init_tstart(tstart)

    ! Here we copy some geometric information required by 
    ! Trinity to state%outputs. We should probably just do this
    ! in calculate_outputs.
    if (state%set_outputs) then
       if (proc0) then
          state%outputs%dvdrho = dvdrhon
          ! Note surfarea isn't defined/set for s-alpha geometry so
          ! the following is not well defined and can cause valgrind and similar
          ! tools to flag this as an error.
          ! Note this isn't actually "grho" as defined by the rest of the
          ! code but rather "grhoavg", i.e. an average value. It may be
          ! appropriate to replace this with something like `mean(grho)`
          state%outputs%grho = surfarea / dvdrhon
       end if
       call broadcast (state%outputs%dvdrho)
       call broadcast (state%outputs%grho)
    end if
    
    call time_message(.false.,state%timers%init,' Initialization')

    ! Set defaults. These are typically only important
    ! for the standalone gs2 program
    state%nstep = nstep
    state%do_eigsolve = do_eigsolve

    call debug_message(state%verb, 'gs2_main::initialize_equations finished')

    ! Since the number of species may have changed
    ! since the last call to initialize_equations 
    ! we reallocate outputs every time.
    call deallocate_outputs(state)
    call allocate_outputs(state)

    call init_gs2_reinit

    call time_message(.false.,state%timers%total,' Total')

  end subroutine initialize_equations