21 use,
intrinsic :: iso_fortran_env
65 real(real64),
allocatable :: positions(:, :)
66 integer :: n_centroids_global
67 integer :: n_centroids
68 integer(int64),
allocatable :: icg_to_ipg(:)
70 integer,
allocatable :: ic_to_icg(:)
71 integer,
allocatable :: ic_to_ip(:)
99 class(centroids_t),
intent(out) :: this
100 class(mesh_t),
intent(in ) :: mesh
101 real(real64),
intent(in ) :: positions(:, :)
102 logical,
optional,
intent(in ) :: check_duplicates
107 this%ndim =
size(positions, 1)
108 this%n_centroids_global =
size(positions, 2)
109 safe_allocate_source(this%positions(1:this%ndim, 1:this%n_centroids_global), positions)
119 class(centroids_t),
intent(in) :: this
120 integer :: n_centroids
122 n_centroids = this%n_centroids
129 class(centroids_t),
intent(in) :: this
130 integer :: n_centroids_global
132 n_centroids_global = this%n_centroids_global
148 class(centroids_t),
intent(in) :: this
149 integer,
intent(in) :: ic
150 integer(int64) :: ipg
153 icg = this%ic_to_icg(ic)
154 ipg = this%icg_to_ipg(icg)
162 integer(int64),
allocatable :: global_mesh_indices(:)
166 allocate(global_mesh_indices(this%n_centroids))
167 do ic = 1, this%n_centroids
168 icg = this%ic_to_icg(ic)
169 global_mesh_indices(ic) = this%icg_to_ipg(icg)
178 integer,
intent(in) :: ic
181 ip = this%ic_to_ip(ic)
189 integer,
allocatable :: mesh_indices(:)
191 allocate(mesh_indices(this%n_centroids), source=this%ic_to_ip)
199 integer,
intent(in) :: ic
202 icg = this%ic_to_icg(ic)
210 integer,
allocatable :: global_centroid_indices(:)
212 allocate(global_centroid_indices(this%n_centroids), source=this%ic_to_icg)
220 class(
mesh_t),
intent(in) :: mesh
221 integer,
intent(in) :: ic
223 real(real64) :: pos(this%ndim)
225 pos(:) = mesh%x(this%ic_to_ip(ic), :)
233 real(real64),
allocatable :: positions(:, :)
235 allocate(positions(this%ndim, this%n_centroids_global), source=this%positions)
244 character(len=*),
intent(in) :: fname
250 unit =
io_open(trim(adjustl(fname)), action=
'write')
252 write(unit, *)
'N centroids', this%n_centroids_global
253 do icg = 1, this%n_centroids_global
254 write(unit, *) this%icg_to_ipg(icg)
268 safe_deallocate_a(this%positions)
269 safe_deallocate_a(this%icg_to_ipg)
270 safe_deallocate_a(this%ic_to_icg)
288 class(
mesh_t),
intent(in ) :: mesh
289 logical,
intent(in ) :: check_duplicates
292 real(real64) :: chi(this%ndim)
293 integer :: ix(this%ndim)
295 integer(int64) :: ipg
296 integer,
allocatable :: tmp_ic_to_icg(:), tmp_ic_to_ip(:)
298 integer :: n_centroids_global
303 safe_allocate(this%icg_to_ipg(1:this%n_centroids_global))
308 safe_allocate(tmp_ic_to_icg(1:this%n_centroids_global))
309 safe_allocate(tmp_ic_to_ip(1:this%n_centroids_global))
312 do icg = 1, this%n_centroids_global
313 chi = mesh%coord_system%from_cartesian(this%positions(:, icg))
315 ix = nint(chi / mesh%spacing)
317 this%icg_to_ipg(icg) = ipg
325 if (check_duplicates)
then
327 this%n_centroids_global =
size(this%icg_to_ipg)
331 do icg = 1, this%n_centroids_global
332 ipg = this%icg_to_ipg(icg)
334 if (ip > 0 .and. ip <= mesh%np)
then
335 this%n_centroids = this%n_centroids + 1
336 tmp_ic_to_icg(this%n_centroids) = icg
337 tmp_ic_to_ip(this%n_centroids) = ip
343 n_centroids_global = this%n_centroids
345 assert(n_centroids_global == this%n_centroids_global)
349 safe_allocate_source(this%ic_to_icg(1:this%n_centroids), tmp_ic_to_icg(1:this%n_centroids))
350 safe_deallocate_a(tmp_ic_to_icg)
352 safe_allocate_source(this%ic_to_ip(1:this%n_centroids), tmp_ic_to_ip(1:this%n_centroids))
353 safe_deallocate_a(tmp_ic_to_ip)
361 integer(int64),
intent(inout),
allocatable :: indices(:)
364 integer :: n_duplicates, cnt, n, i
365 integer(int64),
allocatable :: unique_indices(:)
372 allocate(unique_indices(n))
376 unique_indices(1) = indices(1)
379 if (indices(i) == indices(i+1))
then
380 n_duplicates = n_duplicates + 1
384 unique_indices(cnt) = indices(i+1)
387 safe_deallocate_a(indices)
388 safe_allocate_source(indices(1:cnt), unique_indices(1:cnt))
389 safe_deallocate_a(unique_indices)
391 if (
debug%info .and. n_duplicates > 0)
then
392 write(
message(1),
'(I0)') n_duplicates
393 message(1) = trim(
message(1)) //
" duplicates found after discretisation of centroid positions"
395 message(2) =
" Removed the duplicate/s and resized 'indices' array to " // trim(
message(2))
This is the common interface to a sorting routine. It performs the shell algorithm,...
pure integer(int64) function centroids_global_centroid_to_global_mesh_index(this, ic)
Given centroid index ic, return the global mesh index ipg.
subroutine remove_duplicates_int64(indices)
Remove duplicates from an array of integers.
pure integer function, dimension(:), allocatable centroids_get_local_mesh_indices(this)
Return mesh indices ip for all centroids in this domain.
subroutine centroids_finalize(this)
Finalize a centroids instance.
pure integer function, dimension(:), allocatable centroids_local_index_to_global_indices(this)
Return global centroid indices for all centroids in this domain.
pure integer function centroids_local_index_to_global_index(this, ic)
Get the global centroid index, given centroid ic this domain.
subroutine centroids_init(this, mesh, positions, check_duplicates)
Initialise a centroids_t instance.
pure integer(int64) function, dimension(:), allocatable centroids_global_centroid_to_global_mesh_indices(this)
Return global mesh indices for all centroids in this domain.
subroutine centroids_output_all_indices(this, fname)
Output all centroid indices, across all domains.
pure real(real64) function, dimension(this%ndim) centroids_get_local_position(this, mesh, ic)
Get the position of the centroid ic.
subroutine exact_centroids_init_index_maps(this, mesh, check_duplicates)
Initialise index maps with centroid points that are commensurate with the grid.
pure integer function centroids_get_local_mesh_index(this, ic)
Get the mesh index ip of centroid ic in this domain.
pure integer function centroids_get_n_centroids(this)
Number of centroids in local domain.
pure real(real64) function, dimension(:, :), allocatable centroids_get_all_positions(this)
Return a copy of all centroid positions.
pure integer function centroids_get_n_centroids_global(this)
Total number of centroids in system.
type(debug_t), save, public debug
subroutine, public io_close(iunit, grp)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
This module defines the meshes, which are used in Octopus.
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.
integer function, public mesh_global2local(mesh, ipg)
This function returns the local mesh index for a given global index.
subroutine, public messages_warning(no_lines, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
type(mpi_grp_t), public mpi_world
This module is intended to contain "only mathematical" functions and procedures.
Encapsulate centroid points and their indexing across a domain-decomposed mesh.
Describes mesh distribution to nodes.