Line data Source code
1 : !!****m* ABINIT/m_wvl_denspot
2 : !! NAME
3 : !! m_wvl_denspot
4 : !!
5 : !! FUNCTION
6 : !!
7 : !!
8 : !! COPYRIGHT
9 : !! Copyright (C) 2008-2026 ABINIT group (DC)
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_wvl_denspot
23 :
24 : use defs_basis
25 : use m_errors
26 : use m_abicore
27 : use m_xmpi
28 :
29 : use defs_datatypes, only : pseudopotential_gth_type
30 : use m_geometry, only : xred2xcart
31 :
32 : implicit none
33 :
34 : private
35 : !!***
36 :
37 : public :: wvl_denspot_set
38 : public :: wvl_denspot_free
39 : !!***
40 :
41 : contains
42 : !!***
43 :
44 : !!****f* ABINIT/wvl_denspot_set
45 : !! NAME
46 : !! wvl_denspot_set
47 : !!
48 : !! FUNCTION
49 : !! Fill in denspot datatype with information related
50 : !! to density and potential data.
51 : !!
52 : !! INPUTS
53 : !! argin(sizein)=description
54 : !!
55 : !! OUTPUT
56 : !! argout(sizeout)=description
57 : !!
58 : !! SIDE EFFECTS
59 : !!
60 : !! NOTES
61 : !!
62 : !! SOURCE
63 :
64 0 : subroutine wvl_denspot_set(den,gth_params,ixc,natom,nsppol,rprimd,wvl,&
65 0 : & wvl_crmult,wvl_frmult,wvl_mpi_comm,xred)
66 :
67 : use defs_wvltypes
68 :
69 : #if defined HAVE_BIGDFT
70 : use BigDFT_API,only: initialize_DFT_local_fields,allocateRhoPot, &
71 : & input_variables,dpbox_set,density_descriptors
72 : #endif
73 :
74 : !Arguments ------------------------------------
75 : integer,intent(in):: ixc,natom,nsppol,wvl_mpi_comm
76 : real(dp), intent(in) :: rprimd(3, 3)
77 : real(dp), intent(in) :: wvl_frmult,wvl_crmult
78 : real(dp), intent(inout) :: xred(3,natom)
79 : type(wvl_denspot_type), intent(out) :: den
80 : type(wvl_internal_type),intent(in) :: wvl
81 : type(pseudopotential_gth_type),intent(in)::gth_params
82 :
83 : !Local variables-------------------------------
84 : #if defined HAVE_BIGDFT
85 : integer :: groupsize,me,nproc
86 : real(dp), allocatable :: xcart(:,:)
87 : character(len=3),parameter :: rho_commun='DBL'
88 : character(len=500) :: message
89 : character(len=4) :: SICapproach
90 : type(local_zone_descriptors) :: Lzd
91 : #endif
92 :
93 : ! *************************************************************************
94 :
95 : !DEBUG
96 : !write (std_out,*) ' wvl_denspot_set : enter'
97 : !ENDDEBUG
98 :
99 : #if defined HAVE_BIGDFT
100 :
101 : write(message, '(a,a)' ) ch10,&
102 : & ' wvl_denspot_set: Create wavelet type denspot.'
103 : call wrtout(std_out,message,'COLL')
104 :
105 : nproc=xmpi_comm_size(wvl_mpi_comm)
106 : me=xmpi_comm_rank(wvl_mpi_comm)
107 : groupsize=0
108 :
109 : !Store xcart for each atom
110 : ABI_MALLOC(xcart,(3, natom))
111 : call xred2xcart(natom, rprimd, xcart, xred)
112 :
113 : call initialize_DFT_local_fields(den%denspot, ixc, nsppol)
114 :
115 : !number of planes for the density
116 : !dpbox%nscatterarr(jproc, 1) = ngfft3_density
117 : !number of planes for the potential
118 : !dpbox%nscatterarr(jproc, 2) = ngfft3_potential
119 : !starting offset for the potential
120 : !dpbox%nscatterarr(jproc, 3) = density_start + potential_shift - 1
121 : !GGA XC shift between density and potential
122 : !dpbox%nscatterarr(jproc, 4) = potential_shift
123 :
124 : SICapproach="NONE"
125 : Lzd%hgrids(1:3)=wvl%h(1:3)
126 : Lzd%Glr%d%n1i=wvl%Glr%d%n1i
127 : Lzd%Glr%d%n2i=wvl%Glr%d%n2i
128 : Lzd%Glr%d%n3i=wvl%Glr%d%n3i
129 : call dpbox_set(den%denspot%dpbox,Lzd,den%denspot%xc,me,nproc,wvl_mpi_comm,groupsize,&
130 : & SICapproach,wvl%atoms%astruct%geocode,nsppol)
131 :
132 : !here dpbox can be put as input
133 : call density_descriptors(me,nproc,den%denspot%xc,nsppol,wvl_crmult,wvl_frmult,wvl%atoms,&
134 : den%denspot%dpbox,rho_commun,xcart,gth_params%radii_cf,den%denspot%rhod)
135 :
136 : !Note: change allocateRhoPot
137 : call allocateRhoPot(wvl%Glr,nsppol,wvl%atoms,xcart,den%denspot)
138 :
139 : !Aditional information.
140 : den%symObj = wvl%atoms%astruct%sym%symObj
141 :
142 : ABI_FREE(xcart)
143 :
144 : #else
145 0 : BIGDFT_NOTENABLED_ERROR()
146 : if (.false.) write(std_out,*) ixc,natom,nsppol,wvl_mpi_comm,rprimd(1,1),wvl_frmult,wvl_crmult,&
147 : & xred(1,1),den%symObj,wvl%h(1),gth_params%psppar
148 : #endif
149 :
150 : !DEBUG
151 : !write (std_out,*) ' wvl_denspot_set : exit'
152 : !ENDDEBUG
153 :
154 0 : end subroutine wvl_denspot_set
155 : !!***
156 :
157 : !!****f* ABINIT/wvl_denspot_free
158 : !! NAME
159 : !! wvl_denspot_free
160 : !!
161 : !! FUNCTION
162 : !!
163 : !! INPUTS
164 : !!
165 : !! OUTPUT
166 : !!
167 : !! SOURCE
168 :
169 0 : subroutine wvl_denspot_free(den)
170 :
171 : use defs_wvltypes
172 : #if defined HAVE_BIGDFT
173 : use BigDFT_API, only: deallocate_rho_descriptors, &
174 : & deallocate_denspot_distribution, denspot_free_history
175 : use dynamic_memory
176 : #endif
177 :
178 : !Arguments ------------------------------------
179 : type(wvl_denspot_type), intent(inout) :: den
180 :
181 : !Local variables-------------------------------
182 :
183 : ! *************************************************************************
184 :
185 : !DEBUG
186 : !write (std_out,*) ' wvl_denspot_free : enter'
187 : !ENDDEBUG
188 :
189 : #if defined HAVE_BIGDFT
190 : if(associated(den%denspot%rhov)) then
191 : call f_free_ptr(den%denspot%rhov)
192 : end if
193 : if(associated(den%denspot%rho_psi)) then
194 : call f_free_ptr(den%denspot%rho_psi)
195 : end if
196 : if(associated(den%denspot%rho_C)) then
197 : call f_free_ptr(den%denspot%rho_C)
198 : end if
199 : if(associated(den%denspot%V_ext)) then
200 : call f_free_ptr(den%denspot%V_ext)
201 : end if
202 : if(associated(den%denspot%V_XC)) then
203 : call f_free_ptr(den%denspot%V_XC)
204 : end if
205 : if(associated(den%denspot%Vloc_KS)) then
206 : call f_free_ptr(den%denspot%Vloc_KS)
207 : end if
208 : if(associated(den%denspot%f_XC)) then
209 : call f_free_ptr(den%denspot%f_XC)
210 : end if
211 : if(associated(den%denspot%rho_work)) then
212 : call f_free_ptr(den%denspot%rho_work)
213 : end if
214 : if(associated(den%denspot%pot_work)) then
215 : call f_free_ptr(den%denspot%pot_work)
216 : end if
217 : nullify(den%denspot%rhov)
218 : nullify(den%denspot%rho_psi)
219 : nullify(den%denspot%rho_C)
220 : nullify(den%denspot%V_ext)
221 : nullify(den%denspot%V_XC)
222 : nullify(den%denspot%Vloc_KS)
223 : nullify(den%denspot%f_XC)
224 : nullify(den%denspot%rho_work)
225 : nullify(den%denspot%pot_work)
226 : !
227 : call deallocate_rho_descriptors(den%denspot%rhod)
228 : call deallocate_denspot_distribution(den%denspot%dpbox)
229 : call denspot_free_history(den%denspot)
230 : #else
231 0 : BIGDFT_NOTENABLED_ERROR()
232 : if (.false.) write(std_out,*) den%symObj
233 : #endif
234 :
235 0 : end subroutine wvl_denspot_free
236 : !!***
237 :
238 : end module m_wvl_denspot
239 : !!***
|