Octopus
augmentation_mixer.F90
Go to the documentation of this file.
1!! Copyright (C) 2026 N. Tancogne-Dejean
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
35 use debug_oct_m
36 use global_oct_m
39 use mix_oct_m
42 use types_oct_m
43
44 implicit none
45
46 private
47
48 public :: &
56
58 private
59 logical :: apply = .false.
60 integer :: size = 0
61 type(mixfield_t) :: field
62 real(real64), allocatable :: tmp(:, :)
64
65contains
66
67 ! ---------------------------------------------------------
68 subroutine augmentation_mixer_init_auxmixer(namespace, mixer, smix, hm)
69 type(namespace_t), intent(in) :: namespace
70 type(augmentation_mixer_t), intent(inout) :: mixer
71 type(mix_t), intent(inout) :: smix
72 type(hamiltonian_elec_t), intent(in) :: hm
73
75
76 ! Only PAW builds a one-center density matrix; ultrasoft-only runs screen D purely with the
77 ! (already mixed) mesh potential, so there is nothing extra to mix there.
78 ! The matrix exists as soon as the projectors are built, which is the case at this point.
79 if (hm%ep%has_paw .and. hm%vnl%nprojector_matrices > 0 &
80 .and. .not. allocated(hm%aug_overlap%onsite_density_matrix)) then
81 message(1) = "Internal error: the PAW one-center density matrix is not allocated,"
82 message(2) = "it cannot be mixed."
83 call messages_fatal(2, namespace=namespace)
84 end if
85 if (hm%ep%has_paw .and. allocated(hm%aug_overlap%onsite_density_matrix)) then
86 mixer%apply = .true.
87 mixer%size = product(shape(hm%aug_overlap%onsite_density_matrix))
88 safe_allocate(mixer%tmp(1:mixer%size, 1:1))
89 call mixfield_init(smix, mixer%field, mixer%size, 1, mix_d3(smix), type_float)
90 call mixfield_clear(mix_scheme(smix), mixer%field)
91 call mix_add_auxmixfield(namespace, smix, mixer%field)
92 else
93 mixer%apply = .false.
94 end if
95
98
99 ! ---------------------------------------------------------
100 subroutine augmentation_mixer_clear(mixer, smix)
101 type(augmentation_mixer_t), intent(inout) :: mixer
102 type(mix_t), intent(inout) :: smix
103
104 if (.not. mixer%apply) return
107 call mixfield_clear(mix_scheme(smix), mixer%field)
108
110 end subroutine augmentation_mixer_clear
111
112 ! ---------------------------------------------------------
113 subroutine augmentation_mixer_end(mixer, smix)
114 type(augmentation_mixer_t), intent(inout) :: mixer
115 type(mix_t), intent(inout) :: smix
116
117 if (.not. mixer%apply) return
118 push_sub(augmentation_mixer_end)
119
120 call mixfield_end(smix, mixer%field)
121 safe_deallocate_a(mixer%tmp)
122 mixer%apply = .false.
123
125 end subroutine augmentation_mixer_end
126
127 ! ---------------------------------------------------------
128 subroutine augmentation_mixer_set_vout(mixer, hm)
129 type(augmentation_mixer_t), intent(inout) :: mixer
130 type(hamiltonian_elec_t), intent(in) :: hm
132 if (.not. mixer%apply) return
135 mixer%tmp(1:mixer%size, 1) = reshape(hm%aug_overlap%onsite_density_matrix, [mixer%size])
136 call mixfield_set_vout(mixer%field, mixer%tmp)
137
139 end subroutine augmentation_mixer_set_vout
141 ! ---------------------------------------------------------
142 subroutine augmentation_mixer_set_vin(mixer, hm)
143 type(augmentation_mixer_t), intent(inout) :: mixer
144 type(hamiltonian_elec_t), intent(in) :: hm
145
146 if (.not. mixer%apply) return
148
149 mixer%tmp(1:mixer%size, 1) = reshape(hm%aug_overlap%onsite_density_matrix, [mixer%size])
150 call mixfield_set_vin(mixer%field, mixer%tmp)
151
153 end subroutine augmentation_mixer_set_vin
154
155 ! ---------------------------------------------------------
156 subroutine augmentation_mixer_get_vnew(mixer, hm)
157 type(augmentation_mixer_t), intent(inout) :: mixer
158 type(hamiltonian_elec_t), intent(inout) :: hm
159
160 if (.not. mixer%apply) return
162
163 call mixfield_get_vnew(mixer%field, mixer%tmp)
164 hm%aug_overlap%onsite_density_matrix = &
165 reshape(mixer%tmp(1:mixer%size, 1), shape(hm%aug_overlap%onsite_density_matrix))
166
168 end subroutine augmentation_mixer_get_vnew
169
171
172!! Local Variables:
173!! mode: f90
174!! coding: utf-8
175!! End:
Auxiliary SCF mixer for the PAW one-center density matrix.
subroutine, public augmentation_mixer_clear(mixer, smix)
subroutine, public augmentation_mixer_get_vnew(mixer, hm)
subroutine, public augmentation_mixer_init_auxmixer(namespace, mixer, smix, hm)
subroutine, public augmentation_mixer_set_vin(mixer, hm)
subroutine, public augmentation_mixer_end(mixer, smix)
subroutine, public augmentation_mixer_set_vout(mixer, hm)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public mixfield_end(smix, mixfield)
Deallocate all arrays of a mixfield instance.
Definition: mix.F90:908
integer pure function, public mix_scheme(this)
Definition: mix.F90:807
subroutine, public mixfield_init(smix, mixfield, d1, d2, d3, func_type)
Initialise all attributes of a mixfield instance.
Definition: mix.F90:861
subroutine, public mix_add_auxmixfield(namespace, smix, mixfield)
Definition: mix.F90:842
subroutine, public mixfield_clear(scheme, mixfield)
Zero all potential and field attributes of a mixfield instance.
Definition: mix.F90:945
integer pure function, public mix_d3(this)
Definition: mix.F90:813
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
type(type_t), parameter, public type_float
Definition: types.F90:113
int true(void)