ddx 1.0.0
Libary for domain-decomposition methods for polarizable continuum models
ddx_parameters.f90
Go to the documentation of this file.
1
13
16! Include compile-time definitions
18use ddx_errors
19! Enable OpenMP
20use omp_lib
21implicit none
22
23
27 integer :: model
29 integer :: force
31 real(dp) :: eps
33 real(dp) :: kappa
35 real(dp) :: eta
38 real(dp) :: se
40 integer :: lmax
42 integer :: ngrid
44 integer :: maxiter
47 integer :: jacobi_ndiis
49 integer :: fmm
52 integer :: pm
55 integer :: pl
58 integer :: nproc
60 integer :: nsph
62 real(dp), allocatable :: csph(:, :)
64 real(dp), allocatable :: rsph(:)
66 real(dp) :: epsp = 1.0_dp
68 integer :: matvecmem
71 character(len=255) :: output_filename
73 integer :: len_output_filename
75 logical :: verbose
77 integer :: iunit
79 integer :: switching
80end type ddx_params_type
81
82contains
83
123subroutine params_init(model, force, eps, kappa, eta, se, lmax, ngrid, &
124 & matvecmem, maxiter, jacobi_ndiis, fmm, pm, pl, nproc, nsph, &
125 & csph, rsph, output_filename, switching, params, ddx_error)
126 !! Inputs
127 ! Model to use 1 for COSMO, 2 for PCM, 3 for LPB.
128 integer, intent(in) :: model
129 ! Whether computing analytical forces will be required (1) or not (0).
130 integer, intent(in) :: force
131 ! Relative dielectric permittivity.
132 real(dp), intent(in) :: eps
133 ! Debye-H\"{u}ckel parameter. Referenced only in LPB model (model=3)
134 real(dp), intent(in) :: kappa
135 ! Regularization parameter.
136 real(dp), intent(in) :: eta
137 ! Shift of the regularization. -1 for interior, 0 for centered and
138 ! 1 for outer regularization.
139 real(dp), intent(in) :: se
140 ! Maximal degree of modeling spherical harmonics.
141 integer, intent(in) :: lmax
142 ! Number of Lebedev grid points on each sphere.
143 integer, intent(in) :: ngrid
144 ! handling of sparse matrix. 1 for precomputing them and keeping them in
145 ! memory, 0 for assembling the mvps on-the-fly.
146 integer, intent(in) :: matvecmem
147 ! Maximum number of iterations for the iterative solver.
148 integer, intent(in) :: maxiter
149 ! Number of extrapolation points for Jacobi/DIIS solver. Referenced only
150 ! if Jacobi solver is used.
151 integer, intent(in) :: jacobi_ndiis
152 ! Enable (1) or disable (0) use of FMM techniques.
153 integer, intent(in) :: fmm
154 ! Maximal degree of spherical harmonics for a multipole expansion.
155 !
156 ! If this value is -1 then no far-field FMM interactions are performed.
157 integer, intent(in) :: pm
158 ! Maximal degree of spherical harmonics for a local expansion.
159 !
160 ! If this value is -1 then no far-field FMM interactions are performed.
161 integer, intent(in) :: pl
162 ! Number of OpenMP threads to be used.
163 integer, intent(in) :: nproc
164 ! Number of atoms in the molecule.
165 integer, intent(in) :: nsph
166 ! Centers of atoms of a dimension (3, nsph).
167 real(dp), intent(in) :: csph(3, nsph)
168 ! Array of radii of atoms of a dimension (nsph).
169 real(dp), intent(in) :: rsph(nsph)
170 ! log file name
171 character(len=255) :: output_filename
172 ! switching: kind of switching, 0 legacy, 1 new version.
173 integer, intent(in) :: switching
174 !! Outputs
175 type(ddx_params_type), intent(out) :: params
176 type(ddx_error_type), intent(inout) :: ddx_error
177 !! Local variables
178 integer :: igrid, i, info
179 !! The code
180 if (ddx_error % flag .ne. 0) then
181 call update_error(ddx_error, "params_init received input in ddx_error " // &
182 & " state, exiting")
183 end if
184 ! parse the log file name
185 if (len(trim(output_filename)) .ne. 0) then
186 params % output_filename = output_filename
187 params % verbose = .true.
188 params % len_output_filename = len(trim(output_filename))
189 else
190 params % output_filename = ''
191 params % verbose = .false.
192 params % len_output_filename = 0
193 end if
194 ! Model, 1=COSMO, 2=PCM, 3=LPB
195 if ((model .lt. 1) .or. (model .gt. 3)) then
196 call update_error(ddx_error, "params_init: invalid value of `model`")
197 end if
198 params % model = model
199 ! Check if forces are needed
200 if ((force .lt. 0) .or. (force .gt. 1)) then
201 call update_error(ddx_error, "params_init: invalid value of `force`")
202 end if
203 params % force = force
204 ! Relative dielectric permittivity
205 if (eps .le. one) then
206 call update_error(ddx_error, "params_init: invalid value of `eps`")
207 end if
208 params % eps = eps
209 ! Debye-H\"{u}ckel parameter (only used in ddLPB)
210 if ((model .eq. 3) .and. (kappa .le. zero)) then
211 call update_error(ddx_error, "params_init: invalid value of `kappa`")
212 end if
213 params % kappa = kappa
214 ! Regularization parameter
215 if ((eta .lt. zero) .or. (eta .gt. one)) then
216 call update_error(ddx_error, "params_init: invalid value of `eta`")
217 end if
218 params % eta = eta
219 ! Shift of a regularization
220 if ((se .lt. -one) .or. (se .gt. one)) then
221 call update_error(ddx_error, "params_init: invalid value of `se`")
222 end if
223 params % se = se
224 ! Degree of modeling spherical harmonics
225 if (lmax .lt. 0) then
226 call update_error(ddx_error, "params_init: invalid value of `lmax`")
227 end if
228 params % lmax = lmax
229 ! Check number of Lebedev grid points
230 igrid = 0
231 do i = 1, nllg
232 if (ng0(i) .eq. ngrid) then
233 igrid = i
234 exit
235 end if
236 end do
237 if (igrid .eq. 0) then
238 call update_error(ddx_error, "params_init: Unsupported value of `ngrid`")
239 end if
240 params % ngrid = ngrid
241 ! Maximum number of iterations
242 if (maxiter .le. 0) then
243 call update_error(ddx_error, "params_init: invalid value of `maxiter`")
244 end if
245 params % maxiter = maxiter
246 ! Number of Jacobi DIIS extrapolation points (ndiis=25 works)
247 if (jacobi_ndiis .lt. 0) then
248 call update_error(ddx_error, "params_init: invalid value of `jacobi_ndiis`")
249 end if
250 params % jacobi_ndiis = jacobi_ndiis
251 ! Check if FMM-acceleration is needed
252 if ((fmm .lt. 0) .or. (fmm .gt. 1)) then
253 call update_error(ddx_error, "params_init: invalid value of `fmm`")
254 end if
255 params % fmm = fmm
256 ! Set FMM parameters if FMM is needed
257 if (fmm .eq. 1) then
258 ! Maximal degree of multipole spherical harmonics. Value -1 means no
259 ! far-field interactions are to be computed, only near-field
260 ! interactions are taken into account.
261 if (pm .lt. -1) then
262 call update_error(ddx_error, "params_init: invalid value of `pm`")
263 end if
264 ! Maximal degree of local spherical harmonics. Value -1 means no
265 ! far-field interactions are to be computed, only near-field
266 ! interactions are taken into account.
267 if (pl .lt. -1) then
268 call update_error(ddx_error, "params_init: invalid value of `pl`")
269 end if
270 ! If far-field interactions are to be ignored
271 if ((pl .eq. -1) .or. (pm .eq. -1)) then
272 params % pm = -1
273 params % pl = -1
274 ! If far-field interactions are to be taken into account
275 else
276 params % pm = pm
277 params % pl = pl
278 end if
279 else
280 ! These values are ignored if fmm flag is 0
281 params % pm = -2
282 params % pl = -2
283 end if
284 ! Number of OpenMP threads to be used
285 ! available.
286 if (nproc .lt. 0) then
287 call update_error(ddx_error, "params_init: invalid value of `nproc`")
288 params % nproc = 1
289 else if (nproc .eq. 0) then
290 params % nproc = 1
291 else
292 params % nproc = nproc
293 end if
294 call omp_set_num_threads(params % nproc)
295 ! Number of atoms
296 if (nsph .le. 0) then
297 call update_error(ddx_error, "params_init: invalid value of `nsph`")
298 end if
299 params % nsph = nsph
300 allocate(params % csph(3, nsph), params % rsph(nsph), stat=info)
301 if (info .ne. 0) then
302 call update_error(ddx_error, "params_init: `csph` and `rsph` " // &
303 & "allocations failed")
304 return
305 end if
306 params % csph = csph
307 params % rsph = rsph
308 if (matvecmem.eq.0 .or. matvecmem.eq.1) then
309 params % matvecmem = matvecmem
310 else
311 call update_error(ddx_error, "params_init: invalid value of `matvecmem`")
312 end if
313
314 if (switching.eq.0 .or. switching.eq.1) then
315 params % switching = switching
316 else
317 call update_error(ddx_error, "params_init: invalid value of `switching`")
318 end if
319
320 if (ddx_error % flag .ne. 0) return
321
322 ! init log
323 call init_printing(params, ddx_error)
324 if (ddx_error % flag .ne. 0) then
325 call update_error(ddx_error, "init_printing returned an error, exiting")
326 return
327 end if
328end subroutine params_init
329
335 integer, intent(inout) :: ngrid
336 integer :: igrid, i, inear, jnear
337 ! Get nearest number of Lebedev grid points
338 igrid = 0
339 inear = 100000
340 do i = 1, nllg
341 jnear = abs(ng0(i) - ngrid)
342 if (jnear .lt. inear) then
343 inear = jnear
344 igrid = i
345 end if
346 end do
347 ngrid = ng0(igrid)
348end subroutine
349
355subroutine params_free(params, ddx_error)
356 implicit none
357 type(ddx_params_type), intent(inout) :: params
358 type(ddx_error_type), intent(inout) :: ddx_error
359 integer :: istat
360
361 call finalize_printing(params)
362
363 if (allocated(params % csph)) then
364 deallocate(params % csph, stat=istat)
365 if (istat .ne. 0) then
366 call update_error(ddx_error, "params_free: `csph` deallocation failed")
367 end if
368 end if
369 if (allocated(params % rsph)) then
370 deallocate(params % rsph, stat=istat)
371 if (istat .ne. 0) then
372 call update_error(ddx_error, "params_free: `rsph` deallocation failed")
373 end if
374 end if
375end subroutine params_free
376
378subroutine init_printing(params, ddx_error)
379 implicit none
380 type(ddx_params_type), intent(inout) :: params
381 type(ddx_error_type), intent(inout) :: ddx_error
382 logical :: exists
383 if (.not.params % verbose) return
384 inquire(file=params % output_filename(1:params % len_output_filename), &
385 & exist=exists)
386 if (exists) then
387 call update_error(ddx_error, 'Log file already present')
388 return
389 else
390 params % iunit = 100
391 open(params % iunit, &
392 & file=params % output_filename(1: params % len_output_filename), &
393 & form='formatted')
394 end if
395end subroutine init_printing
396
398subroutine finalize_printing(params)
399 implicit none
400 type(ddx_params_type), intent(inout) :: params
401 if (.not.params % verbose) return
402 close(params % iunit)
403 params % verbose = .false.
404 params % output_filename = ''
405 params % len_output_filename = 0
406 params % iunit = 0
407end subroutine finalize_printing
408
409end module ddx_parameters
Compile-time constants and definitions.
integer, dimension(nllg), parameter ng0
Number of grid points of each Lebedev grid.
integer, parameter dp
Kind of double precision.
integer, parameter nllg
Number of supported Lebedev grids.
Module to treat properly user input parameters.
subroutine closest_supported_lebedev_grid(ngrid)
Adjust a guess for the number of Lebedev grid points.
subroutine init_printing(params, ddx_error)
Open the log file.
subroutine finalize_printing(params)
Close the log file.
subroutine params_free(params, ddx_error)
Deallocate the parameter object.
subroutine params_init(model, force, eps, kappa, eta, se, lmax, ngrid, matvecmem, maxiter, jacobi_ndiis, fmm, pm, pl, nproc, nsph, csph, rsph, output_filename, switching, params, ddx_error)
Initialize and check input parameters.
ddX type for containing ddx_error information
Definition: ddx_errors.f90:6
Type to check and store user input parameters.