eig66_data.F90 5.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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
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
    END TYPE

    TYPE,EXTENDS(t_data):: t_data_DA
        REAL,   ALLOCATABLE:: el_s(:,:),ello_s(:,:),evac_s(:)
        INTEGER,ALLOCATABLE:: kvec_s(:,:),kveclo_s(:)
        INTEGER            :: recl_bas=0,recl_vec=0
        CHARACTER(LEN=20)  :: fname="eig"
        INTEGER            :: file_io_id_bas,file_io_id_vec
    END TYPE

    TYPE,extends(t_data):: t_data_MPI
       INTEGER             :: n_size=1
       INTEGER             :: size_k,size_el,size_ello,size_eig
       INTEGER             :: int_handle,real_handle,eig_handle,zr_handle,zc_handle,neig_handle
       INTEGER,ALLOCATABLE :: pe_basis(:,:),slot_basis(:,:)
       INTEGER,ALLOCATABLE :: pe_ev(:,:,:),slot_ev(:,:,:)
       INTEGER             :: irank
       INTEGER,POINTER     :: neig_data(:),int_data(:)
       REAL,POINTER        :: eig_data(:),zr_data(:),real_data(:)
       COMPLEX,POINTER     :: zc_data(:)
    END TYPE
    TYPE,EXTENDS(t_data):: t_data_hdf
#ifdef CPP_HDF
         INTEGER(HID_T) :: fid
         INTEGER(HID_T) :: esetid,evacsetid,ellosetid
         INTEGER(HID_T) :: bksetid,wksetid,ksetid
         INTEGER(HID_T) :: neigsetid,nvsetid,nmatsetid
         INTEGER(HID_T) :: energysetid,evsetid
         CHARACTER(LEN=20) :: fname="eig"
#endif
      END TYPE

   TYPE,EXTENDS(t_data):: t_data_mem
        INTEGER,ALLOCATABLE :: eig_int(:,:)
        REAL,ALLOCATABLE    :: eig_real(:,:)
        REAL,ALLOCATABLE    :: eig_eig(:,:)
        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
    
    subroutine eig66_data_storedefault(d,jspins,nkpts,nmat,neig,lmax,nlotot,nlo,ntype)
    CLASS(t_data)::d
    INTEGER,INTENT(IN)::jspins,nkpts,nmat,neig,lmax,nlotot,nlo,ntype
    d%jspins=jspins
    d%nkpts=nkpts
    d%nmat=nmat
    d%neig=neig
    d%lmax=lmax
    d%nlotot=nlotot
    d%nlo=nlo
    d%ntype=ntype
    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