atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
cqvf.F90
Go to the documentation of this file.
1! This file is part of the 'atomes' software.
2!
3! 'atomes' is free software: you can redistribute it and/or modify it under the terms
4! of the GNU Affero General Public License as published by the Free Software Foundation,
5! either version 3 of the License, or (at your option) any later version.
6!
7! 'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8! without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9! See the GNU General Public License for more details.
10!
11! You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12! If not, see <https://www.gnu.org/licenses/>
13!
14! Copyright (C) 2022-2024 by CNRS and University of Strasbourg
15!
20
21INTEGER (KIND=c_int) FUNCTION cqvf (QMAX, QMIN, NQ, PROBA, LIMQ) bind (C,NAME='cqvf_')
22
23!
24! Determines the q-vectors for which the q-dependent
25! correlation functions are computed - general cell
26!
27
28 USE parameters
29
30 IMPLICIT NONE
31
32 INTEGER (KIND=c_int), INTENT(IN) :: nq
33 REAL (kind=c_double), INTENT(IN) :: proba, limq
34 REAL (kind=c_double), INTENT(IN) :: qmax, qmin
35
36 LOGICAL :: kpts, keepkpts
37 INTEGER :: hkl, q_index, seed
38 INTEGER :: klow, llow
39 INTEGER, DIMENSION(3) :: nkpts
40 DOUBLE PRECISION, DIMENSION(3) :: qmrecip
41 DOUBLE PRECISION :: qmax2, qmin2, limq2
42 DOUBLE PRECISION :: kpx, kpy, kpz, keep
43
44 INTERFACE
45 DOUBLE PRECISION FUNCTION ran3 (idnum)
46 INTEGER, INTENT(IN) :: idnum
47 END FUNCTION
48 END INTERFACE
49
50 qmrecip(:) = 0.0d0
51 do i=1, ncells
52 do j=1, 3
53 qmrecip(j) = qmrecip(j)+the_box(i)%modr(j)
54 enddo
55 enddo
56 qmrecip(:) = qmrecip(:)/ncells
57 do i=1, 3
58 nkpts(i) = anint(qmax/qmrecip(i))+1
59 enddo
60 hkl=0
61! To simply the case of the calculation in the case of a simple cubic box
62 if (overall_cubic) then
63 qmax2=(qmax/qmin)**2
64 qmin2=1.0d0
65 limq2=(limq/qmin)**2
66 else
67 qmax2=qmax**2 ! mod(q_max)**2
68 limq2=limq**2
69 qmin2=qmin**2 ! min module of the reciprocal lattice vectors - lattice.f90
70 endif
71 q_index=0
72 qvmax=0.0d0
73 qvmin=50.0d0
74
75do i=1, 2
76
77! The firt iteration to evaluate the number of k-points
78! to be saved for the analysis, and the second to store them.
79
80 if (i .eq. 2) then
81
82 number_of_qmod=q_index
83 if (allocated(qvectx)) deallocate(qvectx)
84 allocate(qvectx(number_of_qmod), stat=err)
85 if (err .ne. 0) then
86 call show_error ("Impossible to allocate memory"//char(0), &
87 "Function: COMP_Q_VAL_FULL"//char(0), "Table: qvectx"//char(0))
88 cqvf=0
89 goto 001
90 endif
91 if (allocated(qvecty)) deallocate(qvecty)
92 allocate(qvecty(number_of_qmod), stat=err)
93 if (err .ne. 0) then
94 call show_error ("Impossible to allocate memory"//char(0), &
95 "Function: COMP_Q_VAL_FULL"//char(0), "Table: qvecty"//char(0))
96 cqvf=0
97 goto 001
98 endif
99 if (allocated(qvectz)) deallocate(qvectz)
100 allocate(qvectz(number_of_qmod), stat=err)
101 if (err .ne. 0) then
102 call show_error ("Impossible to allocate memory"//char(0), &
103 "Function: COMP_Q_VAL_FULL"//char(0), "Table: qvectz"//char(0))
104 cqvf=0
105 goto 001
106 endif
107 if (allocated(modq)) deallocate(modq)
108 allocate(modq(number_of_qmod), stat=err)
109 if (err .ne. 0) then
110 call show_error ("Impossible to allocate memory"//char(0), &
111 "Function: COMP_Q_VAL_FULL"//char(0), "Table: modq"//char(0))
112 cqvf=0
113 goto 001
114 endif
115 q_index=0
116
117 endif
118
119 do h=0, nkpts(1)
120
121 if (h .eq. 0) then
122 klow=0
123 else
124 klow=-nkpts(2)
125 endif
126
127 do k=klow, nkpts(2)
128
129 if (k.eq.0 .and. h.eq.0) then
130 llow=0
131 else
132 llow=-nkpts(3)
133 endif
134
135 do l=llow, nkpts(3)
136
137 if (overall_cubic) then
138 kpx= h
139 kpy= k
140 kpz= l
141 else
142 kpx= 2.0d0*pi*(h*the_box(1)%lrecp(1,1) + k*the_box(1)%lrecp(2,1) + l*the_box(1)%lrecp(3,1))
143 kpy= 2.0d0*pi*(h*the_box(1)%lrecp(1,2) + k*the_box(1)%lrecp(2,2) + l*the_box(1)%lrecp(3,2))
144 kpz= 2.0d0*pi*(h*the_box(1)%lrecp(1,3) + k*the_box(1)%lrecp(2,3) + l*the_box(1)%lrecp(3,3))
145 endif
146 qvmod= kpx**2 + kpy**2 + kpz**2
147
148! we want the maximum number of k-points in the FSDP part of the spectra
149! therefore we choose to keep all qvectors with qmod in:
150! minr < qmod < limq
151! where 'minr' is minimum q modulus accessible considering the analysed
152! lattice ie. the minimum modulus of the reciprocal cell vectors,
153! limq is the limit to be fixed for the FSDP part of the spectra
154! Thereafter: QMIN=minr**2 and LIMQ2=limq**2.
155! The qvectors with a qmod > limq are accepted with a probability of PROBA
156
157 if (qvmod .le. qmax2 .and. qvmod .ge. qmin2) then
158 kpts=.true.
159 else
160 kpts=.false.
161 endif
162 if (i .eq. 1 .and. kpts) then
163 q_index=q_index+2
164 elseif (i .eq. 2 .and. kpts) then
165 if (qvmod .le. limq2) then
166 keepkpts=.true.
167 else
168 seed=173932
169 keep = ran3(seed+h**3+k**2+l**5)
170 if (keep .le. proba) then
171 keepkpts=.true.
172 else
173 keepkpts=.false.
174 endif
175 endif
176 if (keepkpts) then
177 q_index=q_index+1
178 qvectx(q_index)=kpx
179 qvecty(q_index)=kpy
180 qvectz(q_index)=kpz
181 modq(q_index)=sqrt(qvmod)
182 qvmax=max(qvmax,modq(q_index))
183 qvmin=min(qvmin,modq(q_index))
184 if (h.ne.0 .or. k.ne.0 .or. l.ne.0) then
185 q_index=q_index+1
186 qvectx(q_index)=-kpx
187 qvecty(q_index)=-kpy
188 qvectz(q_index)=-kpz
189 modq(q_index)=sqrt(qvmod)
190 endif
191 endif
192 endif
193
194 enddo ! l
195
196 enddo ! k
197
198 enddo ! h
199
200enddo
201
202number_of_qvect=q_index
203
204! NQ is given in input
205! the value of each Q_POINT is find in the
206! interval |qvmax - qvmin| and then we compute
207! the degeneracy of each Q_POINT in q modulus.
208
209if (allocated(degeneracy)) deallocate(degeneracy)
210allocate(degeneracy(nq+1), stat=err)
211if (err .ne. 0) then
212 call show_error ("Impossible to allocate memory"//char(0), &
213 "Function: COMP_Q_VAL_FULL"//char(0), "Table: degeneracy"//char(0))
214 cqvf=0
215 goto 001
216endif
217degeneracy(:)=0
218
219! We do not sort the Q vectors by modulus,
220! to save CPU time we discretize the distribution
221! of the modulus, this approximation is perfect
222! if the variable NQ given by the user
223! in the input file is big enough (>= 1000).
224
226
227do i=1, number_of_qvect
228 hkl=anint((modq(i)-qvmin)/delta_q)+1
229 degeneracy(hkl)=degeneracy(hkl)+1
230enddo
231
232if (allocated(k_point)) deallocate(k_point)
233allocate(k_point(nq), stat=err)
234if (err .ne. 0) then
235 call show_error ("Impossible to allocate memory"//char(0), &
236 "Function: COMP_Q_VAL_FULL"//char(0), "Table: K_POINT"//char(0))
237 cqvf=0
238 goto 001
239endif
240
241do i=1, nq
242! The next line to avoid NAN error when computing the normalisation factor of the S(q)
243 if (degeneracy(i) .eq. 0) degeneracy(i)=1
244 k_point(i)=(i-1.0)*delta_q+qvmin
245enddo
246
247if (overall_cubic) then
248 do i=1, number_of_qvect
249 qvectx(i)=qvectx(i)*qmin
250 qvecty(i)=qvecty(i)*qmin
251 qvectz(i)=qvectz(i)*qmin
252 enddo
253 do i=1, nq
254 k_point(i)=k_point(i)*qmin
255 enddo
256endif
257
258cqvf=1
259
260001 continue
261
262END FUNCTION
integer(kind=c_int) function cqvf(qmax, qmin, nq, proba, limq)
Definition cqvf.F90:22
#define min(a, b)
Definition global.h:81
#define max(a, b)
Definition global.h:80
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
double precision qvmin
integer ncells
double precision qvmod
double precision, dimension(:), allocatable qvectx
integer number_of_qmod
integer number_of_qvect
double precision, dimension(:), allocatable qvecty
double precision delta_q
double precision, dimension(:), allocatable k_point
integer, dimension(:), allocatable degeneracy
integer err
double precision, dimension(:), allocatable modq
type(lattice), dimension(:), allocatable, target the_box
double precision, dimension(:), allocatable qvectz
logical overall_cubic
double precision qvmax
double precision, parameter pi
double precision function ran3(idnum)
Definition utils.F90:421