types_cell.f90 5.22 KB
Newer Older
Daniel Wortmann's avatar
Daniel Wortmann committed
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
!--------------------------------------------------------------------------------
! 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.
!--------------------------------------------------------------------------------

MODULE m_types_cell
  USE m_judft
  USE m_types_fleurinput_base
  IMPLICIT NONE
  PRIVATE
  !> This type contains the basic information on the lattice-cell of the calculation
  !> To use it, you basically only have to provide cell%amat (and cell%z1 for films)
  !> and call its init routine.
  TYPE,EXTENDS(t_fleurinput_base):: t_cell
     !vol of dtilde box
     REAL::omtil
     !2D area
     REAL::area
     !bravais matrix
     REAL::amat(3, 3)
     !rez. bravais matrx
     REAL::bmat(3, 3)
     !square of bbmat
     REAL::bbmat(3, 3),aamat(3,3)
     !d-value
     REAL::z1
     !volume of cell
     REAL::vol
     !volume of interstitial
     REAL::volint
   CONTAINS
     PROCEDURE :: init
     PROCEDURE :: read_xml=>read_xml_cell
  END TYPE t_cell
  PUBLIC t_cell
CONTAINS
Daniel Wortmann's avatar
Daniel Wortmann committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  subroutine mpi_bc(this,mpi_comm,irank)
    use m_mpi_bc_tool
    class(t_cell),INTENT(INOUT)::this
    integer,INTENT(IN):: mpi_comm
    INTEGER,INTENT(IN),OPTIONAL::irank
    INTEGER ::rank
    if (present(irank)) THEN
       rank=0
    else
       rank=irank
    end if

    call mpi_bc(this%omtil,rank,mpi_comm)
    call mpi_bc(this%area,rank,mpi_comm)
    call mpi_bc(this%amat,rank,mpi_comm)
    call mpi_bc(this%bmat,rank,mpi_comm)
    call mpi_bc(this%bbmat,rank,mpi_comm)
    call mpi_bc(this%aamat,rank,mpi_comm)
    call mpi_bc(this%z1,rank,mpi_comm)
    call mpi_bc(this%vol,rank,mpi_comm)
    call mpi_bc(this%volint,rank,mpi_comm)
  end subroutine mpi_bc
    
Daniel Wortmann's avatar
Daniel Wortmann committed
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
  SUBROUTINE init(cell)
    !initialize cell, only input is cell%amat and cell%z1 in case of a film
    USE m_constants,ONLY:tpi_const
    CLASS (t_cell),INTENT(INOUT):: cell
    
    
    CALL inv3(cell%amat,cell%bmat,cell%omtil)
    IF (cell%omtil<0) CALL judft_warn("Negative volume! You are using a left-handed coordinate system")
    cell%omtil=ABS(cell%omtil)
    
    cell%bmat=tpi_const*cell%bmat
    IF (cell%z1>0) THEN
       cell%vol = (cell%omtil/cell%amat(3,3))*cell%z1
       cell%area = cell%omtil/cell%amat(3,3)
    ELSE
       cell%vol = cell%omtil
       cell%area =ABS(cell%amat(1,1)*cell%amat(2,2)-cell%amat(1,2)*cell%amat(2,1))
       IF (cell%area < 1.0e-7) THEN
          cell%area = 1.
          CALL juDFT_warn("area = 0",calledby ="types_cell")
       END IF
     END IF

     cell%bbmat=matmul(cell%bmat,transpose(cell%bmat))
     cell%aamat=matmul(transpose(cell%amat),cell%amat)
   CONTAINS
     !This is a copy of the code in math/inv3
     !Put here to make library independent
     SUBROUTINE inv3(a,b,d)
       IMPLICIT NONE
       !     ..
       !     .. Arguments ..
       REAL, INTENT (IN)  :: a(3,3)
       REAL, INTENT (OUT) :: b(3,3)  ! inverse matrix
       REAL, INTENT (OUT) :: d       ! determinant
       !     ..
       d = a(1,1)*a(2,2)*a(3,3) + a(1,2)*a(2,3)*a(3,1) + &
            a(2,1)*a(3,2)*a(1,3) - a(1,3)*a(2,2)*a(3,1) - &
            a(2,3)*a(3,2)*a(1,1) - a(2,1)*a(1,2)*a(3,3)
       b(1,1) = (a(2,2)*a(3,3)-a(2,3)*a(3,2))/d
       b(1,2) = (a(1,3)*a(3,2)-a(1,2)*a(3,3))/d
       b(1,3) = (a(1,2)*a(2,3)-a(2,2)*a(1,3))/d
       b(2,1) = (a(2,3)*a(3,1)-a(2,1)*a(3,3))/d
       b(2,2) = (a(1,1)*a(3,3)-a(3,1)*a(1,3))/d
       b(2,3) = (a(1,3)*a(2,1)-a(1,1)*a(2,3))/d
       b(3,1) = (a(2,1)*a(3,2)-a(2,2)*a(3,1))/d
       b(3,2) = (a(1,2)*a(3,1)-a(1,1)*a(3,2))/d
       b(3,3) = (a(1,1)*a(2,2)-a(1,2)*a(2,1))/d
       
     END SUBROUTINE inv3

   END SUBROUTINE init

   SUBROUTINE  read_xml_cell(this,xml)
     use m_types_xml
     class(t_cell),intent(out)::this
     type(t_xml),intent(in)   ::xml
     
     ! Read in lattice parameters
     character(len=200)::valueString,path
     REAL:: scale,dvac,dtild
     
     if (xml%GetNumberOfNodes('')==1) then
        path= '/fleurInput/cell/filmLattice'
        this%z1=evaluateFirstOnly(xml%GetAttributeValue(trim(path)//'/@dvac'))/2
        dtild=evaluateFirstOnly(xml%GetAttributeValue(trim(path)//'/@dtilda'))
     else        
        path = '/fleurInput/cell/bulkLattice'
     endif
     
     scale=evaluateFirstOnly(xml%GetAttributeValue(trim(path)//'/@scale'))
     path=trim(path)//'/bravaisMatrix'
     valueString = TRIM(ADJUSTL(xml%GetAttributeValue(TRIM(ADJUSTL(path))//'/row-1')))
     this%amat(1,1) = evaluateFirst(valueString)
     this%amat(2,1) = evaluateFirst(valueString)
     this%amat(3,1) = evaluateFirst(valueString)
     valueString = TRIM(ADJUSTL(xml%GetAttributeValue(TRIM(ADJUSTL(path))//'/row-2')))
     this%amat(1,2) = evaluateFirst(valueString)
     this%amat(2,2) = evaluateFirst(valueString)
     this%amat(3,2) = evaluateFirst(valueString)
     valueString = TRIM(ADJUSTL(xml%GetAttributeValue(TRIM(ADJUSTL(path))//'/row-2')))
     this%amat(1,3) = evaluateFirst(valueString)
     this%amat(2,3) = evaluateFirst(valueString)
     this%amat(3,3) = evaluateFirst(valueString)
     
     IF (dvac>0) THEN
        this%amat(3,3)=2*this%z1
     ENDIF
     this%amat=this%amat*scale
     
   END SUBROUTINE read_xml_cell
   
 END MODULE m_types_cell