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(:,:)
24 bfieldc00(:)=bfieldc0(:)
27 vkloff0(:)=vkloff(:)
28 ! enable spin-orbit coupling
29 spinorb=.true.
30 ! enforce collinear magnetism in the z-direction
31 cmagz=.true.
32 ! no fixed spin moment calculation: the crystal is rotated instead
33 fsmtype=0
34 ! rotate the spherical cover used for the spherical harmonic transform
35 trotsht=.true.
36 ! if task=28 then start from atomic densities; if task=29 read STATE.OUT
37 trdstate=(task == 29)
38 ! zero k-point offset
39 vkloff(:)=0.d0
40 ! start with large magnetic field
41 bfieldc0(1:2)=0.d0
42 bfieldc0(3)=-1.d0
43 ! reduce the external magnetic field after each s.c. loop
44 reducebf=0.85d0
45 ! generate the spin moment directions in (theta,phi) coordinates
46 call gentpmae
47 ! open MAE_INFO.OUT
48 if (mp_mpi) then
49  open(71,file='MAE_INFO.OUT',form='FORMATTED')
50  write(71,*)
51  write(71,'("Scale factor of spin-orbit coupling term : ",G18.10)') socscf
52 end if
53 i0=1; i1=1
54 e0=1.d8; e1=-1.d8
55 ! loop over points on sphere
56 do i=1,npmae
57  if (mp_mpi) then
58  write(*,'("Info(mae): fixed spin moment direction ",I0," of ",I0)') i,npmae
59  end if
60 ! rotate lattice vectors instead of moment (thanks to J. Glasbrenner,
61 ! K. Bussmann and I. Mazin)
62 ! first by -phi around the z-axis
63  v1(:)=0.d0
64  v1(3)=1.d0
65  th=-tpmae(2,i)
66  call axangrot(v1,th,a)
67 ! then by -theta around the y-axis
68  v1(:)=0.d0
69  v1(2)=1.d0
70  th=-tpmae(1,i)
71  call axangrot(v1,th,b)
72  call r3mm(b,a,rotsht)
73  call r3mm(rotsht,avec0,avec)
74 ! find the corresponding moment direction vector
75  call r3minv(rotsht,a)
76  v1(:)=0.d0
77  v1(3)=1.d0
78  call r3mv(a,v1,v2)
79  do j=1,3
80  if (abs(v2(j)) < epslat) v2(j)=0.d0
81  end do
82 ! run the ground-state calculation
83  call gndstate
84 ! subsequent calculations should read the previous density
85  trdstate=.true.
86  if (mp_mpi) then
87  write(71,*)
88  write(71,'("Fixed spin moment direction point ",I0," of ",I0)') i,npmae
89  write(71,'("Spherical coordinates of direction : ",2G18.10)') tpmae(:,i)
90  write(71,'("Direction vector (Cartesian coordinates) : ",3G18.10)') v2
91  write(71,'("Calculated total moment magnitude : ",G18.10)') momtotm
92  write(71,'("Total energy : ",G24.14)') engytot
93  flush(71)
94  end if
95 ! check for minimum and maximum total energy
96  if (engytot < e0) then
97  e0=engytot
98  i0=i
99  end if
100  if (engytot > e1) then
101  e1=engytot
102  i1=i
103  end if
104 ! delete the eigenvector files
105  call delfiles(evec=.true.)
106 ! synchronise MPI processes
107  call mpi_barrier(mpicom,ierror)
108 end do
109 ! magnetic anisotropy energy
110 de=e1-e0
111 if (mp_mpi) then
112  write(71,*)
113  write(71,'("Minimum energy point : ",I6)') i0
114  write(71,'("Maximum energy point : ",I6)') i1
115  write(71,*)
116  write(71,'("Estimated magnetic anisotropy energy (MAE) : ",G18.10)') de
117  write(71,*)
118  write(71,'("MAE per unit volume : ",G18.10)') de/omega
119  close(71)
120  open(50,file='MAE.OUT',form='FORMATTED')
121  write(50,'(G18.10)') de
122  close(50)
123  open(50,file='MAEPUV.OUT',form='FORMATTED')
124  write(50,'(G18.10)') de/omega
125  close(50)
126  write(*,*)
127  write(*,'("Info(mae):")')
128  write(*,'(" Estimated magnetic anisotropy energy written to MAE.OUT")')
129  write(*,'(" MAE per unit volume written to MAEPUV.OUT")')
130  write(*,*)
131  write(*,'(" Number of fixed spin moment directions used : ",I0)') npmae
132  write(*,*)
133  write(*,'(" Additional information written to MAE_INFO.OUT")')
134 end if
135 ! write the MAE to test file
136 call writetest(28,'magnetic anisotropy energy',tol=1.d-5,rv=de)
137 ! restore original input parameters
138 avec(:,:)=avec0(:,:)
143 trotsht=.false.
144 bfieldc0(:)=bfieldc00(:)
146 vkloff(:)=vkloff0(:)
147 end subroutine
148 
real(8) socscf
Definition: modmain.f90:232
real(8), dimension(:,:), allocatable tpmae
Definition: modmain.f90:304
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:1293
logical mp_mpi
Definition: modmpi.f90:17
integer fsmtype0
Definition: modmain.f90:251
logical spinpol
Definition: modmain.f90:228
real(8) reducebf
Definition: modmain.f90:279
real(8) momtotm
Definition: modmain.f90:740
real(8) omega
Definition: modmain.f90:20
subroutine r3minv(a, b)
Definition: r3minv.f90:10
real(8), dimension(3) vkloff0
Definition: modmain.f90:450
real(8), dimension(3) vkloff
Definition: modmain.f90:450
subroutine gentpmae
Definition: gentpmae.f90:7
real(8) reducebf0
Definition: modmain.f90:279
real(8), dimension(3, 3) rotsht
Definition: modmain.f90:563
real(8) engytot
Definition: modmain.f90:977
pure subroutine axangrot(v, th, rot)
Definition: axangrot.f90:10
real(8), dimension(3, 3) avec
Definition: modmain.f90:12
logical cmagz
Definition: modmain.f90:242
logical spinorb0
Definition: modmain.f90:230
logical spinpol0
Definition: modmain.f90:228
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:561
logical cmagz0
Definition: modmain.f90:242
logical spinorb
Definition: modmain.f90:230
real(8), dimension(3) bfieldc0
Definition: modmain.f90:271
real(8), dimension(3) bfieldc00
Definition: modmain.f90:271
logical trdstate
Definition: modmain.f90:682
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:251
integer npmae
Definition: modmain.f90:302
integer ierror
Definition: modmpi.f90:19