2
! Copyright (C) 1996-2016 The SIESTA group
3
! This file is distributed under the terms of the
4
! GNU General Public License: see COPYING in the top directory
5
! or http://www.gnu.org/copyleft/gpl.txt .
6
! See Docs/Contributors.txt for a list of contributors.
10
use class_OrbitalDistribution
14
character(len=*), parameter :: mod_name="class_"//STR_TYPE_NAME//".F90"
16
public :: val, spar, dist, init_val
17
public :: nrows, nrows_g, nnzs, n_col, list_ptr, list_col
18
public :: print_type, spar_dim, size
21
integer, parameter :: sp = selected_real_kind(5,10)
22
integer, parameter :: dp = selected_real_kind(10,100)
25
integer :: refCount = 0
26
character(len=36) :: id = "null_id"
27
!----------------------
28
character(len=256) :: name = "null "//STR_TYPE_NAME
29
!> See [[Sparsity(type)]]
31
!> See [[VAR_TYPE(type)]]
33
!> See [[OrbitalDistribution(type)]]
34
type(OrbitalDistribution) :: dist
38
type(TYPE_NAME_), pointer :: data => null()
42
module procedure newSpDataFromData
43
module procedure newSpDataFromDims
47
module procedure initializeSpData
51
module procedure valSpData
52
module procedure valSpData_Idx
56
module procedure sparSpData
60
module procedure distSpData
64
module procedure nrowsSpData
68
module procedure nrows_gSpData
72
module procedure nnzsSpData
76
module procedure n_colSpData
80
module procedure list_ptrSpData
84
module procedure list_colSpData
88
module procedure spar_dimSpData
92
module procedure sizeSpData
96
module procedure printSpData
97
end interface print_type
99
!==========================
100
#include "basic_type.inc"
101
!==========================
103
subroutine delete_Data(smdata)
104
type(TYPE_NAME_) :: smdata
106
call delete(smdata%sp)
107
call delete(smdata%a)
108
call delete(smdata%dist)
109
end subroutine delete_Data
111
subroutine newSpDataFromData(sp,a,dist,this,name)
112
!........................................
114
!........................................
115
type(TYPE_NAME), intent(inout) :: this
116
type(Sparsity), intent(in) :: sp
117
type(VAR_TYPE), intent(in) :: a
118
type(OrbitalDistribution), intent(in) :: dist
119
character(len=*), intent(in), optional :: name
125
this%data%dist = dist
127
if (present(name)) then
128
this%data%name = trim(name)
130
this%data%name = "(SpData from sp, dist, and a)"
132
call tag_new_object(this)
134
end subroutine newSpDataFromData
136
subroutine newSpDataFromDims(sp,dim1,dim2,dist,this,name,sparsity_dim)
137
!........................................
139
!........................................
140
type(TYPE_NAME), intent(inout) :: this
141
type(Sparsity), intent(in) :: sp
142
type(OrbitalDistribution), intent(in) :: dist
143
integer, intent(in) :: dim1, dim2
144
character(len=*), intent(in), optional :: name
145
integer, intent(in), optional :: sparsity_dim
149
this%data%dist = dist
150
if ( present(sparsity_dim) ) then
151
if ( sparsity_dim < 1 .or. 3 < sparsity_dim ) then
152
call die('Supplying a sparsity dimension out-of-bounds &
153
&for SpData2D data is not allowed, range={1,2,3}')
155
if ( sparsity_dim == 1 ) then ! Regular way...
156
call VAR_NEW_TYPE(this%data%a, &
157
nnzs(sp),dim1,dim2,"(new from "//STR_TYPE_NAME//")")
158
else if ( sparsity_dim == 2 ) then ! Regular way...
159
call VAR_NEW_TYPE(this%data%a, &
160
dim1,nnzs(sp),dim2,"(new from "//STR_TYPE_NAME//")")
162
call VAR_NEW_TYPE(this%data%a, &
163
dim1,dim2,nnzs(sp),"(new from "//STR_TYPE_NAME//")")
165
else ! Regular handling, sparsity_dim == 1
166
call VAR_NEW_TYPE(this%data%a, &
167
nnzs(sp),dim1,dim2,"(new from "//STR_TYPE_NAME//")")
170
if (present(name)) then
171
this%data%name = trim(name)
173
this%data%name = "("//STR_TYPE_NAME//" from sp, dims, and dist)"
175
call tag_new_object(this)
177
end subroutine newSpDataFromDims
179
!--------------------------------------------------
180
function valSpData(this) result(p)
181
type(TYPE_NAME), intent(in) :: this
183
VAR_TYPE_TYPE(PREC), pointer :: p(:,:,:) !=> null()
185
VAR_TYPE_TYPE , pointer :: p(:,:,:) !=> null()
188
p => val(this%data%a)
189
end function valSpData
191
function valSpData_Idx(this,idx1,idx2,idx3) result(v)
192
type(TYPE_NAME), intent(in) :: this
193
integer, intent(in) :: idx1, idx2, idx3
195
VAR_TYPE_TYPE(PREC) :: v
200
v = val(this%data%a,idx1,idx2,idx3)
201
end function valSpData_Idx
203
function sparSpData(this) result(p)
204
type(TYPE_NAME), intent(in) :: this
205
type(Sparsity), pointer :: p !=> null()
208
end function sparSpData
210
function distSpData(this) result(p)
211
type(TYPE_NAME), intent(in) :: this
212
type(OrbitalDistribution), pointer :: p !=> null()
215
end function distSpData
217
!--------------------------------------------------
218
function nrowsSpData(this) result (n)
219
type(TYPE_NAME), intent(in) :: this
222
n = nrows(this%data%sp)
223
end function nrowsSpData
225
function nrows_gSpData(this) result (n)
226
type(TYPE_NAME), intent(in) :: this
229
n = nrows_g(this%data%sp)
230
end function nrows_gSpData
232
function nnzsSpData(this) result (n)
233
type(TYPE_NAME), intent(in) :: this
236
if ( initialized(this) ) then
237
n = nnzs(this%data%sp)
242
end function nnzsSpData
244
function n_colSpData(this) result (p)
245
type(TYPE_NAME), intent(in) :: this
246
integer, pointer :: p(:) !=> null()
248
p => n_col(this%data%sp)
249
end function n_colSpData
251
function list_ptrSpData(this) result (p)
252
type(TYPE_NAME), intent(in) :: this
253
integer, pointer :: p(:) !=> null()
254
p => list_ptr(this%data%sp)
255
end function list_ptrSpData
257
function list_colSpData(this) result (p)
258
type(TYPE_NAME), intent(in) :: this
259
integer, pointer :: p(:)
260
p => list_col(this%data%sp)
261
end function list_colSpData
264
function spar_dimSpData(this) result(dim)
265
type(TYPE_NAME), intent(in) :: this
269
if ( .not. initialized(this) ) return
271
! Check which dimension is the sparsity dimension
272
if ( nnzs(this) == size(this%data%a%data%val,dim=1) ) then
274
else if ( nnzs(this) == size(this%data%a%data%val,dim=2) ) then
280
end function spar_dimSpData
282
function sizeSpData(this, dim) result(n)
283
type(TYPE_NAME), intent(in) :: this
284
integer, intent(in), optional :: dim
288
if ( .not. initialized(this) ) return
290
if ( present(dim) ) then
291
if ( dim < 1 .or. 3 < dim ) then
294
! we have to use a different variable
295
! name than dim (due to interface problems)
297
n = size(this%data%a%data%val,ldim)
300
n = size(this%data%a%data%val)
303
end function sizeSpData
305
subroutine printSpData(this)
306
type(TYPE_NAME), intent(in) :: this
308
if (.not. initialized(this) ) then
309
print "(a)", STR_TYPE_NAME//" Not Associated"
313
print "(a)", "<"//STR_TYPE_NAME//":"//trim(this%data%name)
314
call print_type(this%data%sp)
315
call print_type(this%data%a)
316
print "(a,i0,a)", "refcount: ",refcount(this),">"
318
end subroutine printSpData
320
subroutine initializeSpData(this)
321
type(TYPE_NAME), intent(inout) :: this
323
if ( .not. initialized(this) ) return
324
call init_val(this%data%a)
326
end subroutine initializeSpData