94 class(box_t),
pointer :: box
95 class(coordinate_system_t),
pointer :: coord_system
97 logical :: use_curvilinear
99 real(real64),
allocatable :: spacing(:)
106 integer(int64) :: np_global
107 integer(int64) :: np_part_global
108 logical :: parallel_in_domains
109 type(mpi_grp_t) :: mpi_grp
110 type(par_vec_t) :: pv
111 type(partition_t) :: partition
113 real(real64),
allocatable :: x(:,:)
114 real(real64),
allocatable :: chi(:,:)
115 real(real64) :: volume_element
116 real(real64),
allocatable :: vol_pp(:)
117 real(real64),
allocatable :: jacobian_inverse(:,:,:)
119 logical :: masked_periodic_boundaries
120 character(len=256) :: periodic_boundary_mask
126 procedure :: dmesh_allreduce_0, zmesh_allreduce_0, imesh_allreduce_0, lmesh_allreduce_0
127 procedure :: dmesh_allreduce_1, zmesh_allreduce_1, imesh_allreduce_1, lmesh_allreduce_1
128 procedure :: dmesh_allreduce_2, zmesh_allreduce_2, imesh_allreduce_2, lmesh_allreduce_2
129 procedure :: dmesh_allreduce_3, zmesh_allreduce_3, imesh_allreduce_3, lmesh_allreduce_3
130 procedure :: dmesh_allreduce_4, zmesh_allreduce_4, imesh_allreduce_4, lmesh_allreduce_4
131 procedure :: dmesh_allreduce_5, zmesh_allreduce_5, imesh_allreduce_5, lmesh_allreduce_5
132 generic :: allreduce => dmesh_allreduce_0, zmesh_allreduce_0, imesh_allreduce_0, lmesh_allreduce_0
133 generic :: allreduce => dmesh_allreduce_1, zmesh_allreduce_1, imesh_allreduce_1, lmesh_allreduce_1
134 generic :: allreduce => dmesh_allreduce_2, zmesh_allreduce_2, imesh_allreduce_2, lmesh_allreduce_2
135 generic :: allreduce => dmesh_allreduce_3, zmesh_allreduce_3, imesh_allreduce_3, lmesh_allreduce_3
136 generic :: allreduce => dmesh_allreduce_4, zmesh_allreduce_4, imesh_allreduce_4, lmesh_allreduce_4
137 generic :: allreduce => dmesh_allreduce_5, zmesh_allreduce_5, imesh_allreduce_5, lmesh_allreduce_5
154 real(real64) :: u(3), v(3)
155 real(real64) :: origin(3)
156 real(real64) :: spacing
157 integer :: nu, mu, nv, mv
167 real(real64) :: origin(2)
168 real(real64) :: spacing
175 class(mesh_t),
intent(inout) :: this
179 call this%set_time_dependent(.false.)
187 class(space_t),
intent(in) :: space
188 type(mesh_t),
intent(in) :: mesh
189 real(real64),
intent(in) :: alpha
190 integer,
intent(out) :: db(:)
199 do idir = 1, space%periodic_dim
200 db(idir) = mesh%idx%ll(idir)
202 do idir = space%periodic_dim + 1, space%dim
203 db(idir) = nint(alpha * (mesh%idx%ll(idir) - 1)) + 1
213 integer,
optional,
intent(in) :: iunit
217 real(real64) :: cutoff
222 do ii = 1, this%box%dim
230 write(
message(2),
'(a, i10)')
' # inner mesh = ', this%np_global
231 write(
message(3),
'(a, i10)')
' # total mesh = ', this%np_part_global
243 pure subroutine mesh_r(mesh, ip, rr, origin, coords)
244 class(
mesh_t),
intent(in) :: mesh
245 integer,
intent(in) :: ip
246 real(real64),
intent(out) :: rr
247 real(real64),
intent(in),
optional :: origin(:)
248 real(real64),
intent(out),
optional :: coords(:)
250 real(real64) :: xx(1:mesh%box%dim)
253 if (
present(origin)) xx = xx - origin
256 if (
present(coords))
then
265 integer(int64),
intent(in) :: ipg
266 real(real64),
intent(out) :: rr
267 real(real64),
intent(in),
optional :: origin(:)
268 real(real64),
intent(out),
optional :: coords(:)
270 real(real64) :: xx(1:mesh%box%dim)
273 if (
present(origin)) xx = xx - origin
276 if (
present(coords))
then
288 class(
mesh_t),
intent(in) :: mesh
289 real(real64),
intent(in) :: pos(:)
290 real(real64),
intent(out) :: dmin
291 integer,
intent(out) :: rankmin
302 dd = sum((pos - mesh%x(ip, :))**2)
303 if ((dd < dmin) .or. (ip == 1))
then
310 call mesh%mpi_grp%bcast(imin, 1, mpi_integer, rankmin)
318 class(
mesh_t),
intent(in ) :: mesh
319 real(real64),
intent(inout) ::
values(:, :)
321 integer :: i, ip, ndim
323 real(real64) :: dummy
327 if (mesh%parallel_in_domains)
then
332 if (mesh%mpi_grp%rank == process)
values(:, i) = mesh%x(ip, :)
333 call mesh%mpi_grp%bcast(
values(:, i), ndim, mpi_double_precision, process)
352 class(
mesh_t),
intent(in) :: mesh
355 gmax =
m_pi / (maxval(mesh%spacing))
362 type(
mesh_t),
intent(in) :: mesh
363 character(len=*),
intent(in) :: dir
364 character(len=*),
intent(in) :: filename
365 type(mpi_grp_t),
intent(in) :: mpi_grp
366 type(namespace_t),
intent(in) :: namespace
367 integer,
intent(out) :: ierr
375 iunit = io_open(trim(dir)//
"/"//trim(filename), namespace, action=
'write', &
376 die=.false., grp=mpi_grp)
377 if (iunit == -1)
then
378 message(1) =
"Unable to open file '"//trim(dir)//
"/"//trim(filename)//
"'."
379 call messages_warning(1, namespace=namespace)
382 if (mpi_grp%is_root())
then
383 write(iunit,
'(a20,i21)')
'np_part_global= ', mesh%np_part_global
384 write(iunit,
'(a20,i21)')
'np_global= ', mesh%np_global
385 write(iunit,
'(a20,i21)')
'algorithm= ', 1
386 write(iunit,
'(a20,i21)')
'checksum= ', mesh%idx%checksum
387 write(iunit,
'(a20,i21)')
'bits= ', mesh%idx%bits
388 write(iunit,
'(a20,i21)')
'dim= ', mesh%idx%dim
389 write(iunit,
'(a20,i21)')
'type= ', mesh%idx%type
390 do ii = 1, mesh%idx%dim
391 write(iunit,
'(a7,i2,a11,i21)')
'offset(',ii,
')= ', mesh%idx%offset(ii)
393 do ii = 1, mesh%idx%dim
394 write(iunit,
'(a7,i2,a11,i21)')
'nn(',ii,
')= ', mesh%idx%nr(2, ii) - mesh%idx%nr(1, ii) + 1
397 call io_close(iunit, grp=mpi_grp)
410 read_np_part, read_np, bits, type, offset, nn, ierr)
411 type(
mesh_t),
intent(in) :: mesh
412 character(len=*),
intent(in) :: dir
413 character(len=*),
intent(in) :: filename
414 type(mpi_grp_t),
intent(in) :: mpi_grp
415 type(namespace_t),
intent(in) :: namespace
416 integer(int64),
intent(out) :: read_np_part
417 integer(int64),
intent(out) :: read_np
418 integer,
intent(out) :: bits
419 integer,
intent(out) :: type
420 integer,
intent(out) :: offset(1:mesh%idx%dim)
421 integer,
intent(out) :: nn(1:mesh%idx%dim)
422 integer,
intent(out) :: ierr
424 character(len=20) :: str
425 character(len=100) :: lines(7)
426 integer :: iunit, algorithm, dim, err, ii
427 integer(int64) :: checksum
433 read_np_part = 0_int64
436 iunit = io_open(trim(dir)//
"/"//trim(filename), namespace, action=
'read', &
437 status=
'old', die=.false., grp=mpi_grp)
438 if (iunit == -1)
then
440 message(1) =
"Unable to open file '"//trim(dir)//
"/"//trim(filename)//
"'."
441 call messages_warning(1, namespace=namespace)
443 call iopar_read(mpi_grp, iunit, lines, 7, err)
447 read(lines(1),
'(a20,i21)') str, read_np_part
448 read(lines(2),
'(a20,i21)') str, read_np
449 read(lines(3),
'(a20,i21)') str, algorithm
450 read(lines(4),
'(a20,i21)') str, checksum
451 read(lines(5),
'(a20,i21)') str, bits
452 read(lines(6),
'(a20,i21)') str, dim
453 read(lines(7),
'(a20,i21)') str,
type
455 if (dim /= mesh%idx%dim)
then
459 call iopar_read(mpi_grp, iunit, lines, dim, err)
464 read(lines(ii),
'(a20,i21)') str, offset(ii)
469 call iopar_read(mpi_grp, iunit, lines, dim, err)
474 read(lines(ii),
'(a20,i21)') str, nn(ii)
479 assert(read_np_part >= read_np)
481 if (read_np_part == mesh%np_part_global &
482 .and. read_np == mesh%np_global &
483 .and. algorithm == 1 &
484 .and. checksum == mesh%idx%checksum)
then
490 call io_close(iunit, grp=mpi_grp)
498 type(
mesh_t),
intent(in) :: mesh
499 character(len=*),
intent(in) :: dir
500 character(len=*),
intent(in) :: filename
501 type(namespace_t),
intent(in) :: namespace
502 type(mpi_grp_t),
intent(in) :: mpi_grp
503 logical,
intent(out) :: grid_changed
504 logical,
intent(out) :: grid_reordered
505 integer(int64),
allocatable,
intent(out) :: map(:)
506 integer,
intent(out) :: ierr
508 integer(int64) :: ipg, ipg_new, read_np_part, read_np
510 integer :: bits,
type, offset(mesh%idx%dim), point(mesh%idx%dim), nn(mesh%idx%dim)
511 integer(int64),
allocatable :: read_indices(:)
512 type(index_t) :: idx_old
518 grid_changed = .false.
519 grid_reordered = .false.
523 bits,
type, offset, nn, err)
526 message(1) =
"Unable to read mesh fingerprint from '"//trim(dir)//
"/"//trim(filename)//
"'."
527 call messages_warning(1, namespace=namespace)
529 else if (read_np > 0)
then
530 if (.not.
associated(mesh%box))
then
535 grid_changed = .
true.
540 grid_reordered = (read_np == mesh%np_global)
543 safe_allocate(read_indices(1:read_np_part))
544 call io_binary_read(trim(io_workpath(dir, namespace))//
"/indices.obf", read_np_part, &
548 message(1) =
"Unable to read index map from '"//trim(dir)//
"'."
549 call messages_warning(1, namespace=namespace)
552 call index_init(idx_old, mesh%idx%dim)
555 idx_old%nr(1, :) = -offset
556 idx_old%nr(2, :) = -offset + nn - 1
557 idx_old%offset = offset
558 idx_old%stride(1) = 1
559 do idir = 2, mesh%idx%dim
560 idx_old%stride(idir) = idx_old%stride(idir-1) * nn(idir-1)
563 safe_allocate(map(1:read_np))
566 call index_spatial_to_point(idx_old, mesh%idx%dim, read_indices(ipg), point)
571 if (map(ipg) > mesh%np_global) map(ipg) = 0
573 if (map(ipg) == 0) grid_reordered = .false.
575 call index_end(idx_old)
578 safe_deallocate_a(read_indices)
588 class(
mesh_t),
intent(inout) :: this
593 call lmpi_destroy_shared_memory_window(this%idx%window_grid_to_spatial)
594 call lmpi_destroy_shared_memory_window(this%idx%window_spatial_to_grid)
595 nullify(this%idx%grid_to_spatial_global)
596 nullify(this%idx%spatial_to_grid_global)
598 safe_deallocate_p(this%idx%grid_to_spatial_global)
599 safe_deallocate_p(this%idx%spatial_to_grid_global)
602 safe_deallocate_a(this%x)
603 safe_deallocate_a(this%chi)
604 safe_deallocate_a(this%vol_pp)
605 safe_deallocate_a(this%jacobian_inverse)
607 if (this%parallel_in_domains)
then
608 call par_vec_end(this%pv)
609 call partition_end(this%partition)
612 call index_end(this%idx)
613 safe_deallocate_a(this%spacing)
626 class(
mesh_t),
intent(in) :: mesh
627 class(space_t),
intent(in) :: space
628 integer,
intent(in) :: ip
630 integer :: ix(space%dim), nr(2, space%dim), idim
631 real(real64) :: xx(space%dim), rr, ufn_re, ufn_im
636 nr(1, :) = mesh%idx%nr(1, :) + mesh%idx%enlarge(:)
637 nr(2, :) = mesh%idx%nr(2, :) - mesh%idx%enlarge(:)
639 do idim = 1, space%periodic_dim
640 do while (ix(idim) < nr(1, idim))
641 ix(idim) = ix(idim) + mesh%idx%ll(idim)
643 do while (ix(idim) > nr(2, idim))
644 ix(idim) = ix(idim) - mesh%idx%ll(idim)
651 if (mesh%masked_periodic_boundaries)
then
652 call mesh_r(mesh, ip, rr, coords = xx)
653 call parse_expression(ufn_re, ufn_im, space%dim, xx, rr, m_zero, mesh%periodic_boundary_mask)
660 class(
mesh_t),
intent(in) :: mesh
661 class(space_t),
intent(in) :: space
662 integer(int64),
intent(in) :: ipg_in
664 integer :: ix(space%dim), nr(2, space%dim), idim
665 real(real64) :: xx(space%dim), rr, ufn_re, ufn_im
670 nr(1, :) = mesh%idx%nr(1, :) + mesh%idx%enlarge(:)
671 nr(2, :) = mesh%idx%nr(2, :) - mesh%idx%enlarge(:)
673 do idim = 1, space%periodic_dim
674 if (ix(idim) < nr(1, idim)) ix(idim) = ix(idim) + mesh%idx%ll(idim)
675 if (ix(idim) > nr(2, idim)) ix(idim) = ix(idim) - mesh%idx%ll(idim)
681 if (mesh%masked_periodic_boundaries)
then
683 call parse_expression(ufn_re, ufn_im, space%dim, xx, rr, m_zero, mesh%periodic_boundary_mask)
684 if (int(ufn_re) == 0) ipg = ipg_in
693 use iso_c_binding,
only: c_sizeof, c_long_long
694 class(
mesh_t),
intent(in) :: mesh
697 memory = c_sizeof(c_long_long) * real(mesh%np_part_global, real64) * 2
704 use iso_c_binding,
only: c_sizeof, c_long_long
705 class(
mesh_t),
intent(in) :: mesh
710 memory = memory + real64 * real(mesh%np_part, real64) * mesh%idx%dim
712 memory = memory + c_sizeof(c_long_long) * real(mesh%np_part, real64) * 2
719 class(
mesh_t),
intent(in) :: mesh
720 integer(int64),
intent(in) :: ipg
721 real(real64) :: xx(1:mesh%box%dim)
723 real(real64) :: chi(1:mesh%box%dim)
724 integer :: ix(1:mesh%box%dim)
729 chi = ix * mesh%spacing
730 xx = mesh%coord_system%to_cartesian(chi)
737 class(
mesh_t),
intent(in) :: mesh
738 type(symmetries_t),
intent(in) :: symm
739 integer,
intent(in) :: periodic_dim
741 integer :: iop, ip, idim, nops, ix(1:3)
742 real(real64) :: destpoint(1:3), srcpoint(1:3), lsize(1:3), offset(1:3)
743 real(real64),
parameter :: tol_spacing = 1e-12_real64
751 if (mesh%idx%ll(1) == mesh%idx%ll(2) .and. &
752 mesh%idx%ll(2) == mesh%idx%ll(3) .and. &
753 abs(mesh%spacing(1) - mesh%spacing(2)) < tol_spacing .and. &
754 abs(mesh%spacing(2) - mesh%spacing(3)) < tol_spacing)
return
758 message(1) =
"Checking if the real-space grid is symmetric"
759 call messages_info(1)
761 lsize(1:3) = real(mesh%idx%ll(1:3), real64)
762 offset(1:3) = real(mesh%idx%nr(1, 1:3) + mesh%idx%enlarge(1:3), real64)
764 nops = symmetries_number(symm)
771 destpoint(1:3) = real(ix(1:3), real64) - offset(1:3)
773 assert(all(destpoint >= 0))
774 assert(all(destpoint < lsize))
777 destpoint = destpoint - real(int(lsize)/2, real64)
781 destpoint(idim) = destpoint(idim)/lsize(idim)
786 srcpoint = symm_op_apply_red(symm%ops(iop), destpoint)
790 srcpoint(idim) = srcpoint(idim)*lsize(idim)
794 srcpoint = srcpoint + real(int(lsize)/2, real64)
797 do idim = 1, periodic_dim
798 if (nint(srcpoint(idim)) < 0 .or. nint(srcpoint(idim)) >= lsize(idim))
then
799 srcpoint(idim) = modulo(srcpoint(idim)+m_half*symprec, lsize(idim))
802 assert(all(srcpoint >= -symprec))
803 assert(all(srcpoint < lsize))
805 srcpoint(1:3) = srcpoint(1:3) + offset(1:3)
807 if (any(srcpoint-anint(srcpoint)> symprec*m_two))
then
808 message(1) =
"The real-space grid breaks at least one of the symmetries of the system."
809 message(2) =
"Change your spacing or use SymmetrizeDensity=no."
810 call messages_fatal(2)
821 class(
mesh_t),
intent(in) :: mesh
822 integer,
intent(in) :: ix(:)
824 index = index_from_coords(mesh%idx, ix)
830 type(
mesh_t),
intent(in) :: mesh
831 integer(int64),
intent(in) :: ipg
832 integer,
intent(out) :: ix(:)
834 call index_to_coords(mesh%idx, ipg, ix)
840 type(
mesh_t),
intent(in) :: mesh
841 integer,
intent(in) :: ix(:)
843 integer(int64) :: ipg
845 ipg = index_from_coords(mesh%idx, ix)
852 type(
mesh_t),
intent(in) :: mesh
853 integer,
intent(in) :: ip
854 integer,
intent(out) :: ix(:)
856 integer(int64) :: ipg
859 call index_to_coords(mesh%idx, ipg, ix)
864 type(
mesh_t),
intent(in) :: mesh
865 integer,
intent(in) :: ip
867 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)
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)
Given a global point index, this function returns the coordinates of the point.
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)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
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)