eig66_data.F90 5.38 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

7 8 9 10 11 12 13 14 15 16
module m_eig66_data
#include "juDFT_env.h"
#ifdef CPP_HDF
    use hdf5
#endif
    implicit none

    TYPE :: t_data
       INTEGER:: io_mode
       INTEGER:: jspins,nkpts,nmat,neig,lmax,nlotot,nlo,ntype
17
       LOGICAL:: l_real,l_soc
18 19 20
    END TYPE

    TYPE,EXTENDS(t_data):: t_data_DA
21
        INTEGER            :: recl_vec=0,recl_wiks
22
        CHARACTER(LEN=20)  :: fname="eig"
23
        INTEGER            :: file_io_id_vec,file_io_id_wiks
24 25 26 27 28
    END TYPE

    TYPE,extends(t_data):: t_data_MPI
       INTEGER             :: n_size=1
       INTEGER             :: size_k,size_el,size_ello,size_eig
29
       INTEGER             :: eig_handle,zr_handle,zc_handle,neig_handle,w_iks_handle
30 31 32
       INTEGER,ALLOCATABLE :: pe_basis(:,:),slot_basis(:,:)
       INTEGER,ALLOCATABLE :: pe_ev(:,:,:),slot_ev(:,:,:)
       INTEGER             :: irank
33 34
       INTEGER,POINTER     :: neig_data(:)
       REAL,POINTER        :: eig_data(:),zr_data(:), w_iks_data(:)
35 36 37 38 39
       COMPLEX,POINTER     :: zc_data(:)
    END TYPE
    TYPE,EXTENDS(t_data):: t_data_hdf
#ifdef CPP_HDF
         INTEGER(HID_T) :: fid
40
         INTEGER(HID_T) :: neigsetid
Daniel Wortmann's avatar
Daniel Wortmann committed
41
         INTEGER(HID_T) :: energysetid,wikssetid,evsetid
42 43 44 45 46
         CHARACTER(LEN=20) :: fname="eig"
#endif
      END TYPE

   TYPE,EXTENDS(t_data):: t_data_mem
47
        INTEGER,ALLOCATABLE :: eig_int(:)
Daniel Wortmann's avatar
Daniel Wortmann committed
48
        REAL,ALLOCATABLE    :: eig_eig(:,:,:)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        REAL,ALLOCATABLE    :: eig_vecr(:,:)
        COMPLEX,ALLOCATABLE :: eig_vecc(:,:)
    END TYPE

    TYPE t_list
        INTEGER               :: id
        CLASS(t_data),POINTER :: data
        TYPE(t_list),POINTER  :: next=>null()
    END TYPE



    TYPE(t_list),POINTER :: linked_list=>null()
    private linked_list
    INTEGER, PARAMETER :: DA_mode=0,HDF_mode=1,MEM_mode=2,MPI_mode=3

    contains
    
67
    subroutine eig66_data_storedefault(d,jspins,nkpts,nmat,neig,lmax,nlotot,nlo,ntype,l_real,l_soc)
68 69
    CLASS(t_data)::d
    INTEGER,INTENT(IN)::jspins,nkpts,nmat,neig,lmax,nlotot,nlo,ntype
70
    LOGICAL,INTENT(IN):: l_real,l_soc
71 72 73 74 75 76 77 78
    d%jspins=jspins
    d%nkpts=nkpts
    d%nmat=nmat
    d%neig=neig
    d%lmax=lmax
    d%nlotot=nlotot
    d%nlo=nlo
    d%ntype=ntype
79 80
    d%l_real=l_real
    d%l_soc=l_soc
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    END SUBROUTINE

    subroutine eig66_find_data(d,id,io_mode)
    IMPLICIT NONE
    INTEGER,INTENT(IN) ::id
    INTEGER,INTENT(IN),OPTIONAL :: io_mode
    CLASS(t_data),pointer::d

    TYPE(t_list),POINTER:: listpointer,lastinlist
    lastinlist=>null()

    listpointer=>linked_list
    DO WHILE(associated(listpointer))
       lastinlist=>listpointer
       if (listpointer%id==id) THEN
           d=>listpointer%data
           return
       endif
       listpointer=>listpointer%next
    enddo
    !no pointer found
    IF (present(io_mode)) THEN
       IF (.not.associated(lastinlist)) THEN
          allocate(linked_list)
          linked_list%id=id
          lastinlist=>linked_list
       ELSE
          allocate(lastinlist%next)
          lastinlist%next%id=id
          lastinlist=>lastinlist%next
       ENDIF
       SELECT CASE (io_mode)
         case (DA_MODE)
          allocate(t_data_DA::lastinlist%data)
         case (HDF_MODE)
#ifdef CPP_HDF
          allocate(t_data_HDF::lastinlist%data)
#else
          call juDFT_error("Cannot use hdf mode for IO, recompile with CPP_HDF",calledby="eig66_data")
#endif
         case (MEM_MODE)
          allocate(t_data_MEM::lastinlist%data)
         case (MPI_MODE)
          allocate(t_data_MPI::lastinlist%data)
         end select
         lastinlist%data%io_mode=io_mode
         d=>lastinlist%data
    ELSE
       call juDFT_error("BUG:Could not find data object in eig66_mpi")
    ENDIF
    END SUBROUTINE

    subroutine eig66_remove_data(id)
    INTEGER,INTENT(IN)::id

    TYPE(t_list),POINTER:: listpointer,lastpointer
    lastpointer=>null()
    listpointer=>linked_list
    loop:DO WHILE(associated(listpointer))
      IF (listpointer%id==id) THEN
        exit loop
      ENDIF
      lastpointer=>listpointer
      listpointer=>listpointer%next
    ENDDO loop

    if (.not.associated(listpointer)) call juDFT_error("BUG in eig66_data: ID not found in deleting")
    IF (associated(lastpointer)) THEN
        lastpointer%next=>listpointer%next
    ELSE
        linked_list=>listpointer%next
    ENDIF

    deallocate(listpointer)
    end subroutine

    INTEGER FUNCTION eig66_data_newid(mode)
    INTEGER,INTENT(IN)  :: mode
    TYPE(t_list),POINTER:: listpointer
    INTEGER             :: id
    CLASS(t_data),POINTER::d

    id=0
    listpointer=>linked_list
    DO WHILE(associated(listpointer))
      id=max(id,listpointer%id)
      listpointer=>listpointer%next
    ENDDO
    eig66_data_newid=id+1

    call eig66_find_data(d,id+1,mode)

    end function

    INTEGER function eig66_data_mode(id)RESULT(mode)
    INTEGER,INTENT(IN)  :: id
    TYPE(t_list),POINTER:: listpointer
    mode=-1
    listpointer=>linked_list
    DO WHILE(associated(listpointer))
      if (id==listpointer%id) THEN
           mode=listpointer%data%io_mode
           return
      ENDIF
      listpointer=>listpointer%next
    ENDDO
    END FUNCTION

end module m_eig66_data