Octopus
projector_matrix.F90
Go to the documentation of this file.
1!! Copyright (C) 2010 X. Andrade
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use debug_oct_m
23 use global_oct_m
24 use math_oct_m
28
29 implicit none
30
31 private
32
33 public :: &
38
41 ! Components are public by default
43 real(real64), pointer, contiguous :: dprojectors(:, :) => null()
44 complex(real64), pointer, contiguous :: zprojectors(:, :) => null()
45 real(real64), allocatable :: scal(:)
46 integer :: npoints
47 integer :: nprojs
48 integer :: nregions
49 integer, allocatable :: regions(:)
54 real(real64), allocatable :: dmix(:, :, :)
55 complex(real64), allocatable :: zmix(:, :, :)
59 real(real64), allocatable :: qmix(:, :)
64 complex(real64), allocatable :: zqmix(:, :, :)
65 integer, allocatable :: l(:)
66 integer, allocatable :: m(:)
67 integer, allocatable :: channel(:)
68 integer, allocatable :: beta_index(:)
69 logical :: is_cmplx = .false.
70
71 integer, pointer, contiguous :: map(:)
72 real(real64), pointer, contiguous :: position(:, :)
75 real(real64), allocatable :: sphere_weights(:)
76
81 real(real64), pointer, contiguous :: aug_ylm(:, :) => null()
82 end type projector_matrix_t
83
84contains
85
86 ! -------------------------------------------------
87 subroutine projector_matrix_allocate(this, nprojs, sphere, has_mix_matrix, is_cmplx, complex_mix, nspin_channels)
88 type(projector_matrix_t), intent(out) :: this
89 integer, intent(in) :: nprojs
90 type(submesh_t), intent(in) :: sphere
91 logical, intent(in) :: has_mix_matrix
92 logical, optional, intent(in) :: is_cmplx
93 logical, optional, intent(in) :: complex_mix
94 integer, optional, intent(in) :: nspin_channels
95
96 logical :: complex_mix_
97 integer :: nspin_channels_
98
100
101 this%npoints = sphere%np
102 this%nprojs = nprojs
103 this%nregions = sphere%num_regions
104 nullify(this%map)
105 nullify(this%position)
106
107 this%is_cmplx = optional_default(is_cmplx, .false.)
108 complex_mix_ = optional_default(complex_mix, this%is_cmplx)
109
110 safe_allocate(this%regions(1:this%nregions+1))
111 if (this%is_cmplx) then
112 safe_allocate(this%zprojectors(1:this%npoints, 1:nprojs))
113 else
114 safe_allocate(this%dprojectors(1:this%npoints, 1:nprojs))
115 end if
116 safe_allocate(this%scal(1:nprojs))
117 safe_allocate(this%l(1:nprojs))
118 safe_allocate(this%m(1:nprojs))
119 safe_allocate(this%channel(1:nprojs))
120 safe_allocate(this%beta_index(1:nprojs))
121 this%l = -1
122 this%m = 0
123 this%channel = 0
124 this%beta_index = 0
125
126 nspin_channels_ = optional_default(nspin_channels, 1)
127 assert(nspin_channels_ == 1 .or. nspin_channels_ == 2)
128
129 if (has_mix_matrix) then
130 if (complex_mix_) then
131 safe_allocate(this%zmix(1:nprojs, 1:nprojs, 1:4))
132 else
133 safe_allocate(this%dmix(1:nprojs, 1:nprojs, 1:nspin_channels_))
134 end if
135 end if
140 ! -------------------------------------------------
142 subroutine projector_matrix_deallocate(this, owns_data)
143 type(projector_matrix_t), intent(inout) :: this
146 logical, optional, intent(in) :: owns_data
149
150 safe_deallocate_a(this%regions)
151 if (optional_default(owns_data, .true.)) then
152 safe_deallocate_p(this%dprojectors)
153 safe_deallocate_p(this%zprojectors)
154 end if
155 nullify(this%dprojectors)
156 nullify(this%zprojectors)
157 ! aug_ylm is never shared (built lazily per instance): always owned
158 safe_deallocate_p(this%aug_ylm)
159 nullify(this%aug_ylm)
160 safe_deallocate_a(this%scal)
161 safe_deallocate_a(this%sphere_weights)
162 safe_deallocate_a(this%dmix)
163 safe_deallocate_a(this%zmix)
164 safe_deallocate_a(this%qmix)
165 safe_deallocate_a(this%zqmix)
166 safe_deallocate_a(this%l)
167 safe_deallocate_a(this%m)
168 safe_deallocate_a(this%channel)
169 safe_deallocate_a(this%beta_index)
170
171 nullify(this%position)
172 nullify(this%map)
173 this%npoints = 0
174 this%nprojs = 0
175 this%nregions = 0
176 this%is_cmplx = .false.
177
179 end subroutine projector_matrix_deallocate
180
181 ! -------------------------------------------------
189 subroutine projector_matrix_build_aug_ylm(this, lmaxq)
190 type(projector_matrix_t), intent(inout) :: this
191 integer, intent(in) :: lmaxq
192
193 integer :: ltot, mtot, lm, is
194
195 if (associated(this%aug_ylm)) return
196
198
199 safe_allocate(this%aug_ylm(1:this%npoints, 1:(lmaxq + 1)**2))
200 do ltot = 0, lmaxq
201 do mtot = -ltot, ltot
202 lm = ltot*(ltot + 1) + mtot + 1
203 do is = 1, this%npoints
204 call ylmr_real(this%position(1:3, is), ltot, mtot, this%aug_ylm(is, lm))
205 end do
206 end do
207 end do
208
210 end subroutine projector_matrix_build_aug_ylm
211
212 ! -------------------------------------------------
213
215
216!! Local Variables:
217!! mode: f90
218!! coding: utf-8
219!! End:
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
subroutine, public ylmr_real(xx, li, mi, ylm)
This is a Numerical Recipes-based subroutine computes real spherical harmonics ylm at position (x,...
Definition: math.F90:367
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public projector_matrix_deallocate(this, owns_data)
subroutine, public projector_matrix_allocate(this, nprojs, sphere, has_mix_matrix, is_cmplx, complex_mix, nspin_channels)
subroutine, public projector_matrix_build_aug_ylm(this, lmaxq)
Build (once, lazily) the cached real spherical harmonics Y_LM at the sphere points.
A set of projectors defined on a submesh.
int true(void)