47 use,
intrinsic :: iso_fortran_env
84 integer,
allocatable :: nt(:)
85 integer,
allocatable :: ct(:, :)
86 real(real64),
allocatable :: wt(:, :)
87 real(real64),
allocatable :: kd(:, :)
98 logical :: valid = .false.
100 integer :: divisor = 0
103 integer :: kmin(3) = 0
104 integer :: kmax(3) = 0
105 real(real64) :: rel_ref(3) =
m_zero
106 real(real64),
allocatable :: xstep(:, :)
107 integer,
allocatable :: offs(:, :)
108 real(real64),
allocatable :: xoff(:, :)
109 integer,
allocatable :: isub(:, :, :)
110 integer,
allocatable :: tgt(:, :)
111 real(real64),
allocatable :: wgt(:, :)
112 integer,
allocatable :: ntgt(:)
113 type(dg_axis_kernel_t) :: ax(3)
118 logical :: enabled = .false.
120 integer :: divisor = 0
122 integer :: interp_min = 0
123 integer :: interp_max = 0
128 real(real64),
allocatable :: co(:, :)
135 type(double_grid_t),
intent(out) :: this
136 type(namespace_t),
intent(in) :: namespace
137 integer,
intent(in) :: dim
140 real(real64),
allocatable :: points(:)
160 this%enabled = .false.
163 if (.not. this%enabled)
then
183 if (mod(this%order, 2) == 0 .or. this%order < 3)
then
196 if (mod(this%divisor, 2) == 0 .or. this%divisor < 3)
then
200 this%nn = (this%divisor - 1)/2
201 this%interp_min = -this%order/2
202 this%interp_max = this%order/2 + 1
208 safe_allocate(this%co(this%interp_min:this%interp_max, 1:this%nn))
209 safe_allocate(points(1:this%order + 1))
211 do ll = this%interp_min, this%interp_max
212 points(ll - this%interp_min + 1) = real(this%divisor*ll - aa, real64)
216 safe_deallocate_a(points)
227 safe_deallocate_a(this%co)
228 this%enabled = .false.
240 class(
mesh_t),
intent(in) :: mesh
242 integer :: i1, i2, i3
245 if (.not. this%enabled)
return
250 margin = max(margin, norm2(mesh%coord_system%to_cartesian(mesh%spacing(1:3)*[i1, i2, i3])))
254 margin = this%interp_max*margin
270 type(submesh_t),
intent(in) :: sm
271 integer,
intent(in) :: nf
272 type(spline_t),
intent(in) :: spl(:)
273 integer,
intent(in) :: ll(:)
274 integer,
intent(in) :: mm(:)
275 real(real64),
intent(in) :: rcut(:)
276 real(real64),
intent(out) :: feff(:, :)
277 integer,
optional,
intent(in) :: cart_dir(:)
283 real(real64),
allocatable :: rcut_eff(:)
284 integer,
allocatable :: cdir(:)
294 assert(
size(feff, 1) >= sm%np)
295 assert(
size(spl) >= nf .and.
size(ll) >= nf .and.
size(mm) >= nf .and.
size(rcut) >= nf)
298 safe_allocate(rcut_eff(1:nf))
300 rcut_eff(jf) = min(rcut(jf), spline_range_max(spl(jf)))
303 safe_allocate(cdir(1:nf))
305 if (
present(cart_dir)) cdir(1:nf) = cart_dir(1:nf)
307 if (.not. this%enabled)
then
311 if (sm%r(ip) <= rcut_eff(jf))
then
312 feff(ip, jf) = spline_eval(spl(jf), sm%r(ip))
313 if (ll(jf) >= 0)
then
314 call ylmr_real(sm%rel_x(1:3, ip), ll(jf), mm(jf), ylm)
315 feff(ip, jf) = feff(ip, jf)*ylm
317 if (cdir(jf) > 0) feff(ip, jf) = feff(ip, jf)*sm%rel_x(cdir(jf), ip)
319 feff(ip, jf) = m_zero
330 safe_deallocate_a(rcut_eff)
331 safe_deallocate_a(cdir)
356 type(submesh_t),
intent(in) :: sm
357 integer,
intent(in) :: nf
358 type(spline_t),
intent(in) :: spl(:)
359 integer,
intent(in) :: ll(:)
360 integer,
intent(in) :: mm(:)
361 real(real64),
intent(in) :: rcut(:)
362 integer,
intent(in) :: cdir(:)
363 real(real64),
intent(out) :: feff(:, :)
367 integer :: jf, nlm, im, ngrp, igrp
368 integer :: ng1, ng2, ng3, nc1, nc2, nc3, g1, g2, g3, c1, c2, c3, ip
369 integer,
allocatable :: ilm(:), lmlist(:, :), gfirst(:)
370 real(real64) :: rmax, rr, rad, frac, ylm, xfine(1:3), xfine_yz(1:3), e1(1:3)
371 real(real64),
allocatable :: vals(:), ylm_lm(:)
372 real(real64),
allocatable :: vplane(:, :, :), bplane(:, :, :)
373 integer,
allocatable :: active(:)
375 real(real64),
allocatable :: xc1(:, :), xc2(:, :), xc3(:, :)
376 real(real64),
allocatable :: b1(:, :, :, :), b2(:, :, :, :), feffbox(:, :, :, :)
377 type(c_ptr),
allocatable :: acc(:)
382 call profiling_in(
"DOUBLE_GRID")
385 assert(.not. sm%mesh%use_curvilinear)
386 assert(sm%mesh%box%dim == 3)
391 own_cache = .not.
present(cache)
398 assert(cc%np == sm%np)
399 assert(cc%divisor == this%divisor .and. cc%order == this%order)
402 rmax = maxval(rcut(1:nf))
406 safe_allocate(gfirst(1:nf + 1))
410 if (spline_same(spl(jf), spl(jf - 1)) .and. abs(rcut(jf) - rcut(jf - 1)) < m_epsilon) cycle
414 gfirst(ngrp + 1) = nf + 1
419 safe_allocate(ilm(1:nf))
420 safe_allocate(lmlist(1:2, 1:nf))
424 if (ll(jf) < 0) cycle
426 if (lmlist(1, im) == ll(jf) .and. lmlist(2, im) == mm(jf))
then
431 if (ilm(jf) == 0)
then
433 lmlist(1:2, nlm) = [ll(jf), mm(jf)]
441 ng1 = cc%ax(1)%ng; ng2 = cc%ax(2)%ng; ng3 = cc%ax(3)%ng
442 nc1 = cc%ax(1)%nc; nc2 = cc%ax(2)%nc; nc3 = cc%ax(3)%nc
445 safe_allocate(xc1(1:3, 1:ng1))
446 safe_allocate(xc2(1:3, 1:ng2))
447 safe_allocate(xc3(1:3, 1:ng3))
449 frac = cc%ax(1)%amin + real(g1 - 1 - this%nn, real64)/real(this%divisor, real64)
450 xc1(1:3, g1) = cc%xstep(1:3, 1)*frac
453 frac = cc%ax(2)%amin + real(g2 - 1 - this%nn, real64)/real(this%divisor, real64)
454 xc2(1:3, g2) = cc%xstep(1:3, 2)*frac
457 frac = cc%ax(3)%amin + real(g3 - 1 - this%nn, real64)/real(this%divisor, real64)
458 xc3(1:3, g3) = cc%xstep(1:3, 3)*frac
474 e1(1:3) = cc%xstep(1:3, 1)/norm2(cc%xstep(1:3, 1))
475 safe_allocate(b1(1:nc1, 1:ng2, 1:nf, 1:ng3))
476 safe_allocate(vplane(1:ng1, 1:nf, 1:ng2))
477 safe_allocate(bplane(1:nc1, 1:nf, 1:ng2))
478 safe_allocate(active(1:ng2))
483 xfine_yz(1:3) = cc%rel_ref(1:3) + xc2(1:3, g2) + xc3(1:3, g3)
484 if (norm2(xfine_yz - dot_product(xfine_yz, e1)*e1) > rmax) cycle
491 safe_allocate(vals(1:nf))
492 safe_allocate(ylm_lm(1:max(nlm, 1)))
493 safe_allocate(acc(1:ngrp))
495 call spline_accel_init(acc(igrp))
500 vplane(:, :, ia) = m_zero
501 xfine_yz(1:3) = cc%rel_ref(1:3) + xc2(1:3, g2) + xc3(1:3, g3)
503 xfine(1:3) = xfine_yz(1:3) + xc1(1:3, g1)
507 call ylmr_real(xfine, lmlist(1, im), lmlist(2, im), ylm)
511 if (rr > rcut(gfirst(igrp)))
then
512 vals(gfirst(igrp):gfirst(igrp + 1) - 1) = m_zero
515 rad = spline_eval_accel(spl(gfirst(igrp)), rr, acc(igrp))
516 do jf = gfirst(igrp), gfirst(igrp + 1) - 1
518 if (ilm(jf) > 0) vals(jf) = vals(jf)*ylm_lm(ilm(jf))
519 if (cdir(jf) > 0) vals(jf) = vals(jf)*xfine(cdir(jf))
522 vplane(g1, 1:nf, ia) = vals(1:nf)
527 call spline_accel_end(acc(igrp))
529 safe_deallocate_a(acc)
530 safe_deallocate_a(vals)
531 safe_deallocate_a(ylm_lm)
534 call blas_gemm(
'N',
'N', nc1, nf*nact, ng1, m_one, cc%ax(1)%kd(1, 1), nc1, &
535 vplane(1, 1, 1), ng1, m_zero, bplane(1, 1, 1), nc1)
538 b1(1:nc1, active(ia), jf, g3) = bplane(1:nc1, jf, ia)
542 safe_deallocate_a(vplane)
543 safe_deallocate_a(bplane)
544 safe_deallocate_a(active)
547 safe_allocate(b2(1:nc1, 1:nc2, 1:nf, 1:ng3))
550 call blas_gemm(
'N',
'T', nc1, nc2, ng2, m_one, b1(1, 1, jf, g3), nc1, &
551 cc%ax(2)%kd(1, 1), nc2, m_zero, b2(1, 1, jf, g3), nc1)
557 safe_allocate(feffbox(1:nc1, 1:nc2, 1:nc3, 1:nf))
559 call blas_gemm(
'N',
'T', nc1*nc2, nc3, ng3, m_one, b2(1, 1, jf, 1), nc1*nc2*nf, &
560 cc%ax(3)%kd(1, 1), nc3, m_zero, feffbox(1, 1, 1, jf), nc1*nc2)
569 ip = cc%isub(cc%kmin(1) + c1 - 1, cc%kmin(2) + c2 - 1, cc%kmin(3) + c3 - 1)
572 feff(ip, jf) = feffbox(c1, c2, c3, jf)/real(cc%noff, real64)
580 safe_deallocate_a(xc1)
581 safe_deallocate_a(xc2)
582 safe_deallocate_a(xc3)
583 safe_deallocate_a(b1)
584 safe_deallocate_a(b2)
585 safe_deallocate_a(feffbox)
586 safe_deallocate_a(ilm)
587 safe_deallocate_a(lmlist)
588 safe_deallocate_a(gfirst)
592 call profiling_out(
"DOUBLE_GRID")
607 type(submesh_t),
intent(in) :: sm
609 integer :: ip, idir, io, io1, io2, io3, il1
610 integer :: kmin(1:3), kmax(1:3), key(1:3)
611 real(real64) :: hh(1:3), chi(1:3), rel_ref(1:3)
615 assert(.not. sm%mesh%use_curvilinear)
616 assert(sm%mesh%box%dim == 3)
619 cache%divisor = this%divisor
620 cache%order = this%order
621 hh(1:3) = sm%mesh%spacing(1:3)
622 rel_ref(1:3) = sm%rel_x(1:3, 1)
623 cache%rel_ref(1:3) = rel_ref(1:3)
631 chi = sm%mesh%coord_system%from_cartesian(sm%rel_x(1:3, ip) - rel_ref(1:3))
633 assert(all(abs(chi/hh - key) < 1e-6_real64))
634 kmin = min(kmin, key)
635 kmax = max(kmax, key)
637 cache%kmin(1:3) = kmin(1:3)
638 cache%kmax(1:3) = kmax(1:3)
640 safe_allocate(cache%isub(kmin(1):kmax(1), kmin(2):kmax(2), kmin(3):kmax(3)))
643 chi = sm%mesh%coord_system%from_cartesian(sm%rel_x(1:3, ip) - rel_ref(1:3))
645 assert(cache%isub(key(1), key(2), key(3)) == 0)
646 cache%isub(key(1), key(2), key(3)) = ip
650 safe_allocate(cache%xstep(1:3, 1:3))
654 cache%xstep(1:3, idir) = sm%mesh%coord_system%to_cartesian(chi)
657 cache%noff = this%divisor**3
658 safe_allocate(cache%offs(1:3, 1:cache%noff))
659 safe_allocate(cache%xoff(1:3, 1:cache%noff))
661 do io3 = -this%nn, this%nn
662 do io2 = -this%nn, this%nn
663 do io1 = -this%nn, this%nn
665 cache%offs(1:3, io) = [io1, io2, io3]
666 cache%xoff(1:3, io) = (cache%xstep(1:3, 1)*io1 + cache%xstep(1:3, 2)*io2 &
667 + cache%xstep(1:3, 3)*io3)/this%divisor
675 safe_allocate(cache%tgt(1:this%order + 1, -this%nn:this%nn))
676 safe_allocate(cache%wgt(1:this%order + 1, -this%nn:this%nn))
677 safe_allocate(cache%ntgt(-this%nn:this%nn))
678 do io1 = -this%nn, this%nn
681 cache%tgt(1, io1) = 0
682 cache%wgt(1, io1) = m_one
684 cache%ntgt(io1) = this%order + 1
685 do il1 = this%interp_min, this%interp_max
686 cache%tgt(il1 - this%interp_min + 1, io1) = il1*sign(1, io1)
687 cache%wgt(il1 - this%interp_min + 1, io1) = this%co(il1, abs(io1))
699 cache%ax(idir)%amin = kmin(idir) - this%interp_max
700 cache%ax(idir)%nc = kmax(idir) - kmin(idir) + 1
701 cache%ax(idir)%ng = (kmax(idir) - kmin(idir) + 1 + 2*this%interp_max)*this%divisor
702 safe_allocate(cache%ax(idir)%nt(1:cache%ax(idir)%ng))
703 safe_allocate(cache%ax(idir)%ct(1:this%order + 1, 1:cache%ax(idir)%ng))
704 safe_allocate(cache%ax(idir)%wt(1:this%order + 1, 1:cache%ax(idir)%ng))
705 cache%ax(idir)%nt = 0
717 integer,
intent(in) :: kmn, kmx
719 integer :: g, g0, iia, oo, il, cc, nt
723 iia = ax%amin + g0/this%divisor
724 oo = mod(g0, this%divisor) - this%nn
726 do il = 1, cache%ntgt(oo)
727 cc = iia + cache%tgt(il, oo)
728 if (cc < kmn .or. cc > kmx) cycle
730 ax%ct(nt, g) = cc - kmn + 1
731 ax%wt(nt, g) = cache%wgt(il, oo)
737 safe_allocate(ax%kd(1:ax%nc, 1:ax%ng))
741 ax%kd(ax%ct(il, g), g) = ax%wt(il, g)
756 cache%valid = .false.
759 safe_deallocate_a(cache%isub)
760 safe_deallocate_a(cache%offs)
761 safe_deallocate_a(cache%xoff)
762 safe_deallocate_a(cache%xstep)
763 safe_deallocate_a(cache%tgt)
764 safe_deallocate_a(cache%wgt)
765 safe_deallocate_a(cache%ntgt)
767 cache%ax(idir)%ng = 0
768 cache%ax(idir)%nc = 0
769 safe_deallocate_a(cache%ax(idir)%nt)
770 safe_deallocate_a(cache%ax(idir)%ct)
771 safe_deallocate_a(cache%ax(idir)%wt)
772 safe_deallocate_a(cache%ax(idir)%kd)
subroutine build_axis_kernel(ax, kmn, kmx)
Fill one axis kernel: for every fine index g = (ia,o), enumerate its coarse targets.
This module contains interfaces for BLAS routines You should not use these routines directly....
The Ono-Hirose double-grid technique [T. Ono and K. Hirose, Phys. Rev. Lett. 82, 5016 (1999); Phys....
real(real64) function, public double_grid_margin(this, mesh)
Submesh radius enlargement needed to contain the effective support of a transformed function: the ten...
subroutine, public double_grid_end(this)
subroutine double_grid_transform_kernel(this, sm, nf, spl, ll, mm, rcut, cdir, feff, cache)
The transpose-interpolation scatter. All arithmetic is done with integer grid keys relative to the fi...
subroutine, public double_grid_cache_init(cache, this, sm)
Precompute the function-independent geometry of the double-grid transpose scatter for one submesh: th...
subroutine, public double_grid_init(this, namespace, dim)
subroutine, public double_grid_cache_end(cache)
subroutine, public double_grid_transform(this, sm, nf, spl, ll, mm, rcut, feff, cart_dir, cache)
Evaluate a batch of localized functions f_jf(x) = spl_jf(r) * Y_{ll,mm}(x) (or a purely radial spl_jf...
real(real64), parameter, public m_zero
This module is intended to contain "only mathematical" functions and procedures.
subroutine, public interpolation_coefficients(nn, xa, xx, cc)
This module defines the meshes, which are used in Octopus.
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_experimental(name, namespace)
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
One-dimensional transpose-interpolation kernel along a single Cartesian axis. The full 3D tensor-prod...
Persistent, function-independent geometry of the double-grid transpose scatter for one submesh....
Describes mesh distribution to nodes.