-
Notifications
You must be signed in to change notification settings - Fork 1
/
lri_compression.F
177 lines (153 loc) · 6.1 KB
/
lri_compression.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief integral compression (fix point accuracy)
!> \par History
!> created JGH [11.2017]
!> \authors JGH
! **************************************************************************************************
MODULE lri_compression
USE kinds, ONLY: dp,&
sp
USE lri_environment_types, ONLY: carray,&
int_container
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
! **************************************************************************************************
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'lri_compression'
PUBLIC :: lri_comp, lri_decomp_i, lri_cont_mem
! **************************************************************************************************
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param aval ...
!> \param amax ...
!> \param cont ...
! **************************************************************************************************
SUBROUTINE lri_comp(aval, amax, cont)
REAL(KIND=dp), DIMENSION(:, :, :), INTENT(IN) :: aval
REAL(KIND=dp), DIMENSION(:), INTENT(OUT) :: amax
TYPE(int_container), INTENT(INOUT) :: cont
INTEGER :: i, ia, ib, ii, na, nb, nc, nn
REAL(KIND=dp) :: xm
TYPE(carray), POINTER :: ca
IF (ASSOCIATED(cont%ca)) THEN
DO i = 1, SIZE(cont%ca)
IF (ASSOCIATED(cont%ca(i)%cdp)) DEALLOCATE (cont%ca(i)%cdp)
IF (ASSOCIATED(cont%ca(i)%csp)) DEALLOCATE (cont%ca(i)%csp)
IF (ASSOCIATED(cont%ca(i)%cip)) DEALLOCATE (cont%ca(i)%cip)
END DO
END IF
na = SIZE(aval, 1)
nb = SIZE(aval, 2)
nc = SIZE(aval, 3)
nn = na*nb
cont%na = na
cont%nb = nb
cont%nc = nc
IF (nc > 0) THEN
ALLOCATE (cont%ca(nc))
DO i = 1, nc
ca => cont%ca(i)
NULLIFY (ca%cdp, ca%csp, ca%cip)
xm = MAXVAL(ABS(aval(:, :, i)))
IF (xm >= 1.0e-05_dp) THEN
ca%compression = 1
ALLOCATE (ca%cdp(nn))
ii = 0
DO ib = 1, nb
DO ia = 1, na
ii = ii + 1
ca%cdp(ii) = aval(ia, ib, i)
END DO
END DO
ELSE IF (xm >= 1.0e-10_dp) THEN
ca%compression = 2
ALLOCATE (ca%csp(nn))
ii = 0
DO ib = 1, nb
DO ia = 1, na
ii = ii + 1
ca%csp(ii) = REAL(aval(ia, ib, i), KIND=sp)
END DO
END DO
ELSE
ca%compression = 0
END IF
amax(i) = xm
END DO
END IF
END SUBROUTINE lri_comp
! **************************************************************************************************
!> \brief ...
!> \param cont ...
!> \return ...
! **************************************************************************************************
FUNCTION lri_cont_mem(cont) RESULT(cmem)
TYPE(int_container), INTENT(IN) :: cont
REAL(KIND=dp) :: cmem
INTEGER :: i
cmem = 0.0_dp
IF (ASSOCIATED(cont%ca)) THEN
DO i = 1, SIZE(cont%ca)
IF (ASSOCIATED(cont%ca(i)%cdp)) THEN
cmem = cmem + SIZE(cont%ca(i)%cdp)
END IF
IF (ASSOCIATED(cont%ca(i)%csp)) THEN
cmem = cmem + 0.5_dp*SIZE(cont%ca(i)%csp)
END IF
IF (ASSOCIATED(cont%ca(i)%cip)) THEN
cmem = cmem + SIZE(cont%ca(i)%cip)
END IF
END DO
END IF
END FUNCTION lri_cont_mem
! **************************************************************************************************
!> \brief ...
!> \param aval ...
!> \param cont ...
!> \param ival ...
! **************************************************************************************************
SUBROUTINE lri_decomp_i(aval, cont, ival)
REAL(KIND=dp), DIMENSION(:, :), INTENT(INOUT) :: aval
TYPE(int_container), INTENT(INOUT) :: cont
INTEGER :: ival
INTEGER :: ia, ib, ii, na, nb, nn
TYPE(carray), POINTER :: ca
na = SIZE(aval, 1)
nb = SIZE(aval, 2)
nn = na*nb
CPASSERT(na == cont%na)
CPASSERT(nb == cont%nb)
CPASSERT(ival <= cont%nc)
ca => cont%ca(ival)
!
SELECT CASE (ca%compression)
CASE (0)
aval(1:na, 1:nb) = 0.0_dp
CASE (1)
ii = 0
DO ib = 1, nb
DO ia = 1, na
ii = ii + 1
aval(ia, ib) = ca%cdp(ii)
END DO
END DO
CASE (2)
ii = 0
DO ib = 1, nb
DO ia = 1, na
ii = ii + 1
aval(ia, ib) = REAL(ca%csp(ii), KIND=dp)
END DO
END DO
CASE DEFAULT
CPABORT("lri_decomp_i: compression label invalid")
END SELECT
END SUBROUTINE lri_decomp_i
END MODULE lri_compression