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
21#include "global.h"
22
23module test_oct_m
24 use batch_oct_m
27 use box_oct_m
32 use clock_oct_m
33 use debug_oct_m
37 use global_oct_m
38 use grid_oct_m
43 use iihash_oct_m
45 use iso_c_binding
46 use io_oct_m
50 use mesh_oct_m
56 use mpi_oct_m
63 use parser_oct_m
69 use sihash_oct_m
71 use space_oct_m
72 use sphash_oct_m
81 use types_oct_m
82 use v_ks_oct_m
86
87 implicit none
88
90 private
91 integer :: type
92 integer :: repetitions
93 integer :: min_blocksize
94 integer :: max_blocksize
95 end type test_parameters_t
96
97 !Auxiliary quantities needed by the linear solver
98 float :: shift_aux
99 type(derivatives_t), pointer :: der_aux => null()
100 type(preconditioner_t) :: prec_aux
101
102 public :: test_run
103
104contains
105
106 ! ---------------------------------------------------------
107 subroutine test_run(namespace)
108 type(namespace_t), intent(in) :: namespace
109
110 type(test_parameters_t) :: param
111 integer :: test_mode
112
114
115 call messages_obsolete_variable(namespace, 'WhichTest', 'TestMode')
116
117 !%Variable TestMode
118 !%Type integer
119 !%Default hartree
120 !%Section Calculation Modes::Test
121 !%Description
122 !% Decides what kind of test should be performed.
123 !%Option hartree 1
124 !% Tests the Poisson solvers used to calculate the Hartree potential.
125 !%Option derivatives 2
126 !% Tests and benchmarks the implementation of the finite-difference operators, used to calculate derivatives.
127 !%Option orthogonalization 3
128 !% Tests the implementation of the orthogonalization routines.
129 !%Option interpolation 4
130 !% Test the interpolation routines.
131 !%Option ion_interaction 5
132 !% Tests the ion-ion interaction routines.
133 !%Option projector 6
134 !% Tests the code that applies the nonlocal part of the pseudopotentials
135 !% in case of spin-orbit coupling
136 !%Option dft_u 7
137 !% Tests the DFT+U part of the code for projections on the basis.
138 !%Option hamiltonian_apply 8
139 !% Tests the application of the Hamiltonian, or a part of it
140 !%Option density_calc 9
141 !% Calculation of the density.
142 !%Option exp_apply 10
143 !% Tests the exponential of the Hamiltonian
144 !%Option boundaries 11
145 !% Tests the boundaries conditions
146 !%Option subspace_diag 12
147 !% Tests the subspace diagonalization
148 !%Option batch_ops 13
149 !% Tests the batch operations
150 !%Option clock 18
151 !% Tests for clock
152 !%Option linear_solver 19
153 !% Tests the linear solvers
154 !%Option cgal 20
155 !% Tests for cgal interface
156 !%Option dense_eigensolver 21
157 !% Tests for dense eigensolvers (especially parallel ones)
158 !%Option grid_interpolation 22
159 !% Tests for grid interpolation and multigrid methods.
160 !%Option iihash 23
161 !% Tests for the integer-integer hash table.
162 !%Option sihash 24
163 !% Tests for the string-integer hash table.
164 !%Option sphash 25
165 !% Tests for the string-polymorphic hash table.
166 !%Option mpiwrappers 26
167 !% Tests for the MPI wrappers with large integer displacements.
168 !%Option regridding 27
169 !% Tests the regridding between two different grids.
170 !%Option helmholtz_decomposition 28
171 !% Test for the Helmholtz decomposition subroutines
172 !%Option vecpot_analytical 29
173 !% Tests analytically the vector potential from B field.
174 !%Option current_density 30
175 !% Tests the different contributions to the total electronic current density
176 !%End
177 call parse_variable(namespace, 'TestMode', option__testmode__hartree, test_mode)
179 call messages_obsolete_variable(namespace, 'TestDerivatives', 'TestType')
180 call messages_obsolete_variable(namespace, 'TestOrthogonalization', 'TestType')
181
182 !%Variable TestType
183 !%Type integer
184 !%Default all
185 !%Section Calculation Modes::Test
186 !%Description
187 !% Decides on what type of values the test should be performed.
188 !%Option real 1
189 !% Test for double-precision real functions.
190 !%Option complex 2
191 !%Option all 3
192 !% Tests for double-precision real and complex functions.
193 !%End
194 call parse_variable(namespace, 'TestType', option__testtype__all, param%type)
195 if (param%type < 1 .or. param%type > 5) then
196 message(1) = "Invalid option for TestType."
197 call messages_fatal(1, only_root_writes = .true., namespace=namespace)
198 end if
199
200 !%Variable TestRepetitions
201 !%Type integer
202 !%Default 1
203 !%Section Calculation Modes::Test
204 !%Description
205 !% This variable controls the behavior of oct-test for performance
206 !% benchmarking purposes. It sets the number of times the
207 !% computational kernel of a test will be executed, in order to
208 !% provide more accurate timings.
209 !%
210 !% Currently this variable is used by the <tt>hartree_test</tt>,
211 !% <tt>derivatives</tt>, and <tt>projector</tt> tests.
212 !%End
213 call parse_variable(namespace, 'TestRepetitions', 1, param%repetitions)
214
215 !%Variable TestMinBlockSize
216 !%Type integer
217 !%Default 1
218 !%Section Calculation Modes::Test
219 !%Description
220 !% Some tests can work with multiple blocksizes, in this case of
221 !% range of blocksizes will be tested. This variable sets the lower
222 !% bound of that range.
223 !%
224 !% Currently this variable is only used by the derivatives test.
225 !%End
226 call parse_variable(namespace, 'TestMinBlockSize', 1, param%min_blocksize)
227
228 !%Variable TestMaxBlockSize
229 !%Type integer
230 !%Default 128
231 !%Section Calculation Modes::Test
232 !%Description
233 !% Some tests can work with multiple blocksizes, in this case of
234 !% range of blocksizes will be tested. This variable sets the lower
235 !% bound of that range.
236 !%
237 !% Currently this variable is only used by the derivatives test.
238 !%End
239 call parse_variable(namespace, 'TestMaxBlockSize', 128, param%max_blocksize)
240
241 call messages_print_with_emphasis(msg="Test mode", namespace=namespace)
242 call messages_print_var_option("TestMode", test_mode, namespace=namespace)
243 call messages_print_var_option("TestType", param%type, namespace=namespace)
244 call messages_print_var_value("TestRepetitions", param%repetitions, namespace=namespace)
245 call messages_print_var_value("TestMinBlockSize", param%min_blocksize, namespace=namespace)
246 call messages_print_var_value("TestMaxBlockSize", param%max_blocksize, namespace=namespace)
247 call messages_print_with_emphasis(namespace=namespace)
248
249 select case (test_mode)
250 case (option__testmode__hartree)
251 call test_hartree(param, namespace)
252 case (option__testmode__derivatives)
253 call test_derivatives(param, namespace)
254 case (option__testmode__orthogonalization)
255 call test_orthogonalization(param, namespace)
256 case (option__testmode__interpolation)
257 call test_interpolation(param, namespace)
258 case (option__testmode__ion_interaction)
259 call test_ion_interaction(namespace)
260 case (option__testmode__projector)
261 call test_projector(param, namespace)
262 case (option__testmode__dft_u)
263 call test_dft_u(param, namespace)
264 case (option__testmode__hamiltonian_apply)
265 call test_hamiltonian(param, namespace)
266 case (option__testmode__density_calc)
267 call test_density_calc(param, namespace)
268 case (option__testmode__exp_apply)
269 call test_exponential(param, namespace)
270 case (option__testmode__boundaries)
271 call test_boundaries(param, namespace)
272 case (option__testmode__subspace_diag)
273 call test_subspace_diagonalization(param, namespace)
274 case (option__testmode__batch_ops)
275 call test_batch_ops(param, namespace)
276 case (option__testmode__clock)
277 call test_clock()
278 case (option__testmode__linear_solver)
279 call test_linear_solver(namespace)
280 case (option__testmode__cgal)
281 call test_cgal()
282 case (option__testmode__dense_eigensolver)
284 case (option__testmode__grid_interpolation)
286 case (option__testmode__iihash)
287 call test_iihash()
288 case (option__testmode__sihash)
289 call test_sihash()
290 case (option__testmode__sphash)
291 call test_sphash(namespace)
292 case (option__testmode__mpiwrappers)
293 call test_mpiwrappers()
294 case (option__testmode__regridding)
295 call test_regridding(namespace)
296 case (option__testmode__helmholtz_decomposition)
297 call test_helmholtz_decomposition(namespace)
298 case (option__testmode__vecpot_analytical)
299 call test_vecpot_analytical(namespace)
300 case (option__testmode__current_density)
301 call test_current_density(namespace)
302 end select
303
305 end subroutine test_run
306
307 ! ---------------------------------------------------------
308 subroutine test_hartree(param, namespace)
309 type(test_parameters_t), intent(in) :: param
310 type(namespace_t), intent(in) :: namespace
311
312 type(electrons_t), pointer :: sys
313
315
317
318 sys => electrons_t(namespace, generate_epot=.false.)
319 call sys%init_parallelization(mpi_world)
320 call poisson_test(sys%hm%psolver, sys%space, sys%gr, sys%ions%latt, namespace, param%repetitions)
321 safe_deallocate_p(sys)
322
324 end subroutine test_hartree
325
326 ! ---------------------------------------------------------
327 subroutine test_helmholtz_decomposition(namespace)
328 type(namespace_t), intent(in) :: namespace
329
330 type(electrons_t), pointer :: sys
331 type(helmholtz_decomposition_t) :: helmholtz
332
334
335 ! First of all we have to initialize the grid and the poisson solver
337
338 sys => electrons_t(namespace, generate_epot=.false.)
339 call sys%init_parallelization(mpi_world)
340
341 call helmholtz%init(namespace, sys%gr, sys%mc, sys%space)
342
343 ! Then we have to initialize the exact fields
344 write(message(1),'(a)') "Helmholtz decomposition: beginning Hertzian dipole test"
345 call messages_info(1, namespace=namespace)
346 call hertzian_dipole_test(helmholtz, sys%gr, sys%namespace, sys%space)
347
348 write(message(1),'(a)') "Helmholtz decomposition: beginning Gaussian test"
349 call messages_info(1, namespace=namespace)
350 call gaussian_test(helmholtz, sys%gr, sys%namespace, sys%space)
351
352 safe_deallocate_p(sys)
353
355 end subroutine test_helmholtz_decomposition
356
357 ! ---------------------------------------------------------
358 subroutine test_linear_solver(namespace)
359 type(namespace_t), intent(in) :: namespace
360
361 type(electrons_t), pointer :: sys
362 float, allocatable :: rho(:), x(:)
363 float :: center(max_dim)
364 float :: rr, alpha, beta, res
365 integer :: ip, iter
366
367 float, parameter :: threshold = cnst(1e-7)
368
370
372
373 sys => electrons_t(namespace, generate_epot=.false.)
374 call sys%init_parallelization(mpi_world)
375
376 ! We need to set up some auxiliary quantities called by the linear solver
377 call mesh_init_mesh_aux(sys%gr)
378 ! Shift of the linear equation
379 shift_aux = cnst(0.25)
380 ! Preconditioner used for the QMR algorithm
381 call preconditioner_init(prec_aux, namespace, sys%gr, sys%mc, sys%space)
382 ! Derivative object needed
383 call set_der_aux(sys%gr%der)
384
385 ! Here we put a Gaussian as the right-hand side of the linear solver
386 ! Values are taken from the poisson_test routine
387 alpha = m_four * sys%gr%spacing(1)
388 beta = m_one / (alpha**sys%space%dim * sqrt(m_pi)**sys%space%dim)
389 ! The Gaussian is centered around the origin
390 center = m_zero
391
392 safe_allocate(rho(1:sys%gr%np))
393 rho = m_zero
394 do ip = 1, sys%gr%np
395 call mesh_r(sys%gr, ip, rr, origin = center(:))
396 rho(ip) = beta*exp(-(rr/alpha)**2)
397 end do
398
399 safe_allocate(x(1:sys%gr%np))
400
401 !Test the CG linear solver
402 x = m_zero
403 iter = 1000
404 call dconjugate_gradients(sys%gr%np, x, rho, laplacian_op, dmf_dotp_aux, iter, res, threshold)
405 write(message(1),'(a,i6,a)') "Info: CG converged with ", iter, " iterations."
406 write(message(2),'(a,e14.6)') "Info: The residue is ", res
407 write(message(3),'(a,e14.6)') "Info: Norm solution CG ", dmf_nrm2(sys%gr, x)
408 call messages_info(3, namespace=namespace)
409
410 call preconditioner_end(prec_aux)
411 safe_deallocate_a(x)
412 safe_deallocate_a(rho)
413 safe_deallocate_p(sys)
414
416 contains
417
418 subroutine set_der_aux(der)
419 type(derivatives_t), target, intent(in) :: der
421 der_aux => der
423 end subroutine set_der_aux
424
425 ! ---------------------------------------------------------
427 subroutine laplacian_op(x, hx)
428 float, intent(in) :: x(:)
429 float, contiguous,intent(out) :: hx(:)
430
431 float, allocatable :: tmpx(:)
432
433 assert(associated(mesh_aux))
434
435 safe_allocate(tmpx(1:mesh_aux%np_part))
436 call lalg_copy(mesh_aux%np, x, tmpx)
437 call dderivatives_lapl(der_aux, tmpx, hx)
438 call lalg_scal(mesh_aux%np, -m_one, hx)
439 call lalg_axpy(mesh_aux%np, shift_aux, x, hx)
440 safe_deallocate_a(tmpx)
441
442 end subroutine laplacian_op
444 end subroutine test_linear_solver
445
446
447 ! ---------------------------------------------------------
448 subroutine test_projector(param, namespace)
449 type(test_parameters_t), intent(in) :: param
450 type(namespace_t), intent(in) :: namespace
451
452 type(electrons_t), pointer :: sys
453 type(wfs_elec_t) :: epsib
454 integer :: itime
455 cmplx, allocatable :: psi(:, :)
456
458
460
461 call messages_write('Info: Testing the nonlocal part of the pseudopotential with SOC')
462 call messages_new_line()
463 call messages_new_line()
464 call messages_info(namespace=namespace)
465
466 sys => electrons_t(namespace, generate_epot=.false.)
467 call sys%init_parallelization(mpi_world)
468
469 call states_elec_allocate_wfns(sys%st, sys%gr, wfs_type = type_cmplx)
470 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
471
472 ! Initialize external potential
473 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
474
475 call sys%st%group%psib(1, 1)%copy_to(epsib)
476
477 call batch_set_zero(epsib)
478
479 do itime = 1, param%repetitions
480 call zproject_psi_batch(sys%gr, sys%gr%der%boundaries, sys%hm%ep%proj, &
481 sys%hm%ep%natoms, 2, sys%st%group%psib(1, 1), epsib)
482 end do
483
484 safe_allocate(psi(1:sys%gr%np, 1:sys%st%d%dim))
485 do itime = 1, epsib%nst
486 call batch_get_state(epsib, itime, sys%gr%np, psi)
487 write(message(1),'(a,i1,3x, f12.6)') "Norm state ", itime, zmf_nrm2(sys%gr, 2, psi)
488 call messages_info(1, namespace=sys%namespace)
489 end do
490 safe_deallocate_a(psi)
491
492 call epsib%end()
493 call states_elec_deallocate_wfns(sys%st)
494 safe_deallocate_p(sys)
495
497 end subroutine test_projector
498
499 ! ---------------------------------------------------------
500 subroutine test_dft_u(param, namespace)
501 type(test_parameters_t), intent(in) :: param
502 type(namespace_t), intent(in) :: namespace
504 type(electrons_t), pointer :: sys
505 type(wfs_elec_t) :: epsib, epsib2
506 integer :: itime, ist
507 type(orbitalbasis_t) :: basis
508 float, allocatable :: ddot(:,:,:), dweight(:,:)
509 cmplx, allocatable :: zdot(:,:,:), zweight(:,:)
510
516
517 call messages_write('Info: Testing some DFT+U routines')
518 call messages_new_line()
519 call messages_new_line()
520 call messages_info(namespace=namespace)
521
522 sys => electrons_t(namespace, generate_epot=.false.)
523 call sys%init_parallelization(mpi_world)
524
525 call states_elec_allocate_wfns(sys%st, sys%gr)
526 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
527 if (sys%st%d%pack_states) call sys%st%pack()
528
529 call sys%st%group%psib(1, 1)%copy_to(epsib2, copy_data = .true.)
530
531 ! We set the phase of the batch if needed
532 if (.not. allocated(sys%hm%hm_base%phase)) then
533 call sys%st%group%psib(1, 1)%copy_to(epsib, copy_data = .true.)
534 else
535 call sys%st%group%psib(1, 1)%copy_to(epsib)
536 call sys%hm%hm_base%apply_phase(sys%gr, sys%gr%np, &
537 .false., epsib, src=sys%st%group%psib(1, 1))
538 epsib2%has_phase = .true.
539 end if
540
541 ! Initialize the orbital basis
542 call orbitalbasis_init(basis, sys%namespace, sys%space%periodic_dim)
543 if (states_are_real(sys%st)) then
544 call dorbitalbasis_build(basis, sys%namespace, sys%ions, sys%gr, sys%st%d%kpt, sys%st%d%dim, &
545 allocated(sys%hm%hm_base%phase), .false., .false.)
546 safe_allocate(dweight(1:basis%orbsets(1)%norbs, 1:epsib%nst_linear))
547 safe_allocate(ddot(1:sys%st%d%dim, 1:basis%orbsets(1)%norbs, 1:epsib%nst))
548 else
549 call zorbitalbasis_build(basis, sys%namespace, sys%ions, sys%gr, sys%st%d%kpt, sys%st%d%dim, &
550 allocated(sys%hm%hm_base%phase), .false., .false.)
551 call orbitalset_update_phase(basis%orbsets(1), sys%space%dim, sys%st%d%kpt, sys%kpoints, (sys%st%d%ispin==spin_polarized))
552 safe_allocate(zweight(1:basis%orbsets(1)%norbs, 1:epsib%nst_linear))
553 safe_allocate(zdot(1:sys%st%d%dim, 1:basis%orbsets(1)%norbs, 1:epsib%nst))
554
555 !We set the phase of the orbitals if needed
556 if (allocated(sys%hm%hm_base%phase)) then
557 call orbitalset_update_phase(basis%orbsets(1), sys%space%dim, sys%st%d%kpt, sys%kpoints, &
558 (sys%st%d%ispin==spin_polarized))
559 end if
560 end if
561
562 do itime = 1, param%repetitions
563 call batch_set_zero(epsib2)
564 if (states_are_real(sys%st)) then
565 dweight = m_one
566 ddot = m_zero
567 call dorbitalset_get_coeff_batch(basis%orbsets(1), sys%st%d%dim, sys%st%group%psib(1, 1), ddot)
568 call dorbitalset_add_to_batch(basis%orbsets(1), sys%st%d%dim, epsib2, dweight)
569 else
570 zweight = m_one
571 zdot = m_zero
572 call zorbitalset_get_coeff_batch(basis%orbsets(1), sys%st%d%dim, epsib, zdot)
573 call zorbitalset_add_to_batch(basis%orbsets(1), sys%st%d%dim, epsib2, zweight)
574 end if
575 end do
576
577 if (epsib%is_packed()) then
578 call epsib%do_unpack(force = .true.)
579 end if
580
581 do ist = 1, epsib%nst
582 if (states_are_real(sys%st)) then
583 write(message(1),'(a,i2,3x,e13.6)') "Dotp state ", ist, ddot(1,1,ist)
584 else
585 write(message(1),'(a,i2,2(3x,e13.6))') "Dotp state ", ist, zdot(1,1,ist)
586 end if
587 call messages_info(1)
588 end do
589
590
591 call test_prints_info_batch(sys%st, sys%gr, epsib2)
592
593 safe_deallocate_a(dweight)
594 safe_deallocate_a(zweight)
595 safe_deallocate_a(ddot)
596 safe_deallocate_a(zdot)
597
598 call epsib%end()
599 call epsib2%end()
600 call orbitalbasis_end(basis)
601 call states_elec_deallocate_wfns(sys%st)
602 safe_deallocate_p(sys)
603
605 end subroutine test_dft_u
606
607 ! ---------------------------------------------------------
608 subroutine test_hamiltonian(param, namespace)
609 type(test_parameters_t), intent(in) :: param
610 type(namespace_t), intent(in) :: namespace
611
612 type(electrons_t), pointer :: sys
613 type(wfs_elec_t) :: hpsib
614 integer :: itime, terms
615
617
618 !%Variable TestHamiltonianApply
619 !%Type integer
620 !%Default term_all
621 !%Section Calculation Modes::Test
622 !%Description
623 !% Decides which part of the Hamiltonian is applied.
624 !%Option term_all 0
625 !% Apply the full Hamiltonian.
626 !%Option term_kinetic 1
627 !% Apply only the kinetic operator
628 !%Option term_local_potential 2
629 !% Apply only the local potential.
630 !%Option term_non_local_potential 4
631 !% Apply only the non_local potential.
632 !%End
633 call parse_variable(namespace, 'TestHamiltonianApply', option__testhamiltonianapply__term_all, terms)
634 if (terms == 0) terms = huge(1)
635
636
638
639 call messages_write('Info: Testing the application of the Hamiltonian')
640 call messages_new_line()
641 call messages_new_line()
642 call messages_info(namespace=namespace)
643
644 sys => electrons_t(namespace, generate_epot=.false.)
645 call sys%init_parallelization(mpi_world)
646
647 call states_elec_allocate_wfns(sys%st, sys%gr)
648 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
649
650 ! Initialize external potential
651 if (sys%st%d%pack_states .and. sys%hm%apply_packed()) call sys%st%pack()
652 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
653 call density_calc(sys%st, sys%gr, sys%st%rho)
654 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, sys%st, sys%ions, sys%ext_partners)
655
656 call boundaries_set(sys%gr%der%boundaries, sys%gr, sys%st%group%psib(1, 1))
657
658 call sys%st%group%psib(1, 1)%copy_to(hpsib)
659
660 if (sys%hm%apply_packed()) then
661 call sys%st%group%psib(1, 1)%do_pack()
662 call hpsib%do_pack(copy = .false.)
663 end if
664
665 do itime = 1, param%repetitions
666 if (states_are_real(sys%st)) then
667 call dhamiltonian_elec_apply_batch(sys%hm, sys%namespace, sys%gr, sys%st%group%psib(1, 1), hpsib, terms = terms, &
668 set_bc = .false.)
669 else
670 call zhamiltonian_elec_apply_batch(sys%hm, sys%namespace, sys%gr, sys%st%group%psib(1, 1), hpsib, terms = terms, &
671 set_bc = .false.)
672 end if
673 end do
674
675 if (hpsib%is_packed()) then
676 call hpsib%do_unpack(force = .true.)
677 end if
678
679 call test_prints_info_batch(sys%st, sys%gr, hpsib)
680
681 call hpsib%end(copy = .false.)
682 call states_elec_deallocate_wfns(sys%st)
683 safe_deallocate_p(sys)
684
686 end subroutine test_hamiltonian
687
688
689 ! ---------------------------------------------------------
690 subroutine test_density_calc(param, namespace)
691 type(test_parameters_t), intent(in) :: param
692 type(namespace_t), intent(in) :: namespace
694 type(electrons_t), pointer :: sys
695 integer :: itime
696
698
700
701 call messages_write('Info: Testing density calculation')
702 call messages_new_line()
703 call messages_new_line()
704 call messages_info(namespace=namespace)
705
706 sys => electrons_t(namespace, generate_epot=.false.)
707 call sys%init_parallelization(mpi_world)
708
709 call states_elec_allocate_wfns(sys%st, sys%gr)
710 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
711 if (sys%st%d%pack_states) call sys%st%pack()
712
713 do itime = 1, param%repetitions
714 call density_calc(sys%st, sys%gr, sys%st%rho)
715 end do
716
717 write(message(1),'(a,3x, f12.6)') "Norm density ", dmf_nrm2(sys%gr, sys%st%rho(:,1))
718 call messages_info(1, namespace=namespace)
719
720 call states_elec_deallocate_wfns(sys%st)
721 safe_deallocate_p(sys)
722
724 end subroutine test_density_calc
725
726
727 ! ---------------------------------------------------------
728 subroutine test_boundaries(param, namespace)
729 type(test_parameters_t), intent(in) :: param
730 type(namespace_t), intent(in) :: namespace
731
732 type(electrons_t), pointer :: sys
733 integer :: itime
734
736
738
739 call messages_write('Info: Testing boundary conditions')
740 call messages_new_line()
741 call messages_new_line()
742 call messages_info(namespace=namespace)
743
744 sys => electrons_t(namespace, generate_epot=.false.)
745 call sys%init_parallelization(mpi_world)
746
747 call states_elec_allocate_wfns(sys%st, sys%gr)
748 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
749 if (sys%st%d%pack_states) call sys%st%pack()
750
751 do itime = 1, param%repetitions
752 call boundaries_set(sys%gr%der%boundaries, sys%gr, sys%st%group%psib(1, 1))
753 end do
754
755 call test_prints_info_batch(sys%st, sys%gr, sys%st%group%psib(1, 1))
756
757 call states_elec_deallocate_wfns(sys%st)
758 safe_deallocate_p(sys)
759
761 end subroutine test_boundaries
762
763
764 ! ---------------------------------------------------------
765 subroutine test_exponential(param, namespace)
766 type(test_parameters_t), intent(in) :: param
767 type(namespace_t), intent(in) :: namespace
768
769 type(electrons_t), pointer :: sys
770 type(exponential_t) :: te
771 integer :: itime
772
774
776
777 call messages_write('Info: Testing exponential')
778 call messages_new_line()
779 call messages_new_line()
780 call messages_info(namespace=namespace)
781
782 sys => electrons_t(namespace, generate_epot=.false.)
783 call sys%init_parallelization(mpi_world)
784
785 call states_elec_allocate_wfns(sys%st, sys%gr, wfs_type=type_cmplx)
786 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
787
788 ! Initialize external potential
789 if (sys%st%d%pack_states .and. sys%hm%apply_packed()) call sys%st%pack()
790 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
791 call density_calc(sys%st, sys%gr, sys%st%rho)
792 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, sys%st, sys%ions, sys%ext_partners)
793
794 call exponential_init(te, namespace)
795
796 if (sys%hm%apply_packed()) then
797 call sys%st%group%psib(1, 1)%do_pack()
798 end if
799
800 do itime = 1, param%repetitions
801 call te%apply_batch(sys%namespace, sys%gr, sys%hm, sys%st%group%psib(1, 1), m_one)
802 end do
803
804 call test_prints_info_batch(sys%st, sys%gr, sys%st%group%psib(1, 1))
805
806 call states_elec_deallocate_wfns(sys%st)
807 safe_deallocate_p(sys)
808
810 end subroutine test_exponential
811
812
813 ! ---------------------------------------------------------
814 subroutine test_subspace_diagonalization(param, namespace)
815 type(test_parameters_t), intent(in) :: param
816 type(namespace_t), intent(in) :: namespace
817
818 type(electrons_t), pointer :: sys
819 integer :: itime
820 type(subspace_t) :: sdiag
821 float, allocatable :: diff(:)
822
824
826
827 call messages_write('Info: Testing boundary conditions')
828 call messages_new_line()
829 call messages_new_line()
830 call messages_info(namespace=namespace)
831
832 sys => electrons_t(namespace, generate_epot=.false.)
833 call sys%init_parallelization(mpi_world)
834
835 call states_elec_allocate_wfns(sys%st, sys%gr)
836 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
837
838 if (sys%st%d%pack_states .and. sys%hm%apply_packed()) call sys%st%pack()
839 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
840 call density_calc(sys%st, sys%gr, sys%st%rho)
841 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, sys%st, sys%ions, sys%ext_partners)
842
843 call sdiag%init(sys%namespace, sys%st)
844
845 safe_allocate(diff(1:sys%st%nst))
846
847 do itime = 1, param%repetitions
848 if (states_are_real(sys%st)) then
849 call dsubspace_diag(sdiag, sys%namespace, sys%gr, sys%st, sys%hm, 1, sys%st%eigenval(:, 1), diff)
850 else
851 call zsubspace_diag(sdiag, sys%namespace, sys%gr, sys%st, sys%hm, 1, sys%st%eigenval(:, 1), diff)
852 end if
853 end do
854
855 safe_deallocate_a(diff)
856
857 call test_prints_info_batch(sys%st, sys%gr, sys%st%group%psib(1, 1))
858
859 call states_elec_deallocate_wfns(sys%st)
860 safe_deallocate_p(sys)
861
863 end subroutine test_subspace_diagonalization
864
865
866 ! ---------------------------------------------------------
867 subroutine test_batch_ops(param, namespace)
868 type(test_parameters_t), intent(in) :: param
869 type(namespace_t), intent(in) :: namespace
870
871 type(electrons_t), pointer :: sys
872 integer :: itime, ops, ops_default, ist, jst, nst
873 type(wfs_elec_t) :: xx, yy
874 float, allocatable :: tmp(:)
875 float, allocatable :: ddotv(:)
876 cmplx, allocatable :: zdotv(:)
877 float, allocatable :: ddot(:,:)
878 cmplx, allocatable :: zdot(:,:)
879
880
882
883 !%Variable TestBatchOps
884 !%Type flag
885 !%Default ops_axpy + ops_scal + ops_nrm2
886 !%Section Calculation Modes::Test
887 !%Description
888 !% Decides which part of the Hamiltonian is applied.
889 !%Option ops_axpy bit(1)
890 !% Tests batch_axpy operation
891 !%Option ops_scal bit(2)
892 !% Tests batch_scal operation
893 !%Option ops_nrm2 bit(3)
894 !% Tests batch_nrm2 operation
895 !%Option ops_dotp_matrix bit(4)
896 !% Tests X(mesh_batch_dotp_matrix)
897 !%Option ops_dotp_self bit(5)
898 !% Tests X(mesh_batch_dotp_self)
899 !%Option ops_dotp_vector bit(6)
900 !% Tests X(mesh_batch_dotp_vector)
901 !%End
902 ops_default = &
903 option__testbatchops__ops_axpy + &
904 option__testbatchops__ops_scal + &
905 option__testbatchops__ops_nrm2 + &
906 option__testbatchops__ops_dotp_matrix + &
907 option__testbatchops__ops_dotp_self + &
908 option__testbatchops__ops_dotp_vector
909
910 call parse_variable(namespace, 'TestBatchOps', ops_default, ops)
911
913
914 call messages_write('Info: Testing batch operations')
915 call messages_new_line()
916 call messages_new_line()
917 call messages_info(namespace=namespace)
918
919 sys => electrons_t(namespace, generate_epot=.false.)
920 call sys%init_parallelization(mpi_world)
921
922 call states_elec_allocate_wfns(sys%st, sys%gr)
923 call test_batch_set_gaussian(sys%st%group%psib(1, 1), sys%gr)
924 if (sys%st%d%pack_states) call sys%st%pack()
925
926 if (bitand(ops, option__testbatchops__ops_axpy) /= 0) then
927 message(1) = 'Info: Testing axpy'
928 call messages_info(1, namespace=sys%namespace)
929
930 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
931 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
932
933 do itime = 1, param%repetitions
934 call batch_axpy(sys%gr%np, cnst(0.1), xx, yy)
935 end do
936 call test_prints_info_batch(sys%st, sys%gr, yy, string = "axpy")
937
938 call xx%end()
939 call yy%end()
940 end if
941
942 if (bitand(ops, option__testbatchops__ops_scal) /= 0) then
943 message(1) = 'Info: Testing scal'
944 call messages_info(1, namespace=sys%namespace)
945
946 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
947 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
948
949 do itime = 1, param%repetitions
950 call batch_scal(sys%gr%np, cnst(0.1), yy)
951 end do
952 call test_prints_info_batch(sys%st, sys%gr, yy, string="scal")
953
954 call xx%end()
955 call yy%end()
956 end if
957
958 if (bitand(ops, option__testbatchops__ops_nrm2) /= 0) then
959 message(1) = 'Info: Testing nrm2'
960 call messages_info(1, namespace=sys%namespace)
961
962 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
963 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
964
965 safe_allocate(tmp(1:xx%nst))
966
967 do itime = 1, param%repetitions
968 call mesh_batch_nrm2(sys%gr, yy, tmp)
969 end do
970 do itime = 1, xx%nst
971 write(message(1),'(a,i1,3x,e23.16)') "Nrm2 norm state ", itime, tmp(itime)
972 call messages_info(1, namespace=sys%namespace)
973 end do
974
975 safe_deallocate_a(tmp)
976
977 call xx%end()
978 call yy%end()
979 end if
980
981 if (bitand(ops, option__testbatchops__ops_dotp_matrix) /= 0) then
982
983 message(1) = 'Info: Testing dotp_matrix'
984 call messages_info(1, namespace=sys%namespace)
985
986 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
987 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
988
989 nst = sys%st%group%psib(1, 1)%nst
990
991 if (states_are_real(sys%st)) then
992 safe_allocate(ddot(1:nst, 1:nst))
993 call dmesh_batch_dotp_matrix(sys%gr, xx, yy, ddot)
994
995 do ist = 1, nst
996 do jst = 1, nst
997 write(message(jst), '(a,2i3,3x,e23.16)') 'Dotp_matrix states', ist, jst, ddot(ist,jst)
998 end do
999 call messages_info(nst, namespace=sys%namespace)
1000 end do
1001 safe_deallocate_a(ddot)
1002 else
1003 safe_allocate(zdot(1:nst, 1:nst))
1004 call zmesh_batch_dotp_matrix(sys%gr, xx, yy, zdot)
1005
1006 do ist = 1, nst
1007 do jst = 1, nst
1008 write(message(jst), '(a,2i3,3x,2(e23.16,1x))') 'Dotp_matrix states', ist, jst, zdot(ist,jst)
1009 end do
1010 call messages_info(nst, namespace=sys%namespace)
1011 end do
1012 safe_deallocate_a(zdot)
1013 end if
1014
1015 call xx%end()
1016 call yy%end()
1017 end if
1018
1019 if (bitand(ops, option__testbatchops__ops_dotp_vector) /= 0) then
1020
1021 message(1) = 'Info: Testing dotp_vector'
1022 call messages_info(1, namespace=sys%namespace)
1023
1024 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1025 call sys%st%group%psib(1, 1)%copy_to(yy, copy_data = .true.)
1026
1027 nst = sys%st%group%psib(1, 1)%nst
1028
1029 if (states_are_real(sys%st)) then
1030 safe_allocate(ddotv(1:nst))
1031 call dmesh_batch_dotp_vector(sys%gr, xx, yy, ddotv)
1032
1033 do ist = 1, nst
1034 write(message(ist), '(a,i3,3x,e23.16)') 'Dotp_vector state', ist, ddotv(ist)
1035 end do
1036 call messages_info(nst, namespace=sys%namespace)
1037 safe_deallocate_a(ddotv)
1038 else
1039 safe_allocate(zdotv(1:nst))
1040 call zmesh_batch_dotp_vector(sys%gr, xx, yy, zdotv)
1041 do ist = 1, nst
1042 write(message(ist), '(a,i3,3x,2(e23.16,1x))') 'Dotp_vector state', ist, zdotv(ist)
1043 end do
1044 call messages_info(nst, namespace=sys%namespace)
1045 safe_deallocate_a(zdotv)
1046 end if
1047
1048 call xx%end()
1049 call yy%end()
1050 end if
1051
1052 if (bitand(ops, option__testbatchops__ops_dotp_self) /= 0) then
1053
1054 message(1) = 'Info: Testing dotp_self'
1055 call messages_info(1, namespace=sys%namespace)
1056
1057 call sys%st%group%psib(1, 1)%copy_to(xx, copy_data = .true.)
1058
1059 nst = sys%st%group%psib(1, 1)%nst
1060
1061 if (states_are_real(sys%st)) then
1062 safe_allocate(ddot(1:nst, 1:nst))
1063 call dmesh_batch_dotp_self(sys%gr, xx, ddot)
1064
1065 do ist = 1, nst
1066 do jst = 1, nst
1067 write(message(jst), '(a,2i3,3x,e23.16)') 'Dotp_self states', ist, jst, ddot(ist,jst)
1068 end do
1069 call messages_info(nst, namespace=sys%namespace)
1070 end do
1071 safe_deallocate_a(ddot)
1072 else
1073 safe_allocate(zdot(1:nst, 1:nst))
1074 call zmesh_batch_dotp_self(sys%gr, xx, zdot)
1075 do ist = 1, nst
1076 do jst = 1, nst
1077 write(message(jst), '(a,2i3,3x,2(e23.16,1x))') 'Dotp_self states', ist, jst, zdot(ist,jst)
1078 end do
1079 call messages_info(nst, namespace=sys%namespace)
1080 end do
1081 safe_deallocate_a(zdot)
1082 end if
1083
1084 call xx%end()
1085 end if
1086
1087 call states_elec_deallocate_wfns(sys%st)
1088 safe_deallocate_p(sys)
1089
1091 end subroutine test_batch_ops
1092
1093! ---------------------------------------------------------
1094 subroutine test_derivatives(param, namespace)
1095 type(test_parameters_t), intent(in) :: param
1096 type(namespace_t), intent(in) :: namespace
1097
1098 type(electrons_t), pointer :: sys
1099
1101
1102 sys => electrons_t(namespace, generate_epot=.false.)
1103 call sys%init_parallelization(mpi_world)
1104
1105 message(1) = 'Info: Testing the finite-differences derivatives.'
1106 message(2) = ''
1107 call messages_info(2, namespace=namespace)
1108
1109 if (param%type == option__testtype__all .or. param%type == option__testtype__real) then
1110 call dderivatives_test(sys%gr%der, sys%namespace, param%repetitions, param%min_blocksize, param%max_blocksize)
1111 end if
1112
1113 if (param%type == option__testtype__all .or. param%type == option__testtype__complex) then
1114 call zderivatives_test(sys%gr%der, sys%namespace, param%repetitions, param%min_blocksize, param%max_blocksize)
1115 end if
1116
1117 safe_deallocate_p(sys)
1118
1120 end subroutine test_derivatives
1121
1122 ! ---------------------------------------------------------
1123
1124 subroutine test_orthogonalization(param, namespace)
1125 type(test_parameters_t), intent(in) :: param
1126 type(namespace_t), intent(in) :: namespace
1127
1128 type(electrons_t), pointer :: sys
1129 integer :: itime
1130
1132
1135
1136 sys => electrons_t(namespace, generate_epot=.false.)
1137 call sys%init_parallelization(mpi_world)
1138
1139 message(1) = 'Info: Testing orthogonalization.'
1140 message(2) = ''
1141 call messages_info(2, namespace=namespace)
1142
1143 if (param%type == option__testtype__all .or. param%type == option__testtype__real) then
1144 message(1) = 'Info: Real wave-functions.'
1145 call messages_info(1, namespace=namespace)
1146 do itime = 1, param%repetitions
1147 call dstates_elec_calc_orth_test(sys%st, sys%namespace, sys%gr, sys%kpoints)
1148 end do
1149 end if
1150
1151 if (param%type == option__testtype__all .or. param%type == option__testtype__complex) then
1152 message(1) = 'Info: Complex wave-functions.'
1153 call messages_info(1, namespace=namespace)
1154 do itime = 1, param%repetitions
1155 call zstates_elec_calc_orth_test(sys%st, sys%namespace, sys%gr, sys%kpoints)
1156 end do
1157 end if
1158
1159 safe_deallocate_p(sys)
1160
1162 end subroutine test_orthogonalization
1163
1164 ! ---------------------------------------------------------
1165
1166 subroutine test_interpolation(param, namespace)
1167 type(test_parameters_t), intent(in) :: param
1168 type(namespace_t), intent(in) :: namespace
1169
1170 type(electrons_t), pointer :: sys
1171
1173
1174 sys => electrons_t(namespace, generate_epot=.false.)
1175 call sys%init_parallelization(mpi_world)
1176
1177 if (param%type == option__testtype__all .or. param%type == option__testtype__real) then
1178 call messages_write('Info: Testing real interpolation routines')
1180 call messages_new_line()
1181 call messages_info(namespace=namespace)
1182
1183 call dmesh_interpolation_test(sys%gr)
1184 end if
1185
1186 if (param%type == option__testtype__all .or. param%type == option__testtype__complex) then
1187 call messages_new_line()
1188 call messages_write('Info: Testing complex interpolation routines')
1189 call messages_new_line()
1190 call messages_new_line()
1191 call messages_info(namespace=namespace)
1192
1193 call zmesh_interpolation_test(sys%gr)
1194 end if
1195
1196 safe_deallocate_p(sys)
1197
1199 end subroutine test_interpolation
1200
1201
1202 ! ---------------------------------------------------------
1203
1204 subroutine test_ion_interaction(namespace)
1205 type(namespace_t), intent(in) :: namespace
1206
1207 type(electrons_t), pointer :: sys
1208
1210
1211 sys => electrons_t(namespace, generate_epot=.false.)
1212 call sys%init_parallelization(mpi_world)
1213
1214 call ion_interaction_test(sys%space, sys%ions%latt, sys%ions%atom, sys%ions%natoms, sys%ions%pos, &
1215 sys%gr%box%bounding_box_l, namespace, sys%mc)
1216
1217 safe_deallocate_p(sys)
1218
1220 end subroutine test_ion_interaction
1221
1222 ! ---------------------------------------------------------
1223
1224 subroutine test_prints_info_batch(st, gr, psib, string)
1225 type(states_elec_t), intent(in) :: st
1226 type(grid_t), intent(in) :: gr
1227 class(batch_t), intent(inout) :: psib
1228 character(*), optional, intent(in) :: string
1229
1230 integer :: itime
1231 cmplx, allocatable :: zpsi(:, :)
1232 float, allocatable :: dpsi(:, :)
1233
1234 character(80) :: string_
1235
1236 string_ = optional_default(string, "")
1237
1239
1240 if (states_are_real(st)) then
1241 safe_allocate(dpsi(1:gr%np, 1:st%d%dim))
1242 else
1243 safe_allocate(zpsi(1:gr%np, 1:st%d%dim))
1244 end if
1245
1246 do itime = 1, psib%nst
1247 if (states_are_real(st)) then
1248 call batch_get_state(psib, itime, gr%np, dpsi)
1249 write(message(1),'(a,i2,3x,e23.16)') "Norm state "//trim(string_)//" ", itime, dmf_nrm2(gr, st%d%dim, dpsi)
1250 else
1251 call batch_get_state(psib, itime, gr%np, zpsi)
1252 write(message(1),'(a,i2,3x,e23.16)') "Norm state "//trim(string_)//" ", itime, zmf_nrm2(gr, st%d%dim, zpsi)
1253 end if
1254 call messages_info(1)
1255 end do
1256
1257 if (states_are_real(st)) then
1258 safe_deallocate_a(dpsi)
1259 else
1260 safe_deallocate_a(zpsi)
1261 end if
1262
1264
1265 end subroutine test_prints_info_batch
1266
1267
1268 ! ---------------------------------------------------------
1269 subroutine test_clock()
1270
1271 type(clock_t) :: test_clock_a, test_clock_b
1272
1274
1275 test_clock_a = clock_t(time_step=m_two, initial_tick=100)
1276 test_clock_b = clock_t(time_step=m_one)
1277 call test_clock_a%print()
1278 call test_clock_b%print()
1279
1280 call test_clock_a%set_time(test_clock_b)
1281 call test_clock_a%print()
1282 test_clock_a = test_clock_a + clock_tick
1283 call test_clock_a%print()
1284 test_clock_a = test_clock_a - clock_tick
1285 call test_clock_a%print()
1286 test_clock_a = test_clock_a + clock_tick
1287 call test_clock_a%print()
1288 call test_clock_a%reset()
1289 call test_clock_a%print()
1290 test_clock_a = test_clock_a + 3*clock_tick
1291 call test_clock_a%print()
1292 test_clock_a = test_clock_a - 2*clock_tick
1293 call test_clock_a%print()
1294 message(1) = test_clock_a%print_str()
1295 call messages_info(1)
1296
1297 write(message(1),'(A,x,I10.10)') &
1298 'clock_get_tick', test_clock_a%get_tick()
1299 write(message(2),'(A,x,F15.10)') &
1300 'clock_time', test_clock_a%time()
1301 write(message(3),'(A,x,I1)') &
1302 'clock_is_earlier', abs(transfer(test_clock_a .lt. test_clock_b, 0))
1303 write(message(4),'(A,x,I1)') &
1304 'clock_is_equal_or_earlier', abs(transfer(test_clock_a .le. test_clock_b, 0))
1305 write(message(5),'(A,x,I1)') &
1306 'clock_is_later', abs(transfer(test_clock_a .gt. test_clock_b, 0))
1307 write(message(6),'(A,x,I1)') &
1308 'clock_is_equal_or_later', abs(transfer(test_clock_a .ge. test_clock_b, 0))
1309 write(message(7),'(A,x,I1)') &
1310 'clock_is_equal', abs(transfer(test_clock_a .eq. test_clock_b, 0))
1311 call messages_info(7)
1312
1314 end subroutine test_clock
1315
1316
1317 ! ---------------------------------------------------------
1318 subroutine test_cgal()
1319
1320 type(cgal_polyhedra_t) :: cgal_poly
1321
1323
1324 call cgal_polyhedron_init(cgal_poly, "28-cgal.02-X.off", verbose = .true.)
1325
1326 if (cgal_polyhedron_point_inside(cgal_poly, cnst(30.), cnst(10.), cnst(30.))) then
1327 message(1) = "cgal_polyhedron_point_inside"
1328 call messages_info(1)
1329 end if
1330
1331 call cgal_polyhedron_end(cgal_poly)
1332
1334 end subroutine test_cgal
1335
1336
1337 ! ---------------------------------------------------------
1338 subroutine test_dense_eigensolver()
1339 integer :: N, ii, jj, N_list(4), i_N
1340 float, allocatable :: matrix(:, :), eigenvectors(:, :), eigenvalues(:), test(:)
1341 float, allocatable :: differences(:)
1342
1344
1345 n_list = [15, 32, 100, 500]
1346
1347 do i_n = 1, 4
1348 n = n_list(i_n)
1349 safe_allocate(matrix(1:n, 1:n))
1350 safe_allocate(eigenvectors(1:n, 1:n))
1351 safe_allocate(eigenvalues(1:n))
1352 safe_allocate(test(1:n))
1353 safe_allocate(differences(1:n))
1355
1356 ! set up symmetrix matrix
1357 do jj = 1, n
1358 do ii = 1, n
1359 matrix(ii, jj) = ii * jj
1360 end do
1361 end do
1362
1363 ! parallel solver
1364 eigenvectors(1:n, 1:n) = matrix(1:n, 1:n)
1365 call lalg_eigensolve_parallel(n, eigenvectors, eigenvalues)
1366
1367 do ii = 1, n
1368 test(:) = matmul(matrix, eigenvectors(:, ii)) - eigenvalues(ii) * eigenvectors(:, ii)
1369 differences(ii) = sum(abs(test)) / sum(abs(eigenvectors(:, ii)))
1370 end do
1371 write(message(1), "(A, I3, A, E13.6)") "Parallel solver - N: ", n, &
1372 ", average difference: ", sum(differences)/n
1373 call messages_info(1)
1374
1375 ! serial solver
1376 eigenvectors(1:n, 1:n) = matrix(1:n, 1:n)
1377 call lalg_eigensolve(n, eigenvectors, eigenvalues)
1378
1379 do ii = 1, n
1380 test(:) = matmul(matrix, eigenvectors(:, ii)) - eigenvalues(ii) * eigenvectors(:, ii)
1381 differences(ii) = sum(abs(test)) / sum(abs(eigenvectors(:, ii)))
1382 end do
1383 write(message(1), "(A, I3, A, E13.6)") "Serial solver - N: ", n, &
1384 ", average difference: ", sum(differences)/n
1385 call messages_info(1)
1386
1387 safe_deallocate_a(matrix)
1388 safe_deallocate_a(eigenvectors)
1389 safe_deallocate_a(eigenvalues)
1390 safe_deallocate_a(test)
1391 safe_deallocate_a(differences)
1392 end do
1393
1395 end subroutine test_dense_eigensolver
1396
1397 subroutine test_batch_set_gaussian(psib, mesh)
1398 class(batch_t), intent(inout) :: psib
1399 class(mesh_t), intent(in) :: mesh
1400
1401 float, allocatable :: dff(:)
1402 cmplx, allocatable :: zff(:)
1403 integer :: ist, ip
1404 float :: da, db, dc
1405 cmplx :: za, zb, zc
1406
1408
1409 ! use a similar function as in the derivatives test
1410 da = m_one/mesh%box%bounding_box_l(1)
1411 db = cnst(10.0)
1412 dc = cnst(100.0)
1413
1414 if (type_is_complex(psib%type())) then
1415 ! we make things more "complex"
1416 za = da + m_zi*cnst(0.01)
1417 zb = db*exp(m_zi*cnst(0.345))
1418 zc = dc - m_zi*cnst(50.0)
1419
1420 safe_allocate(zff(1:mesh%np))
1421 do ist = 1, psib%nst_linear
1422 za = za * ist
1423 zb = zb / ist
1424 do ip = 1, mesh%np
1425 zff(ip) = zb*exp(-za*sum(mesh%x(ip, :)**2)) + zc
1426 end do
1427 call batch_set_state(psib, ist, mesh%np, zff)
1428 end do
1429 call zmesh_batch_normalize(mesh, psib)
1430 safe_deallocate_a(zff)
1431 else
1432 safe_allocate(dff(1:mesh%np))
1433 do ist = 1, psib%nst_linear
1434 da = da * ist
1435 db = db / ist
1436 do ip = 1, mesh%np
1437 dff(ip) = db*exp(-da*sum(mesh%x(ip, :)**2)) + dc
1438 end do
1439 call batch_set_state(psib, ist, mesh%np, dff)
1440 end do
1441 call dmesh_batch_normalize(mesh, psib)
1442 safe_deallocate_a(dff)
1443 end if
1444
1446 end subroutine test_batch_set_gaussian
1447
1448 ! ---------------------------------------------------------
1449 subroutine test_grid_interpolation()
1450 type(electrons_t), pointer :: sys
1451 type(multigrid_t) :: mgrid
1452
1454
1455 sys => electrons_t(global_namespace, generate_epot=.false.)
1456 call sys%init_parallelization(mpi_world)
1457
1458 call multigrid_init(mgrid, global_namespace, sys%space, sys%gr, sys%gr%der, &
1459 sys%gr%stencil, sys%mc, used_for_preconditioner = .true.)
1460
1461 call multigrid_test_interpolation(mgrid, sys%space)
1462
1463 call multigrid_end(mgrid)
1464
1465 safe_deallocate_p(sys)
1466
1468 end subroutine test_grid_interpolation
1469
1470 subroutine test_iihash()
1471
1472 type(iihash_t) :: h
1473 integer :: value
1474 logical :: found
1475
1476 call iihash_init(h)
1477 call iihash_insert(h, 1,5)
1478 call iihash_insert(h, 3,7)
1479
1480 value = iihash_lookup(h, 1, found)
1481 write(message(1),*) 'hash[1] :', found, value
1483
1484 value = iihash_lookup(h, 2, found)
1485 write(message(1),*) 'hash[2] :', found, value
1486 call messages_info()
1487
1488 value = iihash_lookup(h, 3, found)
1489 write(message(1),*) 'hash[3] :', found, value
1490 call messages_info()
1491
1492 call iihash_end(h)
1493
1494 end subroutine test_iihash
1495
1496 subroutine test_sihash()
1497 type(sihash_t) :: h
1498 type(sihash_iterator_t) :: it
1499
1500 integer :: counter
1501 integer :: value, sum
1502 logical :: found
1503
1504 call sihash_init(h)
1505 call sihash_insert(h, "one",5)
1506 call sihash_insert(h, "three",7)
1507 call sihash_insert(h, "the answer", 42)
1508
1509 value = sihash_lookup(h, "one", found)
1510 write(message(1),*) 'hash["one"]: ', found, value
1511 call messages_info()
1512
1513 value = sihash_lookup(h, "two", found)
1514 write(message(1),*) 'hash["two"]: ', found, value
1515 call messages_info()
1516
1517 value = sihash_lookup(h, "three", found)
1518 write(message(1),*) 'hash["three"]: ', found, value
1519 call messages_info()
1520
1521 sum = 0
1522 counter = 1
1523 call it%start(h)
1524
1525 do while (it%has_next())
1526 value = it%get_next()
1527 sum = sum + value
1528 write(message(1),'(I3,A,I5)') counter,': hash[...] = ',value
1529 call messages_info()
1530 counter = counter + 1
1531 end do
1532 write(message(1),*) 'counter = ', counter
1533 write(message(2),*) 'sum = ', sum
1535
1536
1537 call sihash_end(h)
1538
1539 end subroutine test_sihash
1540
1541
1542 subroutine test_sphash(namespace)
1543 type(namespace_t), intent(in) :: namespace
1544
1545 type(sphash_t) :: h
1546 type(sphash_iterator_t) :: it
1547
1548 logical :: found
1549
1550
1551 type(clock_t) :: clock_1
1552 type(clock_t), allocatable :: clock_2
1553 type(space_t) :: space_1
1554
1555 class(*), pointer :: value
1556
1557 integer :: count_clock, count_space
1558
1559 safe_allocate(clock_2)
1560
1561 clock_1 = clock_t(1.d-5, 1)
1562 clock_2 = clock_t(2.d-5, 2)
1563 call space_init(space_1, namespace)
1564
1565 call sphash_init(h)
1566 call sphash_insert(h, "one", clock_1)
1567 call sphash_insert(h, "two", space_1)
1568 call sphash_insert(h, "three", clock_2, clone=.true.)
1569
1570 value => sphash_lookup(h, "one", found)
1571 select type(value)
1572 type is (clock_t)
1573 write(message(1),*) 'hash["one"]: ', found, value%get_tick()
1574 call messages_info()
1575 type is (space_t)
1576 write(message(1),*) 'hash["one"]: ', found, value%short_info()
1577 call messages_info()
1578 class default
1579 write(message(1),*) 'wrong type. found = ', found
1580 call messages_info()
1581 end select
1582
1583 value => sphash_lookup(h, "two", found)
1584 select type(value)
1585 type is (clock_t)
1586 write(message(1),*) 'hash["two"]: ', found, value%get_tick()
1587 call messages_info()
1588 type is (space_t)
1589 write(message(1),*) 'hash["two"]: ', found, value%short_info()
1590 call messages_info()
1591 class default
1592 write(message(1),*) 'wrong type. found = ',found
1593 call messages_info()
1594 end select
1595
1596 safe_deallocate_a(clock_2)
1597
1598 value => sphash_lookup(h, "three", found)
1599 select type(value)
1600 type is (clock_t)
1601 write(message(1),*) 'hash["three"]: ', found, value%get_tick()
1602 call messages_info()
1603 type is (space_t)
1604 write(message(1),*) 'hash["three"]: ', found, value%short_info()
1605 call messages_info()
1606 class default
1607 write(message(1),*) 'wrong type. found = ',found
1608 call messages_info()
1609 end select
1610
1611 count_clock = 0
1612 count_space = 0
1613
1614 call it%start(h)
1615
1616 do while (it%has_next())
1617 value => it%get_next()
1618 select type(value)
1619 type is (clock_t)
1620 count_clock = count_clock + 1
1621 type is (space_t)
1622 count_space = count_space + 1
1623 end select
1624 end do
1625
1626 write(message(1), *) 'Count_clock = ', count_clock
1627 write(message(2), *) 'Count_space = ', count_space
1628 call messages_info(2)
1629
1630 call sphash_end(h)
1631
1632 end subroutine test_sphash
1633
1634 ! ---------------------------------------------------------
1635 subroutine test_regridding(namespace)
1636 type(namespace_t), intent(in) :: namespace
1637
1638 type(electrons_t), pointer :: sysA, sysB
1639 type(regridding_t), pointer :: regridding
1640 float, allocatable :: ff_a(:), ff_a_reference(:), ff_b(:), ff_b_reference(:), diff_a(:), diff_b(:)
1641 float :: norm_ff, norm_diff
1642 integer :: ip, ierr
1643
1645
1646 sysa => electrons_t(namespace_t("A", namespace), generate_epot=.false.)
1647 sysb => electrons_t(namespace_t("B", namespace), generate_epot=.false.)
1648
1650 call sysa%init_parallelization(mpi_world)
1651 call sysb%init_parallelization(mpi_world)
1652
1653
1654 safe_allocate(ff_a(1:sysa%gr%np))
1655 safe_allocate(ff_a_reference(1:sysa%gr%np))
1656 safe_allocate(diff_a(1:sysa%gr%np))
1657 safe_allocate(ff_b(1:sysb%gr%np))
1658 safe_allocate(ff_b_reference(1:sysb%gr%np))
1659 safe_allocate(diff_b(1:sysb%gr%np))
1660
1661 do ip = 1, sysa%gr%np
1662 ff_a_reference(ip) = values(sysa%gr%x(ip, :))
1663 end do
1664 do ip = 1, sysb%gr%np
1665 ff_b_reference(ip) = values(sysb%gr%x(ip, :))
1666 end do
1667
1668 ! forward mapping A->B
1669 regridding => regridding_t(sysb%gr, sysa%gr, sysa%space, sysa%namespace)
1670 call regridding%do_transfer(ff_b, ff_a_reference)
1671 safe_deallocate_p(regridding)
1672
1673 ! check that mapped function is exactly the same for the points that are available on both grids
1674 do ip = 1, sysb%gr%np
1675 if (ff_b(ip) == m_zero) then
1676 ff_b_reference(ip) = m_zero
1677 diff_b(ip) = m_zero
1678 else
1679 diff_b(ip) = abs(ff_b_reference(ip) - ff_b(ip))
1680 end if
1681 end do
1682 norm_ff = dmf_nrm2(sysb%gr, ff_b_reference)
1683 norm_diff = dmf_nrm2(sysb%gr, diff_b)
1684
1685 write(message(1),'(a, E14.6)') "Forward: difference of reference to mapped function (rel.): ", &
1686 norm_diff/norm_ff
1687 call messages_info(1, namespace=namespace)
1688
1689 call dio_function_output(io_function_fill_how('AxisX'), ".", "forward_reference", namespace, sysb%space, &
1690 sysb%gr, ff_b_reference, unit_one, ierr)
1691 call dio_function_output(io_function_fill_how('AxisX'), ".", "forward_mapped", namespace, sysb%space, &
1692 sysb%gr, ff_b, unit_one, ierr)
1693 call dio_function_output(io_function_fill_how('AxisX'), ".", "forward_original", namespace, sysa%space, &
1694 sysa%gr, ff_a_reference, unit_one, ierr)
1695
1696 ! backward mapping B->A
1697 regridding => regridding_t(sysa%gr, sysb%gr, sysb%space, sysb%namespace)
1698 call regridding%do_transfer(ff_a, ff_b_reference)
1699 safe_deallocate_p(regridding)
1700
1701 do ip = 1, sysa%gr%np
1702 if (ff_a(ip) == m_zero) then
1703 ff_a_reference(ip) = m_zero
1704 diff_a(ip) = m_zero
1705 else
1706 diff_a(ip) = abs(ff_a_reference(ip) - ff_a(ip))
1707 end if
1708 end do
1709 norm_ff = dmf_nrm2(sysa%gr, ff_a_reference)
1710 norm_diff = dmf_nrm2(sysa%gr, diff_a)
1711
1712 write(message(1),'(a, E14.6)') "Backward: difference of reference to mapped function (rel.): ", &
1713 norm_diff/norm_ff
1714 call messages_info(1, namespace=namespace)
1715
1716 call dio_function_output(io_function_fill_how('AxisX'), ".", "backward_reference", namespace, sysa%space, &
1717 sysa%gr, ff_a_reference, unit_one, ierr)
1718 call dio_function_output(io_function_fill_how('AxisX'), ".", "backward_mapped", namespace, sysa%space, &
1719 sysa%gr, ff_a, unit_one, ierr)
1720 call dio_function_output(io_function_fill_how('AxisX'), ".", "backward_original", namespace, sysb%space, &
1721 sysb%gr, ff_b_reference, unit_one, ierr)
1722
1723 safe_deallocate_a(ff_a)
1724 safe_deallocate_a(ff_a_reference)
1725 safe_deallocate_a(ff_b)
1726 safe_deallocate_a(ff_b_reference)
1727 safe_deallocate_a(diff_a)
1728 safe_deallocate_a(diff_b)
1729 safe_deallocate_p(sysa)
1730 safe_deallocate_p(sysb)
1731
1732 call messages_info(1, namespace=namespace)
1733
1735 contains
1736 float function values(xx)
1737 float, intent(in) :: xx(:)
1738 float :: xx0(1:size(xx, dim=1))
1739 float, parameter :: aa = m_half
1740 float, parameter :: bb = m_four
1741
1742 ! no push_sub/pop_sub because this function is called often
1743 xx0(:) = m_one
1744 values = bb * exp(-aa*sum((xx-xx0)**2))
1745 end function values
1746 end subroutine test_regridding
1747
1753 subroutine test_vecpot_analytical(namespace)
1754 type(namespace_t), intent(in) :: namespace
1755
1756 class(maxwell_t), pointer :: maxwell_system
1757
1758 float, allocatable :: magnetic_field(:,:)
1759 float, allocatable :: vector_potential_mag(:,:)
1760 float, allocatable :: vector_potential_analytical(:,:)
1761 float, allocatable :: delta(:,:)
1762 float :: exp_factor
1763 float :: xx
1764 float :: yy
1765 float :: zz
1766 float :: sigma
1767 integer :: ip, j, ierr, nn
1768 integer(i8) :: out_how
1769 character(len=MAX_PATH_LEN) :: fname, fname2, fname3
1770
1771 out_how = 32
1772 maxwell_system => maxwell_t(namespace)
1773 sigma = maxwell_system%gr%box%bounding_box_l(1)/cnst(10) ! this is exponential width
1774 call maxwell_system%init_parallelization(mpi_world)
1775
1776 safe_allocate(magnetic_field(1:maxwell_system%gr%np_part, 1:3))
1777 safe_allocate(vector_potential_mag(1:maxwell_system%gr%np_part, 1:3))
1778 safe_allocate(vector_potential_analytical(1:maxwell_system%gr%np_part, 1:3))
1779 safe_allocate(delta(1:maxwell_system%gr%np, 1:3))
1780
1781 !%Variable TestVectorPotentialType
1782 !%Type integer
1783 !%Default bounded
1784 !%Section Calculation Modes::Test
1785 !%Description
1786 !% Select whether bounded or unbounded type will be used for vector potential tests
1787 !%Option bounded 1
1788 !% Analytical Vector Potential formulation is bounded by spatial gaussian
1789 !%Option unbounded 2
1790 !% Analytical Vector Potential is not bounded
1791 !%End
1792 call parse_variable(namespace, 'TestVectorPotentialType', option__testvectorpotentialtype__bounded, nn)
1793
1794 select case (nn)
1795 case (option__testvectorpotentialtype__bounded) ! bounded input
1796 do ip = 1, maxwell_system%gr%np_part
1797 xx = maxwell_system%gr%x(ip, 1)
1798 yy = maxwell_system%gr%x(ip, 2)
1799 zz = maxwell_system%gr%x(ip, 3)
1800 exp_factor = exp((-xx**2 - yy**2 - zz**2)*1/(2*sigma**2))
1801 magnetic_field(ip, 1) = exp_factor*yy*(1 - (-xx**2 + yy**2)/(3*sigma**2) - zz**2/(3*sigma**2))
1802 magnetic_field(ip, 2) = exp_factor * xx * (1 + (-xx**2 + yy**2)/(3*sigma**2) - zz**2/(3*sigma**2))
1803 magnetic_field(ip, 3) = exp_factor * 2 * xx * yy * zz * 1/(3*sigma**2)
1804
1805 vector_potential_analytical(ip, 1) = m_third * xx * zz * exp_factor
1806 vector_potential_analytical(ip, 2) = - m_third * yy * zz * exp_factor
1807 vector_potential_analytical(ip, 3) = m_third * (-xx**2 + yy**2) * exp_factor
1808 end do
1809 case (option__testvectorpotentialtype__unbounded) ! unbounded input, TODO this unit test requires implementation of BCs for Helmholtz decomposition
1810 do ip = 1, maxwell_system%gr%np_part
1811 magnetic_field(ip, 1) = maxwell_system%gr%x(ip, 2)
1812 magnetic_field(ip, 2) = maxwell_system%gr%x(ip, 1)
1813 magnetic_field(ip, 3) = m_zero
1814
1815 vector_potential_analytical(ip, 1) = m_third * maxwell_system%gr%x(ip, 1) * maxwell_system%gr%x(ip, 3)
1816 vector_potential_analytical(ip, 2) = - m_third * maxwell_system%gr%x(ip, 2) * maxwell_system%gr%x(ip, 3)
1817 vector_potential_analytical(ip, 3) = - m_third * (maxwell_system%gr%x(ip, 1)**2 - maxwell_system%gr%x(ip, 2)**2)
1818 end do
1819 end select
1820 call maxwell_system%helmholtz%get_vector_potential(namespace, vector_potential_mag, magnetic_field)
1822 do j = 1, 3
1823 delta(:,:) = m_zero
1824 do ip = 1, maxwell_system%gr%np
1825 delta(ip,j) = vector_potential_analytical(ip, j) - vector_potential_mag(ip, j)
1826 end do
1827 end do
1828
1829 do j = 1, 3
1830 write(message(j),*) 'j, norm2(delta)', j, norm2(delta(:,j))
1831 end do
1832 call messages_info(3)
1833
1834 write(fname, '(a)') 'deviation_from_analytical_formulation' ! use messages later
1835 call io_function_output_vector(out_how , './' , trim(fname), namespace, maxwell_system%space, maxwell_system%gr, &
1836 delta, unit_one, ierr)
1837 write(fname2, '(a)') 'vector_potential_analytical'
1838 call io_function_output_vector(out_how , './' , trim(fname2), namespace, maxwell_system%space, maxwell_system%gr, &
1839 vector_potential_analytical, unit_one, ierr)
1840 write(fname3, '(a)') 'vector_potential_mag'
1841 call io_function_output_vector(out_how , './' , trim(fname3), namespace, maxwell_system%space, maxwell_system%gr, &
1842 vector_potential_mag, unit_one, ierr)
1843
1844 safe_deallocate_a(magnetic_field)
1845 safe_deallocate_a(vector_potential_mag)
1846 safe_deallocate_a(vector_potential_analytical)
1847 safe_deallocate_a(delta)
1848 safe_deallocate_p(maxwell_system)
1849
1850 end subroutine test_vecpot_analytical
1851
1852 ! ---------------------------------------------------------
1853 subroutine multigrid_test_interpolation(mgrid, space)
1854 type(multigrid_t), intent(in) :: mgrid
1855 type(space_t), intent(in) :: space
1856
1857 float, allocatable :: guess0(:), res0(:), guess1(:)
1858 type(mesh_t), pointer :: mesh0, mesh1
1859 float :: delta, xx(3,2), alpha, beta, rr
1860 integer :: nn, ip, ierr, order
1861
1863
1864 !%Variable InterpolationTestOrder
1865 !%Type integer
1866 !%Default 1
1867 !%Section Calculation Modes::Test
1868 !%Description
1869 !% This variable controls the order of the grid interpolation
1870 !% used in the corresponding unit test.
1871 !%End
1872 call parse_variable(global_namespace, 'InterpolationTestOrder', 1, order)
1873
1874 message(1) = 'Info: Testing the grid interpolation.'
1875 message(2) = ''
1876 call messages_info(2)
1877
1878 mesh0 => mgrid%level(0)%mesh
1879 mesh1 => mgrid%level(1)%mesh
1880
1881 safe_allocate(guess0(1:mesh0%np_part))
1882 safe_allocate(res0(1:mesh0%np))
1883 safe_allocate(guess1(1:mesh1%np_part))
1884
1885 alpha = m_four*mesh0%spacing(1)
1886 beta = m_one / (alpha**space%dim * sqrt(m_pi)**space%dim)
1887
1888 ! Set the centers of the Gaussians by hand
1889 xx(1, 1) = m_one
1890 xx(2, 1) = -m_half
1891 xx(3, 1) = m_two
1892 xx(1, 2) = -m_two
1893 xx(2, 2) = m_zero
1894 xx(3, 2) = -m_one
1895 xx = xx * alpha
1896
1897 ! Density as sum of Gaussians
1898 guess0 = m_zero
1899 do nn = 1, 2
1900 do ip = 1, mesh0%np
1901 call mesh_r(mesh0, ip, rr, origin = xx(:, nn))
1902 guess0(ip) = guess0(ip) + (-1)**nn * beta*exp(-(rr/alpha)**2)
1903 end do
1904 end do
1905
1906 call dio_function_output (io_function_fill_how('AxisX'), ".", "interpolation_target", global_namespace, &
1907 space, mesh0, guess0, unit_one, ierr)
1908 call dio_function_output (io_function_fill_how('AxisZ'), ".", "interpolation_target", global_namespace, &
1909 space, mesh0, guess0, unit_one, ierr)
1910 call dio_function_output (io_function_fill_how('PlaneZ'), ".", "interpolation_target", global_namespace, &
1911 space, mesh0, guess0, unit_one, ierr)
1912
1913 ! We start by testing the interpolation scheme. For this, we generate a function on the fine grid
1914 ! and we inject it on the coarse grid. Then we interpolate it back to the fine grid and we compare
1915 ! This allows for testing the quality of the interpolation scheme
1916
1917 ! move to level 1
1918 call dmultigrid_fine2coarse(mgrid%level(1)%tt, mgrid%level(0)%der, mesh1, guess0, guess1, injection)
1919 ! back to level 0
1920 call dmultigrid_coarse2fine(mgrid%level(1)%tt, mgrid%level(1)%der, mesh0, guess1, res0, order = order)
1921
1922 call dio_function_output (io_function_fill_how('AxisX'), ".", "interpolation_result", global_namespace, &
1923 space, mesh0, res0, unit_one, ierr)
1924 call dio_function_output (io_function_fill_how('AxisZ'), ".", "interpolation_result", global_namespace, &
1925 space, mesh0, res0, unit_one, ierr)
1926 call dio_function_output (io_function_fill_how('PlaneZ'), ".", "interpolation_result", global_namespace, &
1927 space, mesh0, res0, unit_one, ierr)
1928
1929 delta = dmf_nrm2(mesh0, guess0(1:mesh0%np)-res0)
1930 write(message(1),'(a,e13.6)') 'Interpolation test (abs.) = ', delta
1931
1932 ! Now we test if the restriction+interpolation combination returns the original result or not
1933 ! This allows to test if restriction and interpolation are adjoint operators or not.
1934
1935 ! move to level 1
1936 call dmultigrid_fine2coarse(mgrid%level(1)%tt, mgrid%level(0)%der, mesh1, guess0, guess1, fullweight)
1937 ! back to level 0
1938 call dmultigrid_coarse2fine(mgrid%level(1)%tt, mgrid%level(1)%der, mesh0, guess1, res0, order = order)
1939
1940 call dio_function_output (io_function_fill_how('AxisX'), ".", "restriction_result", global_namespace, &
1941 space, mesh0, res0, unit_one, ierr)
1942 call dio_function_output (io_function_fill_how('AxisZ'), ".", "restriction_result", global_namespace, &
1943 space, mesh0, res0, unit_one, ierr)
1944 call dio_function_output (io_function_fill_how('PlaneZ'), ".", "restriction_result", global_namespace, &
1945 space, mesh0, res0, unit_one, ierr)
1946
1947 delta = dmf_nrm2(mesh0, guess0(1:mesh0%np)-res0)
1948 write(message(2),'(a,e13.6)') 'Restriction test (abs.) = ', delta
1949 call messages_info(2)
1950
1951 safe_deallocate_a(guess0)
1952 safe_deallocate_a(res0)
1953 safe_deallocate_a(guess1)
1954
1956 end subroutine multigrid_test_interpolation
1957
1958
1960 subroutine test_current_density(namespace)
1961 type(namespace_t), intent(in) :: namespace
1962 type(electrons_t), pointer :: sys
1963
1964 type(current_t) :: current
1965 character(len=MAX_PATH_LEN) :: fname
1966 integer :: ierr, ip, idir
1967 integer(i8) :: out_how
1968 float, allocatable :: current_para_ref(:,:), current_dia_ref(:,:), current_mag_ref(:,:), delta(:)
1969 float :: xx(3), rr, a0, mag_curr, sin_thet, sin_phi, cos_phi, vec_pot_slope
1970 cmplx :: alpha
1971
1972 sys => electrons_t(namespace, generate_epot=.false.)
1973 call sys%init_parallelization(mpi_world)
1974
1975 alpha = (cnst(0.0), cnst(0.5))
1976 a0 = m_one
1977 vec_pot_slope = cnst(0.4) ! units of B field
1978
1979 call states_elec_allocate_wfns(sys%st, sys%gr, wfs_type = type_cmplx)
1980 call set_hydrogen_states(sys%st%group%psib(1, 1), sys%gr, namespace, alpha, a0)
1981
1982 call current_init(current, namespace)
1983
1984 call hamiltonian_elec_epot_generate(sys%hm, sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st)
1985
1986 safe_allocate(sys%hm%hm_base%vector_potential(1:3, 1:sys%gr%np))
1987
1988 sys%hm%hm_base%vector_potential = m_zero
1989 do ip = 1, sys%gr%np
1990 xx = sys%gr%x(ip, 1:3)
1991 sys%hm%hm_base%vector_potential(2, ip) = vec_pot_slope * xx(1) / p_c ! vector potential is here devided by c_0
1992 end do
1993
1994 call states_elec_allocate_current(sys%st, sys%space, sys%gr)
1995 call density_calc(sys%st, sys%gr, sys%st%rho)
1996 ! paramagnetic + diamagnetic current densities
1997 call current_calculate(current, namespace, sys%gr, sys%hm, sys%space, sys%st)
1998
1999 safe_allocate(current_para_ref(1:sys%gr%np,1:3))
2000 safe_allocate(current_dia_ref(1:sys%gr%np,1:3))
2001 safe_allocate(current_mag_ref(1:sys%gr%np,1:3))
2002 safe_allocate(delta(1:sys%gr%np))
2003
2004 ! analytic paramagnetic
2005 current_para_ref(:,:) = m_zero
2006 do ip = 1, sys%gr%np
2007 call mesh_r(sys%gr, ip, rr)
2008 xx = sys%gr%x(ip, 1:3)
2009 if (rr > r_small) then
2010 current_para_ref(ip,1:3) = - (psi_2s(rr, a0) * dr_psi_1s(rr, a0) - &
2011 psi_1s(rr, a0) * dr_psi_2s(rr, a0) ) * imag(alpha) / (1 + abs(alpha)**2) * xx(1:3) / rr
2012 end if
2013 end do
2014
2015 write(fname, '(a)') 'current_para'
2016 out_how = io_function_fill_how("PlaneZ")
2017 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2018 sys%st%current_para(:,:,1), unit_one, ierr)
2019
2020 write(fname, '(a)') 'current_para-ref'
2021 out_how = io_function_fill_how("PlaneZ")
2022 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2023 current_para_ref(:,:), unit_one, ierr)
2024
2025 do idir = 1, 3
2026 delta = m_zero
2027 delta(:) = current_para_ref(1:sys%gr%np, idir) - sys%st%current_para(1:sys%gr%np, idir, 1)
2028 write(message(idir),*) 'idir =',idir,', norm2(delta paramagnetic)',norm2(delta)
2029 end do
2030 call messages_info(3)
2031
2032 ! analytic diamagnetic
2033 current_dia_ref(:,:) = m_zero
2034 do ip = 1, sys%gr%np
2035 call mesh_r(sys%gr, ip, rr)
2036 current_dia_ref(ip,1:3) = - sys%hm%hm_base%vector_potential(1:3,ip) *&
2037 m_one / (1 + abs(alpha)**2) * abs(lc_hydrogen_state(rr, alpha, a0))**2
2038 end do
2039
2040 write(fname, '(a)') 'current_dia'
2041 out_how = io_function_fill_how("PlaneZ")
2042 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2043 sys%st%current_dia(:,:,1), unit_one, ierr)
2044
2045 write(fname, '(a)') 'current_dia-ref'
2046 out_how = io_function_fill_how("PlaneZ")
2047 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2048 current_dia_ref(:,:), unit_one, ierr)
2049
2050 do idir = 1, 3
2051 delta = m_zero
2052 delta(:) = current_dia_ref(1:sys%gr%np, idir) - sys%st%current_dia(1:sys%gr%np, idir, 1)
2053 write(message(idir),*) 'idir =',idir,', norm2(delta diamagnetic)',norm2(delta)
2054 end do
2055 call messages_info(3)
2056
2057 ! magnetization current
2058 call current_calculate_mag(current, namespace, sys%gr%der, sys%hm, sys%st)
2059
2060 ! analytic magnetization
2061 current_mag_ref(:,:) = m_zero
2062 do ip = 1, sys%gr%np
2063 call mesh_r(sys%gr, ip, rr)
2064 xx = sys%gr%x(ip, 1:3)
2065 if (norm2(xx(1:2)) > r_small .and. rr > r_small) then
2066 sin_thet = norm2(xx(1:2)) / rr
2067 sin_phi = xx(2) / norm2(xx(1:2))
2068 cos_phi = xx(1) / norm2(xx(1:2))
2069 mag_curr = m_two * (psi_1s(rr,a0)*dr_psi_1s(rr,a0) + real(alpha)*(psi_1s(rr,a0)*dr_psi_2s(rr,a0) &
2070 + dr_psi_1s(rr,a0)*psi_2s(rr,a0)) + abs(alpha)**2 * psi_2s(rr,a0)*dr_psi_2s(rr,a0))
2071 ! minus signs are reversed because of the charge of the electron
2072 current_mag_ref(ip,1) = m_half * mag_curr * sin_thet * sin_phi / (1+abs(alpha)**2)
2073 current_mag_ref(ip,2) = -m_half * mag_curr * sin_thet * cos_phi / (1+abs(alpha)**2)
2074 endif
2075 end do
2076
2077 write(fname, '(a)') 'current_mag'
2078 out_how = io_function_fill_how("PlaneZ")
2079 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2080 sys%st%current_mag(:,:,1), unit_one, ierr)
2081
2082 write(fname, '(a)') 'current_mag-ref'
2083 out_how = io_function_fill_how("PlaneZ")
2084 call io_function_output_vector(out_how , './' , trim(fname), namespace, sys%space, sys%gr, &
2085 current_mag_ref(:,:), unit_one, ierr)
2086
2087 do idir = 1, 3
2088 delta = m_zero
2089 delta(:) = current_mag_ref(1:sys%gr%np, idir) - sys%st%current_mag(1:sys%gr%np, idir, 1)
2090 write(message(idir),*) 'idir =',idir,', norm2(delta magnetization)',norm2(delta)
2091 end do
2092 call messages_info(3)
2093
2094 safe_deallocate_a(current_para_ref)
2095 safe_deallocate_a(current_dia_ref)
2096 safe_deallocate_a(current_mag_ref)
2097 safe_deallocate_a(delta)
2098 safe_deallocate_p(sys)
2099
2100 end subroutine test_current_density
2101
2102
2103 subroutine set_hydrogen_states(psib, mesh, namespace, alpha, a0)
2104 class(batch_t), intent(inout) :: psib
2105 class(mesh_t), intent(in) :: mesh
2106 type(namespace_t), intent(in) :: namespace
2107 cmplx, intent(in) :: alpha
2108 float, intent(in) :: a0
2109
2110 cmplx, allocatable :: zff(:)
2111 integer :: ip
2112 float :: rr
2113
2115
2116 ! psi = phi_{1s} + \alpha \phi_{2s}
2117 safe_allocate(zff(1:mesh%np))
2118 if (type_is_complex(psib%type())) then
2119 do ip = 1, mesh%np
2120 call mesh_r(mesh, ip, rr)
2121 zff(ip) = m_one / sqrt(1 + abs(alpha)**2) * lc_hydrogen_state(rr, alpha, a0)
2122 call batch_set_state(psib, 1, mesh%np, zff)
2123 end do
2124 safe_deallocate_a(zff)
2125 else
2126 write(message(1),*) "States should be complex for the linear combination of hydrogenic states to work"
2127 call messages_info(1, namespace=namespace)
2128 end if
2129
2131 end subroutine set_hydrogen_states
2132
2133 cmplx function lc_hydrogen_state(rr, alpha, a0)
2134 float, intent(in) :: a0, rr
2135 cmplx, intent(in) :: alpha
2136
2137 lc_hydrogen_state = psi_1s(rr, a0) + alpha * psi_2s(rr, a0)
2138 end function lc_hydrogen_state
2139
2140 ! phi_{1s} = R_{10}(r)Y_{00}(\theta, \phi) = 1/(2\sqrt(\pi)) * 2 a0^{-3/2} * \exp(-r/a0)
2141 float function psi_1s(rr, a0)
2142 float, intent(in) :: a0, rr
2143
2144 psi_1s = a0**(-m_three/m_two) * exp(-rr / a0) / sqrt(m_pi)
2145 end function psi_1s
2146
2147 ! phi_{2s} = R_{20}(r)Y_{00}(\theta, \phi) = 1/(2\sqrt(\pi)) * \sqrt(2) a0^{-3/2} (1 - r/(2a0)) \exp(-r/(2a0))
2148 float function psi_2s(rr, a0)
2149 float, intent(in) :: a0, rr
2150
2151 psi_2s = sqrt(m_two) * a0**(-m_three/m_two) * (m_one - rr/(m_two * a0)) * exp(-rr/(m_two * a0)) &
2152 / (m_two * sqrt(m_pi))
2153 end function psi_2s
2154
2155 float function dr_psi_1s(rr, a0)
2156 float, intent(in) :: a0, rr
2157
2158 dr_psi_1s = -(m_one / a0) * psi_1s(rr, a0)
2159 end function dr_psi_1s
2160
2161 float function dr_psi_2s(rr, a0)
2162 float, intent(in) :: a0, rr
2163
2164 dr_psi_2s = -(m_half / a0) * psi_2s(rr, a0) - &
2165 a0**(-m_five/m_two) * exp(-rr/(m_two * a0)) / (sqrt(m_two) * m_two * sqrt(m_pi))
2166 end function dr_psi_2s
2167
2168end module test_oct_m
2169
2170!! Local Variables:
2171!! mode: f90
2172!! coding: utf-8
2173!! End:
There are several ways how to call batch_set_state and batch_get_state:
Definition: batch_ops.F90:188
constant times a vector plus a vector
Definition: lalg_basic.F90:161
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:176
scales a vector by a constant
Definition: lalg_basic.F90:147
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:176
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
Definition: batch.F90:120
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:108
subroutine, public batch_set_zero(this)
Definition: batch_ops.F90:230
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:114
Module, implementing a factory for boxes.
This module handles the calculation mode.
subroutine, public calc_mode_par_set_parallelization(par, default)
Add a parallelization strategy to the list of possible ones. Make it default also if default = ....
subroutine, public calc_mode_par_set_scalapack_compat()
Defines that the current run mode requires division of states and domains to be compatible with scala...
subroutine, public calc_mode_par_unset_parallelization(par)
Remove a parallelization strategy from the list of possible ones. It will also be removed from the de...
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)
integer, parameter, public clock_tick
Definition: clock.F90:120
subroutine, public current_calculate_mag(this, namespace, der, hm, st)
Compute magnetization current Note: due to the the numerical curl, the magnetization current could de...
Definition: current.F90:435
subroutine, public current_calculate(this, namespace, gr, hm, space, st)
Compute total electronic current density.
Definition: current.F90:368
subroutine, public current_init(this, namespace)
Definition: current.F90:168
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:562
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public dderivatives_test(this, namespace, repetitions, min_blocksize, max_blocksize)
unit test for derivatives
subroutine, public dderivatives_lapl(der, ff, op_ff, ghost_update, set_bc, factor)
apply the Laplacian to a mesh function
subroutine, public zderivatives_test(this, namespace, repetitions, min_blocksize, max_blocksize)
unit test for derivatives
subroutine, public exponential_init(te, namespace)
real(8), parameter, public m_five
Definition: global.F90:175
real(8), parameter, public m_pi
some mathematical constants
Definition: global.F90:168
real(8), parameter, public m_two
Definition: global.F90:172
real(8), parameter, public r_small
Definition: global.F90:162
real(8), parameter, public p_c
Definition: global.F90:199
real(8), parameter, public m_one
Definition: global.F90:171
complex(8), parameter, public m_zi
Definition: global.F90:184
real(8), parameter, public m_zero
Definition: global.F90:170
real(8), parameter, public m_half
Definition: global.F90:176
real(8), parameter, public m_four
Definition: global.F90:174
real(8), parameter, public m_third
Definition: global.F90:177
real(8), parameter, public m_three
Definition: global.F90:173
This module implements the underlying real-space grid.
Definition: grid.F90:109
subroutine, public zhamiltonian_elec_apply_batch(hm, namespace, mesh, psib, hpsib, terms, set_bc)
subroutine, public hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
subroutine, public dhamiltonian_elec_apply_batch(hm, namespace, mesh, psib, hpsib, terms, set_bc)
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:117
subroutine, public iihash_end(h)
Free a hash table.
Definition: iihash.F90:177
subroutine, public iihash_insert(h, key, val)
Insert a (key, val) pair into the hash table h.
Definition: iihash.F90:199
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:224
subroutine, public iihash_init(h)
Initialize a hash table h.
Definition: iihash.F90:154
subroutine, public dio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
integer(i8) 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:106
subroutine, public ion_interaction_test(space, latt, atom, natoms, pos, lsize, namespace, mc)
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:108
subroutine, public dmesh_batch_dotp_matrix(mesh, aa, bb, dot, reduce)
Calculate the overlap matrix of two batches.
Definition: mesh_batch.F90:255
subroutine, public dmesh_batch_dotp_self(mesh, aa, dot, reduce)
calculate the overlap matrix of a batch with itself
Definition: mesh_batch.F90:502
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:162
subroutine, public zmesh_batch_dotp_vector(mesh, aa, bb, dot, reduce, cproduct)
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)
Definition: mesh_batch.F90:617
This module defines various routines, operating on mesh functions.
class(mesh_t), pointer, public mesh_aux
real(8) function, public dmf_dotp_aux(f1, f2)
dot product between two vectors
subroutine, public mesh_init_mesh_aux(mesh)
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:110
subroutine, public mesh_r(mesh, ip, rr, origin, coords)
return radial component
Definition: mesh.F90:324
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:918
character(len=512), private msg
Definition: messages.F90:162
subroutine, public push_sub(sub_name)
Definition: messages.F90:1046
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1168
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
Definition: messages.F90:611
subroutine, public messages_new_line()
Definition: messages.F90:1257
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:157
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:406
subroutine, public pop_sub(sub_name)
Definition: messages.F90:1101
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:247
subroutine, public test_mpiwrappers
Definition: mpi_test.F90:119
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:137
integer, parameter, public p_strategy_domains
parallelization in domains
Definition: multicomm.F90:172
integer, parameter, public p_strategy_kpoints
parallelization in k-points
Definition: multicomm.F90:172
integer, parameter, public p_strategy_states
parallelization in states
Definition: multicomm.F90:172
subroutine, public multigrid_init(mgrid, namespace, space, mesh, der, stencil, mc, used_for_preconditioner)
Definition: multigrid.F90:178
subroutine, public multigrid_end(mgrid)
Definition: multigrid.F90:484
subroutine, public dmultigrid_fine2coarse(tt, fine_der, coarse_mesh, f_fine, f_coarse, method_p)
Definition: multigrid.F90:688
integer, parameter, public fullweight
Definition: multigrid.F90:149
subroutine, public dmultigrid_coarse2fine(tt, coarse_der, fine_mesh, f_coarse, f_fine, order, set_bc)
Definition: multigrid.F90:605
integer, parameter, public injection
Definition: multigrid.F90:149
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_get_coeff_batch(os, ndim, psib, dot)
Definition: orbitalset.F90:553
subroutine, public dorbitalset_add_to_batch(os, ndim, psib, weight)
Definition: orbitalset.F90:692
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:266
subroutine, public zorbitalset_get_coeff_batch(os, ndim, psib, dot)
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...
Definition: poisson.F90:1174
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:1256
Implementation details for regridding.
Definition: regridding.F90:154
This module implements a simple hash table for string valued keys and integer values using the C++ ST...
Definition: sihash.F90:110
subroutine, public sihash_insert(h, key, val)
Insert a (key, val) pair into the hash table h.
Definition: sihash.F90:195
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:154
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:221
subroutine, public sihash_end(h)
Free a hash table.
Definition: sihash.F90:175
This module is intended to contain "only mathematical" functions and procedures.
Definition: solvers.F90:109
subroutine, public space_init(this, namespace)
Definition: space.F90:137
This module implements a simple hash table for string valued keys and integer values using the C++ ST...
Definition: sphash.F90:110
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:215
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:279
subroutine, public sphash_end(h)
Free a hash table.
Definition: sphash.F90:236
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:311
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)
integer, parameter, public spin_polarized
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 states_elec_allocate_current(st, space, mesh)
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:296
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:912
This module implements a unit-test like runmode for Octopus.
Definition: test.F90:108
subroutine test_sihash()
Definition: test.F90:1582
subroutine test_cgal()
Definition: test.F90:1404
subroutine test_helmholtz_decomposition(namespace)
Definition: test.F90:413
subroutine test_hartree(param, namespace)
Definition: test.F90:394
subroutine test_derivatives(param, namespace)
Definition: test.F90:1180
subroutine test_subspace_diagonalization(param, namespace)
Definition: test.F90:900
subroutine, public test_run(namespace)
Definition: test.F90:193
subroutine test_density_calc(param, namespace)
Definition: test.F90:776
real(8) shift_aux
Definition: test.F90:183
subroutine test_iihash()
Definition: test.F90:1556
subroutine test_current_density(namespace)
Here we test the different contributions to the total electronic current density.
Definition: test.F90:2046
subroutine test_batch_set_gaussian(psib, mesh)
Definition: test.F90:1483
complex(8) function lc_hydrogen_state(rr, alpha, a0)
Definition: test.F90:2219
real(8) function psi_2s(rr, a0)
Definition: test.F90:2234
subroutine test_regridding(namespace)
Definition: test.F90:1721
subroutine test_sphash(namespace)
Definition: test.F90:1628
subroutine test_hamiltonian(param, namespace)
Definition: test.F90:694
subroutine test_dense_eigensolver()
Definition: test.F90:1424
real(8) function psi_1s(rr, a0)
Definition: test.F90:2227
subroutine test_interpolation(param, namespace)
Definition: test.F90:1252
subroutine multigrid_test_interpolation(mgrid, space)
Definition: test.F90:1939
subroutine test_ion_interaction(namespace)
Definition: test.F90:1290
subroutine test_boundaries(param, namespace)
Definition: test.F90:814
subroutine test_orthogonalization(param, namespace)
Definition: test.F90:1210
subroutine test_batch_ops(param, namespace)
Definition: test.F90:953
subroutine test_projector(param, namespace)
Definition: test.F90:534
subroutine test_dft_u(param, namespace)
Definition: test.F90:586
subroutine test_prints_info_batch(st, gr, psib, string)
Definition: test.F90:1310
real(8) function dr_psi_2s(rr, a0)
Definition: test.F90:2247
subroutine test_linear_solver(namespace)
Definition: test.F90:444
subroutine test_grid_interpolation()
Definition: test.F90:1535
subroutine set_hydrogen_states(psib, mesh, namespace, alpha, a0)
Definition: test.F90:2189
real(8) function dr_psi_1s(rr, a0)
Definition: test.F90:2241
subroutine test_exponential(param, namespace)
Definition: test.F90:851
subroutine test_vecpot_analytical(namespace)
Here, analytical formulation for vector potential and B field are used. Ref: Sangita Sen and Erik I....
Definition: test.F90:1839
subroutine test_clock()
Definition: test.F90:1355
type(type_t), public type_cmplx
Definition: types.F90:126
logical pure function, public type_is_complex(this)
Definition: types.F90:172
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, use_vxc)
Definition: v_ks.F90:723
Class defining batches of mesh functions.
Definition: batch.F90:145
class representing derivatives
Class describing the electron system.
Definition: electrons.F90:196
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:159
Class describing Maxwell systems.
Definition: maxwell.F90:184
Describes mesh distribution to nodes.
Definition: mesh.F90:175
contains the information of the meshes and provides the transfer functions
Definition: regridding.F90:177
The states_elec_t class contains all electronic wave funnctions.
batches of electronic states
Definition: wfs_elec.F90:126
int true(void)
subroutine laplacian_op(x, hx)
Computes .
Definition: test.F90:513
subroutine set_der_aux(der)
Definition: test.F90:504
real(8) function values(xx)
Definition: test.F90:1822