21 use,
intrinsic :: iso_fortran_env
63 real(real64),
allocatable :: positions(:, :)
64 integer :: n_centroids_global
65 integer :: n_centroids
66 integer(int64),
allocatable :: icg_to_ipg(:)
68 integer,
allocatable :: ic_to_icg(:)
69 integer,
allocatable :: ic_to_ip(:)
95 class(centroids_t),
intent(out) :: this
96 class(mesh_t),
intent(in ) :: mesh
97 real(real64),
intent(in ) :: positions(:, :)
101 this%ndim =
size(positions, 1)
102 this%n_centroids_global =
size(positions, 2)
103 safe_allocate_source(this%positions(1:this%ndim, 1:this%n_centroids_global), positions)
113 class(centroids_t),
intent(in) :: this
114 integer :: n_centroids
116 n_centroids = this%n_centroids
123 class(centroids_t),
intent(in) :: this
124 integer :: n_centroids_global
126 n_centroids_global = this%n_centroids_global
142 class(centroids_t),
intent(in) :: this
143 integer,
intent(in) :: ic
144 integer(int64) :: ipg
147 icg = this%ic_to_icg(ic)
148 ipg = this%icg_to_ipg(icg)
156 integer(int64),
allocatable :: global_mesh_indices(:)
160 allocate(global_mesh_indices(this%n_centroids))
161 do ic = 1, this%n_centroids
162 icg = this%ic_to_icg(ic)
163 global_mesh_indices(ic) = this%icg_to_ipg(icg)
172 integer,
intent(in) :: ic
175 ip = this%ic_to_ip(ic)
183 integer,
allocatable :: mesh_indices(:)
185 allocate(mesh_indices(this%n_centroids), source=this%ic_to_ip)
193 integer,
intent(in) :: ic
196 icg = this%ic_to_icg(ic)
204 integer,
allocatable :: global_centroid_indices(:)
206 allocate(global_centroid_indices(this%n_centroids), source=this%ic_to_icg)
214 class(
mesh_t),
intent(in) :: mesh
215 integer,
intent(in) :: ic
217 real(real64) :: pos(this%ndim)
219 pos(:) = mesh%x(this%ic_to_ip(ic), :)
227 real(real64),
allocatable :: positions(:, :)
229 allocate(positions(this%ndim, this%n_centroids_global), source=this%positions)
238 safe_deallocate_a(this%positions)
239 safe_deallocate_a(this%icg_to_ipg)
240 safe_deallocate_a(this%ic_to_icg)
258 class(
mesh_t),
intent(in ) :: mesh
260 real(real64) :: chi(this%ndim)
261 integer :: ix(this%ndim)
263 integer(int64) :: ipg
264 integer,
allocatable :: tmp_ic_to_icg(:), tmp_ic_to_ip(:)
266 integer :: n_centroids_global
271 safe_allocate(this%icg_to_ipg(1:this%n_centroids_global))
276 safe_allocate(tmp_ic_to_icg(1:this%n_centroids_global))
277 safe_allocate(tmp_ic_to_ip(1:this%n_centroids_global))
279 do icg = 1, this%n_centroids_global
280 chi = mesh%coord_system%from_cartesian(this%positions(:, icg))
282 ix = nint(chi / mesh%spacing)
284 this%icg_to_ipg(icg) = ipg
287 if (ip > 0 .and. ip <= mesh%np)
then
288 this%n_centroids = this%n_centroids + 1
289 tmp_ic_to_icg(this%n_centroids) = icg
290 tmp_ic_to_ip(this%n_centroids) = ip
296 n_centroids_global = this%n_centroids
298 assert(n_centroids_global == this%n_centroids_global)
302 safe_allocate_source(this%ic_to_icg(1:this%n_centroids), tmp_ic_to_icg(1:this%n_centroids))
303 safe_deallocate_a(tmp_ic_to_icg)
305 safe_allocate_source(this%ic_to_ip(1:this%n_centroids), tmp_ic_to_ip(1:this%n_centroids))
306 safe_deallocate_a(tmp_ic_to_ip)
pure integer(int64) function centroids_global_centroid_to_global_mesh_index(this, ic)
Given centroid index ic, return the global mesh index ipg.
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.
subroutine exact_centroids_init_index_maps(this, mesh)
Initialise index maps with centroid points that are commensurate with the grid.
subroutine centroids_init(this, mesh, positions)
Initialise a centroids_t instance.
pure integer function centroids_local_index_to_global_index(this, ic)
Get the global centroid index, given centroid ic this domain.
pure integer(int64) function, dimension(:), allocatable centroids_global_centroid_to_global_mesh_indices(this)
Return global mesh indices for all centroids in this domain.
pure real(real64) function, dimension(this%ndim) centroids_get_local_position(this, mesh, ic)
Get the position of the centroid ic.
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.
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.
Encapsulate centroid points and their indexing across a domain-decomposed mesh.
Describes mesh distribution to nodes.