58 type(grid_t),
pointer :: gr_aux => null()
59 real(real64),
pointer :: rho_aux(:) => null()
60 real(real64),
allocatable :: diag_lapl(:)
71 subroutine x_fbe_calc (id, namespace, psolver, gr, st, space, ex, vxc)
72 integer,
intent(in) :: id
73 type(namespace_t),
intent(in) :: namespace
74 type(poisson_t),
intent(in) :: psolver
75 type(grid_t),
intent(in) :: gr
76 type(states_elec_t),
intent(inout) :: st
77 type(space_t),
intent(in) :: space
78 real(real64),
intent(inout) :: ex
79 real(real64),
contiguous,
optional,
intent(inout) :: vxc(:,:)
81 real(real64),
allocatable :: fxc(:,:,:), internal_vxc(:,:)
88 call dx_fbe_calc(namespace, psolver, gr, gr%der, st, ex, vxc=vxc)
90 call zx_fbe_calc(namespace, psolver, gr, gr%der, st, ex, vxc=vxc)
93 safe_allocate(fxc(1:gr%np_part, 1:gr%box%dim, 1:st%d%spin_channels))
94 safe_allocate(internal_vxc(1:gr%np, 1:st%d%spin_channels))
98 call dx_fbe_calc(namespace, psolver, gr, gr%der, st, ex, vxc=internal_vxc, fxc=fxc)
100 call zx_fbe_calc(namespace, psolver, gr, gr%der, st, ex, vxc=internal_vxc, fxc=fxc)
104 if (
present(vxc))
then
112 call lalg_axpy(gr%np, st%d%spin_channels,
m_one, internal_vxc, vxc)
114 safe_deallocate_a(fxc)
115 safe_deallocate_a(internal_vxc)
127 type(namespace_t),
intent(in) :: namespace
128 type(grid_t),
target,
intent(in) :: gr
129 type(states_elec_t),
target,
intent(in) :: st
130 type(space_t),
intent(in) :: space
131 real(real64),
contiguous,
intent(inout) :: fxc(:,:,:)
132 real(real64),
contiguous,
intent(inout) :: vxc(:,:)
134 real(real64),
allocatable :: rhs(:)
135 integer :: iter, ispin
137 real(real64),
parameter :: threshold = 1e-7_real64
138 character(len=32) :: name
140 type(nl_operator_t) :: op(1)
144 assert(ubound(fxc, dim=1) >= gr%np_part)
150 name =
'FBE preconditioner'
152 safe_allocate(diag_lapl(1:op(1)%np))
156 safe_allocate(rhs(1:gr%np))
158 do ispin = 1, st%d%spin_channels
160 rho_aux => st%rho(:, ispin)
165 iter, residue = res, threshold = threshold, showprogress = .false.)
167 write(
message(1),
'(a, i6, a)')
"Info: Sturm-Liouville solver converged in ", iter,
" iterations."
168 write(
message(2),
'(a, es14.6)')
"Info: The residue is ", res
172 safe_deallocate_a(rhs)
174 safe_deallocate_a(diag_lapl)
184 real(real64),
contiguous,
intent(in) :: x(:)
185 real(real64),
contiguous,
intent(out) :: hx(:)
188 real(real64),
allocatable :: vxc(:)
189 real(real64),
allocatable :: grad_vxc(:,:)
191 safe_allocate(vxc(1:gr_aux%np_part))
192 safe_allocate(grad_vxc(1:gr_aux%np_part, 1:gr_aux%box%dim))
198 do idir = 1, gr_aux%box%dim
201 grad_vxc(ip, idir) = grad_vxc(ip, idir)*rho_aux(ip)
209 safe_deallocate_a(vxc)
210 safe_deallocate_a(grad_vxc)
218 real(real64),
contiguous,
intent(in) :: x(:)
219 real(real64),
contiguous,
intent(out) :: hx(:)
225 hx(ip) = x(ip) / (max(rho_aux(ip), 1d-12) * diag_lapl(ip))
234 real(real64) function get_virial_energy(gr, nspin, fxc) result(exc)
235 type(
grid_t),
intent(in) :: gr
236 integer,
intent(in) :: nspin
237 real(real64),
intent(in) :: fxc(:,:,:)
239 integer :: isp, idir, ip
240 real(real64),
allocatable :: rfxc(:)
241 real(real64) :: xx(gr%box%dim), rr
243 push_sub(get_virial_energy)
247 safe_allocate(rfxc(1:gr%np))
250 call mesh_r(gr, ip, rr, coords=xx)
251 do idir = 1, gr%box%dim
252 rfxc(ip) = rfxc(ip) + fxc(ip, idir, isp) * xx(idir)
256 safe_deallocate_a(rfxc)
259 pop_sub(get_virial_energy)
269 subroutine lda_c_fbe (st, n_blocks, l_dens, l_dedd, l_zk)
270 type(states_elec_t),
intent(in) :: st
271 integer,
intent(in) :: n_blocks
272 real(real64),
intent(in) :: l_dens(:,:)
273 real(real64),
intent(inout) :: l_dedd(:,:)
274 real(real64),
optional,
intent(inout) :: l_zk(:)
277 real(real64) :: rho, beta, beta2, e_c
283 q = ((5.0_real64*
sqrt(m_pi)**5)/(m_three*(m_one-
log(m_two))))**(m_third)
284 if (
present(l_zk)) l_zk = m_zero
287 rho = sum(l_dens(1:st%d%spin_channels, ip))
288 if (rho < 1e-20_real64)
then
289 l_dedd(1:st%d%spin_channels, ip) = m_zero
292 rho = max(rho, 1e-12_real64)
293 beta = q*rho**m_third
298 l_dedd(1:st%d%spin_channels, ip) = (m_pi/(q**3))*((
sqrt(m_pi)*beta/(m_one+
sqrt(m_pi)*beta))**2 -m_one) * beta
300 l_dedd(1:st%d%spin_channels, ip) = l_dedd(1:st%d%spin_channels, ip) &
301 - (5.0_real64*
sqrt(m_pi))/(m_three*q**3)*(
log(m_one+
sqrt(m_pi)*beta) &
302 -m_half/(m_one+
sqrt(m_pi)*beta)**2 + m_two/(m_one+
sqrt(m_pi)*beta)) + (5.0_real64*
sqrt(m_pi))/(m_two*q**3)
304 if (st%d%nspin == 1 .and.
present(l_zk))
then
307 e_c = (9.0_real64*q**3)/m_two/beta &
308 - m_two*q**3*
sqrt(m_pi) &
309 - 12.0_real64/beta2*(q**3/
sqrt(m_pi)) &
310 + m_three/(m_pi*rho)*(m_one/(m_one+
sqrt(m_pi)*beta) - m_one &
311 + 5.0_real64*
log(m_one+
sqrt(m_pi)*beta))
314 e_c = e_c - 5.0_real64/6.0_real64*( &
315 7.0_real64*q**3/beta &
316 + m_three/(m_pi*rho*(m_one+
sqrt(m_pi)*beta)) &
317 - 17.0_real64*q**3/
sqrt(m_pi)/beta2 &
318 - 11.0_real64*q**3*
sqrt(m_pi)/(m_three) &
319 + (20.0_real64/(m_pi*rho) + m_two*
sqrt(m_pi)*q**3)*
log(m_one+
sqrt(m_pi)*beta) &
320 - m_three/(m_pi*rho))
323 else if(st%d%nspin == 2)
then
326 do ispin = 1, st%d%spin_channels
327 l_dedd(ispin, ip) = l_dedd(ispin, ip) * m_two * l_dens(-ispin+3, ip) / rho
337 subroutine fbe_c_lda_sl (namespace, psolver, gr, st, space, ec, vxc)
338 type(namespace_t),
intent(in) :: namespace
339 type(poisson_t),
intent(in) :: psolver
340 type(grid_t),
intent(in) :: gr
341 type(states_elec_t),
intent(inout) :: st
342 type(space_t),
intent(in) :: space
343 real(real64),
intent(inout) :: ec
344 real(real64),
contiguous,
optional,
intent(inout) :: vxc(:,:)
346 integer :: idir, ip, ispin
347 real(real64),
allocatable :: fxc(:,:,:), internal_vxc(:,:), grad_rho(:,:,:), tmp1(:,:), tmp2(:,:)
348 real(real64) :: q, beta, rho, l_gdens
352 safe_allocate(internal_vxc(1:gr%np, 1:st%d%spin_channels))
355 safe_allocate(tmp1(1:st%d%spin_channels, 1:gr%np))
356 safe_allocate(tmp2(1:st%d%spin_channels, 1:gr%np))
357 tmp1 = transpose(st%rho(1:gr%np, 1:st%d%spin_channels))
359 internal_vxc = transpose(tmp2)
360 safe_deallocate_a(tmp1)
361 safe_deallocate_a(tmp2)
364 q = ((5.0_real64*
sqrt(m_pi)**5)/(m_three*(m_one-
log(m_two))))**(m_third)
366 safe_allocate(fxc(1:gr%np_part, 1:gr%box%dim, 1:st%d%spin_channels))
367 safe_allocate(grad_rho(1:gr%np, 1:gr%box%dim, 1:st%d%spin_channels))
368 do ispin = 1, st%d%spin_channels
369 call dderivatives_grad(gr%der, st%rho(:, ispin), grad_rho(:, :, ispin))
372 do ispin = 1, st%d%spin_channels
373 do idir = 1, gr%box%dim
375 rho = sum(st%rho(ip, 1:st%d%spin_channels))
376 if (st%rho(ip, ispin) < 1e-20_real64)
then
377 fxc(ip, idir, ispin) = m_zero
380 rho = max(rho, 1e-12_real64)
381 beta = rho**m_third * q
383 l_gdens = sum(grad_rho(ip, idir, 1:st%d%spin_channels))
385 if (st%d%spin_channels == 1)
then
386 fxc(ip, idir, ispin) = l_gdens * &
387 ( m_pi * beta**2/((m_one +
sqrt(m_pi)*beta)**2) - m_one &
388 + m_third * m_pi * beta**2 / ((m_one +
sqrt(m_pi)*beta)**3) )
390 fxc(ip, idir, ispin) = m_two * (grad_rho(ip, idir, 3-ispin) * &
391 (m_pi * beta**2/((m_one +
sqrt(m_pi)*beta)**2) - m_one ) &
392 + l_gdens * (m_third * m_pi * beta**2 / ((m_one +
sqrt(m_pi)*beta)**3) ) &
393 * st%rho(ip, 3-ispin) / rho)
396 fxc(ip, idir, ispin) = fxc(ip, idir, ispin) * m_pi/(m_three*beta**2) * st%rho(ip, ispin)
402 if (
present(vxc))
then
410 call lalg_axpy(gr%np, st%d%spin_channels, m_one, internal_vxc, vxc)
412 safe_deallocate_a(fxc)
420#include "xc_fbe_inc.F90"
423#include "complex.F90"
424#include "xc_fbe_inc.F90"
constant times a vector plus a vector
Copies a vector x, to a vector y.
double log(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public dderivatives_grad(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the gradient to a mesh function
subroutine, public derivatives_get_lapl(this, namespace, op, space, name, order)
subroutine, public dderivatives_div(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the divergence operator to a vector of mesh functions
real(real64), parameter, public m_zero
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
This module defines various routines, operating on mesh functions.
real(real64) function, public dmf_dotu_aux(f1, f2)
dot product between two vectors (mesh functions) without conjugation
subroutine, public mesh_init_mesh_aux(mesh)
Initialise a pointer to the grid/mesh, that is globally exposed, such that low level mesh operations ...
real(real64) function, public dmf_nrm2_aux(ff)
calculate norm2 of a vector (mesh function)
real(real64) function, public dmf_integrate(mesh, ff, mask, reduce)
Integrate a function on the mesh.
This module defines the meshes, which are used in Octopus.
pure subroutine, public mesh_r(mesh, ip, rr, origin, coords)
return the distance to the origin for a given grid point
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
This module defines non-local operators.
subroutine, public dnl_operator_operate_diag(op, fo)
subroutine, public nl_operator_end(op)
This module is an helper to perform ring-pattern communications among all states.
This module is intended to contain "only mathematical" functions and procedures.
subroutine, public dqmr_sym_gen_dotu(np, x, b, op, dotu, nrm2, prec, iter, residue, threshold, showprogress, converged, use_initial_guess)
for complex symmetric matrices W Chen and B Poirier, J Comput Phys 219, 198-209 (2006)
pure logical function, public states_are_real(st)
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public lda_c_fbe(st, n_blocks, l_dens, l_dedd, l_zk)
Computes the local density correlation potential and energy obtained from the Colle-Salvetti approxim...
subroutine solve_sturm_liouville(namespace, gr, st, space, fxc, vxc)
Solve the Sturm-Liouville equation On entry, vxc is the adiabatic one, on exit, it is the solution of...
subroutine zx_fbe_calc(namespace, psolver, mesh, der, st, ex, vxc, fxc)
subroutine, public x_fbe_calc(id, namespace, psolver, gr, st, space, ex, vxc)
Interface to X(x_fbe_calc) Two possible run modes possible: adiabatic and Sturm-Liouville....
subroutine dx_fbe_calc(namespace, psolver, mesh, der, st, ex, vxc, fxc)
subroutine, public fbe_c_lda_sl(namespace, psolver, gr, st, space, ec, vxc)
Sturm-Liouville version of the FBE local-density correlation functional.
real(real64) function get_virial_energy(gr, nspin, fxc)
Computes the energy from the force virial relation.
integer, parameter, public xc_oep_x_fbe_sl
Exchange approximation based on the force balance equation - Sturn-Liouville version.
integer, parameter, public xc_oep_x_fbe
Exchange approximation based on the force balance equation.
Description of the grid, containing information on derivatives, stencil, and symmetries.
subroutine sl_operator(x, hx)
Computes Ax = \nabla\cdot(\rho\nabla x)
subroutine preconditioner(x, hx)
Simple preconditioner Here we need to approximate P^-1 We use the Jacobi approximation and that \nabl...