29 use,
intrinsic :: iso_fortran_env
81 real(real64),
allocatable :: center(:)
82 real(real64) :: radius =
m_zero
83 class(box_t),
pointer :: box => null()
85 integer,
allocatable :: map(:)
86 integer :: num_regions
87 integer,
allocatable :: regions(:)
88 type(accel_mem_t) :: buff_map
89 real(real64),
allocatable :: rel_x(:,:)
90 real(real64),
allocatable :: r(:)
91 type(mesh_t),
pointer :: mesh => null()
94 integer :: np_global = -1
95 real(real64),
allocatable :: rel_x_global(:,:)
96 integer,
allocatable :: part_v(:)
97 integer,
allocatable :: global2local(:)
99 type(mesh_cube_map_t) :: cube_map
116 recursive real(real64) function f_n(dims)
result(fn)
121 else if (dims == 1)
then
130 subroutine submesh_init(this, space, mesh, latt, center, rc)
131 type(submesh_t),
intent(inout) :: this
132 class(space_t),
intent(in) :: space
133 class(mesh_t),
target,
intent(in) :: mesh
134 type(lattice_vectors_t),
intent(in) :: latt
135 real(real64),
intent(in) :: center(1:space%dim)
136 real(real64),
intent(in) :: rc
138 real(real64) :: r2, rc2, xx(space%dim), rc_norm_n
139 real(real64),
allocatable :: center_copies(:,:), xtmp(:, :), rtmp(:)
140 integer :: icell, is, ip, ix, iy, iz
141 integer(int64) :: max_elements_count
142 type(lattice_iterator_t) :: latt_iter
143 integer,
allocatable :: map_inv(:), map_temp(:)
144 integer :: nmax(3), nmin(3)
145 real(real64),
parameter :: tol = 1e-13_real64
151 assert(space%dim <= 3)
155 safe_allocate(this%center(1:space%dim))
156 this%center(:) = center(:)
164 if (.not. space%is_periodic())
then
167 safe_allocate(map_inv(0:this%mesh%np))
168 map_inv(0:this%mesh%np) = 0
174 nmin(1:space%dim) = int((center(1:space%dim) - abs(rc))/mesh%spacing(1:space%dim)) - 1
175 nmax(1:space%dim) = int((center(1:space%dim) + abs(rc))/mesh%spacing(1:space%dim)) + 1
179 nmin(1:space%dim) = max(mesh%idx%nr(1, 1:space%dim), nmin(1:space%dim))
180 nmax(1:space%dim) = min(mesh%idx%nr(2, 1:space%dim), nmax(1:space%dim))
184 do iz = nmin(3), nmax(3)
185 do iy = nmin(2), nmax(2)
186 do ix = nmin(1), nmax(1)
188 if (ip == 0 .or. ip > mesh%np) cycle
189 r2 = sum((mesh%x(:, ip) - center)**2)
201 safe_allocate(this%map(1:this%np))
202 safe_allocate(xtmp(1:space%dim, 1:this%np))
203 safe_allocate(rtmp(1:this%np))
206 do iz = nmin(3), nmax(3)
207 do iy = nmin(2), nmax(2)
208 do ix = nmin(1), nmax(1)
210 if (ip == 0 .or. ip > mesh%np) cycle
214 xtmp(:, is) = mesh%x(:, ip) - center
215 rtmp(is) = norm2(xtmp(:,is))
220 safe_deallocate_a(map_inv)
233 latt_iter =
lattice_iterator_t(latt, rc, center=latt%cart_to_red(center) - mesh%red_min(space))
236 safe_allocate(center_copies(1:space%dim, 1:latt_iter%n_cells))
237 do icell = 1, latt_iter%n_cells
238 center_copies(:, icell) = center + latt_iter%get(icell)
243 rc_norm_n = product(ceiling(rc / mesh%spacing(1:space%dim), int64) +
m_one)
244 if (mesh%use_curvilinear) rc_norm_n = rc_norm_n / mesh%coord_system%min_mesh_scaling_product
245 max_elements_count = 3**space%dim * int(
m_pi**
floor(0.5 * space%dim) * rc_norm_n *
f_n(space%dim), int64)
248 safe_allocate(map_temp(1:max_elements_count))
249 safe_allocate(xtmp(1:space%dim, 1:max_elements_count))
250 safe_allocate(rtmp(1:max_elements_count))
254 do icell = 1, latt_iter%n_cells
255 xx = mesh%x(:,ip) - center_copies(:, icell)
256 if(any(abs(xx)>rc+tol)) cycle
266 assert(is < huge(is))
269 safe_allocate(this%map(1:this%np))
270 this%map(1:this%np) = map_temp(1:this%np)
273 safe_deallocate_a(map_temp)
274 safe_deallocate_a(center_copies)
281 safe_deallocate_a(xtmp)
282 safe_deallocate_a(rtmp)
289 class(
space_t),
intent(in) :: space
290 real(real64),
intent(in) :: xtmp(:, :), rtmp(:)
292 integer :: ip, i_region, offset
293 integer,
allocatable :: order(:), order_new(:)
294 integer,
allocatable :: map_new(:)
295 integer,
allocatable :: np_region(:), tmp_array(:)
302 safe_allocate(order(1:this%np))
303 safe_allocate(this%rel_x(1:space%dim, 1:this%np))
304 safe_allocate(this%r(1:this%np))
311 call sort(this%map, order)
314 this%overlap = .false.
315 do ip = 1, this%np - 1
316 if (this%map(ip) == this%map(ip + 1))
then
318 this%overlap = .
true.
326 if(this%overlap)
then
330 safe_allocate(tmp_array(1:this%np))
331 safe_allocate(order_new(1:this%np))
332 safe_allocate(np_region(1:this%np))
333 safe_allocate(map_new( 1:this%np))
340 if (this%map(ip) == this%map(ip - 1))
then
341 i_region = i_region + 1
342 if (i_region > this%num_regions)
then
343 this%num_regions = i_region
344 np_region(i_region) = 0
349 tmp_array(ip) = i_region
350 np_region(i_region) = np_region(i_region) + 1
353 assert( .not.
allocated(this%regions))
356 safe_allocate(this%regions(1:this%num_regions+1))
360 if(this%num_regions > 1)
then
361 do i_region = 1, this%num_regions
362 this%regions(i_region + 1) = this%regions(i_region) + np_region(i_region)
365 this%regions(2) = this%np + 1
368 np_region(1:this%np) = 0
369 order_new(1:this%np) = -1
370 map_new(1:this%np) = -1
375 i_region = tmp_array(ip)
376 np_region(i_region) = np_region(i_region) + 1
377 offset = this%regions(i_region) - 1
378 map_new( offset + np_region(i_region) ) = this%map(ip)
379 order_new( offset + np_region(i_region) ) = order(ip)
382 order(1:this%np) = order_new(1:this%np)
383 this%map(1:this%np) = map_new(1:this%np)
385 safe_deallocate_a(tmp_array)
386 safe_deallocate_a(order_new)
387 safe_deallocate_a(np_region)
388 safe_deallocate_a(map_new)
393 safe_allocate(this%regions(1:2))
395 this%regions(2) = this%np + 1
400 this%rel_x(:, ip) = xtmp(:, order(ip))
401 this%r(ip) = rtmp(order(ip))
404 safe_deallocate_a(order)
415 class(
space_t),
intent(in) :: space
416 class(
mesh_t),
target,
intent(in) :: mesh
419 real(real64),
optional,
intent(in) :: shift(:)
423 real(real64) :: xx(space%dim), diff_centers(space%dim)
430 safe_allocate(this%center(1:space%dim))
431 this%center(:) = sm1%center(:)
432 this%radius = sm1%radius
436 this%overlap = sm1%overlap .or. sm2%overlap
438 diff_centers = sm1%center - sm2%center
439 if (
present(shift)) diff_centers = diff_centers - shift
446 xx = sm2%rel_x(:, ip) - diff_centers
448 if (sum(xx**2) > sm1%radius**2) is = is + 1
453 safe_allocate(this%map(1:this%np))
454 safe_allocate(this%rel_x(1:space%dim, 1:this%np))
455 safe_allocate(this%r(1:this%np))
456 this%map(1:sm1%np) = sm1%map(1:sm1%np)
457 this%rel_x(:, 1:sm1%np) = sm1%rel_x(:, 1:sm1%np)
458 this%r(1:sm1%np) = sm1%r(1:sm1%np)
463 xx = sm2%rel_x(:, ip) - diff_centers
465 if (r2 > sm1%radius**2)
then
467 this%map(is) = sm2%map(ip)
468 this%r(is) =
sqrt(r2)
469 this%rel_x(:, is) = xx
481 class(
space_t),
intent(in) :: space
482 real(real64),
intent(in) :: newcenter(:)
484 real(real64) :: xx(space%dim), diff_centers(space%dim), oldcenter(space%dim)
490 oldcenter = this%center
491 this%center(:) = newcenter(:)
493 diff_centers = newcenter - oldcenter
496 xx = this%rel_x(:, ip) - diff_centers
497 this%r(ip) = norm2(xx)
498 this%rel_x(:, ip) = xx
509 type(
mesh_t),
target,
intent(in) :: mesh
510 real(real64),
intent(in) :: center(1:space%dim)
511 real(real64),
intent(in) :: radius
512 integer,
intent(in) :: root
515 integer :: nparray(1:3)
520 if (root /= mpi_grp%rank)
then
522 safe_allocate(this%center(1:space%dim))
523 this%center(:) = center(:)
527 if (mpi_grp%size > 1)
then
529 if (root == mpi_grp%rank)
then
531 nparray(2) = this%num_regions
532 if (this%overlap)
then
539 call mpi_grp%bcast(nparray, 3, mpi_integer, root)
541 this%num_regions = nparray(2)
542 this%overlap = (nparray(3) == 1)
544 if (root /= mpi_grp%rank)
then
545 safe_allocate(this%map(1:this%np))
546 safe_allocate(this%rel_x(1:space%dim, 1:this%np))
547 safe_allocate(this%r(1:this%np))
548 safe_allocate(this%regions(1:this%num_regions+1))
551 call mpi_grp%bcast(this%regions(1), this%num_regions+1, mpi_integer, root)
553 if (this%np > 0)
then
554 call mpi_grp%bcast(this%map(1), this%np, mpi_integer, root)
555 call mpi_grp%bcast(this%rel_x(1, 1), this%np*space%dim, mpi_double_precision, root)
556 call mpi_grp%bcast(this%r(1), this%np, mpi_double_precision, root)
568 real(real64),
intent(in) :: radius
569 real(real64),
intent(in) :: center(:)
570 real(real64),
intent(in) :: dx
573 if (
allocated(this%center))
then
576 if (radius <= this%radius+dx*1e-6_real64 .and. all(abs(this%center - center) < 0.25*dx))
then
591 if (this%np /= -1)
then
593 safe_deallocate_a(this%center)
594 safe_deallocate_a(this%map)
595 safe_deallocate_a(this%rel_x)
596 safe_deallocate_a(this%r)
597 safe_deallocate_a(this%regions)
612 class(
space_t),
intent(in) :: space
614 integer :: ii, jj, dd
619 if (.not. space%is_periodic())
then
621 distance = sum((sm1%center - sm2%center)**2)
622 overlap =
distance <= (1.5_real64*(sm1%radius + sm2%radius))**2
625 if (.not. overlap)
return
633 do while(ii <= sm1%np .and. jj <= sm2%np)
634 dd = sm1%map(ii) - sm2%map(jj)
637 else if (dd > 0)
then
645 if (sm1%mesh%parallel_in_domains)
then
646 call sm1%mesh%mpi_grp%allreduce_inplace(overlap, 1, mpi_logical, mpi_lor)
654 class(
space_t),
intent(in) :: space
656 integer,
allocatable :: part_np(:)
657 integer :: ipart, ind, ip
661 if (.not. this%mesh%parallel_in_domains)
then
662 this%np_global = this%np
667 safe_allocate(part_np(this%mesh%pv%npart))
669 part_np(this%mesh%pv%partno) = this%np
671 call this%mesh%allreduce(part_np)
672 this%np_global = sum(part_np)
674 safe_allocate(this%rel_x_global(1:space%dim, 1:this%np_global))
675 safe_allocate(this%part_v(1:this%np_global))
676 safe_allocate(this%global2local(1:this%np_global))
677 this%rel_x_global(1:space%dim, 1:this%np_global) =
m_zero
678 this%part_v(1:this%np_global) = 0
679 this%global2local(1:this%np_global) = 0
682 do ipart = 1, this%mesh%pv%npart
683 if (ipart == this%mesh%pv%partno)
then
685 this%rel_x_global(:, ind + ip) = this%rel_x(:, ip)
686 this%part_v(ind + ip) = this%mesh%pv%partno
687 this%global2local(ind + ip) = ip
690 ind = ind + part_np(ipart)
693 call this%mesh%allreduce(this%rel_x_global)
694 call this%mesh%allreduce(this%part_v)
695 call this%mesh%allreduce(this%global2local)
697 safe_deallocate_a(part_np)
708 safe_deallocate_a(this%rel_x_global)
710 safe_deallocate_a(this%part_v)
711 safe_deallocate_a(this%global2local)
720 complex(real64),
intent(in) :: sphi(:)
721 complex(real64),
intent(inout) :: phi(:)
722 complex(real64),
optional,
intent(in) :: factor
728 if (
present(factor))
then
732 phi(this%map(ip)) = phi(this%map(ip)) + factor*sphi(ip)
734 if (this%np.ge.4)
then
735 do ip = m+1, this%np, 4
736 phi(this%map(ip)) = phi(this%map(ip)) + factor*sphi(ip)
737 phi(this%map(ip+1)) = phi(this%map(ip+1)) + factor*sphi(ip+1)
738 phi(this%map(ip+2)) = phi(this%map(ip+2)) + factor*sphi(ip+2)
739 phi(this%map(ip+3)) = phi(this%map(ip+3)) + factor*sphi(ip+3)
745 phi(this%map(ip)) = phi(this%map(ip)) + sphi(ip)
747 if (this%np.ge.4)
then
748 do ip = m+1, this%np, 4
749 phi(this%map(ip)) = phi(this%map(ip)) + sphi(ip)
750 phi(this%map(ip+1)) = phi(this%map(ip+1)) + sphi(ip+1)
751 phi(this%map(ip+2)) = phi(this%map(ip+2)) + sphi(ip+2)
752 phi(this%map(ip+3)) = phi(this%map(ip+3)) + sphi(ip+3)
763 complex(real64),
intent(in) :: sphi(:)
764 complex(real64),
intent(in) :: phi(:)
765 logical,
optional,
intent(in) :: reduce
773 if (this%mesh%use_curvilinear)
then
775 dotp = dotp + this%mesh%vol_pp(this%map(is))*phi(this%map(is))*conjg(sphi(is))
780 dotp = dotp + phi(this%map(ip))*conjg(sphi(ip))
782 if (this%np.ge.4)
then
783 do ip = m+1, this%np, 4
784 dotp = dotp + phi(this%map(ip))*conjg(sphi(ip)) &
785 + phi(this%map(ip+1))*conjg(sphi(ip+1)) &
786 + phi(this%map(ip+2))*conjg(sphi(ip+2)) &
787 + phi(this%map(ip+3))*conjg(sphi(ip+3))
790 dotp = dotp*this%mesh%vol_pp(1)
795 call this%mesh%allreduce(dotp)
805 type(
submesh_t),
target,
intent(in) :: sm
806 class(
space_t),
intent(in) :: space
807 integer,
intent(out) :: db(1:space%dim)
810 real(real64) :: chi(space%dim), max_chi(space%dim)
811 integer :: db_red(1:space%dim)
812 real(real64),
parameter :: tol=1.0e-10_real64
818 chi = sm%mesh%coord_system%from_cartesian(sm%rel_x(:, ip))
819 do idir = 1, space%dim
820 max_chi(idir) = max(max_chi(idir), abs(chi(idir))/sm%mesh%spacing(idir))
824 do idir = 1, space%dim
825 db(idir) = nint(max_chi(idir)-tol)
828 if(sm%mesh%parallel_in_domains)
then
829 call sm%mesh%mpi_grp%allreduce(db(1), db_red(1), space%dim, mpi_integer, mpi_max)
830 db(1:space%dim) = db_red(1:space%dim)
840 type(
submesh_t),
target,
intent(inout) :: sm
841 class(
space_t),
intent(in) :: space
845 real(real64) :: chi(space%dim), shift(space%dim)
849 sm%cube_map%nmap = sm%np
851 safe_allocate(sm%cube_map%map(1:space%dim, 1:sm%cube_map%nmap))
855 chi = sm%mesh%coord_system%from_cartesian(sm%center)
856 do idir = 1, space%dim
857 shift(idir) = nint(chi(idir)/sm%mesh%spacing(idir))*sm%mesh%spacing(idir)
859 shift = sm%mesh%coord_system%to_cartesian(shift)
860 shift = shift - sm%center
862 do ip = 1, sm%cube_map%nmap
863 chi = sm%mesh%coord_system%from_cartesian(sm%rel_x(:,ip) - shift)
864 do idir = 1, space%dim
865 sm%cube_map%map(idir, ip) = nint(chi(idir)/sm%mesh%spacing(idir))
871 call accel_write_buffer(sm%cube_map%map_buffer, space%dim, sm%cube_map%nmap, sm%cube_map%map)
896 class(
batch_t),
intent(in) :: ss
897 class(
batch_t),
intent(inout) :: mm
899 integer :: ist, idim, jdim, is
903 assert(.not. mm%is_packed())
906 assert(ss%nst_linear == mm%nst_linear)
907 assert(ss%status() == mm%status())
908 assert(ss%dim == mm%dim)
910 assert(mm%nst == ss%nst)
915 jdim = min(idim, ss%dim)
918 mm%zff(this%map(is), idim, ist) = &
919 mm%zff(this%map(is), idim, ist) + ss%dff(is, jdim, ist)
932#include "submesh_inc.F90"
935#include "complex.F90"
936#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 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(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)
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 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)