30 use,
intrinsic :: iso_fortran_env
86 real(real64),
allocatable :: center(:)
87 real(real64) :: radius =
m_zero
88 class(box_t),
pointer :: box => null()
90 integer,
allocatable :: map(:)
91 integer :: num_regions
92 integer,
allocatable :: regions(:)
93 type(accel_mem_t) :: buff_map
94 real(real64),
allocatable :: rel_x(:,:)
95 real(real64),
allocatable :: r(:)
96 type(mesh_t),
pointer :: mesh => null()
99 integer :: np_global = -1
100 real(real64),
allocatable :: rel_x_global(:,:)
101 integer,
allocatable :: part_v(:)
102 integer,
allocatable :: global2local(:)
104 type(mesh_cube_map_t) :: cube_map
121 recursive real(real64) function f_n(dims)
result(fn)
126 else if (dims == 1)
then
136 type(submesh_t),
intent(inout) :: this
137 class(space_t),
intent(in) :: space
138 class(mesh_t),
target,
intent(in) :: mesh
139 class(box_t),
target,
intent(in) :: box
140 real(real64),
intent(in) :: center(:)
142 integer :: original_mesh_index, submesh_index
143 logical :: submesh_points(1:mesh%np)
144 real(real64),
allocatable :: xtmp(:, :), rtmp(:)
148 assert(.not. space%is_periodic())
155 submesh_points = box%contains_points(mesh%np, mesh%x)
156 this%np = count(submesh_points)
158 assert(this%np <= mesh%np)
160 safe_allocate(this%map(1:this%np))
161 safe_allocate(xtmp(1:space%dim, 1:this%np))
162 safe_allocate(rtmp(1:this%np))
168 do original_mesh_index = 1, mesh%np
170 if (submesh_points(original_mesh_index))
then
171 submesh_index = submesh_index + 1
172 this%map(submesh_index) = original_mesh_index
174 xtmp(:, submesh_index) = mesh%x(original_mesh_index, :) - center(:)
175 rtmp(submesh_index) = norm2(xtmp(:, submesh_index))
181 safe_deallocate_a(xtmp)
182 safe_deallocate_a(rtmp)
191 class(
mesh_t),
target,
intent(in) :: mesh
193 real(real64),
intent(in) :: center(1:space%dim)
194 real(real64),
intent(in) :: rc
196 real(real64) :: r2, rc2, xx(space%dim), rc_norm_n
197 real(real64),
allocatable :: center_copies(:,:), xtmp(:, :), rtmp(:), x(:,:)
198 integer :: icell, is, ip, ix, iy, iz
199 integer(int64) :: max_elements_count
200 type(lattice_iterator_t) :: latt_iter
201 integer,
allocatable :: map_inv(:), map_temp(:)
202 integer :: nmax(3), nmin(3)
203 real(real64),
parameter :: tol = 1e-13_real64
209 assert(space%dim <= 3)
213 safe_allocate(this%center(1:space%dim))
222 if (.not. space%is_periodic())
then
225 safe_allocate(map_inv(0:this%mesh%np))
226 map_inv(0:this%mesh%np) = 0
232 nmin(1:space%dim) = int((center(1:space%dim) - abs(rc))/mesh%spacing(1:space%dim)) - 1
233 nmax(1:space%dim) = int((center(1:space%dim) + abs(rc))/mesh%spacing(1:space%dim)) + 1
237 nmin(1:space%dim) = max(mesh%idx%nr(1, 1:space%dim), nmin(1:space%dim))
238 nmax(1:space%dim) = min(mesh%idx%nr(2, 1:space%dim), nmax(1:space%dim))
242 do iz = nmin(3), nmax(3)
243 do iy = nmin(2), nmax(2)
244 do ix = nmin(1), nmax(1)
246 if (ip == 0 .or. ip > mesh%np) cycle
247 r2 = sum((mesh%x(ip, :) - center)**2)
259 safe_allocate(this%map(1:this%np))
260 safe_allocate(xtmp(1:space%dim, 1:this%np))
261 safe_allocate(rtmp(1:this%np))
264 do iz = nmin(3), nmax(3)
265 do iy = nmin(2), nmax(2)
266 do ix = nmin(1), nmax(1)
268 if (ip == 0 .or. ip > mesh%np) cycle
272 xtmp(:, is) = mesh%x(ip, :) - center
273 rtmp(is) = norm2(xtmp(:,is))
278 safe_deallocate_a(map_inv)
291 safe_allocate(center_copies(1:space%dim, 1:latt_iter%n_cells))
292 do icell = 1, latt_iter%n_cells
293 center_copies(:, icell) = center + latt_iter%get(icell)
298 rc_norm_n = product(ceiling(rc / mesh%spacing(1:space%dim), int64) +
m_one)
299 if (mesh%use_curvilinear) rc_norm_n = rc_norm_n / mesh%coord_system%min_mesh_scaling_product
300 max_elements_count = 3**space%dim * int(
m_pi**
floor(0.5 * space%dim) * rc_norm_n *
f_n(space%dim), int64)
302 safe_allocate(x(1:space%dim,1:mesh%np))
304 x(:,ip) = mesh%x(ip,:)
307 safe_allocate(map_temp(1:max_elements_count))
308 safe_allocate(xtmp(1:space%dim, 1:max_elements_count))
309 safe_allocate(rtmp(1:max_elements_count))
313 do icell = 1, latt_iter%n_cells
314 xx = x(:,ip) - center_copies(:, icell)
315 if(any(abs(xx)>rc+tol)) cycle
325 assert(is < huge(is))
328 safe_allocate(this%map(1:this%np))
329 this%map(1:this%np) = map_temp(1:this%np)
332 safe_deallocate_a(map_temp)
333 safe_deallocate_a(center_copies)
341 safe_deallocate_a(xtmp)
342 safe_deallocate_a(rtmp)
349 class(
space_t),
intent(in) :: space
350 real(real64),
intent(in) :: xtmp(:, :), rtmp(:)
352 integer :: ip, i_region, offset
353 integer,
allocatable :: order(:), order_new(:)
354 integer,
allocatable :: map_new(:)
355 integer,
allocatable :: np_region(:), tmp_array(:)
362 safe_allocate(order(1:this%np))
363 safe_allocate(this%rel_x(1:space%dim, 1:this%np))
364 safe_allocate(this%r(1:this%np))
371 call sort(this%map, order)
374 this%overlap = .false.
375 do ip = 1, this%np - 1
376 if (this%map(ip) == this%map(ip + 1))
then
378 this%overlap = .
true.
386 if(this%overlap)
then
390 safe_allocate(tmp_array(1:this%np))
391 safe_allocate(order_new(1:this%np))
392 safe_allocate(np_region(1:this%np))
393 safe_allocate(map_new( 1:this%np))
400 if (this%map(ip) == this%map(ip - 1))
then
401 i_region = i_region + 1
402 if (i_region > this%num_regions)
then
403 this%num_regions = i_region
404 np_region(i_region) = 0
409 tmp_array(ip) = i_region
410 np_region(i_region) = np_region(i_region) + 1
413 assert( .not.
allocated(this%regions))
416 safe_allocate(this%regions(1:this%num_regions+1))
420 if(this%num_regions > 1)
then
421 do i_region = 1, this%num_regions
422 this%regions(i_region + 1) = this%regions(i_region) + np_region(i_region)
425 this%regions(2) = this%np + 1
428 np_region(1:this%np) = 0
429 order_new(1:this%np) = -1
430 map_new(1:this%np) = -1
435 i_region = tmp_array(ip)
436 np_region(i_region) = np_region(i_region) + 1
437 offset = this%regions(i_region) - 1
438 map_new( offset + np_region(i_region) ) = this%map(ip)
439 order_new( offset + np_region(i_region) ) = order(ip)
442 order(1:this%np) = order_new(1:this%np)
443 this%map(1:this%np) = map_new(1:this%np)
445 safe_deallocate_a(tmp_array)
446 safe_deallocate_a(order_new)
447 safe_deallocate_a(np_region)
448 safe_deallocate_a(map_new)
453 safe_allocate(this%regions(1:2))
455 this%regions(2) = this%np + 1
460 this%rel_x(:, ip) = xtmp(:, order(ip))
461 this%r(ip) = rtmp(order(ip))
464 safe_deallocate_a(order)
475 class(
space_t),
intent(in) :: space
476 class(
mesh_t),
target,
intent(in) :: mesh
479 real(real64),
optional,
intent(in) :: shift(:)
483 real(real64) :: xx(space%dim), diff_centers(space%dim)
490 safe_allocate(this%center(1:space%dim))
491 this%center = sm1%center
492 this%radius = sm1%radius
496 this%overlap = sm1%overlap .or. sm2%overlap
498 diff_centers = sm1%center - sm2%center
499 if (
present(shift)) diff_centers = diff_centers - shift
506 xx = sm2%rel_x(:, ip) - diff_centers
508 if (sum(xx**2) > sm1%radius**2) is = is + 1
513 safe_allocate(this%map(1:this%np))
514 safe_allocate(this%rel_x(1:space%dim, 1:this%np))
515 safe_allocate(this%r(1:this%np))
516 this%map(1:sm1%np) = sm1%map(1:sm1%np)
517 this%rel_x(:, 1:sm1%np) = sm1%rel_x(:, 1:sm1%np)
518 this%r(1:sm1%np) = sm1%r(1:sm1%np)
523 xx = sm2%rel_x(:, ip) - diff_centers
525 if (r2 > sm1%radius**2)
then
527 this%map(is) = sm2%map(ip)
528 this%r(is) =
sqrt(r2)
529 this%rel_x(:, is) = xx
541 class(
space_t),
intent(in) :: space
542 real(real64),
intent(in) :: newcenter(:)
544 real(real64) :: xx(space%dim), diff_centers(space%dim), oldcenter(space%dim)
550 oldcenter = this%center
551 this%center = newcenter
553 diff_centers = newcenter - oldcenter
556 xx = this%rel_x(:, ip) - diff_centers
557 this%r(ip) = norm2(xx)
558 this%rel_x(:, ip) = xx
568 class(
space_t),
intent(in) :: space
569 type(
mesh_t),
target,
intent(in) :: mesh
570 real(real64),
intent(in) :: center(1:space%dim)
571 real(real64),
intent(in) :: radius
572 integer,
intent(in) :: root
575 integer :: nparray(1:3)
580 if (root /= mpi_grp%rank)
then
586 if (mpi_grp%size > 1)
then
588 if (root == mpi_grp%rank)
then
590 nparray(2) = this%num_regions
591 if (this%overlap)
then
598 call mpi_grp%bcast(nparray, 2, mpi_integer, root)
600 this%num_regions = nparray(2)
601 this%overlap = (nparray(3) == 1)
603 if (root /= mpi_grp%rank)
then
604 safe_allocate(this%map(1:this%np))
605 safe_allocate(this%rel_x(1:space%dim, 1:this%np))
606 safe_allocate(this%r(1:this%np))
607 safe_allocate(this%regions(1:this%num_regions+1))
610 call mpi_grp%bcast(this%regions(1), this%num_regions+1, mpi_integer, root)
612 if (this%np > 0)
then
613 call mpi_grp%bcast(this%map(1), this%np, mpi_integer, root)
614 call mpi_grp%bcast(this%rel_x(1, 1), this%np*space%dim, mpi_double_precision, root)
615 call mpi_grp%bcast(this%r(1), this%np, mpi_double_precision, root)
627 real(real64),
intent(in) :: radius
628 real(real64),
intent(in) :: center(:)
629 real(real64),
intent(in) :: dx
632 if (
allocated(this%center))
then
635 if (radius <= this%radius+dx*1e-6_real64 .and. all(abs(this%center - center) < 0.25*dx))
then
648 if (this%np /= -1)
then
651 safe_deallocate_a(this%center)
652 safe_deallocate_a(this%map)
653 safe_deallocate_a(this%rel_x)
654 safe_deallocate_a(this%r)
655 safe_deallocate_a(this%regions)
669 integer,
intent(out) :: map_inv(:)
675 map_inv(1:this%mesh%np_part) = 0
677 map_inv(this%map(is)) = is
687 class(
space_t),
intent(in) :: space
689 integer :: ii, jj, dd
694 if (.not. space%is_periodic())
then
696 distance = sum((sm1%center - sm2%center)**2)
697 overlap =
distance <= (1.5_real64*(sm1%radius + sm2%radius))**2
700 if (.not. overlap)
return
708 do while(ii <= sm1%np .and. jj <= sm2%np)
709 dd = sm1%map(ii) - sm2%map(jj)
712 else if (dd > 0)
then
720 if (sm1%mesh%parallel_in_domains)
then
721 call sm1%mesh%mpi_grp%allreduce_inplace(overlap, 1, mpi_logical, mpi_lor)
729 class(
space_t),
intent(in) :: space
731 integer,
allocatable :: part_np(:)
732 integer :: ipart, ind, ip
736 if (.not. this%mesh%parallel_in_domains)
then
737 this%np_global = this%np
742 safe_allocate(part_np(this%mesh%pv%npart))
744 part_np(this%mesh%pv%partno) = this%np
746 call this%mesh%allreduce(part_np)
747 this%np_global = sum(part_np)
749 safe_allocate(this%rel_x_global(1:space%dim, 1:this%np_global))
750 safe_allocate(this%part_v(1:this%np_global))
751 safe_allocate(this%global2local(1:this%np_global))
752 this%rel_x_global(1:space%dim, 1:this%np_global) =
m_zero
753 this%part_v(1:this%np_global) = 0
754 this%global2local(1:this%np_global) = 0
757 do ipart = 1, this%mesh%pv%npart
758 if (ipart == this%mesh%pv%partno)
then
760 this%rel_x_global(:, ind + ip) = this%rel_x(:, ip)
761 this%part_v(ind + ip) = this%mesh%pv%partno
762 this%global2local(ind + ip) = ip
765 ind = ind + part_np(ipart)
768 call this%mesh%allreduce(this%rel_x_global)
769 call this%mesh%allreduce(this%part_v)
770 call this%mesh%allreduce(this%global2local)
772 safe_deallocate_a(part_np)
783 safe_deallocate_a(this%rel_x_global)
785 safe_deallocate_a(this%part_v)
786 safe_deallocate_a(this%global2local)
795 complex(real64),
intent(in) :: sphi(:)
796 complex(real64),
intent(inout) :: phi(:)
797 complex(real64),
optional,
intent(in) :: factor
801 push_sub(zzdsubmesh_add_to_mesh)
803 if (
present(factor))
then
807 phi(this%map(ip)) = phi(this%map(ip)) + factor*sphi(ip)
809 if (this%np.ge.4)
then
810 do ip = m+1, this%np, 4
811 phi(this%map(ip)) = phi(this%map(ip)) + factor*sphi(ip)
812 phi(this%map(ip+1)) = phi(this%map(ip+1)) + factor*sphi(ip+1)
813 phi(this%map(ip+2)) = phi(this%map(ip+2)) + factor*sphi(ip+2)
814 phi(this%map(ip+3)) = phi(this%map(ip+3)) + factor*sphi(ip+3)
820 phi(this%map(ip)) = phi(this%map(ip)) + sphi(ip)
822 if (this%np.ge.4)
then
823 do ip = m+1, this%np, 4
824 phi(this%map(ip)) = phi(this%map(ip)) + sphi(ip)
825 phi(this%map(ip+1)) = phi(this%map(ip+1)) + sphi(ip+1)
826 phi(this%map(ip+2)) = phi(this%map(ip+2)) + sphi(ip+2)
827 phi(this%map(ip+3)) = phi(this%map(ip+3)) + sphi(ip+3)
832 pop_sub(zzdsubmesh_add_to_mesh)
838 complex(real64),
intent(in) :: sphi(:)
839 complex(real64),
intent(in) :: phi(:)
840 logical,
optional,
intent(in) :: reduce
848 if (this%mesh%use_curvilinear)
then
850 dotp = dotp + this%mesh%vol_pp(this%map(is))*phi(this%map(is))*conjg(sphi(is))
855 dotp = dotp + phi(this%map(ip))*conjg(sphi(ip))
857 if (this%np.ge.4)
then
858 do ip = m+1, this%np, 4
859 dotp = dotp + phi(this%map(ip))*conjg(sphi(ip)) &
860 + phi(this%map(ip+1))*conjg(sphi(ip+1)) &
861 + phi(this%map(ip+2))*conjg(sphi(ip+2)) &
862 + phi(this%map(ip+3))*conjg(sphi(ip+3))
865 dotp = dotp*this%mesh%vol_pp(1)
870 call this%mesh%allreduce(dotp)
880 type(
submesh_t),
target,
intent(in) :: sm
881 class(
space_t),
intent(in) :: space
882 integer,
intent(out) :: db(1:space%dim)
885 real(real64) :: chi(space%dim)
886 integer :: db_red(1:space%dim)
893 chi = sm%mesh%coord_system%from_cartesian(sm%rel_x(:, ip))
894 do idir = 1, space%dim
895 db(idir) = max(db(idir), nint(abs(chi(idir))/sm%mesh%spacing(idir) +
m_half))
899 if(sm%mesh%parallel_in_domains)
then
900 call sm%mesh%mpi_grp%allreduce(db(1), db_red(1), space%dim, mpi_integer, mpi_max)
901 db(1:space%dim) = db_red(1:space%dim)
911 type(
submesh_t),
target,
intent(inout) :: sm
912 class(
space_t),
intent(in) :: space
916 real(real64) :: chi(space%dim), shift(space%dim)
920 sm%cube_map%nmap = sm%np
922 safe_allocate(sm%cube_map%map(1:space%dim, 1:sm%cube_map%nmap))
926 chi = sm%mesh%coord_system%from_cartesian(sm%center)
927 do idir = 1, space%dim
928 shift(idir) = nint(chi(idir)/sm%mesh%spacing(idir))*sm%mesh%spacing(idir)
930 shift = sm%mesh%coord_system%to_cartesian(shift)
931 shift = shift - sm%center
933 do ip = 1, sm%cube_map%nmap
934 chi = sm%mesh%coord_system%from_cartesian(sm%rel_x(:,ip) - shift)
935 do idir = 1, space%dim
936 sm%cube_map%map(idir, ip) = nint(chi(idir)/sm%mesh%spacing(idir))
942 call accel_write_buffer(sm%cube_map%map_buffer, sm%cube_map%nmap*space%dim, sm%cube_map%map)
967 class(
batch_t),
intent(in) :: ss
968 class(
batch_t),
intent(inout) :: mm
970 integer :: ist, idim, jdim, is
974 assert(.not. mm%is_packed())
977 assert(ss%nst_linear == mm%nst_linear)
978 assert(ss%status() == mm%status())
979 assert(ss%dim == mm%dim)
981 assert(mm%nst == ss%nst)
986 jdim = min(idim, ss%dim)
989 mm%zff(this%map(is), idim, ist) = &
990 mm%zff(this%map(is), idim, ist) + ss%dff(is, jdim, ist)
1003#include "submesh_inc.F90"
1006#include "complex.F90"
1007#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__
subroutine, public accel_release_buffer(this)
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_half
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 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, public submesh_end_global(this)
subroutine, public zsubmesh_copy_from_mesh_batch(this, psib, spsi)
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)
subroutine, public submesh_shift_center(this, space, newcenter)
subroutine, public dsubmesh_copy_from_mesh_batch(this, psib, spsi)
subroutine, public submesh_init_box(this, space, mesh, box, center)
This subroutine creates a submesh which has the same box of the one that the user passes.
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)
subroutine, public submesh_build_global(this, space)
subroutine, public submesh_broadcast(this, space, mesh, center, radius, root, mpi_grp)
subroutine, public submesh_get_inv(this, map_inv)
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), public type_float
type(type_t), public type_cmplx
type(type_t), public type_integer
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)