29 use,
intrinsic :: iso_fortran_env
84 real(real64),
allocatable :: center(:)
85 real(real64) :: radius =
m_zero
86 class(box_t),
pointer :: box => null()
88 integer,
allocatable :: map(:)
89 integer :: num_regions
90 integer,
allocatable :: regions(:)
91 type(accel_mem_t) :: buff_map
92 real(real64),
allocatable :: rel_x(:,:)
93 real(real64),
allocatable :: r(:)
96 real(real64),
allocatable :: vol_pp(:)
97 type(mesh_t),
pointer :: mesh => null()
100 integer :: np_global = -1
101 real(real64),
allocatable :: rel_x_global(:,:)
102 integer,
allocatable :: part_v(:)
103 integer,
allocatable :: global2local(:)
105 type(mesh_cube_map_t) :: cube_map
122 recursive real(real64) function f_n(dims)
result(fn)
127 else if (dims == 1)
then
136 subroutine submesh_init(this, space, mesh, latt, center, rc)
137 type(submesh_t),
intent(inout) :: this
138 class(space_t),
intent(in) :: space
139 class(mesh_t),
target,
intent(in) :: mesh
140 type(lattice_vectors_t),
intent(in) :: latt
141 real(real64),
intent(in) :: center(1:space%dim)
142 real(real64),
intent(in) :: rc
144 real(real64) :: r2, rc2, xx(space%dim), rc_norm_n
145 real(real64),
allocatable :: center_copies(:,:), xtmp(:, :), rtmp(:)
146 integer :: icell, is, ip, ix, iy, iz
147 integer(int64) :: max_elements_count
148 type(lattice_iterator_t) :: latt_iter
149 integer,
allocatable :: map_inv(:), map_temp(:)
150 integer :: nmax(3), nmin(3)
151 real(real64),
parameter :: tol = 1e-13_real64
157 assert(space%dim <= 3)
161 safe_allocate(this%center(1:space%dim))
162 this%center(:) = center(:)
170 if (.not. space%is_periodic())
then
173 safe_allocate(map_inv(0:this%mesh%np))
174 map_inv(0:this%mesh%np) = 0
180 nmin(1:space%dim) = int((center(1:space%dim) - abs(rc))/mesh%spacing(1:space%dim)) - 1
181 nmax(1:space%dim) = int((center(1:space%dim) + abs(rc))/mesh%spacing(1:space%dim)) + 1
185 nmin(1:space%dim) = max(mesh%idx%nr(1, 1:space%dim), nmin(1:space%dim))
186 nmax(1:space%dim) = min(mesh%idx%nr(2, 1:space%dim), nmax(1:space%dim))
190 do iz = nmin(3), nmax(3)
191 do iy = nmin(2), nmax(2)
192 do ix = nmin(1), nmax(1)
194 if (ip == 0 .or. ip > mesh%np) cycle
195 r2 = sum((mesh%x(:, ip) - center)**2)
207 safe_allocate(this%map(1:this%np))
208 safe_allocate(xtmp(1:space%dim, 1:this%np))
209 safe_allocate(rtmp(1:this%np))
212 do iz = nmin(3), nmax(3)
213 do iy = nmin(2), nmax(2)
214 do ix = nmin(1), nmax(1)
216 if (ip == 0 .or. ip > mesh%np) cycle
220 xtmp(:, is) = mesh%x(:, ip) - center
221 rtmp(is) = norm2(xtmp(:,is))
226 safe_deallocate_a(map_inv)
239 latt_iter =
lattice_iterator_t(latt, rc, center=latt%cart_to_red(center) - mesh%red_min(space))
242 safe_allocate(center_copies(1:space%dim, 1:latt_iter%n_cells))
243 do icell = 1, latt_iter%n_cells
244 center_copies(:, icell) = center + latt_iter%get(icell)
249 rc_norm_n = product(ceiling(rc / mesh%spacing(1:space%dim), int64) +
m_one)
250 if (mesh%use_vol_pp) rc_norm_n = rc_norm_n / mesh%coord_system%min_mesh_scaling_product
251 max_elements_count = 3**space%dim * int(
m_pi**
floor(0.5 * space%dim) * rc_norm_n *
f_n(space%dim), int64)
254 safe_allocate(map_temp(1:max_elements_count))
255 safe_allocate(xtmp(1:space%dim, 1:max_elements_count))
256 safe_allocate(rtmp(1:max_elements_count))
260 do icell = 1, latt_iter%n_cells
261 xx = mesh%x(:,ip) - center_copies(:, icell)
262 if(any(abs(xx)>rc+tol)) cycle
272 assert(is < huge(is))
275 safe_allocate(this%map(1:this%np))
276 this%map(1:this%np) = map_temp(1:this%np)
279 safe_deallocate_a(map_temp)
280 safe_deallocate_a(center_copies)
287 safe_deallocate_a(xtmp)
288 safe_deallocate_a(rtmp)
305 if (.not. this%mesh%use_vol_pp)
return
310 safe_deallocate_a(this%vol_pp)
311 safe_allocate(this%vol_pp(1:this%np))
313 this%vol_pp(is) = this%mesh%vol_pp(this%map(is))
321 class(
space_t),
intent(in) :: space
322 real(real64),
contiguous,
intent(in) :: xtmp(:, :), rtmp(:)
324 integer :: ip, i_region, offset
325 integer,
allocatable :: order(:), order_new(:)
326 integer,
allocatable :: map_new(:)
327 integer,
allocatable :: np_region(:), tmp_array(:)
334 safe_allocate(order(1:this%np))
335 safe_allocate(this%rel_x(1:space%dim, 1:this%np))
336 safe_allocate(this%r(1:this%np))
343 call sort(this%map, order)
346 this%overlap = .false.
347 do ip = 1, this%np - 1
348 if (this%map(ip) == this%map(ip + 1))
then
350 this%overlap = .
true.
358 if(this%overlap)
then
362 safe_allocate(tmp_array(1:this%np))
363 safe_allocate(order_new(1:this%np))
364 safe_allocate(np_region(1:this%np))
365 safe_allocate(map_new( 1:this%np))
372 if (this%map(ip) == this%map(ip - 1))
then
373 i_region = i_region + 1
374 if (i_region > this%num_regions)
then
375 this%num_regions = i_region
376 np_region(i_region) = 0
381 tmp_array(ip) = i_region
382 np_region(i_region) = np_region(i_region) + 1
385 assert( .not.
allocated(this%regions))
388 safe_allocate(this%regions(1:this%num_regions+1))
392 if(this%num_regions > 1)
then
393 do i_region = 1, this%num_regions
394 this%regions(i_region + 1) = this%regions(i_region) + np_region(i_region)
397 this%regions(2) = this%np + 1
400 np_region(1:this%np) = 0
401 order_new(1:this%np) = -1
402 map_new(1:this%np) = -1
407 i_region = tmp_array(ip)
408 np_region(i_region) = np_region(i_region) + 1
409 offset = this%regions(i_region) - 1
410 map_new( offset + np_region(i_region) ) = this%map(ip)
411 order_new( offset + np_region(i_region) ) = order(ip)
414 order(1:this%np) = order_new(1:this%np)
415 this%map(1:this%np) = map_new(1:this%np)
417 safe_deallocate_a(tmp_array)
418 safe_deallocate_a(order_new)
419 safe_deallocate_a(np_region)
420 safe_deallocate_a(map_new)
425 safe_allocate(this%regions(1:2))
427 this%regions(2) = this%np + 1
432 this%rel_x(:, ip) = xtmp(:, order(ip))
433 this%r(ip) = rtmp(order(ip))
436 safe_deallocate_a(order)
447 class(
space_t),
intent(in) :: space
448 class(
mesh_t),
target,
intent(in) :: mesh
451 real(real64),
optional,
intent(in) :: shift(:)
455 real(real64) :: xx(space%dim), diff_centers(space%dim)
462 safe_allocate(this%center(1:space%dim))
463 this%center(:) = sm1%center(:)
464 this%radius = sm1%radius
468 this%overlap = sm1%overlap .or. sm2%overlap
470 diff_centers = sm1%center - sm2%center
471 if (
present(shift)) diff_centers = diff_centers - shift
478 xx = sm2%rel_x(:, ip) - diff_centers
480 if (sum(xx**2) > sm1%radius**2) is = is + 1
485 safe_allocate(this%map(1:this%np))
486 safe_allocate(this%rel_x(1:space%dim, 1:this%np))
487 safe_allocate(this%r(1:this%np))
488 this%map(1:sm1%np) = sm1%map(1:sm1%np)
489 this%rel_x(:, 1:sm1%np) = sm1%rel_x(:, 1:sm1%np)
490 this%r(1:sm1%np) = sm1%r(1:sm1%np)
495 xx = sm2%rel_x(:, ip) - diff_centers
497 if (r2 > sm1%radius**2)
then
499 this%map(is) = sm2%map(ip)
500 this%r(is) =
sqrt(r2)
501 this%rel_x(:, is) = xx
515 class(
space_t),
intent(in) :: space
516 real(real64),
intent(in) :: newcenter(:)
518 real(real64) :: xx(space%dim), diff_centers(space%dim), oldcenter(space%dim)
524 oldcenter = this%center
525 this%center(:) = newcenter(:)
527 diff_centers = newcenter - oldcenter
530 xx = this%rel_x(:, ip) - diff_centers
531 this%r(ip) = norm2(xx)
532 this%rel_x(:, ip) = xx
542 class(
space_t),
intent(in) :: space
543 type(
mesh_t),
target,
intent(in) :: mesh
544 real(real64),
intent(in) :: center(1:space%dim)
545 real(real64),
intent(in) :: radius
546 integer,
intent(in) :: root
549 integer :: nparray(1:3)
554 if (root /= mpi_grp%rank)
then
556 safe_allocate(this%center(1:space%dim))
557 this%center(:) = center(:)
561 if (mpi_grp%size > 1)
then
563 if (root == mpi_grp%rank)
then
565 nparray(2) = this%num_regions
566 if (this%overlap)
then
573 call mpi_grp%bcast(nparray, 3, mpi_integer, root)
575 this%num_regions = nparray(2)
576 this%overlap = (nparray(3) == 1)
578 if (root /= mpi_grp%rank)
then
579 safe_allocate(this%map(1:this%np))
580 safe_allocate(this%rel_x(1:space%dim, 1:this%np))
581 safe_allocate(this%r(1:this%np))
582 safe_allocate(this%regions(1:this%num_regions+1))
585 call mpi_grp%bcast(this%regions(1), this%num_regions+1, mpi_integer, root)
587 if (this%np > 0)
then
588 call mpi_grp%bcast(this%map(1), this%np, mpi_integer, root)
589 call mpi_grp%bcast(this%rel_x(1, 1), this%np*space%dim, mpi_double_precision, root)
590 call mpi_grp%bcast(this%r(1), this%np, mpi_double_precision, root)
604 real(real64),
intent(in) :: radius
605 real(real64),
intent(in) :: center(:)
606 real(real64),
intent(in) :: dx
609 if (
allocated(this%center))
then
612 if (radius <= this%radius+dx*1e-6_real64 .and. all(abs(this%center - center) < 0.25*dx))
then
627 if (this%np /= -1)
then
629 safe_deallocate_a(this%center)
630 safe_deallocate_a(this%map)
631 safe_deallocate_a(this%rel_x)
632 safe_deallocate_a(this%r)
633 safe_deallocate_a(this%vol_pp)
634 safe_deallocate_a(this%regions)
649 class(
space_t),
intent(in) :: space
651 integer :: ii, jj, dd
656 if (.not. space%is_periodic())
then
658 distance = sum((sm1%center - sm2%center)**2)
659 overlap =
distance <= (1.5_real64*(sm1%radius + sm2%radius))**2
662 if (.not. overlap)
return
670 do while(ii <= sm1%np .and. jj <= sm2%np)
671 dd = sm1%map(ii) - sm2%map(jj)
674 else if (dd > 0)
then
682 if (sm1%mesh%parallel_in_domains)
then
683 call sm1%mesh%mpi_grp%allreduce_inplace(overlap, 1, mpi_logical, mpi_lor)
691 class(
space_t),
intent(in) :: space
693 integer,
allocatable :: part_np(:)
694 integer :: ipart, ind, ip
698 if (.not. this%mesh%parallel_in_domains)
then
699 this%np_global = this%np
704 safe_allocate(part_np(this%mesh%pv%npart))
706 part_np(this%mesh%pv%partno) = this%np
708 call this%mesh%allreduce(part_np)
709 this%np_global = sum(part_np)
711 safe_allocate(this%rel_x_global(1:space%dim, 1:this%np_global))
712 safe_allocate(this%part_v(1:this%np_global))
713 safe_allocate(this%global2local(1:this%np_global))
714 this%rel_x_global(1:space%dim, 1:this%np_global) =
m_zero
715 this%part_v(1:this%np_global) = 0
716 this%global2local(1:this%np_global) = 0
719 do ipart = 1, this%mesh%pv%npart
720 if (ipart == this%mesh%pv%partno)
then
722 this%rel_x_global(:, ind + ip) = this%rel_x(:, ip)
723 this%part_v(ind + ip) = this%mesh%pv%partno
724 this%global2local(ind + ip) = ip
727 ind = ind + part_np(ipart)
730 call this%mesh%allreduce(this%rel_x_global)
731 call this%mesh%allreduce(this%part_v)
732 call this%mesh%allreduce(this%global2local)
734 safe_deallocate_a(part_np)
745 safe_deallocate_a(this%rel_x_global)
747 safe_deallocate_a(this%part_v)
748 safe_deallocate_a(this%global2local)
757 complex(real64),
contiguous,
intent(in) :: sphi(:)
758 complex(real64),
contiguous,
intent(inout) :: phi(:)
759 complex(real64),
optional,
intent(in) :: factor
765 if (
present(factor))
then
769 phi(this%map(ip)) = phi(this%map(ip)) + factor*sphi(ip)
771 if (this%np.ge.4)
then
772 do ip = m+1, this%np, 4
773 phi(this%map(ip)) = phi(this%map(ip)) + factor*sphi(ip)
774 phi(this%map(ip+1)) = phi(this%map(ip+1)) + factor*sphi(ip+1)
775 phi(this%map(ip+2)) = phi(this%map(ip+2)) + factor*sphi(ip+2)
776 phi(this%map(ip+3)) = phi(this%map(ip+3)) + factor*sphi(ip+3)
782 phi(this%map(ip)) = phi(this%map(ip)) + sphi(ip)
784 if (this%np.ge.4)
then
785 do ip = m+1, this%np, 4
786 phi(this%map(ip)) = phi(this%map(ip)) + sphi(ip)
787 phi(this%map(ip+1)) = phi(this%map(ip+1)) + sphi(ip+1)
788 phi(this%map(ip+2)) = phi(this%map(ip+2)) + sphi(ip+2)
789 phi(this%map(ip+3)) = phi(this%map(ip+3)) + sphi(ip+3)
800 complex(real64),
contiguous,
intent(in) :: sphi(:)
801 complex(real64),
contiguous,
intent(in) :: phi(:)
802 logical,
optional,
intent(in) :: reduce
810 if (this%mesh%use_vol_pp)
then
812 dotp = dotp + this%vol_pp(is)*phi(this%map(is))*conjg(sphi(is))
817 dotp = dotp + phi(this%map(ip))*conjg(sphi(ip))
819 if (this%np.ge.4)
then
820 do ip = m+1, this%np, 4
821 dotp = dotp + phi(this%map(ip))*conjg(sphi(ip)) &
822 + phi(this%map(ip+1))*conjg(sphi(ip+1)) &
823 + phi(this%map(ip+2))*conjg(sphi(ip+2)) &
824 + phi(this%map(ip+3))*conjg(sphi(ip+3))
827 dotp = dotp*this%mesh%vol_pp(1)
832 call this%mesh%allreduce(dotp)
842 type(
submesh_t),
target,
intent(in) :: sm
843 class(
space_t),
intent(in) :: space
844 integer,
intent(out) :: db(1:space%dim)
847 real(real64) :: chi(space%dim), max_chi(space%dim)
848 integer :: db_red(1:space%dim)
849 real(real64),
parameter :: tol=1.0e-10_real64
855 chi = sm%mesh%coord_system%from_cartesian(sm%rel_x(:, ip))
856 do idir = 1, space%dim
857 max_chi(idir) = max(max_chi(idir), abs(chi(idir))/sm%mesh%spacing(idir))
861 do idir = 1, space%dim
862 db(idir) = nint(max_chi(idir)-tol)
865 if(sm%mesh%parallel_in_domains)
then
866 call sm%mesh%mpi_grp%allreduce(db(1), db_red(1), space%dim, mpi_integer, mpi_max)
867 db(1:space%dim) = db_red(1:space%dim)
877 type(
submesh_t),
target,
intent(inout) :: sm
878 class(
space_t),
intent(in) :: space
882 real(real64) :: chi(space%dim), shift(space%dim)
886 sm%cube_map%nmap = sm%np
888 safe_allocate(sm%cube_map%map(1:space%dim, 1:sm%cube_map%nmap))
892 chi = sm%mesh%coord_system%from_cartesian(sm%center)
893 do idir = 1, space%dim
894 shift(idir) = nint(chi(idir)/sm%mesh%spacing(idir))*sm%mesh%spacing(idir)
896 shift = sm%mesh%coord_system%to_cartesian(shift)
897 shift = shift - sm%center
899 do ip = 1, sm%cube_map%nmap
900 chi = sm%mesh%coord_system%from_cartesian(sm%rel_x(:,ip) - shift)
901 do idir = 1, space%dim
902 sm%cube_map%map(idir, ip) = nint(chi(idir)/sm%mesh%spacing(idir))
908 call accel_write_buffer(sm%cube_map%map_buffer, space%dim, sm%cube_map%nmap, sm%cube_map%map)
933 class(
batch_t),
intent(in) :: ss
934 class(
batch_t),
intent(inout) :: mm
936 integer :: ist, idim, jdim, is
940 assert(.not. mm%is_packed())
943 assert(ss%nst_linear == mm%nst_linear)
944 assert(ss%status() == mm%status())
945 assert(ss%dim == mm%dim)
947 assert(mm%nst == ss%nst)
952 jdim = min(idim, ss%dim)
955 mm%zff(this%map(is), idim, ist) = &
956 mm%zff(this%map(is), idim, ist) + ss%dff(is, jdim, ist)
969#include "submesh_inc.F90"
972#include "complex.F90"
973#include "submesh_inc.F90"
This is the common interface to a sorting routine. It performs the shell algorithm,...
double sqrt(double __x) __attribute__((__nothrow__
double floor(double __x) __attribute__((__nothrow__
double fn(const gsl_vector *v, void *params)
subroutine, public accel_free_buffer(this, async)
pure logical function, public accel_is_enabled()
integer, parameter, public accel_mem_read_only
This module implements batches of mesh functions.
Module implementing boundary conditions in Octopus.
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_pi
some mathematical constants
complex(real64), parameter, public m_z0
real(real64), parameter, public m_one
This module implements the index, used for the mesh points.
subroutine, public mesh_cube_map_end(this)
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
integer function, public mesh_local_index_from_coords(mesh, ix)
This function returns the local index of the point for a given vector of integer coordinates.
Some general things and nomenclature:
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
This module is intended to contain "only mathematical" functions and procedures.
real(real64) function, public dsm_integrate_frommesh(mesh, sm, ff, reduce)
subroutine zdsubmesh_add_to_mesh(this, sphi, phi, factor)
subroutine, public submesh_init_cube_map(sm, space)
logical function, public submesh_overlap(sm1, sm2, space)
subroutine, public zsubmesh_batch_dotp_matrix(this, mm, ss, dot, reduce)
real(real64) function, public dsm_nrm2(sm, ff, reduce)
this function returns the the norm of a vector
subroutine zzsubmesh_add_to_mesh(this, sphi, phi, factor)
subroutine submesh_get_vol_pp(this)
Gather the per-point volume elements of the sphere from the mesh.
subroutine, public submesh_end_global(this)
subroutine, public zsubmesh_copy_from_mesh(this, phi, sphi, conjugate)
subroutine submesh_reorder_points(this, space, xtmp, rtmp)
complex(real64) function, public zsm_integrate(mesh, sm, ff, reduce)
complex(real64) function, public zsubmesh_dotp(this, f1, f2, reduce)
dot product of two functions defined on the submesh
subroutine, public submesh_shift_center(this, space, newcenter)
complex(real64) function zzsubmesh_to_mesh_dotp(this, sphi, phi, reduce)
real(real64) function, public dsm_integrate(mesh, sm, ff, reduce)
subroutine, public dsubmesh_batch_add_matrix(this, factor, ss, mm)
The following functions takes a batch of functions defined in submesh (ss) and adds all of them to ea...
recursive real(real64) function f_n(dims)
subroutine, public dsubmesh_copy_from_mesh(this, phi, sphi, conjugate)
real(real64) function ddsubmesh_to_mesh_dotp(this, sphi, phi, reduce)
subroutine, public submesh_merge(this, space, mesh, sm1, sm2, shift)
subroutine, public dzsubmesh_batch_add(this, ss, mm)
The following function takes a batch of functions defined in submesh (ss) and adds one of them to eac...
subroutine, public zsubmesh_batch_add(this, ss, mm)
The following function takes a batch of functions defined in submesh (ss) and adds one of them to eac...
real(real64) function, public zsm_nrm2(sm, ff, reduce)
this function returns the the norm of a vector
subroutine, public zsubmesh_batch_add_matrix(this, factor, ss, mm)
The following functions takes a batch of functions defined in submesh (ss) and adds all of them to ea...
subroutine, public submesh_end_cube_map(sm)
subroutine, public submesh_end(this)
subroutine ddsubmesh_add_to_mesh(this, sphi, phi, factor)
subroutine, public submesh_get_cube_dim(sm, space, db)
finds the dimension of a box containing the submesh
subroutine, public dsubmesh_batch_dotp_matrix(this, mm, ss, dot, reduce)
complex(real64) function, public zsm_integrate_frommesh(mesh, sm, ff, reduce)
logical function, public submesh_compatible(this, radius, center, dx)
real(real64) function, public dsubmesh_dotp(this, f1, f2, reduce)
dot product of two functions defined on the submesh
subroutine, public submesh_build_global(this, space)
subroutine, public submesh_broadcast(this, space, mesh, center, radius, root, mpi_grp)
subroutine, public dsubmesh_batch_add(this, ss, mm)
The following function takes a batch of functions defined in submesh (ss) and adds one of them to eac...
subroutine, public submesh_init(this, space, mesh, latt, center, rc)
complex(real64) function zdsubmesh_to_mesh_dotp(this, sphi, phi, reduce)
type(type_t), parameter, public type_cmplx
type(type_t), parameter, public type_integer
type(type_t), parameter, public type_float
Class defining batches of mesh functions.
The following class implements a lattice iterator. It allows one to loop over all cells that are with...
Describes mesh distribution to nodes.
This is defined even when running serial.
A submesh is a type of mesh, used for the projectors in the pseudopotentials It contains points on a ...
void distance(const int iatom, const int jatom, const double coordinates[], double *rr, double *rr2, double *rr6, double *rr7)