get_module_kmesh Subroutine

private subroutine get_module_kmesh(settings, recip_lattice, global_kmesh_set, global_kmesh, error, comm, moduleprefix, should_be_defined, module_kmesh)

Uses

  • proc~~get_module_kmesh~~UsesGraph proc~get_module_kmesh get_module_kmesh module~w90_comms w90_comms proc~get_module_kmesh->module~w90_comms module~w90_error w90_error proc~get_module_kmesh->module~w90_error module~w90_constants w90_constants module~w90_comms->module~w90_constants module~w90_error_base w90_error_base module~w90_comms->module~w90_error_base module~w90_error->module~w90_comms module~w90_error->module~w90_error_base

This function reads and sets the interpolation mesh variables needed by a given module

This function MUST be called after having read the global kmesh and kmesh_spacing!! if the user didn't provide an interpolation_mesh_spacing, it is set to -1, so that one can check in the code what the user asked for The function takes care also of setting the default value to the global one if no local keyword is defined

Arguments

Type IntentOptional Attributes Name
type(settings_type), intent(inout) :: settings
real(kind=dp), intent(in) :: recip_lattice(3,3)
logical, intent(in) :: global_kmesh_set
type(kmesh_spacing_type), intent(in) :: global_kmesh
type(w90_error_type), intent(out), allocatable :: error
type(w90_comm_type), intent(in) :: comm
character(len=*), intent(in) :: moduleprefix

The prefix that is appended before the name of the variables. In particular, if the prefix is for instance XXX, the two variables that are read from the input file are XXX_kmesh and XXX_kmesh_spacing.

logical, intent(in) :: should_be_defined

A logical flag: if it is true, at the end the code stops if no value is specified. Define it to .false. if no check should be performed. Often, you can simply pass the flag that activates the module itself.

type(kmesh_spacing_type), intent(inout) :: module_kmesh

the integer array (length 3) where the interpolation mesh will be saved, and the real number on which the min mesh spacing is saved. -1 if it the user specifies in input the mesh and not the mesh_spacing


Calls

proc~~get_module_kmesh~~CallsGraph proc~get_module_kmesh get_module_kmesh proc~set_error_input set_error_input proc~get_module_kmesh->proc~set_error_input proc~w90_readwrite_get_keyword w90_readwrite_get_keyword proc~get_module_kmesh->proc~w90_readwrite_get_keyword proc~w90_readwrite_get_keyword_vector w90_readwrite_get_keyword_vector proc~get_module_kmesh->proc~w90_readwrite_get_keyword_vector proc~w90_readwrite_get_vector_length w90_readwrite_get_vector_length proc~get_module_kmesh->proc~w90_readwrite_get_vector_length proc~w90_readwrite_set_kmesh w90_readwrite_set_kmesh proc~get_module_kmesh->proc~w90_readwrite_set_kmesh proc~comms_sync_error comms_sync_error proc~set_error_input->proc~comms_sync_error proc~set_base_error set_base_error proc~set_error_input->proc~set_base_error proc~w90_readwrite_get_keyword->proc~set_error_input proc~set_error_fatal set_error_fatal proc~w90_readwrite_get_keyword->proc~set_error_fatal proc~w90_readwrite_get_keyword_vector->proc~set_error_input proc~w90_readwrite_get_keyword_vector->proc~set_error_fatal proc~w90_readwrite_get_vector_length->proc~set_error_input proc~w90_readwrite_get_vector_length->proc~set_error_fatal proc~set_error_fatal->proc~comms_sync_error proc~set_error_fatal->proc~set_base_error

Called by

proc~~get_module_kmesh~~CalledByGraph proc~get_module_kmesh get_module_kmesh proc~w90_wannier90_readwrite_read_local_kmesh w90_wannier90_readwrite_read_local_kmesh proc~w90_wannier90_readwrite_read_local_kmesh->proc~get_module_kmesh proc~w90_postw90_readwrite_read w90_postw90_readwrite_read proc~w90_postw90_readwrite_read->proc~w90_wannier90_readwrite_read_local_kmesh proc~w90_postw90_readwrite_readall w90_postw90_readwrite_readall proc~w90_postw90_readwrite_readall->proc~w90_wannier90_readwrite_read_local_kmesh program~postw90 postw90 program~postw90->proc~w90_postw90_readwrite_read

