Octopus
test.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
20#include "global.h"
21
22module test_oct_m
23 use accel_oct_m
24 use batch_oct_m
27 use box_oct_m
32 use clock_oct_m
34 use debug_oct_m
42 use global_oct_m
43 use grid_oct_m
49 use iihash_oct_m
51 use iso_c_binding
52 use io_csv_oct_m
53 use io_oct_m
55 use, intrinsic :: iso_fortran_env
61 use mesh_oct_m
69 use mpi_oct_m
76 use parser_oct_m
82 use sihash_oct_m
84 use space_oct_m
85 use sphash_oct_m
94 use types_oct_m
95 use v_ks_oct_m
99
100 ! TODO(Alex) Issue 951. Migrate the test implementations to separate modules in $OCTOPUS_ROOT/test_integrations/
101 ! Test implementation modules
104
105 implicit none
106
107 !Auxiliary quantities needed by the linear solver
108 real(real64), target :: shift_aux
109 type(preconditioner_t) :: prec_aux
110
111 public :: test_run
112
113contains
114
118 subroutine test_run(namespace, grp)
119 type(namespace_t), intent(in) :: namespace
120 type(mpi_grp_t), intent(in) :: grp
121
122 type(test_parameters_t) :: param
123 integer :: test_mode
124
125 push_sub(test_run)
126
127 call messages_obsolete_variable(namespace, 'WhichTest', 'TestMode')
128
129 call param%init_from_file(namespace)
130
131 !%Variable TestMode
132 !%Type integer
133 !%Default hartree
134 !%Section Calculation Modes::Test
135 !%Description
136 !% Decides what kind of test should be performed.
137 !%Option hartree 1
138 !% Tests the Poisson solvers used to calculate the Hartree potential.
139 !%Option derivatives 2
140 !% Tests and benchmarks the implementation of the finite-difference operators, used to calculate derivatives.
141 !%Option orthogonalization 3
142 !% Tests the implementation of the orthogonalization routines.
143 !%Option interpolation 4
144 !% Test the interpolation routines.
145 !%Option ion_interaction 5
146 !% Tests the ion-ion interaction routines.
147 !%Option projector 6
148 !% Tests the code that applies the nonlocal part of the pseudopotentials
149 !% in case of spin-orbit coupling
150 !%Option dft_u 7
151 !% Tests the DFT+U part of the code for projections on the basis.
152 !%Option hamiltonian_apply 8
153 !% Tests the application of the Hamiltonian, or a part of it
154 !%Option density_calc 9
155 !% Calculation of the density.
156 !%Option exp_apply 10
157 !% Tests the exponential of the Hamiltonian
158 !%Option boundaries 11
159 !% Tests the boundaries conditions
160 !%Option subspace_diag 12
161 !% Tests the subspace diagonalization
162 !%Option batch_ops 13
163 !% Tests the batch operations
164 !%Option clock 18
165 !% Tests for clock
166 !%Option linear_solver 19
167 !% Tests the linear solvers
168 !%Option cgal 20
169 !% Tests for cgal interface
170 !%Option dense_eigensolver 21
171 !% Tests for dense eigensolvers (especially parallel ones)
172 !%Option grid_interpolation 22
173 !% Tests for grid interpolation and multigrid methods.
174 !%Option iihash 23
175 !% Tests for the integer-integer hash table.
176 !%Option sihash 24
177 !% Tests for the string-integer hash table.
178 !%Option sphash 25
179 !% Tests for the string-polymorphic hash table.
180 !%Option mpiwrappers 26
181 !% Tests for the MPI wrappers with large integer displacements.
182 !%Option regridding 27
183 !% Tests the regridding between two different grids.
184 !%Option helmholtz_decomposition 28
185 !% Test for the Helmholtz decomposition subroutines
186 !%Option vecpot_analytical 29
187 !% Tests analytically the vector potential from B field.
188 !%Option current_density 30
189 !% Tests the different contributions to the total electronic current density
190 !%Option mixing_tests 31
191 !% Unit test for the mixing
192 !%Option optimizers 32
193 !% Tests for the optimizers, using standard test functions
194 !%Option weighted_kmeans 33
195 !% Tests weighted kmeans algorithm, for assignment of centroids at clustered
196 !% around regions of high weight.
197 !%Option csv_input 34
198 !% Tests the reading of csv files in various dimensions
199 !%Option composition_chebyshev 35
200 !% Tests the chebyshev filtering and the related composition rule
201 !%Option lalg_adv 36
202 !% Tests for the advanced linear algebra routines
203 !%Option isdf_serial 37
204 !% Tests construction of interoperable separable density fit vectors using the
205 !% serial reference implementation.
206 !%Option isdf 38
207 !% Tests construction of interoperable separable density fit vectors.
208 !%Option centroids_t 39
209 !% Test centroids type methods
210 !%Option mesh_generation
211 !% Compares mesh operations for two electronic systems under sibling namespaces.
212 !%End
214 call parse_variable(namespace, 'TestMode', option__testmode__hartree, test_mode)
215
216 call messages_print_with_emphasis(msg="Test mode", namespace=namespace)
217 call messages_print_var_option("TestMode", test_mode, namespace=namespace)
218 call messages_print_var_option("TestType", param%type, namespace=namespace)
219 call messages_print_var_value("TestRepetitions", param%repetitions, namespace=namespace)
220 call messages_print_var_value("TestMinBlockSize", param%min_blocksize, namespace=namespace)
221 call messages_print_var_value("TestMaxBlockSize", param%max_blocksize, namespace=namespace)
222 call messages_print_with_emphasis(namespace=namespace)
223
224 select case (test_mode)
225 case (option__testmode__hartree)
226 call test_hartree(param, namespace, grp)
227 case (option__testmode__derivatives)
228 call test_derivatives(param, namespace, grp)
229 case (option__testmode__orthogonalization)
230 call test_orthogonalization(param, namespace, grp)
231 case (option__testmode__interpolation)
232 call test_interpolation(param, namespace, grp)
233 case (option__testmode__ion_interaction)
234 call test_ion_interaction(namespace, grp)
235 case (option__testmode__projector)
236 call test_projector(param, namespace, grp)
237 case (option__testmode__dft_u)
238 call test_dft_u(param, namespace, grp)
239 case (option__testmode__hamiltonian_apply)
240 call test_hamiltonian(param, namespace, grp)
241 case (option__testmode__density_calc)
242 call test_density_calc(param, namespace, grp)
243 case (option__testmode__exp_apply)
244 call test_exponential(param, namespace, grp)
245 case (option__testmode__boundaries)
246 call test_boundaries(param, namespace, grp)
247 case (option__testmode__subspace_diag)
248 call test_subspace_diagonalization(param, namespace, grp)
249 case (option__testmode__batch_ops)
250 call test_batch_ops(param, namespace, grp)
251 case (option__testmode__clock)
252 call test_clock()
253 case (option__testmode__linear_solver)
254 call test_linear_solver(namespace, grp)
255 case (option__testmode__cgal)
256 call test_cgal()
257 case (option__testmode__dense_eigensolver)
259 case (option__testmode__grid_interpolation)
261 case (option__testmode__iihash)
262 call test_iihash()
263 case (option__testmode__sihash)
264 call test_sihash()
265 case (option__testmode__sphash)
266 call test_sphash(namespace)
267 case (option__testmode__mpiwrappers)
268 call test_mpiwrappers()
269 case (option__testmode__regridding)
270 call test_regridding(namespace, grp)
271 case (option__testmode__helmholtz_decomposition)
272 call test_helmholtz_decomposition(namespace, grp)
273 case (option__testmode__vecpot_analytical)
274 call test_vecpot_analytical(namespace, grp)
275 case (option__testmode__current_density)
276 call test_current_density(namespace, grp)
277 case (option__testmode__mixing_tests)
278 call mix_tests_run()
279 case (option__testmode__optimizers)
280 call test_optimizers(namespace)
281 case (option__testmode__weighted_kmeans)
282 call test_weighted_kmeans(namespace)
283 case (option__testmode__csv_input)
284 call test_csv_input(namespace)
285 case (option__testmode__composition_chebyshev)
286 call test_composition_chebyshev(namespace, grp)
287 case (option__testmode__lalg_adv)
288 call test_exponential_matrix(namespace)
289 case (option__testmode__isdf_serial)
290 call test_isdf(namespace, serial=.true.)
291 case (option__testmode__isdf)
292 call test_isdf(namespace)
293 case (option__testmode__mesh_generation)
294 call test_mesh_generation(namespace, grp)
295 end select
296
297 pop_sub(test_run)
298 end subroutine test_run
299
300 ! ---------------------------------------------------------
301 subroutine test_hartree(param, namespace, grp)
302 type(test_parameters_t), intent(in) :: param
303 type(namespace_t), intent(in) :: namespace
304 type(mpi_grp_t), intent(in) :: grp
305
306 type(electrons_t), pointer :: sys
307
308 push_sub(test_hartree)
309
310 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
311
312 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
313 call poisson_test(sys%hm%psolver, sys%space, sys%gr, sys%ions%latt, namespace, param%repetitions)
314 safe_deallocate_p(sys)
315
316 pop_sub(test_hartree)
317 end subroutine test_hartree
318
319 ! ---------------------------------------------------------
320 subroutine test_helmholtz_decomposition(namespace, grp)
321 type(namespace_t), intent(in) :: namespace
322 type(mpi_grp_t), intent(in) :: grp
323
324 type(electrons_t), pointer :: sys
325 type(helmholtz_decomposition_t) :: helmholtz
326
328
329 ! First of all we have to initialize the grid and the poisson solver
330 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
331
332 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
333
334 call helmholtz%init(namespace, sys%gr, sys%mc, sys%space)
335
336 ! Then we have to initialize the exact fields
337 write(message(1),'(a)') "Helmholtz decomposition: beginning Hertzian dipole test"
338 call messages_info(1, namespace=namespace)
339 call hertzian_dipole_test(helmholtz, sys%gr, sys%namespace, sys%space)
340
341 write(message(1),'(a)') "Helmholtz decomposition: beginning Gaussian test"
342 call messages_info(1, namespace=namespace)
343 call gaussian_test(helmholtz, sys%gr, sys%namespace, sys%space)
344
345 safe_deallocate_p(sys)
346
348 end subroutine test_helmholtz_decomposition
349
350 ! ---------------------------------------------------------
351 subroutine test_linear_solver(namespace, grp)
352 use, intrinsic :: iso_c_binding, only: c_ptr
353 type(namespace_t), intent(in) :: namespace
354 type(mpi_grp_t), intent(in) :: grp
355
356 type(electrons_t), pointer :: sys
357 real(real64), allocatable :: rho(:), x(:), center(:)
358 real(real64) :: rr, alpha, beta, res
359 integer :: ip, iter
360 integer, target :: prefactor = -1
361
362 real(real64), parameter :: threshold = 1.e-7_real64
363
364 push_sub(test_linear_solver)
365
366 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
367
368 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
369
370 ! We need to set up some auxiliary quantities called by the linear solver
371 call mesh_init_mesh_aux(sys%gr)
372 ! Shift of the linear equation
373 shift_aux = 0.25_real64
374 ! Preconditioner used for the QMR algorithm
375 call preconditioner_init(prec_aux, namespace, sys%gr, sys%mc, sys%space)
376
377 ! Here we put a Gaussian as the right-hand side of the linear solver
378 ! Values are taken from the poisson_test routine
379 alpha = m_four * sys%gr%spacing(1)
380 beta = m_one / (alpha**sys%space%dim * sqrt(m_pi)**sys%space%dim)
381 ! The Gaussian is centered around the origin
382 safe_allocate(center(1:sys%space%dim))
383 center = m_zero
384
385 safe_allocate(rho(1:sys%gr%np))
386 rho = m_zero
387 do ip = 1, sys%gr%np
388 call mesh_r(sys%gr, ip, rr, origin = center(:))
389 rho(ip) = beta*exp(-(rr/alpha)**2)
390 end do
391
392 safe_allocate(x(1:sys%gr%np))
393
394 !Test the CG linear solver
395 x = m_zero
396 iter = 1000
397
398 call dconjugate_gradients(sys%gr%np, x, rho, dshifted_laplacian_op, dmf_dotp_aux, iter, res, &
399 threshold, userdata=[c_loc(sys%gr%der),c_loc(shift_aux),c_loc(prefactor)])
400 write(message(1),'(a,i6,a)') "Info: CG converged with ", iter, " iterations."
401 write(message(2),'(a,e14.6)') "Info: The residue is ", res
402 write(message(3),'(a,e14.6)') "Info: Norm solution CG ", dmf_nrm2(sys%gr, x)
403 call messages_info(3, namespace=namespace)
404
405 call preconditioner_end(prec_aux)
406 safe_deallocate_a(x)
407 safe_deallocate_a(rho)
408 safe_deallocate_p(sys)
409
410 pop_sub(test_linear_solver)
411 end subroutine test_linear_solver
412
413 ! ---------------------------------------------------------
414 subroutine test_projector(param, namespace, grp)
415 type(test_parameters_t), intent(in) :: param
416 type(namespace_t), intent(in) :: namespace
417 type(mpi_grp_t), intent(in) :: grp
418
419 type(electrons_t), pointer :: sys
420 type(wfs_elec_t) :: epsib
421 integer :: itime
422 complex(real64), allocatable :: psi(:, :)
423
424 push_sub(test_projector)
425
426 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
427
428 call messages_write('Info: Testing the nonlocal part of the pseudopotential with SOC')
429 call messages_new_line()
430 call messages_new_line()
431 call messages_info(namespace=namespace)
432
433 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
434
435 call states_elec_allocate_wfns(sys%st, sys%gr, wfs_type = type_cmplx)
436 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
437
438 ! Initialize external potential
439 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
440
441 call sys%st%group%psib(1, 1)%copy_to(epsib)
442
443 call batch_set_zero(epsib)
444
445 do itime = 1, param%repetitions
446 call zproject_psi_batch(sys%gr, sys%gr%der%boundaries, sys%hm%ep%proj, &
447 sys%hm%ep%natoms, 2, sys%st%group%psib(1, 1), epsib)
448 end do
449
450 safe_allocate(psi(1:sys%gr%np, 1:sys%st%d%dim))
451 do itime = 1, epsib%nst
452 call batch_get_state(epsib, itime, sys%gr%np, psi)
453 write(message(1),'(a,i1,3x, f12.6)') "Norm state ", itime, zmf_nrm2(sys%gr, 2, psi)
454 call messages_info(1, namespace=sys%namespace)
455 end do
456 safe_deallocate_a(psi)
457
458 call epsib%end()
459 call states_elec_deallocate_wfns(sys%st)
460 safe_deallocate_p(sys)
461
462 pop_sub(test_projector)
463 end subroutine test_projector
464
465 ! ---------------------------------------------------------
466 subroutine test_dft_u(param, namespace, grp)
467 type(test_parameters_t), intent(in) :: param
468 type(namespace_t), intent(in) :: namespace
469 type(mpi_grp_t), intent(in) :: grp
470
471 type(electrons_t), pointer :: sys
472 type(wfs_elec_t) :: epsib, epsib2
473 integer :: itime, ist
474 type(orbitalbasis_t) :: basis
475 real(real64), allocatable :: ddot(:,:,:), dweight(:,:)
476 complex(real64), allocatable :: zdot(:,:,:), zweight(:,:)
477 logical :: skipSOrbitals, useAllOrbitals
478
479 push_sub(test_dft_u)
480
481 call calc_mode_par%unset_parallelization(p_strategy_states)
482 call calc_mode_par%unset_parallelization(p_strategy_kpoints)
483 call calc_mode_par%set_parallelization(p_strategy_domains, default = .true.)
484
485 call messages_write('Info: Testing some DFT+U routines')
486 call messages_new_line()
487 call messages_new_line()
488 call messages_info(namespace=namespace)
489
490 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
491
492 call states_elec_allocate_wfns(sys%st, sys%gr)
493 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
494 if (sys%st%pack_states) call sys%st%pack()
495
496 call sys%st%group%psib(1, 1)%copy_to(epsib2, copy_data = .true.)
497
498 ! We set the phase of the batch if needed
499 if (.not. sys%hm%phase%is_allocated()) then
500 call sys%st%group%psib(1, 1)%copy_to(epsib, copy_data = .true.)
501 else
502 call sys%st%group%psib(1, 1)%copy_to(epsib)
503 call sys%hm%phase%apply_to(sys%gr, sys%gr%np, &
504 .false., epsib, src=sys%st%group%psib(1, 1))
505 epsib2%has_phase = .true.
506 end if
507
508 ! Initialize the orbital basis
509 call orbitalbasis_init(basis, sys%namespace, sys%space%periodic_dim)
510
511 ! Parsed in src/hamiltonian/lda_u.F90
512 call parse_variable(namespace, 'UseAllAtomicOrbitals', .false., useallorbitals)
513 call parse_variable(namespace, 'SkipSOrbitals', .true.,skipsorbitals)
514
515 if (states_are_real(sys%st)) then
516 call dorbitalbasis_build(basis, sys%namespace, sys%ions, sys%gr, sys%st%d%kpt, sys%st%d%dim, &
517 skipsorbitals, useallorbitals, verbose=.false.)
518 safe_allocate(dweight(1:basis%orbsets(1)%norbs, 1:epsib%nst_linear))
519 safe_allocate(ddot(1:sys%st%d%dim, 1:basis%orbsets(1)%norbs, 1:epsib%nst))
520 else
521 call zorbitalbasis_build(basis, sys%namespace, sys%ions, sys%gr, sys%st%d%kpt, sys%st%d%dim, &
522 skipsorbitals, useallorbitals, verbose=.false.)
523 call orbitalset_update_phase(basis%orbsets(1), sys%space%dim, sys%st%d%kpt, sys%kpoints, (sys%st%d%ispin==spin_polarized))
524 safe_allocate(zweight(1:basis%orbsets(1)%norbs, 1:epsib%nst_linear))
525 safe_allocate(zdot(1:sys%st%d%dim, 1:basis%orbsets(1)%norbs, 1:epsib%nst))
526
527 !We set the phase of the orbitals if needed
528 if (sys%hm%phase%is_allocated()) then
529 call orbitalset_update_phase(basis%orbsets(1), sys%space%dim, sys%st%d%kpt, sys%kpoints, &
530 (sys%st%d%ispin==spin_polarized))
531 end if
532 end if
533
534 do itime = 1, param%repetitions
535 call batch_set_zero(epsib2)
536 if (states_are_real(sys%st)) then
537 dweight = m_one
538 ddot = m_zero
539 call dorbitalset_get_coeff_batch(basis%orbsets(1), sys%st%d%dim, sys%st%group%psib(1, 1), ddot)
540 call dorbitalset_add_to_batch(basis%orbsets(1), sys%st%d%dim, epsib2, dweight)
541 else
542 zweight = m_one
543 zdot = m_zero
544 call zorbitalset_get_coeff_batch(basis%orbsets(1), sys%st%d%dim, epsib, zdot)
545 call zorbitalset_add_to_batch(basis%orbsets(1), sys%st%d%dim, epsib2, zweight)
546 end if
547 end do
548
549 if (epsib%is_packed()) then
550 call epsib%do_unpack(force = .true.)
551 end if
552
553 do ist = 1, epsib%nst
554 if (states_are_real(sys%st)) then
555 write(message(1),'(a,i2,3x,e13.6)') "Dotp state ", ist, ddot(1,1,ist)
556 else
557 write(message(1),'(a,i2,2(3x,e13.6))') "Dotp state ", ist, zdot(1,1,ist)
558 end if
559 call messages_info(1)
560 end do
562
563 call test_prints_info_batch(sys%st, sys%gr, epsib2)
564
565 safe_deallocate_a(dweight)
566 safe_deallocate_a(zweight)
567 safe_deallocate_a(ddot)
568 safe_deallocate_a(zdot)
569
570 call epsib%end()
571 call epsib2%end()
572 call orbitalbasis_end(basis)
573 call states_elec_deallocate_wfns(sys%st)
574 safe_deallocate_p(sys)
575
576 pop_sub(test_dft_u)
577 end subroutine test_dft_u
578
579 ! ---------------------------------------------------------
580 subroutine test_hamiltonian(param, namespace, grp)
581 type(test_parameters_t), intent(in) :: param
582 type(namespace_t), intent(in) :: namespace
583 type(mpi_grp_t), intent(in) :: grp
584
585 type(electrons_t), pointer :: sys
586 type(hamiltonian_elec_t) :: hm_copy
587 type(wfs_elec_t) :: hpsib, hpsib_copy, hpsib_diff
588 integer :: itime, terms
589 integer :: ist
590 logical :: copy_before_apply
591 real(real64), allocatable :: norm_hpsib(:), norm_diff(:)
592 real(real64) :: max_rel_diff
593 real(real64), parameter :: hamiltonian_copy_rel_tol = 1.0e-12_real64
594
595 push_sub(test_hamiltonian)
596
597 !%Variable TestHamiltonianApply
598 !%Type integer
599 !%Default term_all
600 !%Section Calculation Modes::Test
601 !%Description
602 !% Decides which part of the Hamiltonian is applied.
603 !%Option term_all 0
604 !% Apply the full Hamiltonian.
605 !%Option term_kinetic 1
606 !% Apply only the kinetic operator
607 !%Option term_local_potential 2
608 !% Apply only the local potential.
609 !%Option term_non_local_potential 4
610 !% Apply only the non_local potential.
611 !%End
612 call parse_variable(namespace, 'TestHamiltonianApply', option__testhamiltonianapply__term_all, terms)
613 if (terms == 0) terms = huge(1)
614
615 !%Variable TestHamiltonianCopyBeforeApply
616 !%Type logical
617 !%Default no
618 !%Section Calculation Modes::Test
619 !%Description
620 !% If set to yes, the Hamiltonian is copied with hamiltonian_elec_copy
621 !% and the copied Hamiltonian is used for application.
622 !%End
623 call parse_variable(namespace, 'TestHamiltonianCopyBeforeApply', .false., copy_before_apply)
624 call messages_print_var_value('TestHamiltonianCopyBeforeApply', copy_before_apply, namespace=namespace)
625
626
627 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
628
629 call messages_write('Info: Testing the application of the Hamiltonian')
630 call messages_new_line()
631 call messages_new_line()
632 call messages_info(namespace=namespace)
633
634 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
635
636 call states_elec_allocate_wfns(sys%st, sys%gr)
637 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
638
639 ! Initialize external potential
640 if (sys%st%pack_states .and. sys%hm%apply_packed()) call sys%st%pack()
641 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
642 call density_calc(sys%st, sys%gr, sys%st%rho)
643 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, sys%st, sys%ions, sys%ext_partners)
644
645 if (copy_before_apply) then
646 call hamiltonian_elec_copy(hm_copy, sys%hm)
647 end if
648
649 call boundaries_set(sys%gr%der%boundaries, sys%gr, sys%st%group%psib(1, 1))
650
651 call sys%st%group%psib(1, 1)%copy_to(hpsib)
652 if (copy_before_apply) call sys%st%group%psib(1, 1)%copy_to(hpsib_copy)
653
654 if (sys%hm%apply_packed()) then
655 call sys%st%group%psib(1, 1)%do_pack()
656 call hpsib%do_pack(copy = .false.)
657 if (copy_before_apply) call hpsib_copy%do_pack(copy = .false.)
658 end if
659
660 do itime = 1, param%repetitions
661 if (states_are_real(sys%st)) then
662 call dhamiltonian_elec_apply_batch(sys%hm, sys%namespace, sys%gr, sys%st%group%psib(1, 1), hpsib, &
663 terms = terms, set_bc = .false.)
664 if (copy_before_apply) then
665 call dhamiltonian_elec_apply_batch(hm_copy, sys%namespace, sys%gr, sys%st%group%psib(1, 1), hpsib_copy, &
666 terms = terms, set_bc = .false.)
667 end if
668 else
669 call zhamiltonian_elec_apply_batch(sys%hm, sys%namespace, sys%gr, sys%st%group%psib(1, 1), hpsib, &
670 terms = terms, set_bc = .false.)
671 if (copy_before_apply) then
672 call zhamiltonian_elec_apply_batch(hm_copy, sys%namespace, sys%gr, sys%st%group%psib(1, 1), hpsib_copy, &
673 terms = terms, set_bc = .false.)
674 end if
675 end if
676 end do
677
678 if (hpsib%is_packed()) then
679 call hpsib%do_unpack(force = .true.)
680 end if
681 if (copy_before_apply .and. hpsib_copy%is_packed()) then
682 call hpsib_copy%do_unpack(force = .true.)
683 end if
684
685 if (copy_before_apply) then
686 call hpsib_copy%copy_to(hpsib_diff, copy_data = .true.)
687 call batch_axpy(sys%gr%np, -1.0_real64, hpsib, hpsib_diff)
688
689 safe_allocate(norm_hpsib(1:hpsib%nst))
690 safe_allocate(norm_diff(1:hpsib_diff%nst))
691 call mesh_batch_nrm2(sys%gr, hpsib, norm_hpsib)
692 call mesh_batch_nrm2(sys%gr, hpsib_diff, norm_diff)
693
694 max_rel_diff = maxval(norm_diff / max(norm_hpsib, tiny(1.0_real64)))
695 write(message(1),'(a,e23.16)') 'Hamiltonian copy max relative difference ', max_rel_diff
696 call messages_info(1, namespace=namespace)
697
698 do ist = 1, hpsib%nst
699 if (norm_diff(ist) > hamiltonian_copy_rel_tol*max(norm_hpsib(ist), tiny(1.0_real64))) then
700 write(message(1),'(a,i6)') 'Hamiltonian copy mismatch for state ', ist
701 call messages_fatal(1, namespace=namespace)
702 end if
703 end do
704
705 safe_deallocate_a(norm_hpsib)
706 safe_deallocate_a(norm_diff)
707 call hpsib_diff%end(copy = .false.)
708 end if
709
710 call test_prints_info_batch(sys%st, sys%gr, hpsib)
711
712 if (copy_before_apply) then
713 call hamiltonian_elec_end(hm_copy)
714 call hpsib_copy%end(copy = .false.)
715 ! check that original hm still works after teardown of copy
716 if (sys%hm%apply_packed()) then
717 call hpsib%do_pack(copy = .false.)
718 end if
719 if (states_are_real(sys%st)) then
720 call dhamiltonian_elec_apply_batch(sys%hm, sys%namespace, sys%gr, sys%st%group%psib(1, 1), hpsib, &
721 terms = terms, set_bc = .false.)
722 else
723 call zhamiltonian_elec_apply_batch(sys%hm, sys%namespace, sys%gr, sys%st%group%psib(1, 1), hpsib, &
724 terms = terms, set_bc = .false.)
725 end if
726 end if
727 call hpsib%end(copy = .false.)
728 call states_elec_deallocate_wfns(sys%st)
729 safe_deallocate_p(sys)
730
731 pop_sub(test_hamiltonian)
732 end subroutine test_hamiltonian
733
734
735 ! ---------------------------------------------------------
736 subroutine test_density_calc(param, namespace, grp)
737 type(test_parameters_t), intent(in) :: param
738 type(namespace_t), intent(in) :: namespace
739 type(mpi_grp_t), intent(in) :: grp
740
741 type(electrons_t), pointer :: sys
742 integer :: itime
743
744 push_sub(test_density_calc)
745
746 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
747
748 call messages_write('Info: Testing density calculation')
749 call messages_new_line()
750 call messages_new_line()
751 call messages_info(namespace=namespace)
752
753 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
754
755 call states_elec_allocate_wfns(sys%st, sys%gr)
756 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
757 if (sys%st%pack_states) call sys%st%pack()
758
759 do itime = 1, param%repetitions
760 call density_calc(sys%st, sys%gr, sys%st%rho)
761 end do
762
763 write(message(1),'(a,3x, f12.6)') "Norm density ", dmf_nrm2(sys%gr, sys%st%rho(:,1))
764 call messages_info(1, namespace=namespace)
765
766 call states_elec_deallocate_wfns(sys%st)
767 safe_deallocate_p(sys)
768
769 pop_sub(test_density_calc)
770 end subroutine test_density_calc
771
772
773 ! ---------------------------------------------------------
774 subroutine test_boundaries(param, namespace, grp)
775 type(test_parameters_t), intent(in) :: param
776 type(namespace_t), intent(in) :: namespace
777 type(mpi_grp_t), intent(in) :: grp
778
779 type(electrons_t), pointer :: sys
780 integer :: itime
781
782 push_sub(test_boundaries)
783
784 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
785
786 call messages_write('Info: Testing boundary conditions')
787 call messages_new_line()
788 call messages_new_line()
789 call messages_info(namespace=namespace)
790
791 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
792
793 call states_elec_allocate_wfns(sys%st, sys%gr)
794 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
795 if (sys%st%pack_states) call sys%st%pack()
796
797 do itime = 1, param%repetitions
798 call boundaries_set(sys%gr%der%boundaries, sys%gr, sys%st%group%psib(1, 1))
799 end do
800
801 call test_prints_info_batch(sys%st, sys%gr, sys%st%group%psib(1, 1))
802
803 call states_elec_deallocate_wfns(sys%st)
804 safe_deallocate_p(sys)
805
806 pop_sub(test_boundaries)
807 end subroutine test_boundaries
808
809 ! ---------------------------------------------------------
813 subroutine test_composition_chebyshev(namespace, grp)
814 type(namespace_t), intent(in) :: namespace
815 type(mpi_grp_t), intent(in) :: grp
816
817 type(electrons_t), pointer :: sys
818 type(chebyshev_filter_bounds_t), pointer :: bounds
819 integer, allocatable :: degree(:)
820 integer :: degree_n
821 type(wfs_elec_t) :: psib
822
824
825 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
826
827 call messages_write('Info: Testing Chebyshev filtering and its composition rule')
828 call messages_new_line()
829 call messages_new_line()
830 call messages_info(namespace=namespace)
832 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
833
834 call states_elec_allocate_wfns(sys%st, sys%gr)
835
836 if (sys%st%pack_states .and. sys%hm%apply_packed()) call sys%st%pack()
837 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
838 call density_calc(sys%st, sys%gr, sys%st%rho)
839 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, sys%st, sys%ions, sys%ext_partners)
840
841 bounds => chebyshev_filter_bounds_t(-1.0_real64, 1.0_real64)
842 safe_allocate(degree(1:sys%st%group%nblocks))
843
844 !%Variable TestCompositionOrder
845 !%Type integer
846 !%Section Calculation Modes::Test
847 !%Description
848 !% Specifies the value of m for the test of the composition rule
849 !% $T_{2n}(x) = 2*T_n(x)^2-1$.
850 !%
851 !%End
852 call parse_variable(namespace, 'TestCompositionOrder', 2, degree_n)
853
854 !Initialization
855 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
856 call messages_new_line()
857 call messages_write('Info: Result for the original vector')
858 call messages_info(namespace=namespace)
859 call test_prints_info_batch(sys%st, sys%gr, sys%st%group%psib(1, 1))
860
861 ! Direct evaluation of mxn-th order Chebyshev filtering
862 degree = 2*degree_n
863 if (states_are_real(sys%st)) then
864 call dchebyshev_filter(namespace, sys%gr, sys%st, sys%hm, degree, bounds, 1, normalize=.false.)
865 else
866 call zchebyshev_filter(namespace, sys%gr, sys%st, sys%hm, degree, bounds, 1, normalize=.false.)
867 end if
868
870 call messages_write('Info: Result after calling 2n-th order filtering')
871 call messages_info(namespace=namespace)
872 call test_prints_info_batch(sys%st, sys%gr, sys%st%group%psib(1, 1))
873
874 ! Composition rule: m-th order Chebyshev filtering followed by n-th order filtering
875 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
876 call sys%st%group%psib(1, 1)%copy_to(psib, copy_data=.true.)
877 degree = degree_n
878 if (states_are_real(sys%st)) then
879 call dchebyshev_filter(namespace, sys%gr, sys%st, sys%hm, degree, bounds, 1, normalize=.false.)
880 call dchebyshev_filter(namespace, sys%gr, sys%st, sys%hm, degree, bounds, 1, normalize=.false.)
881 else
882 call zchebyshev_filter(namespace, sys%gr, sys%st, sys%hm, degree, bounds, 1, normalize=.false.)
883 call zchebyshev_filter(namespace, sys%gr, sys%st, sys%hm, degree, bounds, 1, normalize=.false.)
884 end if
885 call batch_scal(sys%gr%np, m_two, sys%st%group%psib(1, 1))
886 call batch_axpy(sys%gr%np, -m_one, psib, sys%st%group%psib(1, 1))
887
888 call messages_new_line()
889 call messages_write('Info: Result using the composition rule')
890 call messages_info(namespace=namespace)
891 call test_prints_info_batch(sys%st, sys%gr, sys%st%group%psib(1, 1))
892
893
894 safe_deallocate_a(degree)
895 safe_deallocate_p(bounds)
896
897 call psib%end()
898 call states_elec_deallocate_wfns(sys%st)
899 safe_deallocate_p(sys)
900
902 end subroutine test_composition_chebyshev
903
904
905
906 ! ---------------------------------------------------------
907 subroutine test_exponential(param, namespace, grp)
908 type(test_parameters_t), intent(in) :: param
909 type(namespace_t), intent(in) :: namespace
910 type(mpi_grp_t), intent(in) :: grp
911
912 type(electrons_t), pointer :: sys
913 type(exponential_t) :: te
914 integer :: itime
915
916 push_sub(test_exponential)
917
918 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
919
920 call messages_write('Info: Testing exponential')
921 call messages_new_line()
922 call messages_new_line()
923 call messages_info(namespace=namespace)
924
925 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
926
927 call states_elec_allocate_wfns(sys%st, sys%gr, wfs_type=type_cmplx)
928 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
929
930 ! Initialize external potential
931 if (sys%st%pack_states .and. sys%hm%apply_packed()) call sys%st%pack()
932 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
933 call density_calc(sys%st, sys%gr, sys%st%rho)
934 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, sys%st, sys%ions, sys%ext_partners)
935
936 call exponential_init(te, namespace)
937
938 if (sys%hm%apply_packed()) then
939 call sys%st%group%psib(1, 1)%do_pack()
940 end if
941
942 do itime = 1, param%repetitions
943 call te%apply_batch(sys%namespace, sys%gr, sys%hm, sys%st%group%psib(1, 1), 1e-3_real64)
944 end do
945
946 call test_prints_info_batch(sys%st, sys%gr, sys%st%group%psib(1, 1))
947
948 call states_elec_deallocate_wfns(sys%st)
949 safe_deallocate_p(sys)
950
951 pop_sub(test_exponential)
952 end subroutine test_exponential
953
954
955 ! ---------------------------------------------------------
956 subroutine test_subspace_diagonalization(param, namespace, grp)
957 type(test_parameters_t), intent(in) :: param
958 type(namespace_t), intent(in) :: namespace
959 type(mpi_grp_t), intent(in) :: grp
960
961 type(electrons_t), pointer :: sys
962 integer :: itime
963 type(subspace_t) :: sdiag
964 real(real64), allocatable :: diff(:)
965
967
968 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
969
970 call messages_write('Info: Testing subspace diagonalization')
971 call messages_new_line()
972 call messages_new_line()
973 call messages_info(namespace=namespace)
974
975 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
976
977 call states_elec_allocate_wfns(sys%st, sys%gr)
978 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
979
980 if (sys%st%pack_states .and. sys%hm%apply_packed()) call sys%st%pack()
981 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
982 call density_calc(sys%st, sys%gr, sys%st%rho)
983 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, sys%st, sys%ions, sys%ext_partners)
984
985 call sdiag%init(sys%namespace, sys%st)
986
987 safe_allocate(diff(1:sys%st%nst))
988
989 do itime = 1, param%repetitions
990 if (states_are_real(sys%st)) then
991 call dsubspace_diag(sdiag, sys%namespace, sys%gr, sys%st, sys%hm, 1, sys%st%eigenval(:, 1), diff)
992 else
993 call zsubspace_diag(sdiag, sys%namespace, sys%gr, sys%st, sys%hm, 1, sys%st%eigenval(:, 1), diff)
994 end if
995 end do
996
997 safe_deallocate_a(diff)
998
999 call test_prints_info_batch(sys%st, sys%gr, sys%st%group%psib(1, 1))
1000
1001 call states_elec_deallocate_wfns(sys%st)
1002 safe_deallocate_p(sys)
1003
1005 end subroutine test_subspace_diagonalization
1006
1007
1008 ! ---------------------------------------------------------
1009 subroutine test_batch_ops(param, namespace, grp)
1010 type(test_parameters_t), intent(in) :: param
1011 type(namespace_t), intent(in) :: namespace
1012 type(mpi_grp_t), intent(in) :: grp
1013
1014 type(electrons_t), pointer :: sys
1015 integer :: itime, ops, ops_default, ist, jst, nst, ip
1016 type(wfs_elec_t) :: xx, yy, zz
1017 real(real64), allocatable :: tmp(:)
1018 real(real64), allocatable :: ddotv(:)
1019 complex(real64), allocatable :: zdotv(:)
1020 real(real64), allocatable :: ddot(:,:), df(:,:), dweight(:), dpoints(:,:,:)
1021 complex(real64), allocatable :: zdot(:,:), zf(:,:), zweight(:), zpoints(:,:,:)
1022 real(real64), allocatable :: dff_mf(:)
1023 complex(real64), allocatable :: zff_mf(:)
1024 integer :: sp, block_size, size
1025
1026
1027 push_sub(test_batch_ops)
1028
1029 !%Variable TestBatchOps
1030 !%Type flag
1031 !%Default all
1032 !%Section Calculation Modes::Test
1033 !%Description
1034 !% Decides which part of the Hamiltonian is applied.
1035 !%Option ops_axpy bit(1)
1036 !% Tests batch_axpy operation
1037 !%Option ops_scal bit(2)
1038 !% Tests batch_scal operation
1039 !%Option ops_nrm2 bit(3)
1040 !% Tests batch_nrm2 operation
1041 !%Option ops_dotp_matrix bit(4)
1042 !% Tests X(mesh_batch_dotp_matrix)
1043 !%Option ops_dotp_self bit(5)
1044 !% Tests X(mesh_batch_dotp_self)
1045 !%Option ops_dotp_vector bit(6)
1046 !% Tests X(mesh_batch_dotp_vector)
1047 !%Option ops_ax_function_py bit(7)
1048 !% Tests X(batch_ax_function_py)
1049 !%Option ops_get_points bit(8)
1050 !% Tests batch_get_points and batch_set_points
1051 !%End
1052 ops_default = &
1053 option__testbatchops__ops_axpy + &
1054 option__testbatchops__ops_scal + &
1055 option__testbatchops__ops_nrm2 + &
1056 option__testbatchops__ops_dotp_matrix + &
1057 option__testbatchops__ops_dotp_self + &
1058 option__testbatchops__ops_dotp_vector + &
1059 option__testbatchops__ops_ax_function_py + &
1060 option__testbatchops__ops_get_points
1061
1062 call parse_variable(namespace, 'TestBatchOps', ops_default, ops)
1063
1064 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
1065
1066 call messages_write('Info: Testing batch operations')
1067 call messages_new_line()
1068 call messages_new_line()
1069 call messages_info(namespace=namespace)
1070
1071 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
1072
1073 call states_elec_allocate_wfns(sys%st, sys%gr)
1074 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
1075 if (sys%st%pack_states) call sys%st%pack()
1076
1077 if (bitand(ops, option__testbatchops__ops_axpy) /= 0) then
1078 message(1) = 'Info: Testing axpy'
1079 call messages_info(1, namespace=sys%namespace)
1080
1081 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1082 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
1083
1084 do itime = 1, param%repetitions
1085 call batch_axpy(sys%gr%np, 0.1_real64, xx, yy)
1086 end do
1087 call test_prints_info_batch(sys%st, sys%gr, yy, string = "axpy")
1088
1089 call xx%end()
1090 call yy%end()
1091
1092 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1093 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
1094 do itime = 1, param%repetitions
1095 call batch_axpby(sys%gr%np, 0.1_real64, xx, 0.2_real64, yy)
1096 end do
1097 call test_prints_info_batch(sys%st, sys%gr, yy, string = "axpby")
1098
1099 call xx%end()
1100 call yy%end()
1101 end if
1102
1103 if (bitand(ops, option__testbatchops__ops_scal) /= 0) then
1104 message(1) = 'Info: Testing scal'
1105 call messages_info(1, namespace=sys%namespace)
1106
1107 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1108
1109 do itime = 1, param%repetitions
1110 call batch_scal(sys%gr%np, 0.1_real64, xx)
1111 end do
1112 call test_prints_info_batch(sys%st, sys%gr, xx, string="scal")
1113 call xx%end()
1114
1115 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1116 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .false.)
1117 do itime = 1, param%repetitions
1118 call batch_scal2v(sys%gr%np, 0.1_real64, xx, yy)
1119 end do
1120 call test_prints_info_batch(sys%st, sys%gr, yy, string="scal2v")
1121
1122 call xx%end()
1123 call yy%end()
1124 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1125 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
1126 call sys%st%group%psib(1, 1)%copy_to(zz, copy_data = .false.)
1127
1128 do itime = 1, param%repetitions
1129 call batch_pointwise_mul(sys%gr%np, xx, yy, zz)
1130 end do
1131 call test_prints_info_batch(sys%st, sys%gr, zz, string="hadamard")
1132 call xx%end()
1133 call yy%end()
1134 call zz%end()
1135
1136 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1137 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .false.)
1138 if (states_are_real(sys%st)) then
1139 safe_allocate(dff_mf(1:sys%gr%np))
1140 do ip = 1, sys%gr%np
1141 dff_mf(ip) = 0.01_real64 + 0.001_real64*real(sys%gr%x(1, ip), real64)
1142 end do
1143
1144 do itime = 1, param%repetitions
1145 call batch_mul_mf(sys%gr%np, dff_mf, xx, yy)
1146 end do
1147 else
1148 safe_allocate(zff_mf(1:sys%gr%np))
1149 do ip = 1, sys%gr%np
1150 zff_mf(ip) = cmplx(0.01_real64 + 0.001_real64*real(sys%gr%x(1, ip), real64), 0.02_real64, real64)
1151 end do
1152
1153 do itime = 1, param%repetitions
1154 call batch_mul_mf(sys%gr%np, zff_mf, xx, yy)
1155 end do
1156 end if
1157
1158 call test_prints_info_batch(sys%st, sys%gr, yy, string="mul_mf")
1159
1160
1161 safe_deallocate_a(dff_mf)
1162 safe_deallocate_a(zff_mf)
1163
1164 call xx%end()
1165 call yy%end()
1166 end if
1167
1168 if (bitand(ops, option__testbatchops__ops_nrm2) /= 0) then
1169 message(1) = 'Info: Testing nrm2'
1170 call messages_info(1, namespace=sys%namespace)
1171
1172 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1173 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
1174
1175 safe_allocate(tmp(1:xx%nst))
1176
1177 do itime = 1, param%repetitions
1178 call mesh_batch_nrm2(sys%gr, yy, tmp)
1179 end do
1180 do itime = 1, xx%nst
1181 write(message(1),'(a,i1,3x,e23.16)') "Nrm2 norm state ", itime, tmp(itime)
1182 call messages_info(1, namespace=sys%namespace)
1183 end do
1184
1185 safe_deallocate_a(tmp)
1186
1187 call xx%end()
1188 call yy%end()
1189 end if
1190
1191 if (bitand(ops, option__testbatchops__ops_dotp_matrix) /= 0) then
1192
1193 message(1) = 'Info: Testing dotp_matrix'
1194 call messages_info(1, namespace=sys%namespace)
1195
1196 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1197 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
1198
1199 nst = sys%st%group%psib(1, 1)%nst
1200
1201 if (states_are_real(sys%st)) then
1202 safe_allocate(ddot(1:nst, 1:nst))
1203 do itime = 1, param%repetitions
1204 call dmesh_batch_dotp_matrix(sys%gr, xx, yy, ddot)
1205 end do
1206
1207 do ist = 1, nst
1208 do jst = 1, nst
1209 write(message(jst), '(a,2i3,3x,e23.16)') 'Dotp_matrix states', ist, jst, ddot(ist,jst)
1210 end do
1211 call messages_info(nst, namespace=sys%namespace)
1212 end do
1213 safe_deallocate_a(ddot)
1214 else
1215 safe_allocate(zdot(1:nst, 1:nst))
1216 do itime = 1, param%repetitions
1217 call zmesh_batch_dotp_matrix(sys%gr, xx, yy, zdot)
1218 end do
1219
1220 do ist = 1, nst
1221 do jst = 1, nst
1222 write(message(jst), '(a,2i3,3x,2(e23.16,1x))') 'Dotp_matrix states', ist, jst, zdot(ist,jst)
1223 end do
1224 call messages_info(nst, namespace=sys%namespace)
1225 end do
1226 safe_deallocate_a(zdot)
1227 end if
1228
1229 call xx%end()
1230 call yy%end()
1231 end if
1232
1233 if (bitand(ops, option__testbatchops__ops_dotp_vector) /= 0) then
1234
1235 message(1) = 'Info: Testing dotp_vector'
1236 call messages_info(1, namespace=sys%namespace)
1237
1238 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1239 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
1240
1241 nst = sys%st%group%psib(1, 1)%nst
1242
1243 if (states_are_real(sys%st)) then
1244 safe_allocate(ddotv(1:nst))
1245 do itime = 1, param%repetitions
1246 call dmesh_batch_dotp_vector(sys%gr, xx, yy, ddotv)
1247 end do
1248
1249 do ist = 1, nst
1250 write(message(ist), '(a,i3,3x,e23.16)') 'Dotp_vector state', ist, ddotv(ist)
1251 end do
1252 call messages_info(nst, namespace=sys%namespace)
1253 safe_deallocate_a(ddotv)
1254 else
1255 safe_allocate(zdotv(1:nst))
1256 do itime = 1, param%repetitions
1257 call zmesh_batch_dotp_vector(sys%gr, xx, yy, zdotv)
1258 end do
1259
1260 do ist = 1, nst
1261 write(message(ist), '(a,i3,3x,2(e23.16,1x))') 'Dotp_vector state', ist, zdotv(ist)
1262 end do
1263 call messages_info(nst, namespace=sys%namespace)
1264 safe_deallocate_a(zdotv)
1265 end if
1266
1267 call xx%end()
1268 call yy%end()
1269 end if
1270
1271 if (bitand(ops, option__testbatchops__ops_dotp_self) /= 0) then
1272
1273 message(1) = 'Info: Testing dotp_self'
1274 call messages_info(1, namespace=sys%namespace)
1275
1276 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1277
1278 nst = sys%st%group%psib(1, 1)%nst
1279
1280 if (states_are_real(sys%st)) then
1281 safe_allocate(ddot(1:nst, 1:nst))
1282 do itime = 1, param%repetitions
1283 call dmesh_batch_dotp_self(sys%gr, xx, ddot)
1284 end do
1285
1286 do ist = 1, nst
1287 do jst = 1, nst
1288 write(message(jst), '(a,2i3,3x,e23.16)') 'Dotp_self states', ist, jst, ddot(ist,jst)
1289 end do
1290 call messages_info(nst, namespace=sys%namespace)
1291 end do
1292 safe_deallocate_a(ddot)
1293 else
1294 safe_allocate(zdot(1:nst, 1:nst))
1295 do itime = 1, param%repetitions
1296 call zmesh_batch_dotp_self(sys%gr, xx, zdot)
1297 end do
1298
1299 do ist = 1, nst
1300 do jst = 1, nst
1301 write(message(jst), '(a,2i3,3x,2(e23.16,1x))') 'Dotp_self states', ist, jst, zdot(ist,jst)
1302 end do
1303 call messages_info(nst, namespace=sys%namespace)
1304 end do
1305 safe_deallocate_a(zdot)
1306 end if
1307
1308 call xx%end()
1309 end if
1310
1311 if (bitand(ops, option__testbatchops__ops_ax_function_py) /= 0) then
1312 message(1) = 'Info: Testing ax_function_py'
1313 call messages_info(1, namespace=sys%namespace)
1314
1315 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
1316
1317 if (states_are_real(sys%st)) then
1318 safe_allocate(df(sys%gr%np, sys%st%d%dim))
1319 safe_allocate(dweight(1:sys%st%group%psib(1, 1)%nst_linear))
1320 dweight = 0.1_real64
1321 call batch_get_state(sys%st%group%psib(1, 1), 1, sys%gr%np, df)
1322
1323 do itime = 1, param%repetitions
1324 call dbatch_ax_function_py(sys%gr%np, dweight, df, yy)
1325 end do
1326 safe_deallocate_a(df)
1327 safe_deallocate_a(dweight)
1328 else
1329 safe_allocate(zf(sys%gr%np, sys%st%d%dim))
1330 safe_allocate(zweight(1:sys%st%group%psib(1, 1)%nst_linear))
1331 zweight = cmplx(0.1_real64, m_zero, real64)
1332 call batch_get_state(sys%st%group%psib(1, 1), 1, sys%gr%np, zf)
1333
1334 do itime = 1, param%repetitions
1335 call zbatch_ax_function_py(sys%gr%np, zweight, zf, yy)
1336 end do
1337 safe_deallocate_a(zf)
1338 safe_deallocate_a(zweight)
1339 end if
1340 call test_prints_info_batch(sys%st, sys%gr, yy, string = "ax_function_py")
1341
1342 call yy%end()
1343 end if
1344
1345 if (bitand(ops, option__testbatchops__ops_get_points) /= 0) then
1346 ! The blocking over grid points mimics the actual use in the code
1347
1348 if (.not. accel_is_enabled()) then
1349
1350 call sys%st%group%psib(1, 1)%copy_to(yy)
1351
1352 if (states_are_real(sys%st)) then
1353
1354 block_size = max(40, cpu_hardware%l2%size/(2 * sizeof_real64 * sys%st%nst))
1355
1356 safe_allocate(dpoints(1:sys%st%nst, 1:sys%st%d%dim, 1:block_size))
1357
1358 do itime = 1, param%repetitions
1359 do sp = 1, sys%gr%np, block_size
1360 size = min(block_size, sys%gr%np - sp + 1)
1361 call batch_get_points(sys%st%group%psib(1, 1), sp, sp + size - 1, dpoints)
1362 call batch_set_points(yy, sp, sp + size - 1, dpoints)
1363 end do
1364 end do
1365 safe_deallocate_a(dpoints)
1366
1367 else
1368
1369 block_size = max(20, cpu_hardware%l2%size/(2 * sizeof_complex64 * sys%st%nst))
1370
1371 safe_allocate(zpoints(1:sys%st%nst, 1:sys%st%d%dim, 1:block_size))
1372
1373 do itime = 1, param%repetitions
1374 do sp = 1, sys%gr%np, block_size
1375 size = min(block_size, sys%gr%np - sp + 1)
1376 call batch_get_points(sys%st%group%psib(1, 1), sp, sp + size - 1, zpoints)
1377 call batch_set_points(yy, sp, sp + size - 1, zpoints)
1378 end do
1379 end do
1380 safe_deallocate_a(zpoints)
1381
1382 end if
1383
1384 call test_prints_info_batch(sys%st, sys%gr, yy, string = "get_points")
1385
1386 call yy%end()
1387 end if
1388 end if
1389
1390 call states_elec_deallocate_wfns(sys%st)
1391 safe_deallocate_p(sys)
1392
1393 pop_sub(test_batch_ops)
1394 end subroutine test_batch_ops
1395
1396! ---------------------------------------------------------
1397 subroutine test_derivatives(param, namespace, grp)
1398 type(test_parameters_t), intent(in) :: param
1399 type(namespace_t), intent(in) :: namespace
1400 type(mpi_grp_t), intent(in) :: grp
1401
1402 type(electrons_t), pointer :: sys
1403
1404 push_sub(test_derivatives)
1405
1406 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
1407
1408 message(1) = 'Info: Testing the finite-differences derivatives.'
1409 message(2) = ''
1410 call messages_info(2, namespace=namespace)
1411
1412 if (param%type == option__testtype__all .or. param%type == option__testtype__real) then
1413 call dderivatives_test(sys%gr%der, sys%namespace, param%repetitions, param%min_blocksize, param%max_blocksize)
1414 end if
1415
1416 if (param%type == option__testtype__all .or. param%type == option__testtype__complex) then
1417 call zderivatives_test(sys%gr%der, sys%namespace, param%repetitions, param%min_blocksize, param%max_blocksize)
1418 end if
1419
1420 if (sys%space%dim > 1) then
1421 call derivatives_advanced_benchmark(sys%gr%der, sys%namespace)
1422 end if
1423
1424 safe_deallocate_p(sys)
1425
1426 pop_sub(test_derivatives)
1427 end subroutine test_derivatives
1428
1429 ! ---------------------------------------------------------
1430
1431 subroutine test_orthogonalization(param, namespace, grp)
1432 type(test_parameters_t), intent(in) :: param
1433 type(namespace_t), intent(in) :: namespace
1434 type(mpi_grp_t), intent(in) :: grp
1435
1436 type(electrons_t), pointer :: sys
1437 integer :: itime
1438
1439 push_sub(test_orthogonalization)
1440
1441 call calc_mode_par%set_parallelization(p_strategy_states, default = .false.)
1442 call calc_mode_par%set_scalapack_compat()
1443
1444 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
1445
1446 message(1) = 'Info: Testing orthogonalization.'
1447 message(2) = ''
1448 call messages_info(2, namespace=namespace)
1449
1450 if (param%type == option__testtype__all .or. param%type == option__testtype__real) then
1451 message(1) = 'Info: Real wave-functions.'
1452 call messages_info(1, namespace=namespace)
1453 do itime = 1, param%repetitions
1454 call dstates_elec_calc_orth_test(sys%st, sys%namespace, sys%gr, sys%kpoints)
1455 end do
1456 end if
1457
1458 if (param%type == option__testtype__all .or. param%type == option__testtype__complex) then
1459 message(1) = 'Info: Complex wave-functions.'
1460 call messages_info(1, namespace=namespace)
1461 do itime = 1, param%repetitions
1462 call zstates_elec_calc_orth_test(sys%st, sys%namespace, sys%gr, sys%kpoints)
1463 end do
1464 end if
1465
1466 safe_deallocate_p(sys)
1467
1468 pop_sub(test_orthogonalization)
1469 end subroutine test_orthogonalization
1470
1471 ! ---------------------------------------------------------
1472
1473 subroutine test_interpolation(param, namespace, grp)
1474 type(test_parameters_t), intent(in) :: param
1475 type(namespace_t), intent(in) :: namespace
1476 type(mpi_grp_t), intent(in) :: grp
1477
1478 type(electrons_t), pointer :: sys
1479
1480 push_sub(test_interpolation)
1481
1482 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
1483
1484 if (param%type == option__testtype__all .or. param%type == option__testtype__real) then
1485 call messages_write('Info: Testing real interpolation routines')
1486 call messages_new_line()
1487 call messages_new_line()
1488 call messages_info(namespace=namespace)
1489
1490 call dmesh_interpolation_test(sys%gr)
1491 end if
1493 if (param%type == option__testtype__all .or. param%type == option__testtype__complex) then
1494 call messages_new_line()
1495 call messages_write('Info: Testing complex interpolation routines')
1496 call messages_new_line()
1497 call messages_new_line()
1498 call messages_info(namespace=namespace)
1499
1500 call zmesh_interpolation_test(sys%gr)
1501 end if
1502
1503 safe_deallocate_p(sys)
1504
1505 pop_sub(test_interpolation)
1506 end subroutine test_interpolation
1507
1508
1509 ! ---------------------------------------------------------
1510
1511 subroutine test_ion_interaction(namespace, grp)
1512 type(namespace_t), intent(in) :: namespace
1513 type(mpi_grp_t), intent(in) :: grp
1514
1515 type(electrons_t), pointer :: sys
1516
1517 push_sub(test_ion_interaction)
1518
1519 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
1520
1521 call ion_interaction_test(sys%space, sys%ions%latt, sys%ions%atom, sys%ions%natoms, sys%ions%pos, &
1522 sys%gr%box%bounding_box_l, namespace, sys%mc)
1523
1524 safe_deallocate_p(sys)
1525
1527 end subroutine test_ion_interaction
1528
1529 ! ---------------------------------------------------------
1530
1531 subroutine test_prints_info_batch(st, gr, psib, string)
1532 type(states_elec_t), intent(in) :: st
1533 type(grid_t), intent(in) :: gr
1534 class(batch_t), intent(inout) :: psib
1535 character(*), optional, intent(in) :: string
1536
1537 integer :: itime
1538 complex(real64), allocatable :: zpsi(:, :)
1539 real(real64), allocatable :: dpsi(:, :)
1540
1541 character(80) :: string_
1542
1543 string_ = optional_default(string, "")
1544
1545 push_sub(test_prints_info_batch)
1546
1547 if (states_are_real(st)) then
1548 safe_allocate(dpsi(1:gr%np, 1:st%d%dim))
1549 else
1550 safe_allocate(zpsi(1:gr%np, 1:st%d%dim))
1551 end if
1552
1553 do itime = 1, psib%nst
1554 if (states_are_real(st)) then
1555 call batch_get_state(psib, itime, gr%np, dpsi)
1556 write(message(1),'(a,i2,3x,e23.16)') "Norm state "//trim(string_)//" ", itime, dmf_nrm2(gr, st%d%dim, dpsi)
1557 else
1558 call batch_get_state(psib, itime, gr%np, zpsi)
1559 write(message(1),'(a,i2,3x,e23.16)') "Norm state "//trim(string_)//" ", itime, zmf_nrm2(gr, st%d%dim, zpsi)
1560 end if
1561 call messages_info(1)
1562 end do
1563
1564 if (states_are_real(st)) then
1565 safe_deallocate_a(dpsi)
1566 else
1567 safe_deallocate_a(zpsi)
1568 end if
1569
1570 pop_sub(test_prints_info_batch)
1571
1572 end subroutine test_prints_info_batch
1573
1574
1575 ! ---------------------------------------------------------
1576 subroutine test_clock()
1577
1578 type(iteration_counter_t) :: clock, other_clock
1579
1580 push_sub(test_clock)
1581
1582 ! Clock operations
1583 write(message(1),'(a)') " Operation Counter Time Global step"
1584 call messages_info(1)
1585
1586 clock = clock_t(time_step=m_two, initial_iteration=2)
1587 call write_clock("initialization")
1588
1589 clock = clock + 5
1590 call write_clock("addition (+5)")
1591
1592 clock = clock - 3
1593 call write_clock("subtraction (-3)")
1594
1595 call clock%reset()
1596 call write_clock("reset (=0)")
1597
1598 call clock%set(clock_t(time_step=m_four, initial_iteration=1))
1599 call write_clock("set (=2)")
1600
1601 ! Clock comparisons:
1602 write(message(1),'(a)') " Clock comparisons:"
1603 call messages_info(1)
1604
1605 other_clock = clock_t(time_step=m_one, initial_iteration=5)
1607 call write_condition_result("4 < 5", clock < other_clock)
1608 call write_condition_result("4 <= 5", clock <= other_clock)
1609 call write_condition_result("4 > 5", clock > other_clock)
1610 call write_condition_result("4 >= 5", clock >= other_clock)
1611 call write_condition_result("4 == 5", clock == other_clock)
1612 call write_condition_result("4 /= 5", clock /= other_clock)
1613
1614 pop_sub(test_clock)
1615 contains
1616 subroutine write_clock(operation)
1617 character(len=*), intent(in) :: operation
1618
1619 write(message(1),'(a17,1x,i6,1x,f10.1,1x,i16)') operation, clock%counter(), clock%value(), clock%global_step()
1620 call messages_info(1)
1621 end subroutine write_clock
1622
1623 subroutine write_condition_result(condition, result)
1624 character(len=*), intent(in) :: condition
1625 logical, intent(in) :: result
1627 write(message(1),'(a10," = ",i1," (",l1,")")') condition, abs(transfer(result, 0)), result
1628 call messages_info(1)
1629 end subroutine write_condition_result
1630
1631 end subroutine test_clock
1632
1633
1634 ! ---------------------------------------------------------
1635 subroutine test_cgal()
1636
1637 type(cgal_polyhedra_t) :: cgal_poly
1638
1639 push_sub(test_cgal)
1640
1641 call cgal_polyhedron_init(cgal_poly, "28-cgal.02-X.off", verbose = .true.)
1642
1643 if (cgal_polyhedron_point_inside(cgal_poly, 30._real64, 10._real64, 30._real64)) then
1644 message(1) = "cgal_polyhedron_point_inside"
1645 call messages_info(1)
1646 end if
1647
1648 call cgal_polyhedron_end(cgal_poly)
1649
1650 pop_sub(test_cgal)
1651 end subroutine test_cgal
1652
1653
1654 ! ---------------------------------------------------------
1655 subroutine test_dense_eigensolver()
1656 integer :: N, ii, jj, N_list(4), i_N
1657 real(real64), allocatable :: matrix(:, :), eigenvectors(:, :), eigenvalues(:), test(:)
1658 real(real64), allocatable :: differences(:)
1659
1660 push_sub(test_dense_eigensolver)
1661
1662 n_list = [15, 32, 100, 500]
1663
1664 do i_n = 1, 4
1665 n = n_list(i_n)
1666 safe_allocate(matrix(1:n, 1:n))
1667 safe_allocate(eigenvectors(1:n, 1:n))
1668 safe_allocate(eigenvalues(1:n))
1669 safe_allocate(test(1:n))
1670 safe_allocate(differences(1:n))
1672
1673 ! set up symmetrix matrix
1674 do jj = 1, n
1675 do ii = 1, n
1676 matrix(ii, jj) = ii * jj
1677 end do
1678 end do
1679
1680 ! parallel solver
1681 eigenvectors(1:n, 1:n) = matrix(1:n, 1:n)
1682 call lalg_eigensolve_parallel(n, eigenvectors, eigenvalues)
1683
1684 do ii = 1, n
1685 test(:) = matmul(matrix, eigenvectors(:, ii)) - eigenvalues(ii) * eigenvectors(:, ii)
1686 differences(ii) = sum(abs(test)) / sum(abs(eigenvectors(:, ii)))
1687 end do
1688 write(message(1), "(A, I3, A, E13.6)") "Parallel solver - N: ", n, &
1689 ", average difference: ", sum(differences)/n
1690 call messages_info(1)
1691
1692 ! serial solver
1693 eigenvectors(1:n, 1:n) = matrix(1:n, 1:n)
1694 call lalg_eigensolve(n, eigenvectors, eigenvalues)
1695
1696 do ii = 1, n
1697 test(:) = matmul(matrix, eigenvectors(:, ii)) - eigenvalues(ii) * eigenvectors(:, ii)
1698 differences(ii) = sum(abs(test)) / sum(abs(eigenvectors(:, ii)))
1699 end do
1700 write(message(1), "(A, I3, A, E13.6)") "Serial solver - N: ", n, &
1701 ", average difference: ", sum(differences)/n
1702 call messages_info(1)
1703
1704 safe_deallocate_a(matrix)
1705 safe_deallocate_a(eigenvectors)
1706 safe_deallocate_a(eigenvalues)
1707 safe_deallocate_a(test)
1708 safe_deallocate_a(differences)
1709 end do
1710
1712 end subroutine test_dense_eigensolver
1713
1714 subroutine test_batch_set_gaussian(psib, mesh)
1715 class(batch_t), intent(inout) :: psib
1716 class(mesh_t), intent(in) :: mesh
1717
1718 real(real64), allocatable :: dff(:)
1719 complex(real64), allocatable :: zff(:)
1720 integer :: ist, ip
1721 real(real64) :: da, db, dc
1722 complex(real64) :: za, zb, zc
1723
1724 push_sub(test_batch_set_gaussian)
1725
1726 ! use a similar function as in the derivatives test
1727 da = m_one/mesh%box%bounding_box_l(1)
1728 db = 10.0_real64
1729 dc = 100.0_real64
1731 if (type_is_complex(psib%type())) then
1732 ! we make things more "complex"
1733 za = da + m_zi*0.01_real64
1734 zb = db*exp(m_zi*0.345_real64)
1735 zc = dc - m_zi*50.0_real64
1736
1737 safe_allocate(zff(1:mesh%np))
1738 do ist = 1, psib%nst_linear
1739 za = za * ist
1740 zb = zb / ist
1741 do ip = 1, mesh%np
1742 zff(ip) = zb*exp(-za*sum(mesh%x(:, ip)**2)) + zc
1743 end do
1744 call batch_set_state(psib, ist, mesh%np, zff)
1745 end do
1746 call zmesh_batch_normalize(mesh, psib)
1747 safe_deallocate_a(zff)
1748 else
1749 safe_allocate(dff(1:mesh%np))
1750 do ist = 1, psib%nst_linear
1751 da = da * ist
1752 db = db / ist
1753 do ip = 1, mesh%np
1754 dff(ip) = db*exp(-da*sum(mesh%x(:, ip)**2)) + dc
1755 end do
1756 call batch_set_state(psib, ist, mesh%np, dff)
1757 end do
1758 call dmesh_batch_normalize(mesh, psib)
1759 safe_deallocate_a(dff)
1760 end if
1761
1763 end subroutine test_batch_set_gaussian
1764
1765 ! ---------------------------------------------------------
1766 subroutine test_grid_interpolation(grp)
1767 type(mpi_grp_t), intent(in) :: grp
1768 type(electrons_t), pointer :: sys
1769 type(multigrid_t) :: mgrid
1770
1771 push_sub(test_grid_interpolation)
1772
1773 sys => electrons_t(global_namespace, grp, int(option__calculationmode__dummy, int32))
1774
1775 call multigrid_init(mgrid, global_namespace, sys%space, sys%gr, sys%gr%der, &
1776 sys%gr%stencil, sys%mc, nlevels=3)
1777
1778 call multigrid_test_interpolation(mgrid, sys%space)
1779
1780 call multigrid_end(mgrid)
1781
1782 safe_deallocate_p(sys)
1783
1785 end subroutine test_grid_interpolation
1786
1787 subroutine test_iihash()
1788
1789 type(iihash_t) :: h
1790 integer :: value
1791 logical :: found
1792
1793 call iihash_init(h)
1794 call iihash_insert(h, 1,5)
1795 call iihash_insert(h, 3,7)
1796
1797 value = iihash_lookup(h, 1, found)
1798 write(message(1),*) 'hash[1] :', found, value
1799 call messages_info()
1800
1801 value = iihash_lookup(h, 2, found)
1802 write(message(1),*) 'hash[2] :', found, value
1803 call messages_info()
1804
1805 value = iihash_lookup(h, 3, found)
1806 write(message(1),*) 'hash[3] :', found, value
1807 call messages_info()
1808
1810
1811 end subroutine test_iihash
1812
1813 subroutine test_sihash()
1814 type(sihash_t) :: h
1815 type(sihash_iterator_t) :: it
1816
1817 integer :: counter
1818 integer :: value, sum
1819 logical :: found
1820
1821 call sihash_init(h)
1822 call sihash_insert(h, "one",5)
1823 call sihash_insert(h, "three",7)
1824 call sihash_insert(h, "the answer", 42)
1825
1826 value = sihash_lookup(h, "one", found)
1827 write(message(1),*) 'hash["one"]: ', found, value
1828 call messages_info()
1829
1830 value = sihash_lookup(h, "two", found)
1831 write(message(1),*) 'hash["two"]: ', found, value
1832 call messages_info()
1833
1834 value = sihash_lookup(h, "three", found)
1835 write(message(1),*) 'hash["three"]: ', found, value
1836 call messages_info()
1837
1838 sum = 0
1839 counter = 1
1840 call it%start(h)
1841
1842 do while (it%has_next())
1843 value = it%get_next()
1844 sum = sum + value
1845 write(message(1),'(I3,A,I5)') counter,': hash[...] = ',value
1846 call messages_info()
1847 counter = counter + 1
1848 end do
1849 write(message(1),*) 'counter = ', counter
1850 write(message(2),*) 'sum = ', sum
1851 call messages_info(2)
1852
1853
1854 call sihash_end(h)
1855
1856 end subroutine test_sihash
1857
1858
1859 subroutine test_sphash(namespace)
1860 type(namespace_t), intent(in) :: namespace
1862 type(sphash_t) :: h
1863 type(sphash_iterator_t) :: it
1864
1865 logical :: found
1866
1867
1868 type(iteration_counter_t) :: clock_1
1869 type(iteration_counter_t), allocatable :: clock_2
1870 type(space_t) :: space_1
1871
1872 class(*), pointer :: value
1873
1874 integer :: count_clock, count_space
1875
1876 safe_allocate(clock_2)
1877
1878 clock_1 = clock_t(1.d-5, 1)
1879 clock_2 = clock_t(2.d-5, 2)
1880 space_1 = space_t(namespace)
1881
1883 call sphash_insert(h, "one", clock_1)
1884 call sphash_insert(h, "two", space_1)
1885 call sphash_insert(h, "three", clock_2, clone=.true.)
1886
1887 value => sphash_lookup(h, "one", found)
1888 select type(value)
1889 type is (iteration_counter_t)
1890 write(message(1),*) 'hash["one"]: ', found, value%counter()
1891 call messages_info()
1892 type is (space_t)
1893 write(message(1),*) 'hash["one"]: ', found, value%short_info()
1894 call messages_info()
1895 class default
1896 write(message(1),*) 'wrong type. found = ', found
1897 call messages_info()
1898 end select
1899
1900 value => sphash_lookup(h, "two", found)
1901 select type(value)
1902 type is (iteration_counter_t)
1903 write(message(1),*) 'hash["two"]: ', found, value%counter()
1904 call messages_info()
1905 type is (space_t)
1906 write(message(1),*) 'hash["two"]: ', found, value%short_info()
1907 call messages_info()
1908 class default
1909 write(message(1),*) 'wrong type. found = ',found
1910 call messages_info()
1911 end select
1912
1913 safe_deallocate_a(clock_2)
1914
1915 value => sphash_lookup(h, "three", found)
1916 select type(value)
1917 type is (iteration_counter_t)
1918 write(message(1),*) 'hash["three"]: ', found, value%counter()
1919 call messages_info()
1920 type is (space_t)
1921 write(message(1),*) 'hash["three"]: ', found, value%short_info()
1922 call messages_info()
1923 class default
1924 write(message(1),*) 'wrong type. found = ',found
1925 call messages_info()
1926 end select
1927
1928 count_clock = 0
1929 count_space = 0
1930
1931 call it%start(h)
1932
1933 do while (it%has_next())
1934 value => it%get_next()
1935 select type(value)
1936 type is (iteration_counter_t)
1937 count_clock = count_clock + 1
1938 type is (space_t)
1939 count_space = count_space + 1
1940 end select
1941 end do
1942
1943 write(message(1), *) 'Count_clock = ', count_clock
1944 write(message(2), *) 'Count_space = ', count_space
1945 call messages_info(2)
1946
1947 call sphash_end(h)
1948
1949 end subroutine test_sphash
1950
1951 ! ---------------------------------------------------------
1952 subroutine test_regridding(namespace, grp)
1953 type(namespace_t), intent(in) :: namespace
1954 type(mpi_grp_t), intent(in) :: grp
1955
1956 type(electrons_t), pointer :: sysA, sysB
1957 type(regridding_t), pointer :: regridding
1958 real(real64), allocatable :: ff_A(:), ff_A_reference(:), ff_B(:), ff_B_reference(:), diff_A(:), diff_B(:)
1959 real(real64) :: norm_ff, norm_diff
1960 integer :: ip, ierr
1961
1962 push_sub(test_regridding)
1963
1964 call calc_mode_par%set_parallelization(p_strategy_states, default=.true.)
1965
1966 sysa => electrons_t(namespace_t("A", namespace), grp, int(option__calculationmode__dummy, int32))
1967 sysb => electrons_t(namespace_t("B", namespace), grp, int(option__calculationmode__dummy, int32))
1968
1969 safe_allocate(ff_a(1:sysa%gr%np))
1970 safe_allocate(ff_a_reference(1:sysa%gr%np))
1971 safe_allocate(diff_a(1:sysa%gr%np))
1972 safe_allocate(ff_b(1:sysb%gr%np))
1973 safe_allocate(ff_b_reference(1:sysb%gr%np))
1974 safe_allocate(diff_b(1:sysb%gr%np))
1975
1976 do ip = 1, sysa%gr%np
1977 ff_a_reference(ip) = values(sysa%gr%x(:, ip))
1978 end do
1979 do ip = 1, sysb%gr%np
1980 ff_b_reference(ip) = values(sysb%gr%x(:, ip))
1981 end do
1982
1983 ! forward mapping A->B
1984 regridding => regridding_t(sysb%gr, sysa%gr, sysa%space, sysa%namespace)
1985 call regridding%do_transfer(ff_b, ff_a_reference)
1986 safe_deallocate_p(regridding)
1987
1988 ! check that mapped function is exactly the same for the points that are available on both grids
1989 do ip = 1, sysb%gr%np
1990 if (abs(ff_b(ip)) <= m_epsilon) then
1991 ff_b_reference(ip) = m_zero
1992 diff_b(ip) = m_zero
1993 else
1994 diff_b(ip) = abs(ff_b_reference(ip) - ff_b(ip))
1995 end if
1996 end do
1997 norm_ff = dmf_nrm2(sysb%gr, ff_b_reference)
1998 norm_diff = dmf_nrm2(sysb%gr, diff_b)
1999
2000 write(message(1),'(a, E14.6)') "Forward: difference of reference to mapped function (rel.): ", &
2001 norm_diff/norm_ff
2002 call messages_info(1, namespace=namespace)
2003
2004 call dio_function_output(io_function_fill_how('AxisX'), ".", "forward_reference", namespace, sysb%space, &
2005 sysb%gr, ff_b_reference, unit_one, ierr)
2006 call dio_function_output(io_function_fill_how('AxisX'), ".", "forward_mapped", namespace, sysb%space, &
2007 sysb%gr, ff_b, unit_one, ierr)
2008 call dio_function_output(io_function_fill_how('AxisX'), ".", "forward_original", namespace, sysa%space, &
2009 sysa%gr, ff_a_reference, unit_one, ierr)
2010
2011 ! backward mapping B->A
2012 regridding => regridding_t(sysa%gr, sysb%gr, sysb%space, sysb%namespace)
2013 call regridding%do_transfer(ff_a, ff_b_reference)
2014 safe_deallocate_p(regridding)
2015
2016 do ip = 1, sysa%gr%np
2017 if (abs(ff_a(ip)) <= m_epsilon) then
2018 ff_a_reference(ip) = m_zero
2019 diff_a(ip) = m_zero
2020 else
2021 diff_a(ip) = abs(ff_a_reference(ip) - ff_a(ip))
2022 end if
2023 end do
2024 norm_ff = dmf_nrm2(sysa%gr, ff_a_reference)
2025 norm_diff = dmf_nrm2(sysa%gr, diff_a)
2026
2027 write(message(1),'(a, E14.6)') "Backward: difference of reference to mapped function (rel.): ", &
2028 norm_diff/norm_ff
2029 call messages_info(1, namespace=namespace)
2030
2031 call dio_function_output(io_function_fill_how('AxisX'), ".", "backward_reference", namespace, sysa%space, &
2032 sysa%gr, ff_a_reference, unit_one, ierr)
2033 call dio_function_output(io_function_fill_how('AxisX'), ".", "backward_mapped", namespace, sysa%space, &
2034 sysa%gr, ff_a, unit_one, ierr)
2035 call dio_function_output(io_function_fill_how('AxisX'), ".", "backward_original", namespace, sysb%space, &
2036 sysb%gr, ff_b_reference, unit_one, ierr)
2037
2038 safe_deallocate_a(ff_a)
2039 safe_deallocate_a(ff_a_reference)
2040 safe_deallocate_a(ff_b)
2041 safe_deallocate_a(ff_b_reference)
2042 safe_deallocate_a(diff_a)
2043 safe_deallocate_a(diff_b)
2044 safe_deallocate_p(sysa)
2045 safe_deallocate_p(sysb)
2046
2047 call messages_info(1, namespace=namespace)
2048
2049 pop_sub(test_regridding)
2050 contains
2051 real(real64) function values(xx)
2052 real(real64), intent(in) :: xx(:)
2053 real(real64) :: xx0(1:size(xx, dim=1))
2054 real(real64), parameter :: aa = m_half
2055 real(real64), parameter :: bb = m_four
2056
2057 ! no push_sub/pop_sub because this function is called often
2058 xx0(:) = m_one
2059 values = bb * exp(-aa*sum((xx-xx0)**2))
2060 end function values
2061 end subroutine test_regridding
2062
2063 ! ---------------------------------------------------------
2064 subroutine test_mesh_generation(namespace, grp)
2065 type(namespace_t), intent(in) :: namespace
2066 type(mpi_grp_t), intent(in) :: grp
2067
2068 type(namespace_t) :: namespace_a, namespace_b
2069 type(electrons_t), pointer :: sysA, sysB
2070 type(regridding_t), pointer :: regridding
2071 real(real64), allocatable :: ff_a(:), ff_b(:), lapl_a(:), lapl_b(:), lapl_b_on_a(:), diff_lapl(:)
2072 real(real64) :: abs_diff, rel_diff, norm_lapl
2073 integer :: ip, dim
2074 real(real64), parameter :: alpha = 0.5_real64
2075
2076 push_sub(test_mesh_generation)
2077
2078 call calc_mode_par%set_parallelization(p_strategy_states, default=.false.)
2079
2080 namespace_a = namespace_t("A", namespace)
2081 namespace_b = namespace_t("B", namespace)
2082
2083 sysa => electrons_t(namespace_a, grp, int(option__calculationmode__dummy, int32))
2084 sysb => electrons_t(namespace_b, grp, int(option__calculationmode__dummy, int32))
2085
2086 assert(sysa%gr%np_global == sysb%gr%np_global)
2087 assert(sysa%st%nst == sysb%st%nst)
2088 assert(sysa%ions%natoms == sysb%ions%natoms)
2089
2090 dim = sysa%gr%box%dim
2091 safe_allocate(ff_a(1:sysa%gr%np_part))
2092 safe_allocate(ff_b(1:sysb%gr%np_part))
2093 safe_allocate(lapl_a(1:sysa%gr%np))
2094 safe_allocate(lapl_b(1:sysb%gr%np))
2095 safe_allocate(lapl_b_on_a(1:sysa%gr%np))
2096 safe_allocate(diff_lapl(1:sysa%gr%np))
2097
2098 do ip = 1, sysa%gr%np_part
2099 ff_a(ip) = gaussian(sysa%gr%x(1:dim, ip), alpha)
2100 end do
2101 do ip = 1, sysb%gr%np_part
2102 ff_b(ip) = gaussian(sysb%gr%x(1:dim, ip), alpha)
2103 end do
2104
2105 call dderivatives_lapl(sysa%gr%der, ff_a, lapl_a, set_bc=.false.)
2106 call dderivatives_lapl(sysb%gr%der, ff_b, lapl_b, set_bc=.false.)
2107
2108 regridding => regridding_t(sysa%gr, sysb%gr, sysb%space, sysb%namespace)
2109 call regridding%do_transfer(lapl_b_on_a, lapl_b)
2110 safe_deallocate_p(regridding)
2111
2112 diff_lapl = lapl_a - lapl_b_on_a
2113 abs_diff = dmf_nrm2(sysa%gr, diff_lapl)
2114 norm_lapl = dmf_nrm2(sysa%gr, lapl_a)
2115 rel_diff = abs_diff/max(norm_lapl, m_epsilon)
2116
2117 assert(rel_diff <= 1.0e-12_real64)
2118
2119 write(message(1), '(a)') "System A initialized"
2120 call messages_info(1, namespace=namespace_a)
2121 write(message(1), '(a)') "System B initialized"
2122 call messages_info(1, namespace=namespace_b)
2123 write(message(1), '(a,es17.10)') "Gaussian Laplacian absolute difference = ", abs_diff
2124 write(message(2), '(a,es17.10)') "Gaussian Laplacian relative difference = ", rel_diff
2125 write(message(3), '(a,es17.10)') "Gaussian Laplacian reference norm = ", norm_lapl
2126 call messages_info(3, namespace=namespace)
2127
2128 safe_deallocate_a(ff_a)
2129 safe_deallocate_a(ff_b)
2130 safe_deallocate_a(lapl_a)
2131 safe_deallocate_a(lapl_b)
2132 safe_deallocate_a(lapl_b_on_a)
2133 safe_deallocate_a(diff_lapl)
2134 safe_deallocate_p(sysa)
2135 safe_deallocate_p(sysb)
2136
2137 pop_sub(test_mesh_generation)
2138 contains
2139 real(real64) function gaussian(x, a) result(val)
2140 real(real64), intent(in) :: x(:)
2141 real(real64), intent(in) :: a
2142
2143 val = exp(-a*sum(x**2))
2144 end function gaussian
2145
2147
2153 subroutine test_vecpot_analytical(namespace, grp)
2154 type(namespace_t), intent(in) :: namespace
2155 type(mpi_grp_t), intent(in) :: grp
2156
2157 class(maxwell_t), pointer :: maxwell_system
2158
2159 real(real64), allocatable :: magnetic_field(:,:)
2160 real(real64), allocatable :: vector_potential_mag(:,:)
2161 real(real64), allocatable :: vector_potential_analytical(:,:)
2162 real(real64), allocatable :: delta(:,:)
2163 real(real64) :: exp_factor
2164 real(real64) :: xx
2165 real(real64) :: yy
2166 real(real64) :: zz
2167 real(real64) :: sigma
2168 integer :: ip, j, ierr, nn
2169 integer(int64) :: out_how
2170 character(len=MAX_PATH_LEN) :: fname, fname2, fname3
2171
2172 out_how = 32
2173 maxwell_system => maxwell_t(namespace, grp)
2174 sigma = maxwell_system%gr%box%bounding_box_l(1)/10_real64 ! this is exponential width
2175
2176 safe_allocate(magnetic_field(1:maxwell_system%gr%np_part, 1:3))
2177 safe_allocate(vector_potential_mag(1:maxwell_system%gr%np_part, 1:3))
2178 safe_allocate(vector_potential_analytical(1:maxwell_system%gr%np_part, 1:3))
2179 safe_allocate(delta(1:maxwell_system%gr%np, 1:3))
2180
2181 !%Variable TestVectorPotentialType
2182 !%Type integer
2183 !%Default bounded
2184 !%Section Calculation Modes::Test
2185 !%Description
2186 !% Select whether bounded or unbounded type will be used for vector potential tests
2187 !%Option bounded 1
2188 !% Analytical Vector Potential formulation is bounded by spatial gaussian
2189 !%Option unbounded 2
2190 !% Analytical Vector Potential is not bounded
2191 !%End
2192 call parse_variable(namespace, 'TestVectorPotentialType', option__testvectorpotentialtype__bounded, nn)
2193
2194 select case (nn)
2195 case (option__testvectorpotentialtype__bounded) ! bounded input
2196 do ip = 1, maxwell_system%gr%np_part
2197 xx = maxwell_system%gr%x(1, ip)
2198 yy = maxwell_system%gr%x(2, ip)
2199 zz = maxwell_system%gr%x(3, ip)
2200 exp_factor = exp((-xx**2 - yy**2 - zz**2)*1/(2*sigma**2))
2201 magnetic_field(ip, 1) = exp_factor*yy*(1 - (-xx**2 + yy**2)/(3*sigma**2) - zz**2/(3*sigma**2))
2202 magnetic_field(ip, 2) = exp_factor * xx * (1 + (-xx**2 + yy**2)/(3*sigma**2) - zz**2/(3*sigma**2))
2203 magnetic_field(ip, 3) = exp_factor * 2 * xx * yy * zz * 1/(3*sigma**2)
2204
2205 vector_potential_analytical(ip, 1) = m_third * xx * zz * exp_factor
2206 vector_potential_analytical(ip, 2) = - m_third * yy * zz * exp_factor
2207 vector_potential_analytical(ip, 3) = m_third * (-xx**2 + yy**2) * exp_factor
2208 end do
2209 case (option__testvectorpotentialtype__unbounded) ! unbounded input,
2210 ! TODO this unit test requires implementation of BCs for Helmholtz decomposition
2211 do ip = 1, maxwell_system%gr%np_part
2212 magnetic_field(ip, 1) = maxwell_system%gr%x(2, ip)
2213 magnetic_field(ip, 2) = maxwell_system%gr%x(1, ip)
2214 magnetic_field(ip, 3) = m_zero
2215
2216 vector_potential_analytical(ip, 1) = m_third * maxwell_system%gr%x(1, ip) * maxwell_system%gr%x(3, ip)
2217 vector_potential_analytical(ip, 2) = - m_third * maxwell_system%gr%x(2, ip) * maxwell_system%gr%x(3, ip)
2218 vector_potential_analytical(ip, 3) = - m_third * (maxwell_system%gr%x(1, ip)**2 - maxwell_system%gr%x(2, ip)**2)
2219 end do
2220 end select
2221 call maxwell_system%helmholtz%get_vector_potential(namespace, vector_potential_mag, magnetic_field)
2222
2223 do j = 1, 3
2224 delta(:,:) = m_zero
2225 do ip = 1, maxwell_system%gr%np
2226 delta(ip,j) = vector_potential_analytical(ip, j) - vector_potential_mag(ip, j)
2227 end do
2228 end do
2229
2230 do j = 1, 3
2231 write(message(j),*) 'j, norm2(delta)', j, norm2(delta(:,j))
2232 end do
2233 call messages_info(3)
2235 write(fname, '(a)') 'deviation_from_analytical_formulation' ! use messages later
2236 call io_function_output_vector(out_how , './' , trim(fname), namespace, maxwell_system%space, maxwell_system%gr, &
2237 delta, unit_one, ierr)
2238 write(fname2, '(a)') 'vector_potential_analytical'
2239 call io_function_output_vector(out_how , './' , trim(fname2), namespace, maxwell_system%space, maxwell_system%gr, &
2240 vector_potential_analytical, unit_one, ierr)
2241 write(fname3, '(a)') 'vector_potential_mag'
2242 call io_function_output_vector(out_how , './' , trim(fname3), namespace, maxwell_system%space, maxwell_system%gr, &
2243 vector_potential_mag, unit_one, ierr)
2244
2245 safe_deallocate_a(magnetic_field)
2246 safe_deallocate_a(vector_potential_mag)
2247 safe_deallocate_a(vector_potential_analytical)
2248 safe_deallocate_a(delta)
2249 safe_deallocate_p(maxwell_system)
2250
2251 end subroutine test_vecpot_analytical
2252
2253 ! ---------------------------------------------------------
2254 subroutine multigrid_test_interpolation(mgrid, space)
2255 type(multigrid_t), intent(in) :: mgrid
2256 class(space_t), intent(in) :: space
2257
2258 real(real64), allocatable :: guess0(:), res0(:), guess1(:)
2259 type(mesh_t), pointer :: mesh0, mesh1
2260 real(real64) :: delta, xx(3,2), alpha, beta, rr
2261 integer :: nn, ip, ierr
2262
2264
2265 message(1) = 'Info: Testing the grid interpolation.'
2266 message(2) = ''
2267 call messages_info(2)
2268
2269 mesh0 => mgrid%level(0)%mesh
2270 mesh1 => mgrid%level(1)%mesh
2271
2272 safe_allocate(guess0(1:mesh0%np_part))
2273 safe_allocate(res0(1:mesh0%np_part))
2274 safe_allocate(guess1(1:mesh1%np_part))
2275
2276 alpha = m_four*mesh0%spacing(1)
2277 beta = m_one / (alpha**space%dim * sqrt(m_pi)**space%dim)
2278
2279 ! Set the centers of the Gaussians by hand
2280 xx(1, 1) = m_one
2281 xx(2, 1) = -m_half
2282 xx(3, 1) = m_two
2283 xx(1, 2) = -m_two
2284 xx(2, 2) = m_zero
2285 xx(3, 2) = -m_one
2286 xx = xx * alpha
2287
2288 ! Density as sum of Gaussians
2289 guess0 = m_zero
2290 do nn = 1, 2
2291 do ip = 1, mesh0%np
2292 call mesh_r(mesh0, ip, rr, origin = xx(:, nn))
2293 guess0(ip) = guess0(ip) + (-1)**nn * beta*exp(-(rr/alpha)**2)
2294 end do
2295 end do
2296
2297 call dio_function_output (io_function_fill_how('AxisX'), ".", "interpolation_target", global_namespace, &
2298 space, mesh0, guess0, unit_one, ierr)
2299 call dio_function_output (io_function_fill_how('AxisZ'), ".", "interpolation_target", global_namespace, &
2300 space, mesh0, guess0, unit_one, ierr)
2301 call dio_function_output (io_function_fill_how('PlaneZ'), ".", "interpolation_target", global_namespace, &
2302 space, mesh0, guess0, unit_one, ierr)
2303
2304 ! We start by testing the interpolation scheme. For this, we generate a function on the fine grid
2305 ! and we inject it on the coarse grid. Then we interpolate it back to the fine grid and we compare
2306 ! This allows for testing the quality of the interpolation scheme
2307
2308 ! move to level 1
2309 call dmultigrid_fine2coarse(mgrid%level(1)%tt, mgrid%level(0)%der, mesh1, guess0, guess1, injection)
2310 ! back to level 0
2311 call dmultigrid_coarse2fine(mgrid%level(1)%tt, mgrid%level(1)%der, mesh0, guess1, res0)
2312
2313 call dio_function_output (io_function_fill_how('AxisX'), ".", "interpolation_result", global_namespace, &
2314 space, mesh0, res0, unit_one, ierr)
2315 call dio_function_output (io_function_fill_how('AxisZ'), ".", "interpolation_result", global_namespace, &
2316 space, mesh0, res0, unit_one, ierr)
2317 call dio_function_output (io_function_fill_how('PlaneZ'), ".", "interpolation_result", global_namespace, &
2318 space, mesh0, res0, unit_one, ierr)
2319
2320 delta = dmf_nrm2(mesh0, guess0(1:mesh0%np)-res0(1:mesh0%np))
2321 write(message(1),'(a,e13.6)') 'Interpolation test (abs.) = ', delta
2322
2323 ! Now we test if the restriction+interpolation combination returns the original result or not
2324 ! This allows to test if restriction and interpolation are adjoint operators or not.
2325
2326 ! move to level 1
2327 call dmultigrid_fine2coarse(mgrid%level(1)%tt, mgrid%level(0)%der, mesh1, guess0, guess1, fullweight)
2328 ! back to level 0
2329 call dmultigrid_coarse2fine(mgrid%level(1)%tt, mgrid%level(1)%der, mesh0, guess1, res0)
2330
2331 call dio_function_output (io_function_fill_how('AxisX'), ".", "restriction_result", global_namespace, &
2332 space, mesh0, res0, unit_one, ierr)
2333 call dio_function_output (io_function_fill_how('AxisZ'), ".", "restriction_result", global_namespace, &
2334 space, mesh0, res0, unit_one, ierr)
2335 call dio_function_output (io_function_fill_how('PlaneZ'), ".", "restriction_result", global_namespace, &
2336 space, mesh0, res0, unit_one, ierr)
2337
2338 delta = dmf_nrm2(mesh0, guess0(1:mesh0%np)-res0(1:mesh0%np))
2339 write(message(2),'(a,e13.6)') 'Restriction test (abs.) = ', delta
2340 call messages_info(2)
2341
2342 safe_deallocate_a(guess0)
2343 safe_deallocate_a(res0)
2344 safe_deallocate_a(guess1)
2345
2347 end subroutine multigrid_test_interpolation
2348
2351 subroutine test_current_density(namespace, grp)
2352 type(namespace_t), intent(in) :: namespace
2353 type(mpi_grp_t), intent(in) :: grp
2354 type(electrons_t), pointer :: sys
2355
2356 type(current_t) :: current
2357 character(len=MAX_PATH_LEN) :: fname
2358 integer :: ierr, ip, idir
2359 integer(int64) :: out_how
2360 real(real64), allocatable :: current_para_ref(:,:), current_dia_ref(:,:), current_mag_ref(:,:), delta(:)
2361 real(real64) :: xx(3), rr, a0, mag_curr, sin_thet, sin_phi, cos_phi, vec_pot_slope
2362 complex(real64) :: alpha
2363
2364 sys => electrons_t(namespace, grp, int(option__calculationmode__dummy, int32))
2365
2366 alpha = (0.0_real64, 0.5_real64)
2367 a0 = m_one
2368 vec_pot_slope = 0.4_real64 ! units of B field
2369
2370 call states_elec_allocate_wfns(sys%st, sys%gr, wfs_type = type_cmplx)
2371 call set_hydrogen_states(sys%st%group%psib(1, 1), sys%gr, namespace, alpha, a0)
2372
2373 call current_init(current, namespace)
2374
2375 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
2376
2377 safe_allocate(sys%hm%hm_base%vector_potential(1:3, 1:sys%gr%np))
2378
2379 sys%hm%hm_base%vector_potential = m_zero
2380 do ip = 1, sys%gr%np
2381 xx = sys%gr%x(1:3, ip)
2382 sys%hm%hm_base%vector_potential(2, ip) = vec_pot_slope * xx(1) / p_c ! vector potential is here devided by c_0
2383 end do
2384
2385 call states_elec_allocate_current(sys%st, sys%space, sys%gr)
2386 call density_calc(sys%st, sys%gr, sys%st%rho)
2387 ! paramagnetic + diamagnetic current densities
2388 call current_calculate(current, namespace, sys%gr, sys%hm, sys%space, sys%st)
2389
2390 safe_allocate(current_para_ref(1:sys%gr%np,1:3))
2391 safe_allocate(current_dia_ref(1:sys%gr%np,1:3))
2392 safe_allocate(current_mag_ref(1:sys%gr%np,1:3))
2393 safe_allocate(delta(1:sys%gr%np))
2394
2395 ! analytic paramagnetic
2396 current_para_ref(:,:) = m_zero
2397 do ip = 1, sys%gr%np
2398 call mesh_r(sys%gr, ip, rr)
2399 xx = sys%gr%x(1:3, ip)
2400 if (rr > r_small) then
2401 current_para_ref(ip,1:3) = - (psi_2s(rr, a0) * dr_psi_1s(rr, a0) - &
2402 psi_1s(rr, a0) * dr_psi_2s(rr, a0) ) * aimag(alpha) / (1 + abs(alpha)**2) * xx(1:3) / rr
2403 end if
2404 end do
2405
2406 write(fname, '(a)') 'current_para'
2407 out_how = io_function_fill_how("PlaneZ")
2408 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2409 sys%st%current_para(:,:,1), unit_one, ierr)
2410
2411 write(fname, '(a)') 'current_para-ref'
2412 out_how = io_function_fill_how("PlaneZ")
2413 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2414 current_para_ref(:,:), unit_one, ierr)
2415
2416 do idir = 1, 3
2417 delta = m_zero
2418 delta(:) = current_para_ref(1:sys%gr%np, idir) - sys%st%current_para(1:sys%gr%np, idir, 1)
2419 write(message(idir),*) 'idir =',idir,', norm2(delta paramagnetic)',norm2(delta)
2420 end do
2421 call messages_info(3)
2422
2423 ! analytic diamagnetic
2424 current_dia_ref(:,:) = m_zero
2425 do ip = 1, sys%gr%np
2426 call mesh_r(sys%gr, ip, rr)
2427 current_dia_ref(ip,1:3) = - sys%hm%hm_base%vector_potential(1:3,ip) *&
2428 m_one / (1 + abs(alpha)**2) * abs(lc_hydrogen_state(rr, alpha, a0))**2
2429 end do
2430
2431 write(fname, '(a)') 'current_dia'
2432 out_how = io_function_fill_how("PlaneZ")
2433 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2434 sys%st%current_dia(:,:,1), unit_one, ierr)
2435
2436 write(fname, '(a)') 'current_dia-ref'
2437 out_how = io_function_fill_how("PlaneZ")
2438 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2439 current_dia_ref(:,:), unit_one, ierr)
2440
2441 do idir = 1, 3
2442 delta = m_zero
2443 delta(:) = current_dia_ref(1:sys%gr%np, idir) - sys%st%current_dia(1:sys%gr%np, idir, 1)
2444 write(message(idir),*) 'idir =',idir,', norm2(delta diamagnetic)',norm2(delta)
2445 end do
2446 call messages_info(3)
2447
2448 ! magnetization current
2449 call current_calculate_mag(sys%gr%der, sys%st)
2450
2451 ! analytic magnetization
2452 current_mag_ref(:,:) = m_zero
2453 do ip = 1, sys%gr%np
2454 call mesh_r(sys%gr, ip, rr)
2455 xx = sys%gr%x(1:3, ip)
2456 if (norm2(xx(1:2)) > r_small .and. rr > r_small) then
2457 sin_thet = norm2(xx(1:2)) / rr
2458 sin_phi = xx(2) / norm2(xx(1:2))
2459 cos_phi = xx(1) / norm2(xx(1:2))
2460 mag_curr = m_two * (psi_1s(rr,a0)*dr_psi_1s(rr,a0) + real(alpha)*(psi_1s(rr,a0)*dr_psi_2s(rr,a0) &
2461 + dr_psi_1s(rr,a0)*psi_2s(rr,a0)) + abs(alpha)**2 * psi_2s(rr,a0)*dr_psi_2s(rr,a0))
2462 ! minus signs are reversed because of the charge of the electron
2463 current_mag_ref(ip,1) = m_half * mag_curr * sin_thet * sin_phi / (1+abs(alpha)**2)
2464 current_mag_ref(ip,2) = -m_half * mag_curr * sin_thet * cos_phi / (1+abs(alpha)**2)
2465 endif
2466 end do
2467
2468 write(fname, '(a)') 'current_mag'
2469 out_how = io_function_fill_how("PlaneZ")
2470 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2471 sys%st%current_mag(:,:,1), unit_one, ierr)
2472
2473 write(fname, '(a)') 'current_mag-ref'
2474 out_how = io_function_fill_how("PlaneZ")
2475 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2476 current_mag_ref(:,:), unit_one, ierr)
2477
2478 do idir = 1, 3
2479 delta = m_zero
2480 delta(:) = current_mag_ref(1:sys%gr%np, idir) - sys%st%current_mag(1:sys%gr%np, idir, 1)
2481 write(message(idir),*) 'idir =',idir,', norm2(delta magnetization)',norm2(delta)
2482 end do
2483 call messages_info(3)
2484
2485 safe_deallocate_a(current_para_ref)
2486 safe_deallocate_a(current_dia_ref)
2487 safe_deallocate_a(current_mag_ref)
2488 safe_deallocate_a(delta)
2489 safe_deallocate_p(sys)
2490
2491 end subroutine test_current_density
2492
2493
2494 subroutine set_hydrogen_states(psib, mesh, namespace, alpha, a0)
2495 class(batch_t), intent(inout) :: psib
2496 class(mesh_t), intent(in) :: mesh
2497 type(namespace_t), intent(in) :: namespace
2498 complex(real64), intent(in) :: alpha
2499 real(real64), intent(in) :: a0
2500
2501 complex(real64), allocatable :: zff(:)
2502 integer :: ip
2503 real(real64) :: rr
2504
2505 push_sub(set_hydrogen_states)
2506
2507 ! psi = phi_{1s} + \alpha \phi_{2s}
2508 safe_allocate(zff(1:mesh%np))
2509 if (type_is_complex(psib%type())) then
2510 do ip = 1, mesh%np
2511 call mesh_r(mesh, ip, rr)
2512 zff(ip) = m_one / sqrt(1 + abs(alpha)**2) * lc_hydrogen_state(rr, alpha, a0)
2513 end do
2514 call batch_set_state(psib, 1, mesh%np, zff)
2515 else
2516 write(message(1),*) "States should be complex for the linear combination of hydrogenic states to work"
2517 call messages_info(1, namespace=namespace)
2518 end if
2519 safe_deallocate_a(zff)
2520
2521 pop_sub(set_hydrogen_states)
2522 end subroutine set_hydrogen_states
2523
2524 complex(real64) function lc_hydrogen_state(rr, alpha, a0)
2525 real(real64), intent(in) :: a0, rr
2526 complex(real64), intent(in) :: alpha
2527
2528 lc_hydrogen_state = psi_1s(rr, a0) + alpha * psi_2s(rr, a0)
2529 end function lc_hydrogen_state
2530
2531 ! phi_{1s} = R_{10}(r)Y_{00}(\theta, \phi) = 1/(2\sqrt(\pi)) * 2 a0^{-3/2} * \exp(-r/a0)
2532 real(real64) function psi_1s(rr, a0)
2533 real(real64), intent(in) :: a0, rr
2534
2535 psi_1s = a0**(-m_three/m_two) * exp(-rr / a0) / sqrt(m_pi)
2536 end function psi_1s
2537
2538 ! phi_{2s} = R_{20}(r)Y_{00}(\theta, \phi) = 1/(2\sqrt(\pi)) * \sqrt(2) a0^{-3/2} (1 - r/(2a0)) \exp(-r/(2a0))
2539 real(real64) function psi_2s(rr, a0)
2540 real(real64), intent(in) :: a0, rr
2541
2542 psi_2s = sqrt(m_two) * a0**(-m_three/m_two) * (m_one - rr/(m_two * a0)) * exp(-rr/(m_two * a0)) &
2543 / (m_two * sqrt(m_pi))
2544 end function psi_2s
2545
2546 real(real64) function dr_psi_1s(rr, a0)
2547 real(real64), intent(in) :: a0, rr
2548
2549 dr_psi_1s = -(m_one / a0) * psi_1s(rr, a0)
2550 end function dr_psi_1s
2551
2552 real(real64) function dr_psi_2s(rr, a0)
2553 real(real64), intent(in) :: a0, rr
2554
2555 dr_psi_2s = -(m_half / a0) * psi_2s(rr, a0) - &
2556 a0**(-m_five/m_two) * exp(-rr/(m_two * a0)) / (sqrt(m_two) * m_two * sqrt(m_pi))
2557 end function dr_psi_2s
2558
2559
2560 subroutine test_csv_input(namespace)
2561 type(namespace_t), intent(in) :: namespace
2562
2563 integer :: ierr
2564 integer(int64) :: i, j, k
2565 integer(int64) :: dims(3)
2566 character(len=MAX_PATH_LEN) :: fname
2567
2568 real(real64), allocatable :: ff(:)
2569
2570 push_sub(test_csv_input)
2571
2572 !%Variable TestCSVFileName
2573 !%Type string
2574 !%Section Calculation Modes::Test
2575 !%Description
2576 !% The file name of the csv file to be read
2577 !%End
2578 call parse_variable(namespace, 'TestCSVFileName', "", fname)
2579
2580 message(1) = "Attempting to probe "//trim(fname)
2581 call messages_info(1, namespace=namespace)
2582
2583 call io_csv_get_info(fname, dims, ierr)
2584 if (ierr == 0) then
2585 message(1) = "Probing successful."
2586 write(message(2), '("found dimensions: ",3I20)') dims
2587 call messages_info(2, namespace=namespace)
2588 else
2589 write(message(1),'("Probing failed. ierr = ",I5)') ierr
2590 call messages_fatal(1, namespace=namespace)
2591 end if
2592
2593 safe_allocate(ff(1:dims(1)*dims(2)*dims(3)))
2594
2595 message(1) = "Attempting to read "//trim(fname)
2596 call messages_info(1, namespace=namespace)
2597
2598 call dread_csv(fname, dims(1)*dims(2)*dims(3), ff, ierr)
2599 if (ierr == 0) then
2600 message(1) = "Reading successful."
2601 call messages_info(1, namespace=namespace)
2602
2603 do k=1, min(4_int64, dims(3))
2604 do j=1, min(4_int64, dims(2))
2605 write(message(j), '("data ",2I5, 1X, 4F8.2)') k, j, &
2606 (ff(i + dims(1)*(j-1) + dims(1)* dims(2)*(k-1)), i=1, min(4_int64, dims(1)))
2607 end do
2608 write(message(int(j, int32)), '("")')
2609 call messages_info(int(j, int32), namespace=namespace)
2610 end do
2611
2612 else
2613 message(1) = "Reading failed."
2614 call messages_fatal(1, namespace=namespace)
2615 end if
2616
2617 safe_deallocate_a(ff)
2618
2620 end subroutine test_csv_input
2621
2622end module test_oct_m
2623
2624!! Local Variables:
2625!! mode: f90
2626!! coding: utf-8
2627!! End:
batchified version of the BLAS axpy routine:
Definition: batch_ops.F90:159
batchified multiplication by mesh function with optional conjugation:
Definition: batch_ops.F90:254
batchified scale with optional conjugation:
Definition: batch_ops.F90:181
scale a batch by a constant or vector
Definition: batch_ops.F90:167
There are several ways how to call batch_set_state and batch_get_state:
Definition: batch_ops.F90:218
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:182
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
pure logical function, public accel_is_enabled()
Definition: accel.F90:403
This module implements batches of mesh functions.
Definition: batch.F90:135
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
subroutine, public dbatch_ax_function_py(np, aa, psi, yy)
This routine performs a set of axpy operations adding the same function psi to all functions of a bat...
Definition: batch_ops.F90:1198
subroutine, public batch_set_zero(this, np, async)
fill all mesh functions of the batch with zero
Definition: batch_ops.F90:265
subroutine, public zbatch_ax_function_py(np, aa, psi, yy)
This routine performs a set of axpy operations adding the same function psi to all functions of a bat...
Definition: batch_ops.F90:3099
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:124
Module, implementing a factory for boxes.
This module handles the calculation mode.
integer, parameter, public p_strategy_kpoints
parallelization in k-points
integer, parameter, public p_strategy_domains
parallelization in domains
type(calc_mode_par_t), public calc_mode_par
Singleton instance of parallel calculation mode.
integer, parameter, public p_strategy_states
parallelization in states
subroutine, public cgal_polyhedron_init(cgal_poly, fname, verbose)
logical function, public cgal_polyhedron_point_inside(cgal_poly, xq, yq, zq)
subroutine, public cgal_polyhedron_end(cgal_poly)
pure real(real64) function center(this)
Center of the filter interval.
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:653
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
This module provides unit tests for the derivatives.
subroutine, public zderivatives_test(this, namespace, repetitions, min_blocksize, max_blocksize)
unit test for derivatives
subroutine, public dderivatives_test(this, namespace, repetitions, min_blocksize, max_blocksize)
unit test for derivatives
subroutine, public derivatives_advanced_benchmark(this, namespace)
Further unit tests design to challenge numerical stability of the finite differences.
subroutine, public zchebyshev_filter(namespace, mesh, st, hm, degree, bounds, ik, normalize)
Chebyshev Filter.
subroutine, public dchebyshev_filter(namespace, mesh, st, hm, degree, bounds, ik, normalize)
Chebyshev Filter.
integer, parameter, public spin_polarized
subroutine, public exponential_init(te, namespace, full_batch)
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_four
Definition: global.F90:204
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:198
complex(real64), parameter, public m_zi
Definition: global.F90:214
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_half
Definition: global.F90:206
real(real64), parameter, public m_one
Definition: global.F90:201
This module implements the underlying real-space grid.
Definition: grid.F90:119
subroutine, public zhamiltonian_elec_apply_batch(hm, namespace, mesh, psib, hpsib, terms, set_bc)
subroutine, public hamiltonian_elec_end(hm)
subroutine, public hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
subroutine, public hamiltonian_elec_copy(hm_out, hm_in)
Deep-copy a hamiltonian_elec_t snapshot.
subroutine, public dhamiltonian_elec_apply_batch(hm, namespace, mesh, psib, hpsib, terms, set_bc)
type(hardware_t), public cpu_hardware
Global instance of CPU hardware specification.
Definition: hardware.F90:61
integer, parameter, public sizeof_real64
Number of bytes to store a variable of type real(real64)
Definition: hardware.F90:55
integer, parameter, public sizeof_complex64
Number of bytes to store a variable of type complex(real64)
Definition: hardware.F90:58
The Helmholtz decomposition is intended to contain "only mathematical" functions and procedures to co...
Test suit for the Helmholtz decomposition module.
subroutine, public gaussian_test(helmholtz, sys_grid, namespace, space)
subroutine, public hertzian_dipole_test(helmholtz, sys_grid, namespace, space)
This module implements a simple hash table for non-negative integer keys and integer values.
Definition: iihash.F90:127
subroutine, public iihash_end(h)
Free a hash table.
Definition: iihash.F90:186
subroutine, public iihash_insert(h, key, val)
Insert a (key, val) pair into the hash table h.
Definition: iihash.F90:208
integer function, public iihash_lookup(h, key, found)
Look up a value in the hash table h. If found is present, it indicates if key could be found in the t...
Definition: iihash.F90:233
subroutine, public iihash_init(h)
Initialize a hash table h.
Definition: iihash.F90:163
subroutine, public dio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
Top-level IO routine for functions defined on the mesh.
integer(int64) function, public io_function_fill_how(where)
Use this function to quickly plot functions for debugging purposes: call dio_function_output(io_funct...
Definition: io.F90:116
subroutine, public ion_interaction_test(space, latt, atom, natoms, pos, lsize, namespace, mc)
This modules takes care of testing some linear algebra routines.
subroutine, public test_exponential_matrix(namespace)
Unit tests for the exponential of a matrix.
Computes and , suitable as an operator callback for iterative solvers (CG, QMR, etc....
subroutine, public dshifted_laplacian_op(x, lx, userdata)
Computes the shifted Laplacian operator: .
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:118
subroutine, public dmesh_batch_dotp_matrix(mesh, aa, bb, dot, reduce)
Calculate the overlap matrix of two batches.
Definition: mesh_batch.F90:273
subroutine, public dmesh_batch_dotp_self(mesh, aa, dot, reduce)
calculate the overlap matrix of a batch with itself
Definition: mesh_batch.F90:536
subroutine, public mesh_batch_nrm2(mesh, aa, nrm2, reduce)
Calculate the norms (norm2, not the square!) of a batch of mesh functions.
Definition: mesh_batch.F90:178
subroutine, public zmesh_batch_dotp_vector(mesh, aa, bb, dot, reduce, cproduct)
A simple switch between specialized kernels and generic kernels.
subroutine, public zmesh_batch_dotp_matrix(mesh, aa, bb, dot, reduce)
Calculate the overlap matrix of two batches.
subroutine, public zmesh_batch_normalize(mesh, psib, norm)
Normalize a batch.
subroutine, public zmesh_batch_dotp_self(mesh, aa, dot, reduce)
calculate the overlap matrix of a batch with itself
subroutine, public dmesh_batch_normalize(mesh, psib, norm)
Normalize a batch.
subroutine, public dmesh_batch_dotp_vector(mesh, aa, bb, dot, reduce, cproduct)
A simple switch between specialized kernels and generic kernels.
Definition: mesh_batch.F90:652
This module defines various routines, operating on mesh functions.
real(real64) function, public dmf_dotp_aux(f1, f2)
dot product between two vectors (mesh functions)
subroutine, public mesh_init_mesh_aux(mesh)
Initialise a pointer to the grid/mesh, that is globally exposed, such that low level mesh operations ...
subroutine, public zmesh_interpolation_test(mesh)
subroutine, public dmesh_interpolation_test(mesh)
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
pure subroutine, public mesh_r(mesh, ip, rr, origin, coords)
return the distance to the origin for a given grid point
Definition: mesh.F90:342
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:898
character(len=512), private msg
Definition: messages.F90:167
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1000
subroutine, public messages_new_line()
Definition: messages.F90:1089
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
This modules takes care of testing optimizers using standard test functions.
subroutine, public test_optimizers(namespace)
Unit tests for different optimizers.
This module implements unit tests for the mixing methods.
Definition: mix_tests.F90:117
subroutine, public mix_tests_run()
Definition: mix_tests.F90:138
subroutine, public test_mpiwrappers
Definition: mpi_test.F90:130
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
subroutine, public multigrid_end(mgrid)
Definition: multigrid.F90:518
subroutine, public multigrid_init(mgrid, namespace, space, mesh, der, stencil, mc, nlevels)
Definition: multigrid.F90:187
type(namespace_t), public global_namespace
Definition: namespace.F90:135
subroutine, public orbitalbasis_end(this)
subroutine, public zorbitalbasis_build(this, namespace, ions, mesh, kpt, ndim, skip_s_orb, use_all_orb, verbose)
This routine is an interface for constructing the orbital basis.
subroutine, public dorbitalbasis_build(this, namespace, ions, mesh, kpt, ndim, skip_s_orb, use_all_orb, verbose)
This routine is an interface for constructing the orbital basis.
subroutine, public orbitalbasis_init(this, namespace, periodic_dim)
subroutine, public dorbitalset_add_to_batch(os, ndim, psib, weight)
Definition: orbitalset.F90:864
subroutine, public zorbitalset_add_to_batch(os, ndim, psib, weight)
subroutine, public orbitalset_update_phase(os, dim, kpt, kpoints, spin_polarized, vec_pot, vec_pot_var, kpt_max)
Build the phase correction to the global phase in case the orbital crosses the border of the simulato...
Definition: orbitalset.F90:285
subroutine, public dorbitalset_get_coeff_batch(os, ndim, psib, dot, reduce)
Definition: orbitalset.F90:589
subroutine, public zorbitalset_get_coeff_batch(os, ndim, psib, dot, reduce)
subroutine, public poisson_test(this, space, mesh, latt, namespace, repetitions)
This routine checks the Hartree solver selected in the input file by calculating numerically and anal...
subroutine, public preconditioner_end(this)
subroutine, public preconditioner_init(this, namespace, gr, mc, space)
subroutine, public zproject_psi_batch(mesh, bnd, pj, npj, dim, psib, ppsib)
To optimize the application of the non-local operator in parallel, the projectors are applied in step...
Definition: projector.F90:1257
Implementation details for regridding.
Definition: regridding.F90:172
This module implements a simple hash table for string valued keys and integer values using the C++ ST...
Definition: sihash.F90:120
subroutine, public sihash_insert(h, key, val)
Insert a (key, val) pair into the hash table h.
Definition: sihash.F90:205
subroutine, public sihash_init(h)
Initialize a hash table h with size entries. Since we use separate chaining, the number of entries in...
Definition: sihash.F90:164
integer function, public sihash_lookup(h, key, found)
Look up a value in the hash table h. If found is present, it indicates if key could be found in the t...
Definition: sihash.F90:231
subroutine, public sihash_end(h)
Free a hash table.
Definition: sihash.F90:185
This module is intended to contain "only mathematical" functions and procedures.
Definition: solvers.F90:117
This module implements a simple hash table for string valued keys and integer values using the C++ ST...
Definition: sphash.F90:120
subroutine, public sphash_init(h)
Initialize a hash table h with size entries. Since we use separate chaining, the number of entries in...
Definition: sphash.F90:223
subroutine, public sphash_insert(h, key, val, clone)
Insert a (key, val) pair into the hash table h. If clone=.true., the object will be copied.
Definition: sphash.F90:293
subroutine, public sphash_end(h)
Free a hash table.
Definition: sphash.F90:249
class(*) function, pointer, public sphash_lookup(h, key, found)
Look up a value in the hash table h. If found is present, it indicates if key could be found in the t...
Definition: sphash.F90:325
pure logical function, public states_are_real(st)
subroutine, public zstates_elec_calc_orth_test(st, namespace, mesh, kpoints)
subroutine, public dstates_elec_calc_orth_test(st, namespace, mesh, kpoints)
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public states_elec_deallocate_wfns(st)
Deallocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public dsubspace_diag(this, namespace, mesh, st, hm, ik, eigenval, diff, nonortho)
Diagonalises the Hamiltonian in the subspace defined by the states.
Definition: subspace.F90:298
subroutine, public zsubspace_diag(this, namespace, mesh, st, hm, ik, eigenval, diff, nonortho)
Diagonalises the Hamiltonian in the subspace defined by the states.
Definition: subspace.F90:769
Integration tests for ISDF.
Definition: test_isdf.F90:116
subroutine, public test_isdf(namespace, serial)
Set up an electron system, compute some optimal centroid positions, and use these to build a set of I...
Definition: test_isdf.F90:156
subroutine, public test_weighted_kmeans(namespace)
Test weighted kmeans algorithm for a finite system.
This module implements a unit-test like runmode for Octopus.
Definition: test.F90:117
real(real64) function psi_2s(rr, a0)
Definition: test.F90:2635
subroutine test_sihash()
Definition: test.F90:1909
subroutine test_cgal()
Definition: test.F90:1731
subroutine test_ion_interaction(namespace, grp)
Definition: test.F90:1607
subroutine test_hartree(param, namespace, grp)
Definition: test.F90:397
subroutine test_interpolation(param, namespace, grp)
Definition: test.F90:1569
subroutine test_helmholtz_decomposition(namespace, grp)
Definition: test.F90:416
subroutine test_iihash()
Definition: test.F90:1883
subroutine test_current_density(namespace, grp)
Here we test the different contributions to the total electronic current density.
Definition: test.F90:2447
subroutine test_derivatives(param, namespace, grp)
Definition: test.F90:1493
real(real64) function psi_1s(rr, a0)
Definition: test.F90:2628
subroutine test_batch_set_gaussian(psib, mesh)
Definition: test.F90:1810
subroutine test_boundaries(param, namespace, grp)
Definition: test.F90:870
subroutine test_sphash(namespace)
Definition: test.F90:1955
subroutine test_hamiltonian(param, namespace, grp)
Definition: test.F90:676
subroutine test_dense_eigensolver()
Definition: test.F90:1751
subroutine multigrid_test_interpolation(mgrid, space)
Definition: test.F90:2350
subroutine test_projector(param, namespace, grp)
Definition: test.F90:510
real(real64) function dr_psi_2s(rr, a0)
Definition: test.F90:2648
subroutine test_composition_chebyshev(namespace, grp)
Test the composition rule for Chebyshev polynomials.
Definition: test.F90:909
complex(real64) function lc_hydrogen_state(rr, alpha, a0)
Definition: test.F90:2620
subroutine test_subspace_diagonalization(param, namespace, grp)
Definition: test.F90:1052
subroutine, public test_run(namespace, grp)
Components and integration test runner.
Definition: test.F90:214
subroutine test_density_calc(param, namespace, grp)
Definition: test.F90:832
subroutine test_linear_solver(namespace, grp)
Definition: test.F90:447
subroutine test_prints_info_batch(st, gr, psib, string)
Definition: test.F90:1627
subroutine test_orthogonalization(param, namespace, grp)
Definition: test.F90:1527
real(real64) function dr_psi_1s(rr, a0)
Definition: test.F90:2642
subroutine test_regridding(namespace, grp)
Definition: test.F90:2048
subroutine test_batch_ops(param, namespace, grp)
Definition: test.F90:1105
subroutine test_vecpot_analytical(namespace, grp)
Here, analytical formulation for vector potential and B field are used. Ref: Sangita Sen and Erik I....
Definition: test.F90:2249
subroutine test_exponential(param, namespace, grp)
Definition: test.F90:1003
subroutine test_mesh_generation(namespace, grp)
Definition: test.F90:2160
subroutine set_hydrogen_states(psib, mesh, namespace, alpha, a0)
Definition: test.F90:2590
subroutine test_dft_u(param, namespace, grp)
Definition: test.F90:562
subroutine test_grid_interpolation(grp)
Definition: test.F90:1862
subroutine test_csv_input(namespace)
Definition: test.F90:2656
subroutine test_clock()
Definition: test.F90:1672
type(type_t), parameter, public type_cmplx
Definition: types.F90:136
logical pure function, public type_is_complex(this)
Definition: types.F90:182
This module defines the unit system, used for input and output.
type(unit_t), public unit_one
some special units required for particular quantities
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Definition: v_ks.F90:754
Class defining batches of mesh functions.
Definition: batch.F90:161
Class describing the electron system.
Definition: electrons.F90:221
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
This class implements the iteration counter used by the multisystem algorithms. As any iteration coun...
Describes mesh distribution to nodes.
Definition: mesh.F90:187
This is defined even when running serial.
Definition: mpi.F90:144
contains the information of the meshes and provides the transfer functions
Definition: regridding.F90:198
The states_elec_t class contains all electronic wave functions.
batches of electronic states
Definition: wfs_elec.F90:141
int true(void)
subroutine write_clock(operation)
Definition: test.F90:1712
real(real64) function gaussian(x, a)
Definition: test.F90:2235
subroutine write_condition_result(condition, result)
Definition: test.F90:1719
real(real64) function values(xx)
Definition: test.F90:2147