(git:374b731)
Loading...
Searching...
No Matches
negf_green_cache.F
Go to the documentation of this file.
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 Storage to keep precomputed surface Green's functions
10! **************************************************************************************************
12 USE cp_cfm_types, ONLY: cp_cfm_release,&
14 USE kinds, ONLY: dp
15 USE util, ONLY: sort
16#include "./base/base_uses.f90"
17
18 IMPLICIT NONE
19 PRIVATE
20
21 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'negf_green_cache'
22 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .true.
23
25
29
30! **************************************************************************************************
31!> \brief Storage to keep surface Green's functions.
32!> \author Sergey Chulkov
33! **************************************************************************************************
35 !> retarded surface Green's functions [ncontacts, nnodes]
36 TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:, :) :: g_surf_contacts
37 !> list of points over the normalised interval [-1 .. 1].
38 !> Coordinates of actual point where Green's functions were evaluated
39 !> can be obtained by using an appropriate rescale_nodes_*() subroutine
40 !> from the module 'negf_integr_utils'.
41 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: tnodes
43
44CONTAINS
45! **************************************************************************************************
46!> \brief Reallocate storage so it can handle extra 'nnodes_extra' items for each contact.
47!> \param cache storage to expand
48!> \param ncontacts number of contacts
49!> \param nnodes_extra number of items to add
50!> \author Sergey Chulkov
51! **************************************************************************************************
52 SUBROUTINE green_functions_cache_expand(cache, ncontacts, nnodes_extra)
53 TYPE(green_functions_cache_type), INTENT(inout) :: cache
54 INTEGER, INTENT(in) :: ncontacts, nnodes_extra
55
56 INTEGER :: nentries_exist
57 LOGICAL :: is_alloc
58 TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:, :) :: g_surf_contacts
59
60 is_alloc = ALLOCATED(cache%g_surf_contacts)
61
62 IF (is_alloc) THEN
63 cpassert(SIZE(cache%g_surf_contacts, 1) == ncontacts)
64 nentries_exist = SIZE(cache%g_surf_contacts, 2)
65
66 ELSE
67 nentries_exist = 0
68 END IF
69
70 ALLOCATE (g_surf_contacts(ncontacts, nentries_exist + nnodes_extra))
71
72 IF (is_alloc) THEN
73 g_surf_contacts(1:ncontacts, 1:nentries_exist) = cache%g_surf_contacts(1:ncontacts, 1:nentries_exist)
74 DEALLOCATE (cache%g_surf_contacts)
75 END IF
76
77 CALL move_alloc(g_surf_contacts, cache%g_surf_contacts)
78 END SUBROUTINE green_functions_cache_expand
79
80! **************************************************************************************************
81!> \brief Sort cached items in ascending order.
82!> \param cache storage to reorder
83!> \param tnodes coordinate of items in storage
84!> \author Sergey Chulkov
85! **************************************************************************************************
86 SUBROUTINE green_functions_cache_reorder(cache, tnodes)
87 TYPE(green_functions_cache_type), INTENT(inout) :: cache
88 REAL(kind=dp), DIMENSION(:), INTENT(in) :: tnodes
89
90 INTEGER :: ind_new, ind_old, ncontacts, nnodes
91 INTEGER, ALLOCATABLE, DIMENSION(:) :: indices
92 TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:, :) :: g_surf_contacts
93
94 nnodes = SIZE(tnodes)
95
96 cpassert(ALLOCATED(cache%g_surf_contacts))
97 cpassert(SIZE(cache%g_surf_contacts, 2) == nnodes)
98
99 ncontacts = SIZE(cache%g_surf_contacts, 1)
100
101 IF (ALLOCATED(cache%tnodes)) DEALLOCATE (cache%tnodes)
102
103 ALLOCATE (g_surf_contacts(ncontacts, nnodes))
104 ALLOCATE (cache%tnodes(nnodes))
105 ALLOCATE (indices(nnodes))
106
107 cache%tnodes(:) = tnodes(:)
108 CALL sort(cache%tnodes, nnodes, indices)
109
110 DO ind_new = 1, nnodes
111 ind_old = indices(ind_new)
112 g_surf_contacts(1:ncontacts, ind_new) = cache%g_surf_contacts(1:ncontacts, ind_old)
113 END DO
114
115 CALL move_alloc(g_surf_contacts, cache%g_surf_contacts)
116 END SUBROUTINE green_functions_cache_reorder
117
118! **************************************************************************************************
119!> \brief Release storage.
120!> \param cache storage to release
121!> \author Sergey Chulkov
122! **************************************************************************************************
124 TYPE(green_functions_cache_type), INTENT(inout) :: cache
125
126 INTEGER :: icontact, ipoint, ncontacts
127
128 IF (ALLOCATED(cache%tnodes)) DEALLOCATE (cache%tnodes)
129
130 IF (ALLOCATED(cache%g_surf_contacts)) THEN
131 ncontacts = SIZE(cache%g_surf_contacts, 1)
132 DO ipoint = SIZE(cache%g_surf_contacts, 2), 1, -1
133 DO icontact = ncontacts, 1, -1
134 CALL cp_cfm_release(cache%g_surf_contacts(icontact, ipoint))
135 END DO
136 END DO
137
138 DEALLOCATE (cache%g_surf_contacts)
139 END IF
140 END SUBROUTINE green_functions_cache_release
141END MODULE negf_green_cache
142
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Storage to keep precomputed surface Green's functions.
subroutine, public green_functions_cache_reorder(cache, tnodes)
Sort cached items in ascending order.
subroutine, public green_functions_cache_release(cache)
Release storage.
subroutine, public green_functions_cache_expand(cache, ncontacts, nnodes_extra)
Reallocate storage so it can handle extra 'nnodes_extra' items for each contact.
All kind of helpful little routines.
Definition util.F:14
Represent a complex full matrix.
Storage to keep surface Green's functions.