Source Code

  subroutine get_module_kmesh(settings, recip_lattice, global_kmesh_set, global_kmesh, error, &
                              comm, moduleprefix, should_be_defined, module_kmesh)
    !================================================!
    !! This function reads and sets the interpolation mesh variables needed by a given module
    !>
    !!  This function MUST be called after having read the global kmesh and kmesh_spacing!!
    !!  if the user didn't provide an interpolation_mesh_spacing, it is set to -1, so that
    !!       one can check in the code what the user asked for
    !!  The function takes care also of setting the default value to the global one if no local
    !!       keyword is defined
    !================================================!

    use w90_error, only: w90_error_type
    use w90_comms, only: w90_comm_type

    real(kind=dp), intent(in) :: recip_lattice(3, 3)
    character(len=*), intent(in)       :: moduleprefix
    !!The prefix that is appended before the name of the variables. In particular,
    !!if the prefix is for instance XXX, the two variables that are read from the
    !!input file are XXX_kmesh and XXX_kmesh_spacing.
    logical, intent(in)                :: should_be_defined
    !! A logical flag: if it is true, at the end the code stops if no value is specified.
    !! Define it to .false. if no check should be performed.
    !! Often, you can simply pass the flag that activates the module itself.
    type(kmesh_spacing_type), intent(inout) :: module_kmesh
    !! the integer array (length 3) where the interpolation mesh will be saved, and
    !! the real number on which the min mesh spacing is saved. -1 if it the
    !!user specifies in input the mesh and not the mesh_spacing
    logical, intent(in) :: global_kmesh_set
    type(kmesh_spacing_type), intent(in) :: global_kmesh
    type(w90_error_type), allocatable, intent(out) :: error
    type(w90_comm_type), intent(in) :: comm
    type(settings_type), intent(inout) :: settings

    logical :: found, found2
    integer :: i

    ! Default values
    module_kmesh%spacing = -1._dp
    module_kmesh%mesh = 0
    call w90_readwrite_get_keyword(settings, trim(moduleprefix)//'_kmesh_spacing', found, error, &
                                   comm, r_value=module_kmesh%spacing)
    if (allocated(error)) return
    if (found) then
      if (module_kmesh%spacing .le. 0._dp) then
        call set_error_input(error, 'Error: '//trim(moduleprefix)//'_kmesh_spacing must be greater than zero', comm)
        return
      end if

      call w90_readwrite_set_kmesh(module_kmesh%spacing, recip_lattice, module_kmesh%mesh)
    end if
    call w90_readwrite_get_vector_length(settings, trim(moduleprefix)//'_kmesh', found2, i, &
                                         error, comm)
    if (allocated(error)) return
    if (found2) then
      if (found) then
        call set_error_input(error, 'Error: cannot set both '//trim(moduleprefix)//'_kmesh and ' &
                             //trim(moduleprefix)//'_kmesh_spacing', comm)
        return
      end if
      if (i .eq. 1) then
        call w90_readwrite_get_keyword_vector(settings, trim(moduleprefix)//'_kmesh', found2, &
                                              1, error, comm, i_value=module_kmesh%mesh)
        if (allocated(error)) return
        module_kmesh%mesh(2) = module_kmesh%mesh(1)
        module_kmesh%mesh(3) = module_kmesh%mesh(1)
      elseif (i .eq. 3) then
        call w90_readwrite_get_keyword_vector(settings, trim(moduleprefix)//'_kmesh', found2, &
                                              3, error, comm, i_value=module_kmesh%mesh)
        if (allocated(error)) return
      else
        call set_error_input(error, 'Error: '//trim(moduleprefix)// &
                             '_kmesh must be provided as either one integer or a vector of 3 integers', &
                             comm)
        return
      end if
      if (any(module_kmesh%mesh <= 0)) then
        call set_error_input(error, 'Error: '//trim(moduleprefix)//'_kmesh elements must be greater than zero', comm)
        return
      end if
    end if

    if ((found .eqv. .false.) .and. (found2 .eqv. .false.)) then
      ! This is the case where no  "local" interpolation k-mesh is provided in the input
      if (global_kmesh_set) then
        module_kmesh%mesh = global_kmesh%mesh
        ! I set also boltz_kmesh_spacing so that I can check if it is < 0 or not, and if it is
        ! > 0 I can print on output the mesh spacing that was chosen
        module_kmesh%spacing = global_kmesh%spacing
      else
        if (should_be_defined) then
          call set_error_input(error, 'Error: '//trim(moduleprefix)//' module required, but no interpolation mesh given.', comm)
          return
        end if
      end if
    end if
  end subroutine get_module_kmesh