22use omp_lib,
only : omp_get_wtime
45 real(dp),
allocatable :: vscales(:)
48 real(dp),
allocatable :: v4pi2lp1(:)
53 real(dp),
allocatable :: vscales_rel(:)
59 real(dp),
allocatable :: vfact(:)
63 real(dp),
allocatable :: vcnk(:)
67 real(dp),
allocatable :: m2l_ztranslate_coef(:, :, :)
71 real(dp),
allocatable :: m2l_ztranslate_adj_coef(:, :, :)
73 real(dp),
allocatable :: cgrid(:, :)
75 real(dp),
allocatable :: wgrid(:)
83 integer :: vgrid_nbasis
86 real(dp),
allocatable :: vgrid(:, :)
90 real(dp),
allocatable :: vwgrid(:, :)
92 real(dp),
allocatable :: vgrid2(:, :)
99 real(dp),
allocatable :: pchi(:, :, :)
102 real(dp),
allocatable :: c_ik(:, :)
104 real(dp),
allocatable :: si_ri(:, :)
107 real(dp),
allocatable :: di_ri(:, :)
109 real(dp),
allocatable :: sk_ri(:, :)
112 real(dp),
allocatable :: dk_ri(:, :)
114 real(dp),
allocatable :: termimat(:, :)
116 real(dp),
allocatable :: b(:,:,:)
118 real(dp),
allocatable :: l(:,:,:)
123 integer,
allocatable :: inl(:)
126 integer,
allocatable :: nl(:)
128 integer,
allocatable :: itrnl(:)
131 real(dp),
allocatable :: fi(:, :)
134 real(dp),
allocatable :: ui(:, :)
137 real(dp),
allocatable :: ui_cav(:)
140 real(dp),
allocatable :: zi(:, :, :)
143 real(dp),
allocatable :: zi_dr(:, :)
147 integer,
allocatable :: ncav_sph(:)
149 real(dp),
allocatable :: ccav(:, :)
151 integer,
allocatable :: icav_ia(:)
153 integer,
allocatable :: icav_ja(:)
156 real(dp),
allocatable :: rx_prc(:, :, :)
160 integer,
allocatable :: order(:)
165 integer,
allocatable :: cluster(:, :)
168 integer,
allocatable :: children(:, :)
171 integer,
allocatable :: parent(:)
174 real(dp),
allocatable :: cnode(:, :)
177 real(dp),
allocatable :: rnode(:)
180 integer,
allocatable :: snode(:)
183 real(dp),
allocatable :: sk_rnode(:, :)
186 real(dp),
allocatable :: si_rnode(:, :)
193 integer,
allocatable :: nfar(:)
196 integer,
allocatable :: nnear(:)
199 integer,
allocatable :: far(:)
202 integer,
allocatable :: near(:)
206 integer,
allocatable :: sfar(:)
210 integer,
allocatable :: snear(:)
219 integer :: m2p_nbasis
223 integer :: grad_nbasis
225 real(dp) :: inner_tol
245 type(ddx_error_type),
intent(inout) :: ddx_error
247 integer :: i, alloc_size, l, indl, igrid, isph, l0, &
248 & NZ, ierr, info, tmp_pmax
249 real(dp) :: rho, ctheta, stheta, cphi, sphi, termi, termk, &
251 real(dp),
allocatable :: vplm(:), vcos(:), vsin(:), vylm(:), SK_rijn(:), &
253 complex(dp),
allocatable :: bessel_work(:)
257 if (ddx_error % flag .ne. 0)
then
258 call update_error(ddx_error,
"constants_init received input in error " // &
264 constants % dodiag = .false.
266 constants % nbasis = (params % lmax+1) ** 2
268 constants % n = params % nsph * constants % nbasis
270 if (params % fmm .eq. 0)
then
271 if (params % force .eq. 1)
then
272 constants % dmax = params % lmax + 1
273 constants % vgrid_dmax = params % lmax + 1
275 constants % dmax = params % lmax
276 constants % vgrid_dmax = params % lmax
279 constants % m2p_lmax = -1
280 constants % m2p_nbasis = -1
281 constants % grad_nbasis = -1
285 if (params % force .eq. 1)
then
286 constants % dmax = max(params % pm+params % pl+1, &
288 constants % m2p_lmax = params % lmax + 1
289 constants % grad_nbasis = (params % lmax+2) ** 2
290 constants % vgrid_dmax = max(params % pl, params % lmax) + 1
292 constants % dmax = max(params % pm+params % pl, &
294 constants % m2p_lmax = params % lmax
295 constants % grad_nbasis = -1
296 constants % vgrid_dmax = max(params % pl, params % lmax)
298 constants % m2p_nbasis = (constants % m2p_lmax+1) ** 2
301 constants % vgrid_nbasis = (constants % vgrid_dmax+1) ** 2
302 constants % nfact = 2*constants % dmax+1
303 constants % nscales = (constants % dmax+1) ** 2
305 allocate(constants % vscales(constants % nscales), stat=info)
306 if (info .ne. 0)
then
307 call update_error(ddx_error,
"constants_init: `vscales` allocation " &
311 allocate(constants % v4pi2lp1(constants % dmax+1), stat=info)
312 if (info .ne. 0)
then
313 call update_error(ddx_error,
"constants_init: `v4pi2lp1` allocation " &
317 allocate(constants % vscales_rel(constants % nscales), stat=info)
318 if (info .ne. 0)
then
319 call update_error(ddx_error,
"constants_init: `vscales_rel` " // &
320 &
"allocation failed")
324 call ylmscale(constants % dmax, constants % vscales, &
325 & constants % v4pi2lp1, constants % vscales_rel)
327 allocate(constants % vfact(constants % nfact), stat=info)
328 if (info .ne. 0)
then
329 call update_error(ddx_error,
"constants_init: `vfact` allocation failed")
333 constants % vfact(1) = 1
334 do i = 2, constants % nfact
335 constants % vfact(i) = constants % vfact(i-1) * sqrt(dble(i-1))
339 if (params % fmm .eq. 1 .or. &
340 & (params % model .eq. 3 .and. params % force .eq. 1))
then
341 alloc_size = 2*constants % dmax + 1
342 alloc_size = alloc_size * (constants % dmax+1)
344 allocate(constants % vcnk(alloc_size), stat=info)
345 if (info .ne. 0)
then
346 call update_error(ddx_error,
"constants_init: `vcnk` allocation " &
351 allocate(constants % m2l_ztranslate_coef(&
352 & (params % pm+1), (params % pl+1), (params % pl+1)), &
354 if (info .ne. 0)
then
355 call update_error(ddx_error,
"constants_init: " // &
356 &
"`m2l_ztranslate_coef` allocation failed")
360 allocate(constants % m2l_ztranslate_adj_coef(&
361 & (params % pl+1), (params % pl+1), (params % pm+1)), &
363 if (info .ne. 0)
then
364 call update_error(ddx_error,
"constants_init: " // &
365 &
"`m2l_ztranslate_adj_coef` allocation failed")
370 & params % pl, constants % vcnk, &
371 & constants % m2l_ztranslate_coef, &
372 & constants % m2l_ztranslate_adj_coef)
375 allocate(constants % cgrid(3, params % ngrid), &
376 & constants % wgrid(params % ngrid), stat=info)
377 if (info .ne. 0)
then
378 call update_error(ddx_error,
"constants_init: `cgrid` and `wgrid` " // &
379 &
"allocations failed")
383 call llgrid(params % ngrid, constants % wgrid, constants % cgrid)
386 allocate(constants % vgrid(constants % vgrid_nbasis, params % ngrid), &
387 & constants % vwgrid(constants % vgrid_nbasis, params % ngrid), &
389 if (info .ne. 0)
then
390 call update_error(ddx_error,
"constants_init: `vgrid`, `wgrid` and" // &
391 &
" allocations failed")
394 allocate(vplm(constants % vgrid_nbasis), vcos(constants % vgrid_dmax+1), &
395 & vsin(constants % vgrid_dmax+1), stat=info)
396 if (info .ne. 0)
then
397 call update_error(ddx_error,
"constants_init: `vplm`, `vcos` and " // &
398 &
"`vsin` allocations failed")
403 do igrid = 1, params % ngrid
404 call ylmbas(constants % cgrid(:, igrid), rho, ctheta, stheta, cphi, &
405 & sphi, constants % vgrid_dmax, constants % vscales, &
406 & constants % vgrid(:, igrid), vplm, vcos, vsin)
407 constants % vwgrid(:, igrid) = constants % wgrid(igrid) * &
408 & constants % vgrid(:, igrid)
410 if (params % fmm .eq. 1)
then
411 allocate(constants % vgrid2( &
412 & constants % vgrid_nbasis, params % ngrid), &
414 if (info .ne. 0)
then
415 call update_error(ddx_error,
"constants_init: `vgrid2` " // &
416 &
"allocation failed")
419 do igrid = 1, params % ngrid
420 do l = 0, constants % vgrid_dmax
422 constants % vgrid2(indl-l:indl+l, igrid) = &
423 & constants % vgrid(indl-l:indl+l, igrid) / &
424 & constants % vscales(indl)**2
431 if (ddx_error % flag .ne. 0)
then
432 call update_error(ddx_error,
"constants_geometry_init returned an " // &
438 if (params % model .eq. 3)
then
439 constants % lmax0 = params % lmax
440 constants % nbasis0 = constants % nbasis
441 allocate(vylm(constants % vgrid_nbasis), &
442 & sk_rijn(0:constants % lmax0), dk_rijn(0:constants % lmax0), &
443 & bessel_work(constants % dmax+2), stat=info)
444 if (info .ne. 0)
then
445 call update_error(ddx_error,
"constants_init: `vylm`, `SK_rijn` " // &
446 &
"and `DK_rijn` allocations failed")
449 allocate(constants % SI_ri(0:constants % dmax+1, params % nsph), &
450 & constants % DI_ri(0:constants % dmax+1, params % nsph), &
451 & constants % SK_ri(0:params % lmax+1, params % nsph), &
452 & constants % DK_ri(0:params % lmax+1, params % nsph), &
453 & constants % Pchi(constants % nbasis, constants % nbasis0, params % nsph), &
454 & constants % C_ik(0:params % lmax, params % nsph), &
455 & constants % termimat(0:params % lmax, params % nsph), &
457 if (info .ne. 0)
then
458 call update_error(ddx_error,
"constants_init: allocation failed")
463 do isph = 1, params % nsph
466 call modified_spherical_bessel_first_kind(constants % dmax+1, &
467 & params % rsph(isph)*params % kappa,&
468 & constants % SI_ri(:, isph), constants % DI_ri(:, isph), &
470 call modified_spherical_bessel_second_kind(params % lmax+1, &
471 & params % rsph(isph)*params % kappa, &
472 & constants % SK_ri(:, isph), constants % DK_ri(:, isph), &
477 call mkpmat(params, constants, isph, constants % Pchi(:, :, isph))
479 do l = 0, params % lmax
480 constants % termimat(l, isph) = constants % DI_ri(l, isph) / &
481 & constants % SI_ri(l, isph) * params % kappa
484 do l0 = 0, constants % lmax0
485 termi = constants % DI_ri(l0, isph) / &
486 & constants % SI_ri(l0, isph) * params % kappa
487 termk = constants % DK_ri(l0, isph)/ &
488 & constants % SK_ri(l0, isph) * params % kappa
489 constants % C_ik(l0, isph) = one / (termi-termk)
492 if (params % fmm .eq. 1)
then
493 tmp_pmax = max(params % pm, params % pl)
494 allocate(constants % SI_rnode(tmp_pmax+1, constants % nclusters), &
495 & constants % SK_rnode(tmp_pmax+1, constants % nclusters), &
498 call update_error(ddx_error,
"constants_init: `si_rnode, " // &
499 &
"sk_rnode allocation failed")
502 do i = 1, constants % nclusters
503 z = constants % rnode(i) * params % kappa
504 s1 = sqrt(two/(pi*real(z)))
505 s2 = sqrt(pi/(two*real(z)))
506 call cbesk(z, pt5, 1, 1, bessel_work(1), nz, ierr)
507 constants % SK_rnode(1, i) = s1 * real(bessel_work(1))
508 call cbesi(z, pt5, 1, 1, bessel_work(1), nz, ierr)
509 constants % SI_rnode(1, i) = s2 * real(bessel_work(1))
510 if (tmp_pmax .gt. 0)
then
511 call cbesk(z, 1.5d0, 1, tmp_pmax, bessel_work(2:), nz, ierr)
512 constants % SK_rnode(2:, i) = s1 * real(bessel_work(2:tmp_pmax+1))
513 call cbesi(z, 1.5d0, 1, tmp_pmax, bessel_work(2:), nz, ierr)
514 constants % SI_rnode(2:, i) = s2 * real(bessel_work(2:tmp_pmax+1))
518 deallocate(vylm, sk_rijn, dk_rijn, bessel_work, stat=info)
519 if (info .ne. 0)
then
520 call update_error(ddx_error,
"constants_init: `vylm`, `SK_rijn` " // &
521 &
"and `DK_rijn` deallocations failed")
525 if (params % matvecmem .eq. 1)
then
526 call build_b(constants, params, ddx_error)
527 if (ddx_error % flag .ne. 0)
then
528 call update_error(ddx_error,
"build_b returned an " // &
534 deallocate(vplm, vcos, vsin, stat=info)
535 if (info .ne. 0)
then
536 call update_error(ddx_error,
"constants_init: `vplm`, `vcos` and " // &
537 &
"`vsin` deallocations failed")
541 if (params % matvecmem .eq. 1)
then
543 if (ddx_error % flag .ne. 0)
then
544 call update_error(ddx_error,
"build_itrnl returned an " // &
548 call build_l(constants, params, ddx_error)
549 if (ddx_error % flag .ne. 0)
then
550 call update_error(ddx_error,
"build_l returned an " // &
562 type(ddx_error_type),
intent(inout) :: ddx_error
563 integer :: isph, ij, jsph, ji, istat
565 allocate(constants % itrnl(constants % inl(params % nsph + 1)), stat=istat)
567 call update_error(ddx_error,
'Allocation failed in build_itrnl')
571 do isph = 1, params % nsph
572 do ij = constants % inl(isph), constants % inl(isph + 1) - 1
573 jsph = constants % nl(ij)
574 do ji = constants % inl(jsph), constants % inl(jsph + 1) - 1
575 if (constants % nl(ji) .eq. isph)
exit
577 constants % itrnl(ij) = ji
583subroutine build_l(constants, params, ddx_error)
587 type(ddx_error_type),
intent(inout) :: ddx_error
588 integer :: isph, ij, jsph, igrid, l, m, ind, info
589 real(dp),
dimension(3) :: vij, sij
590 real(dp) :: vvij, tij, xij, oij, rho, ctheta, stheta, cphi, sphi, &
592 real(dp),
dimension(constants % nbasis) :: vylm, vplm
593 real(dp),
dimension(params % lmax + 1) :: vcos, vsin
594 real(dp),
dimension(constants % nbasis, params % ngrid) :: scratch
597 allocate(constants % l(constants % nbasis, constants % nbasis, &
598 & constants % inl(params % nsph + 1)), stat=info)
599 if (info .ne. 0)
then
600 call update_error(ddx_error,
'Allocation failed in build_l')
604 thigh = one + pt5*(params % se + one)*params % eta
610 do isph = 1, params % nsph
611 do ij = constants % inl(isph), constants % inl(isph + 1) - 1
612 jsph = constants % nl(ij)
614 do igrid = 1, params % ngrid
615 if (constants % ui(igrid, isph).eq.one) cycle
616 vij = params % csph(:, isph) &
617 & + params % rsph(isph)*constants % cgrid(:,igrid) &
618 & - params % csph(:, jsph)
619 vvij = sqrt(dot_product(vij, vij))
620 tij = vvij/params % rsph(jsph)
621 if (tij.lt.thigh)
then
622 if (tij.ne.zero)
then
627 xij =
fsw(tij, params % se, params % eta)
628 if (constants % fi(igrid, isph).gt.one)
then
629 oij = xij/constants % fi(igrid, isph)
633 call ylmbas(sij, rho, ctheta, stheta, cphi, sphi, &
634 & params % lmax, constants % vscales, vylm, vplm, &
637 do l = 0, params % lmax
639 fac = - tt/(constants % vscales(ind)**2)
641 scratch(ind + m, igrid) = fac*vylm(ind + m)
647 call dgemm(
'n',
't', constants % nbasis, constants % nbasis, params % ngrid, &
648 & one, constants % vwgrid, constants % vgrid_nbasis, scratch, &
649 & constants % nbasis, zero, constants % l(:,:,ij), constants % nbasis)
655subroutine build_b(constants, params, ddx_error)
659 type(ddx_error_type),
intent(inout) :: ddx_error
660 integer :: isph, ij, jsph, igrid, l, m, ind
661 real(dp),
dimension(3) :: vij, sij
662 real(dp) :: vvij, tij, xij, oij, rho, ctheta, stheta, cphi, sphi, &
664 real(dp),
dimension(constants % nbasis) :: vylm, vplm
665 real(dp),
dimension(params % lmax + 1) :: vcos, vsin
666 complex(dp),
dimension(max(2, params % lmax + 1)) :: bessel_work
667 real(dp),
dimension(0:params % lmax) :: SI_rijn, DI_rijn
668 real(dp),
dimension(constants % nbasis, params % ngrid) :: scratch
672 allocate(constants % b(constants % nbasis, constants % nbasis, &
673 & constants % inl(params % nsph + 1)), stat=info)
675 call update_error(ddx_error,
"Allocation failed in build_b")
679 thigh = one + pt5*(params % se + one)*params % eta
686 do isph = 1, params % nsph
687 do ij = constants % inl(isph), constants % inl(isph + 1) - 1
688 jsph = constants % nl(ij)
690 do igrid = 1, params % ngrid
691 if (constants % ui(igrid, isph).eq.one) cycle
692 vij = params % csph(:, isph) &
693 & + params % rsph(isph)*constants % cgrid(:,igrid) &
694 & - params % csph(:, jsph)
695 vvij = sqrt(dot_product(vij, vij))
696 tij = vvij/params % rsph(jsph)
697 if (tij.lt.thigh)
then
698 if (tij.ne.zero)
then
703 xij =
fsw(tij, params % se, params % eta)
704 if (constants % fi(igrid, isph).gt.one)
then
705 oij = xij/constants % fi(igrid, isph)
709 call ylmbas(sij, rho, ctheta, stheta, cphi, sphi, &
710 & params % lmax, constants % vscales, vylm, vplm, &
714 vvtij = vvij*params % kappa
715 call modified_spherical_bessel_first_kind(params % lmax, &
716 & vvtij, si_rijn, di_rijn, bessel_work)
717 do l = 0, params % lmax
718 fac = - oij*si_rijn(l)/constants % SI_ri(l, jsph)
721 scratch(ind + m, igrid) = fac*vylm(ind + m)
726 call dgemm(
'n',
't', constants % nbasis, constants % nbasis, params % ngrid, &
727 & one, constants % vwgrid, constants % vgrid_nbasis, scratch, &
728 & constants % nbasis, zero, constants % b(:,:,ij), constants % nbasis)
734subroutine mkpmat(params, constants, isph, pmat)
737 integer,
intent(in) :: isph
738 real(dp),
dimension(constants % nbasis, constants % nbasis0),
intent(inout) :: pmat
739 integer :: l, m, ind, l0, m0, ind0, its
742 do its = 1, params % ngrid
743 if (constants % ui(its,isph).ne.0)
then
744 do l = 0, params % lmax
747 f = constants % wgrid(its) * constants % vgrid(ind+m,its) * constants % ui(its,isph)
748 do l0 = 0, constants % lmax0
749 ind0 = l0*l0 + l0 + 1
751 f0 = constants % vgrid(ind0+m0,its)
752 pmat(ind+m,ind0+m0) = pmat(ind+m,ind0+m0) + f * f0
775 type(ddx_error_type),
intent(inout) :: ddx_error
777 real(dp) :: swthr, v(3), maxv, ssqv, vv, t
778 integer :: i, isph, jsph, inear, igrid, iwork, jwork, lwork, &
779 & old_lwork, icav, info
780 integer,
allocatable :: work(:, :), tmp_work(:, :)
781 real(dp) :: start_time
784 start_time = omp_get_wtime()
785 if (params % fmm .eq. 1)
then
787 allocate(constants % order(params % nsph), stat=info)
788 if (info .ne. 0)
then
789 call update_error(ddx_error,
"constants_geometry_init: `order` " &
790 & //
"allocation failed")
793 constants % nclusters = 2*params % nsph - 1
794 allocate(constants % cluster(2, constants % nclusters), stat=info)
795 if (info .ne. 0)
then
796 call update_error(ddx_error,
"constants_geometry_init: `cluster` " &
797 & //
"allocation failed")
800 allocate(constants % children(2, constants % nclusters), stat=info)
801 if (info .ne. 0)
then
802 call update_error(ddx_error,
"constants_geometry_init: " // &
803 &
"`children` allocation failed")
806 allocate(constants % parent(constants % nclusters), stat=info)
807 if (info .ne. 0)
then
808 call update_error(ddx_error,
"constants_geometry_init: `parent` " &
809 & //
"allocation failed")
812 allocate(constants % cnode(3, constants % nclusters), stat=info)
813 if (info .ne. 0)
then
814 call update_error(ddx_error,
"constants_geometry_init: `cnode` " &
815 & //
"allocation failed")
818 allocate(constants % rnode(constants % nclusters), stat=info)
819 if (info .ne. 0)
then
820 call update_error(ddx_error,
"constants_geometry_init: `rnode` " &
821 & //
"allocation failed")
824 allocate(constants % snode(params % nsph), stat=info)
825 if (info .ne. 0)
then
826 call update_error(ddx_error,
"constants_geometry_init: `snode` " &
827 & //
"allocation failed")
830 allocate(constants % nfar(constants % nclusters), stat=info)
831 if (info .ne. 0)
then
832 call update_error(ddx_error,
"constants_geometry_init: `nfar` " &
833 & //
"allocation failed")
836 allocate(constants % nnear(constants % nclusters), stat=info)
837 if (info .ne. 0)
then
838 call update_error(ddx_error,
"constants_geometry_init: `nnear` " &
839 & //
"allocation failed")
843 call tree_rib_build(params % nsph, params % csph, params % rsph, &
844 & constants % order, constants % cluster, constants % children, &
845 & constants % parent, constants % cnode, constants % rnode, &
846 & constants % snode, ddx_error)
847 if (ddx_error % flag .ne. 0)
then
848 call update_error(ddx_error,
"tree_rib_build returned an " // &
849 &
"ddx_error, exiting")
856 allocate(work(3, lwork), stat=info)
857 if (info .ne. 0)
then
858 call update_error(ddx_error,
"constants_geometry_init: `work` " &
859 & //
"allocation failed")
862 do while (iwork .le. jwork)
863 allocate(tmp_work(3, lwork), stat=info)
864 if (info .ne. 0)
then
865 call update_error(ddx_error,
"constants_geometry_init: " // &
866 &
"`tmp_work` allocation failed")
870 deallocate(work, stat=info)
871 if (info .ne. 0)
then
872 call update_error(ddx_error,
"constants_geometry_init: " // &
873 &
"`work` deallocation failed")
877 lwork = old_lwork + 1000*params % nsph
878 allocate(work(3, lwork), stat=info)
879 if (info .ne. 0)
then
880 call update_error(ddx_error,
"constants_geometry_init: " // &
881 &
"`work` allocation failed")
884 work(:, 1:old_lwork) = tmp_work
885 deallocate(tmp_work, stat=info)
886 if (info .ne. 0)
then
887 call update_error(ddx_error,
"constants_geometry_init: " // &
888 &
"`tmp_work` deallocation failed")
892 & constants % children, constants % cnode, &
893 & constants % rnode, lwork, iwork, jwork, work, &
894 & constants % nnfar, constants % nfar, constants % nnnear, &
897 allocate(constants % sfar(constants % nclusters+1), &
898 & constants % snear(constants % nclusters+1), stat=info)
899 if (info .ne. 0)
then
900 call update_error(ddx_error,
"constants_geometry_init: `sfar` " // &
901 &
"and `snear` allocations failed")
904 allocate(constants % far(constants % nnfar), stat=info)
905 if (info .ne. 0)
then
906 call update_error(ddx_error,
"constants_geometry_init: `far` " // &
907 &
"allocation failed")
910 allocate(constants % near(constants % nnnear), stat=info)
911 if (info .ne. 0)
then
912 call update_error(ddx_error,
"constants_geometry_init: `near` " // &
913 &
"allocation failed")
917 & constants % nnfar, constants % nfar, constants % sfar, &
918 & constants % far, constants % nnnear, constants % nnear, &
919 & constants % snear, constants % near)
920 deallocate(work, stat=info)
921 if (info .ne. 0)
then
922 call update_error(ddx_error,
"constants_geometry_init: `work` " // &
923 &
"deallocation failed")
928 swthr = one + (params % se+one)*params % eta/two
930 if (params % fmm .eq. 1)
then
935 if (ddx_error % flag .ne. 0)
then
936 call update_error(ddx_error,
"Neighbor list construction failed")
940 allocate(constants % fi(params % ngrid, params % nsph), &
941 & constants % ui(params % ngrid, params % nsph), stat=info)
942 if (info .ne. 0)
then
943 call update_error(ddx_error,
"`fi` and `ui` allocations failed")
946 constants % fi = zero
947 constants % ui = zero
949 if (params % force .eq. 1)
then
950 allocate(constants % zi(3, params % ngrid, params % nsph), stat=info)
951 if (info .ne. 0)
then
952 call update_error(ddx_error,
"`zi` allocation failed")
955 constants % zi = zero
957 allocate(constants % zi_dr(params % ngrid, params % nsph), stat=info)
958 if (info .ne. 0)
then
959 call update_error(ddx_error,
"`zi_dr` allocation failed")
962 constants % zi_dr = zero
967 do isph = 1, params % nsph
968 do igrid = 1, params % ngrid
970 do inear = constants % inl(isph), constants % inl(isph+1)-1
972 jsph = constants % nl(inear)
974 v = params % csph(:, isph) - params % csph(:, jsph) + &
975 & params % rsph(isph)*constants % cgrid(:, igrid)
976 maxv = max(abs(v(1)), abs(v(2)), abs(v(3)))
977 if (maxv .gt. zero)
then
978 ssqv = (v(1)/maxv)**2 + (v(2)/maxv)**2 + (v(3)/maxv)**2
982 vv = maxv * sqrt(ssqv)
983 t = vv / params % rsph(jsph)
985 constants % fi(igrid, isph) = constants % fi(igrid, isph) + &
986 &
fsw(t, params % se, params % eta)
988 if (params % force .eq. 1)
then
990 if ((t .lt. swthr) .and. (t .gt. swthr-params % eta))
then
992 vv =
dfsw(t, params % se, params % eta) / &
993 & params % rsph(jsph) / vv
994 constants % zi(:, igrid, isph) = &
995 & constants % zi(:, igrid, isph) + vv*v
996 constants % zi_dr(igrid, isph) = &
997 & constants % zi_dr(igrid, isph) &
998 & + vv*dot_product(v, constants % cgrid(:, igrid))
1003 if (constants % fi(igrid, isph) .le. one)
then
1004 constants % ui(igrid, isph) = one - constants % fi(igrid, isph)
1009 allocate(constants % ncav_sph(params % nsph), stat=info)
1010 if (info .ne. 0)
then
1011 call update_error(ddx_error,
"`ncav_sph` allocation failed")
1016 do isph = 1, params % nsph
1017 constants % ncav_sph(isph) = 0
1019 do i = 1, params % ngrid
1021 if (constants % ui(i, isph) .gt. zero)
then
1022 constants % ncav_sph(isph) = constants % ncav_sph(isph) + 1
1026 constants % ncav = sum(constants % ncav_sph)
1028 allocate(constants % ccav(3, constants % ncav), &
1029 & constants % icav_ia(params % nsph+1), &
1030 & constants % icav_ja(constants % ncav), stat=info)
1031 if (info .ne. 0)
then
1032 call update_error(ddx_error,
"`ccav`, `icav_ia` and " // &
1033 &
"`icav_ja` allocations failed")
1037 allocate(constants % ui_cav(constants % ncav), stat=info)
1038 if (info .ne. 0)
then
1039 call update_error(ddx_error,
"`ui_cav` allocations failed")
1044 constants % icav_ia(1) = 1
1046 do isph = 1, params % nsph
1047 constants % icav_ia(isph+1) = constants % icav_ia(isph) + &
1048 & constants % ncav_sph(isph)
1050 do igrid = 1, params % ngrid
1052 if (constants % ui(igrid, isph) .eq. zero) cycle
1054 constants % ccav(:, icav) = params % csph(:, isph) + &
1055 & params % rsph(isph)* &
1056 & constants % cgrid(:, igrid)
1058 constants % icav_ja(icav) = igrid
1060 constants % ui_cav(icav) = constants % ui(igrid, isph)
1066 if (params % model .eq. 2)
then
1067 allocate(constants % rx_prc( &
1068 & constants % nbasis, constants % nbasis, params % nsph), &
1070 if (info .ne. 0)
then
1071 call update_error(ddx_error,
"constants_geometry_init: `rx_prc` " &
1072 & //
"allocation failed")
1075 call mkprec(params % lmax, constants % nbasis, params % nsph, &
1076 & params % ngrid, params % eps, constants % ui, &
1077 & constants % wgrid, constants % vgrid, constants % vgrid_nbasis, &
1078 & constants % rx_prc, ddx_error)
1079 if (info .ne. 0)
then
1080 call update_error(ddx_error,
"mkprec returned an ddx_error, exiting")
1090 type(ddx_error_type),
intent(inout) :: ddx_error
1091 real(dp) :: swthr, v(3), maxv, ssqv, vv, r
1092 integer :: nngmax, i, lnl, isph, jsph, info
1093 integer,
allocatable :: tmp_nl(:)
1095 swthr = (params % se+one)*params % eta/two
1098 allocate(constants % inl(params % nsph+1), &
1099 & constants % nl(params % nsph*nngmax), stat=info)
1100 if (info .ne. 0)
then
1101 call update_error(ddx_error,
"`inl` and `nl` allocations failed")
1106 do isph = 1, params % nsph
1107 constants % inl(isph) = lnl + 1
1108 do jsph = 1, params % nsph
1109 if (isph .ne. jsph)
then
1110 v = params % csph(:, isph)-params % csph(:, jsph)
1111 maxv = max(abs(v(1)), abs(v(2)), abs(v(3)))
1112 if (maxv .gt. zero)
then
1113 ssqv = (v(1)/maxv)**2 + (v(2)/maxv)**2 + (v(3)/maxv)**2
1117 vv = maxv * sqrt(ssqv)
1123 r = params % rsph(isph) + params % rsph(jsph) &
1124 & + swthr * max(params % rsph(isph), params % rsph(jsph))
1126 constants % nl(i) = jsph
1130 if (i .gt. params % nsph*nngmax)
then
1131 allocate(tmp_nl(params % nsph*nngmax), stat=info)
1132 if (info .ne. 0)
then
1133 call update_error(ddx_error,
"`tmp_nl` " // &
1134 &
"allocation failed")
1137 tmp_nl(1:params % nsph*nngmax) = &
1138 & constants % nl(1:params % nsph*nngmax)
1139 deallocate(constants % nl, stat=info)
1140 if (info .ne. 0)
then
1141 call update_error(ddx_error,
"`nl` " // &
1142 &
"deallocation failed")
1145 nngmax = nngmax + 10
1146 allocate(constants % nl(params % nsph*nngmax), &
1148 if (info .ne. 0)
then
1149 call update_error(ddx_error,
"`nl` " // &
1150 &
"allocation failed")
1153 constants % nl(1:params % nsph*(nngmax-10)) = &
1154 & tmp_nl(1:params % nsph*(nngmax-10))
1155 deallocate(tmp_nl, stat=info)
1156 if (info .ne. 0)
then
1157 call update_error(ddx_error,
"`tmp_nl` " // &
1158 &
"deallocation failed")
1166 constants % inl(params % nsph+1) = lnl+1
1167 constants % nngmax = nngmax
1175 type(ddx_error_type),
intent(inout) :: ddx_error
1176 real(dp) :: swthr, v(3), maxv, ssqv, vv, r
1177 integer :: nngmax, i, lnl, isph, jsph, inode, jnode, j, k, info
1178 integer,
allocatable :: tmp_nl(:)
1180 swthr = (params % se+one)*params % eta/two
1183 allocate(constants % inl(params % nsph+1), &
1184 & constants % nl(params % nsph*nngmax), stat=info)
1185 if (info .ne. 0)
then
1186 call update_error(ddx_error,
"`inl` and `nl` allocations failed")
1192 do isph = 1, params % nsph
1193 constants % inl(isph) = lnl + 1
1194 inode = constants % snode(isph)
1196 do j = constants % snear(inode), constants % snear(inode+1) - 1
1197 jnode = constants % near(j)
1198 do k = constants % cluster(1, jnode), constants % cluster(2, jnode)
1199 jsph = constants % order(k)
1200 if (isph .ne. jsph)
then
1201 v = params % csph(:, isph)-params % csph(:, jsph)
1202 maxv = max(abs(v(1)), abs(v(2)), abs(v(3)))
1203 if (maxv .gt. zero)
then
1204 ssqv = (v(1)/maxv)**2 + (v(2)/maxv)**2 + (v(3)/maxv)**2
1208 vv = maxv * sqrt(ssqv)
1214 r = params % rsph(isph) + params % rsph(jsph) &
1215 & + swthr * max(params % rsph(isph), params % rsph(jsph))
1217 constants % nl(i) = jsph
1221 if (i .gt. params % nsph*nngmax)
then
1222 allocate(tmp_nl(params % nsph*nngmax), stat=info)
1223 if (info .ne. 0)
then
1224 call update_error(ddx_error,
"`tmp_nl` " // &
1225 &
"allocation failed")
1228 tmp_nl(1:params % nsph*nngmax) = &
1229 & constants % nl(1:params % nsph*nngmax)
1230 deallocate(constants % nl, stat=info)
1231 if (info .ne. 0)
then
1232 call update_error(ddx_error,
"`nl` " // &
1233 &
"deallocation failed")
1236 nngmax = nngmax + 10
1237 allocate(constants % nl(params % nsph*nngmax), &
1239 if (info .ne. 0)
then
1240 call update_error(ddx_error,
"`nl` " // &
1241 &
"allocation failed")
1244 constants % nl(1:params % nsph*(nngmax-10)) = &
1245 & tmp_nl(1:params % nsph*(nngmax-10))
1246 deallocate(tmp_nl, stat=info)
1247 if (info .ne. 0)
then
1248 call update_error(ddx_error,
"`tmp_nl` " // &
1249 &
"deallocation failed")
1258 constants % inl(params % nsph+1) = lnl+1
1259 constants % nngmax = nngmax
1289real(dp) function fsw(t, se, eta)
1291 real(dp),
intent(in) :: t, se, eta
1293 real(dp) :: a, b, c, x
1298 x = t - (se*pt5 + pt5)*eta
1303 if (a .le. zero)
then
1306 else if (a .ge. eta)
then
1346 real(dp),
intent(in) :: t, se, eta
1349 real(dp),
parameter :: f30=30.0d0
1354 x = t - (se + 1.d0)*eta / 2.d0
1358 if (x .ge. one)
then
1360 else if (x .le. flow)
then
1363 dfsw = -f30 * (( (one-x)*(x-one+eta) )**2) / (eta**5)
1370subroutine mkprec(lmax, nbasis, nsph, ngrid, eps, ui, wgrid, vgrid, &
1371 & vgrid_nbasis, rx_prc, ddx_error)
1373 integer,
intent(in) :: lmax, nbasis, nsph, ngrid, vgrid_nbasis
1374 real(dp),
intent(in) :: eps, ui(ngrid, nsph), wgrid(ngrid), &
1375 & vgrid(vgrid_nbasis, ngrid)
1377 real(dp),
intent(out) :: rx_prc(nbasis, nbasis, nsph)
1378 type(ddx_error_type),
intent(inout) :: ddx_error
1380 integer :: info, isph, lm, l1, m1, ind1, igrid
1382 integer,
allocatable :: ipiv(:)
1383 real(dp),
allocatable :: work(:)
1384 external :: dgetrf, dgetri
1386 allocate(ipiv(nbasis), work(nbasis**2), stat=info)
1387 if (info .ne. 0)
then
1388 call update_error(ddx_error,
"mkprec: `ipiv` and `work` allocation failed")
1396 f = twopi * ui(igrid, isph) * wgrid(igrid)
1398 ind1 = l1*l1 + l1 + 1
1400 f1 = f * vgrid(ind1+m1, igrid) / (two*dble(l1) + one)
1402 rx_prc(lm, ind1+m1, isph) = &
1403 & rx_prc(lm, ind1+m1, isph) + f1*vgrid(lm, igrid)
1410 f = twopi * (eps+one) / (eps-one)
1413 rx_prc(lm, lm, isph) = rx_prc(lm, lm, isph) + f
1418 call dgetrf(nbasis, nbasis, rx_prc(:, :, isph), nbasis, ipiv, info)
1419 if (info .ne. 0)
then
1420 call update_error(ddx_error,
"mkprec: dgetrf failed")
1423 call dgetri(nbasis, rx_prc(:, :, isph), nbasis, ipiv, work, &
1425 if (info .ne. 0)
then
1426 call update_error(ddx_error,
"mkprec: dgetri failed")
1431 deallocate(work, ipiv, stat=info)
1432 if (info .ne. 0)
then
1433 call update_error(ddx_error,
"mkprec: `ipiv` and `work` " // &
1434 &
"deallocation failed")
1462 & cnode, rnode, snode, ddx_error)
1464 integer,
intent(in) :: nsph
1465 real(dp),
intent(in) :: csph(3, nsph), rsph(nsph)
1467 integer,
intent(out) :: order(nsph), cluster(2, 2*nsph-1), &
1468 & children(2, 2*nsph-1), parent(2*nsph-1), snode(nsph)
1469 real(dp),
intent(out) :: cnode(3, 2*nsph-1), rnode(2*nsph-1)
1470 type(ddx_error_type),
intent(inout) :: ddx_error
1472 integer :: nclusters, i, j, n, s, e, div
1473 real(dp) :: r, r1, r2, c(3), c1(3), c2(3), d, maxc
1475 nclusters = 2*nsph - 1
1478 cluster(2, 1) = nsph
1499 if (ddx_error % flag .ne. 0)
then
1500 call update_error(ddx_error,
"tree_rib_node_bisect returned " // &
1501 &
"an ddx_error, exiting")
1506 cluster(2, j) = s + div - 1
1508 cluster(1, j+1) = s + div
1512 children(2, i) = j + 1
1528 do i = nclusters, 1, -1
1531 if (children(1, i) .eq. 0)
then
1533 j = order(cluster(1, i))
1535 cnode(:, i) = csph(:, j)
1551 maxc = max(abs(c(1)), abs(c(2)), abs(c(3)))
1552 if (maxc .eq. zero)
then
1555 d = (c(1)/maxc)**2 + (c(2)/maxc)**2 + (c(3)/maxc)**2
1559 if (r1 .ge. (r2+d))
then
1563 else if(r2 .ge. (r1+d))
then
1590 integer,
intent(in) :: nsph, n
1591 real(dp),
intent(in) :: csph(3, nsph)
1593 integer,
intent(inout) :: order(n)
1594 integer,
intent(out) :: div
1595 type(ddx_error_type),
intent(inout) :: ddx_error
1597 real(dp) :: c(3), s(3)
1598 real(dp),
allocatable :: tmp_csph(:, :), work(:)
1600 integer :: i, l, r, lwork, info, istat
1601 integer,
allocatable :: tmp_order(:)
1603 allocate(tmp_csph(3, n), tmp_order(n), stat=istat)
1604 if (istat.ne.0)
then
1605 call update_error(ddx_error,
'Allocation failed in tree_node_bisect')
1612 c = c + csph(:, order(i))
1617 tmp_csph(:, i) = csph(:, order(i)) - c
1622 call dgesvd(
'N',
'O', 3, n, tmp_csph, 3, s, tmp_csph, 3, tmp_csph, 3, &
1625 allocate(work(lwork), stat=istat)
1626 if (istat.ne.0)
then
1627 call update_error(ddx_error,
'Allocation failed in tree_node_bisect')
1631 call dgesvd(
'N',
'O', 3, n, tmp_csph, 3, s, tmp_csph, 3, tmp_csph, 3, &
1632 & work, lwork, info)
1634 call update_error(ddx_error,
'DGESVD failed in tree_node_bisect')
1637 deallocate(work, stat=istat)
1638 if (istat.ne.0)
then
1639 call update_error(ddx_error,
'Deallocation failed in tree_node_bisect')
1653 if (tmp_csph(1, i) .ge. zero)
then
1654 tmp_order(l) = order(i)
1658 tmp_order(r) = order(i)
1665 deallocate(tmp_csph, tmp_order, stat=istat)
1666 if (istat.ne.0)
then
1667 call update_error(ddx_error,
'Deallocation failed in tree_node_bisect')
1697 & jwork, work, nnfar, nfar, nnnear, nnear)
1699 integer,
intent(in) :: n, children(2, n), lwork
1700 real(dp),
intent(in) :: cnode(3, n), rnode(n)
1702 integer,
intent(inout) :: iwork, jwork, work(3, lwork)
1703 integer,
intent(out) :: nnfar, nfar(n), nnnear, nnear(n)
1705 integer :: j(2), npairs, k1, k2
1706 real(dp) :: c(3), r, d, dmax, dssq
1708 if (iwork .eq. 0)
then
1715 do while (iwork .le. jwork)
1716 j = work(1:2, iwork)
1717 c = cnode(:, j(1)) - cnode(:, j(2))
1718 r = rnode(j(1)) + rnode(j(2)) + max(rnode(j(1)), rnode(j(2)))
1720 dmax = max(abs(c(1)), abs(c(2)), abs(c(3)))
1721 if (dmax .gt. zero)
then
1722 dssq = (c(1)/dmax)**2 + (c(2)/dmax)**2 + (c(3)/dmax)**2
1726 d = dmax * sqrt(dssq)
1731 npairs = max(1, children(2, j(1))-children(1, j(1))+1) * &
1732 & max(1, children(2, j(2))-children(1, j(2))+1)
1736 else if (npairs .eq. 1)
then
1739 else if (jwork+npairs .gt. lwork)
then
1747 if (children(1, j(1)) .eq. 0)
then
1749 do k2 = children(1, j(2)), children(2, j(2))
1754 else if(children(1, j(2)) .eq. 0)
then
1756 do k1 = children(1, j(1)), children(2, j(1))
1762 do k1 = children(1, j(1)), children(2, j(1))
1763 do k2 = children(1, j(2)), children(2, j(2))
1776 if (work(3, iwork) .eq. 1)
then
1777 nfar(work(1, iwork)) = nfar(work(1, iwork)) + 1
1778 else if (work(3, iwork) .eq. 2)
then
1779 nnear(work(1, iwork)) = nnear(work(1, iwork)) + 1
1790 & nnnear, nnear, snear, near)
1804 integer,
intent(in) :: jwork, lwork, work(3, lwork), n, nnfar, nnnear
1805 integer,
intent(in) :: nfar(n), nnear(n)
1806 integer,
intent(out) :: sfar(n+1), far(nnfar), snear(n+1), near(nnnear)
1808 integer,
allocatable :: cfar(:), cnear(:)
1810 allocate(cfar(n+1), cnear(n+1))
1814 sfar(i) = sfar(i-1) + nfar(i-1)
1815 snear(i) = snear(i-1) + nnear(i-1)
1820 if (work(3, i) .eq. 1)
then
1823 if ((j .gt. n) .or. (j .le. 0))
then
1824 write(*,*)
"ALARM", j
1826 far(cfar(j)) = work(2, i)
1827 cfar(j) = cfar(j) + 1
1828 else if (work(3, i) .eq. 2)
then
1831 if ((j .gt. n) .or. (j .le. 0))
then
1832 write(*,*)
"ALARM", j
1834 near(cnear(j)) = work(2, i)
1835 cnear(j) = cnear(j) + 1
1839 deallocate(cfar, cnear)
1851 type(ddx_error_type),
intent(inout) :: ddx_error
1856 if (
allocated(constants % vscales))
then
1857 deallocate(constants % vscales, stat=istat)
1858 if (istat .ne. 0)
then
1859 call update_error(ddx_error,
"`vscales` deallocation failed!")
1862 if (
allocated(constants % v4pi2lp1))
then
1863 deallocate(constants % v4pi2lp1, stat=istat)
1864 if (istat .ne. 0)
then
1865 call update_error(ddx_error,
"`v4pi2lp1` deallocation failed!")
1868 if (
allocated(constants % vscales_rel))
then
1869 deallocate(constants % vscales_rel, stat=istat)
1870 if (istat .ne. 0)
then
1871 call update_error(ddx_error,
"`vscales_rel` deallocation failed!")
1874 if (
allocated(constants % vfact))
then
1875 deallocate(constants % vfact, stat=istat)
1876 if (istat .ne. 0)
then
1877 call update_error(ddx_error,
"`vfact` deallocation failed!")
1880 if (
allocated(constants % vcnk))
then
1881 deallocate(constants % vcnk, stat=istat)
1882 if (istat .ne. 0)
then
1883 call update_error(ddx_error,
"`vcnk` deallocation failed!")
1886 if (
allocated(constants % m2l_ztranslate_coef))
then
1887 deallocate(constants % m2l_ztranslate_coef, stat=istat)
1888 if (istat .ne. 0)
then
1889 call update_error(ddx_error, &
1890 &
"`m2l_ztranslate_coef` deallocation failed!")
1893 if (
allocated(constants % m2l_ztranslate_adj_coef))
then
1894 deallocate(constants % m2l_ztranslate_adj_coef, stat=istat)
1895 if (istat .ne. 0)
then
1896 call update_error(ddx_error, &
1897 &
"`m2l_ztranslate_adj_coef` deallocation failed!")
1900 if (
allocated(constants % cgrid))
then
1901 deallocate(constants % cgrid, stat=istat)
1902 if (istat .ne. 0)
then
1903 call update_error(ddx_error,
"`cgrid` deallocation failed!")
1906 if (
allocated(constants % wgrid))
then
1907 deallocate(constants % wgrid, stat=istat)
1908 if (istat .ne. 0)
then
1909 call update_error(ddx_error,
"`wgrid` deallocation failed!")
1912 if (
allocated(constants % vgrid))
then
1913 deallocate(constants % vgrid, stat=istat)
1914 if (istat .ne. 0)
then
1915 call update_error(ddx_error,
"`vgrid` deallocation failed!")
1918 if (
allocated(constants % vwgrid))
then
1919 deallocate(constants % vwgrid, stat=istat)
1920 if (istat .ne. 0)
then
1921 call update_error(ddx_error,
"`vwgrid` deallocation failed!")
1924 if (
allocated(constants % vgrid2))
then
1925 deallocate(constants % vgrid2, stat=istat)
1926 if (istat .ne. 0)
then
1927 call update_error(ddx_error,
"`vgrid2` deallocation failed!")
1930 if (
allocated(constants % pchi))
then
1931 deallocate(constants % pchi, stat=istat)
1932 if (istat .ne. 0)
then
1933 call update_error(ddx_error,
"`pchi` deallocation failed!")
1936 if (
allocated(constants % c_ik))
then
1937 deallocate(constants % c_ik, stat=istat)
1938 if (istat .ne. 0)
then
1939 call update_error(ddx_error,
"`c_ik` deallocation failed!")
1942 if (
allocated(constants % si_ri))
then
1943 deallocate(constants % si_ri, stat=istat)
1944 if (istat .ne. 0)
then
1945 call update_error(ddx_error,
"`si_ri` deallocation failed!")
1948 if (
allocated(constants % di_ri))
then
1949 deallocate(constants % di_ri, stat=istat)
1950 if (istat .ne. 0)
then
1951 call update_error(ddx_error,
"`di_ri` deallocation failed!")
1954 if (
allocated(constants % sk_ri))
then
1955 deallocate(constants % sk_ri, stat=istat)
1956 if (istat .ne. 0)
then
1957 call update_error(ddx_error,
"`sk_ri` deallocation failed!")
1960 if (
allocated(constants % dk_ri))
then
1961 deallocate(constants % dk_ri, stat=istat)
1962 if (istat .ne. 0)
then
1963 call update_error(ddx_error,
"`dk_ri` deallocation failed!")
1966 if (
allocated(constants % termimat))
then
1967 deallocate(constants % termimat, stat=istat)
1968 if (istat .ne. 0)
then
1969 call update_error(ddx_error,
"`termimat` deallocation failed!")
1972 if (
allocated(constants % b))
then
1973 deallocate(constants % b, stat=istat)
1974 if (istat .ne. 0)
then
1975 call update_error(ddx_error,
"`b` deallocation failed!")
1978 if (
allocated(constants % l))
then
1979 deallocate(constants % l, stat=istat)
1980 if (istat .ne. 0)
then
1981 call update_error(ddx_error,
"`l` deallocation failed!")
1984 if (
allocated(constants % inl))
then
1985 deallocate(constants % inl, stat=istat)
1986 if (istat .ne. 0)
then
1987 call update_error(ddx_error,
"`inl` deallocation failed!")
1990 if (
allocated(constants % nl))
then
1991 deallocate(constants % nl, stat=istat)
1992 if (istat .ne. 0)
then
1993 call update_error(ddx_error,
"`nl` deallocation failed!")
1996 if (
allocated(constants % itrnl))
then
1997 deallocate(constants % itrnl, stat=istat)
1998 if (istat .ne. 0)
then
1999 call update_error(ddx_error,
"`itrnl` deallocation failed!")
2002 if (
allocated(constants % fi))
then
2003 deallocate(constants % fi, stat=istat)
2004 if (istat .ne. 0)
then
2005 call update_error(ddx_error,
"`fi` deallocation failed!")
2008 if (
allocated(constants % ui))
then
2009 deallocate(constants % ui, stat=istat)
2010 if (istat .ne. 0)
then
2011 call update_error(ddx_error,
"`ui` deallocation failed!")
2014 if (
allocated(constants % ui_cav))
then
2015 deallocate(constants % ui_cav, stat=istat)
2016 if (istat .ne. 0)
then
2017 call update_error(ddx_error,
"`ui_cav` deallocation failed!")
2020 if (
allocated(constants % zi))
then
2021 deallocate(constants % zi, stat=istat)
2022 if (istat .ne. 0)
then
2023 call update_error(ddx_error,
"`zi` deallocation failed!")
2026 if (
allocated(constants % zi_dr))
then
2027 deallocate(constants % zi_dr, stat=istat)
2028 if (istat .ne. 0)
then
2029 call update_error(ddx_error,
"`zi_dr` deallocation failed!")
2032 if (
allocated(constants % ncav_sph))
then
2033 deallocate(constants % ncav_sph, stat=istat)
2034 if (istat .ne. 0)
then
2035 call update_error(ddx_error,
"`ncav_sph` deallocation failed!")
2038 if (
allocated(constants % ccav))
then
2039 deallocate(constants % ccav, stat=istat)
2040 if (istat .ne. 0)
then
2041 call update_error(ddx_error,
"`ccav` deallocation failed!")
2044 if (
allocated(constants % icav_ia))
then
2045 deallocate(constants % icav_ia, stat=istat)
2046 if (istat .ne. 0)
then
2047 call update_error(ddx_error,
"`icav_ia` deallocation failed!")
2050 if (
allocated(constants % icav_ja))
then
2051 deallocate(constants % icav_ja, stat=istat)
2052 if (istat .ne. 0)
then
2053 call update_error(ddx_error,
"`icav_ja` deallocation failed!")
2056 if (
allocated(constants % rx_prc))
then
2057 deallocate(constants % rx_prc, stat=istat)
2058 if (istat .ne. 0)
then
2059 call update_error(ddx_error,
"`rx_prc` deallocation failed!")
2062 if (
allocated(constants % order))
then
2063 deallocate(constants % order, stat=istat)
2064 if (istat .ne. 0)
then
2065 call update_error(ddx_error,
"`order` deallocation failed!")
2068 if (
allocated(constants % cluster))
then
2069 deallocate(constants % cluster, stat=istat)
2070 if (istat .ne. 0)
then
2071 call update_error(ddx_error,
"`cluster` deallocation failed!")
2074 if (
allocated(constants % children))
then
2075 deallocate(constants % children, stat=istat)
2076 if (istat .ne. 0)
then
2077 call update_error(ddx_error,
"`children` deallocation failed!")
2080 if (
allocated(constants % parent))
then
2081 deallocate(constants % parent, stat=istat)
2082 if (istat .ne. 0)
then
2083 call update_error(ddx_error,
"`parent` deallocation failed!")
2086 if (
allocated(constants % cnode))
then
2087 deallocate(constants % cnode, stat=istat)
2088 if (istat .ne. 0)
then
2089 call update_error(ddx_error,
"`cnode` deallocation failed!")
2092 if (
allocated(constants % rnode))
then
2093 deallocate(constants % rnode, stat=istat)
2094 if (istat .ne. 0)
then
2095 call update_error(ddx_error,
"`rnode` deallocation failed!")
2098 if (
allocated(constants % snode))
then
2099 deallocate(constants % snode, stat=istat)
2100 if (istat .ne. 0)
then
2101 call update_error(ddx_error,
"`snode` deallocation failed!")
2104 if (
allocated(constants % sk_rnode))
then
2105 deallocate(constants % sk_rnode, stat=istat)
2106 if (istat .ne. 0)
then
2107 call update_error(ddx_error,
"`sk_rnode` deallocation failed!")
2110 if (
allocated(constants % si_rnode))
then
2111 deallocate(constants % si_rnode, stat=istat)
2112 if (istat .ne. 0)
then
2113 call update_error(ddx_error,
"`si_rnode` deallocation failed!")
2116 if (
allocated(constants % nfar))
then
2117 deallocate(constants % nfar, stat=istat)
2118 if (istat .ne. 0)
then
2119 call update_error(ddx_error,
"`nfar` deallocation failed!")
2122 if (
allocated(constants % nnear))
then
2123 deallocate(constants % nnear, stat=istat)
2124 if (istat .ne. 0)
then
2125 call update_error(ddx_error,
"`nnear` deallocation failed!")
2128 if (
allocated(constants % far))
then
2129 deallocate(constants % far, stat=istat)
2130 if (istat .ne. 0)
then
2131 call update_error(ddx_error,
"`far` deallocation failed!")
2134 if (
allocated(constants % near))
then
2135 deallocate(constants % near, stat=istat)
2136 if (istat .ne. 0)
then
2137 call update_error(ddx_error,
"`near` deallocation failed!")
2140 if (
allocated(constants % sfar))
then
2141 deallocate(constants % sfar, stat=istat)
2142 if (istat .ne. 0)
then
2143 call update_error(ddx_error,
"`sfar` deallocation failed!")
2146 if (
allocated(constants % snear))
then
2147 deallocate(constants % snear, stat=istat)
2148 if (istat .ne. 0)
then
2149 call update_error(ddx_error,
"`snear` deallocation failed!")
2152 if (
allocated(constants % m2l_ztranslate_coef))
then
2153 deallocate(constants % m2l_ztranslate_coef, stat=istat)
2154 if (istat .ne. 0)
then
2155 call update_error(ddx_error,
"`m2l_ztranslate_coef` " // &
2156 &
"deallocation failed!")
2159 if (
allocated(constants % m2l_ztranslate_adj_coef))
then
2160 deallocate(constants % m2l_ztranslate_adj_coef, stat=istat)
2161 if (istat .ne. 0)
then
2162 call update_error(ddx_error,
"`m2l_ztranslate_adj_coef` " // &
2163 &
"deallocation failed!")
subroutine build_itrnl(constants, params, ddx_error)
Build the transposed neighbor list.
subroutine build_b(constants, params, ddx_error)
Allocate and build the HSP sparse matrix, only if incore is set.
subroutine tree_get_farnear_work(n, children, cnode, rnode, lwork, iwork, jwork, work, nnfar, nfar, nnnear, nnear)
Find near and far admissible pairs of tree nodes and store it in work array.
subroutine neighbor_list_init(params, constants, ddx_error)
Build the neighbor list using a N^2 code.
subroutine mkprec(lmax, nbasis, nsph, ngrid, eps, ui, wgrid, vgrid, vgrid_nbasis, rx_prc, ddx_error)
Compute preconditioner assemble the diagonal blocks of the reps matrix then invert them to build the ...
subroutine build_l(constants, params, ddx_error)
Allocate and build the ddCOSMO sparse matrix, only if incore is set.
real(dp) function dfsw(t, se, eta)
Derivative of a switching function.
subroutine constants_init(params, constants, ddx_error)
Compute all necessary constants.
subroutine neighbor_list_init_fmm(params, constants, ddx_error)
Build the neighbor list using a linear scaling code (only if FMMs are enabled)
subroutine constants_geometry_init(params, constants, ddx_error)
Initialize geometry-related constants like list of neighbouring spheres.
subroutine constants_free(constants, ddx_error)
Deallocate the constants.
subroutine tree_rib_build(nsph, csph, rsph, order, cluster, children, parent, cnode, rnode, snode, ddx_error)
Build a recursive inertial binary tree.
real(dp) function fsw(t, se, eta)
Switching function.
subroutine tree_rib_node_bisect(nsph, csph, n, order, div, ddx_error)
Divide given cluster of spheres into two subclusters by inertial bisection.
subroutine mkpmat(params, constants, isph, pmat)
Computation of P_chi.
subroutine tree_get_farnear(jwork, lwork, work, n, nnfar, nfar, sfar, far, nnnear, nnear, snear, near)
Get near and far admissible pairs from work array of tree_get_farnear_work Works only for binary tree...
Harmonics-related core routines.
subroutine ylmscale(p, vscales, v4pi2lp1, vscales_rel)
Compute scaling factors of real normalized spherical harmonics.
subroutine ylmbas(x, rho, ctheta, stheta, cphi, sphi, p, vscales, vylm, vplm, vcos, vsin)
Compute all spherical harmonics up to a given degree at a given point.
subroutine fmm_constants(dmax, pm, pl, vcnk, m2l_ztranslate_coef, m2l_ztranslate_adj_coef)
Compute FMM-related constants.
Module to treat properly user input parameters.
Container for precomputed constants.
Type to check and store user input parameters.