Line data Source code
1 : !!****m* ABINIT/m_abi2big
2 : !! NAME
3 : !! m_abi2big
4 : !!
5 : !! FUNCTION
6 : !! Module to copy objects from ABINIT to BigDFT and viceversa.
7 : !!
8 : !! COPYRIGHT
9 : !! Copyright (C) 2012-2026 ABINIT group (TR,DC,MT)
10 : !! This file is distributed under the terms of the
11 : !! GNU General Public License, see ~abinit/COPYING
12 : !! or http://www.gnu.org/copyleft/gpl.txt .
13 : !!
14 : !! SOURCE
15 :
16 : #if defined HAVE_CONFIG_H
17 : #include "config.h"
18 : #endif
19 :
20 : #include "abi_common.h"
21 :
22 : module m_abi2big
23 :
24 : use defs_basis
25 : use defs_wvltypes
26 : use m_errors
27 : use m_xmpi
28 :
29 : use m_geometry, only : mkrdim, xcart2xred, xred2xcart
30 :
31 : implicit none
32 :
33 : private
34 :
35 : public :: wvl_vtrial_abi2big
36 : !to copy vtrial to wvl_den%rhov and viceversa.
37 :
38 : public :: wvl_rho_abi2big
39 : !to copy a density from ABINIT to BigDFT or viceversa
40 :
41 : public :: wvl_vhartr_abi2big
42 : ! to copy V_hartree from ABINIT to BigDFT and viceversa
43 :
44 : public :: wvl_vxc_abi2big
45 : ! to copy Vxc from ABINIT to BigDFT and viceversa
46 :
47 : public :: wvl_occ_abi2big
48 : ! to copy occupations from/to ABINIT to/from BigDFT
49 :
50 : public :: wvl_eigen_abi2big
51 : ! to copy eigenvalues from/to ABINIT to/from BigDFT
52 :
53 : public :: wvl_occopt_abi2big
54 : ! maps occupation method in ABINIT and BigDFT
55 :
56 : public :: wvl_rhov_abi2big
57 : !generic routine to copy a density or potential from/to
58 : !ABINIT to/from BigDFT.
59 : interface wvl_rhov_abi2big
60 : module procedure wvl_rhov_abi2big_2D_4D
61 : module procedure wvl_rhov_abi2big_1D_4D
62 : module procedure wvl_rhov_abi2big_2D_2D
63 : module procedure wvl_rhov_abi2big_1D_2D
64 : module procedure wvl_rhov_abi2big_2D_1D
65 : module procedure wvl_rhov_abi2big_1D_1D
66 : end interface wvl_rhov_abi2big
67 :
68 : logical,parameter :: hmem=.false. !high memory
69 : !! Set hmem=.false. if memory is limited. It will copy element by element.
70 : !! If hmem=.true. all elements are copied at once.
71 :
72 : public :: wvl_setngfft
73 :
74 : public :: wvl_setBoxGeometry
75 :
76 : contains
77 : !!***
78 :
79 : !!****f* m_abi2big/wvl_vtrial_abi2big
80 : !! NAME
81 : !! wvl_vtrial_abi2big
82 : !!
83 : !! FUNCTION
84 : !! Copies vtrial in ABINIT to BigDFT objects and viceversa.
85 : !!
86 : !! INPUTS
87 : !! opt= 1) copy from ABINIT to BigDFT
88 : !! 2) copy from BigDFT to ABINIT
89 : !! vtrial(nfft,nspden)= trial potential (ABINIT array)
90 : !! wvl_den= density-potential BigDFT object
91 : !!
92 : !! OUTPUT
93 : !!
94 : !! SIDE EFFECTS
95 : !! vtrial is copied to wvl_den, or viceversa, depending on "opt" (see above).
96 : !! It verifies that (or sets) wvl_den%rhov_is = KS_POTENTIAL.
97 : !!
98 : !! NOTES
99 : !! It uses the generic routine wvl_rhov_abi2big.
100 : !!
101 : !! SOURCE
102 :
103 0 : subroutine wvl_vtrial_abi2big(opt,vtrial,wvl_den)
104 :
105 : #if defined HAVE_BIGDFT
106 : use BigDFT_API, only : KS_POTENTIAL
107 : #endif
108 :
109 : !Arguments ------------------------------------
110 : integer,intent(in) :: opt
111 : real(dp),intent(inout) :: vtrial(:,:)
112 : type(wvl_denspot_type),intent(inout) :: wvl_den
113 :
114 : !Local variables-------------------------------
115 : #if defined HAVE_BIGDFT
116 : integer :: shiftV
117 : character(len=100) :: message
118 : #endif
119 :
120 : ! *************************************************************************
121 :
122 : DBG_ENTER("COLL")
123 :
124 : #if defined HAVE_BIGDFT
125 : ! write(message,'(2a)') ch10,' wvl_vtrial_abi2big: but why are you copying me :..o('
126 : ! call wrtout(std_out,message,'COLL')
127 :
128 : shiftV=wvl_den%denspot%dpbox%ndims(1)*wvl_den%denspot%dpbox%ndims(2) &
129 : & *wvl_den%denspot%dpbox%i3xcsh
130 :
131 : if(opt==1) then !ABINIT -> BIGDFT
132 :
133 : call wvl_rhov_abi2big(opt,vtrial,wvl_den%denspot%rhov,shift=shiftV)
134 : wvl_den%denspot%rhov_is = KS_POTENTIAL
135 :
136 : elseif(opt==2) then !BigDFT -> ABINIT
137 :
138 : if(wvl_den%denspot%rhov_is .ne. KS_POTENTIAL) then
139 : message='wvl_vtrial_abi2big: rhov should contain the KS_POTENTIAL'
140 : ABI_BUG(message)
141 : end if
142 :
143 : call wvl_rhov_abi2big(opt,vtrial,wvl_den%denspot%rhov,shift=shiftV)
144 :
145 : else
146 : message='wvl_vtrial_abi2big: wrong option'
147 : ABI_BUG(message)
148 : end if
149 :
150 : #else
151 0 : BIGDFT_NOTENABLED_ERROR()
152 : if (.false.) write(std_out,*) opt,vtrial(1,1),wvl_den%symObj
153 : #endif
154 :
155 : DBG_EXIT("COLL")
156 :
157 0 : end subroutine wvl_vtrial_abi2big
158 : !!***
159 :
160 : !!****f* m_abi2big/wvl_rho_abi2big
161 : !! NAME
162 : !! wvl_rho_abi2big
163 : !!
164 : !! FUNCTION
165 : !! Copies the density from ABINIT to BigDFT, or viceversa.
166 : !!
167 : !! INPUTS
168 : !! opt= 1) copy from ABINIT to BigDFT
169 : !! 2) copy from BigDFT to ABINIT
170 : !! rhor(nfft,nspden)= trial potential (ABINIT array)
171 : !! wvl_den= density-potential BigDFT object
172 : !!
173 : !! OUTPUT
174 : !!
175 : !! SIDE EFFECTS
176 : !! Density copied from ABINIT to BigDFT or viceversa.
177 : !! It verifies that (or sets) wvl_den%rhov_is= ELECTRONIC_DENSITY.
178 : !!
179 : !! NOTES
180 : !! It uses the generic routine wvl_rhov_abi2big.
181 : !!
182 : !! SOURCE
183 :
184 0 : subroutine wvl_rho_abi2big(opt,rhor,wvl_den)
185 :
186 : #if defined HAVE_BIGDFT
187 : use BigDFT_API, only : ELECTRONIC_DENSITY
188 : #endif
189 :
190 : !Arguments ------------------------------------
191 : integer , intent(in) :: opt
192 : real(dp) , intent(inout) :: rhor(:,:)
193 : type(wvl_denspot_type), intent(inout) :: wvl_den
194 :
195 : !Local variables-------------------------------
196 : #if defined HAVE_BIGDFT
197 : character(len=100) :: message
198 : #endif
199 :
200 : ! *************************************************************************
201 :
202 : DBG_ENTER("COLL")
203 :
204 : #if defined HAVE_BIGDFT
205 : ! write(message,'(2a)') ch10,'wvl_rho_abi2big: but why are you copying me :..o('
206 : ! call wrtout(std_out,message,'COLL')
207 :
208 : if(opt==1) then !ABINIT -> BIGDFT
209 :
210 : call wvl_rhov_abi2big(opt,rhor,wvl_den%denspot%rhov)
211 : wvl_den%denspot%rhov_is = ELECTRONIC_DENSITY
212 :
213 : elseif(opt==2) then !BigDFT -> ABINIT
214 :
215 : if(wvl_den%denspot%rhov_is .ne. ELECTRONIC_DENSITY) then
216 : message='wvl_rho_abi2big: rhov should contain the ELECTRONIC_DENSITY'
217 : ABI_BUG(message)
218 : end if
219 : call wvl_rhov_abi2big(opt,rhor,wvl_den%denspot%rhov)
220 :
221 : else
222 : message='wvl_rho_abi2big: wrong option'
223 : ABI_BUG(message)
224 : end if
225 :
226 : #else
227 0 : BIGDFT_NOTENABLED_ERROR()
228 : if (.false.) write(std_out,*) opt,rhor(1,1),wvl_den%symObj
229 : #endif
230 :
231 : DBG_EXIT("COLL")
232 :
233 0 : end subroutine wvl_rho_abi2big
234 : !!***
235 :
236 : !!****f* m_abi2big/wvl_vhartr_abi2big
237 : !! NAME
238 : !! wvl_vhartr_abi2big
239 : !!
240 : !! FUNCTION
241 : !! Copies vhartree in ABINIT to BigDFT objects and viceversa.
242 : !!
243 : !! INPUTS
244 : !! opt= 1) copy from ABINIT to BigDFT
245 : !! 2) copy from BigDFT to ABINIT
246 : !! vhartr(nfft)= Hartree potential (ABINIT array)
247 : !! wvl_den= density-potential BigDFT object
248 : !!
249 : !! OUTPUT
250 : !!
251 : !! SIDE EFFECTS
252 : !! vhartr is copied to wvl_den, or viceversa, depending on "opt" (see above).
253 : !! It verifies that (or sets) wvl_den%rhov_is = HARTREE_POTENTIAL
254 : !!
255 : !! NOTES
256 : !! It uses the generic routine wvl_rhov_abi2big.
257 : !!
258 : !! SOURCE
259 :
260 0 : subroutine wvl_vhartr_abi2big(opt,vhartr,wvl_den)
261 :
262 : #if defined HAVE_BIGDFT
263 : use BigDFT_API, only : HARTREE_POTENTIAL
264 : #endif
265 :
266 : !Arguments ------------------------------------
267 : integer , intent(in) :: opt
268 : real(dp) , intent(inout) :: vhartr(:)
269 : type(wvl_denspot_type), intent(inout) :: wvl_den
270 :
271 : !Local variables-------------------------------
272 : #if defined HAVE_BIGDFT
273 : integer :: shiftV
274 : character(len=100) :: message
275 : #endif
276 :
277 : ! *************************************************************************
278 :
279 : DBG_ENTER("COLL")
280 :
281 : #if defined HAVE_BIGDFT
282 : ! write(message,'(2a)') ch10, 'wvl_vhartr_abi2big: but why are you copying me :..o('
283 : ! call wrtout(std_out,message,'COLL')
284 :
285 : shiftV=wvl_den%denspot%dpbox%ndims(1)*wvl_den%denspot%dpbox%ndims(2) &
286 : & *wvl_den%denspot%dpbox%i3xcsh
287 :
288 : if(opt==1) then !ABINIT -> BIGDFT
289 :
290 : call wvl_rhov_abi2big(opt,vhartr,wvl_den%denspot%rhov,shift=shiftV)
291 : wvl_den%denspot%rhov_is = HARTREE_POTENTIAL
292 :
293 : elseif(opt==2) then !BigDFT -> ABINIT
294 :
295 : if(wvl_den%denspot%rhov_is .ne. HARTREE_POTENTIAL) then
296 : message='wvl_vhartr_abi2big: rhov should contain the HARTREE_POTENTIAL'
297 : ABI_BUG(message)
298 : end if
299 : call wvl_rhov_abi2big(opt,vhartr,wvl_den%denspot%rhov,shift=shiftV)
300 :
301 : else
302 : message='wvl_vhartr_abi2big: wrong option'
303 : ABI_BUG(message)
304 : end if
305 :
306 : #else
307 0 : BIGDFT_NOTENABLED_ERROR()
308 : if (.false.) write(std_out,*) opt,vhartr(1),wvl_den%symObj
309 : #endif
310 :
311 : DBG_EXIT("COLL")
312 :
313 0 : end subroutine wvl_vhartr_abi2big
314 : !!***
315 :
316 : !!****f* m_abi2big/wvl_vxc_abi2big
317 : !! NAME
318 : !! wvl_vxc_abi2big
319 : !!
320 : !! FUNCTION
321 : !! It copies the Vxc potential from ABINIT to BigDFT or viceversa.
322 : !!
323 : !! INPUTS
324 : !! opt= 1) copy from ABINIT to BigDFT
325 : !! 2) copy from BigDFT to ABINIT
326 : !! vxc(nfft,nspden)= trial potential (ABINIT array)
327 : !! wvl_den= density-potential BigDFT object
328 : !!
329 : !! OUTPUT
330 : !!
331 : !! SIDE EFFECTS
332 : !! vxc is copied to wvl_den, or viceversa, depending on "opt" (see above).
333 : !!
334 : !! NOTES
335 : !! It uses the generic routine wvl_rhov_abi2big.
336 : !!
337 : !! SOURCE
338 :
339 0 : subroutine wvl_vxc_abi2big(opt,vxc,wvl_den)
340 :
341 :
342 : !Arguments ------------------------------------
343 : integer,intent(in) :: opt
344 : real(dp),intent(inout) :: vxc(:,:)
345 : type(wvl_denspot_type), intent(inout) :: wvl_den
346 :
347 : !Local variables-------------------------------
348 : #if defined HAVE_BIGDFT
349 : integer :: shiftV
350 : #endif
351 :
352 : ! *************************************************************************
353 :
354 : DBG_ENTER("COLL")
355 :
356 : #if defined HAVE_BIGDFT
357 : ! write(message,'(2a)') ch10, 'wvl_vxc_abi2big: but why are you copying me :..o('
358 : ! call wrtout(std_out,message,'COLL')
359 :
360 : shiftV=wvl_den%denspot%dpbox%ndims(1)*wvl_den%denspot%dpbox%ndims(2) &
361 : & *wvl_den%denspot%dpbox%i3xcsh
362 :
363 : call wvl_rhov_abi2big(opt,vxc,wvl_den%denspot%v_xc,shift=shiftV)
364 :
365 : #else
366 0 : BIGDFT_NOTENABLED_ERROR()
367 : if (.false.) write(std_out,*) opt,vxc(1,1),wvl_den%symObj
368 : #endif
369 :
370 : DBG_EXIT("COLL")
371 :
372 0 : end subroutine wvl_vxc_abi2big
373 : !!***
374 :
375 : !!****f* m_abi2big/wvl_occ_abi2big
376 : !! NAME
377 : !! wvl_occ_abi2big
378 : !!
379 : !! FUNCTION
380 : !! Copies occupations in ABINIT to BigDFT objects and viceversa.
381 : !!
382 : !! INPUTS
383 : !! opt= 1) copy from ABINIT to BigDFT
384 : !! 2) copy from BigDFT to ABINIT
385 : !! nsppol= number of spin polarization
386 : !!
387 : !! OUTPUT
388 : !!
389 : !! SIDE EFFECTS
390 : !! occ is copied to wfs%ks%orbs%occup, or viceversa, depending on "opt" (see above).
391 : !!
392 : !! SOURCE
393 :
394 0 : subroutine wvl_occ_abi2big(mband,nkpt,nsppol,occ,opt,wvl_wfs)
395 :
396 :
397 : !Arguments ------------------------------------
398 : integer , intent(in) :: mband,nkpt,nsppol,opt
399 : real(dp) , intent(inout) :: occ(mband*nkpt*nsppol)
400 : type(wvl_wf_type), intent(inout) :: wvl_wfs
401 :
402 : !Local variables-------------------------------
403 : #if defined HAVE_BIGDFT
404 : integer :: norb,norbd,norbu,ii
405 : character(len=100) :: message
406 : #endif
407 :
408 : ! *************************************************************************
409 :
410 : DBG_ENTER("COLL")
411 :
412 : #if defined HAVE_BIGDFT
413 : !PENDING: I am not sure this will work for nsppol==2
414 : !check also the parallel case.
415 :
416 : norbu=wvl_wfs%ks%orbs%norbu
417 : norbd=wvl_wfs%ks%orbs%norbd
418 : norb =wvl_wfs%ks%orbs%norb
419 : if(opt==1) then !ABINIT -> BIGDFT
420 : if (nsppol == 1) then
421 : do ii=1,norb
422 : wvl_wfs%ks%orbs%occup(ii)=occ(ii)
423 : end do
424 : else
425 : wvl_wfs%ks%orbs%occup(1:norbu)=occ(1:norbu)
426 : wvl_wfs%ks%orbs%occup(norbu + 1:norb)= &
427 : & occ(mband + 1:mband + norbd)
428 : end if
429 : elseif(opt==2) then !BigDFT -> ABINIT
430 : if (nsppol == 1) then
431 : do ii=1,norb
432 : occ=wvl_wfs%ks%orbs%occup
433 : end do
434 : else
435 : occ(1:norbu) = wvl_wfs%ks%orbs%occup(1:norbu)
436 : occ(mband + 1:mband + norbd) = &
437 : & wvl_wfs%ks%orbs%occup(norbu + 1:norb)
438 : end if
439 : else
440 : message='wvl_occ_abi2big: wrong option'
441 : ABI_BUG(message)
442 : end if
443 :
444 : #else
445 0 : BIGDFT_NOTENABLED_ERROR()
446 : if (.false.) write(std_out,*) mband,nkpt,nsppol,opt,occ(1),wvl_wfs%ks
447 : #endif
448 :
449 : DBG_EXIT("COLL")
450 :
451 0 : end subroutine wvl_occ_abi2big
452 : !!***
453 :
454 : !!****f* m_abi2big/wvl_eigen_abi2big
455 : !! NAME
456 : !! wvl_eigen_abi2big
457 : !!
458 : !! FUNCTION
459 : !! Copies eigenvalues in ABINIT to BigDFT objects and viceversa.
460 : !!
461 : !! INPUTS
462 : !! opt= 1) copy from ABINIT to BigDFT
463 : !! 2) copy from BigDFT to ABINIT
464 : !! nsppol= number of spin polarization
465 : !!
466 : !! OUTPUT
467 : !!
468 : !! SIDE EFFECTS
469 : !! occ is copied to wfs%ks%orbs%occup, or viceversa, depending on "opt" (see above).
470 : !!
471 : !! SOURCE
472 :
473 0 : subroutine wvl_eigen_abi2big(mband,nkpt,nsppol,eigen,opt,wvl_wfs)
474 :
475 :
476 : !Arguments ------------------------------------
477 : integer , intent(in) :: mband,nkpt,nsppol,opt
478 : real(dp) , intent(inout) :: eigen(mband*nkpt*nsppol)
479 : type(wvl_wf_type), intent(inout) :: wvl_wfs
480 :
481 : !Local variables-------------------------------
482 : #if defined HAVE_BIGDFT
483 : integer :: ii,norb,norbd,norbu
484 : character(len=100) :: message
485 : #endif
486 :
487 : ! *************************************************************************
488 :
489 : DBG_ENTER("COLL")
490 :
491 : #if defined HAVE_BIGDFT
492 : !PENDING: I am not sure this will work for nsppol==2
493 : !check also the parallel case.
494 :
495 : norbu=wvl_wfs%ks%orbs%norbu
496 : norbd=wvl_wfs%ks%orbs%norbd
497 : norb =wvl_wfs%ks%orbs%norb
498 : if(opt==1) then !ABINIT -> BIGDFT
499 : if (nsppol == 1) then
500 : wvl_wfs%ks%orbs%eval=eigen
501 : else
502 : wvl_wfs%ks%orbs%eval(1:norbu)=eigen(1:norbu)
503 : wvl_wfs%ks%orbs%eval(norbu + 1:norb)= &
504 : & eigen(mband + 1:mband + norbd)
505 : end if
506 : elseif(opt==2) then !BigDFT -> ABINIT
507 : if (nsppol == 1) then
508 : do ii=1,norb
509 : eigen(ii)=wvl_wfs%ks%orbs%eval(ii)
510 : end do
511 : else
512 : eigen(1:norbu) = wvl_wfs%ks%orbs%eval(1:norbu)
513 : eigen(mband + 1:mband + norbd) = &
514 : & wvl_wfs%ks%orbs%eval(norbu + 1:norb)
515 : end if
516 : else
517 : message='wvl_eigen_abi2big: wrong option'
518 : ABI_BUG(message)
519 : end if
520 :
521 : #else
522 0 : BIGDFT_NOTENABLED_ERROR()
523 : if (.false.) write(std_out,*) mband,nkpt,nsppol,opt,eigen(1),wvl_wfs%ks
524 : #endif
525 :
526 : DBG_EXIT("COLL")
527 :
528 0 : end subroutine wvl_eigen_abi2big
529 : !!***
530 :
531 : !!****f* m_abi2big/wvl_occopt_abi2big
532 : !! NAME
533 : !! wvl_occopt_abi2big
534 : !!
535 : !! FUNCTION
536 : !! Copies occopt in ABINIT to BigDFT objects and viceversa.
537 : !!
538 : !! INPUTS
539 : !! opt= 1) copy from ABINIT to BigDFT
540 : !! 2) copy from BigDFT to ABINIT
541 : !!
542 : !! OUTPUT
543 : !!
544 : !! SIDE EFFECTS
545 : !!
546 : !! NOTES
547 : !! Several smearing schemes do not exists in both codes such
548 : !! as the SMEARING_DIST_ERF in BigDFT.
549 : !!
550 : !! SOURCE
551 :
552 0 : subroutine wvl_occopt_abi2big(occopt_abi,occopt_big,opt)
553 :
554 : #if defined HAVE_BIGDFT
555 : use BigDFT_API, only : &
556 : & SMEARING_DIST_FERMI, SMEARING_DIST_COLD1, SMEARING_DIST_COLD2,&
557 : & SMEARING_DIST_METPX
558 : #endif
559 :
560 : !Arguments ------------------------------------
561 : integer , intent(inout) :: occopt_abi,occopt_big
562 : integer , intent(in) :: opt
563 :
564 : !Local variables-------------------------------
565 : #if defined HAVE_BIGDFT
566 : character(len=500) :: message
567 : #endif
568 :
569 : ! *************************************************************************
570 :
571 : DBG_ENTER("COLL")
572 :
573 : #if defined HAVE_BIGDFT
574 :
575 : if(opt==1) then !ABINIT -> BIGDFT
576 : if(occopt_abi==3) then
577 : occopt_big=SMEARING_DIST_FERMI
578 : elseif(occopt_abi==4) then
579 : occopt_big=SMEARING_DIST_COLD1
580 : elseif(occopt_abi==5) then
581 : occopt_big=SMEARING_DIST_COLD2
582 : elseif(occopt_abi==6) then
583 : occopt_big=SMEARING_DIST_METPX
584 : else
585 : write(message,'(4a)') ch10,&
586 : & ' wvl_occopt_abi2big: occopt does not have a corresponding option in BigDFT.',ch10,&
587 : & ' Action: change the value of occopt to a number between 3 and 6'
588 : ABI_ERROR(message)
589 : end if
590 : elseif(opt==2) then !BigDFT -> ABINIT
591 : if(occopt_big==SMEARING_DIST_FERMI) then
592 : occopt_abi=3
593 : elseif(occopt_big==SMEARING_DIST_COLD1) then
594 : occopt_abi=4
595 : elseif(occopt_big==SMEARING_DIST_COLD2) then
596 : occopt_abi=5
597 : elseif(occopt_big==SMEARING_DIST_METPX) then
598 : occopt_abi=6
599 : else
600 : ! One should never get here.
601 : write(message,'(4a)') ch10,&
602 : & ' wvl_occopt_abi2big: occopt in BigDFT does not have a corresponding option in ABINIT.',ch10,&
603 : & ' Action: contact the ABINIT group'
604 : ABI_ERROR(message)
605 : end if
606 : else
607 : message='wvl_occopt_abi2big: wrong option'
608 : ABI_BUG(message)
609 : end if
610 :
611 : #else
612 0 : BIGDFT_NOTENABLED_ERROR()
613 : if (.false.) write(std_out,*) occopt_abi,occopt_big,opt
614 : #endif
615 :
616 : DBG_EXIT("COLL")
617 :
618 0 : end subroutine wvl_occopt_abi2big
619 : !!***
620 :
621 : !!****f* m_abi2big/wvl_rhov_abi2big_2D_4D
622 : !! NAME
623 : !! wvl_rhov_abi2big_2D_4D
624 : !!
625 : !! FUNCTION
626 : !! Copies a density/potential from ABINIT to BigDFT or viceversa.
627 : !! Target : ABINIT 2D arrays (with spin), BigDFT 4D arrays (with spin)
628 : !!
629 : !! INPUTS
630 : !! opt= 1: copy from ABINIT to BigDFT, 2: copy from BigDFT to ABINIT
631 : !! rhov_abi(:,:) = density/potential array in ABINIT
632 : !! rhov_big(:,:,:,:) = density/potential array in BigDFT
633 : !! [shift] = shift to be applied in rhov_abi array (parallelism)
634 : !!
635 : !! OUTPUT
636 : !!
637 : !! SIDE EFFECTS
638 : !! At output rhov_abi is copied to rhov_abinit, or viceversa
639 : !!
640 : !! SOURCE
641 :
642 0 : subroutine wvl_rhov_abi2big_2D_4D(opt,rhov_abi,rhov_big,shift)
643 :
644 :
645 : !Arguments ------------------------------------
646 : integer,intent(in) :: opt
647 : integer,intent(in),optional :: shift
648 : real(dp) :: rhov_abi(:,:),rhov_big(:,:,:,:)
649 :
650 : !Local variables-------------------------------
651 : #if defined HAVE_BIGDFT
652 : integer :: nfft_abi,nfft_big,nspden,shift_
653 : character(len=100) :: message
654 : #endif
655 :
656 : ! *************************************************************************
657 :
658 : #if defined HAVE_BIGDFT
659 : nspden=size(rhov_abi,2)
660 : if (size(rhov_big,4)/=nspden) then
661 : message='wvl_rhov_abi2big: ABINIT and BigDFT objects do not have the same nspden'
662 : ABI_BUG(message)
663 : end if
664 : nfft_abi=size(rhov_abi)/nspden ; nfft_big=size(rhov_big)/nspden
665 : shift_=0;if (present(shift)) shift_=shift
666 : call wvl_rhov_abi2big_gen(nfft_abi,nfft_big,nspden,opt,rhov_abi,rhov_big,shift_)
667 : #else
668 0 : BIGDFT_NOTENABLED_ERROR()
669 : if (.false. .and. present(shift)) write(std_out,*) opt,rhov_abi(1,1),rhov_big(1,1,1,1)
670 : #endif
671 :
672 0 : end subroutine wvl_rhov_abi2big_2D_4D
673 : !!***
674 :
675 : !!****f* m_abi2big/wvl_rhov_abi2big_1D_4D
676 : !! NAME
677 : !! wvl_rhov_abi2big_1D_4D
678 : !!
679 : !! FUNCTION
680 : !! Copies a density/potential from ABINIT to BigDFT or viceversa.
681 : !! Target : ABINIT 1D arrays (without spin), BigDFT 4D arrays (with spin)
682 : !!
683 : !! INPUTS
684 : !! opt= 1: copy from ABINIT to BigDFT, 2: copy from BigDFT to ABINIT
685 : !! rhov_abi(:) = density/potential array in ABINIT
686 : !! rhov_big(:,:,:,:) = density/potential array in BigDFT
687 : !! [shift] = shift to be applied in rhov_abi array (parallelism)
688 : !!
689 : !! OUTPUT
690 : !!
691 : !! SIDE EFFECTS
692 : !! At output rhov_abi is copied to rhov_abinit, or viceversa
693 : !!
694 : !! SOURCE
695 :
696 0 : subroutine wvl_rhov_abi2big_1D_4D(opt,rhov_abi,rhov_big,shift)
697 :
698 :
699 : !Arguments ------------------------------------
700 : integer,intent(in) :: opt
701 : integer,intent(in),optional :: shift
702 : real(dp) :: rhov_abi(:),rhov_big(:,:,:,:)
703 :
704 : !Local variables-------------------------------
705 : #if defined HAVE_BIGDFT
706 : integer :: nfft_abi,nfft_big,shift_
707 : character(len=100) :: message
708 : #endif
709 :
710 : ! *************************************************************************
711 :
712 : #if defined HAVE_BIGDFT
713 : if (size(rhov_big,4)/=1) then
714 : message='wvl_rhov_abi2big: ABINIT and BigDFT objects do not have the same nspden'
715 : ABI_BUG(message)
716 : end if
717 : nfft_abi=size(rhov_abi) ; nfft_big=size(rhov_big)
718 : shift_=0;if (present(shift)) shift_=shift
719 : call wvl_rhov_abi2big_gen(nfft_abi,nfft_big,1,opt,rhov_abi,rhov_big,shift_)
720 : #else
721 0 : BIGDFT_NOTENABLED_ERROR()
722 : if (.false. .and. present(shift)) write(std_out,*) opt,rhov_abi(1),rhov_big(1,1,1,1)
723 : #endif
724 :
725 0 : end subroutine wvl_rhov_abi2big_1D_4D
726 : !!***
727 :
728 : !!****f* m_abi2big/wvl_rhov_abi2big_2D_2D
729 : !! NAME
730 : !! wvl_rhov_abi2big_2D_2D
731 : !!
732 : !! FUNCTION
733 : !! Copies a density/potential from ABINIT to BigDFT or viceversa.
734 : !! Target : ABINIT 2D arrays (with spin), BigDFT 2D arrays (with spin)
735 : !!
736 : !! INPUTS
737 : !! opt= 1: copy from ABINIT to BigDFT, 2: copy from BigDFT to ABINIT
738 : !! rhov_abi(:,:) = density/potential array in ABINIT
739 : !! rhov_big(:,:) = density/potential array in BigDFT
740 : !! [shift] = shift to be applied in rhov_abi array (parallelism)
741 : !!
742 : !! OUTPUT
743 : !!
744 : !! SIDE EFFECTS
745 : !! At output rhov_abi is copied to rhov_abinit, or viceversa
746 : !!
747 : !! SOURCE
748 :
749 0 : subroutine wvl_rhov_abi2big_2D_2D(opt,rhov_abi,rhov_big,shift)
750 :
751 :
752 : !Arguments ------------------------------------
753 : integer,intent(in) :: opt
754 : integer,intent(in),optional :: shift
755 : real(dp) :: rhov_abi(:,:),rhov_big(:,:)
756 :
757 : !Local variables-------------------------------
758 : #if defined HAVE_BIGDFT
759 : integer :: nfft_abi,nfft_big,nspden,shift_
760 : character(len=100) :: message
761 : #endif
762 :
763 : ! *************************************************************************
764 :
765 : #if defined HAVE_BIGDFT
766 : nspden=size(rhov_abi,2)
767 : if (size(rhov_big,2)/=nspden) then
768 : message='wvl_rhov_abi2big: ABINIT and BigDFT objects do not have the same nspden'
769 : ABI_BUG(message)
770 : end if
771 : nfft_abi=size(rhov_abi)/nspden ; nfft_big=size(rhov_big)/nspden
772 : shift_=0;if (present(shift)) shift_=shift
773 : call wvl_rhov_abi2big_gen(nfft_abi,nfft_big,nspden,opt,rhov_abi,rhov_big,shift_)
774 : #else
775 0 : BIGDFT_NOTENABLED_ERROR()
776 : if (.false. .and. present(shift)) write(std_out,*) opt,rhov_abi(1,1),rhov_big(1,1)
777 : #endif
778 :
779 0 : end subroutine wvl_rhov_abi2big_2D_2D
780 : !!***
781 :
782 : !!****f* m_abi2big/wvl_rhov_abi2big_1D_2D
783 : !! NAME
784 : !! wvl_rhov_abi2big_1D_2D
785 : !!
786 : !! FUNCTION
787 : !! Copies a density/potential from ABINIT to BigDFT or viceversa.
788 : !! Target : ABINIT 1D arrays (without spin), BigDFT 2D arrays (with spin)
789 : !!
790 : !! INPUTS
791 : !! opt= 1: copy from ABINIT to BigDFT, 2: copy from BigDFT to ABINIT
792 : !! rhov_abi(:) = density/potential array in ABINIT
793 : !! rhov_big(:,:) = density/potential array in BigDFT
794 : !! [shift] = shift to be applied in rhov_abi array (parallelism)
795 : !!
796 : !! OUTPUT
797 : !!
798 : !! SIDE EFFECTS
799 : !! At output rhov_abi is copied to rhov_abinit, or viceversa
800 : !!
801 : !! SOURCE
802 :
803 0 : subroutine wvl_rhov_abi2big_1D_2D(opt,rhov_abi,rhov_big,shift)
804 :
805 :
806 : !Arguments ------------------------------------
807 : integer,intent(in) :: opt
808 : integer,intent(in),optional :: shift
809 : real(dp) :: rhov_abi(:),rhov_big(:,:)
810 :
811 : !Local variables-------------------------------
812 : #if defined HAVE_BIGDFT
813 : integer :: nfft_abi,nfft_big,shift_
814 : character(len=100) :: message
815 : #endif
816 :
817 : ! *************************************************************************
818 :
819 : #if defined HAVE_BIGDFT
820 : if (size(rhov_big,2)/=1) then
821 : message='wvl_rhov_abi2big: ABINIT and BigDFT objects do not have the same nspden'
822 : ABI_BUG(message)
823 : end if
824 : nfft_abi=size(rhov_abi) ; nfft_big=size(rhov_big)
825 : shift_=0;if (present(shift)) shift_=shift
826 : call wvl_rhov_abi2big_gen(nfft_abi,nfft_big,1,opt,rhov_abi,rhov_big,shift_)
827 : #else
828 0 : BIGDFT_NOTENABLED_ERROR()
829 : if (.false. .and. present(shift)) write(std_out,*) opt,rhov_abi(1),rhov_big(1,1)
830 : #endif
831 :
832 0 : end subroutine wvl_rhov_abi2big_1D_2D
833 : !!***
834 :
835 : !!****f* m_abi2big/wvl_rhov_abi2big_2D_1D
836 : !! NAME
837 : !! wvl_rhov_abi2big_2D_1D
838 : !!
839 : !! FUNCTION
840 : !! Copies a density/potential from ABINIT to BigDFT or viceversa.
841 : !! Target : ABINIT 2D arrays (with spin), BigDFT 1D arrays (with or without spin)
842 : !!
843 : !! INPUTS
844 : !! opt= 1: copy from ABINIT to BigDFT, 2: copy from BigDFT to ABINIT
845 : !! rhov_abi(:,:) = density/potential array in ABINIT
846 : !! rhov_big(:) = density/potential array in BigDFT
847 : !! [shift] = shift to be applied in rhov_abi array (parallelism)
848 : !!
849 : !! OUTPUT
850 : !!
851 : !! SIDE EFFECTS
852 : !! At output rhov_abi is copied to rhov_abinit, or viceversa
853 : !!
854 : !! SOURCE
855 :
856 0 : subroutine wvl_rhov_abi2big_2D_1D(opt,rhov_abi,rhov_big,shift)
857 :
858 :
859 : !Arguments ------------------------------------
860 : integer,intent(in) :: opt
861 : integer,intent(in),optional :: shift
862 : real(dp) :: rhov_abi(:,:),rhov_big(:)
863 :
864 : !Local variables-------------------------------
865 : #if defined HAVE_BIGDFT
866 : integer :: nfft_abi,nfft_big,nspden,shift_
867 : #endif
868 :
869 : ! *************************************************************************
870 :
871 : #if defined HAVE_BIGDFT
872 : nspden=size(rhov_abi,2)
873 : nfft_abi=size(rhov_abi)/nspden ; nfft_big=size(rhov_big)/nspden
874 : shift_=0;if (present(shift)) shift_=shift
875 : call wvl_rhov_abi2big_gen(nfft_abi,nfft_big,nspden,opt,rhov_abi,rhov_big,shift_)
876 : #else
877 0 : BIGDFT_NOTENABLED_ERROR()
878 : if (.false. .and. present(shift)) write(std_out,*) opt,rhov_abi(1,1),rhov_big(1)
879 : #endif
880 :
881 0 : end subroutine wvl_rhov_abi2big_2D_1D
882 : !!***
883 :
884 : !!****f* m_abi2big/wvl_rhov_abi2big_1D_1D
885 : !! NAME
886 : !! wvl_rhov_abi2big_1D_1D
887 : !!
888 : !! FUNCTION
889 : !! Copies a density/potential from ABINIT to BigDFT or viceversa.
890 : !! Target : ABINIT 2D arrays (without spin), BigDFT 1D arrays (with or without spin)
891 : !!
892 : !! INPUTS
893 : !! opt= 1: copy from ABINIT to BigDFT, 2: copy from BigDFT to ABINIT
894 : !! rhov_abi(:) = density/potential array in ABINIT
895 : !! rhov_big(:) = density/potential array in BigDFT
896 : !! [shift] = shift to be applied in rhov_abi array (parallelism)
897 : !!
898 : !! OUTPUT
899 : !!
900 : !! SIDE EFFECTS
901 : !! At output rhov_abi is copied to rhov_abinit, or viceversa
902 : !!
903 : !! SOURCE
904 :
905 0 : subroutine wvl_rhov_abi2big_1D_1D(opt,rhov_abi,rhov_big,shift)
906 :
907 :
908 : !Arguments ------------------------------------
909 : integer,intent(in) :: opt
910 : integer,intent(in),optional :: shift
911 : real(dp) :: rhov_abi(:),rhov_big(:)
912 :
913 : !Local variables-------------------------------
914 : #if defined HAVE_BIGDFT
915 : integer :: nfft_abi,nfft_big,shift_
916 : #endif
917 :
918 : ! *************************************************************************
919 :
920 : #if defined HAVE_BIGDFT
921 : nfft_abi=size(rhov_abi) ; nfft_big=size(rhov_big)
922 : shift_=0;if (present(shift)) shift_=shift
923 : call wvl_rhov_abi2big_gen(nfft_abi,nfft_big,1,opt,rhov_abi,rhov_big,shift_)
924 : #else
925 0 : BIGDFT_NOTENABLED_ERROR()
926 : if (.false. .and. present(shift)) write(std_out,*) opt,rhov_abi(1),rhov_big(1)
927 : #endif
928 :
929 0 : end subroutine wvl_rhov_abi2big_1D_1D
930 : !!***
931 :
932 : !!****f* m_abi2big/wvl_rhov_abi2big_gen
933 : !! NAME
934 : !! wvl_rhov_abi2big_gen
935 : !!
936 : !! FUNCTION
937 : !! Copies a density/potential from ABINIT to BigDFT or viceversa.
938 : !! This is a generic routine to copy objects.
939 : !!
940 : !! INPUTS
941 : !! nfft_abi = size of rhov_abi
942 : !! nfft_big = size of rhov_big
943 : !! nspden = number of spin components
944 : !! opt= 1) copy from ABINIT to BigDFT
945 : !! 2) copy from BigDFT to ABINIT
946 : !! rhov_abi(nfft_abi,nspden) = density/potential array in ABINIT
947 : !! rhov_big(nfft_big,nspden) = density/potential array in BigDFT
948 : !! shift = shift to be applied in rhov_abi array (parallelism)
949 : !!
950 : !! OUTPUT
951 : !!
952 : !! SIDE EFFECTS
953 : !! At output rhov_abi is copied to rhov_abinit, or viceversa
954 : !!
955 : !! NOTES
956 : !! This routine is duplicated:
957 : !! This option is faster but it requires more memory.
958 : !! Notice that we cannot point the variables since the spin convention is not
959 : !! the same in BigDFT and ABINIT.
960 : !! In ABINIT: index 1 is for the total spin (spin up + spin down) and index 2 is for spin up.
961 : !! In BigDFT: indices 1 and 2 are for spin up and down, respectively.
962 : !!
963 : !! SOURCE
964 :
965 : subroutine wvl_rhov_abi2big_gen(nfft_abi,nfft_big,nspden,opt,rhov_abi,rhov_big,shift)
966 :
967 :
968 : !Arguments ------------------------------------
969 : integer,intent(in) :: nfft_abi,nfft_big,nspden,opt,shift
970 : real(dp) :: rhov_abi(nfft_abi,nspden),rhov_big(nfft_big,nspden)
971 :
972 : !Local variables-------------------------------
973 : #if defined HAVE_BIGDFT
974 : integer :: ifft,jfft,nfft
975 : real(dp) :: tmpUp,tmpDown,tmpTot
976 : character(len=100) :: message
977 : real(dp),allocatable :: rhoup(:),rhodn(:),rhotot(:)
978 : #endif
979 :
980 : ! *************************************************************************
981 :
982 : DBG_ENTER("COLL")
983 :
984 : #if defined HAVE_BIGDFT
985 : !No objects to copy; in BigDFT by default they have size of 1!
986 : if(size(rhov_big)==1.and.size(rhov_abi)==0) return
987 :
988 : nfft=nfft_big;if (nfft_big+shift>nfft_abi) nfft=nfft-shift
989 :
990 : if (nfft_abi<nfft+shift) then
991 : message='wvl_rhov_abi2big: cannot handle nfft(abi)<nfft(big)+shift case'
992 : ABI_BUG(message)
993 : end if
994 : if(nspden==4) then
995 : message='wvl_rhov_abi2big: nspden=4 not yet supported'
996 : ABI_ERROR(message)
997 : end if
998 :
999 : if (hmem.and.nspden==2) then
1000 : if (opt==1) then
1001 : ABI_MALLOC(rhoup,(nfft))
1002 : ABI_MALLOC(rhodn,(nfft))
1003 : else if (opt==2) then
1004 : ABI_MALLOC(rhotot,(nfft))
1005 : end if
1006 : end if
1007 :
1008 : if (opt==1) then !ABINIT -> BIGDFT
1009 : if (nspden==2) then
1010 : if (hmem) then
1011 : rhoup(1:nfft)=rhov_abi(shift+1:shift+nfft,2)
1012 : rhodn(1:nfft)=rhov_abi(shift+1:shift+nfft,1)-rhoup(1:nfft)
1013 : rhov_big(:,1)=rhoup(:)
1014 : rhov_big(:,2)=rhodn(:)
1015 : else
1016 : do ifft=1,nfft
1017 : jfft=shift+ifft
1018 : ! We change convention for BigDFT
1019 : tmpDown=rhov_abi(jfft,1)-rhov_abi(jfft,2)
1020 : tmpUp =rhov_abi(jfft,2)
1021 : rhov_big(ifft,1)=tmpUp
1022 : rhov_big(ifft,2)=tmpDown
1023 : end do
1024 : end if !hmem
1025 : else !nspden==1
1026 : if (hmem) then
1027 : rhov_big(1:nfft,1)=rhov_abi(shift+1:shift+nfft,1)
1028 : else
1029 : do ifft=1,nfft
1030 : rhov_big(ifft,1)=rhov_abi(shift+ifft,1)
1031 : end do
1032 : end if!hmem
1033 : end if !nspden
1034 :
1035 : else if (opt==2) then !BigDFT -> ABINIT
1036 : if (nspden==2) then
1037 : if (hmem) then
1038 : rhotot(:)=rhov_big(:,1)+rhov_big(:,2)
1039 : rhov_abi(shift+1:shift+nfft,1)=rhotot(1:nfft)
1040 : rhov_abi(shift+1:shift+nfft,2)=rhov_big(1:nfft,1)
1041 : else
1042 : do ifft=1,nfft
1043 : jfft=shift+ifft
1044 : ! We change convention for BigDFT
1045 : tmpTot=rhov_big(ifft,1)+rhov_big(ifft,2)
1046 : rhov_abi(jfft,1)=tmpTot
1047 : rhov_abi(jfft,2)=rhov_big(ifft,1) !Spin Up
1048 : end do
1049 : end if !hmem
1050 : else if (nspden==1) then
1051 : if (hmem) then
1052 : rhov_abi(shift+1:shift+nfft,1)=rhov_big(1:nfft,1)
1053 : else
1054 : do ifft=1,nfft
1055 : rhov_abi(shift+ifft,1)=rhov_big(ifft,1)
1056 : end do
1057 : end if !hmem
1058 : end if !nspden
1059 :
1060 : else
1061 : message='wvl_rhov_abi2big_gen: wrong option'
1062 : ABI_BUG(message)
1063 : end if
1064 :
1065 : if (hmem.and.nspden==2) then
1066 : if (opt==1) then
1067 : ABI_FREE(rhoup)
1068 : ABI_FREE(rhodn)
1069 : else if (opt==2) then
1070 : ABI_FREE(rhotot)
1071 : end if !opt
1072 : end if
1073 :
1074 : #else
1075 : BIGDFT_NOTENABLED_ERROR()
1076 : if (.false.) write(std_out,*) nfft_abi,nfft_big,nspden,opt,shift,rhov_big(1,1),rhov_abi(1,1)
1077 : #endif
1078 :
1079 : DBG_EXIT("COLL")
1080 :
1081 : end subroutine wvl_rhov_abi2big_gen
1082 : !!***
1083 :
1084 : !!****f* ABINIT/wvl_setngfft
1085 : !! NAME
1086 : !! wvl_setngfft
1087 : !!
1088 : !! FUNCTION
1089 : !! When wavelets are used, the FFT grid is used to store potentials and
1090 : !! density. The size of the grid takes into account the two resolution in wavelet
1091 : !! description and also the distribution over processor in the parallel case.
1092 : !!
1093 : !! The FFT grid is not in strict terms an FFT grid but rather a real space grid.
1094 : !! Its dimensions are not directly compatible with FFTs. This is not relevant
1095 : !! when using the wavelet part of the code and in the Poisson solver the arrays
1096 : !! are extended to match FFT dimensions internally. But for other parts of the
1097 : !! code, this must be taken into account.
1098 : !!
1099 : !! see doc/variables/vargs.html#ngfft for details about ngfft
1100 : !!
1101 : !! SIDE EFFECTS
1102 : !! mpi_enreg=information about MPI parallelization (description of the
1103 : !! density and potentials scatterring is allocated and updated).
1104 : !! dtset <type(dataset_type)>=the FFT grid is changed.
1105 : !!
1106 : !! SOURCE
1107 :
1108 0 : subroutine wvl_setngfft(me_wvl, mgfft, nfft, ngfft, nproc_wvl, n1i, n2i, n3i,n3d)
1109 :
1110 :
1111 : !Arguments ------------------------------------
1112 : !scalars
1113 : integer, intent(inout) :: mgfft, nfft
1114 : integer, intent(in) :: n1i, n2i, n3i,n3d, nproc_wvl, me_wvl
1115 : !arrays
1116 : integer, intent(inout) :: ngfft(18)
1117 :
1118 : !Local variables-------------------------------
1119 : !scalars
1120 : #if defined HAVE_BIGDFT
1121 : character(len=500) :: message
1122 : #endif
1123 :
1124 : ! *************************************************************************
1125 :
1126 : #if defined HAVE_BIGDFT
1127 : write(message, '(a,a,a,a)' ) ch10,&
1128 : & ' wvl_setngfft : Changing the FFT grid definition.'
1129 : call wrtout(std_out,message,'COLL')
1130 :
1131 : !Change nfft and ngfft
1132 : !Now ngfft will use the density definition (since the potential size
1133 : !is always smaller than the density one). ????
1134 : ngfft(1) = n1i
1135 : ngfft(2) = n2i
1136 : ngfft(3) = n3i
1137 :
1138 : nfft = n1i*n2i*n3d
1139 : !Set up fft array dimensions ngfft(4,5,6) to avoid cache conflicts
1140 : !Code paste from getng()
1141 : ngfft(4) = 2 * (ngfft(1) / 2) + 1
1142 : ngfft(5) = 2 * (ngfft(2) / 2) + 1
1143 : ngfft(6) = ngfft(3)
1144 : if (nproc_wvl == 0) then
1145 : ngfft(9) = 0 ! paral_fft
1146 : ngfft(10) = 1 ! nproc_fft
1147 : ngfft(11) = 0 ! me_fft
1148 : ngfft(12) = 0 ! n2proc
1149 : ngfft(13) = 0 ! n3proc
1150 : else
1151 : ngfft(9) = 1 ! paral_fft
1152 : ngfft(10) = nproc_wvl
1153 : ngfft(11) = me_wvl
1154 : ngfft(12) = ngfft(2)
1155 : ngfft(13) = n3d
1156 : end if
1157 :
1158 : write(message, '(a,3I12)' ) &
1159 : & ' | ngfft(1:3) is now: ', ngfft(1:3)
1160 : call wrtout(std_out,message,'COLL')
1161 : write(message, '(a,3I12)' ) &
1162 : & ' | ngfft(4:6) is now: ', ngfft(4:6)
1163 : call wrtout(std_out,message,'COLL')
1164 :
1165 : !Set mgfft
1166 : mgfft= max(ngfft(1), ngfft(2), ngfft(3))
1167 :
1168 : #else
1169 0 : BIGDFT_NOTENABLED_ERROR()
1170 : if (.false.) write(std_out,*) mgfft,nfft,n1i,n2i,n3i,n3d,nproc_wvl,me_wvl,ngfft(1)
1171 : #endif
1172 :
1173 0 : end subroutine wvl_setngfft
1174 : !!***
1175 :
1176 :
1177 : !!****f* ABINIT/wvl_setBoxGeometry
1178 : !! NAME
1179 : !! wvl_setBoxGeometry
1180 : !!
1181 : !! FUNCTION
1182 : !! When wavelets are used, the box definition needs to be changed.
1183 : !! The box size is recomputed knowing some psp information such as
1184 : !! the radius for coarse and fine grid. Then, the atoms are translated
1185 : !! to be included in the new box. Finally the FFT grid is computed using
1186 : !! the fine wavelet mesh and a buffer characteristic of used wavelets plus
1187 : !! a buffer used to be multiple of 2, 3 or 5.
1188 : !!
1189 : !! INPUTS
1190 : !! psps <type(pseudopotential_type)>=variables related to pseudopotentials
1191 : !! radii= the radii for each type of atoms, giving the fine and the coarse grid.
1192 : !!
1193 : !! OUTPUT
1194 : !! rprimd(3,3)=dimensional primitive translations in real space (bohr)
1195 : !!
1196 : !! SIDE EFFECTS
1197 : !! wvl <type(wvl_internal_type)>=internal variables used by wavelets, describing
1198 : !! the box are set.
1199 : !! xred(3,natom)=reduced dimensionless atomic coordinates
1200 : !!
1201 : !! SOURCE
1202 :
1203 0 : subroutine wvl_setBoxGeometry(prtvol, radii, rprimd, xred, wvl, wvl_crmult, wvl_frmult)
1204 :
1205 : #if defined HAVE_BIGDFT
1206 : use BigDFT_API, only: system_size,nullify_locreg_descriptors
1207 : #endif
1208 :
1209 : !Arguments ------------------------------------
1210 : !scalars
1211 : integer,intent(in) :: prtvol
1212 : real(dp), intent(in) :: wvl_crmult, wvl_frmult
1213 : type(wvl_internal_type), intent(inout) :: wvl
1214 : !arrays
1215 : real(dp),intent(in) :: radii(:,:)
1216 : real(dp),intent(inout) :: rprimd(3,3),xred(:,:)
1217 :
1218 : !Local variables-------------------------------
1219 : #if defined HAVE_BIGDFT
1220 : !scalars
1221 : integer :: ii
1222 : logical,parameter :: OCLconv=.false.
1223 : character(len=500) :: message
1224 : !arrays
1225 : real(dp) :: rprim(3,3),acell(3)
1226 : real(dp),allocatable :: xcart(:,:)
1227 : #endif
1228 :
1229 : ! *********************************************************************
1230 :
1231 : #if defined HAVE_BIGDFT
1232 : if (prtvol == 0) then
1233 : write(message, '(a,a,a,a)' ) ch10,&
1234 : & ' wvl_setBoxGeometry : Changing the box for wavelets computation.'
1235 : call wrtout(std_out,message,'COLL')
1236 : end if
1237 :
1238 : !Store xcart for each atom
1239 : ABI_MALLOC(xcart,(3, wvl%atoms%astruct%nat))
1240 : call xred2xcart(wvl%atoms%astruct%nat, rprimd, xcart, xred)
1241 :
1242 : call nullify_locreg_descriptors(wvl%Glr)
1243 : call system_size(wvl%atoms, xcart, radii, wvl_crmult, &
1244 : & wvl_frmult, wvl%h(1), wvl%h(2), wvl%h(3), OCLconv, wvl%Glr, wvl%shift)
1245 :
1246 : acell(:) = wvl%atoms%astruct%cell_dim(:)
1247 :
1248 : if (prtvol == 0) then
1249 : write(message, '(a,3F12.6)' ) &
1250 : & ' | acell is now: ', acell
1251 : call wrtout(std_out,message,'COLL')
1252 : write(message, '(a,2I5,a,a,2I5,a,a,2I5)' ) &
1253 : & ' | nfl1, nfu1: ', wvl%Glr%d%nfl1, wvl%Glr%d%nfu1, ch10, &
1254 : & ' | nfl2, nfu2: ', wvl%Glr%d%nfl2, wvl%Glr%d%nfu2, ch10, &
1255 : & ' | nfl3, nfu3: ', wvl%Glr%d%nfl3, wvl%Glr%d%nfu3
1256 : call wrtout(std_out,message,'COLL')
1257 : end if
1258 :
1259 : !Change the metric to orthogonal one
1260 : rprim(:, :) = real(0., dp)
1261 : do ii = 1, 3, 1
1262 : rprim(ii,ii) = real(1., dp)
1263 : end do
1264 : call mkrdim(acell, rprim, rprimd)
1265 :
1266 : !Save shifted atom positions into xred
1267 : call xcart2xred(wvl%atoms%astruct%nat, rprimd, xcart, xred)
1268 : ABI_FREE(xcart)
1269 :
1270 : if (prtvol == 0) then
1271 : write(message, '(a,3I12)' ) &
1272 : & ' | box size for datas: ', wvl%Glr%d%n1i, wvl%Glr%d%n2i, wvl%Glr%d%n3i
1273 : call wrtout(std_out,message,'COLL')
1274 : write(message, '(a,3I12)' ) &
1275 : & ' | box size for wavelets:', wvl%Glr%d%n1, wvl%Glr%d%n2, wvl%Glr%d%n3
1276 : call wrtout(std_out,message,'COLL')
1277 : end if
1278 :
1279 : #else
1280 0 : BIGDFT_NOTENABLED_ERROR()
1281 : if (.false.) write(std_out,*) prtvol,wvl_crmult,wvl_frmult,wvl%h(1),&
1282 : & radii(1,1),rprimd(1,1),xred(1,1)
1283 : #endif
1284 :
1285 0 : end subroutine wvl_setBoxGeometry
1286 : !!***
1287 :
1288 : end module m_abi2big
1289 : !!***
|