The Elk Code
mae.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2013 J. K. Dewhurst, S. Sharma and E. K. U. Gross.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine mae
7 use modmain
8 use modmpi
9 use moddelf
10 use modtest
11 implicit none
12 ! local variables
13 integer i,j,i0,i1
14 real(8) e0,e1,de
15 real(8) v1(3),v2(3),th
16 real(8) a(3,3),b(3,3)
17 ! initialise global variables
18 call init0
19 ! store original parameters
20 avec0(:,:)=avec(:,:)
23 bfieldc00(:)=bfieldc0(:)
26 vkloff0(:)=vkloff(:)
27 ! enable spin-orbit coupling
28 spinorb=.true.
29 ! no fixed spin moment calculation: the crystal is rotated instead
30 fsmtype=0
31 ! rotate the spherical cover used for the spherical harmonic transform
32 trotsht=.true.
33 ! if task = 28 then start from atomic densities; if task = 29 read STATE.OUT
34 trdstate=(task == 29)
35 ! zero k-point offset
36 vkloff(:)=0.d0
37 ! start with large magnetic field
38 bfieldc0(1:2)=0.d0
39 bfieldc0(3)=-1.d0
40 ! reduce the external magnetic field after each s.c. loop
41 reducebf=0.85d0
42 ! generate the spin moment directions in (theta,phi) coordinates
43 call gentpmae
44 ! open MAE_INFO.OUT
45 if (mp_mpi) then
46  open(71,file='MAE_INFO.OUT',form='FORMATTED')
47  write(71,*)
48  write(71,'("Scale factor of spin-orbit coupling term : ",G18.10)') socscf
49 end if
50 i0=1; i1=1
51 e0=1.d8; e1=-1.d8
52 ! loop over points on sphere
53 do i=1,npmae
54  if (mp_mpi) then
55  write(*,'("Info(mae): fixed spin moment direction ",I0," of ",I0)') i,npmae
56  end if
57 ! rotate lattice vectors instead of moment (thanks to J. Glasbrenner,
58 ! K. Bussmann and I. Mazin)
59 ! first by -phi around the z-axis
60  v1(:)=0.d0
61  v1(3)=1.d0
62  th=-tpmae(2,i)
63  call axangrot(v1,th,a)
64 ! then by -theta around the y-axis
65  v1(:)=0.d0
66  v1(2)=1.d0
67  th=-tpmae(1,i)
68  call axangrot(v1,th,b)
69  call r3mm(b,a,rotsht)
70  call r3mm(rotsht,avec0,avec)
71 ! find the corresponding moment direction vector
72  call r3minv(rotsht,a)
73  v1(:)=0.d0
74  v1(3)=1.d0
75  call r3mv(a,v1,v2)
76  do j=1,3
77  if (abs(v2(j)) < epslat) v2(j)=0.d0
78  end do
79 ! run the ground-state calculation
80  call gndstate
81 ! subsequent calculations should read the previous density
82  trdstate=.true.
83  if (mp_mpi) then
84  write(71,*)
85  write(71,'("Fixed spin moment direction point ",I0," of ",I0)') i,npmae
86  write(71,'("Spherical coordinates of direction : ",2G18.10)') tpmae(:,i)
87  write(71,'("Direction vector (Cartesian coordinates) : ",3G18.10)') v2
88  write(71,'("Calculated total moment magnitude : ",G18.10)') momtotm
89  write(71,'("Total energy : ",G24.14)') engytot
90  flush(71)
91  end if
92 ! check for minimum and maximum total energy
93  if (engytot < e0) then
94  e0=engytot
95  i0=i
96  end if
97  if (engytot > e1) then
98  e1=engytot
99  i1=i
100  end if
101 ! delete the eigenvector files
102  call delfiles(evec=.true.)
103 ! synchronise MPI processes
104  call mpi_barrier(mpicom,ierror)
105 end do
106 ! magnetic anisotropy energy
107 de=e1-e0
108 if (mp_mpi) then
109  write(71,*)
110  write(71,'("Minimum energy point : ",I6)') i0
111  write(71,'("Maximum energy point : ",I6)') i1
112  write(71,*)
113  write(71,'("Estimated magnetic anisotropy energy (MAE) : ",G18.10)') de
114  write(71,*)
115  write(71,'("MAE per unit volume : ",G18.10)') de/omega
116  close(71)
117  open(50,file='MAE.OUT',form='FORMATTED')
118  write(50,'(G18.10)') de
119  close(50)
120  open(50,file='MAEPUV.OUT',form='FORMATTED')
121  write(50,'(G18.10)') de/omega
122  close(50)
123  write(*,*)
124  write(*,'("Info(mae):")')
125  write(*,'(" Estimated magnetic anisotropy energy written to MAE.OUT")')
126  write(*,'(" MAE per unit volume written to MAEPUV.OUT")')
127  write(*,*)
128  write(*,'(" Number of fixed spin moment directions used : ",I0)') npmae
129  write(*,*)
130  write(*,'(" Additional information written to MAE_INFO.OUT")')
131 end if
132 ! write the MAE to test file
133 call writetest(28,'magnetic anisotropy energy',tol=1.d-5,rv=de)
134 ! restore original input parameters
135 avec(:,:)=avec0(:,:)
139 trotsht=.false.
140 bfieldc0(:)=bfieldc00(:)
142 vkloff(:)=vkloff0(:)
143 end subroutine
144 
real(8) socscf
Definition: modmain.f90:234
real(8), dimension(:,:), allocatable tpmae
Definition: modmain.f90:306
subroutine writetest(id, descr, nv, iv, iva, tol, rv, rva, zv, zva)
Definition: modtest.f90:16
subroutine gndstate
Definition: gndstate.f90:10
integer task
Definition: modmain.f90:1299
logical mp_mpi
Definition: modmpi.f90:17
integer fsmtype0
Definition: modmain.f90:253
logical spinpol
Definition: modmain.f90:230
real(8) reducebf
Definition: modmain.f90:281
real(8) momtotm
Definition: modmain.f90:743
real(8) omega
Definition: modmain.f90:20
subroutine r3minv(a, b)
Definition: r3minv.f90:10
real(8), dimension(3) vkloff0
Definition: modmain.f90:453
real(8), dimension(3) vkloff
Definition: modmain.f90:453
subroutine gentpmae
Definition: gentpmae.f90:7
real(8) reducebf0
Definition: modmain.f90:281
real(8), dimension(3, 3) rotsht
Definition: modmain.f90:566
real(8) engytot
Definition: modmain.f90:985
pure subroutine axangrot(v, th, rot)
Definition: axangrot.f90:10
real(8), dimension(3, 3) avec
Definition: modmain.f90:12
logical spinorb0
Definition: modmain.f90:232
logical spinpol0
Definition: modmain.f90:230
real(8), dimension(3, 3) avec0
Definition: modmain.f90:12
subroutine mae
Definition: mae.f90:7
subroutine delfiles(evec, devec, eval, occ, pmat, epsi)
Definition: moddelf.f90:25
real(8) epslat
Definition: modmain.f90:24
Definition: modmpi.f90:6
logical trotsht
Definition: modmain.f90:564
logical spinorb
Definition: modmain.f90:232
real(8), dimension(3) bfieldc0
Definition: modmain.f90:273
real(8), dimension(3) bfieldc00
Definition: modmain.f90:273
logical trdstate
Definition: modmain.f90:685
subroutine init0
Definition: init0.f90:10
pure subroutine r3mv(a, x, y)
Definition: r3mv.f90:10
pure subroutine r3mm(a, b, c)
Definition: r3mm.f90:10
integer mpicom
Definition: modmpi.f90:11
integer fsmtype
Definition: modmain.f90:253
integer npmae
Definition: modmain.f90:304
integer ierror
Definition: modmpi.f90:19