55 class(*),
intent(inout) :: system
61 message(1) =
"CalculationMode = invert_ks not implemented for multi-system calculations"
72 type(electrons_t),
intent(inout) :: sys
74 integer :: ii, jj, np, nspin
76 real(real64) :: diffdensity
77 real(real64),
allocatable :: target_rho(:,:), rho(:)
78 type(restart_t) :: restart
82 if (sys%hm%pcm%run_pcm)
then
86 if (sys%kpoints%use_symmetries)
then
87 call messages_experimental(
"KPoints symmetries with CalculationMode = invert_ks", namespace=sys%namespace)
90 if (sys%st%d%ispin ==
spinors)
then
99 nspin = sys%st%d%nspin
102 safe_allocate(target_rho(1:np, 1:nspin))
103 safe_allocate(rho(1:np))
107 sys%hm%energy%intnvxc =
m_zero
108 sys%hm%energy%hartree =
m_zero
109 sys%hm%energy%exchange =
m_zero
110 sys%hm%energy%correlation =
m_zero
115 do ii = 2, sys%st%d%spin_channels
120 call dpoisson_solve(sys%hm%psolver, sys%namespace, sys%hm%vhartree, rho)
123 do ii = 1, sys%st%d%spin_channels
124 call lalg_copy(np, sys%hm%vhartree, sys%hm%vhxc(:, ii))
128 write(
message(1),
'(a)')
"Calculating KS potential"
133 sys%ks%ks_inversion%eigensolver, sys%ks%ks_inversion%aux_st, sys%hm, sys%ks%ks_inversion%max_iter)
138 call invertks_2part(sys%ks%ks_inversion, target_rho, nspin, sys%hm, sys%gr, &
139 sys%ks%ks_inversion%aux_st, sys%ks%ks_inversion%eigensolver, sys%namespace, sys%space, &
145 call invertks_iter(sys%ks%ks_inversion, target_rho, sys%namespace, sys%space, sys%ext_partners, nspin, sys%hm, sys%gr, &
146 sys%ks%ks_inversion%aux_st, sys%ks%ks_inversion%eigensolver)
152 sys%ks%ks_inversion%eigensolver, sys%ks%ks_inversion%aux_st, sys%hm, sys%ks%ks_inversion%max_iter)
158 if (abs(sys%ks%ks_inversion%aux_st%rho(ii,jj)-target_rho(ii,jj)) > diffdensity)
then
159 diffdensity = abs(sys%ks%ks_inversion%aux_st%rho(ii,jj)-target_rho(ii,jj))
163 write (
message(1),
'(a,F16.6)')
'Achieved difference in densities wrt target:', &
169 sys%ks%ks_inversion%aux_st, sys%hm, sys%ks)
171 sys%ks%ks_inversion%aux_st)
173 sys%ks%ks_inversion%aux_st%dom_st_kpt_mpi_grp = sys%st%dom_st_kpt_mpi_grp
176 call states_elec_dump(restart, sys%space, sys%ks%ks_inversion%aux_st, sys%gr, sys%kpoints, err, 0)
178 message(1) =
"Unable to write states wavefunctions."
183 safe_deallocate_a(target_rho)
184 safe_deallocate_a(rho)
192 character(len=256) :: filename
193 integer :: pass, iunit, ierr, ii, npoints
194 real(real64) :: l_xx(sys%space%dim), l_ff(nspin), rr
195 real(real64),
allocatable :: xx(:,:), ff(:,:)
196 character(len=1) :: char
210 call parse_variable(sys%namespace,
'InvertKSTargetDensity',
"target_density.dat", filename)
212 iunit =
io_open(filename, sys%namespace, action=
'read', status=
'old')
220 read(iunit,
'(a)', advance=
'no') char
222 if (char ==
'#')
read(iunit,
'(a)') char
224 read(iunit, fmt=*, iostat=ierr) l_xx(:), l_ff(:)
227 if (pass == 1) npoints = npoints + 1
234 safe_allocate(xx(1:npoints, 1:sys%space%dim))
235 safe_allocate(ff(1:npoints, 1:nspin))
241 np, sys%gr%x, target_rho(:, ii))
246 do ii = 1, sys%st%d%spin_channels
247 rr = rr +
dmf_integrate(sys%gr, target_rho(:, ii), reduce = .false.)
249 if (sys%gr%parallel_in_domains)
then
250 call sys%gr%allreduce(rr)
253 target_rho(:,:) = rr*target_rho(:,:)
255 safe_deallocate_a(xx)
256 safe_deallocate_a(ff)
constant times a vector plus a vector
Copies a vector x, to a vector y.
subroutine read_target_rho()
This module implements a calculator for the density and defines related functions.
integer, parameter, public spinors
real(real64), parameter, public m_zero
character(len= *), parameter, public static_dir
real(real64), parameter, public m_one
subroutine, public invert_ks_run(system)
subroutine invert_ks_run_legacy(sys)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
This module defines various routines, operating on mesh functions.
subroutine, public dmf_interpolate_points(ndim, npoints_in, x_in, f_in, npoints_out, x_out, f_out)
This function receives a function f_in defined in a mesh, and returns the interpolated values of the ...
real(real64) function, public dmf_integrate(mesh, ff, mask, reduce)
Integrate a function on the mesh.
subroutine, public messages_not_implemented(feature, namespace)
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_experimental(name, namespace)
This module implements the basic mulsisystem class, a container system for other systems.
subroutine, public output_modelmb(outp, namespace, space, dir, gr, ions, iter, st)
this module contains the output system
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel)
Calculates the Poisson equation. Given the density returns the corresponding potential.
integer, parameter, public restart_gs
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
integer, parameter, public restart_type_dump
subroutine, public restart_end(restart)
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_dump(restart, space, st, mesh, kpoints, ierr, iter, lr, st_start_writing, verbose)
integer, parameter, public xc_inv_method_iter_godby
subroutine, public invertks_2part(ks_inv, target_rho, nspin, aux_hm, gr, st, eigensolver, namespace, space, ext_partners)
Given a density, it performs the Kohn-Sham inversion, assuming a two-particle, one orbital case.
integer, parameter, public xc_inv_method_two_particle
KS inversion methods/algorithms.
integer, parameter, public xc_inv_method_vs_iter
subroutine, public xc_ks_inversion_write_info(ks_inversion, iunit, namespace)
subroutine, public invertks_iter(ks_inv, target_rho, namespace, space, ext_partners, nspin, aux_hm, gr, st, eigensolver)
Iterative inversion of KS potential from the density.
subroutine, public invertks_update_hamiltonian(namespace, gr, space, ext_partners, eigensolver, st, hm, max_iter)
A small auxiliary function to perform the update of the Hamiltonian, run the eigensolver,...
Class describing the electron system.
Container class for lists of system_oct_m::system_t.