(git:6344619)
Loading...
Searching...
No Matches
ri_rs_types.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Shared real-space resolution-of-identity grid and matrix data.
10! **************************************************************************************************
13 USE cell_types, ONLY: cell_type
14 USE cp_dbcsr_api, ONLY: dbcsr_release,&
16 USE kinds, ONLY: dp
18 USE physcon, ONLY: angstrom
19#include "./base/base_uses.f90"
20
21 IMPLICIT NONE
22 PRIVATE
24
25 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ri_rs_types'
26
27 ! Atom-relative RI-RS grids
29 INTEGER :: npts = 0
30 REAL(kind=dp), ALLOCATABLE :: raw_points(:, :)
31 END TYPE rirs_grid_type
32
33 ! User input for the in-memory RI-RS grid optimization.
35 LOGICAL :: enabled = .false.
36 REAL(kind=dp) :: cutoff_atomic_cluster = 3.0_dp/angstrom
37 REAL(kind=dp) :: rs_ao_ratio = 5.0_dp
38 INTEGER :: max_iter = 300
39 END TYPE ri_rs_grid_opt_type
40
42
43 ! Input parameters for RI-RS
44 INTEGER :: grid_select = 1
45 REAL(kind=dp) :: tikhonov = 1.0e-08_dp
46 REAL(kind=dp) :: cutoff_radius_ri_ao = -1.0_dp
47 REAL(kind=dp) :: cutoff_radius_v_w = -1.0_dp
49
50 ! Geometry references used by RI-RS grid setup and optimization.
51 ! They remain owned by qs_env and must never be deallocated here.
52 TYPE(cell_type), POINTER :: cell => null()
53 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set => null()
54 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set => null()
55
56 ! Data types for cutoffs based DBCSR matrices
57 REAL(kind=dp), ALLOCATABLE :: chunk_centroids(:, :)
58 INTEGER, ALLOCATABLE :: grid_atom_boundaries(:)
59 INTEGER, ALLOCATABLE :: pan_first(:), pan_last(:)
60 ! Panel plans share a fixed grid, process layout and message limit until release.
61 REAL(kind=dp) :: panel_plan_cutoff = 0.0_dp
62
63 ! Atom-specific grids used directly by the grid assembler
64 TYPE(rirs_grid_type), ALLOCATABLE :: atomic_grids(:)
65
66 ! Data types for storing RI-RS matrices
67 INTEGER :: n_grid_points = 0
68 TYPE(dbcsr_type) :: mat_phi_mu_l = dbcsr_type()
69 TYPE(dbcsr_type) :: mat_z_lp = dbcsr_type()
70 REAL(kind=dp), ALLOCATABLE :: grid_points(:, :)
71 LOGICAL :: z_lp_exists = .false.
72
73 ! Dense Gram + phi + threaded RHS memory model, collected during fitting setup.
74 INTEGER :: fit_max_grid = 0
75 REAL(kind=dp) :: fit_peak_bytes = 0.0_dp
76
77 ! Spatial extent of most diffuse Gaussian primitive of AO/RI basis for each atom
78 REAL(kind=dp), ALLOCATABLE :: radius_ao_per_atom(:)
79 REAL(kind=dp), ALLOCATABLE :: radius_ri_per_atom(:)
80
81 ! Precomputed grid-basis kernels for RT-BSE
82 ! mat_V_aux_rtbse(P, Q) = truncated-Coulomb V_PQ with M^-1 sandwich (RI x RI);
83 ! the Hartree grid kernel Z V Z^T is applied factorized, never materialized
84 ! mat_W0_grid_rtbse(l, l') = sum_PQ Z_lP W^{w=0}_PQ Z_l'Q
85 TYPE(dbcsr_type) :: mat_v_aux_rtbse = dbcsr_type()
86 TYPE(dbcsr_type) :: mat_w0_grid_rtbse = dbcsr_type()
87
88 ! RTBSE%EPS_FILTER_RHO: cuts Delta-rho_AO in compute_sigma_ri_rs, also cuts SEX and Hartree
89 REAL(kind=dp) :: eps_filter_rho = -1.0_dp
90
91 ! RTBSE%CUTOFF_RADIUS_W0 (bohr): drops grid block pairs of W0 beyond this distance.
92 ! BSE-only: the GW quasiparticle energies use their own &GW CUTOFF_RADIUS_* family.
93 REAL(kind=dp) :: cutoff_radius_w0 = -1.0_dp
94
95 ! Set TRUE once mat_phi_mu_l and mat_Z_lP have been populated in memory (by GW RI-RS
96 ! or on-demand by the RT-BSE RI-RS kernel path).
97 LOGICAL :: grid_built = .false.
98
99 ! Independent toggles for auxiliary Coulomb / grid W0 availability
100 LOGICAL :: v_grid_built = .false.
101 LOGICAL :: w0_grid_built = .false.
102
103 END TYPE ri_rs_env
104
105CONTAINS
106
107! **************************************************************************************************
108!> \brief Release owned RI-RS matrices and grid data, then clear construction state.
109!> Input settings and restart-file availability are retained. Geometry references are
110!> borrowed from qs_env and are only nullified. Repeated calls are safe.
111!> \param ri_rs RI-RS input, owned grid/matrix data and borrowed geometry references
112! **************************************************************************************************
113 SUBROUTINE ri_rs_release(ri_rs)
114 TYPE(ri_rs_env), INTENT(INOUT) :: ri_rs
115
116 CHARACTER(LEN=*), PARAMETER :: routinen = 'ri_rs_release'
117
118 INTEGER :: handle
119
120 CALL timeset(routinen, handle)
121
122 IF (ri_rs%W0_grid_built) CALL dbcsr_release(ri_rs%mat_W0_grid_rtbse)
123 IF (ri_rs%V_grid_built) CALL dbcsr_release(ri_rs%mat_V_aux_rtbse)
124 IF (ri_rs%grid_built) THEN
125 CALL dbcsr_release(ri_rs%mat_phi_mu_l)
126 CALL dbcsr_release(ri_rs%mat_Z_lP)
127 END IF
128 IF (ALLOCATED(ri_rs%grid_points)) DEALLOCATE (ri_rs%grid_points)
129 IF (ALLOCATED(ri_rs%atomic_grids)) DEALLOCATE (ri_rs%atomic_grids)
130 IF (ALLOCATED(ri_rs%radius_ao_per_atom)) DEALLOCATE (ri_rs%radius_ao_per_atom)
131 IF (ALLOCATED(ri_rs%radius_ri_per_atom)) DEALLOCATE (ri_rs%radius_ri_per_atom)
132 IF (ALLOCATED(ri_rs%chunk_centroids)) DEALLOCATE (ri_rs%chunk_centroids)
133 IF (ALLOCATED(ri_rs%grid_atom_boundaries)) DEALLOCATE (ri_rs%grid_atom_boundaries)
134 IF (ALLOCATED(ri_rs%pan_first)) DEALLOCATE (ri_rs%pan_first)
135 IF (ALLOCATED(ri_rs%pan_last)) DEALLOCATE (ri_rs%pan_last)
136 ri_rs%panel_plan_cutoff = 0.0_dp
137 NULLIFY (ri_rs%atomic_kind_set, ri_rs%cell, ri_rs%particle_set)
138 ri_rs%fit_max_grid = 0
139 ri_rs%fit_peak_bytes = 0.0_dp
140 ri_rs%n_grid_points = 0
141 ri_rs%grid_built = .false.
142 ri_rs%V_grid_built = .false.
143 ri_rs%W0_grid_built = .false.
144
145 CALL timestop(handle)
146
147 END SUBROUTINE ri_rs_release
148
149END MODULE ri_rs_types
Define the atomic kind types and their sub types.
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public dbcsr_release(matrix)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Define the data structure for the particle information.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public angstrom
Definition physcon.F:144
Shared real-space resolution-of-identity grid and matrix data.
Definition ri_rs_types.F:11
subroutine, public ri_rs_release(ri_rs)
Release owned RI-RS matrices and grid data, then clear construction state. Input settings and restart...
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60