15 #include "../base/base_uses.f90"
20 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'dbt_index'
42 INTEGER :: ndim_nd = -1
43 INTEGER :: ndim1_2d = -1
44 INTEGER :: ndim2_2d = -1
46 INTEGER,
DIMENSION(:),
ALLOCATABLE :: dims_nd
47 INTEGER(KIND=int_8),
DIMENSION(2) :: dims_2d = -1
48 INTEGER,
DIMENSION(:),
ALLOCATABLE :: dims1_2d
49 INTEGER,
DIMENSION(:),
ALLOCATABLE :: dims2_2d
51 INTEGER,
DIMENSION(:),
ALLOCATABLE :: map1_2d
52 INTEGER,
DIMENSION(:),
ALLOCATABLE :: map2_2d
53 INTEGER,
DIMENSION(:),
ALLOCATABLE :: map_nd
56 LOGICAL :: col_major = .false.
57 END TYPE nd_to_2d_mapping
73 TYPE(nd_to_2d_mapping),
INTENT(OUT) :: map
74 INTEGER,
DIMENSION(:),
INTENT(IN) :: dims, map1_2d, map2_2d
75 INTEGER,
INTENT(IN),
OPTIONAL :: base
76 LOGICAL,
INTENT(IN),
OPTIONAL :: col_major
80 IF (
PRESENT(col_major))
THEN
81 map%col_major = col_major
83 map%col_major = .true.
86 IF (
PRESENT(base))
THEN
92 map%ndim1_2d =
SIZE(map1_2d)
93 map%ndim2_2d =
SIZE(map2_2d)
94 map%ndim_nd =
SIZE(dims)
96 ALLOCATE (map%map1_2d, source=map1_2d)
97 ALLOCATE (map%map2_2d, source=map2_2d)
98 ALLOCATE (map%dims_nd, source=dims)
99 ALLOCATE (map%dims1_2d, source=dims(map1_2d))
100 ALLOCATE (map%dims2_2d, source=dims(map2_2d))
102 ALLOCATE (map%map_nd(map%ndim_nd))
103 map%map_nd(map1_2d) = (/(i, i=1,
SIZE(map1_2d))/)
104 map%map_nd(map2_2d) = (/(i +
SIZE(map1_2d), i=1,
SIZE(map2_2d))/)
106 map%dims_2d = [product(int(map%dims1_2d, kind=
int_8)), product(int(map%dims2_2d, kind=
int_8))]
115 TYPE(nd_to_2d_mapping),
INTENT(INOUT) :: map
117 DEALLOCATE (map%dims1_2d)
118 DEALLOCATE (map%dims2_2d)
119 DEALLOCATE (map%map1_2d)
120 DEALLOCATE (map%map2_2d)
121 DEALLOCATE (map%map_nd)
122 DEALLOCATE (map%dims_nd)
130 TYPE(nd_to_2d_mapping),
INTENT(IN) :: map
141 TYPE(nd_to_2d_mapping),
INTENT(IN) :: map
151 TYPE(nd_to_2d_mapping),
INTENT(IN) :: map
174 dims_2d, dims_nd, dims1_2d, dims2_2d, &
175 map1_2d, map2_2d, map_nd, base, col_major)
176 TYPE(nd_to_2d_mapping),
INTENT(IN) :: map
177 INTEGER,
INTENT(OUT),
OPTIONAL :: ndim_nd, ndim1_2d, ndim2_2d
178 INTEGER(KIND=int_8),
DIMENSION(2),
INTENT(OUT),
OPTIONAL :: dims_2d_i8
179 INTEGER,
DIMENSION(2),
INTENT(OUT),
OPTIONAL :: dims_2d
180 INTEGER,
DIMENSION(ndims_mapping(map)), &
181 INTENT(OUT),
OPTIONAL :: dims_nd
182 INTEGER,
DIMENSION(ndims_mapping_row(map)),
INTENT(OUT), &
184 INTEGER,
DIMENSION(ndims_mapping_column(map)),
INTENT(OUT), &
186 INTEGER,
DIMENSION(ndims_mapping_row(map)),
INTENT(OUT), &
188 INTEGER,
DIMENSION(ndims_mapping_column(map)),
INTENT(OUT), &
190 INTEGER,
DIMENSION(ndims_mapping(map)), &
191 INTENT(OUT),
OPTIONAL :: map_nd
192 INTEGER,
INTENT(OUT),
OPTIONAL :: base
193 LOGICAL,
INTENT(OUT),
OPTIONAL :: col_major
195 IF (
PRESENT(ndim_nd)) ndim_nd = map%ndim_nd
196 IF (
PRESENT(ndim1_2d)) ndim1_2d = map%ndim1_2d
197 IF (
PRESENT(ndim2_2d)) ndim2_2d = map%ndim2_2d
198 IF (
PRESENT(dims_2d_i8)) dims_2d_i8(:) = map%dims_2d(:)
199 IF (
PRESENT(dims_2d)) dims_2d(:) = int(map%dims_2d(:))
200 IF (
PRESENT(dims_nd))
THEN
201 dims_nd(:) = map%dims_nd(:)
203 IF (
PRESENT(dims1_2d))
THEN
204 dims1_2d(:) = map%dims1_2d
206 IF (
PRESENT(dims2_2d))
THEN
207 dims2_2d(:) = map%dims2_2d
209 IF (
PRESENT(map1_2d))
THEN
210 map1_2d(:) = map%map1_2d
212 IF (
PRESENT(map2_2d))
THEN
213 map2_2d(:) = map%map2_2d
215 IF (
PRESENT(map_nd))
THEN
216 map_nd(:) = map%map_nd(:)
218 IF (
PRESENT(base))
THEN
221 IF (
PRESENT(col_major))
THEN
222 col_major = map%col_major
235 INTEGER,
DIMENSION(:),
INTENT(IN) :: ind_in, dims
236 INTEGER(KIND=int_8) :: ind_out
239 ind_out = ind_in(
SIZE(dims))
240 DO i_dim =
SIZE(dims) - 1, 1, -1
241 ind_out = (ind_out - 1)*dims(i_dim) + ind_in(i_dim)
254 INTEGER,
DIMENSION(:),
INTENT(IN) :: ind_in, dims
260 DO i_dim = 2,
SIZE(dims)
261 ind_out = ind_out*dims(i_dim) + ind_in(i_dim)
273 INTEGER(KIND=int_8),
INTENT(IN) :: ind_in
274 INTEGER,
DIMENSION(:),
INTENT(IN) :: dims
275 INTEGER,
DIMENSION(SIZE(dims)) :: ind_out
277 INTEGER(KIND=int_8) :: tmp
281 DO i_dim = 1,
SIZE(dims)
282 ind_out(i_dim) = int(mod(tmp - 1, int(dims(i_dim),
int_8)) + 1)
283 tmp = (tmp - 1)/dims(i_dim) + 1
296 INTEGER,
INTENT(IN) :: ind_in
297 INTEGER,
DIMENSION(:),
INTENT(IN) :: dims
298 INTEGER,
DIMENSION(SIZE(dims)) :: ind_out
304 DO i_dim =
SIZE(dims), 1, -1
305 ind_out(i_dim) = mod(tmp, dims(i_dim))
306 tmp = tmp/dims(i_dim)
318 TYPE(nd_to_2d_mapping),
INTENT(IN) :: map
319 INTEGER,
DIMENSION(map%ndim_nd),
INTENT(IN) :: ind_in
320 INTEGER(KIND=int_8),
DIMENSION(2) :: ind_out
322 INTEGER,
DIMENSION(4) :: ind_tmp
324 DO i = 1, map%ndim1_2d
325 ind_tmp(i) = ind_in(map%map1_2d(i))
329 DO i = 1, map%ndim2_2d
330 ind_tmp(i) = ind_in(map%map2_2d(i))
343 TYPE(nd_to_2d_mapping),
INTENT(IN) :: map
344 INTEGER,
DIMENSION(map%ndim_nd),
INTENT(IN) :: ind_in
345 INTEGER,
DIMENSION(2) :: ind_out
347 INTEGER,
DIMENSION(4) :: ind_tmp
349 DO i = 1, map%ndim1_2d
350 ind_tmp(i) = ind_in(map%map1_2d(i))
354 DO i = 1, map%ndim2_2d
355 ind_tmp(i) = ind_in(map%map2_2d(i))
368 TYPE(nd_to_2d_mapping),
INTENT(IN) :: map
369 INTEGER(KIND=int_8),
DIMENSION(2),
INTENT(IN) :: ind_in
370 INTEGER,
DIMENSION(map%ndim_nd) :: ind_out
371 INTEGER,
DIMENSION(4) :: ind_tmp
376 DO i = 1, map%ndim1_2d
377 ind_out(map%map1_2d(i)) = ind_tmp(i)
382 DO i = 1, map%ndim2_2d
383 ind_out(map%map2_2d(i)) = ind_tmp(i)
396 TYPE(nd_to_2d_mapping),
INTENT(IN) :: map
397 INTEGER,
DIMENSION(2),
INTENT(IN) :: ind_in
398 INTEGER,
DIMENSION(map%ndim_nd) :: ind_out
410 INTEGER,
DIMENSION(:),
INTENT(IN) :: order
423 TYPE(nd_to_2d_mapping),
INTENT(IN) :: map_in
424 TYPE(nd_to_2d_mapping),
INTENT(OUT) :: map_out
425 INTEGER,
DIMENSION(ndims_mapping(map_in)), &
429 INTEGER,
DIMENSION(ndims_mapping_row(map_in)) :: map1_2d, map1_2d_reorder
430 INTEGER,
DIMENSION(ndims_mapping_column(map_in)) :: map2_2d, map2_2d_reorder
431 INTEGER,
DIMENSION(ndims_mapping(map_in)) :: dims_nd, dims_reorder
435 dims_reorder(order) = dims_nd
437 map1_2d_reorder(:) = order(map1_2d)
438 map2_2d_reorder(:) = order(map2_2d)
Wrapper for allocating, copying and reshaping arrays.
tensor index and mapping to DBM index
pure integer function, dimension(2), public get_2d_indices_pgrid(map, ind_in)
transform nd index to 2d index, using info from index mapping.
subroutine, public create_nd_to_2d_mapping(map, dims, map1_2d, map2_2d, base, col_major)
Create all data needed to quickly map between nd index and 2d index.
pure integer function, dimension(map%ndim_nd), public get_nd_indices_pgrid(map, ind_in)
transform 2d index to nd index, using info from index mapping.
pure integer function, public ndims_mapping_row(map)
how many tensor dimensions are mapped to matrix row
pure integer(kind=int_8) function, dimension(2), public get_2d_indices_tensor(map, ind_in)
transform nd index to 2d index, using info from index mapping.
pure integer function, dimension(size(order)), public dbt_inverse_order(order)
Invert order.
pure integer function, public ndims_mapping(map)
pure integer(kind=int_8) function, public combine_tensor_index(ind_in, dims)
transform nd index to flat index
subroutine, public permute_index(map_in, map_out, order)
reorder tensor index (no data)
pure subroutine, public dbt_get_mapping_info(map, ndim_nd, ndim1_2d, ndim2_2d, dims_2d_i8, dims_2d, dims_nd, dims1_2d, dims2_2d, map1_2d, map2_2d, map_nd, base, col_major)
get mapping info
pure integer function, public combine_pgrid_index(ind_in, dims)
transform nd index to flat index
pure integer function, public ndims_mapping_column(map)
how many tensor dimensions are mapped to matrix column
pure integer function, dimension(map%ndim_nd), public get_nd_indices_tensor(map, ind_in)
transform 2d index to nd index, using info from index mapping.
subroutine, public destroy_nd_to_2d_mapping(map)
pure integer function, dimension(size(dims)), public split_tensor_index(ind_in, dims)
transform flat index to nd index
pure integer function, dimension(size(dims)), public split_pgrid_index(ind_in, dims)
transform flat index to nd index
Defines the basic variable types.
integer, parameter, public int_8