95 class(box_t),
pointer :: box
96 class(coordinate_system_t),
pointer :: coord_system
98 logical :: use_curvilinear
100 real(real64),
allocatable :: spacing(:)
107 integer(int64) :: np_global
108 integer(int64) :: np_part_global
109 logical :: parallel_in_domains
110 type(mpi_grp_t) :: mpi_grp
111 type(par_vec_t) :: pv
112 type(partition_t) :: partition
114 real(real64),
allocatable :: x(:,:)
115 real(real64) :: volume_element
116 real(real64),
allocatable :: vol_pp(:)
118 logical :: masked_periodic_boundaries
119 character(len=256) :: periodic_boundary_mask
125 procedure :: dmesh_allreduce_0, zmesh_allreduce_0, imesh_allreduce_0, lmesh_allreduce_0
126 procedure :: dmesh_allreduce_1, zmesh_allreduce_1, imesh_allreduce_1, lmesh_allreduce_1
127 procedure :: dmesh_allreduce_2, zmesh_allreduce_2, imesh_allreduce_2, lmesh_allreduce_2
128 procedure :: dmesh_allreduce_3, zmesh_allreduce_3, imesh_allreduce_3, lmesh_allreduce_3
129 procedure :: dmesh_allreduce_4, zmesh_allreduce_4, imesh_allreduce_4, lmesh_allreduce_4
130 procedure :: dmesh_allreduce_5, zmesh_allreduce_5, imesh_allreduce_5, lmesh_allreduce_5
131 generic :: allreduce => dmesh_allreduce_0, zmesh_allreduce_0, imesh_allreduce_0, lmesh_allreduce_0
132 generic :: allreduce => dmesh_allreduce_1, zmesh_allreduce_1, imesh_allreduce_1, lmesh_allreduce_1
133 generic :: allreduce => dmesh_allreduce_2, zmesh_allreduce_2, imesh_allreduce_2, lmesh_allreduce_2
134 generic :: allreduce => dmesh_allreduce_3, zmesh_allreduce_3, imesh_allreduce_3, lmesh_allreduce_3
135 generic :: allreduce => dmesh_allreduce_4, zmesh_allreduce_4, imesh_allreduce_4, lmesh_allreduce_4
136 generic :: allreduce => dmesh_allreduce_5, zmesh_allreduce_5, imesh_allreduce_5, lmesh_allreduce_5
153 real(real64) :: u(3), v(3)
154 real(real64) :: origin(3)
155 real(real64) :: spacing
156 integer :: nu, mu, nv, mv
166 real(real64) :: origin(2)
167 real(real64) :: spacing
174 class(mesh_t),
intent(inout) :: this
178 call this%set_time_dependent(.false.)
186 class(space_t),
intent(in) :: space
187 type(mesh_t),
intent(in) :: mesh
188 real(real64),
intent(in) :: alpha
189 integer,
intent(out) :: db(:)
198 do idir = 1, space%periodic_dim
199 db(idir) = mesh%idx%ll(idir)
201 do idir = space%periodic_dim + 1, space%dim
202 db(idir) = nint(alpha * (mesh%idx%ll(idir) - 1)) + 1
212 integer,
optional,
intent(in) :: iunit
213 type(
namespace_t),
optional,
intent(in) :: namespace
216 real(real64) :: cutoff
221 do ii = 1, this%box%dim
229 write(
message(2),
'(a, i10)')
' # inner mesh = ', this%np_global
230 write(
message(3),
'(a, i10)')
' # total mesh = ', this%np_part_global
242 pure subroutine mesh_r(mesh, ip, rr, origin, coords)
243 class(mesh_t),
intent(in) :: mesh
244 integer,
intent(in) :: ip
245 real(real64),
intent(out) :: rr
246 real(real64),
intent(in),
optional :: origin(:)
247 real(real64),
intent(out),
optional :: coords(:)
249 real(real64) :: xx(1:mesh%box%dim)
252 if (
present(origin)) xx = xx - origin
255 if (
present(coords))
then
263 class(
mesh_t),
intent(in) :: mesh
264 integer(int64),
intent(in) :: ipg
265 real(real64),
intent(out) :: rr
266 real(real64),
intent(in),
optional :: origin(:)
267 real(real64),
intent(out),
optional :: coords(:)
269 real(real64) :: xx(1:mesh%box%dim)
272 if (
present(origin)) xx = xx - origin
275 if (
present(coords))
then
287 class(
mesh_t),
intent(in) :: mesh
288 real(real64),
intent(in) :: pos(:)
289 real(real64),
intent(out) :: dmin
290 integer,
intent(out) :: rankmin
301 dd = sum((pos - mesh%x(ip, :))**2)
302 if ((dd < dmin) .or. (ip == 1))
then
309 call mesh%mpi_grp%bcast(imin, 1, mpi_integer, rankmin)
317 class(
mesh_t),
intent(in ) :: mesh
318 real(real64),
intent(inout) ::
values(:, :)
320 integer :: i, ip, ndim
322 real(real64) :: dummy
326 if (mesh%parallel_in_domains)
then
331 if (mesh%mpi_grp%rank == process)
values(:, i) = mesh%x(ip, :)
332 call mesh%mpi_grp%bcast(
values(:, i), ndim, mpi_double_precision, process)
337 values(:, i) = mesh%x(ip, :)
351 class(
mesh_t),
intent(in) :: mesh
354 gmax =
m_pi / (maxval(mesh%spacing))
361 type(
mesh_t),
intent(in) :: mesh
362 character(len=*),
intent(in) :: dir
363 character(len=*),
intent(in) :: filename
364 type(mpi_grp_t),
intent(in) :: mpi_grp
365 type(namespace_t),
intent(in) :: namespace
366 integer,
intent(out) :: ierr
374 iunit = io_open(trim(dir)//
"/"//trim(filename), namespace, action=
'write', &
375 die=.false., grp=mpi_grp)
377 message(1) =
"Unable to open file '"//trim(dir)//
"/"//trim(filename)//
"'."
378 call messages_warning(1, namespace=namespace)
381 if (mpi_grp_is_root(mpi_grp))
then
382 write(iunit,
'(a20,i21)')
'np_part_global= ', mesh%np_part_global
383 write(iunit,
'(a20,i21)')
'np_global= ', mesh%np_global
384 write(iunit,
'(a20,i21)')
'algorithm= ', 1
385 write(iunit,
'(a20,i21)')
'checksum= ', mesh%idx%checksum
386 write(iunit,
'(a20,i21)')
'bits= ', mesh%idx%bits
387 write(iunit,
'(a20,i21)')
'dim= ', mesh%idx%dim
388 write(iunit,
'(a20,i21)')
'type= ', mesh%idx%type
389 do ii = 1, mesh%idx%dim
390 write(iunit,
'(a7,i2,a11,i21)')
'offset(',ii,
')= ', mesh%idx%offset(ii)
392 do ii = 1, mesh%idx%dim
393 write(iunit,
'(a7,i2,a11,i21)')
'nn(',ii,
')= ', mesh%idx%nr(2, ii) - mesh%idx%nr(1, ii) + 1
396 call io_close(iunit, grp=mpi_grp)
409 read_np_part, read_np, bits, type, offset, nn, ierr)
410 type(
mesh_t),
intent(in) :: mesh
411 character(len=*),
intent(in) :: dir
412 character(len=*),
intent(in) :: filename
413 type(mpi_grp_t),
intent(in) :: mpi_grp
414 type(namespace_t),
intent(in) :: namespace
415 integer(int64),
intent(out) :: read_np_part
416 integer(int64),
intent(out) :: read_np
417 integer,
intent(out) :: bits
418 integer,
intent(out) :: type
419 integer,
intent(out) :: offset(1:mesh%idx%dim)
420 integer,
intent(out) :: nn(1:mesh%idx%dim)
421 integer,
intent(out) :: ierr
423 character(len=20) :: str
424 character(len=100) :: lines(7)
425 integer :: iunit, algorithm, dim, err, ii
426 integer(int64) :: checksum
432 read_np_part = 0_int64
435 iunit = io_open(trim(dir)//
"/"//trim(filename), namespace, action=
'read', &
436 status=
'old', die=.false., grp=mpi_grp)
439 message(1) =
"Unable to open file '"//trim(dir)//
"/"//trim(filename)//
"'."
440 call messages_warning(1, namespace=namespace)
442 call iopar_read(mpi_grp, iunit, lines, 7, err)
446 read(lines(1),
'(a20,i21)') str, read_np_part
447 read(lines(2),
'(a20,i21)') str, read_np
448 read(lines(3),
'(a20,i21)') str, algorithm
449 read(lines(4),
'(a20,i21)') str, checksum
450 read(lines(5),
'(a20,i21)') str, bits
451 read(lines(6),
'(a20,i21)') str, dim
452 read(lines(7),
'(a20,i21)') str,
type
454 if (dim /= mesh%idx%dim)
then
458 call iopar_read(mpi_grp, iunit, lines, dim, err)
463 read(lines(ii),
'(a20,i21)') str, offset(ii)
468 call iopar_read(mpi_grp, iunit, lines, dim, err)
473 read(lines(ii),
'(a20,i21)') str, nn(ii)
478 assert(read_np_part >= read_np)
480 if (read_np_part == mesh%np_part_global &
481 .and. read_np == mesh%np_global &
482 .and. algorithm == 1 &
483 .and. checksum == mesh%idx%checksum)
then
489 call io_close(iunit, grp=mpi_grp)
497 type(
mesh_t),
intent(in) :: mesh
498 character(len=*),
intent(in) :: dir
499 character(len=*),
intent(in) :: filename
500 type(namespace_t),
intent(in) :: namespace
501 type(mpi_grp_t),
intent(in) :: mpi_grp
502 logical,
intent(out) :: grid_changed
503 logical,
intent(out) :: grid_reordered
504 integer(int64),
allocatable,
intent(out) :: map(:)
505 integer,
intent(out) :: ierr
507 integer(int64) :: ipg, ipg_new, read_np_part, read_np
509 integer :: bits,
type, offset(mesh%idx%dim), point(mesh%idx%dim), nn(mesh%idx%dim)
510 integer(int64),
allocatable :: read_indices(:)
511 type(index_t) :: idx_old
517 grid_changed = .false.
518 grid_reordered = .false.
522 bits,
type, offset, nn, err)
525 message(1) =
"Unable to read mesh fingerprint from '"//trim(dir)//
"/"//trim(filename)//
"'."
526 call messages_warning(1, namespace=namespace)
528 else if (read_np > 0)
then
529 if (.not.
associated(mesh%box))
then
534 grid_changed = .
true.
539 grid_reordered = (read_np == mesh%np_global)
542 safe_allocate(read_indices(1:read_np_part))
543 call io_binary_read(trim(io_workpath(dir, namespace))//
"/indices.obf", read_np_part, &
547 message(1) =
"Unable to read index map from '"//trim(dir)//
"'."
548 call messages_warning(1, namespace=namespace)
551 call index_init(idx_old, mesh%idx%dim)
554 idx_old%nr(1, :) = -offset
555 idx_old%nr(2, :) = -offset + nn - 1
556 idx_old%offset = offset
557 idx_old%stride(1) = 1
558 do idir = 2, mesh%idx%dim
559 idx_old%stride(idir) = idx_old%stride(idir-1) * nn(idir-1)
562 safe_allocate(map(1:read_np))
565 call index_spatial_to_point(idx_old, mesh%idx%dim, read_indices(ipg), point)
570 if (map(ipg) > mesh%np_global) map(ipg) = 0
572 if (map(ipg) == 0) grid_reordered = .false.
574 call index_end(idx_old)
577 safe_deallocate_a(read_indices)
587 class(
mesh_t),
intent(inout) :: this
592 call lmpi_destroy_shared_memory_window(this%idx%window_grid_to_spatial)
593 call lmpi_destroy_shared_memory_window(this%idx%window_spatial_to_grid)
594 nullify(this%idx%grid_to_spatial_global)
595 nullify(this%idx%spatial_to_grid_global)
597 safe_deallocate_p(this%idx%grid_to_spatial_global)
598 safe_deallocate_p(this%idx%spatial_to_grid_global)
601 safe_deallocate_a(this%x)
602 safe_deallocate_a(this%vol_pp)
604 if (this%parallel_in_domains)
then
605 call par_vec_end(this%pv)
606 call partition_end(this%partition)
609 call index_end(this%idx)
610 safe_deallocate_a(this%spacing)
623 class(
mesh_t),
intent(in) :: mesh
624 class(space_t),
intent(in) :: space
625 integer,
intent(in) :: ip
627 integer :: ix(space%dim), nr(2, space%dim), idim
628 real(real64) :: xx(space%dim), rr, ufn_re, ufn_im
633 nr(1, :) = mesh%idx%nr(1, :) + mesh%idx%enlarge(:)
634 nr(2, :) = mesh%idx%nr(2, :) - mesh%idx%enlarge(:)
636 do idim = 1, space%periodic_dim
637 if (ix(idim) < nr(1, idim)) ix(idim) = ix(idim) + mesh%idx%ll(idim)
638 if (ix(idim) > nr(2, idim)) ix(idim) = ix(idim) - mesh%idx%ll(idim)
644 if (mesh%masked_periodic_boundaries)
then
645 call mesh_r(mesh, ip, rr, coords = xx)
646 call parse_expression(ufn_re, ufn_im, space%dim, xx, rr, m_zero, mesh%periodic_boundary_mask)
653 class(
mesh_t),
intent(in) :: mesh
654 class(space_t),
intent(in) :: space
655 integer(int64),
intent(in) :: ipg_in
657 integer :: ix(space%dim), nr(2, space%dim), idim
658 real(real64) :: xx(space%dim), rr, ufn_re, ufn_im
663 nr(1, :) = mesh%idx%nr(1, :) + mesh%idx%enlarge(:)
664 nr(2, :) = mesh%idx%nr(2, :) - mesh%idx%enlarge(:)
666 do idim = 1, space%periodic_dim
667 if (ix(idim) < nr(1, idim)) ix(idim) = ix(idim) + mesh%idx%ll(idim)
668 if (ix(idim) > nr(2, idim)) ix(idim) = ix(idim) - mesh%idx%ll(idim)
674 if (mesh%masked_periodic_boundaries)
then
676 call parse_expression(ufn_re, ufn_im, space%dim, xx, rr, m_zero, mesh%periodic_boundary_mask)
677 if (int(ufn_re) == 0) ipg = ipg_in
686 use iso_c_binding,
only: c_sizeof, c_long_long
687 class(
mesh_t),
intent(in) :: mesh
690 memory = c_sizeof(c_long_long) * real(mesh%np_part_global, real64) * 2
697 use iso_c_binding,
only: c_sizeof, c_long_long
698 class(
mesh_t),
intent(in) :: mesh
703 memory = memory + real64 * real(mesh%np_part, real64) * mesh%idx%dim
705 memory = memory + c_sizeof(c_long_long) * real(mesh%np_part, real64) * 2
711 class(
mesh_t),
intent(in) :: mesh
712 integer(int64),
intent(in) :: ipg
713 real(real64) :: xx(1:mesh%box%dim)
715 real(real64) :: chi(1:mesh%box%dim)
716 integer :: ix(1:mesh%box%dim)
721 chi = ix * mesh%spacing
722 xx = mesh%coord_system%to_cartesian(chi)
729 type(
mesh_t),
intent(in) :: mesh
731 cb = .not. mesh%use_curvilinear .and. &
732 .not. mesh%parallel_in_domains
739 class(
mesh_t),
intent(in) :: mesh
740 type(symmetries_t),
intent(in) :: symm
741 integer,
intent(in) :: periodic_dim
743 integer :: iop, ip, idim, nops, ix(1:3)
744 real(real64) :: destpoint(1:3), srcpoint(1:3), lsize(1:3), offset(1:3)
745 real(real64),
parameter :: tol_spacing = 1e-12_real64
753 if (mesh%idx%ll(1) == mesh%idx%ll(2) .and. &
754 mesh%idx%ll(2) == mesh%idx%ll(3) .and. &
755 abs(mesh%spacing(1) - mesh%spacing(2)) < tol_spacing .and. &
756 abs(mesh%spacing(2) - mesh%spacing(3)) < tol_spacing)
return
760 message(1) =
"Checking if the real-space grid is symmetric"
761 call messages_info(1)
763 lsize(1:3) = real(mesh%idx%ll(1:3), real64)
764 offset(1:3) = real(mesh%idx%nr(1, 1:3) + mesh%idx%enlarge(1:3), real64)
766 nops = symmetries_number(symm)
773 destpoint(1:3) = real(ix(1:3), real64) - offset(1:3)
775 assert(all(destpoint >= 0))
776 assert(all(destpoint < lsize))
779 destpoint = destpoint - real(int(lsize)/2, real64)
783 destpoint(idim) = destpoint(idim)/lsize(idim)
788 srcpoint = symm_op_apply_red(symm%ops(iop), destpoint)
792 srcpoint(idim) = srcpoint(idim)*lsize(idim)
796 srcpoint = srcpoint + real(int(lsize)/2, real64)
799 do idim = 1, periodic_dim
800 if (nint(srcpoint(idim)) < 0 .or. nint(srcpoint(idim)) >= lsize(idim))
then
801 srcpoint(idim) = modulo(srcpoint(idim)+m_half*symprec, lsize(idim))
804 assert(all(srcpoint >= -symprec))
805 assert(all(srcpoint < lsize))
807 srcpoint(1:3) = srcpoint(1:3) + offset(1:3)
809 if (any(srcpoint-anint(srcpoint)> symprec*m_two))
then
810 message(1) =
"The real-space grid breaks at least one of the symmetries of the system."
811 message(2) =
"Change your spacing or use SymmetrizeDensity=no."
812 call messages_fatal(2)
823 class(
mesh_t),
intent(in) :: mesh
824 integer,
intent(in) :: ix(:)
826 index = index_from_coords(mesh%idx, ix)
832 type(
mesh_t),
intent(in) :: mesh
833 integer(int64),
intent(in) :: ipg
834 integer,
intent(out) :: ix(:)
836 call index_to_coords(mesh%idx, ipg, ix)
842 type(
mesh_t),
intent(in) :: mesh
843 integer,
intent(in) :: ix(:)
845 integer(int64) :: ipg
847 ipg = index_from_coords(mesh%idx, ix)
854 type(
mesh_t),
intent(in) :: mesh
855 integer,
intent(in) :: ip
856 integer,
intent(out) :: ix(:)
858 integer(int64) :: ipg
861 call index_to_coords(mesh%idx, ipg, ix)
866 type(
mesh_t),
intent(in) :: mesh
867 integer,
intent(in) :: ip
869 ipg = par_vec_local2global(mesh%pv, ip)
874 type(
mesh_t),
intent(in) :: mesh
875 integer(int64),
intent(in) :: ipg
877 ip = par_vec_global2local(mesh%pv, ipg)
883 type(
mesh_t),
intent(in) :: mesh
884 real(real64),
intent(inout) :: min_or_max
885 integer,
intent(out) :: rank_min_or_max
886 type(mpi_op),
intent(in) :: op
888 real(real64) :: loc_in(2), loc_out(2)
892 assert(op == mpi_minloc .or. op == mpi_maxloc)
895 if (mesh%parallel_in_domains)
then
896 loc_in(1) = min_or_max
897 loc_in(2) = mesh%mpi_grp%rank
898 call mesh%mpi_grp%allreduce(loc_in, loc_out, 1, mpi_2double_precision, op)
899 min_or_max = loc_out(1)
900 rank_min_or_max = nint(loc_out(2))
909#include "mesh_inc.F90"
912#include "complex.F90"
913#include "mesh_inc.F90"
916#include "integer.F90"
917#include "mesh_inc.F90"
920#include "integer8.F90"
921#include "mesh_inc.F90"
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_pi
some mathematical constants
This module implements a simple hash table for non-negative integer keys and integer values.
This module implements the index, used for the mesh points.
This module defines the meshes, which are used in Octopus.
integer(int64) function, public mesh_periodic_point(mesh, space, ip)
This function returns the point inside the grid corresponding to a boundary point when PBCs are used....
subroutine, public mesh_global_index_to_coords(mesh, ipg, ix)
Given a global point index, this function returns the set of integer coordinates of the point.
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.
subroutine, public mesh_double_box(space, mesh, alpha, db)
finds the dimension of a box doubled in the non-periodic dimensions
integer(int64) function, public mesh_global_index_from_coords(mesh, ix)
This function returns the true global index of the point for a given vector of integer coordinates.
subroutine, public mesh_check_symmetries(mesh, symm, periodic_dim)
subroutine, public mesh_write_info(this, iunit, namespace)
subroutine, public mesh_local_index_to_coords(mesh, ip, ix)
Given a local point index, this function returns the set of integer coordinates of the point.
subroutine, public mesh_discretize_values_to_mesh(mesh, values)
Assign a set of values to their nearest discrete points on the mesh.
integer function, public mesh_nearest_point(mesh, pos, dmin, rankmin)
Returns the index of the point which is nearest to a given vector position pos.
integer(int64) function, public mesh_periodic_point_global(mesh, space, ipg_in)
real(real64) pure function, public mesh_global_memory(mesh)
subroutine, public mesh_read_fingerprint(mesh, dir, filename, mpi_grp, namespace, read_np_part, read_np, bits, type, offset, nn, ierr)
This function reads the fingerprint of a mesh written in filename. If the meshes are equal (same fing...
pure subroutine, public mesh_r(mesh, ip, rr, origin, coords)
return the distance to the origin for a given grid point
subroutine, public mesh_check_dump_compatibility(mesh, dir, filename, namespace, mpi_grp, grid_changed, grid_reordered, map, ierr)
real(real64) function, public mesh_gcutoff(mesh)
mesh_gcutoff returns the "natural" band limitation of the grid mesh, in terms of the maximum G vector...
subroutine, public mesh_minmaxloc(mesh, min_or_max, rank_min_or_max, op)
Given a local min/max this returns the global min/max and the rank where this is located.
integer function, public mesh_global2local(mesh, ipg)
This function returns the local mesh index for a given global index.
recursive subroutine, public mesh_end(this)
logical pure function, public mesh_compact_boundaries(mesh)
real(real64) pure function, public mesh_local_memory(mesh)
integer(int64) function, public mesh_local2global(mesh, ip)
This function returns the global mesh index for a given local index.
real(real64) function, dimension(1:mesh%box%dim), public mesh_x_global(mesh, ipg)
subroutine mesh_r_global(mesh, ipg, rr, origin, coords)
return the distance to the origin for a given grid point
subroutine, public mesh_write_fingerprint(mesh, dir, filename, mpi_grp, namespace, ierr)
subroutine mesh_init(this)
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
This module contains some common usage patterns of MPI routines.
Some general things and nomenclature:
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
character(len=20) pure function, public units_abbrev(this)
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
abstract class for basis sets
This data type defines a line, and a regular grid defined on this line (or rather,...
define a grid on a plane.
Describes mesh distribution to nodes.
real(real64) function values(xx)