Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief CP2K transport environment and related C-interoperable types
10 : !> \par History
11 : !> 05.2013 created C-interoperable matrices [Hossein Bani-Hashemian]
12 : !> 07.2013 created transport_env [Hossein Bani-Hashemian]
13 : !> 11.2014 revised into CSR matrices [Hossein Bani-Hashemian]
14 : !> 12.2014 merged csr_interop and transport [Hossein Bani-Hashemian]
15 : !> \author Mohammad Hossein Bani-Hashemian
16 : ! **************************************************************************************************
17 : MODULE transport_env_types
18 :
19 : USE ISO_C_BINDING, ONLY: &
20 : C_ASSOCIATED, C_BOOL, C_DOUBLE, C_FUNPTR, C_F_POINTER, C_INT, C_NULL_FUNPTR, C_NULL_PTR, &
21 : C_PTR
22 : USE cp_dbcsr_api, ONLY: dbcsr_csr_destroy,&
23 : dbcsr_csr_type,&
24 : dbcsr_deallocate_matrix,&
25 : dbcsr_release,&
26 : dbcsr_type
27 : USE kinds, ONLY: dp
28 : #include "./base/base_uses.f90"
29 :
30 : IMPLICIT NONE
31 :
32 : PRIVATE
33 :
34 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'transport_env_types'
35 :
36 : PUBLIC :: transport_env_type, cp2k_transport_parameters
37 : PUBLIC :: cp2k_csr_interop_type
38 :
39 : ! DO NOT change the ORDERING or the NAMES in the following data type
40 : TYPE, BIND(C) :: cp2k_transport_parameters
41 : INTEGER(C_INT) :: n_occ = -1_C_INT
42 : INTEGER(C_INT) :: n_atoms = -1_C_INT
43 : REAL(C_DOUBLE) :: energy_diff = -1.0_C_DOUBLE
44 : REAL(C_DOUBLE) :: evoltfactor = -1.0_C_DOUBLE
45 : REAL(C_DOUBLE) :: e_charge = -1.0_C_DOUBLE
46 : REAL(C_DOUBLE) :: boltzmann = -1.0_C_DOUBLE
47 : REAL(C_DOUBLE) :: h_bar = -1.0_C_DOUBLE
48 : INTEGER(C_INT) :: iscf = -1_C_INT
49 : INTEGER(C_INT) :: method = -1_C_INT
50 : INTEGER(C_INT) :: qt_formalism = -1_C_INT
51 : INTEGER(C_INT) :: injection_method = -1_C_INT
52 : INTEGER(C_INT) :: rlaxis_integration_method = -1_C_INT
53 : INTEGER(C_INT) :: linear_solver = -1_C_INT
54 : INTEGER(C_INT) :: matrixinv_method = -1_C_INT
55 : INTEGER(C_INT) :: transport_neutral = -1_C_INT
56 : INTEGER(C_INT) :: num_pole = -1_C_INT
57 : INTEGER(C_INT) :: ordering = -1_C_INT
58 : INTEGER(C_INT) :: row_ordering = -1_C_INT
59 : INTEGER(C_INT) :: verbosity = -1_C_INT
60 : INTEGER(C_INT) :: pexsi_np_symb_fact = -1_C_INT
61 : INTEGER(C_INT) :: n_kpoint = -1_C_INT
62 : INTEGER(C_INT) :: num_interval = -1_C_INT
63 : INTEGER(C_INT) :: num_contacts = -1_C_INT
64 : INTEGER(C_INT) :: stride_contacts = -1_C_INT
65 : INTEGER(C_INT) :: tasks_per_energy_point = -1_C_INT
66 : INTEGER(C_INT) :: tasks_per_pole = -1_C_INT
67 : INTEGER(C_INT) :: gpus_per_point = -1_C_INT
68 : INTEGER(C_INT) :: n_points_beyn = -1_C_INT
69 : INTEGER(C_INT) :: ncrc_beyn = -1_C_INT
70 : INTEGER(C_INT) :: tasks_per_integration_point = -1_C_INT
71 : INTEGER(C_INT) :: n_points_inv = -1_C_INT
72 : INTEGER(C_INT) :: cutout(2) = -1_C_INT
73 : REAL(C_DOUBLE) :: colzero_threshold = -1.0_C_DOUBLE
74 : REAL(C_DOUBLE) :: eps_limit = -1.0_C_DOUBLE
75 : REAL(C_DOUBLE) :: eps_limit_cc = -1.0_C_DOUBLE
76 : REAL(C_DOUBLE) :: eps_decay = -1.0_C_DOUBLE
77 : REAL(C_DOUBLE) :: eps_singularity_curvatures = -1.0_C_DOUBLE
78 : REAL(C_DOUBLE) :: eps_mu = -1.0_C_DOUBLE
79 : REAL(C_DOUBLE) :: eps_eigval_degen = -1.0_C_DOUBLE
80 : REAL(C_DOUBLE) :: eps_fermi = -1.0_C_DOUBLE
81 : REAL(C_DOUBLE) :: energy_interval = -1.0_C_DOUBLE
82 : REAL(C_DOUBLE) :: min_interval = -1.0_C_DOUBLE
83 : REAL(C_DOUBLE) :: temperature = -1.0_C_DOUBLE
84 : REAL(C_DOUBLE) :: dens_mixing = -1.0_C_DOUBLE
85 : REAL(C_DOUBLE) :: n_rand_beyn = -1.0_C_DOUBLE
86 : REAL(C_DOUBLE) :: n_rand_cc_beyn = -1.0_C_DOUBLE
87 : REAL(C_DOUBLE) :: svd_cutoff = -1.0_C_DOUBLE
88 : TYPE(C_PTR) :: contacts_data = C_NULL_PTR
89 : TYPE(C_PTR) :: nsgf = C_NULL_PTR
90 : TYPE(C_PTR) :: zeff = C_NULL_PTR
91 : LOGICAL(C_BOOL) :: obc_equilibrium = .FALSE._C_BOOL
92 : LOGICAL(C_BOOL) :: extra_scf = .FALSE._C_BOOL
93 : END TYPE cp2k_transport_parameters
94 :
95 : TYPE transport_env_type
96 : TYPE(C_FUNPTR) :: ext_c_method_ptr = C_NULL_FUNPTR
97 : TYPE(cp2k_transport_parameters) :: params = cp2k_transport_parameters()
98 : TYPE(dbcsr_type) :: template_matrix_sym = dbcsr_type()
99 : TYPE(dbcsr_type) :: template_matrix_nosym = dbcsr_type()
100 : TYPE(dbcsr_type) :: csr_sparsity = dbcsr_type()
101 : TYPE(dbcsr_type), POINTER :: dm_imag => NULL()
102 : TYPE(dbcsr_csr_type) :: s_matrix = dbcsr_csr_type()
103 : TYPE(dbcsr_csr_type) :: ks_matrix = dbcsr_csr_type()
104 : TYPE(dbcsr_csr_type) :: p_matrix = dbcsr_csr_type()
105 : TYPE(dbcsr_csr_type) :: imagp_matrix = dbcsr_csr_type()
106 : LOGICAL :: csr_screening = .FALSE.
107 : INTEGER, DIMENSION(:), POINTER :: contacts_data => NULL()
108 : INTEGER, DIMENSION(:), POINTER :: nsgf => NULL()
109 : REAL(dp), DIMENSION(:), POINTER :: zeff => NULL()
110 : END TYPE transport_env_type
111 :
112 : ! DO NOT change the ORDERING or the NAMES in the following data type
113 : TYPE, BIND(C) :: cp2k_csr_interop_type
114 : INTEGER(C_INT) :: nrows_total = -1_C_INT
115 : INTEGER(C_INT) :: ncols_total = -1_C_INT
116 : INTEGER(C_INT) :: nze_total = -1_C_INT
117 : INTEGER(C_INT) :: nze_local = -1_C_INT
118 : INTEGER(C_INT) :: nrows_local = -1_C_INT
119 : INTEGER(C_INT) :: data_type = -1_C_INT
120 : INTEGER(C_INT) :: first_row = -1_C_INT
121 : TYPE(C_PTR) :: rowptr_local = C_NULL_PTR
122 : TYPE(C_PTR) :: colind_local = C_NULL_PTR
123 : TYPE(C_PTR) :: nzerow_local = C_NULL_PTR
124 : TYPE(C_PTR) :: nzvals_local = C_NULL_PTR
125 : END TYPE cp2k_csr_interop_type
126 :
127 : PUBLIC :: csr_interop_nullify, &
128 : csr_interop_matrix_get_info
129 : PUBLIC :: transport_env_release
130 :
131 : CONTAINS
132 :
133 : ! **************************************************************************************************
134 : !> \brief releases the transport_env
135 : !> \param[inout] transport_env the transport_env to be released
136 : !> \author Mohammad Hossein Bani-Hashemian
137 : ! **************************************************************************************************
138 0 : SUBROUTINE transport_env_release(transport_env)
139 : TYPE(transport_env_type), POINTER :: transport_env
140 :
141 : CHARACTER(len=*), PARAMETER :: routineN = 'transport_env_release'
142 :
143 : INTEGER :: handle
144 :
145 0 : CALL timeset(routineN, handle)
146 :
147 0 : CPASSERT(ASSOCIATED(transport_env))
148 :
149 0 : IF (C_ASSOCIATED(transport_env%ext_c_method_ptr)) THEN
150 0 : CALL dbcsr_csr_destroy(transport_env%s_matrix)
151 0 : CALL dbcsr_csr_destroy(transport_env%ks_matrix)
152 0 : CALL dbcsr_csr_destroy(transport_env%p_matrix)
153 0 : CALL dbcsr_csr_destroy(transport_env%imagp_matrix)
154 0 : CALL dbcsr_release(transport_env%template_matrix_sym)
155 0 : CALL dbcsr_release(transport_env%template_matrix_nosym)
156 0 : CALL dbcsr_release(transport_env%csr_sparsity)
157 0 : CALL dbcsr_deallocate_matrix(transport_env%dm_imag)
158 : END IF
159 :
160 0 : transport_env%ext_c_method_ptr = C_NULL_FUNPTR
161 :
162 0 : IF (ASSOCIATED(transport_env%contacts_data)) DEALLOCATE (transport_env%contacts_data)
163 0 : IF (ASSOCIATED(transport_env%nsgf)) DEALLOCATE (transport_env%nsgf)
164 0 : IF (ASSOCIATED(transport_env%zeff)) DEALLOCATE (transport_env%zeff)
165 :
166 0 : DEALLOCATE (transport_env)
167 :
168 0 : CALL timestop(handle)
169 :
170 0 : END SUBROUTINE transport_env_release
171 :
172 : ! **************************************************************************************************
173 : !> \brief nullifies (and zeroizes) a C-interoperable CSR matrix
174 : !> \param[inout] csr_interop_mat the matrix to be nullified
175 : !> \author Mohammad Hossein Bani-Hashemian
176 : ! **************************************************************************************************
177 0 : SUBROUTINE csr_interop_nullify(csr_interop_mat)
178 :
179 : TYPE(cp2k_csr_interop_type), INTENT(INOUT) :: csr_interop_mat
180 :
181 : CHARACTER(LEN=*), PARAMETER :: routineN = 'csr_interop_nullify'
182 :
183 : INTEGER :: handle
184 :
185 0 : CALL timeset(routineN, handle)
186 :
187 0 : csr_interop_mat%nrows_total = 0
188 0 : csr_interop_mat%ncols_total = 0
189 0 : csr_interop_mat%nze_total = 0
190 0 : csr_interop_mat%nze_local = 0
191 0 : csr_interop_mat%nrows_local = 0
192 0 : csr_interop_mat%data_type = 0
193 0 : csr_interop_mat%first_row = 0
194 0 : csr_interop_mat%rowptr_local = C_NULL_PTR
195 0 : csr_interop_mat%colind_local = C_NULL_PTR
196 0 : csr_interop_mat%nzerow_local = C_NULL_PTR
197 0 : csr_interop_mat%nzvals_local = C_NULL_PTR
198 :
199 0 : CALL timestop(handle)
200 :
201 0 : END SUBROUTINE csr_interop_nullify
202 :
203 : ! **************************************************************************************************
204 : !> \brief gets the fields of a C-interoperable CSR matrix
205 : !> \param[in] csr_interop_mat C-interoperable CSR matrix
206 : !> \param[out] nrows_total total number of rows
207 : !> \param[out] ncols_total total number of columns
208 : !> \param[out] nze_local number of local nonzero elements
209 : !> \param[out] nze_total total number of nonzero elements
210 : !> \param[out] nrows_local number of local rows
211 : !> \param[out] data_type data type
212 : !> \param[out] first_row index of the first row (C indexing)
213 : !> \param[out] rowptr_local row pointer (local - Fortran indexing)
214 : !> \param[out] colind_local column index (local - Fortran indexing)
215 : !> \param[out] nzerow_local number of nunzeros per row (index-i, local - Fortran indexing)
216 : !> \param[out] nzvals_local nonzero elements (local)
217 : !> \author Mohammad Hossein Bani-Hashemian
218 : ! **************************************************************************************************
219 0 : SUBROUTINE csr_interop_matrix_get_info(csr_interop_mat, &
220 : nrows_total, ncols_total, nze_local, nze_total, nrows_local, data_type, &
221 : first_row, rowptr_local, colind_local, nzerow_local, nzvals_local)
222 :
223 : TYPE(cp2k_csr_interop_type), INTENT(IN) :: csr_interop_mat
224 : INTEGER, INTENT(OUT), OPTIONAL :: nrows_total, ncols_total, nze_local, &
225 : nze_total, nrows_local, data_type, &
226 : first_row
227 : INTEGER, DIMENSION(:), INTENT(OUT), OPTIONAL, &
228 : POINTER :: rowptr_local, colind_local, nzerow_local
229 : REAL(dp), DIMENSION(:), INTENT(OUT), OPTIONAL, &
230 : POINTER :: nzvals_local
231 :
232 : CHARACTER(LEN=*), PARAMETER :: routineN = 'csr_interop_matrix_get_info'
233 :
234 : INTEGER :: handle
235 :
236 0 : CALL timeset(routineN, handle)
237 :
238 0 : IF (PRESENT(nrows_total)) nrows_total = csr_interop_mat%nrows_total
239 0 : IF (PRESENT(ncols_total)) ncols_total = csr_interop_mat%ncols_total
240 0 : IF (PRESENT(nze_local)) nze_local = csr_interop_mat%nze_local
241 0 : IF (PRESENT(nze_total)) nze_total = csr_interop_mat%nze_total
242 0 : IF (PRESENT(nrows_local)) nrows_local = csr_interop_mat%nrows_local
243 0 : IF (PRESENT(data_type)) data_type = csr_interop_mat%data_type
244 0 : IF (PRESENT(first_row)) first_row = csr_interop_mat%first_row
245 :
246 0 : IF (PRESENT(rowptr_local)) CALL C_F_POINTER(csr_interop_mat%rowptr_local, rowptr_local, [nrows_local + 1])
247 0 : IF (PRESENT(colind_local)) CALL C_F_POINTER(csr_interop_mat%colind_local, colind_local, [nze_local])
248 0 : IF (PRESENT(nzerow_local)) CALL C_F_POINTER(csr_interop_mat%nzerow_local, nzerow_local, [nrows_local])
249 0 : IF (PRESENT(nzvals_local)) CALL C_F_POINTER(csr_interop_mat%nzvals_local, nzvals_local, [nze_local])
250 :
251 0 : CALL timestop(handle)
252 :
253 0 : END SUBROUTINE csr_interop_matrix_get_info
254 :
255 0 : END MODULE transport_env_types
256 :
|