set_initial_field_and_dist_fn_values Subroutine

private subroutine set_initial_field_and_dist_fn_values(current)

Arguments

Type IntentOptional Attributes Name
type(init_type), intent(in) :: current

Contents


Source Code

  subroutine set_initial_field_and_dist_fn_values(current)
    use dist_fn_arrays, only: g, gnew, gexp_1, gexp_2, gexp_3
    use fields_arrays, only: phinew, aparnew, bparnew, phi, apar, bpar
    use fields, only: force_maxwell_reinit
    use fields, only: set_init_fields
    use file_utils, only: error_unit
    use init_g, only: ginit, init_vnmult
    use init_g, only: ginitopt_restart_many, initial_condition_is_nonadiabatic_dfn
    use run_parameters, only: has_phi, has_apar, has_bpar
    use collisions, only: vnmult
    use array_utils, only: copy, zero_array
    implicit none
    type (init_type), intent(in) :: current
    logical :: restarted

    if (.not. current%initval_ov%override) then
       ! This is the usual initial setup
       call ginit (restarted)
       ! If initial_condition_is_nonadiabatic_dfn then we have already
       ! calculated the correct fields, unless restarting, so return straight away.
       ! If restarting then we deal with this further below.
       if ((.not.restarted) .and. initial_condition_is_nonadiabatic_dfn) return
       ! If we're restarting from file then we don't want to recalculate
       ! the fields unless force_maxwell_reinit is true. If we are not
       ! restarting then we better call set_init_fields to set the initial
       ! fields here.
       if ((.not.restarted) .or. force_maxwell_reinit) call set_init_fields
       return
    else
       if (current%initval_ov%in_memory) then
          call copy(current%initval_ov%g, g)
          call copy(g, gnew)
          vnmult = current%initval_ov%vnmult
       else
          call ginit(restarted, ginitopt_restart_many)
          call init_vnmult(vnmult)
       end if
    end if

    if (current%initval_ov%in_memory) then
       if (allocated(current%initval_ov%gexp_1)) call copy(current%initval_ov%gexp_1, gexp_1)
       if (allocated(current%initval_ov%gexp_1)) call copy(current%initval_ov%gexp_2, gexp_2)
       if (allocated(current%initval_ov%gexp_1)) call copy(current%initval_ov%gexp_3, gexp_3)
    end if

    ! Do not use the value from state%init%initval_ov%force_maxwell_reinit = current%initval_ov%force_maxwell_reinit as follows:
    !     if (current%initval_ov%force_maxwell_reinit)then
    ! as was done previously because, when restarting a run, this part of the overrides system has not been initialised with the
    ! value from the input file yet. As a result, the above condition is always true, even if the restart file has
    ! force_maxwell_reinit = .false.! (For a reinitialisation due to a timestep change, this part of the override system would be
    ! set up correctly and the above condition would respect the value in the input file.) Unfortunately, because of the way the
    ! state object and the overrides system is set up, it is not possible to have this value correctly initialised from the input
    ! file by this point in a restarted run. Therefore, use the input file value directly to ensure we respect the value in the
    ! input file at the start of restarted runs.
    if (force_maxwell_reinit)then
       call set_init_fields
    else

       if(current%initval_ov%override .and. current%initval_ov%in_memory) then
          if(has_phi) then
             call copy(current%initval_ov%phi, phinew)
          else
             call zero_array(phinew)
          endif
          if(has_apar) then
             call copy(current%initval_ov%apar, aparnew)
          else
             call zero_array(aparnew)
          endif
          if(has_bpar) then
             call copy(current%initval_ov%bpar, bparnew)
          else
             call zero_array(bparnew)
          endif
          call copy(phinew, phi)
          call copy(aparnew, apar)
          call copy(bparnew, bpar)
       else
          ! No need to do anything: fields read from file in
          ! [[gs2_save:gs2_restore_many]]
       end if
    end if
  end subroutine set_initial_field_and_dist_fn_values