Octopus
poisson.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2011 M. Marques, A. Castro, A. Rubio,
2!! G. Bertsch, M. Oliveira
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
22module poisson_oct_m
23 use accel_oct_m
24 use batch_oct_m
27 use cube_oct_m
29 use debug_oct_m
31 use fft_oct_m
33 use global_oct_m
34 use index_oct_m
35 use, intrinsic :: iso_fortran_env
38 use math_oct_m
39 use mesh_oct_m
43 use mpi_oct_m
46#ifdef HAVE_OPENMP
47 use omp_lib
48#endif
50 use parser_oct_m
62 use space_oct_m
65 use types_oct_m
68 use xc_cam_oct_m
69
70 implicit none
71
72 private
73 public :: &
74 poisson_t, &
103
104 integer, public, parameter :: &
105 POISSON_DIRECT_SUM = -1, &
106 poisson_fft = 0, &
107 poisson_cg = 5, &
109 poisson_multigrid = 7, &
110 poisson_isf = 8, &
111 poisson_psolver = 10, &
112 poisson_nfft = option__poissonsolver__nfft, &
113 poisson_no = -99, &
114 poisson_null = -999
115
116 type poisson_t
117 private
118 type(derivatives_t), pointer, public :: der
119 integer, public :: method = poisson_null
120 integer, public :: kernel
121 type(cube_t), public :: cube
122 type(mesh_cube_parallel_map_t), public :: mesh_cube_map
123 type(poisson_mg_solver_t) :: mg
124 type(poisson_fft_t), public :: fft_solver
125 real(real64), public :: poisson_soft_coulomb_param
126 logical :: all_nodes_default
127 type(poisson_corr_t) :: corrector
128 type(poisson_isf_t) :: isf_solver
129 type(poisson_psolver_t) :: psolver_solver
130 type(poisson_no_t) :: no_solver
131 type(poisson_nfft_t) :: nfft_solver
132 integer :: nslaves
133 logical, public :: is_dressed = .false.
134 type(photon_mode_t), public :: photons
135#ifdef HAVE_MPI
136 type(MPI_Comm) :: intercomm
137 type(mpi_grp_t) :: local_grp
138 logical :: root
139#endif
140 end type poisson_t
141
142 integer, parameter :: &
143 CMD_FINISH = 1, &
145
146contains
147
148 !-----------------------------------------------------------------
149 subroutine poisson_init(this, namespace, space, der, mc, stencil, qtot, label, solver, verbose, force_serial, &
150 force_cmplx, fft_library, fft_batch_size, single_precision)
151 type(poisson_t), intent(inout) :: this
152 class(space_t), intent(in) :: space
153 type(namespace_t), intent(in) :: namespace
154 type(derivatives_t), target, intent(in) :: der
155 type(multicomm_t), intent(in) :: mc
156 type(stencil_t), intent(in) :: stencil
157 real(real64), optional, intent(in) :: qtot
158 character(len=*), optional, intent(in) :: label
159 integer, optional, intent(in) :: solver
160 logical, optional, intent(in) :: verbose
161 logical, optional, intent(in) :: force_serial
162 logical, optional, intent(in) :: force_cmplx
163 integer, optional, intent(in) :: fft_library
164 integer, optional, intent(in) :: fft_batch_size
165 logical, optional, intent(in) :: single_precision
166
167 logical :: need_cube, isf_data_is_parallel, anisotropic_spacing
168 integer :: default_solver, default_kernel, box(space%dim), fft_type, library, fft_bs
169 real(real64) :: fft_alpha
170 character(len=60) :: str
171 real(real64), parameter :: tol_spacing = 1e-10_real64
172
173 ! Make sure we do not try to initialize an already initialized solver
174 assert(this%method == poisson_null)
175
176 push_sub(poisson_init)
177
178 if (optional_default(verbose,.true.)) then
179 str = "Hartree"
180 if (present(label)) str = trim(label)
181 call messages_print_with_emphasis(msg=trim(str), namespace=namespace)
182 end if
183
184 this%nslaves = 0
185 this%der => der
186
187 !%Variable DressedOrbitals
188 !%Type logical
189 !%Default false
190 !%Section Hamiltonian::Poisson
191 !%Description
192 !% Allows for the calculation of coupled elecron-photon problems
193 !% by applying the dressed orbital approach. Details can be found in
194 !% https://arxiv.org/abs/1812.05562
195 !% At the moment, N electrons in d (<=3) spatial dimensions, coupled
196 !% to one photon mode can be described. The photon mode is included by
197 !% raising the orbital dimension to d+1 and changing the particle interaction
198 !% kernel and the local potential, where the former is included automatically,
199 !% but the latter needs to by added by hand as a user_defined_potential!
200 !% Coordinate 1-d: electron; coordinate d+1: photon.
201 !%End
202 call parse_variable(namespace, 'DressedOrbitals', .false., this%is_dressed)
203 call messages_print_var_value('DressedOrbitals', this%is_dressed, namespace=namespace)
204 if (this%is_dressed) then
205 assert(present(qtot))
206 call messages_experimental('Dressed Orbitals', namespace=namespace)
207 assert(qtot > m_zero)
208 call photon_mode_init(this%photons, namespace, der%dim-1, mc%base_grp)
209 call photon_mode_set_n_electrons(this%photons, qtot)
210 if(.not.allocated(this%photons%pol_dipole)) then
211 call photon_mode_compute_dipoles(this%photons, der%mesh)
212 end if
213 if (this%photons%nmodes > 1) then
214 call messages_not_implemented('DressedOrbitals for more than one photon mode', namespace=namespace)
215 end if
216 end if
217
218 this%all_nodes_default = .false.
219#ifdef HAVE_MPI
220 if (.not. optional_default(force_serial, .false.)) then
221 !%Variable ParallelizationPoissonAllNodes
222 !%Type logical
223 !%Default true
224 !%Section Execution::Parallelization
225 !%Description
226 !% When running in parallel, this variable selects whether the
227 !% Poisson solver should divide the work among all nodes or only
228 !% among the parallelization-in-domains groups.
229 !%End
230
231 call parse_variable(namespace, 'ParallelizationPoissonAllNodes', .true., this%all_nodes_default)
232 end if
233#endif
234
235 !%Variable PoissonSolver
236 !%Type integer
237 !%Section Hamiltonian::Poisson
238 !%Description
239 !% Defines which method to use to solve the Poisson equation. Some incompatibilities apply depending on
240 !% dimensionality, periodicity, etc.
241 !% For a comparison of the accuracy and performance of the methods in Octopus, see P Garcia-Risue&ntilde;o,
242 !% J Alberdi-Rodriguez <i>et al.</i>, <i>J. Comp. Chem.</i> <b>35</b>, 427-444 (2014)
243 !% or <a href=http://arxiv.org/abs/1211.2092>arXiV</a>.
244 !% Defaults:
245 !% <br> 1D and 2D: <tt>fft</tt>.
246 !% <br> 3D: <tt>cg_corrected</tt> if curvilinear, <tt>isf</tt> if not periodic, <tt>fft</tt> if periodic.
247 !% <br> Dressed orbitals: <tt>direct_sum</tt>.
248 !%Option NoPoisson -99
249 !% Do not use a Poisson solver at all.
250 !%Option direct_sum -1
251 !% Direct evaluation of the Hartree potential (only for finite systems).
252 !%Option fft 0
253 !% The Poisson equation is solved using FFTs. A cutoff technique
254 !% for the Poisson kernel is selected so the proper boundary
255 !% conditions are imposed according to the periodicity of the
256 !% system. This can be overridden by the <tt>PoissonFFTKernel</tt>
257 !% variable. To choose the FFT library use <tt>FFTLibrary</tt>
258 !%Option cg 5
259 !% Conjugate gradients.
260 !%Option cg_corrected 6
261 !% Conjugate gradients, corrected for boundary conditions (only for finite systems).
262 !%Option multigrid 7
263 !% Multigrid method.
264 !%Option isf 8
265 !% Interpolating Scaling Functions Poisson solver (only for finite systems).
266 !%Option psolver 10
267 !% Solver based on Interpolating Scaling Functions as implemented in the PSolver library.
268 !% Parallelization in k-points requires <tt>PoissonSolverPSolverParallelData</tt> = no.
269 !% Requires the PSolver external library.
270 !%Option nfft
271 !% (experimental) The Poisson equation is solved in Fourier space with the mesh points
272 !% as the non-equispaced nodes of a FINUFFT transform, which needs no cube and takes a
273 !% curvilinear mesh as it stands. Only for finite 3D systems. Requires FINUFFT.
274 !%End
275
276 default_solver = poisson_fft
277
278 if (space%dim == 3 .and. .not. space%is_periodic()) default_solver = poisson_isf
279
280 ! The ISF (and BigDFT PSolver) kernels are built for a single, uniform grid
281 ! spacing: on an anisotropic grid they silently use spacing(1) for every
282 ! direction and return a wrong Hartree potential. The FFT solver handles
283 ! anisotropic spacing correctly, so fall back to it for the default.
284 anisotropic_spacing = any(abs(der%mesh%spacing(1:space%dim) - der%mesh%spacing(1)) > tol_spacing)
285 if (default_solver == poisson_isf .and. anisotropic_spacing) default_solver = poisson_fft
286
287#ifdef HAVE_CUDA
288 if(accel_is_enabled()) default_solver = poisson_fft
289#endif
290
291 if (space%dim > 3) default_solver = poisson_no ! Kernel for higher dimensions is not implemented.
292
293 if (der%mesh%use_curvilinear) then
294 select case (space%dim)
295 case (1)
296 default_solver = poisson_direct_sum
297 case (2)
298 default_solver = poisson_direct_sum
299 case (3)
300 default_solver = poisson_multigrid
301 end select
302 end if
303
304 if (this%is_dressed) default_solver = poisson_direct_sum
305
306 if (.not. present(solver)) then
307 call parse_variable(namespace, 'PoissonSolver', default_solver, this%method)
308 else
309 this%method = solver
310 end if
311 if (.not. varinfo_valid_option('PoissonSolver', this%method)) call messages_input_error(namespace, 'PoissonSolver')
312 if (optional_default(verbose, .true.)) then
313 select case (this%method)
314 case (poisson_direct_sum)
315 str = "direct sum"
316 case (poisson_fft)
317 str = "fast Fourier transform"
318 case (poisson_cg)
319 str = "conjugate gradients"
321 str = "conjugate gradients, corrected"
322 case (poisson_multigrid)
323 str = "multigrid"
324 case (poisson_isf)
325 str = "interpolating scaling functions"
326 case (poisson_psolver)
327 str = "interpolating scaling functions (from BigDFT)"
328 case (poisson_nfft)
329 str = "non-equispaced fast Fourier transform"
330 case (poisson_no)
331 str = "no Poisson solver - Hartree set to 0"
332 end select
333 write(message(1),'(a,a,a)') "The chosen Poisson solver is '", trim(str), "'"
334 call messages_info(1, namespace=namespace)
335 end if
336
337 if (space%dim > 3 .and. this%method /= poisson_no) then
338 call messages_input_error(namespace, 'PoissonSolver', 'Currently no Poisson solver is available for Dimensions > 3')
339 end if
340
341 fft_bs = optional_default(fft_batch_size, 1)
342 assert(fft_bs > 0)
343
344 if (this%method /= poisson_fft) then
345 this%kernel = poisson_fft_kernel_none
346 else
347
348 ! Documentation in cube.F90
349 call parse_variable(namespace, 'FFTLibrary', fftlib_fftw, library)
350 if (present(fft_library)) library = fft_library
351
352 !%Variable PoissonFFTKernel
353 !%Type integer
354 !%Section Hamiltonian::Poisson
355 !%Description
356 !% Defines which kernel is used to impose the correct boundary
357 !% conditions when using FFTs to solve the Poisson equation. The
358 !% default is selected depending on the dimensionality and
359 !% periodicity of the system:
360 !% <br>In 1D, <tt>spherical</tt> if finite, <tt>fft_nocut</tt> if periodic.
361 !% <br>In 2D, <tt>spherical</tt> if finite, <tt>cylindrical</tt> if 1D-periodic, <tt>fft_nocut</tt> if 2D-periodic.
362 !% <br>In 3D, <tt>spherical</tt> if finite, <tt>cylindrical</tt> if 1D-periodic, <tt>planar</tt> if 2D-periodic,
363 !% <tt>fft_nocut</tt> if 3D-periodic.
364 !% See C. A. Rozzi et al., <i>Phys. Rev. B</i> <b>73</b>, 205119 (2006) for 3D implementation and
365 !% A. Castro et al., <i>Phys. Rev. B</i> <b>80</b>, 033102 (2009) for 2D implementation.
366 !%Option spherical 0
367 !% FFTs using spherical cutoff (in 2D or 3D).
368 !%Option cylindrical 1
369 !% FFTs using cylindrical cutoff (in 2D or 3D).
370 !%Option planar 2
371 !% FFTs using planar cutoff (in 3D).
372 !%Option fft_nocut 3
373 !% FFTs without using a cutoff (for fully periodic systems).
374 !%Option multipole_correction 4
375 !% The boundary conditions are imposed by using a multipole expansion. Only appropriate for finite systems.
376 !% Further specification occurs with variables <tt>PoissonSolverBoundaries</tt> and <tt>PoissonSolverMaxMultipole</tt>.
377 !%End
378
379 select case (space%dim)
380 case (1)
381 if (.not. space%is_periodic()) then
382 default_kernel = poisson_fft_kernel_sph
383 else
384 default_kernel = poisson_fft_kernel_nocut
385 end if
386 case (2)
387 if (space%periodic_dim == 2) then
388 default_kernel = poisson_fft_kernel_nocut
389 else if (space%is_periodic()) then
390 default_kernel = space%periodic_dim
391 else
392 default_kernel = poisson_fft_kernel_sph
393 end if
394 case (3)
395 default_kernel = space%periodic_dim
396 end select
397
398 call parse_variable(namespace, 'PoissonFFTKernel', default_kernel, this%kernel)
399 if (.not. varinfo_valid_option('PoissonFFTKernel', this%kernel)) call messages_input_error(namespace, 'PoissonFFTKernel')
400
401 if (optional_default(verbose,.true.)) then
402 call messages_print_var_option("PoissonFFTKernel", this%kernel, namespace=namespace)
403 end if
404
405 ! the multipole correction kernel does not work on GPUs
406 if(this%kernel == poisson_fft_kernel_corrected .and. fft_default_lib == fftlib_accel) then
408 message(1) = 'PoissonFFTKernel=multipole_correction is not supported on GPUs'
409 message(2) = 'Using FFTW to compute the FFTs on the CPU'
410 call messages_info(2, namespace=namespace)
411 end if
412
413 end if
414
415 !We assume the developer knows what he is doing by providing the solver option
416 if (.not. present(solver)) then
417 if (space%is_periodic() .and. this%method == poisson_direct_sum) then
418 message(1) = 'A periodic system may not use the direct_sum Poisson solver.'
419 call messages_fatal(1, namespace=namespace)
420 end if
421
422 if (space%is_periodic() .and. this%method == poisson_cg_corrected) then
423 message(1) = 'A periodic system may not use the cg_corrected Poisson solver.'
424 call messages_fatal(1, namespace=namespace)
425 end if
426
427 select case (space%dim)
428 case (1)
429
430 select case (space%periodic_dim)
431 case (0)
432 if ((this%method /= poisson_fft) .and. (this%method /= poisson_direct_sum)) then
433 message(1) = 'A finite 1D system may only use fft or direct_sum Poisson solvers.'
434 call messages_fatal(1, namespace=namespace)
435 end if
436 case (1)
437 if (this%method /= poisson_fft) then
438 message(1) = 'A periodic 1D system may only use the fft Poisson solver.'
439 call messages_fatal(1, namespace=namespace)
440 end if
441 end select
442
443 if (der%mesh%use_curvilinear .and. this%method /= poisson_direct_sum) then
444 message(1) = 'If curvilinear coordinates are used in 1D, then the only working'
445 message(2) = 'Poisson solver is direct_sum.'
446 call messages_fatal(2, namespace=namespace)
447 end if
448
449 case (2)
450
451 if ((this%method /= poisson_fft) .and. (this%method /= poisson_direct_sum)) then
452 message(1) = 'A 2D system may only use fft or direct_sum solvers.'
453 call messages_fatal(1, namespace=namespace)
454 end if
455
456 if (der%mesh%use_curvilinear .and. (this%method /= poisson_direct_sum)) then
457 message(1) = 'If curvilinear coordinates are used in 2D, then the only working'
458 message(2) = 'Poisson solver is direct_sum.'
459 call messages_fatal(2, namespace=namespace)
460 end if
461
462 case (3)
463
464 if (space%is_periodic() .and. this%method == poisson_isf) then
465 call messages_write('The ISF solver can only be used for finite systems.')
466 call messages_fatal()
467 end if
468
469 ! The ISF and PSolver kernels assume a uniform (cubic) grid spacing and
470 ! would silently produce a wrong Hartree potential on an anisotropic grid.
471 if ((this%method == poisson_isf .or. this%method == poisson_psolver) .and. anisotropic_spacing) then
472 message(1) = 'The ISF/PSolver Poisson solver requires a uniform (cubic) grid spacing,'
473 message(2) = 'but the grid has anisotropic spacing. Use PoissonSolver = fft instead.'
474 call messages_fatal(2, namespace=namespace)
475 end if
476
477 if (space%is_periodic() .and. this%method == poisson_fft .and. &
478 this%kernel /= space%periodic_dim .and. this%kernel >= 0 .and. this%kernel <= 3) then
479 write(message(1), '(a,i1,a)')'The system is periodic in ', space%periodic_dim ,' dimension(s),'
480 write(message(2), '(a,i1,a)')'but Poisson solver is set for ', this%kernel, ' dimensions.'
481 call messages_warning(2, namespace=namespace)
482 end if
483
484 if (space%is_periodic() .and. this%method == poisson_fft .and. this%kernel == poisson_fft_kernel_corrected) then
485 write(message(1), '(a,i1,a)')'PoissonFFTKernel = multipole_correction cannot be used for periodic systems.'
486 call messages_fatal(1, namespace=namespace)
487 end if
488
489 if (this%method == poisson_nfft) then
490 call messages_experimental('PoissonSolver = nfft', namespace=namespace)
491 if (space%dim /= 3 .or. space%is_periodic()) then
492 message(1) = 'The nfft Poisson solver is only available for finite 3D systems.'
493 call messages_fatal(1, namespace=namespace)
494 end if
495 end if
496
497 if (der%mesh%use_curvilinear .and. &
498 .not. any(this%method == [poisson_cg_corrected, poisson_multigrid, poisson_nfft])) then
499 message(1) = 'If curvilinear coordinates are used, then the only working'
500 message(2) = 'Poisson solvers are cg_corrected, multigrid and nfft.'
501 call messages_fatal(2, namespace=namespace)
502 end if
503 if (der%mesh%use_curvilinear .and. this%method == poisson_multigrid .and. accel_is_enabled()) then
504 call messages_not_implemented('Multigrid Poisson solver with curvilinear coordinates on GPUs')
505 end if
506
507 select type (box => der%mesh%box)
508 type is (box_minimum_t)
509 if (this%method == poisson_cg_corrected) then
510 message(1) = 'When using the "minimum" box shape and the "cg_corrected"'
511 message(2) = 'Poisson solver, we have observed "sometimes" some non-'
512 message(3) = 'negligible error. You may want to check that the "fft" or "cg"'
513 message(4) = 'solver are providing, in your case, the same results.'
514 call messages_warning(4, namespace=namespace)
515 end if
516 end select
517
518 end select
519 end if
520
521 if (this%method == poisson_psolver) then
522#if !(defined HAVE_PSOLVER)
523 message(1) = "The PSolver Poisson solver cannot be used since the code was not compiled with the PSolver library."
524 call messages_fatal(1, namespace=namespace)
525#endif
526 end if
527
528 if (optional_default(verbose,.true.)) then
529 call messages_print_with_emphasis(namespace=namespace)
530 end if
531
532 ! Now that we know the method, we check if we need a cube and its dimensions
533 need_cube = .false.
534 fft_type = fft_real
535 if (optional_default(force_cmplx, .false.)) fft_type = fft_complex
536
537 if (this%method == poisson_isf .or. this%method == poisson_psolver) then
538 fft_type = fft_none
539 box(:) = der%mesh%idx%ll(:)
540 need_cube = .true.
541 end if
542
543 if (this%method == poisson_psolver .and. multicomm_have_slaves(mc)) then
544 call messages_not_implemented('Task parallelization with PSolver Poisson solver', namespace=namespace)
545 end if
546
548 ! Documentation in poisson_psolver.F90
549 call parse_variable(namespace, 'PoissonSolverPSolverParallelData', .true., isf_data_is_parallel)
550 if (this%method == poisson_psolver .and. isf_data_is_parallel) then
551 call messages_not_implemented("k-point parallelization with PSolver library and", namespace=namespace)
552 call messages_not_implemented("PoissonSolverPSolverParallelData = yes", namespace=namespace)
553 end if
554 if (this%method == poisson_fft .and. library == fftlib_pfft) then
555 call messages_not_implemented("k-point parallelization with PFFT library for", namespace=namespace)
556 call messages_not_implemented("PFFT library for Poisson solver", namespace=namespace)
557 end if
558 end if
559
560 if (this%method == poisson_fft) then
561
562 need_cube = .true.
563
564 !%Variable DoubleFFTParameter
565 !%Type float
566 !%Default 2.0
567 !%Section Mesh::FFTs
568 !%Description
569 !% For solving the Poisson equation in Fourier space, and for applying the local potential
570 !% in Fourier space, an auxiliary cubic mesh is built. This mesh will be larger than
571 !% the circumscribed cube of the usual mesh by a factor <tt>DoubleFFTParameter</tt>. See
572 !% the section that refers to Poisson equation, and to the local potential for details
573 !% [the default value of two is typically good].
574 !%End
575 call parse_variable(namespace, 'DoubleFFTParameter', m_two, fft_alpha)
576 if (fft_alpha < m_one .or. fft_alpha > m_three) then
577 write(message(1), '(a,f12.5,a)') "Input: '", fft_alpha, &
578 "' is not a valid DoubleFFTParameter"
579 message(2) = '1.0 <= DoubleFFTParameter <= 3.0'
580 call messages_fatal(2, namespace=namespace)
581 end if
582
583 if (space%dim /= 3 .and. library == fftlib_pfft) then
584 call messages_not_implemented('PFFT support for dimensionality other than 3', namespace=namespace)
585 end if
586
587 select case (space%dim)
588
589 case (1)
590 select case (this%kernel)
592 call mesh_double_box(space, der%mesh, fft_alpha, box)
594 box = der%mesh%idx%ll
595 end select
596
597 case (2)
598 select case (this%kernel)
600 call mesh_double_box(space, der%mesh, fft_alpha, box)
601 box(1:2) = maxval(box)
603 call mesh_double_box(space, der%mesh, fft_alpha, box)
605 box(:) = der%mesh%idx%ll(:)
606 end select
607
608 case (3)
609 select case (this%kernel)
611 call mesh_double_box(space, der%mesh, fft_alpha, box)
612 box(:) = maxval(box)
614 call mesh_double_box(space, der%mesh, fft_alpha, box)
615 box(2) = maxval(box(2:3)) ! max of finite directions
616 box(3) = maxval(box(2:3)) ! max of finite directions
618 box(:) = der%mesh%idx%ll(:)
620 call mesh_double_box(space, der%mesh, fft_alpha, box)
621 end select
622
623 end select
624
625 end if
626
627 ! Solvers that cannot transform a whole batch at once are applied one function at a time
628 ! (see X(poisson_solve_batch)) and do not need a batched cube.
629 if (.not. poisson_is_batch_capable(this)) fft_bs = 1
630
631 ! Create the cube
632 if (need_cube) then
633 call cube_init(this%cube, box, namespace, space, der%mesh%spacing, &
634 der%mesh%coord_system, fft_type = fft_type, fft_library = fft_library, &
635 need_partition=.not.der%mesh%parallel_in_domains, &
636 batch_size=fft_bs, single=single_precision)
637 call cube_init_cube_map(this%cube, der%mesh)
638 if (this%cube%parallel_in_domains .and. this%method == poisson_fft) then
639 call mesh_cube_parallel_map_init(this%mesh_cube_map, der%mesh, this%cube)
640 end if
641 end if
642
643 if (this%is_dressed .and. .not. this%method == poisson_direct_sum) then
644 write(message(1), '(a)')'Dressed Orbital calculation currently only working with direct sum Poisson solver.'
645 call messages_fatal(1, namespace=namespace)
646 end if
647
648 call poisson_kernel_init(this, namespace, space, mc, stencil)
649
650 pop_sub(poisson_init)
651 end subroutine poisson_init
652
653 !-----------------------------------------------------------------
654 subroutine poisson_end(this)
655 type(poisson_t), intent(inout) :: this
656
657 logical :: has_cube
658
659 push_sub(poisson_end)
660
661 has_cube = .false.
662
663 select case (this%method)
664 case (poisson_fft)
665 call poisson_fft_end(this%fft_solver)
666 if (this%kernel == poisson_fft_kernel_corrected) call poisson_corrections_end(this%corrector)
667 has_cube = .true.
668
670 call poisson_cg_end()
671 call poisson_corrections_end(this%corrector)
672
673 case (poisson_multigrid)
674 call poisson_multigrid_end(this%mg)
675
676 case (poisson_isf)
677 call poisson_isf_end(this%isf_solver)
678 has_cube = .true.
679
680 case (poisson_psolver)
681 call poisson_psolver_end(this%psolver_solver)
682 has_cube = .true.
683
684 case (poisson_nfft)
685 call poisson_nfft_end(this%nfft_solver)
686
687 case (poisson_no)
688 call poisson_no_end(this%no_solver)
689
690 end select
691 this%method = poisson_null
692
693 if (has_cube) then
694 if (this%cube%parallel_in_domains) then
695 call mesh_cube_parallel_map_end(this%mesh_cube_map)
696 end if
697 call cube_end(this%cube)
698 end if
699
700 if (this%is_dressed) then
701 call photon_mode_end(this%photons)
702 end if
703 this%is_dressed = .false.
704
705 pop_sub(poisson_end)
706 end subroutine poisson_end
707
708 !-----------------------------------------------------------------
709
710 subroutine zpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
711 type(poisson_t), intent(in) :: this
712 type(namespace_t), intent(in) :: namespace
713 complex(real64), contiguous, intent(inout) :: pot(:)
714 complex(real64), contiguous, intent(in) :: rho(:)
715 logical, optional, intent(in) :: all_nodes
716 type(fourier_space_op_t), optional, intent(in) :: kernel
717 logical, optional, intent(in) :: reset
718
719 logical :: all_nodes_value
720
721 push_sub(zpoisson_solve)
722
723 all_nodes_value = optional_default(all_nodes, this%all_nodes_default)
724
725 assert(ubound(pot, dim = 1) == this%der%mesh%np_part .or. ubound(pot, dim = 1) == this%der%mesh%np)
726 assert(ubound(rho, dim = 1) == this%der%mesh%np_part .or. ubound(rho, dim = 1) == this%der%mesh%np)
727
728 assert(this%method /= poisson_null)
729
730 if (poisson_solver_is_iterative(this) .and. optional_default(reset, .true.)) then
731 pot(1:this%der%mesh%np) = m_zero
732 end if
733
734 if (poisson_solves_complex_natively(this)) then
735 !We add the profiling here, as the other path uses dpoisson_solve
736 call profiling_in('ZPOISSON_SOLVE')
737 select case (this%method)
738 case (poisson_fft)
739 call zpoisson_fft_solve(this%fft_solver, this%der%mesh, this%cube, pot, rho, this%mesh_cube_map, kernel=kernel)
740 case (poisson_nfft)
741 assert(.not. present(kernel))
742 call zpoisson_nfft_solve(this%nfft_solver, this%der%mesh, pot, rho)
743 end select
744 call profiling_out('ZPOISSON_SOLVE')
745 else
746 call zpoisson_solve_real_and_imag_separately(this, namespace, pot, rho, all_nodes_value, kernel = kernel)
747 end if
748
749 pop_sub(zpoisson_solve)
750 end subroutine zpoisson_solve
751
752
753 !-----------------------------------------------------------------
754
755 subroutine poisson_solve_batch(this, namespace, potb, rhob, all_nodes, kernel)
756 type(poisson_t), intent(inout) :: this
757 type(namespace_t), intent(in) :: namespace
758 type(batch_t), intent(inout) :: potb
759 type(batch_t), intent(inout) :: rhob
760 logical, optional, intent(in) :: all_nodes
761 type(fourier_space_op_t), optional, intent(in) :: kernel
762
763 integer :: ii
764
765 push_sub(poisson_solve_batch)
766
767 assert(potb%nst_linear == rhob%nst_linear)
768 assert(potb%type() == rhob%type())
769
770 if (potb%type() == type_float) then
771 do ii = 1, potb%nst_linear
772 call dpoisson_solve(this, namespace, potb%dff_linear(:, ii), rhob%dff_linear(:, ii), all_nodes, kernel=kernel)
773 end do
774 else
775 do ii = 1, potb%nst_linear
776 call zpoisson_solve(this, namespace, potb%zff_linear(:, ii), rhob%zff_linear(:, ii), all_nodes, kernel=kernel)
777 end do
778 end if
779
780 pop_sub(poisson_solve_batch)
781 end subroutine poisson_solve_batch
782
783 !-----------------------------------------------------------------
787 logical function poisson_solves_complex_natively(this)
788 type(poisson_t), intent(in) :: this
789
790 select case (this%method)
791 case (poisson_fft)
793 .and. .not. this%is_dressed .and. this%cube%fft%type == fft_complex
794 case (poisson_nfft)
796 case default
798 end select
800
801 !-----------------------------------------------------------------
805 logical function poisson_uses_nfft(this)
806 type(poisson_t), intent(in) :: this
807
808 select case (this%method)
809 case (poisson_nfft)
811 case (poisson_fft)
812 poisson_uses_nfft = this%cube%fft%library == fftlib_nfft
813 case default
814 poisson_uses_nfft = .false.
815 end select
816 end function poisson_uses_nfft
817
818 !-----------------------------------------------------------------
824 logical function poisson_is_batch_capable(this)
825 type(poisson_t), intent(in) :: this
826
827 poisson_is_batch_capable = this%method == poisson_fft &
828 .and. this%kernel /= poisson_fft_kernel_corrected
829 end function poisson_is_batch_capable
830
831 !-----------------------------------------------------------------
833 logical function poisson_is_device_batch_capable(this)
834 type(poisson_t), intent(in) :: this
835
836 ! Tested in steps: only a batch-capable solver is guaranteed to have an FFT cube.
838 if (.not. accel_is_enabled()) return
839 if (.not. poisson_is_batch_capable(this)) return
840 poisson_is_device_batch_capable = this%cube%fft%library == fftlib_accel &
841 .and. .not. this%cube%parallel_in_domains
843
844 !-----------------------------------------------------------------
845
851 subroutine dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
852 type(poisson_t), intent(in) :: this
853 type(namespace_t), intent(in) :: namespace
854 real(real64), contiguous, intent(inout) :: pot(:)
855 real(real64), contiguous, intent(in) :: rho(:)
859 logical, optional, intent(in) :: all_nodes
860 type(fourier_space_op_t), optional, intent(in) :: kernel
861 logical, optional, intent(in) :: reset
863 type(derivatives_t), pointer :: der
864 real(real64), allocatable :: rho_corrected(:), vh_correction(:)
865 logical :: all_nodes_value
866
867 call profiling_in('POISSON_SOLVE')
868 push_sub(dpoisson_solve)
869
870 der => this%der
871
872 assert(ubound(pot, dim = 1) == der%mesh%np_part .or. ubound(pot, dim = 1) == der%mesh%np)
873 assert(ubound(rho, dim = 1) == der%mesh%np_part .or. ubound(rho, dim = 1) == der%mesh%np)
874
875 ! Check optional argument and set to default if necessary.
876 all_nodes_value = optional_default(all_nodes, this%all_nodes_default)
877
878 if (poisson_solver_is_iterative(this) .and. optional_default(reset, .true.)) then
879 pot(1:der%mesh%np) = m_zero
880 end if
882 assert(this%method /= poisson_null)
883
884 if (present(kernel)) then
885 assert(this%method == poisson_fft)
886 end if
887
888 select case (this%method)
889 case (poisson_direct_sum)
890 if ((this%is_dressed .and. this%der%dim - 1 > 3) .or. this%der%dim > 3) then
891 message(1) = "Direct sum Poisson solver only available for 1, 2, or 3 dimensions."
892 call messages_fatal(1, namespace=namespace)
893 end if
894 call poisson_solve_direct(this, namespace, pot, rho)
895
896 case (poisson_cg)
897 call poisson_cg1(namespace, der, this%corrector, pot, rho)
898
900 safe_allocate(rho_corrected(1:der%mesh%np))
901 safe_allocate(vh_correction(1:der%mesh%np_part))
902
903 call correct_rho(this%corrector, der, rho, rho_corrected, vh_correction)
904
905 call lalg_axpy(der%mesh%np, -m_one, vh_correction, pot)
906 call poisson_cg2(namespace, der, pot, rho_corrected)
907 call lalg_axpy(der%mesh%np, m_one, vh_correction, pot)
909 safe_deallocate_a(rho_corrected)
910 safe_deallocate_a(vh_correction)
911
912 case (poisson_multigrid)
913 call poisson_multigrid_solver(this%mg, namespace, der, pot, rho)
914
915 case (poisson_fft)
916 if (this%kernel /= poisson_fft_kernel_corrected) then
917 call dpoisson_fft_solve(this%fft_solver, der%mesh, this%cube, pot, rho, this%mesh_cube_map, kernel=kernel)
918 else
919 safe_allocate(rho_corrected(1:der%mesh%np))
920 safe_allocate(vh_correction(1:der%mesh%np_part))
921
922 call correct_rho(this%corrector, der, rho, rho_corrected, vh_correction)
923 call dpoisson_fft_solve(this%fft_solver, der%mesh, this%cube, pot, rho_corrected, this%mesh_cube_map, &
924 average_to_zero = .true., kernel=kernel)
925
926 call lalg_axpy(der%mesh%np, m_one, vh_correction, pot)
927 safe_deallocate_a(rho_corrected)
928 safe_deallocate_a(vh_correction)
929 end if
930
931 case (poisson_isf)
932 call poisson_isf_solve(this%isf_solver, der%mesh, this%cube, pot, rho, all_nodes_value)
933
934
935 case (poisson_psolver)
936 if (this%psolver_solver%datacode == "G") then
937 ! Global version
938 call poisson_psolver_global_solve(this%psolver_solver, der%mesh, this%cube, pot, rho)
939 else ! "D" Distributed version
940 call poisson_psolver_parallel_solve(this%psolver_solver, der%mesh, this%cube, pot, rho, this%mesh_cube_map)
941 end if
942
943 case (poisson_nfft)
944 call dpoisson_nfft_solve(this%nfft_solver, der%mesh, pot, rho)
945
946 case (poisson_no)
947 call poisson_no_solve(this%no_solver, der%mesh, pot, rho)
948 end select
949
950 ! Add extra terms for dressed interaction
951 if (this%is_dressed .and. this%method /= poisson_no) then
952 call photon_mode_add_poisson_terms(this%photons, der%mesh, rho, pot)
953 end if
954
955 pop_sub(dpoisson_solve)
956 call profiling_out('POISSON_SOLVE')
957 end subroutine dpoisson_solve
958
959 !-----------------------------------------------------------------
960 subroutine poisson_init_sm(this, namespace, space, main, der, sm, grp, method, force_cmplx)
961 type(poisson_t), intent(inout) :: this
962 type(namespace_t), intent(in) :: namespace
963 class(space_t), intent(in) :: space
964 type(poisson_t), intent(in) :: main
965 type(derivatives_t), target, intent(in) :: der
966 type(submesh_t), intent(inout) :: sm
967 type(mpi_grp_t), intent(in) :: grp
968 integer, optional, intent(in) :: method
969 logical, optional, intent(in) :: force_cmplx
970
971 integer :: default_solver, idir, iter, maxl
972 integer :: box(space%dim)
973 real(real64) :: qq(der%dim), threshold
974
975 if (this%method /= poisson_null) return ! already initialized
976
977 push_sub(poisson_init_sm)
978
979 this%is_dressed = .false.
980 !TODO: To be implemented as an option
981 this%all_nodes_default = .false.
982
983 this%nslaves = 0
984 this%der => der
985
986#ifdef HAVE_MPI
987 this%all_nodes_default = main%all_nodes_default
988#endif
989
990 default_solver = poisson_direct_sum
991 this%method = default_solver
992 if (present(method)) this%method = method
993
994 if (der%mesh%use_curvilinear) then
995 call messages_not_implemented("Submesh Poisson solver with curvilinear mesh", namespace=namespace)
996 end if
997
998 this%kernel = poisson_fft_kernel_none
999
1000 select case (this%method)
1001 case (poisson_direct_sum)
1002 !Nothing to be done
1003
1004 case (poisson_isf)
1005 !TODO: Add support for domain parrallelization
1006 assert(.not. der%mesh%parallel_in_domains)
1007 call submesh_get_cube_dim(sm, space, box)
1008 call submesh_init_cube_map(sm, space)
1009 call cube_init(this%cube, box, namespace, space, sm%mesh%spacing, sm%mesh%coord_system, &
1010 fft_type = fft_none, need_partition=.not.der%mesh%parallel_in_domains)
1011 call cube_init_cube_map(this%cube, sm%mesh)
1012 call poisson_isf_init(this%isf_solver, namespace, der%mesh, this%cube, grp%comm, init_world = this%all_nodes_default)
1013
1014 case (poisson_psolver)
1015 !TODO: Add support for domain parrallelization
1016 assert(.not. der%mesh%parallel_in_domains)
1017 if (this%all_nodes_default) then
1018 this%cube%mpi_grp = grp
1019 else
1020 this%cube%mpi_grp = this%der%mesh%mpi_grp
1021 end if
1022 call submesh_get_cube_dim(sm, space, box)
1023 call submesh_init_cube_map(sm, space)
1024 call cube_init(this%cube, box, namespace, space, sm%mesh%spacing, sm%mesh%coord_system, &
1025 fft_type = fft_none, need_partition=.not.der%mesh%parallel_in_domains)
1026 call cube_init_cube_map(this%cube, sm%mesh)
1027 qq = m_zero
1028 call poisson_psolver_init(this%psolver_solver, namespace, space, this%cube, m_zero, qq, force_isolated=.true.)
1029 call poisson_psolver_get_dims(this%psolver_solver, this%cube)
1030 case (poisson_fft)
1031 !Here we impose zero boundary conditions
1032 this%kernel = poisson_fft_kernel_sph
1033
1034 call submesh_get_cube_dim(sm, space, box)
1035 call submesh_init_cube_map(sm, space)
1036 !We double the size of the cell
1037 !Maybe the factor of two should be controlled as a variable
1038 do idir = 1, space%dim
1039 box(idir) = (2 * (box(idir) - 1)) + 1
1040 end do
1041 if (optional_default(force_cmplx, .false.)) then
1042 call cube_init(this%cube, box, namespace, space, sm%mesh%spacing, sm%mesh%coord_system, &
1043 fft_type = fft_complex, need_partition=.not.der%mesh%parallel_in_domains)
1044 else
1045 call cube_init(this%cube, box, namespace, space, sm%mesh%spacing, sm%mesh%coord_system, &
1046 fft_type = fft_real, need_partition=.not.der%mesh%parallel_in_domains)
1047 end if
1048 call poisson_fft_init(this%fft_solver, namespace, space, this%cube, this%kernel)
1049 case (poisson_cg)
1050 call parse_variable(namespace, 'PoissonSolverMaxMultipole', 4, maxl)
1051 write(message(1),'(a,i2)')'Info: Boundary conditions fixed up to L =', maxl
1052 call messages_info(1, namespace=namespace)
1053 call parse_variable(namespace, 'PoissonSolverMaxIter', 500, iter)
1054 call parse_variable(namespace, 'PoissonSolverThreshold', 1.0e-6_real64, threshold)
1055 call poisson_corrections_init(this%corrector, namespace, space, maxl, this%der%mesh)
1056 call poisson_cg_init(threshold, iter)
1057 end select
1058
1059 pop_sub(poisson_init_sm)
1060 end subroutine poisson_init_sm
1061
1062 ! -----------------------------------------------------------------
1063
1064 logical pure function poisson_solver_is_iterative(this) result(iterative)
1065 type(poisson_t), intent(in) :: this
1066
1067 iterative = this%method == poisson_cg .or. this%method == poisson_cg_corrected
1068 end function poisson_solver_is_iterative
1069
1070 !-----------------------------------------------------------------
1071 subroutine poisson_async_init(this, mc)
1072 type(poisson_t), intent(inout) :: this
1073 type(multicomm_t), intent(in) :: mc
1074
1075 push_sub(poisson_async_init)
1076
1077#ifdef HAVE_MPI
1078 if (multicomm_have_slaves(mc)) then
1079
1080 call mpi_grp_init(this%local_grp, mc%group_comm(p_strategy_states))
1081
1082 this%root = (this%local_grp%is_root())
1083
1084 this%intercomm = mc%slave_intercomm
1085 call mpi_comm_remote_size(this%intercomm, this%nslaves)
1086
1087 end if
1088#endif
1089
1090 pop_sub(poisson_async_init)
1091
1092 end subroutine poisson_async_init
1093
1094 !-----------------------------------------------------------------
1095
1096 subroutine poisson_async_end(this, mc)
1097 type(poisson_t), intent(inout) :: this
1098 type(multicomm_t), intent(in) :: mc
1099
1100#ifdef HAVE_MPI
1101 integer :: islave
1102#endif
1103
1104 push_sub(poisson_async_end)
1105
1106#ifdef HAVE_MPI
1107 if (multicomm_have_slaves(mc)) then
1108
1109 ! send the finish signal
1110 do islave = this%local_grp%rank, this%nslaves - 1, this%local_grp%size
1111 call mpi_send(m_one, 1, mpi_double_precision, islave, cmd_finish, this%intercomm)
1112 end do
1113
1114 end if
1115#endif
1116
1117 pop_sub(poisson_async_end)
1118
1119 end subroutine poisson_async_end
1120
1121 !-----------------------------------------------------------------
1122
1123 subroutine poisson_slave_work(this, namespace)
1124 type(poisson_t), intent(inout) :: this
1125 type(namespace_t), intent(in) :: namespace
1126
1127#ifdef HAVE_MPI
1128 real(real64), allocatable :: rho(:), pot(:)
1129 logical :: done
1130 type(mpi_status) :: status
1131 integer :: bcast_root
1132
1133 push_sub(poisson_slave_work)
1134 call profiling_in("SLAVE_WORK")
1135
1136 safe_allocate(rho(1:this%der%mesh%np))
1137 safe_allocate(pot(1:this%der%mesh%np))
1138 done = .false.
1139
1140 do while(.not. done)
1141
1142 call profiling_in("SLAVE_WAIT")
1143 call mpi_recv(rho(1), this%der%mesh%np, mpi_double_precision, mpi_any_source, mpi_any_tag, this%intercomm, status)
1144 call profiling_out("SLAVE_WAIT")
1145
1146 ! The tag of the message tells us what we have to do.
1147 select case (status%MPI_TAG)
1148
1149 case (cmd_finish)
1150 done = .true.
1151
1152 case (cmd_poisson_solve)
1153 call dpoisson_solve(this, namespace, pot, rho)
1154
1155 call profiling_in("SLAVE_BROADCAST")
1156 bcast_root = mpi_proc_null
1157 if (this%root) bcast_root = mpi_root
1158 call mpi_bcast(pot(1), this%der%mesh%np, mpi_double_precision, bcast_root, this%intercomm)
1159 call profiling_out("SLAVE_BROADCAST")
1160
1161 end select
1162
1163 end do
1165 safe_deallocate_a(pot)
1166 safe_deallocate_a(rho)
1167
1168 call profiling_out("SLAVE_WORK")
1169 pop_sub(poisson_slave_work)
1170#endif
1171 end subroutine poisson_slave_work
1172
1173 !----------------------------------------------------------------
1174
1175 logical pure function poisson_is_async(this) result(async)
1176 type(poisson_t), intent(in) :: this
1177
1178 async = (this%nslaves > 0)
1179
1180 end function poisson_is_async
1181
1182 !----------------------------------------------------------------
1183
1184 subroutine poisson_build_kernel(this, namespace, space, coulb, qq, cam, singul)
1185 type(poisson_t), intent(in) :: this
1186 type(namespace_t), intent(in) :: namespace
1187 class(space_t), intent(in) :: space
1188 type(fourier_space_op_t), intent(inout) :: coulb
1189 real(real64), intent(in) :: qq(:)
1190 type(xc_cam_t), intent(in) :: cam
1191 real(real64), optional, intent(in) :: singul
1192
1193 logical :: reinit
1194
1195 push_sub(poisson_build_kernel)
1196
1197 if (space%is_periodic()) then
1198 assert(ubound(qq, 1) >= space%periodic_dim)
1199 assert(this%method == poisson_fft)
1200 end if
1201
1202 if (cam%omega > m_epsilon) then
1203 if (this%method /= poisson_fft) then
1204 write(message(1),'(a)') "Poisson solver with range separation is only implemented with FFT."
1205 call messages_fatal(1, namespace=namespace)
1206 end if
1207 end if
1208
1209 !We only reinitialize the poisson solver if needed
1210 reinit = .false.
1211 if (allocated(coulb%qq)) then
1212 reinit = any(abs(coulb%qq(1:space%periodic_dim) - qq(1:space%periodic_dim)) > m_epsilon)
1213 end if
1214 reinit = reinit .or. (abs(coulb%mu - cam%omega) > m_epsilon .and. cam%omega > m_epsilon)
1215 reinit = reinit .or. (abs(coulb%alpha - cam%alpha) > m_epsilon .and. cam%alpha > m_epsilon)
1216 reinit = reinit .or. (abs(coulb%beta - cam%beta) > m_epsilon .and. abs(cam%beta) > m_epsilon)
1217
1218 if (reinit) then
1219 call profiling_in('POISSON_BUILD_KERNEL')
1220 !TODO: this should be a select case supporting other kernels.
1221 ! This means that we need an abstract object for kernels.
1222 select case (this%method)
1223 case (poisson_fft)
1224 ! Check that we are consistent: the Poisson solver supports must return 1 here
1225 assert(is_close(poisson_get_full_range_weight(this, cam), m_one))
1226 call coulb%end()
1227 call coulb%init(space, qq, cam, singul)
1228 call poisson_fft_get_kernel(namespace, space, this%cube, coulb, this%kernel, &
1229 this%poisson_soft_coulomb_param)
1230 case default
1231 call messages_not_implemented("poisson_build_kernel with other methods than FFT", namespace=namespace)
1232 end select
1233 call profiling_out('POISSON_BUILD_KERNEL')
1234 end if
1235
1236 pop_sub(poisson_build_kernel)
1238
1239 !----------------------------------------------------------------
1248 real(real64) function poisson_get_full_range_weight(this, cam) result(weight)
1249 type(poisson_t), intent(in) :: this
1250 type(xc_cam_t), intent(in) :: cam
1251
1252 select case (this%method)
1253 case (poisson_fft)
1254 weight = m_one
1255 case default
1256 if(cam%omega < m_epsilon) then
1257 weight = cam%alpha
1258 else if(cam%alpha > m_epsilon .and. cam%beta < m_epsilon) then
1259 weight = cam%alpha
1260 else if(cam%alpha < m_epsilon .and. cam%beta > m_epsilon) then
1261 weight = cam%beta
1262 else
1263 assert(.false.)
1264 end if
1265 end select
1267
1268#include "poisson_init_inc.F90"
1269#include "poisson_direct_inc.F90"
1270#include "poisson_direct_sm_inc.F90"
1271
1272#include "undef.F90"
1273#include "real.F90"
1274#include "poisson_inc.F90"
1275#include "undef.F90"
1276#include "complex.F90"
1277#include "poisson_inc.F90"
1278#include "poisson_re_im_inc.F90"
1279
1280#include "undef.F90"
1281#include "real32.F90"
1282#include "poisson_inc.F90"
1283#include "undef.F90"
1284#include "complex32.F90"
1285#include "poisson_inc.F90"
1286#include "poisson_re_im_inc.F90"
1287
1288end module poisson_oct_m
1289
1290!! Local Variables:
1291!! mode: f90
1292!! coding: utf-8
1293!! End:
constant times a vector plus a vector
Definition: lalg_basic.F90:171
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:158
pure logical function, public accel_is_enabled()
Definition: accel.F90:391
This module implements batches of mesh functions.
Definition: batch.F90:112
This module handles the calculation mode.
integer, parameter, public p_strategy_kpoints
parallelization in k-points
subroutine, public cube_end(cube)
Definition: cube.F90:383
subroutine, public cube_init(cube, nn, namespace, space, spacing, coord_system, fft_type, fft_library, dont_optimize, nn_out, mpi_grp, need_partition, tp_enlarge, blocksize, batch_size, nthreads, single)
Definition: cube.F90:185
subroutine, public cube_init_cube_map(cube, mesh)
Definition: cube.F90:866
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:97
integer, parameter, public fft_none
global constants
Definition: fft.F90:155
integer, public fft_default_lib
Definition: fft.F90:261
integer, parameter, public fftlib_accel
Definition: fft.F90:160
integer, parameter, public fft_real
Definition: fft.F90:155
integer, parameter, public fft_complex
Definition: fft.F90:155
integer, parameter, public fftlib_nfft
Definition: fft.F90:160
integer, parameter, public fftlib_pfft
Definition: fft.F90:160
integer, parameter, public fftlib_fftw
Definition: fft.F90:160
real(real64), parameter, public m_two
Definition: global.F90:175
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_one
Definition: global.F90:174
real(real64), parameter, public m_three
Definition: global.F90:176
This module implements the index, used for the mesh points.
Definition: index.F90:101
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
subroutine, public mesh_cube_parallel_map_end(this)
subroutine, public mesh_cube_parallel_map_init(this, mesh, cube)
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
subroutine, public mesh_double_box(space, mesh, alpha, db)
finds the dimension of a box doubled in the non-periodic dimensions
Definition: mesh.F90:267
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:878
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1048
character(len=512), private msg
Definition: messages.F90:143
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1020
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:124
logical pure function, public multicomm_strategy_is_parallel(mc, level)
Definition: multicomm.F90:705
logical pure function, public multicomm_have_slaves(this)
Definition: multicomm.F90:831
Some general things and nomenclature:
Definition: par_vec.F90:150
subroutine, public photon_mode_compute_dipoles(this, mesh)
Computes the polarization dipole.
subroutine, public photon_mode_add_poisson_terms(this, mesh, rho, pot)
subroutine, public photon_mode_end(this)
subroutine, public photon_mode_init(this, namespace, dim, grp, photon_free)
subroutine, public photon_mode_set_n_electrons(this, qtot)
real(real64), public threshold
Definition: poisson_cg.F90:118
subroutine, public poisson_cg2(namespace, der, pot, rho)
Definition: poisson_cg.F90:208
subroutine, public poisson_cg1(namespace, der, corrector, pot, rho)
Definition: poisson_cg.F90:144
subroutine, public poisson_cg_init(thr, itr)
Definition: poisson_cg.F90:126
subroutine, public poisson_cg_end
Definition: poisson_cg.F90:138
subroutine, public poisson_corrections_end(this)
subroutine, public poisson_corrections_init(this, namespace, space, ml, mesh)
subroutine, public correct_rho(this, der, rho, rho_corrected, vh_correction)
integer, parameter, public poisson_fft_kernel_nocut
integer, parameter, public poisson_fft_kernel_cyl
subroutine, public zpoisson_fft_solve(this, mesh, cube, pot, rho, mesh_cube_map, average_to_zero, kernel, sm)
subroutine, public poisson_fft_end(this)
subroutine, public poisson_fft_init(this, namespace, space, cube, kernel, soft_coulb_param, fullcube)
integer, parameter, public poisson_fft_kernel_pla
integer, parameter, public poisson_fft_kernel_none
integer, parameter, public poisson_fft_kernel_corrected
integer, parameter, public poisson_fft_kernel_sph
subroutine, public dpoisson_fft_solve(this, mesh, cube, pot, rho, mesh_cube_map, average_to_zero, kernel, sm)
subroutine, public poisson_isf_end(this)
subroutine, public poisson_isf_init(this, namespace, mesh, cube, all_nodes_comm, init_world)
subroutine, public poisson_isf_solve(this, mesh, cube, pot, rho, all_nodes, sm)
subroutine, public poisson_multigrid_solver(this, namespace, der, pot, rho)
A multigrid Poisson solver with corrections at the boundaries.
subroutine, public poisson_multigrid_end(this)
Poisson solver on the mesh points themselves, through non-equispaced FFTs.
subroutine, public dpoisson_nfft_solve(this, mesh, pot, rho)
subroutine, public poisson_nfft_end(this)
subroutine, public zpoisson_nfft_solve(this, mesh, pot, rho)
The transform is complex either way, so a complex density costs the same as a real one and needs no s...
subroutine, public poisson_no_solve(this, mesh, pot, rho)
Definition: poisson_no.F90:141
subroutine, public poisson_no_end(this)
Definition: poisson_no.F90:129
subroutine, public zpoisson_solve_sm(this, namespace, sm, pot, rho, all_nodes)
Calculates the Poisson equation. Given the density returns the corresponding potential.
Definition: poisson.F90:2330
integer, parameter, public poisson_multigrid
Definition: poisson.F90:176
subroutine poisson_kernel_init(this, namespace, space, mc, stencil)
Definition: poisson.F90:1278
integer, parameter, public poisson_psolver
Definition: poisson.F90:176
subroutine, public dpoisson_solve_start(this, rho)
Definition: poisson.F90:2050
integer, parameter cmd_finish
Definition: poisson.F90:214
subroutine, public zpoisson_solve_finish(this, pot)
Definition: poisson.F90:2318
subroutine poisson_solve_direct(this, namespace, pot, rho)
Definition: poisson.F90:1493
integer, parameter, public poisson_fft
Definition: poisson.F90:176
subroutine, public spoisson_solve_batch(this, namespace, pot, rho, kernel, all_nodes, pot_buffer, rho_buffer, count)
Solves the Poisson equation for batched quantities, using fast Fourier transforms (FFTs).
Definition: poisson.F90:2881
subroutine, public spoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Single-precision scalar Poisson solve (FFT method only). This is the s/c counterpart of the concrete ...
Definition: poisson.F90:2834
subroutine, public zpoisson_solve_batch(this, namespace, pot, rho, kernel, all_nodes, pot_buffer, rho_buffer, count)
Solves the Poisson equation for batched quantities, using fast Fourier transforms (FFTs).
Definition: poisson.F90:2466
subroutine, public zpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Definition: poisson.F90:768
subroutine, public poisson_init_sm(this, namespace, space, main, der, sm, grp, method, force_cmplx)
Definition: poisson.F90:1018
subroutine, public poisson_solve_batch(this, namespace, potb, rhob, all_nodes, kernel)
Definition: poisson.F90:813
subroutine, public poisson_async_init(this, mc)
Definition: poisson.F90:1129
subroutine, public dpoisson_solve_sm(this, namespace, sm, pot, rho, all_nodes)
Calculates the Poisson equation. Given the density returns the corresponding potential.
Definition: poisson.F90:2070
subroutine zpoisson_solve_real_and_imag_separately(this, namespace, pot, rho, all_nodes, kernel)
Definition: poisson.F90:2577
subroutine, public cpoisson_solve_batch(this, namespace, pot, rho, kernel, all_nodes, pot_buffer, rho_buffer, count)
Solves the Poisson equation for batched quantities, using fast Fourier transforms (FFTs).
Definition: poisson.F90:3101
integer, parameter, public poisson_nfft
Definition: poisson.F90:176
logical pure function poisson_solver_is_iterative(this)
Definition: poisson.F90:1122
subroutine, public poisson_slave_work(this, namespace)
Definition: poisson.F90:1157
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
Definition: poisson.F90:909
integer, parameter cmd_poisson_solve
Definition: poisson.F90:214
integer, parameter, public poisson_cg
Definition: poisson.F90:176
subroutine, public poisson_init(this, namespace, space, der, mc, stencil, qtot, label, solver, verbose, force_serial, force_cmplx, fft_library, fft_batch_size, single_precision)
Definition: poisson.F90:223
subroutine, public poisson_build_kernel(this, namespace, space, coulb, qq, cam, singul)
Definition: poisson.F90:1174
subroutine, public dpoisson_solve_finish(this, pot)
Definition: poisson.F90:2058
subroutine, public zpoisson_solve_start(this, rho)
Definition: poisson.F90:2310
subroutine, public poisson_async_end(this, mc)
Definition: poisson.F90:1141
integer, parameter, public poisson_cg_corrected
Definition: poisson.F90:176
logical function, public poisson_is_device_batch_capable(this)
Whether a batch can be solved with the densities and potentials kept on the device.
Definition: poisson.F90:891
logical function, public poisson_uses_nfft(this)
Whether the solve goes through a non-equispaced FFT.
Definition: poisson.F90:863
subroutine, public cpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Single-precision scalar Poisson solve (FFT method only). This is the s/c counterpart of the concrete ...
Definition: poisson.F90:3047
logical function, public poisson_is_batch_capable(this)
Whether this solver can transform a whole batch of functions in one call.
Definition: poisson.F90:882
integer, parameter, public poisson_isf
Definition: poisson.F90:176
real(real64) function, public poisson_get_full_range_weight(this, cam)
Most Poisson solvers do not implement Coulomb attenuated potentials, and can only be used for global ...
Definition: poisson.F90:1238
subroutine, public dpoisson_solve_batch(this, namespace, pot, rho, kernel, all_nodes, pot_buffer, rho_buffer, count)
Solves the Poisson equation for batched quantities, using fast Fourier transforms (FFTs).
Definition: poisson.F90:2150
logical function, public poisson_solves_complex_natively(this)
Whether zpoisson_solve takes a complex density in one pass.
Definition: poisson.F90:845
integer, parameter, public poisson_null
Definition: poisson.F90:176
integer, parameter, public poisson_no
Definition: poisson.F90:176
logical pure function, public poisson_is_async(this)
Definition: poisson.F90:1165
subroutine, public poisson_end(this)
Definition: poisson.F90:712
subroutine, public poisson_psolver_global_solve(this, mesh, cube, pot, rho, sm)
subroutine, public poisson_psolver_parallel_solve(this, mesh, cube, pot, rho, mesh_cube_map)
subroutine, public poisson_psolver_end(this)
subroutine, public poisson_psolver_get_dims(this, cube)
subroutine, public poisson_psolver_init(this, namespace, space, cube, mu, qq, force_isolated)
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:672
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:604
This module defines stencils used in Octopus.
Definition: stencil.F90:114
subroutine, public submesh_init_cube_map(sm, space)
Definition: submesh.F90:949
subroutine, public submesh_get_cube_dim(sm, space, db)
finds the dimension of a box containing the submesh
Definition: submesh.F90:914
type(type_t), parameter, public type_float
Definition: types.F90:113
This module defines the unit system, used for input and output.
Class defining batches of mesh functions.
Definition: batch.F90:142
Class implementing a box that is a union of spheres. We do this in a specific class instead of using ...
class representing derivatives
Definition of a Fourier Space Coulomb Kernel.
This is defined even when running serial.
Definition: mpi.F90:121
A submesh is a type of mesh, used for the projectors in the pseudopotentials It contains points on a ...
Definition: submesh.F90:154
int true(void)