atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
sq.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 s_of_q (QMAX, QMIN, NQ) bind (C,NAME='s_of_q_')
22
23! Total structure factor
24! Partials structure factors
25
26! Total structure factor:
27
28!
29! 00 sin (q*r)
30! S(q)= 1 + 4*PI*rho* / dr r² ------------ (g(r) - 1)
31! 0 (q*r)
32!
33
34! or:
35
36! 1 Rmax sin (q*r) sin (PI*r/Rmax)
37! S(q)= 1 + 4*PI*rho* / dr r² (g(r) -1) ----------- * ---------------
38! 0 (q*r) PI*r/Rmax
39!
40
41! Partials structure factors:
42
43!
44! Rmax
45! S (q)= delta(a,b) + sqrt(x * x ) *4*PI*rho* / dr r² (g (r) - 1)
46! ab a b 0 ab
47!
48!
49
50! or:
51
52! Rmax sin (q*r) sin (PI*r/Rmax)
53! S (q)= delta(a,b) + sqrt(x * x ) *4*PI*rho* / dr r² (g (r) - go ) ----------- * ---------------
54! ab a b 0 ab ab (q*r) PI*r/Rmax
55!
56
57! with x = Nbre(a)/Nbre(tot)
58! a
59
60
61USE parameters
62
63IMPLICIT NONE
64
65INTEGER (KIND=c_int), INTENT(IN) :: nq
66real(kind=c_double), INTENT(IN) :: qmax , qmin
67DOUBLE PRECISION :: dq
68DOUBLE PRECISION, DIMENSION (:), ALLOCATABLE :: sqtab
69
70INTERFACE
71 INTEGER FUNCTION recup_data (i, j)
72 INTEGER, INTENT(IN) :: i, j
73 END FUNCTION
74 LOGICAL FUNCTION fzbt (NDQ)
75 INTEGER, INTENT(IN) :: ndq
76 END FUNCTION
77END INTERFACE
78
81
82if (allocated(q_point)) deallocate(q_point)
83allocate(q_point(nq), stat=err)
84if (err .ne. 0) then
85 call show_error ("Impossible to allocate memory"//char(0), &
86 "Function: s_of_q"//char(0), "Table: Q_POINT"//char(0))
87 s_of_q = 0
88 goto 001
89endif
90if (allocated(s)) deallocate(s)
91allocate(s(nq), stat=err)
92if (err .ne. 0) then
93 call show_error ("Impossible to allocate memory"//char(0), &
94 "Function: s_of_q"//char(0), "Table: S"//char(0))
95 s_of_q = 0
96 goto 001
97endif
98if (allocated(xs)) deallocate(xs)
99allocate(xs(nq), stat=err)
100if (err .ne. 0) then
101 call show_error ("Impossible to allocate memory"//char(0), &
102 "Function: s_of_q"//char(0), "Table: XS"//char(0))
103 s_of_q = 0
104 goto 001
105endif
106if (allocated(sij)) deallocate(sij)
107allocate(sij(nq,nsp,nsp), stat=err)
108if (err .ne. 0) then
109 call show_error ("Impossible to allocate memory"//char(0), &
110 "Function: s_of_q"//char(0), "Table: Sij"//char(0))
111 s_of_q = 0
112 goto 001
113endif
114
115! 'QMIN' is minimum q modulus accessible considering the analysed
116! lattice ie. the minimum modulus of the reciprocal cell vectors,
117dq=((qmax-qmin)/dble(nq))
118
119s(:)=0.0d0
120xs(:)=0.0d0
121q_point(:)=0.0d0
122do i=1, nq
123 q_point(i)= dble(i-1)*dq+qmin
124enddo
125
126sij(:,:,:)=0.0d0
127
128j=0
129if (recup_data(j, idgr) .ne. 1) then
130 s_of_q = 0
131 goto 001
132endif
133
134j=j+8
135if (recup_data(j, idgr) .ne. 1) then
136 s_of_q = 0
137 goto 001
138endif
139
140j=j+8
141do o=1, nsp
142do p=1, nsp
143 if (recup_data(j, idgr) .ne. 1) then
144 s_of_q = 0
145 goto 001
146 endif
147 j=j+5
148enddo
149enddo
150
151if (.not. fzbt(nq)) then
152 s_of_q = 0
153 goto 001
154endif
155
156if (allocated(sqtab)) deallocate(sqtab)
157allocate(sqtab(nq), stat=err)
158if (err .ne. 0) then
159 call show_error ("Impossible to allocate memory"//char(0), &
160 "Function: s_of_q"//char(0), "Table: SQTAB"//char(0))
161 s_of_q = 0
162 goto 001
163endif
164
165l=0
166do k=1, nq
167 sqtab(k)= s(k)
168enddo
169call save_curve (nq, sqtab, l, idsq)
170l=l+2
171
172do k=1, nq
173 sqtab(k)= (s(k)-1.0)*q_point(k)
174enddo
175call save_curve (nq, sqtab, l, idsq)
176l=l+2
177
178do k=1, nq
179 sqtab(k)= xs(k)
180enddo
181call save_curve (nq, sqtab, l, idsq)
182l=l+2
183
184do k=1, nq
185 sqtab(k)= (xs(k)-1.0)*q_point(k)
186enddo
187call save_curve (nq, sqtab, l, idsq)
188l=l+2
189
190do i=1, nsp
191do j=1, nsp
192 do k=1, nq
193 sqtab(k)= sij(k,i,j)
194 enddo
195 call save_curve (nq, sqtab, l, idsq)
196 l=l+2
197enddo
198enddo
199do i=1, nsp
200do j=1, nsp
201 do k=1, nq
202 sqtab(k)= fzsij(k,i,j)
203 enddo
204 call save_curve (nq, sqtab, l, idsq)
205 l=l+2
206enddo
207enddo
208if (nsp .eq. 2) then
209 do i=1, 4
210 do j=1, nq
211 sqtab(j)= btij(j,i)
212 enddo
213 call save_curve (nq, sqtab, l, idsq)
214 l=l+2
215 enddo
216endif
217
218s_of_q = 1
219
220001 continue
221
222if (allocated(sqtab)) deallocate(sqtab)
223if (allocated(q_point)) deallocate(q_point)
224if (allocated(sij)) deallocate(sij)
225if (allocated(s)) deallocate(s)
226if (allocated(xs)) deallocate(xs)
227if (allocated(fzsij)) deallocate(fzsij)
228if (allocated(btij)) deallocate(btij)
229
230END FUNCTION
231
232INTEGER (KIND=c_int) FUNCTION send_gr (IC, VAL, DR, RDATA, GDATA) bind (C,NAME='send_gr_')
233
234USE parameters
235
236INTEGER (KIND=c_int), INTENT(IN) :: ic, val
237real(kind=c_double), INTENT(IN) :: dr
238real(kind=c_double), DIMENSION(VAL), INTENT(IN) :: rdata, gdata
239DOUBLE PRECISION :: hcap1, hcap2, vcap
240INTEGER :: rinit
241
242if (allocated(shell_vol)) deallocate(shell_vol)
243allocate(shell_vol(val+1), stat=err)
244if (err .ne. 0) then
245 call show_error ("Impossible to allocate memory"//char(0), &
246 "Function: send_gr"//char(0), "Table: SHELL_VOL"//char(0))
247 send_gr = 0
248 goto 001
249endif
250
251do i=1, val
252 shell_vol(i) = 0.0d0
253 shell_vol(i) = 4.0d0*pi*((rdata(i)+dr)**3 - (rdata(i)**3))/3
254! To take into account the atoms between a/2 and a srqt(3)/2
255! We need the small volume they can be found in.
256 if (overall_cubic .and. rdata(i)+dr.gt.mbox) then
257 hcap1=rdata(i)+dr-mbox
258 if (rdata(i) .le. mbox) then
259 hcap2=0.0d0
260 else
261 hcap2=rdata(i)-mbox
262 endif
263 vcap=hcap1**2*(3*rdata(i) - hcap1) - hcap2**2*(3*rdata(i) - hcap2)
264 vcap=vcap*pi*2
265 shell_vol(i)=shell_vol(i)-vcap
266 endif
267enddo
268
269j=ic
270if (j > 8) then
271 m=j-16
272 m=m/5
273 k=m/nsp+1
274 l=m-(k-1)*nsp+1
275endif
276
277rinit = 1
278if (rdata(1) .eq. 0.0) rinit = 2
279
280rmax = rdata(val)
281do i=1, number_of_qmod
282 do n=rinit, val
283 phi = q_point(i)*rdata(n)
284 fact_rmax = pi*rdata(n)/rmax
285! Sinus_Fact_Rmax = sin(Fact_Rmax)/Fact_Rmax
286 sinus_phi = sin(phi)/phi
287 if (j .eq. 0) then
288 s(i) = s(i) + shell_vol(n)*(gdata(n) - 1)*sinus_phi!*Sinus_Fact_Rmax
289 else if (j .eq. 8) then
290 xs(i) = xs(i) + shell_vol(n)*(gdata(n) - 1)*sinus_phi
291 else
292 sij(i,k,l) = sij(i,k,l) + shell_vol(n)*(gdata(n) - 1)*sinus_phi!*Sinus_Fact_Rmax
293 endif
294 enddo
295 if (j .eq. 0) then
296 s(i) = 1.0d0 + s(i)*total_density
297 else if (j .eq. 8) then
298 xs(i) = 1.0d0 + xs(i)*total_density
299 else
300 if (l .eq. k) then
301 sij(i,k,l) = 1.0d0 + xi(l)*sij(i,k,l)*total_density
302 else
303 sij(i,k,l) = sqrt(xi(k)*xi(l))*sij(i,k,l)*total_density
304 endif
305 endif
306enddo
307
308send_gr = 1
309
310001 continue
311
312if (allocated(shell_vol)) deallocate(shell_vol)
313
314END FUNCTION
logical function fzbt(ndq)
Definition fzbt.F90:22
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
double precision total_density
double precision rmax
double precision fact_rmax
double precision, dimension(:,:,:), allocatable fzsij
integer number_of_qmod
double precision, dimension(:), allocatable q_point
double precision, dimension(:), allocatable xi
double precision phi
double precision, dimension(:), allocatable s
double precision, dimension(:,:), allocatable btij
double precision, dimension(:), allocatable xs
integer err
integer idsq
double precision, dimension(:), allocatable shell_vol
double precision meanvol
double precision mbox
logical overall_cubic
integer idgr
double precision sinus_phi
integer nsp
double precision, dimension(:,:,:), allocatable sij
double precision, parameter pi
integer(kind=c_int) function s_of_q(qmax, qmin, nq)
Definition sq.F90:22
integer(kind=c_int) function send_gr(ic, val, dr, rdata, gdata)
Definition sq.F90:233