Octopus
xc_photons.F90
Go to the documentation of this file.
1!! Copyright (C) 2022 I.-T Lu
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
27
29 use debug_oct_m
31 use epot_oct_m
32 use global_oct_m
33 use grid_oct_m
34 use iso_c_binding
37 use mesh_oct_m
44 use space_oct_m
46 use parser_oct_m
49
50 implicit none
51
52 private
53 public :: xc_photons_t
54
63 !
64 type xc_photons_t
65 private
66 integer :: method = 0
67 real(real64), allocatable, public :: vpx(:)
68 real(real64), public :: ex
69 type(photon_mode_t) :: pt
70 real(real64) :: pxlda_kappa
71 real(real64) :: eta_c
73 integer :: energy_method = 0
74 logical :: lcorrelations = .false.
75 logical :: llamb_re_mass = .false.
76 logical :: llamb_freespace =.false.
77 real(real64) :: lamb_omega
78
79 logical, public :: lpfmf = .false.
80 real(real64), allocatable, public :: mf_vector_potential(:)
81 real(real64), allocatable :: jp_proj_eo(:,:)
84
85 contains
86 procedure :: init => xc_photons_init
87 procedure :: end => xc_photons_end
88 procedure :: wants_to_renormalize_mass => xc_photons_wants_to_renormalize_mass
89 procedure :: get_renormalized_mass => xc_photons_get_renormalized_emass
90 procedure :: mf_dump => xc_photons_mf_dump
91 procedure :: mf_load => xc_photons_mf_load
92 procedure :: v_ks => xc_photons_v_ks
93 procedure :: add_mean_field => xc_photons_add_mean_field
94 end type xc_photons_t
95
96 ! the PhotonXCXCMethod
97 integer, private, parameter :: &
98 XC_PHOTONS_NONE = 0, &
99 xc_photons_lda = 1, &
101
102contains
103
104 ! ---------------------------------------------------------
106 !
107 subroutine xc_photons_init(xc_photons, namespace, xc_photon, space, gr, st)
108 class(xc_photons_t), intent(out) :: xc_photons
109 type(namespace_t), intent(in) :: namespace
110 integer, intent(in) :: xc_photon
111 class(space_t), intent(in) :: space
112 type(grid_t), intent(in) :: gr
113 type(states_elec_t), intent(in) :: st
114
115 push_sub(xc_photons_init)
116
117 xc_photons%lpfmf = .false.
118
119 call messages_experimental("XCPhotonFunctional /= none")
120
121 call photon_mode_init(xc_photons%pt, namespace, space%dim, .true.)
122 call photon_mode_set_n_electrons(xc_photons%pt, st%qtot)
124 select case(xc_photon)
125 case(option__xcphotonfunctional__photon_x_lda)
126 xc_photons%method = xc_photons_lda
127 xc_photons%lcorrelations = .false.
128 case(option__xcphotonfunctional__photon_xc_lda)
129 xc_photons%method = xc_photons_lda
130 xc_photons%lcorrelations = .true.
131 case(option__xcphotonfunctional__photon_x_wfn)
132 xc_photons%method = xc_photons_wfs
133 xc_photons%lcorrelations = .false.
134 case(option__xcphotonfunctional__photon_xc_wfn)
135 xc_photons%method = xc_photons_wfs
136 xc_photons%lcorrelations = .true.
137 case default
138 xc_photons%method = xc_photons_none
139 return
140 end select
141
142
143 if (xc_photons%method == xc_photons_lda) then
144
145 !%Variable PhotonXCLDAKappa
146 !%Type float
147 !%Default 1.0
148 !%Section Hamiltonian::XC
149 !%Description
150 !% the scaling factor for px-LDA potential
151 !%End
152 call parse_variable(namespace, 'PhotonXCLDAKappa', m_one, xc_photons%pxlda_kappa)
153
154 end if
155
156 !%Variable PhotonXCEnergyMethod
157 !%Type integer
158 !%Default 1
159 !%Section Hamiltonian::XC
160 !%Description
161 !% There are different ways to calculate the energy,
162 !%Option virial 1
163 !% (modified) virial approach</br>
164 !% <math>
165 !% (E_{\rm{px}}^{\rm{virial}} = \frac{1}{2}\int d\mathbf{r}\ \mathbf{r}\cdot[
166 !% -\rho(\mathbf{r})\nabla v_{\rm{px}}(\mathbf{r})])
167 !% </math></br>
168 !%Option expectation_value 2
169 !% expectation value w.tr.t. the wave functions (valid only for 1 electron)</br>
170 !% <math>
171 !% E_{\rm{px}}[\rho] = -\sum_{\alpha=1}^{M_{p}}\frac{\tilde{\lambda}_{\alpha}^{2}}{2\tilde{\omega}_{\alpha}^{2}}
172 !% \langle (\tilde{\mathbf{{\varepsilon}}}_{\alpha}\cdot\hat{\mathbf{J}}_{\rm{p}})\Phi[\rho]
173 !% | (\tilde{\mathbf{{\varepsilon}}}_{\alpha}\cdot\hat{\mathbf{J}}_{\rm{p}})\Phi[\rho] \rangle
174 !% </math></br>
175 !% This option only works for the wave function based electron-photon functionals
176 !%Option LDA 3
177 !% energy from electron density</br>
178 !% <math>
179 !% E_{\rm pxLDA}[\rho] = \frac{-2\pi^{2}}{(d+2)({2V_{d}})^{\frac{2}{d}}}
180 !% \sum_{\alpha=1}^{M_{p}}\frac{\tilde{\lambda}_{\alpha}^{2}}{\tilde{\omega}_{\alpha}^{2}}
181 !% \int d\mathbf{r}\ \rho^{\frac{2+d}{d}}(\mathbf{r})
182 !% </math></br>
183 !% This option only works with LDA electron-photon functionals.
184 !%End
186 call parse_variable(namespace, 'PhotonXCEnergyMethod', 1, xc_photons%energy_method)
188 if( xc_photons%method == xc_photons_wfs .and. xc_photons%energy_method == option__photonxcenergymethod__lda ) then
189 message(1) = "Calculating the electron-photon energy from the LDA expression"
190 message(2) = "is not implemented for wave function based electron-photon functionals"
191 call messages_fatal(2, namespace=namespace)
192 end if
193
194
195 if (xc_photons%lcorrelations) then
196
197 !%Variable PhotonXCEtaC
198 !%Type float
199 !%Default 1.0
200 !%Section Hamiltonian::XC
201 !%Description
202 !% The scaling factor for the px potential to reduce the weak coupling perturbation regime
203 !%End
204
205 if (parse_is_defined(namespace, 'PhotonXCEtaC')) then
206 call parse_variable(namespace, 'PhotonXCEtaC', m_one, xc_photons%eta_c)
207 else
208 message(1) = "Defining PhotonXCEtaC is required for photon functionals containing correlation."
209 call messages_fatal(1, namespace=namespace)
210 end if
211
212 else
213
214 xc_photons%eta_c = m_one
215
216 end if
217
218 ! This variable will keep vpx across iterations
219 safe_allocate(xc_photons%vpx(1:gr%np_part))
220
221 xc_photons%vpx = m_zero
222
223 !%Variable PhotonXCLambShift
224 !%Type logical
225 !%Default .false.
226 !%Section Hamiltonian::XC
227 !%Description
228 !% to deal with the photon free exchange potential for continuum mode in free space
229 !%End
230
231 call parse_variable(namespace, 'PhotonXCLambShift', .false., xc_photons%llamb_freespace)
232 call messages_experimental("PhotonXCLambShift", namespace=namespace)
233
234 if (xc_photons%llamb_freespace) then
235
236 !%Variable PhotonXCLambShiftOmegaCutoff
237 !%Type float
238 !%Default 0.0
239 !%Section Hamiltonian::XC
240 !%Description
241 !% the cutoff frequency (Ha) for Lamb shift
242 !%End
243
244 call parse_variable(namespace, 'PhotonXCLambShiftOmegaCutoff', m_zero, xc_photons%lamb_omega)
245
246 !%Variable PhotonXCLambShiftRenormalizeMass
247 !%Type logical
248 !%Default .false.
249 !%Section Hamiltonian::XC
250 !%Description
251 !% to deal with the photon free exchange potential for continuum mode in free space
252 !%End
253
254 call parse_variable(namespace, 'PhotonXCLambShiftRenormalizeMass', .false., xc_photons%llamb_re_mass)
255
256 end if
257
258 ! compute the dressed photon modes
259 call photon_mode_dressed(xc_photons%pt)
260
261
262 pop_sub(xc_photons_init)
263
264 end subroutine xc_photons_init
265
266 ! ---------------------------------------------------------
267 subroutine xc_photons_end(this)
268 class(xc_photons_t), intent(inout) :: this
269
270 push_sub(xc_photons_end)
271
272 call photon_mode_end(this%pt)
273 safe_deallocate_a(this%vpx)
274
275 if (allocated(this%mf_vector_potential)) then
276 safe_deallocate_a(this%mf_vector_potential)
277 end if
278 if (allocated(this%jp_proj_eo)) then
279 safe_deallocate_a(this%jp_proj_eo)
280 end if
281
282 pop_sub(xc_photons_end)
283 end subroutine xc_photons_end
284
290 !
291 subroutine xc_photons_v_ks(xc_photons, namespace, total_density, gr, space, psolver, ep, st)
292 class(xc_photons_t), intent(inout) :: xc_photons
293 type(namespace_t), intent(in) :: namespace
294 real(real64), pointer, contiguous, intent(in) :: total_density(:)
295 class(grid_t), intent(in) :: gr
296 type(space_t), intent(in) :: space
297 type(poisson_t), intent(in) :: psolver
298 type(epot_t), intent(in) :: ep
299 type(states_elec_t), intent(inout) :: st
300
301 integer :: ia
302
303 push_sub(xc_photons_v_ks)
304
305 xc_photons%lpfmf = xc_photons%method > 0
306
307 xc_photons%vpx = m_zero
308 xc_photons%ex = m_zero
309
310 if ( .not. allocated(xc_photons%mf_vector_potential) ) then
311 safe_allocate(xc_photons%mf_vector_potential(1:space%dim))
312 xc_photons%mf_vector_potential = m_zero
313 end if
314 if ( .not. allocated(xc_photons%jp_proj_eo)) then
315 safe_allocate(xc_photons%jp_proj_eo(1:xc_photons%pt%nmodes,1:2))
316 xc_photons%jp_proj_eo = m_zero
317 end if
318
319
320 select case(xc_photons%method)
321 case(xc_photons_lda) ! LDA approximation for px potential
322 call photon_free_vpx_lda(namespace, xc_photons, total_density, gr, space, psolver)
323 case(xc_photons_wfs) ! wave function approxmation for px potential
324 call photon_free_vpx_wfc(namespace, xc_photons, total_density, gr, space, st)
325 case(xc_photons_none) ! no photon-exchange potential
326 call messages_write('Photon-free px potential is not computed', new_line = .true.)
327 call messages_info()
328 case default
329 assert(.false.)
330 end select
331
332
333 if (.not. xc_photons%llamb_freespace) then
334 ! add the constant energy shift
335 do ia = 1, xc_photons%pt%nmodes
336 xc_photons%ex = xc_photons%ex + 0.5_real64 * (xc_photons%pt%dressed_omega(ia)-xc_photons%pt%omega(ia))
337 end do
338 end if
339
340 pop_sub(xc_photons_v_ks)
341 end subroutine xc_photons_v_ks
342 ! ---------------------------------------------------------
343
344 ! ---------------------------------------------------------
345 ! ---------------------------------------------------------
346 !
378 ! The Lamb shift code is experimental and untested
379 subroutine photon_free_vpx_lda(namespace, xc_photons, total_density, gr, space, psolver)
380 type(namespace_t), intent(in) :: namespace
381 type(xc_photons_t), intent(inout) :: xc_photons
382 real(real64), pointer, contiguous, intent(in) :: total_density(:)
383 type(grid_t), target, intent(in) :: gr
384 type(space_t), intent(in) :: space
385 type(poisson_t), intent(in) :: psolver
387 integer :: ia, ip, iter
388 real(real64) :: unit_volume, r, res, presum, prefact
389 real(real64) :: xx(space%dim), prefactor_lamb
390 real(real64), allocatable :: prefactor(:)
391 real(real64), allocatable :: rho_aux(:)
392 real(real64), allocatable :: grad_rho_aux(:,:)
393 real(real64), allocatable :: px_source(:)
394 real(real64), allocatable :: tmp1(:)
395 real(real64), allocatable :: tmp2(:,:)
396 real(real64), allocatable :: tmp3(:)
397 real(real64), allocatable :: grad_vpx(:,:)
398 real(real64), allocatable :: epsgrad_epsgrad_rho_aux(:)
399 real(real64), allocatable :: epx_force_module(:)
400
401 real(real64), parameter :: threshold = 1e-7_real64
402
403 push_sub(photon_free_vpx_lda)
404
405 if (xc_photons%energy_method == 2 .and. xc_photons%pt%n_electrons >1) then
406 call messages_not_implemented("expectation value for energy for pxLDA more than 1 electron", namespace=namespace)
407 end if
408
409 xc_photons%vpx = m_zero
410 xc_photons%ex = m_zero
411
412 safe_allocate(prefactor(1:xc_photons%pt%nmodes))
413 prefactor = m_zero
414 ! here we will use only one spin channel
415 safe_allocate(rho_aux(1:gr%np_part))
416 safe_allocate(grad_rho_aux(1:gr%np, 1:xc_photons%pt%dim))
417 safe_allocate(px_source(1:gr%np_part))
418 safe_allocate(tmp1(1:gr%np_part))
419 safe_allocate(tmp2(1:gr%np, 1:xc_photons%pt%dim))
420 safe_allocate(tmp3(1:gr%np_part))
421 safe_allocate(grad_vpx(1:gr%np, 1:xc_photons%pt%dim))
422 grad_vpx = m_zero
423 safe_allocate(epx_force_module(1:gr%np_part))
424 epx_force_module = m_zero
425
426 select case(xc_photons%pt%dim)
427 case(1)
428 unit_volume = m_two
429 case(2)
430 unit_volume = m_pi
431 case(3)
432 unit_volume = m_four*m_pi/m_three
433 case default
434 call messages_not_implemented("LDA px more than 3 dimension", namespace=namespace)
435 end select
436
437 !$omp parallel do
438 do ip=1, gr%np
439 rho_aux(ip) = ( abs(total_density(ip))/(m_two*unit_volume) )**(m_two/(xc_photons%pt%dim*m_one))
440 end do
441 !$omp end parallel do
442
443
444 ! compute the electron-photon exchange potential
445
446 if (xc_photons%llamb_freespace) then
447
448 ! Note: The Lamb shift part is currently experimental and untested!
449 ! compute the electron-photon exchange potential
450
451 prefactor_lamb = -(8.0_real64*m_pi*m_third) * xc_photons%lamb_omega / (p_c**3)
452
453 !$OMP parallel do
454 do ip=1,gr%np
455 xc_photons%vpx(ip) = prefactor_lamb*rho_aux(ip)
456 end do
457 !$OMP end parallel do
458
459 else
460
461 do ia = 1, xc_photons%pt%nmodes
462 prefactor(ia) = -m_two*(m_pi * xc_photons%pt%dressed_lambda(ia) / xc_photons%pt%dressed_omega(ia))**2
463 end do
464
465 select case(xc_photons%pt%dim)
466 case(1)
467 ! solve the pxLDA potential using the analytical form in 1D
468 px_source = m_zero
469 do ia = 1, xc_photons%pt%nmodes
470 !$OMP parallel do
471 do ip=1,gr%np_part
472 px_source(ip) = px_source(ip) + prefactor(ia)
473 end do
474 !$OMP end parallel do
475 end do
476
477 !$OMP parallel do
478 do ip=1,gr%np
479 xc_photons%vpx(ip) = px_source(ip)*rho_aux(ip)
480 end do
481 !$OMP end parallel do
482 case(2)
483 call get_px_source(px_source)
484 ! for 2D we solve the Poisson equation using the conjugate gradient method
485 mesh_aux => gr%der%mesh
486 iter = 1000
487 call dconjugate_gradients(gr%np, xc_photons%vpx(:), px_source, laplacian_op, dmf_dotp_aux, iter, res, threshold, &
488 userdata=[c_loc(gr)])
489 write(message(1),'(a,i6,a)') "Info: CG converged with ", iter, " iterations."
490 write(message(2),'(a,e14.6)') "Info: The residue is ", res
491 call messages_info(2, namespace=namespace)
492
493 case(3)
494 ! for 3D we use thepoisson solver including the prefactor (-4*pi)
495 ! therefore, we need to remove the factor in advance
496 call get_px_source(px_source)
497
498 call lalg_scal(gr%np, m_one/(-m_four*m_pi), px_source)
499
500 ! solve the Poisson equation
501 call dpoisson_solve(psolver, namespace, xc_photons%vpx(:), px_source)
502 case default
503 assert(.false.)
504 end select
505
506 end if
507
508 ! scaling the potential
509 call lalg_scal(gr%np, (xc_photons%eta_c * xc_photons%pxlda_kappa), xc_photons%vpx)
510
511 ! compute electron-photon energy
512
513 select case (xc_photons%energy_method)
514 case(1) ! compute the epx energy from the virial relation
515
516 do ia = 1, xc_photons%pt%nmodes
517
518 ! compute the electron-photon force
519 !$omp parallel do
520 do ip = 1, gr%np
521 epx_force_module(ip) = -prefactor(ia)*m_two*abs(total_density(ip))*rho_aux(ip)/(xc_photons%pt%dim*m_one+m_two)
522 end do
523 !$omp end parallel do
524
525 call dderivatives_grad(gr%der, epx_force_module(:), tmp2)
526 call lalg_gemv(gr%np, xc_photons%pt%dim, m_one, tmp2, xc_photons%pt%dressed_pol(1:xc_photons%pt%dim, ia), m_zero, tmp1)
527
528 !$omp parallel do private(r, xx)
529 do ip = 1, gr%np
530 call mesh_r(gr, ip, r, coords=xx)
531 tmp3(ip) = tmp1(ip)*dot_product(xx(1:xc_photons%pt%dim), xc_photons%pt%dressed_pol(1:xc_photons%pt%dim, ia))
532 end do
533 !$omp end parallel do
534
535 xc_photons%ex = xc_photons%ex + m_half*dmf_integrate(gr, tmp3)
536 end do
537
538 xc_photons%ex = xc_photons%eta_c * xc_photons%pxlda_kappa * xc_photons%ex
539
540 case(2) ! compute the energy as expetation value wrt to the wave functions
541
542 rho_aux(1:gr%np) = sqrt(abs( total_density(1:gr%np)))
543
544 safe_allocate(epsgrad_epsgrad_rho_aux(1:gr%np))
545
546 call dderivatives_grad(gr%der, rho_aux(1:gr%np_part), grad_rho_aux)
547
548 do ia = 1, xc_photons%pt%nmodes
549 prefact = (xc_photons%pt%dressed_lambda(ia)**2) / (m_two*xc_photons%pt%dressed_omega(ia)**2)
550
551 call lalg_gemv(gr%np, xc_photons%pt%dim, m_one, grad_rho_aux, xc_photons%pt%dressed_pol(:, ia), m_zero, tmp1)
552 call dderivatives_grad(gr%der, tmp1, tmp2)
553 call lalg_gemv(gr%np, xc_photons%pt%dim, m_one, tmp2, xc_photons%pt%dressed_pol(1:xc_photons%pt%dim, ia), m_zero, tmp1)
554
555 !$OMP parallel do
556 do ip=1, gr%np
557 epsgrad_epsgrad_rho_aux(ip) = epsgrad_epsgrad_rho_aux(ip) + prefact*tmp1(ip)
558 end do
559 !$OMP end parallel do
560
561 end do
562
563 xc_photons%ex = xc_photons%eta_c * dmf_dotp(gr, rho_aux(1:gr%np), epsgrad_epsgrad_rho_aux(1:gr%np))
564
565 safe_deallocate_a(epsgrad_epsgrad_rho_aux)
566
567 case(3) ! integrate the aux electron density over the volume
568
569 !$OMP parallel do
570 do ip=1,gr%np
571 tmp1(ip) = abs( total_density(ip))**((m_one*xc_photons%pt%dim+m_two)/(xc_photons%pt%dim*m_one))
572 end do
573 !$OMP end parallel do
574
575 ! sum over the prefactors
576 presum = m_zero
577 do ia = 1, xc_photons%pt%nmodes
578 presum = presum + prefactor(ia)
579 end do
580 presum = presum * (m_one/(m_two*unit_volume))**(m_two/(xc_photons%pt%dim*m_one)) / (xc_photons%pt%dim*m_one+m_two)
581 presum = presum * xc_photons%eta_c * xc_photons%pxlda_kappa
582
583 xc_photons%ex = xc_photons%eta_c * xc_photons%pxlda_kappa * presum * dmf_integrate(gr, tmp1)
584
585 end select
586
587 safe_deallocate_a(prefactor)
588 safe_deallocate_a(rho_aux)
589 safe_deallocate_a(grad_rho_aux)
590 safe_deallocate_a(px_source)
591 safe_deallocate_a(tmp1)
592 safe_deallocate_a(tmp2)
593 safe_deallocate_a(tmp3)
594 safe_deallocate_a(grad_vpx)
595 safe_deallocate_a(epx_force_module)
596
597 pop_sub(photon_free_vpx_lda)
598
599 contains
600
601 subroutine get_px_source(px_source)
602 real(real64), contiguous, intent(out) :: px_source(:)
603
604 call dderivatives_grad(gr%der, rho_aux(1:gr%np_part), grad_rho_aux)
605
606 px_source = m_zero
607 do ia = 1, xc_photons%pt%nmodes
608 call lalg_gemv(gr%np, xc_photons%pt%dim, m_one, grad_rho_aux, xc_photons%pt%dressed_pol(:, ia), m_zero, tmp1)
609 call dderivatives_grad(gr%der, tmp1, tmp2)
610 call lalg_gemv(gr%np, xc_photons%pt%dim, m_one, tmp2, xc_photons%pt%dressed_pol(1:xc_photons%pt%dim, ia), m_zero, tmp1)
611 call lalg_axpy(gr%np, prefactor(ia), tmp1, px_source)
612 end do
613
614 end subroutine get_px_source
615
616 end subroutine photon_free_vpx_lda
617 ! ---------------------------------------------------------
618
619 ! ---------------------------------------------------------
621 subroutine laplacian_op(x, hx, userdata)
622 real(real64), contiguous, intent(in) :: x(:)
623 real(real64), contiguous, intent(out) :: Hx(:)
624 type(c_ptr), intent(in) :: userdata(:)
625
626 real(real64), allocatable :: tmpx(:)
627 type(grid_t), pointer :: gr
628
629 assert(size(userdata) == 1)
630 assert(c_associated(userdata(1)))
631 call c_f_pointer(userdata(1), gr)
632
633 safe_allocate(tmpx(1:gr%np_part))
634 call lalg_copy(gr%np, x, tmpx)
635 call dderivatives_lapl(gr%der, tmpx, hx)
636 safe_deallocate_a(tmpx)
637
638 end subroutine laplacian_op
639 ! ---------------------------------------------------------
640
641 ! ---------------------------------------------------------
642 !
668 !
669 ! The Lamb shift code is experimental and untested
670
671 subroutine photon_free_vpx_wfc(namespace, xc_photons, total_density, gr, space, st)
672 type(namespace_t), intent(in) :: namespace
673 type(xc_photons_t), intent(inout) :: xc_photons
674 real(real64), pointer, contiguous, intent(in) :: total_density(:)
675 class(grid_t), intent(in) :: gr
676 type(space_t), intent(in) :: space
677 type(states_elec_t), intent(in) :: st
678
679 integer :: ia, ip
680 real(real64) :: prefactor_lamb
681 real(real64) :: xx(space%dim), r
682 real(real64), allocatable :: prefactor(:)
683 real(real64), allocatable :: rho_aux(:)
684 real(real64), allocatable :: grad_rho_aux(:,:)
685 real(real64), allocatable :: grad_vpx(:,:)
686 real(real64), allocatable :: epsgrad_epsgrad_rho_aux(:)
687 real(real64), allocatable :: tmp1(:)
688 real(real64), allocatable :: tmp2(:,:)
689 real(real64) :: shift
690
691 push_sub(photon_free_vpx_wfc)
692
693 if (st%d%nspin >1) then
694 call messages_not_implemented("PhotonXCXCMethod = wavefunction for polarized and spinor cases", namespace=namespace)
695 end if
697 if (xc_photons%pt%n_electrons >1) then
698 call messages_not_implemented("PhotonXCXCMethod = wavefunction for more than 1 electron", namespace=namespace)
699 end if
700
701 xc_photons%vpx = m_zero
702 xc_photons%ex = m_zero
703
704 safe_allocate(prefactor(1:xc_photons%pt%nmodes))
705 prefactor = m_zero
706 safe_allocate(rho_aux(1:gr%np_part))
707 rho_aux = m_zero
708 safe_allocate(grad_rho_aux(1:gr%np, 1:xc_photons%pt%dim))
709 grad_rho_aux = m_zero
710 safe_allocate(epsgrad_epsgrad_rho_aux(1:gr%np))
711 safe_allocate(grad_vpx(1:gr%np, 1:xc_photons%pt%dim))
712 safe_allocate(tmp1(1:gr%np_part))
713 safe_allocate(tmp2(1:gr%np_part, 1:xc_photons%pt%dim))
714
715
716 rho_aux(1:gr%np) = sqrt(abs( total_density(1:gr%np)))
717 !$OMP parallel do
718 do ip = 1, gr%np
719 rho_aux(ip) = safe_tol(rho_aux(ip),1e-18_real64)
720 end do
721 !$OMP end parallel do
722
723 if (xc_photons%llamb_freespace) then
724
725 ! experimental Lamb shift mode
726
727 prefactor_lamb = ( m_two/(m_three*m_pi) ) * xc_photons%lamb_omega / p_c**3
728 call dderivatives_lapl(gr%der, rho_aux(1:gr%np_part), epsgrad_epsgrad_rho_aux)
729 call lalg_scal(gr%np, prefactor_lamb, epsgrad_epsgrad_rho_aux)
730
731 else
732
733 do ia = 1, xc_photons%pt%nmodes
734 prefactor(ia) = (xc_photons%pt%dressed_lambda(ia)**2) / (m_two*xc_photons%pt%dressed_omega(ia)**2)
735 end do
736
737 call dderivatives_grad(gr%der, rho_aux, grad_rho_aux)
738
739 epsgrad_epsgrad_rho_aux = m_zero
740 do ia = 1, xc_photons%pt%nmodes
741 tmp1 = m_zero
742 call lalg_gemv(gr%np, xc_photons%pt%dim, m_one, grad_rho_aux, xc_photons%pt%dressed_pol(:, ia), m_zero, tmp1)
743 call dderivatives_grad(gr%der, tmp1, tmp2)
744 call lalg_gemv(gr%np, xc_photons%pt%dim, prefactor(ia), tmp2, xc_photons%pt%dressed_pol(:, ia), &
745 m_one, epsgrad_epsgrad_rho_aux)
746 end do
747
748 end if
749
750 !$OMP parallel do
751 do ip = 1, gr%np
752 xc_photons%vpx(ip) = epsgrad_epsgrad_rho_aux(ip)/rho_aux(ip)
753 end do
754 !$OMP end parallel do
755
756 if(st%eigenval(1,1) < m_huge .and. .not. space%is_periodic()) then
757 shift = m_two * st%eigenval(1,1) * prefactor(1)
758 !$OMP parallel do
759 do ip=1, gr%np
760 xc_photons%vpx(ip) = xc_photons%vpx(ip) + shift
761 end do
762 !$OMP end parallel do
763 end if
764
765 call lalg_scal(gr%np, xc_photons%eta_c, xc_photons%vpx(:))
767 select case (xc_photons%energy_method)
768 case(1) ! virial
769
770 call dderivatives_grad(gr%der, xc_photons%vpx(:), grad_vpx)
771 !$OMP parallel do private(r, xx)
772 do ip = 1, gr%np
773 call mesh_r(gr, ip, r, coords=xx)
774 tmp1(ip) = - total_density(ip)*dot_product(xx(1:xc_photons%pt%dim), grad_vpx(ip,1:xc_photons%pt%dim))
775 end do
776 !$OMP end parallel do
777
778 xc_photons%ex = m_half*dmf_integrate(gr, tmp1)
779
780 case(2) ! expectation_value
781 xc_photons%ex = xc_photons%eta_c * dmf_dotp(gr, rho_aux(1:gr%np), epsgrad_epsgrad_rho_aux)
782
783 case default
784 assert(.false.)
785 end select
786
787 safe_deallocate_a(prefactor)
788 safe_deallocate_a(rho_aux)
789 safe_deallocate_a(grad_rho_aux)
790 safe_deallocate_a(grad_vpx)
791 safe_deallocate_a(epsgrad_epsgrad_rho_aux)
792 safe_deallocate_a(tmp1)
793 safe_deallocate_a(tmp2)
794
795 pop_sub(photon_free_vpx_wfc)
796
797 end subroutine photon_free_vpx_wfc
798 ! ---------------------------------------------------------
799
800
801 ! ---------------------------------------------------------
811 !
812 subroutine xc_photons_add_mean_field(xc_photons, gr, space, kpoints, st, time, dt)
813 class(xc_photons_t), intent(inout) :: xc_photons
814 class(grid_t), intent(in) :: gr
815 class(space_t), intent(in) :: space
816 type(kpoints_t), intent(in) :: kpoints
817 type(states_elec_t), intent(inout) :: st
818 real(real64), intent(in) :: time
819 real(real64), intent(in) :: dt
820
821
822 integer :: ia, idir, ispin
823 real(real64) :: pol_dot_jp
824 real(real64), allocatable :: current(:,:,:)
825 real(real64), allocatable :: jp(:)
826
828
829 ! compute the dressed photon-free vector potential
830 xc_photons%mf_vector_potential = m_zero
831
832 safe_allocate(current(1:gr%np_part, 1:space%dim, 1:st%d%nspin))
833 current = m_zero
834 ! here we use the paramagnetic current; note that the physical current here
835 ! only contains the paramagnetic current.
836 call states_elec_calc_quantities(gr, st, kpoints, .false., paramagnetic_current = current)
837
838 ! compute the paramagnetic current
839 safe_allocate(jp(1:space%dim))
840 do idir = 1, space%dim
841 jp(idir) = m_zero
842 do ispin = 1, st%d%spin_channels
843 jp(idir) = jp(idir) + dmf_integrate(gr%der%mesh, current(:,idir,ispin))
844 end do
845 end do
846
847 ! update the 'projected' current
848 do ia = 1, xc_photons%pt%nmodes
849 pol_dot_jp = dot_product(xc_photons%pt%dressed_pol(1:space%dim, ia),jp(1:space%dim))
850 xc_photons%jp_proj_eo(ia,1) = xc_photons%jp_proj_eo(ia,1) + &
851 cos(xc_photons%pt%dressed_omega(ia)*( time-dt))*pol_dot_jp*dt
852 xc_photons%jp_proj_eo(ia,2) = xc_photons%jp_proj_eo(ia,2) + &
853 sin(xc_photons%pt%dressed_omega(ia)*( time-dt))*pol_dot_jp*dt
854 end do
855
856 do ia = 1, xc_photons%pt%nmodes
857 xc_photons%mf_vector_potential(1:xc_photons%pt%dim) = xc_photons%mf_vector_potential(1:xc_photons%pt%dim) &
858 + (-p_c*(xc_photons%pt%dressed_lambda(ia)**2) / xc_photons%pt%dressed_omega(ia)) &
859 * (xc_photons%jp_proj_eo(ia,1)*sin(xc_photons%pt%dressed_omega(ia)* time) &
860 - xc_photons%jp_proj_eo(ia,2)*cos(xc_photons%pt%dressed_omega(ia)* time)) &
861 * xc_photons%pt%dressed_pol(1:xc_photons%pt%dim, ia)
862 end do
863
864 safe_deallocate_a(current)
865 safe_deallocate_a(jp)
866
868
869 end subroutine xc_photons_add_mean_field
870 ! ---------------------------------------------------------
871
872
876 !
877 logical pure function xc_photons_wants_to_renormalize_mass(xc_photons) result (renorm)
878 class(xc_photons_t), intent(in) :: xc_photons
879
880 renorm = (xc_photons%method>0) .and. xc_photons%llamb_freespace .and. xc_photons%llamb_re_mass
881
883
885 real(real64) pure function xc_photons_get_renormalized_emass(xc_photons) result(mass)
886 class(xc_photons_t), intent(in) :: xc_photons
887
888 mass = m_one - (m_four*xc_photons%lamb_omega) / (3.0*m_pi * p_c**3)
889
891
893 !
894 subroutine xc_photons_mf_dump(xc_photons, restart, ierr)
895 class(xc_photons_t), intent(in) :: xc_photons
896 type(restart_t), intent(in) :: restart
897 integer, intent(out) :: ierr
898
899 character(len=80), allocatable :: lines(:)
900 integer :: iunit, err, jj, nmodes
901 integer :: pt_dim
902
903 push_sub(photon_free_mf_dump)
904 nmodes = xc_photons%pt%nmodes
905 pt_dim = xc_photons%pt%dim
906
907 safe_allocate(lines(1:nmodes+pt_dim))
908
909 ierr = 0
910
911 iunit = restart%open('photon_free_mf')
912
913 do jj = 1, pt_dim
914 write(lines(jj), '(2x, es19.12)') xc_photons%mf_vector_potential(jj)
915 end do
916
917 do jj = 1, nmodes
918 write(lines(jj+pt_dim), '(a10,1x,I8,a1,2x,2(es19.12,2x))') 'Mode ', jj, ":", xc_photons%jp_proj_eo(jj,1:2)
919 end do
920
921 call restart%write(iunit, lines, nmodes+pt_dim, err)
922 if (err /= 0) ierr = ierr + 1
923 call restart%close(iunit)
924
925 safe_deallocate_a(lines)
926
927 pop_sub(photon_free_mf_dump)
928 end subroutine xc_photons_mf_dump
929
930! ---------------------------------------------------------
931
933 !
934 subroutine xc_photons_mf_load(xc_photons, restart, space, ierr)
935 class(xc_photons_t), intent(inout) :: xc_photons
936 type(restart_t), intent(in) :: restart
937 class(space_t), intent(in) :: space
938 integer, intent(out) :: ierr
939
940 character(len=80), allocatable :: lines(:)
941 character(len=7) :: sdummy
942 integer :: idummy
943 integer :: iunit, err, jj, nmodes
944 integer :: pt_dim
945
946 push_sub(photon_free_mf_load)
947
948 ierr = 0
949 nmodes = xc_photons%pt%nmodes
950 pt_dim = xc_photons%pt%dim
951
952 if (restart%skip()) then
953 ierr = -1
954 pop_sub(photon_free_mf_load)
955 return
956 end if
957
958 message(1) = "Debug: Reading Photon-Free Photons restart."
959 call messages_info(1, namespace=restart%namespace, debug_only=.true.)
960
961 if ( .not. allocated(xc_photons%jp_proj_eo)) then
962 safe_allocate(xc_photons%jp_proj_eo(1:xc_photons%pt%nmodes, 1:2))
963 xc_photons%jp_proj_eo = m_zero
964 end if
965 if ( .not. allocated(xc_photons%mf_vector_potential)) then
966 safe_allocate(xc_photons%mf_vector_potential(1:space%dim))
967 xc_photons%mf_vector_potential = m_zero
968 end if
969
970 safe_allocate(lines(1:nmodes+pt_dim))
971 iunit = restart%open('photon_free_mf')
972 call restart%read(iunit, lines, nmodes+pt_dim, err)
973 if (err /= 0) then
974 ierr = ierr + 1
975 else
976 do jj = 1, pt_dim
977 read(lines(jj),'(2x, es19.12)') xc_photons%mf_vector_potential(jj)
978 end do
979
980 do jj = 1, nmodes
981 read(lines(jj+pt_dim), '(a10,1x,I8,a1,2x,2(es19.12,2x))') sdummy, idummy, sdummy, xc_photons%jp_proj_eo(jj,1:2)
982 end do
983 end if
984 call restart%close(iunit)
985
986 message(1) = "Debug: Reading Photons restart done."
987 call messages_info(1, namespace=restart%namespace, debug_only=.true.)
988
989 safe_deallocate_a(lines)
990
991 pop_sub(photon_free_mf_load)
992 end subroutine xc_photons_mf_load
993
994end module xc_photons_oct_m
995
996!! Local Variables:
997!! mode: f90
998!! coding: utf-8
999!! End:
constant times a vector plus a vector
Definition: lalg_basic.F90:173
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:188
scales a vector by a constant
Definition: lalg_basic.F90:159
double sin(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double cos(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 dderivatives_lapl(der, ff, op_ff, ghost_update, set_bc, factor)
apply the Laplacian to a mesh function
real(real64), parameter, public m_two
Definition: global.F90:192
real(real64), parameter, public m_huge
Definition: global.F90:208
real(real64), parameter, public m_zero
Definition: global.F90:190
real(real64), parameter, public m_four
Definition: global.F90:194
real(real64), parameter, public m_third
Definition: global.F90:197
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:188
real(real64), parameter, public m_half
Definition: global.F90:196
real(real64), parameter, public p_c
Electron gyromagnetic ratio, see Phys. Rev. Lett. 130, 071801 (2023)
Definition: global.F90:228
real(real64), parameter, public m_one
Definition: global.F90:191
real(real64), parameter, public m_three
Definition: global.F90:193
This module implements the underlying real-space grid.
Definition: grid.F90:119
This module defines various routines, operating on mesh functions.
class(mesh_t), pointer, public mesh_aux
Globally-scoped pointer to the mesh instance.
real(real64) function, public dmf_dotp_aux(f1, f2)
dot product between two vectors (mesh functions)
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
pure subroutine, public mesh_r(mesh, ip, rr, origin, coords)
return the distance to the origin for a given grid point
Definition: mesh.F90:340
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1097
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:416
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1069
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:600
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:505
subroutine, public photon_mode_end(this)
subroutine, public photon_mode_dressed(this)
subroutine, public photon_mode_set_n_electrons(this, qtot)
subroutine, public photon_mode_init(this, namespace, dim, photon_free)
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
Definition: poisson.F90:871
This module is intended to contain "only mathematical" functions and procedures.
Definition: solvers.F90:117
subroutine, public states_elec_calc_quantities(gr, st, kpoints, nlcc, kinetic_energy_density, paramagnetic_current, density_gradient, density_laplacian, gi_kinetic_energy_density, st_end)
calculated selected quantities
This module implements the "photon-free" electron-photon exchange-correlation functional.
Definition: xc_photons.F90:123
subroutine laplacian_op(x, hx, userdata)
Computes Hx = (\Laplacian) x.
Definition: xc_photons.F90:717
subroutine photon_free_vpx_wfc(namespace, xc_photons, total_density, gr, space, st)
compute the electron-photon exchange potential based on wave functions
Definition: xc_photons.F90:767
logical pure function xc_photons_wants_to_renormalize_mass(xc_photons)
indicate whether the photon-exchange requires a renormalized electron mass
Definition: xc_photons.F90:973
subroutine xc_photons_init(xc_photons, namespace, xc_photon, space, gr, st)
initialize the photon-exchange functional
Definition: xc_photons.F90:203
subroutine xc_photons_add_mean_field(xc_photons, gr, space, kpoints, st, time, dt)
accumulate the results of time integral the paramagnetic current.
Definition: xc_photons.F90:908
subroutine xc_photons_mf_dump(xc_photons, restart, ierr)
write restart information
Definition: xc_photons.F90:990
subroutine xc_photons_v_ks(xc_photons, namespace, total_density, gr, space, psolver, ep, st)
evaluate the KS potential and energy for the given functional
Definition: xc_photons.F90:387
real(real64) pure function xc_photons_get_renormalized_emass(xc_photons)
return the renormalized electron mass for the electron-photon exhange
Definition: xc_photons.F90:981
integer, parameter, private xc_photons_lda
Definition: xc_photons.F90:192
subroutine photon_free_vpx_lda(namespace, xc_photons, total_density, gr, space, psolver)
compute the electron-photon exchange potential within the LDA
Definition: xc_photons.F90:475
subroutine xc_photons_end(this)
Definition: xc_photons.F90:363
integer, parameter, private xc_photons_wfs
Definition: xc_photons.F90:192
subroutine xc_photons_mf_load(xc_photons, restart, space, ierr)
load restart information
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
The states_elec_t class contains all electronic wave functions.
This class described the 'photon-exchange' electron-photon xc functionals, based on QEDFT.
Definition: xc_photons.F90:159
int true(void)
subroutine get_px_source(px_source)
Definition: xc_photons.F90:697