Line data Source code
1 : !!****m* ABINIT/m_primitive_potential_list
2 : !! NAME
3 : !! m_primitive_potential_list
4 : !!
5 : !! FUNCTION
6 : !! This module define the primitive potential list type, which is a list of primitive potentials
7 : !!
8 : !! Datatypes:
9 : !! primitive_potential_list_t
10 : !!
11 : !! Subroutines:
12 : !!
13 : !! * fill_supercell: use translation symmetry to fill the supercell.
14 : !! * load_from_file: load potential from file.
15 : !! * save_to_file: save to file.
16 : !!
17 : !! COPYRIGHT
18 : !! Copyright (C) 2001-2026 ABINIT group (hexu)
19 : !! This file is distributed under the terms of the
20 : !! GNU General Public License, see ~abinit/COPYING
21 : !! or http://www.gnu.org/copyleft/gpl.txt .
22 : !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt .
23 : !!
24 : !! SOURCE
25 :
26 :
27 : #if defined HAVE_CONFIG_H
28 : #include "config.h"
29 : #endif
30 : #include "abi_common.h"
31 :
32 : module m_primitive_potential_list
33 : use defs_basis
34 : use m_abicore
35 : use m_errors
36 : use m_xmpi
37 :
38 : use m_mpi_scheduler, only: init_mpi_info
39 : use m_multibinit_dataset , only: multibinit_dtset_type
40 : !use m_multibinit_cell, only: mbcell_t
41 : use m_supercell_maker, only: supercell_maker_t
42 : use m_abstract_potential, only: abstract_potential_t
43 : use m_potential_list, only: potential_list_t
44 : use m_primitive_potential, only: primitive_potential_t
45 : use m_multibinit_cell, only: mbsupercell_t
46 : implicit none
47 : private
48 : !!***
49 :
50 : !-------------------------------------------------------------------!
51 : ! primitve_potential_pointer_t
52 : !-------------------------------------------------------------------!
53 : type, public:: primitive_potential_pointer_t ! pointer to effpot
54 : class(primitive_potential_t), pointer :: obj=>null()
55 : end type primitive_potential_pointer_t
56 :
57 :
58 : !-------------------------------------------------------------------!
59 : ! primitive_potential_list_t
60 : ! abstract type for primitive potential list
61 : !-------------------------------------------------------------------!
62 : type, public, extends(primitive_potential_t):: primitive_potential_list_t
63 : type(primitive_potential_pointer_t), allocatable :: data(:) ! list of pointer type
64 : integer :: size=0 ! number of components.
65 : integer :: capacity=0 ! number of slots allocated for saving the pointers.
66 : contains
67 : procedure :: initialize
68 : procedure :: append
69 : procedure :: load_from_files
70 : procedure :: fill_supercell
71 : procedure :: fill_supercell_list
72 : procedure:: finalize
73 : end type primitive_potential_list_t
74 : contains
75 :
76 : !-------------------------------------------------------------------!
77 : ! fill supercell:
78 : !-------------------------------------------------------------------!
79 0 : subroutine fill_supercell(self, scmaker, params, scpot, supercell)
80 : class(primitive_potential_list_t), intent(inout) :: self
81 : type(supercell_maker_t), intent(inout) :: scmaker
82 : type(multibinit_dtset_type), intent(inout) :: params
83 : class(abstract_potential_t), pointer, intent(inout) :: scpot
84 : type(mbsupercell_t), target :: supercell
85 : ! Note that sc_pot is a pointer
86 : ! use a pointer to the specific potential which will be filled
87 : ! e.g. type(spin_potential_t), pointer :: tmp
88 : type(abstract_potential_t), pointer :: tmp
89 0 : ABI_MALLOC_TYPE_SCALAR(abstract_potential_t, tmp)
90 : !call tmp%initialize(....)
91 : ! set tmp
92 0 : ABI_UNUSED_A(self)
93 0 : ABI_UNUSED_A(scmaker)
94 0 : ABI_UNUSED_A(params)
95 0 : ABI_UNUSED_A(scpot)
96 0 : ABI_UNUSED_A(supercell)
97 0 : nullify(tmp)
98 0 : end subroutine fill_supercell
99 :
100 : !-------------------------------------------------------------------!
101 : ! load primitive potential from file
102 : !-------------------------------------------------------------------!
103 0 : subroutine load_from_files(self, params, fnames)
104 : class(primitive_potential_list_t), intent(inout) :: self
105 : type(multibinit_dtset_type), intent(in) :: params
106 : character(len=fnlen), intent(in) :: fnames(:)
107 0 : ABI_UNUSED_A(self)
108 0 : ABI_UNUSED_A(params)
109 0 : ABI_UNUSED_A(fnames)
110 :
111 :
112 0 : end subroutine load_from_files
113 :
114 : !-------------------------------------------------------------------!
115 : ! save primitive potential to file
116 : !-------------------------------------------------------------------!
117 : subroutine save_to_file(self, fname)
118 : class(primitive_potential_list_t), intent(inout) :: self
119 : character(len=fnlen), intent(in) :: fname
120 : ABI_UNUSED_A(self)
121 : ABI_UNUSED_A(fname)
122 :
123 : end subroutine save_to_file
124 :
125 :
126 : !-------------------------------------------------------------------!
127 : ! Initialize
128 : !-------------------------------------------------------------------!
129 6 : subroutine initialize(self)
130 : class(primitive_potential_list_t), intent(inout):: self
131 6 : self%label="ListPotential"
132 6 : self%size=0
133 6 : self%capacity=0
134 6 : end subroutine initialize
135 :
136 : !----------------------------------------------------------------------
137 : !> @brief finalize, all the pots in the list will also be finalized.
138 : !> and the pointers will be nullified.
139 : !----------------------------------------------------------------------
140 12 : subroutine finalize(self)
141 : class(primitive_potential_list_t), intent(inout):: self
142 : integer :: i
143 :
144 : integer :: master, my_rank, comm, nproc, ierr
145 : logical :: iam_master
146 6 : call init_mpi_info(master, iam_master, my_rank, comm, nproc)
147 :
148 6 : call xmpi_bcast(self%size, master, comm, ierr)
149 16 : do i=1, self%size
150 10 : call self%data(i)%obj%finalize()
151 10 : if(associated(self%data(i)%obj)) then
152 20 : ABI_FREE(self%data(i)%obj)
153 : endif
154 16 : nullify(self%data(i)%obj)
155 : end do
156 6 : if(allocated(self%data)) then
157 6 : ABI_FREE(self%data)
158 : end if
159 6 : nullify(self%primcell)
160 6 : self%size=0
161 6 : self%capacity=0
162 6 : self%has_displacement=.False.
163 6 : self%has_strain=.False.
164 6 : self%has_spin=.False.
165 6 : self%has_lwf=.False.
166 6 : end subroutine finalize
167 :
168 : !----------------------------------------------------------------------
169 : !> @brief append a potential to the list
170 : !> The meta data will be updated accordingly.
171 : !> @param[in] input
172 : !> @param[out] output
173 : !----------------------------------------------------------------------
174 10 : subroutine append(self, pot)
175 : class(primitive_potential_list_t), intent(inout):: self
176 : class(primitive_potential_t), target, intent(inout) :: pot
177 10 : type(primitive_potential_pointer_t), allocatable :: temp(:)
178 : integer :: master, my_rank, comm, nproc, ierr
179 : logical :: iam_master
180 10 : call init_mpi_info(master, iam_master, my_rank, comm, nproc)
181 :
182 10 : self%size=self%size + 1
183 10 : if(self%size==1) then
184 6 : self%capacity=8
185 54 : ABI_MALLOC(self%data, (self%capacity))
186 4 : else if ( self%size>self%capacity ) then
187 0 : self%capacity = self%size + self%size / 4 + 8
188 0 : ABI_MALLOC(temp, (self%capacity))
189 0 : temp(1:self%size-1) = self%data(:)
190 0 : ABI_MOVE_ALLOC(temp, self%data) !temp gets deallocated
191 : end if
192 :
193 10 : call xmpi_barrier(comm)
194 10 : self%data(self%size)%obj=>pot
195 10 : self%has_spin= (self%has_spin .or. pot%has_spin)
196 10 : self%has_displacement= (self%has_displacement .or. pot%has_displacement)
197 10 : self%has_strain= (self%has_strain.or. pot%has_strain)
198 10 : self%has_lwf= (self%has_lwf.or. pot%has_lwf)
199 10 : call xmpi_bcast(self%size, master, comm, ierr)
200 10 : call xmpi_bcast(self%capacity, master, comm, ierr)
201 10 : call xmpi_bcast(self%has_spin, master, comm, ierr)
202 10 : call xmpi_bcast(self%has_displacement, master, comm, ierr)
203 10 : call xmpi_bcast(self%has_strain, master, comm, ierr)
204 10 : call xmpi_bcast(self%has_lwf, master, comm, ierr)
205 :
206 10 : end subroutine append
207 :
208 :
209 : !----------------------------------------------------------------------
210 : !> @brief build supercell potential for every component in the list
211 : !> Here sc_pot is an pointer.
212 : !> @param[in] sc_maker: the helper class for uilder supercell
213 : !> @param[out] sc_pots: the potential list of supercell pots.
214 : !----------------------------------------------------------------------
215 : subroutine fill_supercell_ptr(self, sc_maker, params, sc_pot, supercell)
216 : class(primitive_potential_list_t), intent(inout) :: self
217 : type(supercell_maker_t), intent(inout) :: sc_maker
218 : type(multibinit_dtset_type), intent(inout) :: params
219 : class(abstract_potential_t), pointer, intent(inout) :: sc_pot
220 : type(mbsupercell_t), target :: supercell
221 :
222 : ! Note that sc_pot is a pointer
223 : ! use a pointer to the specific potential which will be filled
224 : type(potential_list_t), pointer :: tmp
225 : ABI_MALLOC_SCALAR(tmp)
226 : call self%fill_supercell_list( sc_maker, params, tmp, supercell)
227 : sc_pot=>tmp
228 : nullify(tmp)
229 : end subroutine fill_supercell_ptr
230 :
231 : !----------------------------------------------------------------------
232 : !> @brief build supercell potential for every component in the list
233 : !>
234 : !> @param[in] sc_maker: the helper class for uilder supercell
235 : !> @param[out] sc_pots: the potential list of supercell pots.
236 : !----------------------------------------------------------------------
237 6 : subroutine fill_supercell_list(self, sc_maker, params, sc_pots, supercell)
238 : class(primitive_potential_list_t), intent(inout) :: self
239 : type(supercell_maker_t), intent(inout) :: sc_maker
240 : type(multibinit_dtset_type), intent(inout) :: params
241 : type(potential_list_t), intent(inout) :: sc_pots
242 : type(mbsupercell_t), target :: supercell
243 :
244 : ! Note that sc_pot is a pointer
245 : ! use a pointer to the specific potential which will be filled
246 : class(abstract_potential_t), pointer :: tmp
247 : integer :: i
248 6 : tmp=>null()
249 16 : do i =1, self%size
250 10 : call self%data(i)%obj%fill_supercell(sc_maker, params, tmp, supercell)
251 16 : call sc_pots%append(tmp)
252 : end do
253 :
254 6 : ABI_UNUSED_A(params)
255 :
256 6 : end subroutine fill_supercell_list
257 :
258 0 : end module m_primitive_potential_list
259 :
|