Merge lp:~albertog/siesta/4.1-xc into lp:siesta/4.1

Proposed by Alberto Garcia
Status: Merged
Merged at revision: 1066
Proposed branch: lp:~albertog/siesta/4.1-xc
Merge into: lp:siesta/4.1
Diff against target: 4146 lines (+351/-3074) (has conflicts)
16 files modified
Docs/developer/ford-pages/grid.md (+1/-1)
Docs/siesta.tex (+14/-6)
Src/Makefile (+26/-30)
Src/SiestaXC/cellxc.F90 (+18/-1)
Src/atom.F (+16/-14)
Src/bsc_cellxc.F (+25/-8)
Src/bsc_xcmod.F (+0/-115)
Src/cellxc_mod.F (+0/-47)
Src/dhscf.F (+143/-145)
Src/forhar.F (+60/-101)
Src/ldau.F (+0/-8)
Src/meshsubs.F (+6/-4)
Src/siesta_init.F (+0/-7)
Src/xc.f (+0/-2547)
Util/Gen-basis/Makefile (+36/-40)
version.info (+6/-0)
Text conflict in version.info
To merge this branch: bzr merge lp:~albertog/siesta/4.1-xc
Reviewer Review Type Date Requested Status
Nick Papior Needs Information
Review via email: mp+361062@code.launchpad.net

Commit message

Simplify the choice between SiestaXC and BSC's versions of cellxc

The BSC_CELLXC preprocessor blocks have been removed and replaced
by conditional blocks which can be selected at runtime.

The user can control which version of cellxc is used by means of the
fdf logical variable:

     XC.Use.BSC.CellXC (T/F)

which is 'false' by default, thus using SiestaXC's cellxc.

The BSC version might be slightly better for GGA operations, and the
SiestaXC version must of course be used when dealing with van der Waals
density functionals.

NOTES:

* BSC's version of cellxc now uses ldaxc, ggaxc, and setxc/getxc from
  SiestaXC. This enhances its functionality (more functionals) and
  saves on duplicated code. The old 'xc.f' file has been removed.

* In 'meshsubs', 'distriphionmesh' now accepts an extra argument to
  flag the need for stencil initilization.

* In 'forhar', a number of 'reord' operations towards 'sequential'
  fine-point ordering (which were compiled-in only for the new
  interface) have been removed, as all the arrays involved are already
  in 'sequential' form.

  Tests show that these changes do not seem to affect the results, however.

  The 'forhar' interface uses the 'ntm' argument in all cases, to simplify
  the code.

* Removed bogus incompatibility check in ldau.F

To post a comment you must log in.
Revision history for this message
Nick Papior (nickpapior) wrote :

Looks good to me!

1) You mention BSC may be "better" for GGA, I guess this means performance wise, no?

2) It is weird that forhar does not show any differences when using the "wrong" ordering? Why, it seems to suggest something is wrong! ? Or?

Lastly, a suggestion on the name of the XC.Use.BSC.CellXC name.

Could we perhaps make this more generalized so one can later use this to select distribution options?

I.e.

   XC.Distribution BSC|GridXC

or something else?

As far as I understand the only difference is the distribution of mesh-points? Correct me if I am wrong.

Great job!

review: Needs Information
Revision history for this message
Nick Papior (nickpapior) wrote :

See additional comments.

lp:~albertog/siesta/4.1-xc updated
1052. By Alberto Garcia

Clarifications in forhar + removal of dead code

1053. By Alberto Garcia

Use "linear" ("yes/no") distribution as seed in SiestaXC

* Give SiestaXC a head start with the appropriate distribution by
  using the "yes/no" (called 'LINEAR') distribution from BSC as the
  initial one. Just specify the box (with the appropriate conversions)
  and use the new cellXC option described below to deactivate further
  internal changes.

* By settting the optional argument 'keep_input_distribution' to
  .true., the internal workload balancer in cellXC is deactivated,
  and the input distribution kept for the XC computations. This is
  advantageous when the client program has better workload-balancers
  available.

1054. By Alberto Garcia

Update grid.md in ford-pages

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Docs/developer/ford-pages/grid.md'
--- Docs/developer/ford-pages/grid.md 2018-10-12 23:51:05 +0000
+++ Docs/developer/ford-pages/grid.md 2019-01-30 13:43:54 +0000
@@ -57,7 +57,7 @@
57 every point. A ``uniform`` distribution is appropriate. Each process57 every point. A ``uniform`` distribution is appropriate. Each process
58 handles a parallelepipedic portion of the mesh box of the same size.58 handles a parallelepipedic portion of the mesh box of the same size.
5959
60* The XC routine does not work on points where there is no charge60* The XC routine has no work to do on points where there is no charge
61 density. A special algorithm determines the allocation of points to61 density. A special algorithm determines the allocation of points to
62 processors so that all have approximately the same workload. This is62 processors so that all have approximately the same workload. This is
63 the ``linear`` distribution (this is a misnomer: it should be63 the ``linear`` distribution (this is a misnomer: it should be
6464
=== modified file 'Docs/siesta.tex'
--- Docs/siesta.tex 2019-01-30 11:09:09 +0000
+++ Docs/siesta.tex 2019-01-30 13:43:54 +0000
@@ -3703,6 +3703,15 @@
37033703
3704\end{fdfentry}3704\end{fdfentry}
37053705
3706\begin{fdflogicalF}{XC!Use.BSC.CellXC}
3707 \index{exchange-correlation!cellXC}
3708
3709 If \fdftrue, the version of \texttt{cellXC} from the BSC's mesh
3710 suite is used instead of the default SiestaXC version. BSC's version
3711 might be slightly better for GGA operations. SiestaXC's version is
3712 mandatory when dealing with van der Waals functionals.
3713
3714\end{fdflogicalF}
37063715
37073716
3708\subsection{Spin polarization}3717\subsection{Spin polarization}
@@ -12587,12 +12596,11 @@
12587 generation of the basis orbitals and the screened pseudopotentials.12596 generation of the basis orbitals and the screened pseudopotentials.
1258812597
12589 \item%12598 \item%
12590 The exchange-correlation routines contained in file xc.f were12599 The exchange-correlation routines contained in SiestaXC were written
12591 written by J.M.Soler in 1996 and 1997, in collaboration with12600 by J.M.Soler in 1996 and 1997, in collaboration with
12592 \textbf{C.\ Balb\'as} and \textbf{J. L.\ Martins}. Routine pzxc (in12601 \textbf{C.\ Balb\'as} and \textbf{J. L.\ Martins}. Routine pzxc,
12593 the same file), which implements the Perdew-Zunger LDA12602 which implements the Perdew-Zunger LDA parametrization of xc, is
12594 parametrization of xc, is based on routine velect, written by12603 based on routine velect, written by \textbf{S.\ Froyen}.
12595 \textbf{S.\ Froyen}.
1259612604
12597 \item%12605 \item%
12598 The serial version of the multivariate fast fourier transform used12606 The serial version of the multivariate fast fourier transform used
1259912607
=== modified file 'Src/Makefile'
--- Src/Makefile 2019-01-23 08:12:54 +0000
+++ Src/Makefile 2019-01-30 13:43:54 +0000
@@ -81,7 +81,7 @@
8181
82OBJS = automatic_cell.o atom_options.o \82OBJS = automatic_cell.o atom_options.o \
83 arw.o atomlwf.o bands.o basis_enthalpy.o bessph.o bonds.o \83 arw.o atomlwf.o bands.o basis_enthalpy.o bessph.o bonds.o \
84 born_charge.o cellxc_mod.o cgwf.o chkdim.o chkgmx.o \84 born_charge.o cgwf.o chkdim.o chkgmx.o \
85 chempot.o coceri.o coxmol.o cross.o compute_norm.o\85 chempot.o coceri.o coxmol.o cross.o compute_norm.o\
86 denmat.o denmatlomem.o detover.o dfscf.o diagon.o digcel.o \86 denmat.o denmatlomem.o detover.o dfscf.o diagon.o digcel.o \
87 fft.o dhscf.o constr.o diagk_file.o \87 fft.o dhscf.o constr.o diagk_file.o \
@@ -150,7 +150,7 @@
150 moreParallelSubs.o \150 moreParallelSubs.o \
151 read_xc_info.o \151 read_xc_info.o \
152 siesta_master.o \152 siesta_master.o \
153 bsc_xcmod.o bsc_cellxc.o xc.o \153 bsc_cellxc.o \
154 vacuum_level.o \154 vacuum_level.o \
155 write_orb_indx.o \155 write_orb_indx.o \
156 die.o m_pexsi.o m_pexsi_driver.o m_pexsi_dos.o m_pexsi_local_dos.o\156 die.o m_pexsi.o m_pexsi_driver.o m_pexsi_dos.o m_pexsi_local_dos.o\
@@ -543,8 +543,8 @@
543atm_transfer.o: periodic_table.o radial.o sys.o543atm_transfer.o: periodic_table.o radial.o sys.o
544atm_types.o: precision.o radial.o544atm_types.o: precision.o radial.o
545atmfuncs.o: atm_types.o precision.o radial.o spher_harm.o sys.o545atmfuncs.o: atm_types.o precision.o radial.o spher_harm.o sys.o
546atom.o: atmparams.o atom_options.o basis_specs.o basis_types.o bsc_xcmod.o546atom.o: atmparams.o atom_options.o basis_specs.o basis_types.o interpolation.o
547atom.o: interpolation.o m_filter.o old_atmfuncs.o periodic_table.o precision.o547atom.o: m_filter.o old_atmfuncs.o periodic_table.o precision.o
548atom.o: pseudopotential.o sys.o548atom.o: pseudopotential.o sys.o
549atom_graph.o: alloc.o atm_types.o atmfuncs.o class_OrbitalDistribution.o549atom_graph.o: alloc.o atm_types.o atmfuncs.o class_OrbitalDistribution.o
550atom_graph.o: class_SpData1D.o class_SpData2D.o class_SpData2D.o550atom_graph.o: class_SpData1D.o class_SpData2D.o class_SpData2D.o
@@ -573,16 +573,14 @@
573broadcast_projections.o: m_trialorbitalclass.o parallel.o siesta2wannier90.o573broadcast_projections.o: m_trialorbitalclass.o parallel.o siesta2wannier90.o
574broyden_optim.o: m_broyddj_nocomm.o m_memory.o parallel.o precision.o574broyden_optim.o: m_broyddj_nocomm.o m_memory.o parallel.o precision.o
575broyden_optim.o: siesta_options.o sys.o units.o575broyden_optim.o: siesta_options.o sys.o units.o
576bsc_cellxc.o: alloc.o bsc_xcmod.o cellxc_mod.o mesh.o moremeshsubs.o parallel.o576bsc_cellxc.o: alloc.o mesh.o moremeshsubs.o parallel.o parallelsubs.o
577bsc_cellxc.o: parallelsubs.o precision.o sys.o577bsc_cellxc.o: precision.o sys.o
578bsc_xcmod.o: parallel.o precision.o sys.o
579cart2frac.o: precision.o sys.o578cart2frac.o: precision.o sys.o
580cell_broyden_optim.o: m_broyddj_nocomm.o parallel.o precision.o sys.o units.o579cell_broyden_optim.o: m_broyddj_nocomm.o parallel.o precision.o sys.o units.o
581cell_broyden_optim.o: zmatrix.o580cell_broyden_optim.o: zmatrix.o
582cell_fire_optim.o: alloc.o m_fire.o m_memory.o parallel.o precision.o581cell_fire_optim.o: alloc.o m_fire.o m_memory.o parallel.o precision.o
583cell_fire_optim.o: siesta_options.o sys.o zmatrix.o582cell_fire_optim.o: siesta_options.o sys.o zmatrix.o
584cellsubs.o: precision.o583cellsubs.o: precision.o
585cellxc_mod.o: bsc_xcmod.o sys.o
586cgvc.o: alloc.o conjgr_old.o m_mpi_utils.o parallel.o precision.o sys.o units.o584cgvc.o: alloc.o conjgr_old.o m_mpi_utils.o parallel.o precision.o sys.o units.o
587cgvc_zmatrix.o: alloc.o conjgr.o m_mpi_utils.o parallel.o precision.o sys.o585cgvc_zmatrix.o: alloc.o conjgr.o m_mpi_utils.o parallel.o precision.o sys.o
588cgvc_zmatrix.o: units.o zmatrix.o586cgvc_zmatrix.o: units.o zmatrix.o
@@ -672,13 +670,13 @@
672detover.o: alloc.o linpack.o parallel.o parallelsubs.o precision.o670detover.o: alloc.o linpack.o parallel.o parallelsubs.o precision.o
673dfscf.o: alloc.o atm_types.o atmfuncs.o atomlist.o listsc.o mesh.o meshdscf.o671dfscf.o: alloc.o atm_types.o atmfuncs.o atomlist.o listsc.o mesh.o meshdscf.o
674dfscf.o: meshphi.o parallel.o parallelsubs.o precision.o sys.o672dfscf.o: meshphi.o parallel.o parallelsubs.o precision.o sys.o
675dhscf.o: alloc.o atmfuncs.o bsc_xcmod.o cellxc_mod.o delk.o dfscf.o673dhscf.o: alloc.o atmfuncs.o delk.o dfscf.o doping_uniform.o files.o forhar.o
676dhscf.o: doping_uniform.o files.o forhar.o iogrid_netcdf.o m_charge_add.o674dhscf.o: iogrid_netcdf.o m_charge_add.o m_efield.o m_hartree_add.o m_iorho.o
677dhscf.o: m_efield.o m_hartree_add.o m_iorho.o m_mesh_node.o m_ncdf_io.o675dhscf.o: m_mesh_node.o m_ncdf_io.o m_ncdf_siesta.o m_partial_charges.o m_rhog.o
678dhscf.o: m_ncdf_siesta.o m_partial_charges.o m_rhog.o m_spin.o676dhscf.o: m_spin.o m_ts_global_vars.o m_ts_hartree.o m_ts_options.o
679dhscf.o: m_ts_global_vars.o m_ts_hartree.o m_ts_options.o m_ts_voltage.o mesh.o677dhscf.o: m_ts_voltage.o mesh.o meshdscf.o meshsubs.o moremeshsubs.o parallel.o
680dhscf.o: meshdscf.o meshsubs.o moremeshsubs.o parallel.o parsing.o precision.o678dhscf.o: parsing.o precision.o rhofft.o rhoofd.o siesta_options.o sys.o units.o
681dhscf.o: rhofft.o rhoofd.o siesta_options.o sys.o units.o vmat.o679dhscf.o: vmat.o
682diag.o: alloc.o diag_option.o parallel.o precision.o sys.o680diag.o: alloc.o diag_option.o parallel.o precision.o sys.o
683diag2g.o: fermid.o intrinsic_missing.o parallel.o parallelsubs.o precision.o681diag2g.o: fermid.o intrinsic_missing.o parallel.o parallelsubs.o precision.o
684diag2g.o: sys.o682diag2g.o: sys.o
@@ -1104,9 +1102,9 @@
1104meshdscf.o: alloc.o atomlist.o m_dscfcomm.o meshphi.o parallel.o parallelsubs.o1102meshdscf.o: alloc.o atomlist.o m_dscfcomm.o meshphi.o parallel.o parallelsubs.o
1105meshdscf.o: precision.o1103meshdscf.o: precision.o
1106meshphi.o: alloc.o precision.o1104meshphi.o: alloc.o precision.o
1107meshsubs.o: alloc.o atm_types.o atmfuncs.o cellsubs.o cellxc_mod.o chkgmx.o1105meshsubs.o: alloc.o atm_types.o atmfuncs.o cellsubs.o chkgmx.o fft1d.o mesh.o
1108meshsubs.o: fft1d.o mesh.o meshphi.o moremeshsubs.o parallel.o parallelsubs.o1106meshsubs.o: meshphi.o moremeshsubs.o parallel.o parallelsubs.o precision.o
1109meshsubs.o: precision.o radial.o siesta_cml.o sys.o1107meshsubs.o: radial.o siesta_cml.o sys.o
1110metaforce.o: alloc.o parallel.o precision.o sys.o1108metaforce.o: alloc.o parallel.o precision.o sys.o
1111minvec.o: cellsubs.o precision.o sorting.o sys.o1109minvec.o: cellsubs.o precision.o sorting.o sys.o
1112mixer.o: atomlist.o m_mixing.o m_mixing_scf.o m_spin.o parallel.o precision.o1110mixer.o: atomlist.o m_mixing.o m_mixing_scf.o m_spin.o parallel.o precision.o
@@ -1265,17 +1263,16 @@
1265siesta_forces.o: state_analysis.o state_init.o sys.o timer.o units.o1263siesta_forces.o: state_analysis.o state_init.o sys.o timer.o units.o
1266siesta_forces.o: write_subs.o1264siesta_forces.o: write_subs.o
1267siesta_geom.o: precision.o1265siesta_geom.o: precision.o
1268siesta_init.o: alloc.o atomlist.o bands.o bsc_xcmod.o1266siesta_init.o: alloc.o atomlist.o bands.o class_Fstack_Pair_Geometry_SpData2D.o
1269siesta_init.o: class_Fstack_Pair_Geometry_SpData2D.o diag_option.o files.o1267siesta_init.o: diag_option.o files.o flook_siesta.o ioxv.o kpoint_grid.o
1270siesta_init.o: flook_siesta.o ioxv.o kpoint_grid.o kpoint_pdos.o ksvinit.o1268siesta_init.o: kpoint_pdos.o ksvinit.o m_check_walltime.o m_cite.o m_energies.o
1271siesta_init.o: m_check_walltime.o m_cite.o m_energies.o m_eo.o m_fixed.o1269siesta_init.o: m_eo.o m_fixed.o m_forces.o m_iostruct.o m_mpi_utils.o
1272siesta_init.o: m_forces.o m_iostruct.o m_mpi_utils.o m_new_dm.o m_rmaxh.o1270siesta_init.o: m_new_dm.o m_rmaxh.o m_spin.o m_steps.o m_supercell.o m_timer.o
1273siesta_init.o: m_spin.o m_steps.o m_supercell.o m_timer.o m_wallclock.o1271siesta_init.o: m_wallclock.o metaforce.o molecularmechanics.o object_debug.o
1274siesta_init.o: metaforce.o molecularmechanics.o object_debug.o parallel.o1272siesta_init.o: parallel.o parallelsubs.o projected_DOS.o siesta_cmlsubs.o
1275siesta_init.o: parallelsubs.o projected_DOS.o siesta_cmlsubs.o siesta_dicts.o1273siesta_init.o: siesta_dicts.o siesta_geom.o siesta_options.o sparse_matrices.o
1276siesta_init.o: siesta_geom.o siesta_options.o sparse_matrices.o struct_init.o1274siesta_init.o: struct_init.o sys.o timer.o timestamp.o ts_init.o units.o
1277siesta_init.o: sys.o timer.o timestamp.o ts_init.o units.o writewave.o1275siesta_init.o: writewave.o zmatrix.o
1278siesta_init.o: zmatrix.o
1279siesta_master.o: iopipes.o iosockets.o precision.o sys.o1276siesta_master.o: iopipes.o iosockets.o precision.o sys.o
1280siesta_move.o: atomlist.o broyden_optim.o cell_broyden_optim.o1277siesta_move.o: atomlist.o broyden_optim.o cell_broyden_optim.o
1281siesta_move.o: cell_fire_optim.o dynamics.o fire_optim.o flook_siesta.o ioxv.o1278siesta_move.o: cell_fire_optim.o dynamics.o fire_optim.o flook_siesta.o ioxv.o
@@ -1346,7 +1343,6 @@
1346writewave.o: alloc.o atmfuncs.o atomlist.o densematrix.o diag.o diag_option.o1343writewave.o: alloc.o atmfuncs.o atomlist.o densematrix.o diag.o diag_option.o
1347writewave.o: get_kpoints_scale.o kpoint_grid.o m_spin.o parallel.o1344writewave.o: get_kpoints_scale.o kpoint_grid.o m_spin.o parallel.o
1348writewave.o: parallelsubs.o precision.o siesta_geom.o sys.o units.o1345writewave.o: parallelsubs.o precision.o siesta_geom.o sys.o units.o
1349xc.o: alloc.o bsc_xcmod.o precision.o sys.o
1350xml.o: precision.o1346xml.o: precision.o
1351zm_broyden_optim.o: m_broyddj_nocomm.o parallel.o precision.o sys.o units.o1347zm_broyden_optim.o: m_broyddj_nocomm.o parallel.o precision.o sys.o units.o
1352zm_broyden_optim.o: zmatrix.o1348zm_broyden_optim.o: zmatrix.o
13531349
=== modified file 'Src/SiestaXC/cellxc.F90'
--- Src/SiestaXC/cellxc.F90 2017-09-04 11:10:16 +0000
+++ Src/SiestaXC/cellxc.F90 2019-01-30 13:43:54 +0000
@@ -232,7 +232,8 @@
232CONTAINS ! nothing else but public routine cellXC232CONTAINS ! nothing else but public routine cellXC
233233
234SUBROUTINE cellXC( irel, cell, nMesh, lb1, ub1, lb2, ub2, lb3, ub3, &234SUBROUTINE cellXC( irel, cell, nMesh, lb1, ub1, lb2, ub2, lb3, ub3, &
235 nSpin, dens, Ex, Ec, Dx, Dc, stress, Vxc, dVxcdD )235 nSpin, dens, Ex, Ec, Dx, Dc, stress, Vxc, dVxcdD, &
236 keep_input_distribution )
236237
237 ! Module routines238 ! Module routines
238 use mesh3D, only: addMeshData ! Accumulates a mesh array239 use mesh3D, only: addMeshData ! Accumulates a mesh array
@@ -303,6 +304,7 @@
303 ! (spin) xc potential304 ! (spin) xc potential
304 real(gp),intent(out),optional:: & ! dVxc/dDens (LDA only)305 real(gp),intent(out),optional:: & ! dVxc/dDens (LDA only)
305 dVxcdD(0:ub1-lb1,0:ub2-lb2,0:ub3-lb3,1:nSpin**2) 306 dVxcdD(0:ub1-lb1,0:ub2-lb2,0:ub3-lb3,1:nSpin**2)
307 logical, intent(in),optional:: keep_input_distribution
306308
307 ! Fix the order of the numerical derivatives309 ! Fix the order of the numerical derivatives
308 ! nn is the number of points used in each coordinate and direction,310 ! nn is the number of points used in each coordinate and direction,
@@ -404,6 +406,8 @@
404 type(allocDefaults):: &406 type(allocDefaults):: &
405 prevAllocDefaults407 prevAllocDefaults
406408
409 logical :: keep_input_distr
410
407#ifdef DEBUG_XC411#ifdef DEBUG_XC
408 ! Variables for debugging412 ! Variables for debugging
409 real(dp):: GDtot(3), q, dqdD, dqdGD(3)413 real(dp):: GDtot(3), q, dqdD, dqdGD(3)
@@ -415,6 +419,11 @@
415 ! Start time counter419 ! Start time counter
416 call timer_start( myName )420 call timer_start( myName )
417421
422 keep_input_distr = .false.
423 if (present(keep_input_distribution)) then
424 keep_input_distr = keep_input_distribution
425 endif
426
418#ifdef DEBUG_XC427#ifdef DEBUG_XC
419 ! Initialize udebug variable428 ! Initialize udebug variable
420 call setDebugOutputUnit()429 call setDebugOutputUnit()
@@ -469,6 +478,12 @@
469 ! Get ID of the I/O distribution of mesh points478 ! Get ID of the I/O distribution of mesh points
470 call setMeshDistr( ioDistr, nMesh, ioBox )479 call setMeshDistr( ioDistr, nMesh, ioBox )
471480
481 if (keep_input_distr) then
482
483 myDistr = ioDistr
484
485 else
486
472 ! If nMesh has changed, use input distribution also initially as myDistr487 ! If nMesh has changed, use input distribution also initially as myDistr
473 if (any(nMesh/=oldMesh)) call setMeshDistr( myDistr, nMesh, ioBox )488 if (any(nMesh/=oldMesh)) call setMeshDistr( myDistr, nMesh, ioBox )
474 oldMesh = nMesh489 oldMesh = nMesh
@@ -519,6 +534,7 @@
519#endif /* DEBUG_XC */534#endif /* DEBUG_XC */
520 end if ! (nodes>1 .and. timeDisp/timeAvge>maxUnbalance)535 end if ! (nodes>1 .and. timeDisp/timeAvge>maxUnbalance)
521536
537 endif
522#ifdef DEBUG_XC538#ifdef DEBUG_XC
523 ! Keep input distribution for the time being539 ! Keep input distribution for the time being
524! myDistr = ioDistr540! myDistr = ioDistr
@@ -535,6 +551,7 @@
535 ! - The parallel mesh distribution is changed internally (even with LDA)551 ! - The parallel mesh distribution is changed internally (even with LDA)
536 ! - We need finite differences (GGA) and have a distributed mesh552 ! - We need finite differences (GGA) and have a distributed mesh
537 if (.not.sameMeshDistr(myDistr,ioDistr) .or. (GGA .and. myDistr/=0)) then553 if (.not.sameMeshDistr(myDistr,ioDistr) .or. (GGA .and. myDistr/=0)) then
554
538 m11=myBox(1,1); m12=myBox(1,2); m13=myBox(1,3)555 m11=myBox(1,1); m12=myBox(1,2); m13=myBox(1,3)
539 m21=myBox(2,1); m22=myBox(2,2); m23=myBox(2,3)556 m21=myBox(2,1); m22=myBox(2,2); m23=myBox(2,3)
540 ns = nSpin ! Just a shorter name557 ns = nSpin ! Just a shorter name
541558
=== modified file 'Src/atom.F'
--- Src/atom.F 2018-07-13 18:31:43 +0000
+++ Src/atom.F 2019-01-30 13:43:54 +0000
@@ -1,3 +1,5 @@
1
2
1! 3!
2! Copyright (C) 1996-2016 The SIESTA group4! Copyright (C) 1996-2016 The SIESTA group
3! This file is distributed under the terms of the5! This file is distributed under the terms of the
@@ -39,10 +41,10 @@
39 use basis_types, only: basis_def_t41 use basis_types, only: basis_def_t
40 use fdf42 use fdf
41 use pseudopotential, only: pseudopotential_t43 use pseudopotential, only: pseudopotential_t
42#ifndef BSC_CELLXC44
43 use siestaXC, only: atomXC ! XC for a spherical charge45 use siestaXC, only: atomXC ! XC for a spherical charge
44 use siestaXC, only: getXC ! Returns the XC functional to be used46 use siestaXC, only: getXC ! Returns the XC functional to be used
45#endif /* ! BSC_CELLXC */47
4648
47 implicit none 49 implicit none
4850
@@ -1975,20 +1977,20 @@
1975C Checking the functional used for exchange-correlation energy.1977C Checking the functional used for exchange-correlation energy.
1976C Written by D. Sanchez-Portal, Aug. 19981978C Written by D. Sanchez-Portal, Aug. 1998
19771979
1978#ifdef BSC_CELLXC1980
1979 use bsc_xcmod, only : nXCfunc, XCfunc, XCauth1981
19801982
1981#endif /* BSC_CELLXC */1983
1982C Passed variable1984C Passed variable
1983 character(len=2), intent(in) :: icorr1985 character(len=2), intent(in) :: icorr
19841986
1985C Local variables1987C Local variables
1986#ifndef BSC_CELLXC1988
1987 integer :: nf, nXCfunc1989 integer :: nf, nXCfunc
1988 character(len=20) :: XCauth(10), XCfunc(10)1990 character(len=20) :: XCauth(10), XCfunc(10)
1989#else /* BSC_CELLXC */1991
1990 integer :: nf1992
1991#endif /* BSC_CELLXC */1993
1992 character(len=40) :: ps_string1994 character(len=40) :: ps_string
19931995
1994 ps_string = "Unknown atomic XC code"1996 ps_string = "Unknown atomic XC code"
@@ -2001,7 +2003,7 @@
2001 if (icorr .eq. "wc") ps_string ="GGA WC"2003 if (icorr .eq. "wc") ps_string ="GGA WC"
2002 if (icorr .eq. "bl") ps_string ="GGA BLYP"2004 if (icorr .eq. "bl") ps_string ="GGA BLYP"
2003 if (icorr .eq. "ps") ps_string ="GGA PBEsol"2005 if (icorr .eq. "ps") ps_string ="GGA PBEsol"
2004#ifndef BSC_CELLXC2006
2005 if (icorr .eq. "jo") ps_string ="GGA PBEJsJrLO"2007 if (icorr .eq. "jo") ps_string ="GGA PBEJsJrLO"
2006 if (icorr .eq. "jh") ps_string ="GGA PBEJsJrHEG"2008 if (icorr .eq. "jh") ps_string ="GGA PBEJsJrHEG"
2007 if (icorr .eq. "go") ps_string ="GGA PBEGcGxLO"2009 if (icorr .eq. "go") ps_string ="GGA PBEGcGxLO"
@@ -2017,7 +2019,7 @@
20172019
2018C Get functional(s) being used2020C Get functional(s) being used
2019 call getXC( nXCfunc, XCfunc, XCauth )2021 call getXC( nXCfunc, XCfunc, XCauth )
2020#endif /* ! BSC_CELLXC */2022
20212023
2022C Loop over functionals2024C Loop over functionals
2023 do nf = 1,nXCfunc2025 do nf = 1,nXCfunc
@@ -2095,7 +2097,7 @@
2095 . 'xc_check: WARNING: Pseudopotential generated with',2097 . 'xc_check: WARNING: Pseudopotential generated with',
2096 . trim(ps_string), " functional"2098 . trim(ps_string), " functional"
20972099
2098#ifndef BSC_CELLXC2100
2099 elseif((XCauth(nf).eq.'PW91').and.(XCfunc(nf).eq.'GGA')) then2101 elseif((XCauth(nf).eq.'PW91').and.(XCfunc(nf).eq.'GGA')) then
21002102
2101 write(6,'(a)')2103 write(6,'(a)')
@@ -2215,7 +2217,7 @@
2215 . 'xc_check: WARNING: Pseudopotential generated with',2217 . 'xc_check: WARNING: Pseudopotential generated with',
2216 . trim(ps_string), " functional"2218 . trim(ps_string), " functional"
22172219
2218#endif /* ! BSC_CELLXC */2220
2219 else2221 else
22202222
2221 write(6,'(a)')2223 write(6,'(a)')
22222224
=== modified file 'Src/bsc_cellxc.F'
--- Src/bsc_cellxc.F 2016-01-25 16:00:16 +0000
+++ Src/bsc_cellxc.F 2019-01-30 13:43:54 +0000
@@ -115,12 +115,11 @@
115C *******************************************************************115C *******************************************************************
116116
117 use precision, only : dp, grid_p117 use precision, only : dp, grid_p
118 use bsc_xcmod, only : nXCfunc, XCfunc, XCauth
119 use bsc_xcmod, only : XCweightX, XCweightC
120 use sys, only : die118 use sys, only : die
121 use alloc, only : re_alloc, de_alloc119 use alloc, only : re_alloc, de_alloc
122 use cellxc_mod, only : GGA
123 use mesh, only : nsm, meshLim120 use mesh, only : nsm, meshLim
121 use siestaxc, only : ggaxc, ldaxc
122 use siestaxc, only : getXC
124#ifdef MPI123#ifdef MPI
125C Modules124C Modules
126 use mesh, only : nmeshg125 use mesh, only : nmeshg
@@ -179,7 +178,7 @@
179#endif178#endif
180179
181C Local variables and arrays180C Local variables and arrays
182 logical GGAfunctl181 logical GGA, GGAfunctl
183 integer I1, I2, I3, IC, IN, IP, IS, IX,182 integer I1, I2, I3, IC, IN, IP, IS, IX,
184 & J1, J2, J3, JN, JP(3,-NN:NN), JS, JX,183 & J1, J2, J3, JN, JP(3,-NN:NN), JS, JX,
185 & KS, NPG, nf184 & KS, NPG, nf
@@ -190,12 +189,17 @@
190 & DVCDN(mspin*mspin), DVXDN(mspin*mspin),189 & DVCDN(mspin*mspin), DVXDN(mspin*mspin),
191 & EPSC, EPSX, F1, F2, GD(3,mspin),190 & EPSC, EPSX, F1, F2, GD(3,mspin),
192 & VOLCEL, volume, stress(3,3)191 & VOLCEL, volume, stress(3,3)
193 external GGAXC, LDAXC, RECLAT, VOLCEL192 external RECLAT, VOLCEL
193
194 integer BS(3), iDistr194 integer BS(3), iDistr
195 real(grid_p), pointer :: bdensX(:,:,:), bdensY(:,:,:),195 real(grid_p), pointer :: bdensX(:,:,:), bdensY(:,:,:),
196 & bdensZ(:,:,:), bvxcX(:,:,:),196 & bdensZ(:,:,:), bvxcX(:,:,:),
197 & bvxcY(:,:,:), bvxcZ(:,:,:)197 & bvxcY(:,:,:), bvxcZ(:,:,:)
198198
199 integer :: nXCfunc
200 character(len=20) :: XCauth(10), XCfunc(10)
201 real(dp) :: XCweightX(10), XCweightC(10)
202
199#ifdef DEBUG203#ifdef DEBUG
200 call write_debug( ' PRE cellxc' )204 call write_debug( ' PRE cellxc' )
201#endif205#endif
@@ -207,9 +211,21 @@
207#endif211#endif
208 call timer( 'cellXC', 1 )212 call timer( 'cellXC', 1 )
209213
210C Check ider214 call getXC( nXCfunc, XCfunc, XCauth, XCweightX, XCweightC)
211 if (ider.ne.0 .and. GGA)215
212 $ call die('cellXC: ider=1 available only for LDA')216 GGA = .false.
217 do nf = 1,nXCfunc
218 if ( XCfunc(nf).eq.'GGA' .or. XCfunc(nf).eq.'gga' ) then
219 GGA = .true.
220 endif
221 if ( XCfunc(nf).eq.'VDW' .or. XCfunc(nf).eq.'vdw') then
222 call die("BSC's cellxc cannot handle VDW functionals")
223 endif
224 enddo
225
226 if (ider.ne.0 .and. GGA) then
227 call die('BSC cellXC: ider=1 available only for LDA')
228 endif
213229
214C Check value of mspin230C Check value of mspin
215 if (mspin.lt.nspin) then231 if (mspin.lt.nspin) then
@@ -584,6 +600,7 @@
584#endif600#endif
585 endif601 endif
586602
603
587C Loop over all functionals604C Loop over all functionals
588 do nf = 1,nXCfunc605 do nf = 1,nXCfunc
589606
590607
=== removed file 'Src/bsc_xcmod.F'
--- Src/bsc_xcmod.F 2016-01-25 16:00:16 +0000
+++ Src/bsc_xcmod.F 1970-01-01 00:00:00 +0000
@@ -1,115 +0,0 @@
1!
2! Copyright (C) 1996-2016 The SIESTA group
3! This file is distributed under the terms of the
4! GNU General Public License: see COPYING in the top directory
5! or http://www.gnu.org/copyleft/gpl.txt.
6! See Docs/Contributors.txt for a list of contributors.
7!
8 module bsc_xcmod
9
10 use precision, only : dp
11
12 implicit none
13
14 integer, parameter :: MaxFunc = 10
15 integer, save :: nXCfunc
16 character(len=10), save :: XCauth(MaxFunc)
17 character(len=10), save :: XCfunc(MaxFunc)
18 real(dp), save :: XCweightX(MaxFunc)
19 real(dp), save :: XCweightC(MaxFunc)
20
21 public :: nXCfunc, XCauth, XCfunc
22 public :: XCweightX, XCweightC
23 public :: setXC
24 private
25
26 contains
27
28 subroutine setXC()
29C
30C This subroutine reads the exchange-correlation functional information
31C
32 use fdf
33 use parallel, only : Node
34 use sys, only : die
35
36 implicit none
37
38C Local variables
39 integer :: n
40 integer :: ni
41 integer :: nn
42 integer :: nr
43
44 type(block_fdf) :: bfdf
45 type(parsed_line), pointer :: pline
46
47C Read XC functionals
48 if (fdf_block('xc.hybrid',bfdf)) then
49 if (.not. fdf_bline(bfdf,pline)) then
50 call die('setXC: ERROR no data in XC.hybrid block')
51 endif
52 ni = fdf_bnintegers(pline)
53
54 if (ni .eq. 0) then
55 call die('setXC: Number of functionals missing in ' //
56 . 'XC.hybrid')
57 endif
58 nXCfunc = abs(fdf_bintegers(pline,1))
59 if (nXCfunc .gt. MaxFunc) then
60 call die('setXC: Too many functionals in XC.hybrid')
61 endif
62 do n= 1, nXCfunc
63 if (.not. fdf_bline(bfdf,pline)) then
64 call die('setXC: Number of XC functionals does not match')
65 endif
66 nn = fdf_bnnames(pline)
67 nr = fdf_bnreals(pline)
68
69 if (nn .gt. 0) then
70 XCfunc(n) = fdf_bnames(pline,1)
71 else
72 XCfunc(n) = 'LDA'
73 endif
74 if (nn .gt. 1) then
75 XCauth(n) = fdf_bnames(pline,2)
76 else
77 XCauth(n) = 'PZ'
78 endif
79 if (nr .gt. 1) then
80 XCweightX(n) = fdf_breals(pline,1)
81 XCweightC(n) = fdf_breals(pline,2)
82 elseif (nr .eq. 1) then
83 XCweightX(n) = fdf_breals(pline,1)
84 XCweightC(n) = fdf_breals(pline,1)
85 else
86 XCweightX(n) = 1.0_dp
87 XCweightC(n) = 1.0_dp
88 endif
89 enddo
90 else
91 nXCfunc = 1
92 XCfunc(1) = fdf_string('xc.functional','LDA')
93 XCauth(1) = fdf_string('xc.authors','PZ')
94 XCweightX(1) = 1.0_dp
95 XCweightC(1) = 1.0_dp
96 endif
97
98C Output data for hybrid functionals
99 if ((nXCfunc .gt. 1) .and. (Node .eq. 0)) then
100 write(6,'(/,''xc:'')')
101 write(6,'(''xc: Hybrid exchange-correlation functional:'')
102 . ')
103 write(6,'(''xc:'')')
104 write(6,'(''xc: Number Functional Authors '',
105 . '' Weight(Ex) Weight(Ec)'')')
106 do n = 1,nXCfunc
107 write(6,'(''xc: '',i4,7x,a3,5x,a10,3x,f5.3,8x,f5.3)')
108 . n,XCfunc(n),XCauth(n),XCweightX(n),XCweightC(n)
109 enddo
110 write(6,'(''xc:'')')
111 endif
112
113 end subroutine setXC
114
115 end module bsc_xcmod
1160
=== removed file 'Src/cellxc_mod.F'
--- Src/cellxc_mod.F 2016-01-25 16:00:16 +0000
+++ Src/cellxc_mod.F 1970-01-01 00:00:00 +0000
@@ -1,47 +0,0 @@
1! ---
2! Copyright (C) 1996-2016 The SIESTA group
3! This file is distributed under the terms of the
4! GNU General Public License: see COPYING in the top directory
5! or http://www.gnu.org/copyleft/gpl.txt .
6! See Docs/Contributors.txt for a list of contributors.
7! ---
8 MODULE cellxc_mod
9 PRIVATE
10 PUBLIC :: setGGA, GGA
11 logical :: GGA=.FALSE.
12 CONTAINS
13 subroutine setGGA( )
14#ifndef BSC_CELLXC
15 use siestaXC, only : getXC ! Returns the XC functional used
16#else /* BSC_CELLXC */
17 use bsc_xcmod, only : nXCfunc, XCfunc
18#endif /* BSC_CELLXC */
19 use sys, only : die
20 implicit none
21C Local variables
22#ifndef BSC_CELLXC
23 integer :: nf, nXCfunc
24 character(len=20):: XCauth(10), XCfunc(10)
25#else /* BSC_CELLXC */
26 integer :: nf
27#endif /* BSC_CELLXC */
28
29!---------------------------------------------------------------------- BEGIN
30#ifndef BSC_CELLXC
31 call getXC( nXCfunc, XCfunc, XCauth )
32#endif /* ! BSC_CELLXC */
33 do nf = 1,nXCfunc
34 if ( XCfunc(nf).eq.'GGA' .or. XCfunc(nf).eq.'gga') then
35 GGA = .true.
36 else
37 if ( XCfunc(nf).ne.'LDA' .and. XCfunc(nf).ne.'lda' .and.
38 & XCfunc(nf).ne.'LSD' .and. XCfunc(nf).ne.'lsd' ) then
39 write(6,*) 'cellXC: Unknown functional ', XCfunc(nf)
40 call die()
41 endif
42 endif
43 enddo
44!----------------------------------------------------------------------- END
45 end subroutine setGGA
46
47 END MODULE cellxc_mod
480
=== modified file 'Src/dhscf.F'
--- Src/dhscf.F 2018-12-23 19:28:49 +0000
+++ Src/dhscf.F 2019-01-30 13:43:54 +0000
@@ -45,6 +45,8 @@
45 & dvol, field(3), rmax, scell(3,3)45 & dvol, field(3), rmax, scell(3,3)
46 real(dp) :: G2mesh = 0.0_dp46 real(dp) :: G2mesh = 0.0_dp
47 logical :: debug_dhscf = .false.47 logical :: debug_dhscf = .false.
48 logical :: use_bsc_cellxc
49
48 character(len=*), parameter :: debug_fmt =50 character(len=*), parameter :: debug_fmt =
49 & '('' -- dhscf : Node '',i3,tr1,a,4(tr1,e20.7))'51 & '('' -- dhscf : Node '',i3,tr1,a,4(tr1,e20.7))'
5052
@@ -66,11 +68,7 @@
66 use sys, only : die68 use sys, only : die
67 use mesh, only : xdsp, nsm, nsp, meshLim69 use mesh, only : xdsp, nsm, nsp, meshLim
68 use parsing70 use parsing
69#ifndef BSC_CELLXC71
70 use siestaXC, only : getXC ! Returns the XC functional used
71#else /* BSC_CELLXC */
72 use bsc_xcmod, only : nXCfunc, XCauth
73#endif /* BSC_CELLXC */
74 use alloc, only : re_alloc, de_alloc72 use alloc, only : re_alloc, de_alloc
75 use siesta_options, only : harrisfun73 use siesta_options, only : harrisfun
76 use meshsubs, only : PartialCoreOnMesh74 use meshsubs, only : PartialCoreOnMesh
@@ -93,9 +91,6 @@
93 use m_ncdf_siesta, only : cdf_init_grid91 use m_ncdf_siesta, only : cdf_init_grid
94 use m_ncdf_io, only : cdf_init_mesh92 use m_ncdf_io, only : cdf_init_mesh
95#endif93#endif
96#ifdef BSC_CELLXC
97 use cellxc_mod, only : setGGA
98#endif /* BSC_CELLXC */
99 use m_efield, only : initialize_efield, acting_efield94 use m_efield, only : initialize_efield, acting_efield
100 use m_efield, only : get_field_from_dipole95 use m_efield, only : get_field_from_dipole
101 use m_efield, only : dipole_correction96 use m_efield, only : dipole_correction
@@ -145,10 +140,8 @@
145 integer, pointer :: numphi(:), numphi_par(:)140 integer, pointer :: numphi(:), numphi_par(:)
146141
147 integer :: nm(3) ! For call to initMesh142 integer :: nm(3) ! For call to initMesh
148#ifndef BSC_CELLXC143 logical :: need_gradients_in_xc, is_vdw
149 integer :: nXCfunc144
150 character(len=20) :: XCauth(10), XCfunc(10)
151#endif /* ! BSC_CELLXC */
152 ! Transport direction (unit-cell aligned)145 ! Transport direction (unit-cell aligned)
153 integer :: iE146 integer :: iE
154 real(dp) :: ortho, field(3), field2(3)147 real(dp) :: ortho, field(3), field2(3)
@@ -182,18 +175,6 @@
182 & call die('dhscf: ERROR: spiral defined but nspin < 4')175 & call die('dhscf: ERROR: spiral defined but nspin < 4')
183 endif ! First time176 endif ! First time
184177
185#ifndef BSC_CELLXC
186C Get functional(s) being used
187 call getXC( nXCfunc, XCfunc, XCauth )
188#endif /* ! BSC_CELLXC */
189
190 if (harrisfun) then
191 do n = 1,nXCfunc
192 if (.not.(leqi(XCauth(n),'PZ').or.leqi(XCauth(n),'CA'))) then
193 call die("** Harris forces not implemented for non-LDA XC")
194 endif
195 enddo
196 endif
197178
198C ----------------------------------------------------------------------179C ----------------------------------------------------------------------
199C Orbital initialisation : part 1180C Orbital initialisation : part 1
@@ -278,11 +259,23 @@
278C Initialise quantities relating to the atom-mesh positioning259C Initialise quantities relating to the atom-mesh positioning
279 call InitAtomMesh( UNIFORM, na, xa )260 call InitAtomMesh( UNIFORM, na, xa )
280261
281#ifdef BSC_CELLXC262! Check if we need stencils in cellxc, and detect incompatibility
282C Check if we need extencils in cellxc263! with Harris forces
283 call setGGA( )264 call xc_setup(need_gradients_in_xc, is_vdw)
284265
285#endif /* BSC_CELLXC */266 if (need_gradients_in_xc .and. harrisfun) then
267 call die("** Harris forces not implemented for non-LDA XC")
268 endif
269
270 ! Give the opportunity to use BSC's version,
271 ! unless we have a vdw functional
272 use_bsc_cellxc = fdf_get("XC.Use.BSC.CellXC", .false.)
273 if (is_vdw .and. use_bsc_cellxc) then
274 call message("INFO",
275 $ "BSC's cellxc cannot be used with vdW functionals")
276 use_bsc_cellxc = .false.
277 endif
278
286C Compute the number of orbitals on the mesh and recompute the279C Compute the number of orbitals on the mesh and recompute the
287C partions for every processor in order to have a similar load280C partions for every processor in order to have a similar load
288C in each of them.281C in each of them.
@@ -295,7 +288,7 @@
295!$OMP end parallel do288!$OMP end parallel do
296289
297 call distriPhiOnMesh( nm, nmpl, norb, iaorb, iphorb,290 call distriPhiOnMesh( nm, nmpl, norb, iaorb, iphorb,
298 & isa, numphi )291 & isa, numphi, need_gradients_in_xc )
299292
300C Find if there are partial-core-corrections for any atom293C Find if there are partial-core-corrections for any atom
301 npcc = 0294 npcc = 0
@@ -623,18 +616,13 @@
623C ----------------------------------------------------------------------616C ----------------------------------------------------------------------
624C Modules617C Modules
625 use precision, only : dp, grid_p618 use precision, only : dp, grid_p
626#ifndef BSC_CELLXC
627 use parallel, only : ProcessorY
628#endif /* ! BSC_CELLXC */
629619
630! Number of Mesh divisions of each cell vector (global)
631! The status of this variable is confusing
632 use parallel, only : Node, Nodes620 use parallel, only : Node, Nodes
633 use atmfuncs, only : rcut, rcore621 use atmfuncs, only : rcut, rcore
634 use units, only : Debye, eV, Ang622 use units, only : Debye, eV, Ang
635 use fdf623 use fdf
636 use sys, only : die, bye624 use sys, only : die, bye
637 use mesh, only : nsm, nsp625 use mesh, only : nsm, nsp, meshLim
638 use parsing626 use parsing
639 use m_iorho, only : write_rho627 use m_iorho, only : write_rho
640 use m_forhar, only : forhar628 use m_forhar, only : forhar
@@ -652,14 +640,12 @@
652 use moreMeshSubs, only : TO_SEQUENTIAL, TO_CLUSTER, KEEP640 use moreMeshSubs, only : TO_SEQUENTIAL, TO_CLUSTER, KEEP
653 use m_partial_charges, only: compute_partial_charges641 use m_partial_charges, only: compute_partial_charges
654 use m_partial_charges, only: want_partial_charges642 use m_partial_charges, only: want_partial_charges
655#ifndef BSC_CELLXC
656643
657 use siestaXC, only : cellXC ! Finds xc energy and potential644 use siestaXC, only : cellXC ! Finds xc energy and potential
658 use siestaXC, only : myMeshBox ! Returns my processor mesh box645 use siestaXC, only : myMeshBox ! Returns my processor mesh box
659 use siestaXC, only : jms_setMeshDistr => setMeshDistr646 use siestaXC, only : jms_setMeshDistr => setMeshDistr
660 ! Sets a distribution of mesh647 ! Sets a distribution of mesh
661 ! points over parallel processors648 ! points over parallel processors
662#endif /* BSC_CELLXC */
663 use m_vmat, only : vmat649 use m_vmat, only : vmat
664 use m_rhoofd, only: rhoofd650 use m_rhoofd, only: rhoofd
665#ifdef MPI651#ifdef MPI
@@ -754,10 +740,9 @@
754C logical IsDiag : Is supercell diagonal?740C logical IsDiag : Is supercell diagonal?
755C integer ispin : Spin index741C integer ispin : Spin index
756C integer j : General-purpose index742C integer j : General-purpose index
757#ifndef BSC_CELLXC743
758C integer JDGdistr : J.D.Gale's parallel distribution of mesh points744C integer myBox(2,3) : My processor's mesh box
759C integer myBox(2,3) : My processor's mesh box745
760#endif /* ! BSC_CELLXC */
761C integer nbcell : Number of independent bulk lattice vectors746C integer nbcell : Number of independent bulk lattice vectors
762C integer npcc : Partial core corrections? (0=no, 1=yes)747C integer npcc : Partial core corrections? (0=no, 1=yes)
763C integer nsd : Number of diagonal spin values (1 or 2)748C integer nsd : Number of diagonal spin values (1 or 2)
@@ -780,22 +765,11 @@
780765
781C Local variables766C Local variables
782 integer :: i, ia, ip, ispin, nsd, np_vac767 integer :: i, ia, ip, ispin, nsd, np_vac
783#ifndef BSC_CELLXC
784! Interface to JMS's SiestaXC
785 integer :: myBox(2,3)
786 integer, save :: JDGdistr=-1
787 real(dp) :: stressXC(3,3)
788#endif /* ! BSC_CELLXC */
789 real(dp) :: b1Xb2(3), const, DEc, DEx, DStres(3,3),768 real(dp) :: b1Xb2(3), const, DEc, DEx, DStres(3,3),
790 & Ec, Ex, rhotot, x0(3), volume, Vmax_vac, Vmean_vac769 & Ec, Ex, rhotot, x0(3), volume, Vmax_vac, Vmean_vac
791#ifdef BSC_CELLXC
792! Dummy arrays for cellxc call
793 real(grid_p) :: aux3(3,1)
794 real(grid_p) :: dummy_DVxcdn(1,1,1)
795#endif /* BSC_CELLXC */
796770
797 logical :: use_rhog771 logical :: use_rhog
798772
799 real(dp), external :: volcel, ddot773 real(dp), external :: volcel, ddot
800774
801 external775 external
@@ -805,9 +779,16 @@
805 & reord, rhooda, rhoofdsp, 779 & reord, rhooda, rhoofdsp,
806 & timer, vmatsp, 780 & timer, vmatsp,
807 & readsp781 & readsp
808#ifdef BSC_CELLXC782
783! Dummy arrays for bsc_cellxc call
784 real(grid_p) :: aux3(3,1)
785 real(grid_p) :: dummy_DVxcdn(1,1,1)
786 real(grid_p), pointer :: Vscf_gga(:,:), DRho_gga(:,:)
809 external bsc_cellxc787 external bsc_cellxc
810#endif /* BSC_CELLXC */788
789! Interface to JMS's SiestaXC
790 integer :: myBox(2,3)
791 real(dp) :: stressXC(3,3)
811792
812C Work arrays793C Work arrays
813 real(grid_p), pointer :: Vscf(:,:), Vscf_par(:,:),794 real(grid_p), pointer :: Vscf(:,:), Vscf_par(:,:),
@@ -818,9 +799,7 @@
818 & DRho_quad(:,:) => null()799 & DRho_quad(:,:) => null()
819 ! Temporary reciprocal spin quantity800 ! Temporary reciprocal spin quantity
820 real(grid_p) :: rnsd801 real(grid_p) :: rnsd
821#ifdef BSC_CELLXC802
822 real(grid_p), pointer :: Vscf_gga(:,:), DRho_gga(:,:)
823#endif /* BSC_CELLXC */
824#ifdef MPI803#ifdef MPI
825 integer :: MPIerror804 integer :: MPIerror
826 real(dp) :: sbuffer(7), rbuffer(7)805 real(dp) :: sbuffer(7), rbuffer(7)
@@ -862,9 +841,7 @@
862841
863 nullify( Vscf, Vscf_par, DRho, DRho_par,842 nullify( Vscf, Vscf_par, DRho, DRho_par,
864 & Vaux, Vaux_par, Chlocal, Totchar )843 & Vaux, Vaux_par, Chlocal, Totchar )
865#ifdef BSC_CELLXC
866 nullify( Vscf_gga, DRho_gga)844 nullify( Vscf_gga, DRho_gga)
867#endif /* BSC_CELLXC */
868845
869 volume = volcel(cell)846 volume = volcel(cell)
870847
@@ -1471,19 +1448,6 @@
1471!$OMP end parallel do1448!$OMP end parallel do
1472 endif1449 endif
14731450
1474C ----------------------------------------------------------------------
1475#ifndef BSC_CELLXC
1476C Set uniform distribution of mesh points and find my processor mesh box
1477C This is the interface to JM Soler's own cellxc routine, which sets
1478C up the right distribution internally.
1479C ----------------------------------------------------------------------
1480
1481 call jms_setMeshDistr( distrID=JDGdistr, nMesh=ntm,
1482 . nNodesX=1, nNodesY=ProcessorY, nBlock=nsm )
1483 call myMeshBox( ntm, JDGdistr, myBox )
1484
1485C ----------------------------------------------------------------------
1486#endif /* ! BSC_CELLXC */
1487C Exchange-correlation energy1451C Exchange-correlation energy
1488C ----------------------------------------------------------------------1452C ----------------------------------------------------------------------
1489 call re_alloc( Vscf, 1, ntpl, 1, nspin, 'Vscf', 'dhscf' )1453 call re_alloc( Vscf, 1, ntpl, 1, nspin, 'Vscf', 'dhscf' )
@@ -1534,64 +1498,83 @@
15341498
1535! Everything now is in UNIFORM, sequential form1499! Everything now is in UNIFORM, sequential form
15361500
1537 call timer("CellXC",1)1501 call timer("XC",1)
1538#ifdef BSC_CELLXC1502
1539 if (nodes.gt.1) then1503 ! Switch to "zero/not-zero rho" distribution (miscalled 'LINEAR')
1540 call setMeshDistr( LINEAR, nsm, nsp, nml, nmpl, ntml, ntpl )1504 if (nodes.gt.1) then
1541 endif1505 call setMeshDistr( LINEAR, nsm, nsp, nml, nmpl, ntml, ntpl )
15421506 endif
1543 call re_alloc( Vscf_gga, 1, ntpl, 1, nspin, 'Vscf_gga', 'dhscf' )1507
1544 call re_alloc( DRho_gga, 1, ntpl, 1, nspin, 'DRho_gga', 'dhscf' )1508 call re_alloc( Vscf_gga, 1, ntpl, 1, nspin, 'Vscf_gga','dhscf')
15451509 call re_alloc( DRho_gga, 1, ntpl, 1, nspin, 'DRho_gga','dhscf')
1546 ! Redistribute all spin densities1510
1547 do ispin = 1, nspin1511 ! Redistribute all spin densities
1548 fsrc => DRho(:,ispin)1512 do ispin = 1, nspin
1549 fdst => DRho_gga(:,ispin)1513 fsrc => DRho(:,ispin)
1550 call distMeshData( UNIFORM, fsrc, LINEAR, fdst, KEEP )1514 fdst => DRho_gga(:,ispin)
1551 enddo1515 call distMeshData( UNIFORM, fsrc, LINEAR, fdst, KEEP )
15521516 enddo
1553 call bsc_cellxc( 0, 0, cell, ntml, ntml, ntpl, 0, aux3, nspin,1517
1554 & DRho_gga, Ex, Ec, DEx, DEc, Vscf_gga,1518 if (use_bsc_cellxc) then
1555 & dummy_DVxcdn, stressl )1519
1556#endif /* BSC_CELLXC */1520 call timer("BSC-CellXC",1)
15571521 call bsc_cellxc( 0, 0, cell, ntml, ntml, ntpl, 0, aux3, nspin,
1558#ifndef BSC_CELLXC1522 & DRho_gga, Ex, Ec, DEx, DEc, Vscf_gga,
1559 call cellXC( 0, cell, ntm, myBox(1,1), myBox(2,1),1523 & dummy_DVxcdn, stressl )
1560 . myBox(1,2), myBox(2,2),1524
1561 . myBox(1,3), myBox(2,3), nspin,1525 call timer("BSC-CellXC",2)
1562 . DRho, Ex, Ec, DEx, DEc, stressXC, Vscf )1526
1563#else /* BSC_CELLXC */1527 else
15641528
1565 if (nodes.gt.1) then1529 call timer("GXC-CellXC",1)
1566 call setMeshDistr( UNIFORM, nsm, nsp, nml, nmpl, ntml, ntpl )1530
1567 endif1531 ! Note that RG's meshLim is in blocks of nsm points, and 1-based
15681532 ! Example.
1569 ! Redistribute to the Vxc array1533 ! 1:16 17:32 (base 1)
1570 do ispin = 1,nspin1534 ! 0:15 16:31 (base 0)
1571 fsrc => Vscf_gga(:,ispin)1535 ! Times nsm=2:
1572 fdst => Vscf(:,ispin)1536 ! 0:30 32:62
1573 call distMeshData( LINEAR, fsrc, UNIFORM, fdst, KEEP )1537 ! Add 1 to lb, and nsm to ub:
1574 enddo1538 ! 1:32 33:64 (base 1, in units of small-points)
1575#endif /* BSC_CELLXC */1539
1540 myBox(1,:) = (meshLim(1,:)-1)*nsm + 1
1541 myBox(2,:) = (meshLim(2,:)-1)*nsm + nsm
1542
1543 call cellXC( 0, cell, ntm, myBox(1,1), myBox(2,1),
1544 & myBox(1,2), myBox(2,2),
1545 & myBox(1,3), myBox(2,3), nspin,
1546 & DRho_gga, Ex, Ec, DEx, DEc, stressXC, Vscf_gga,
1547 & keep_input_distribution = .true. )
1548 ! Vscf is still sequential after the call to JMS's cellxc
1549 stress = stress + stressXC
1550 call timer("GXC-CellXC",2)
1551
1552 endif ! use_bsc_cellxc
1553
1554 ! Go back to uniform distribution
1555 if (nodes.gt.1) then
1556 call setMeshDistr( UNIFORM, nsm, nsp, nml, nmpl, ntml, ntpl)
1557 endif
1558
1559 ! Redistribute to the Vxc array
1560 do ispin = 1,nspin
1561 fsrc => Vscf_gga(:,ispin)
1562 fdst => Vscf(:,ispin)
1563 call distMeshData( LINEAR, fsrc, UNIFORM, fdst, KEEP )
1564 enddo
1565 call de_alloc( DRho_gga, 'DRho_gga', 'dhscf' )
1566 call de_alloc( Vscf_gga, 'Vscf_gga', 'dhscf' )
1567
1568 call timer("XC",2)
15761569
1577 if ( debug_dhscf ) then1570 if ( debug_dhscf ) then
1578 write(*,debug_fmt) Node,'XC',1571 write(*,debug_fmt) Node,'XC',
1579 & (sqrt(sum(Vscf(:,ispin)**2)),ispin=1,nspin)1572 & (sqrt(sum(Vscf(:,ispin)**2)),ispin=1,nspin)
1580 end if1573 end if
1581 1574
1582
1583#ifndef BSC_CELLXC
1584! Vscf is still sequential after the call to JMS's cellxc
1585#else /* BSC_CELLXC */
1586 call de_alloc( DRho_gga, 'DRho_gga', 'dhscf' )
1587 call de_alloc( Vscf_gga, 'Vscf_gga', 'dhscf' )
1588#endif /* BSC_CELLXC */
1589
1590 Exc = Ex + Ec1575 Exc = Ex + Ec
1591 Dxc = DEx + DEc1576 Dxc = DEx + DEc
15921577
1593 call timer("CellXC",2)
1594
1595! Vscf contains only Vxc, and is UNIFORM and sequential1578! Vscf contains only Vxc, and is UNIFORM and sequential
1596! Now we add up the other contributions to it, at 1579! Now we add up the other contributions to it, at
1597! the same time that we get DRho back to true DeltaRho form1580! the same time that we get DRho back to true DeltaRho form
@@ -1618,10 +1601,6 @@
1618 enddo1601 enddo
1619!$OMP end parallel1602!$OMP end parallel
16201603
1621#ifndef BSC_CELLXC
1622 stress = stress + stressXC
1623#endif /* ! BSC_CELLXC */
1624
1625C ----------------------------------------------------------------------1604C ----------------------------------------------------------------------
1626C Save total potential1605C Save total potential
1627C ----------------------------------------------------------------------1606C ----------------------------------------------------------------------
@@ -1700,20 +1679,16 @@
17001679
1701#ifdef MPI1680#ifdef MPI
1702C Global reduction of Uscf/DUscf/Uatm/Enaatm/Enascf1681C Global reduction of Uscf/DUscf/Uatm/Enaatm/Enascf
1703#ifndef BSC_CELLXC
1704! Note that Exc and Dxc are already reduced in the new cellxc
1705#endif /* ! BSC_CELLXC */
1706 sbuffer(1) = Uscf1682 sbuffer(1) = Uscf
1707 sbuffer(2) = DUscf1683 sbuffer(2) = DUscf
1708 sbuffer(3) = Uatm1684 sbuffer(3) = Uatm
1709 sbuffer(4) = Enaatm1685 sbuffer(4) = Enaatm
1710 sbuffer(5) = Enascf1686 sbuffer(5) = Enascf
1711#ifdef BSC_CELLXC1687 if (use_bsc_cellxc) then
1712 sbuffer(6) = Exc1688 sbuffer(6) = Exc
1713 sbuffer(7) = Dxc1689 sbuffer(7) = Dxc
1714#else1690 endif
1715 sbuffer(6:7) = 0._dp1691
1716#endif /* BSC_CELLXC */
1717 call MPI_AllReduce( sbuffer, rbuffer, 7, MPI_double_precision,1692 call MPI_AllReduce( sbuffer, rbuffer, 7, MPI_double_precision,
1718 & MPI_Sum, MPI_Comm_World, MPIerror )1693 & MPI_Sum, MPI_Comm_World, MPIerror )
1719 Uscf = rbuffer(1)1694 Uscf = rbuffer(1)
@@ -1721,10 +1696,10 @@
1721 Uatm = rbuffer(3)1696 Uatm = rbuffer(3)
1722 Enaatm = rbuffer(4)1697 Enaatm = rbuffer(4)
1723 Enascf = rbuffer(5)1698 Enascf = rbuffer(5)
1724#ifdef BSC_CELLXC1699 if (use_bsc_cellxc) then
1725 Exc = rbuffer(6)1700 Exc = rbuffer(6)
1726 Dxc = rbuffer(7)1701 Dxc = rbuffer(7)
1727#endif /* BSC_CELLXC */1702 endif
1728#endif /* MPI */1703#endif /* MPI */
17291704
1730C Add contribution to stress from the derivative of the Jacobian of ---1705C Add contribution to stress from the derivative of the Jacobian of ---
@@ -1782,11 +1757,8 @@
1782 if ( harrisfun) then1757 if ( harrisfun) then
1783! Forhar deals internally with its own needs1758! Forhar deals internally with its own needs
1784! for distribution changes1759! for distribution changes
1785#ifndef BSC_CELLXC1760! Upon entry, everything is UNIFORM, sequential form
1786 call forhar( ntpl, nspin, nml, ntml, ntm, npcc, cell, 1761 call forhar( ntpl, nspin, nml, ntml, ntm, npcc, cell,
1787#else /* BSC_CELLXC */
1788 call forhar( ntpl, nspin, nml, ntml, npcc, cell,
1789#endif /* BSC_CELLXC */
1790 & rhoatm, rhopcc, Vna, DRho, Vscf, Vaux )1762 & rhoatm, rhopcc, Vna, DRho, Vscf, Vaux )
1791! Upon return, everything is UNIFORM, sequential form1763! Upon return, everything is UNIFORM, sequential form
1792 endif1764 endif
@@ -1993,4 +1965,30 @@
1993 endif1965 endif
1994 end subroutine delk_wrapper1966 end subroutine delk_wrapper
19951967
1968 !> Chech whether we need to initialize stencils for
1969 !> BSC's version of cellxc, and whether we have a vdw
1970 !> functional
1971 subroutine xc_setup(need_grads,is_vdw)
1972 use siestaxc, only: getxc
1973
1974 logical, intent(out) :: need_grads
1975 logical, intent(out) :: is_vdw
1976
1977 integer :: nf, nXCfunc
1978 character(len=20):: XCauth(10), XCfunc(10)
1979
1980 need_grads = .false.
1981 is_vdw = .false.
1982 call getXC( nXCfunc, XCfunc, XCauth )
1983 do nf = 1,nXCfunc
1984 if ( XCfunc(nf).eq.'GGA' .or. XCfunc(nf).eq.'gga') then
1985 need_grads = .true.
1986 endif
1987 if ( XCfunc(nf).eq.'VDW' .or. XCfunc(nf).eq.'vdw') then
1988 need_grads = .true.
1989 is_vdw = .true.
1990 endif
1991 enddo
1992 end subroutine xc_setup
1993
1996 end module m_dhscf1994 end module m_dhscf
19971995
=== modified file 'Src/forhar.F'
--- Src/forhar.F 2016-01-25 16:00:16 +0000
+++ Src/forhar.F 2019-01-30 13:43:54 +0000
@@ -6,35 +6,15 @@
6! See Docs/Contributors.txt for a list of contributors.6! See Docs/Contributors.txt for a list of contributors.
7!7!
8 module m_forhar8 module m_forhar
9 use precision, only : dp, grid_p
10 use alloc, only : re_alloc, de_alloc
11#ifndef BSC_CELLXC
12 use parallel, only : ProcessorY
13 use mesh, only : NSM
14 use siestaXC, only : cellXC ! Finds xc energy and potential
15 use siestaXC, only : myMeshBox ! Returns my processor mesh box
16 use siestaXC, only : jms_setMeshDistr => setMeshDistr
17 ! Sets a distribution of mesh
18 ! points over parallel processors
199
20#else /* BSC_CELLXC */
21 use mesh
22 use moreMeshSubs, only : setMeshDistr, distMeshData
23 use moreMeshSubs, only: UNIFORM, LINEAR
24 use moreMeshSubs, only: KEEP
25#endif /* BSC_CELLXC */
26 implicit none10 implicit none
2711
28 public :: forhar12 public :: forhar
29 private13 private
3014
31 CONTAINS15 CONTAINS
32#ifndef BSC_CELLXC
33 subroutine forhar( NTPL, NSPIN, NML, NTML, NTM, NPCC,16 subroutine forhar( NTPL, NSPIN, NML, NTML, NTM, NPCC,
34 $ CELL, RHOATM,17 $ CELL, RHOATM,
35#else /* BSC_CELLXC */
36 subroutine forhar( NTPL, NSPIN, NML, NTML, NPCC, CELL, RHOATM,
37#endif /* BSC_CELLXC */
38 & RHOPCC, VNA, DRHOOUT, VHARRIS1, VHARRIS2 )18 & RHOPCC, VNA, DRHOOUT, VHARRIS1, VHARRIS2 )
3919
40C **********************************************************************20C **********************************************************************
@@ -45,6 +25,7 @@
45C In the first SCF step, V_Hartree(DeltaRho_in) is zero, because25C In the first SCF step, V_Hartree(DeltaRho_in) is zero, because
46C in that case, Rho_SCF(r) = Rho_atm(r) and therefore, DeltaRho(r) = 026C in that case, Rho_SCF(r) = Rho_atm(r) and therefore, DeltaRho(r) = 0
47C This calculation will be skipped.27C This calculation will be skipped.
28C NOTE: This is true only if the initial DM is built from atomic charges...
48C If Harris + Spin polarized in the first SCF step, then Vharris2 will29C If Harris + Spin polarized in the first SCF step, then Vharris2 will
49C multiply to D Rho(Harris)/D R inside dfscf, and the change of 30C multiply to D Rho(Harris)/D R inside dfscf, and the change of
50C the harris density respect the displacement31C the harris density respect the displacement
@@ -53,25 +34,30 @@
53C Coded by J. Junquera 09/0034C Coded by J. Junquera 09/00
54C **********************************************************************35C **********************************************************************
5536
37 use precision, only : dp, grid_p
38 use alloc, only : re_alloc, de_alloc
39
40 use parallel, only : nodes
41 use mesh, only : NSM, nsp, meshLim
42 use siestaXC, only : cellXC ! Finds xc energy and potential
43
44 use moreMeshSubs, only : setMeshDistr, distMeshData
45 use moreMeshSubs, only: UNIFORM, LINEAR
46 use moreMeshSubs, only: KEEP
47
48 use fdf, only: fdf_get
49
56 INTEGER :: NTPL, NML(3), NTML(3)50 INTEGER :: NTPL, NML(3), NTML(3)
57#ifndef BSC_CELLXC
58 INTEGER, INTENT(IN) :: NSPIN, NPCC, NTM(3)51 INTEGER, INTENT(IN) :: NSPIN, NPCC, NTM(3)
59#else /* BSC_CELLXC */
60 INTEGER, INTENT(IN) :: NSPIN, NPCC
61#endif /* BSC_CELLXC */
62 52
63 REAL(dp), INTENT(IN) :: CELL(3,3)53 REAL(dp), INTENT(IN) :: CELL(3,3)
64 REAL(grid_p), INTENT(IN) :: VNA(NTPL), RHOATM(NTPL),54 REAL(grid_p), INTENT(IN) :: VNA(NTPL), RHOATM(NTPL),
65 & RHOPCC(NTPL)55 & RHOPCC(NTPL)
66 REAL(grid_p), INTENT(INOUT) :: DRHOOUT(NTPL,NSPIN)56 REAL(grid_p), INTENT(IN) :: DRHOOUT(NTPL,NSPIN)
67 REAL(grid_p), TARGET, INTENT(INOUT) :: VHARRIS1(NTPL,NSPIN)57 REAL(grid_p), TARGET, INTENT(OUT) :: VHARRIS1(NTPL,NSPIN)
68 REAL(grid_p), INTENT(INOUT) :: VHARRIS2(NTPL)58 REAL(grid_p), INTENT(OUT) :: VHARRIS2(NTPL)
69 59
70#ifndef BSC_CELLXC
71 EXTERNAL REORD
72#else /* BSC_CELLXC */
73 EXTERNAL bsc_cellxc60 EXTERNAL bsc_cellxc
74#endif /* BSC_CELLXC */
7561
76! AG: Note: REAL*4 variables are really REAL(kind=grid_p)62! AG: Note: REAL*4 variables are really REAL(kind=grid_p)
77!63!
@@ -92,7 +78,7 @@
92C is Drho_out-Rhoatm.78C is Drho_out-Rhoatm.
93C ***** OUTPUT *********************************************************79C ***** OUTPUT *********************************************************
94C REAL*4 VHARRIS1(NTPL,NSPIN) : Vna + V_Hartree(DeltaRho_in) + V_xc(Rho_in)80C REAL*4 VHARRIS1(NTPL,NSPIN) : Vna + V_Hartree(DeltaRho_in) + V_xc(Rho_in)
95C REAL*4 VHARRIS2(NTPL) : Vna + V_Hartree(Rho_in) +81C REAL*4 VHARRIS2(NTPL) : Vna + V_Hartree(DeltaRho_in) +
96C - DV_xc(Rho_in)/DRho_in * (Rho_out-Rho_in)82C - DV_xc(Rho_in)/DRho_in * (Rho_out-Rho_in)
97C If Harris forces are computed in the 83C If Harris forces are computed in the
98C first SCF step, it does not depend on spin84C first SCF step, it does not depend on spin
@@ -104,24 +90,16 @@
104C ----------------------------------------------------------------------90C ----------------------------------------------------------------------
105C Internal variables and arrays91C Internal variables and arrays
106C ----------------------------------------------------------------------92C ----------------------------------------------------------------------
107#ifndef BSC_CELLXC93
108 INTEGER IP, ISPIN, ISPIN2, myBox(2,3)94 INTEGER IP, ISPIN, ISPIN2, myBox(2,3), NMPL
109 REAL(dp) EX, EC, DEX, DEC, STRESS(3,3)95 REAL(dp) EX, EC, DEX, DEC, STRESS(3,3)
110 INTEGER, SAVE:: JDGdistr=-1
11196
112 real(grid_p), pointer :: drhoin(:,:),
113 & dvxcdn(:,:,:)
114#else /* BSC_CELLXC */
115 INTEGER :: IP, ISPIN, ISPIN2, NMPL
116 REAL(dp) :: EX, EC, DEX, DEC, STRESSL(3,3)
117 real(grid_p) :: aux3(3,1) !! dummy arrays for cellxc97 real(grid_p) :: aux3(3,1) !! dummy arrays for cellxc
118
119 real(grid_p), pointer :: drhoin(:,:), drhoin_par(:,:),98 real(grid_p), pointer :: drhoin(:,:), drhoin_par(:,:),
120 & dvxcdn(:,:,:), dvxcdn_par(:,:,:),99 & dvxcdn(:,:,:), dvxcdn_par(:,:,:),
121 & vharris1_par(:,:), fsrc(:), fdst(:)100 & vharris1_par(:,:), fsrc(:), fdst(:)
122 INTEGER :: ntpl_3101 logical :: use_bsc_cellxc
123#endif /* BSC_CELLXC */102
124
125 nullify( drhoin, dvxcdn )103 nullify( drhoin, dvxcdn )
126 call re_alloc( drhoin, 1, ntpl, 1, nspin, 'drhoin', 'forhar' )104 call re_alloc( drhoin, 1, ntpl, 1, nspin, 'drhoin', 'forhar' )
127 call re_alloc( dvxcdn, 1, ntpl, 1, nspin, 1, nspin,105 call re_alloc( dvxcdn, 1, ntpl, 1, nspin, 1, nspin,
@@ -134,18 +112,6 @@
134 VHARRIS2(:) = 0.0_grid_p112 VHARRIS2(:) = 0.0_grid_p
135 DRHOIN(:,:) = 0.0_grid_p113 DRHOIN(:,:) = 0.0_grid_p
136 DVXCDN(:,:,:) = 0.0_grid_p114 DVXCDN(:,:,:) = 0.0_grid_p
137#ifndef BSC_CELLXC
138
139C ----------------------------------------------------------------------
140C Set uniform distribution of mesh points and find my processor mesh box
141C ----------------------------------------------------------------------
142
143 call jms_setMeshDistr( distrID=JDGdistr, nMesh=NTM,
144 . nNodesX=1, nNodesY=ProcessorY, nBlock=NSM )
145 call myMeshBox( NTM, JDGdistr, myBox )
146#else /* BSC_CELLXC */
147 STRESSL(:,:) = 0.0_dp
148#endif /* BSC_CELLXC */
149115
150C ----------------------------------------------------------------------116C ----------------------------------------------------------------------
151C Compute exchange-correlation energy and potential and117C Compute exchange-correlation energy and potential and
@@ -153,6 +119,7 @@
153C or the sum of atomic charges.119C or the sum of atomic charges.
154C ----------------------------------------------------------------------120C ----------------------------------------------------------------------
155121
122 ! All these arrays are in the UNIFORM distribution,in SEQUENTIAL form
156 DO ISPIN = 1, NSPIN123 DO ISPIN = 1, NSPIN
157 DRHOIN(1:NTPL,ISPIN) = RHOATM(1:NTPL)/NSPIN 124 DRHOIN(1:NTPL,ISPIN) = RHOATM(1:NTPL)/NSPIN
158 IF (NPCC .EQ. 1) 125 IF (NPCC .EQ. 1)
@@ -160,79 +127,71 @@
160 . RHOPCC(1:NTPL)/NSPIN127 . RHOPCC(1:NTPL)/NSPIN
161 ENDDO128 ENDDO
162129
163#ifdef BSC_CELLXC130 ! Give the opportunity to use BSC's version
164#ifdef MPI131 use_bsc_cellxc = fdf_get("XC.Use.BSC.Cellxc",.false.)
165 ! The input distribution is UNIFORM, but we need to work132
166 ! with the LINEAR one133 ! The input distribution is UNIFORM, but we need to work with the
167 call setMeshDistr( LINEAR, nsm, nsp, nml, nmpl, ntml, ntpl )134 ! "zero/not-zero rho" distribution (miscalled 'LINEAR')
168#endif135 if (nodes.gt.1) then
169 ntpl_3 = ntpl136 call setMeshDistr( LINEAR, nsm, nsp, nml, nmpl, ntml, ntpl )
137 endif
170138
171 nullify( drhoin_par, vharris1_par, dvxcdn_par )139 nullify( drhoin_par, vharris1_par, dvxcdn_par )
172 call re_alloc( drhoin_par, 1, ntpl_3, 1, nspin,140 call re_alloc( drhoin_par, 1, ntpl, 1, nspin,
173 & 'drhoin_par', 'forhar' )141 & 'drhoin_par', 'forhar' )
174 call re_alloc( vharris1_par, 1, ntpl_3, 1, nspin,142 call re_alloc( vharris1_par, 1, ntpl, 1, nspin,
175 & 'vharris1_par', 'forhar' )143 & 'vharris1_par', 'forhar' )
176 call re_alloc( dvxcdn_par, 1, ntpl_3, 1, nspin, 1, nspin,144 call re_alloc( dvxcdn_par, 1, ntpl, 1, nspin, 1, nspin,
177 & 'dvxcdn_par', 'forhar' )145 & 'dvxcdn_par', 'forhar' )
178#endif /* BSC_CELLXC */
179146
180 DO ISPIN = 1, NSPIN147 DO ISPIN = 1, NSPIN
181#ifndef BSC_CELLXC
182 CALL REORD(DRHOIN(1,ISPIN),DRHOIN(1,ISPIN),NML,NSM,+1)
183#else /* BSC_CELLXC */
184 fsrc => drhoin(:,ispin)148 fsrc => drhoin(:,ispin)
185 fdst => drhoin_par(:,ispin)149 fdst => drhoin_par(:,ispin)
186 call distMeshData( UNIFORM, fsrc, LINEAR, fdst, KEEP )150 call distMeshData( UNIFORM, fsrc, LINEAR, fdst, KEEP )
187#endif /* BSC_CELLXC */
188 ENDDO151 ENDDO
189152
190#ifndef BSC_CELLXC153 if (use_bsc_cellxc) then
191 CALL CELLXC( 0, CELL, NTM, myBox(1,1), myBox(2,1),154
192 . myBox(1,2), myBox(2,2),155 STRESS(:,:) = 0.0_dp
193 . myBox(1,3), myBox(2,3), NSPIN, DRHOIN,156 CALL bsc_cellxc( 0, 1, CELL, NTML, NTML, NTPL, 0, AUX3, NSPIN,
194 . EX, EC, DEX, DEC, STRESS, VHARRIS1, DVXCDN )
195#else /* BSC_CELLXC */
196 CALL bsc_cellxc( 0, 1, CELL, NTML, NTML, NTPL, 0, AUX3, NSPIN,
197 & DRHOIN_PAR, EX, EC, DEX, DEC, VHARRIS1_PAR,157 & DRHOIN_PAR, EX, EC, DEX, DEC, VHARRIS1_PAR,
198 & DVXCDN_PAR, STRESSL )158 & DVXCDN_PAR, STRESS )
199#endif /* BSC_CELLXC */159
160 else
161
162 myBox(1,:) = (meshLim(1,:)-1)*nsm + 1
163 myBox(2,:) = (meshLim(2,:)-1)*nsm + nsm
164
165 CALL CELLXC( 0, CELL, NTM, myBox(1,1), myBox(2,1),
166 . myBox(1,2), myBox(2,2),
167 . myBox(1,3), myBox(2,3), NSPIN, DRHOIN_par,
168 . EX, EC, DEX, DEC, STRESS, VHARRIS1_par, DVXCDN_par,
169 & keep_input_distribution = .true. )
170
171 endif
172
173 if (nodes.gt.1) then
174! Everything back to UNIFORM, sequential
175 call setMeshDistr( UNIFORM, nsm, nsp,
176 & nml, nmpl, ntml, ntpl )
177 endif
200178
201 DO ISPIN = 1, NSPIN179 DO ISPIN = 1, NSPIN
202#ifndef BSC_CELLXC
203 CALL REORD(DRHOIN(1,ISPIN),DRHOIN(1,ISPIN),NML,NSM,-1)
204 CALL REORD(VHARRIS1(1,ISPIN),VHARRIS1(1,ISPIN),NML,NSM,-1)
205
206#else /* BSC_CELLXC */
207 fsrc => VHARRIS1_PAR(:,ISPIN)180 fsrc => VHARRIS1_PAR(:,ISPIN)
208 fdst => VHARRIS1(:,ispin)181 fdst => VHARRIS1(:,ispin)
209 call distMeshData( LINEAR, fsrc, UNIFORM, fdst, KEEP )182 call distMeshData( LINEAR, fsrc, UNIFORM, fdst, KEEP )
210#endif /* BSC_CELLXC */
211 DO ISPIN2 = 1, NSPIN183 DO ISPIN2 = 1, NSPIN
212#ifndef BSC_CELLXC
213 CALL REORD(DVXCDN(1,ISPIN,ISPIN2),DVXCDN(1,ISPIN,ISPIN2),
214 . NML,NSM,-1)
215#else /* BSC_CELLXC */
216 fsrc => DVXCDN_PAR(:,ISPIN,ISPIN2)184 fsrc => DVXCDN_PAR(:,ISPIN,ISPIN2)
217 fdst => DVXCDN(:,ISPIN,ISPIN2)185 fdst => DVXCDN(:,ISPIN,ISPIN2)
218 call distMeshData( LINEAR, fsrc, UNIFORM, fdst, KEEP )186 call distMeshData( LINEAR, fsrc, UNIFORM, fdst, KEEP )
219#endif /* BSC_CELLXC */
220 ENDDO187 ENDDO
221 ENDDO188 ENDDO
222
223#ifdef BSC_CELLXC
224 call de_alloc( dvxcdn_par, 'dvxcdn_par', 'forhar' )189 call de_alloc( dvxcdn_par, 'dvxcdn_par', 'forhar' )
225 call de_alloc( vharris1_par, 'vharris1_par', 'forhar' )190 call de_alloc( vharris1_par, 'vharris1_par', 'forhar' )
226 call de_alloc( drhoin_par, 'drhoin_par', 'forhar' )191 call de_alloc( drhoin_par, 'drhoin_par', 'forhar' )
227192
228#ifdef MPI193
229 call setMeshDistr( UNIFORM, nsm, nsp, nml, nmpl, ntml, ntpl )
230#endif
231#endif /* BSC_CELLXC */
232 DO ISPIN = 1, NSPIN194 DO ISPIN = 1, NSPIN
233 IF( NPCC .EQ. 1)
234 & DRHOIN(1:NTPL,ISPIN) = DRHOIN(1:NTPL,ISPIN) -
235 & RHOPCC(1:NTPL)/NSPIN
236 DO IP = 1, NTPL195 DO IP = 1, NTPL
237 VHARRIS1(IP,ISPIN) = VHARRIS1(IP,ISPIN) + VNA(IP)196 VHARRIS1(IP,ISPIN) = VHARRIS1(IP,ISPIN) + VNA(IP)
238 ENDDO197 ENDDO
@@ -255,7 +214,7 @@
255214
256C ----------------------------------------------------------------------215C ----------------------------------------------------------------------
257C Since V_Hartree(DeltaRho_in) = 0.0, we only add to vharris2 the neutral216C Since V_Hartree(DeltaRho_in) = 0.0, we only add to vharris2 the neutral
258C atom potential217C atom potential (note sign change of above intermediate result)
259C ----------------------------------------------------------------------218C ----------------------------------------------------------------------
260 DO IP = 1, NTPL219 DO IP = 1, NTPL
261 VHARRIS2(IP) = VNA(IP) - VHARRIS2(IP)220 VHARRIS2(IP) = VNA(IP) - VHARRIS2(IP)
262221
=== modified file 'Src/ldau.F'
--- Src/ldau.F 2016-06-22 19:57:38 +0000
+++ Src/ldau.F 2019-01-30 13:43:54 +0000
@@ -197,14 +197,6 @@
197 type(rad_func), pointer :: pp197 type(rad_func), pointer :: pp
198C ......................198C ......................
199199
200#ifdef BSC_CELLXC
201 ! The only reason is that the XC functional
202 ! is not calculated exactly equivalent.
203 ! As such, one may delete this below line to make them accessible
204 ! in conjunction with each other...
205 call die('LDA+U and BSC_CELLXC is not compatible')
206#endif
207
208! Start time counter200! Start time counter
209 call timer( 'hubbard_term', 1 )201 call timer( 'hubbard_term', 1 )
210202
211203
=== modified file 'Src/meshsubs.F'
--- Src/meshsubs.F 2018-12-19 20:31:23 +0000
+++ Src/meshsubs.F 2019-01-30 13:43:54 +0000
@@ -1323,7 +1323,8 @@
13231323
1324!------------------------------------------------------------------1324!------------------------------------------------------------------
1325 subroutine distriPhiOnMesh( nm, nmpl, norb, iaorb,1325 subroutine distriPhiOnMesh( nm, nmpl, norb, iaorb,
1326 & iphorb, isa, numphi )1326 & iphorb, isa, numphi,
1327 & need_gradients_in_xc )
13271328
1328C Computes the number of orbitals that intersects every mesh point1329C Computes the number of orbitals that intersects every mesh point
1329C and calls initMeshDistr in order to compute a new data distribution1330C and calls initMeshDistr in order to compute a new data distribution
@@ -1337,7 +1338,7 @@
1337C integer iaorb(norb) : Atom to which each orbital belongs1338C integer iaorb(norb) : Atom to which each orbital belongs
1338C integer iphorb(norb) : Orbital index (within atom) of each orbital1339C integer iphorb(norb) : Orbital index (within atom) of each orbital
1339C integer isa(na) : Species index of all atoms in supercell1340C integer isa(na) : Species index of all atoms in supercell
1340C1341C logical need_gradients_in_xc :
1341C OUTPUT:1342C OUTPUT:
1342C The output values are in the module moreMeshSubs (New limits of the mesh1343C The output values are in the module moreMeshSubs (New limits of the mesh
1343C and the information needed to transfer data between data1344C and the information needed to transfer data between data
@@ -1377,13 +1378,14 @@
1377 use moreMeshSubs, only: initMeshDistr1378 use moreMeshSubs, only: initMeshDistr
1378 use moreMeshSubs, only: allocASynBuffer1379 use moreMeshSubs, only: allocASynBuffer
1379 use moreMeshSubs, only: UNIFORM, QUADRATIC, LINEAR1380 use moreMeshSubs, only: UNIFORM, QUADRATIC, LINEAR
1380 use cellxc_mod, only: GGA, setGGA
1381 use alloc, only: re_alloc, de_alloc1381 use alloc, only: re_alloc, de_alloc
1382
1382 implicit none1383 implicit none
1383C Passed arguments1384C Passed arguments
1384 integer, intent(in) :: nm(3), nmpl, norb, iaorb(norb),1385 integer, intent(in) :: nm(3), nmpl, norb, iaorb(norb),
1385 & iphorb(norb), isa(*)1386 & iphorb(norb), isa(*)
1386 integer, intent(out) :: numphi(nmpl)1387 integer, intent(out) :: numphi(nmpl)
1388 logical, intent(in) :: need_gradients_in_xc
1387C Local variables1389C Local variables
1388 integer :: ii, io, ia, iphi, is, iop, ip0, isp1390 integer :: ii, io, ia, iphi, is, iop, ip0, isp
1389 real(dp) :: r2o, dxsp(3,nsp), r2sp(nsp)1391 real(dp) :: r2o, dxsp(3,nsp), r2sp(nsp)
@@ -1442,7 +1444,7 @@
1442 endif1444 endif
1443 enddo1445 enddo
1444 call initMeshDistr( UNIFORM, LINEAR, nm, wload )1446 call initMeshDistr( UNIFORM, LINEAR, nm, wload )
1445 if (GGA) call initMeshExtencil( LINEAR, nm )1447 if (need_gradients_in_xc) call initMeshExtencil( LINEAR, nm )
14461448
1447C Free local memory1449C Free local memory
1448 call de_alloc( wload, 'wload', 'distriPhiOnMesh' )1450 call de_alloc( wload, 'wload', 'distriPhiOnMesh' )
14491451
=== modified file 'Src/siesta_init.F'
--- Src/siesta_init.F 2018-10-15 21:10:25 +0000
+++ Src/siesta_init.F 2019-01-30 13:43:54 +0000
@@ -30,9 +30,6 @@
30 & initatomlists, no_l, rmaxldau30 & initatomlists, no_l, rmaxldau
31 use fdf31 use fdf
32 use sys, only: die, bye32 use sys, only: die, bye
33#ifdef BSC_CELLXC
34 use bsc_xcmod, only: setXC
35#endif /* BSC_CELLXC */
36 use molecularmechanics, only: inittwobody33 use molecularmechanics, only: inittwobody
37 use metaforce, only: initmeta34 use metaforce, only: initmeta
38 use m_mpi_utils, only: broadcast35 use m_mpi_utils, only: broadcast
@@ -366,11 +363,7 @@
366363
367364
368! Initialise exchange-correlation functional information365! Initialise exchange-correlation functional information
369#ifndef BSC_CELLXC
370 call read_xc_info()366 call read_xc_info()
371#else /* BSC_CELLXC */
372 call setXC( )
373#endif /* BSC_CELLXC */
374367
375! Initialise force field component368! Initialise force field component
376 call inittwobody( )369 call inittwobody( )
377370
=== removed file 'Src/xc.f'
--- Src/xc.f 2017-07-01 20:58:50 +0000
+++ Src/xc.f 1970-01-01 00:00:00 +0000
@@ -1,2547 +0,0 @@
1!
2! Copyright (C) 1996-2016 The SIESTA group
3! This file is distributed under the terms of the
4! GNU General Public License: see COPYING in the top directory
5! or http://www.gnu.org/copyleft/gpl.txt.
6! See Docs/Contributors.txt for a list of contributors.
7!
8! *******************************************************************
9! This file contains XC subroutines used when siesta is compiled with
10! option BSC_CELLXC. Otherwise, the SiestaXC library is used.
11! *******************************************************************
12
13 subroutine atomxc( IREL, NR, MAXR, RMESH, nspin, Dens,
14 . EX, EC, DX, DC, VXC )
15
16C *******************************************************************
17C Finds total exchange-correlation energy and potential for a
18C spherical electron density distribution.
19C This version implements the Local (spin) Density Approximation and
20C the Generalized-Gradient-Aproximation with the 'explicit mesh
21C functional' approach of White & Bird, PRB 50, 4954 (1994).
22C Gradients are 'defined' by numerical derivatives, using 2*NN+1 mesh
23C points, where NN is a parameter defined below
24C Ref: L.C.Balbas et al, PRB 64, 165110 (2001)
25C Wrtten by J.M.Soler using algorithms developed by
26C L.C.Balbas, J.L.Martins and J.M.Soler, Dec.1996
27C ************************* INPUT ***********************************
28C CHARACTER*(*) FUNCTL : Functional to be used:
29C 'LDA' or 'LSD' => Local (spin) Density Approximation
30C 'GGA' => Generalized Gradient Corrections
31C Uppercase is optional
32C CHARACTER*(*) AUTHOR : Parametrization desired:
33C 'CA' or 'PZ' => LSD Perdew & Zunger, PRB 23, 5075 (1981)
34C 'PW91' => GGA Perdew & Wang, JCP, 100, 1290 (1994)
35C 'PW92' => LSD Perdew & Wang, PRB, 45, 13244 (1992). This is
36C the local density limit of the next:
37C 'PBE' => GGA Perdew, Burke & Ernzerhof, PRL 77, 3865 (1996)
38C 'RPBE' => GGA Hammer, Hansen & Norskov, PRB 59, 7413 (1999)
39C 'REVPBE' => GGA Zhang & Yang, PRL 80,890(1998)
40C 'LYP' => GGA Becke-Lee-Yang-Parr (see subroutine blypxc)
41C 'WC' => GGA Wu-Cohen (see subroutine wcxc)
42C 'PBESOL' => GGA Perdew et al, PRL, 100, 136406 (2008)
43C Uppercase is optional
44C INTEGER IREL : Relativistic exchange? (0=>no, 1=>yes)
45C INTEGER NR : Number of radial mesh points
46C INTEGER MAXR : Physical first dimension of RMESH, Dens and VXC
47C REAL*8 RMESH(MAXR) : Radial mesh points
48C INTEGER nspin : nspin=1 => unpolarized; nspin=2 => polarized
49C REAL*8 Dens(MAXR,nspin) : Total (nspin=1) or spin (nspin=2) electron
50C density at mesh points
51C ************************* OUTPUT **********************************
52C REAL*8 EX : Total exchange energy
53C REAL*8 EC : Total correlation energy
54C REAL*8 DX : IntegralOf( rho * (eps_x - v_x) )
55C REAL*8 DC : IntegralOf( rho * (eps_c - v_c) )
56C REAL*8 VXC(MAXR,nspin) : (Spin) exch-corr potential
57C ************************ UNITS ************************************
58C Distances in atomic units (Bohr).
59C Densities in atomic units (electrons/Bohr**3)
60C Energy unit depending of parameter EUNIT below
61C ********* ROUTINES CALLED *****************************************
62C GGAXC, LDAXC
63C *******************************************************************
64
65 use precision, only : dp
66 use bsc_xcmod, only : nXCfunc, XCfunc, XCauth
67 use bsc_xcmod, only : XCweightX, XCweightC
68 use sys, only: die
69 use alloc, only: re_alloc, de_alloc
70
71C Next line is nonstandard but may be suppressed
72 implicit none
73
74C Argument types and dimensions
75 integer, intent(in) :: IREL
76 integer, intent(in) :: MAXR
77 integer, intent(in) :: NR
78 integer, intent(in) :: nspin
79 real(dp), intent(in) :: Dens(MAXR,nspin)
80 real(dp), intent(in) :: RMESH(MAXR)
81 real(dp), intent(out) :: VXC(MAXR,nspin)
82 real(dp), intent(out) :: DC
83 real(dp), intent(out) :: DX
84 real(dp), intent(out) :: EC
85 real(dp), intent(out) :: EX
86
87C Internal parameters
88C NN : order of the numerical derivatives: the number of radial
89C points used is 2*NN+1
90C mspin : must be equal or larger than nspin (4 for non-collinear spin)
91 integer, parameter :: mspin = 4
92 integer, parameter :: NN = 5
93
94C Fix energy unit: EUNIT=1.0 => Hartrees,
95C EUNIT=0.5 => Rydbergs,
96C EUNIT=0.03674903 => eV
97 real(dp), parameter :: EUNIT = 0.5_dp
98
99C DVMIN is added to differential of volume to avoid division by zero
100 real(dp), parameter :: DVMIN = 1.0d-12
101
102C Local variables and arrays
103 logical
104 . GGA, GGAfunc
105 integer
106 . IN, IN1, IN2, IR, IS, JN, NF
107 real(dp)
108 . D(mspin), DECDD(mspin), DECDGD(3,mspin),
109 . DEXDD(mspin), DEXDGD(3,mspin),
110 . DGDM(-NN:NN), DGIDFJ(-NN:NN), DRDM, DVol,
111 . DVCDN(mspin,mspin), DVXDN(mspin,mspin),
112 . EPSC, EPSX, F1, F2, GD(3,mspin), PI
113 real(dp), pointer :: Aux(:)
114 external
115 . GGAXC, LDAXC
116
117C Set GGA switch
118 GGA = .false.
119 do nf = 1,nXCfunc
120 if ( XCfunc(nf).eq.'GGA' .or. XCfunc(nf).eq.'gga') then
121 GGA = .true.
122 else
123 if ( XCfunc(nf).ne.'LDA' .and. XCfunc(nf).ne.'lda' .and.
124 . XCfunc(nf).ne.'LSD' .and. XCfunc(nf).ne.'lsd' ) then
125 call die('ATOMXC: Unknown functional ' // XCfunc(nf))
126 endif
127 endif
128 enddo
129
130C Initialize output
131 EX = 0.0_dp
132 EC = 0.0_dp
133 DX = 0.0_dp
134 DC = 0.0_dp
135 do IS = 1,nspin
136 do IR = 1,NR
137 VXC(IR,IS) = 0.0_dp
138 enddo
139 enddo
140
141C Set up workspace array
142 if (GGA) then
143 nullify( Aux )
144 call re_alloc( AUX, 1, NR, 'AUX', 'atomxc' )
145 endif
146
147C Get number pi
148 PI = 4.0_dp * ATAN(1.0_dp)
149
150C Loop on mesh points
151 do IR = 1,NR
152
153C Find interval of neighbour points to calculate derivatives
154 IN1 = MAX( 1, IR-NN ) - IR
155 IN2 = MIN( NR, IR+NN ) - IR
156
157C Find weights of numerical derivation from Lagrange
158C interpolation formula
159 do IN = IN1,IN2
160 IF (IN .EQ. 0) THEN
161 DGDM(IN) = 0
162 do JN = IN1,IN2
163 IF (JN.NE.0) DGDM(IN) = DGDM(IN) + 1.D0 / (0 - JN)
164 enddo
165 ELSE
166 F1 = 1
167 F2 = 1
168 do JN = IN1,IN2
169 IF (JN.NE.IN .AND. JN.NE.0) F1 = F1 * (0 - JN)
170 IF (JN.NE.IN) F2 = F2 * (IN - JN)
171 enddo
172 DGDM(IN) = F1 / F2
173 ENDIF
174 enddo
175
176C Find dr/dmesh
177 DRDM = 0.0_dp
178 do IN = IN1,IN2
179 DRDM = DRDM + RMESH(IR+IN) * DGDM(IN)
180 enddo
181
182C Find differential of volume. Use trapezoidal integration rule
183 DVol = 4.0_dp * PI * RMESH(IR)**2 * DRDM
184C DVMIN is a small number added to avoid a division by zero
185 DVol = DVol + DVMIN
186 if (IR.eq.1 .or. IR.eq.NR) DVol = 0.5_dp*DVol
187 if (GGA) Aux(IR) = DVol
188
189C Find the weights for the derivative d(gradF(i))/d(F(j)), of
190C the gradient at point i with respect to the value at point j
191 if (GGA) then
192 do IN = IN1,IN2
193 DGIDFJ(IN) = DGDM(IN) / DRDM
194 enddo
195 endif
196
197C Find density and gradient of density at this point
198 do IS = 1,nspin
199 D(IS) = Dens(IR,IS)
200 enddo
201 if (GGA) then
202 do IS = 1,nspin
203 GD(1,IS) = 0.0_dp
204 GD(2,IS) = 0.0_dp
205 GD(3,IS) = 0.0_dp
206 do IN = IN1,IN2
207 GD(3,IS) = GD(3,IS) + DGIDFJ(IN) * Dens(IR+IN,IS)
208 enddo
209 enddo
210 endif
211
212C Loop over exchange-correlation functions
213 do nf = 1,nXCfunc
214
215C Is this a GGA?
216 if (XCfunc(nf).eq.'GGA' .or. XCfunc(nf).eq.'gga') then
217 GGAfunc = .true.
218 else
219 GGAfunc = .false.
220 endif
221
222C Find exchange and correlation energy densities and their
223C derivatives with respect to density and density gradient
224 if (GGAfunc) then
225 CALL GGAXC( XCauth(nf), IREL, nspin, D, GD,
226 . EPSX, EPSC, DEXDD, DECDD, DEXDGD, DECDGD )
227 else
228 CALL LDAXC( XCauth(nf), IREL, nspin, D, EPSX, EPSC, DEXDD,
229 . DECDD, DVXDN, DVCDN )
230 endif
231
232C Scale terms by weights
233 EPSX = EPSX*XCweightX(nf)
234 EPSC = EPSC*XCweightC(nf)
235 DEXDD(1:nspin) = DEXDD(1:nspin)*XCweightX(nf)
236 DECDD(1:nspin) = DECDD(1:nspin)*XCweightC(nf)
237 if (GGAfunc) then
238 DEXDGD(1:3,1:nspin) = DEXDGD(1:3,1:nspin)*XCweightX(nf)
239 DECDGD(1:3,1:nspin) = DECDGD(1:3,1:nspin)*XCweightC(nf)
240 endif
241
242C Add contributions to exchange-correlation energy and its
243C derivatives with respect to density at all points
244 do IS = 1,nspin
245 EX = EX + DVol*D(IS)*EPSX
246 EC = EC + DVol*D(IS)*EPSC
247 DX = DX + DVol*D(IS)*(EPSX - DEXDD(IS))
248 DC = DC + DVol*D(IS)*(EPSC - DECDD(IS))
249 if (GGAfunc) then
250 VXC(IR,IS) = VXC(IR,IS) + DVol*(DEXDD(IS) + DECDD(IS))
251 do IN = IN1,IN2
252 DX= DX - DVol*Dens(IR+IN,IS)*DEXDGD(3,IS)*DGIDFJ(IN)
253 DC= DC - DVol*Dens(IR+IN,IS)*DECDGD(3,IS)*DGIDFJ(IN)
254 VXC(IR+IN,IS) = VXC(IR+IN,IS) +
255 . DVol*(DEXDGD(3,IS) + DECDGD(3,IS))*DGIDFJ(IN)
256 enddo
257 else
258 if (GGA) then
259 VXC(IR,IS) = VXC(IR,IS) + DVol*(DEXDD(IS) + DECDD(IS))
260 else
261 VXC(IR,IS) = VXC(IR,IS) + DEXDD(IS) + DECDD(IS)
262 endif
263 endif
264 enddo
265
266 enddo
267
268 enddo
269
270C Divide by volume element to obtain the potential (per electron)
271 if (GGA) then
272 do IS = 1,NSPIN
273 do IR = 1,NR
274 DVol = AUX(IR)
275 VXC(IR,IS) = VXC(IR,IS) / DVol
276 enddo
277 enddo
278 call de_alloc( AUX, 'AUX', 'atomxc' )
279 endif
280
281C Divide by energy unit
282 EX = EX / EUNIT
283 EC = EC / EUNIT
284 DX = DX / EUNIT
285 DC = DC / EUNIT
286 do IS = 1,nspin
287 do IR = 1,NR
288 VXC(IR,IS) = VXC(IR,IS) / EUNIT
289 enddo
290 enddo
291
292 end
293
294
295 subroutine exchng( IREL, NSP, DS, EX, VX )
296
297C *****************************************************************
298C Finds local exchange energy density and potential
299C Adapted by J.M.Soler from routine velect of Froyen's
300C pseudopotential generation program. Madrid, Jan'97. Version 0.5.
301C **** Input ******************************************************
302C INTEGER IREL : relativistic-exchange switch (0=no, 1=yes)
303C INTEGER NSP : spin-polarizations (1=>unpolarized, 2=>polarized)
304C REAL*8 DS(NSP) : total (nsp=1) or spin (nsp=2) electron density
305C **** Output *****************************************************
306C REAL*8 EX : exchange energy density
307C REAL*8 VX(NSP) : (spin-dependent) exchange potential
308C **** Units ******************************************************
309C Densities in electrons/Bohr**3
310C Energies in Hartrees
311C *****************************************************************
312
313 use precision, only: dp
314 implicit none
315
316 integer, intent(in) :: nsp, irel
317 real(dp), intent(in) :: DS(NSP)
318 real(dp), intent(out) :: VX(NSP)
319 real(dp), intent(out) :: EX
320
321 real(dp), parameter :: zero = 0.0_dp, one = 1.0_dp
322 real(dp), parameter :: pfive = 0.5_dp, opf = 1.5_dp
323 real(dp), parameter :: C014 = 0.014_dp
324
325 real(dp) :: pi, trd, ftrd, tftm, a0
326 real(dp) :: alp, d1, d2, d, z, fz, fzp, rs, vxp, exp_var
327 real(dp) :: beta, sb, vxf, exf, alb
328
329 PI=4*ATAN(ONE)
330 TRD = ONE/3
331 FTRD = 4*TRD
332 TFTM = 2**FTRD-2
333 A0 = (4/(9*PI))**TRD
334
335C X-alpha parameter:
336 ALP = 2 * TRD
337
338 IF (NSP .EQ. 2) THEN
339 D1 = MAX(DS(1),0.D0)
340 D2 = MAX(DS(2),0.D0)
341 D = D1 + D2
342 IF (D .LE. ZERO) THEN
343 EX = ZERO
344 VX(1) = ZERO
345 VX(2) = ZERO
346 RETURN
347 ENDIF
348 Z = (D1 - D2) / D
349 FZ = ((1+Z)**FTRD+(1-Z)**FTRD-2)/TFTM
350 FZP = FTRD*((1+Z)**TRD-(1-Z)**TRD)/TFTM
351 ELSE
352 D = DS(1)
353 IF (D .LE. ZERO) THEN
354 EX = ZERO
355 VX(1) = ZERO
356 RETURN
357 ENDIF
358 Z = ZERO
359 FZ = ZERO
360 FZP = ZERO
361 ENDIF
362 RS = (3 / (4*PI*D) )**TRD
363 VXP = -(3*ALP/(2*PI*A0*RS))
364 EXP_VAR = 3*VXP/4
365 IF (IREL .EQ. 1) THEN
366 BETA = C014/RS
367 SB = SQRT(1+BETA*BETA)
368 ALB = LOG(BETA+SB)
369 VXP = VXP * (-PFIVE + OPF * ALB / (BETA*SB))
370 EXP_VAR = EXP_VAR * (ONE-OPF*((BETA*SB-ALB)/BETA**2)**2)
371 ENDIF
372 VXF = 2**TRD*VXP
373 EXF = 2**TRD*EXP_VAR
374 IF (NSP .EQ. 2) THEN
375 VX(1) = VXP + FZ*(VXF-VXP) + (1-Z)*FZP*(EXF-EXP_VAR)
376 VX(2) = VXP + FZ*(VXF-VXP) - (1+Z)*FZP*(EXF-EXP_VAR)
377 EX = EXP_VAR + FZ*(EXF-EXP_VAR)
378 ELSE
379 VX(1) = VXP
380 EX = EXP_VAR
381 ENDIF
382 END
383
384 SUBROUTINE GGAXC( AUTHOR, IREL, nspin, D, GD,
385 . EPSX, EPSC, DEXDD, DECDD, DEXDGD, DECDGD )
386
387C Finds the exchange and correlation energies at a point, and their
388C derivatives with respect to density and density gradient, in the
389C Generalized Gradient Correction approximation.
390C Lengths in Bohr, energies in Hartrees
391C Written by L.C.Balbas and J.M.Soler, Dec'96. Version 0.5.
392C Modified by V.M.Garcia-Suarez to include non-collinear spin. June 2002
393
394 use precision, only : dp
395 use sys, only : die
396
397 implicit none
398
399 CHARACTER*(*) AUTHOR
400 INTEGER IREL, nspin, NS, IS, IX
401 real(dp) THETA, PHI, D(nspin), DECDD(nspin),
402 . DECDGD(3,nspin), DEXDD(nspin), DEXDGD(3,nspin),
403 . EPSC, EPSX, GD(3,nspin),
404 . DD(2), DTOT, DPOL,
405 . GDD(3,2), TINY, DECDN(2), DEXDN(2),
406 . VPOL, DECDGN(3,2), DEXDGN(3,2),
407 . C2, S2, ST, CT, CP, SP, dpolz, dpolxy
408
409
410 PARAMETER ( TINY = 1.D-12 )
411
412 IF (nspin .EQ. 4) THEN
413C Find eigenvalues of density matrix (up and down densities
414C along the spin direction)
415C Note: D(1)=D11, D(2)=D22, D(3)=Real(D12), D(4)=Im(D12)
416 NS = 2
417 DTOT = D(1) + D(2)
418
419! Explicit calculation of the rotation-matrix elements from
420! the entries of D
421
422 dpolz= D(1)-D(2)
423 dpolxy= 2.0d0*sqrt(D(3)**2+D(4)**2)
424 DPOL = sqrt( dpolz**2 + dpolxy**2 )
425 if ( DPOL.gt.1.0d-12 ) then
426 THETA = atan2(dpolxy,dpolz)
427 else
428 THETA = 0.0_dp
429 endif
430 C2 = COS(THETA/2)
431 S2 = SIN(THETA/2)
432 ST = SIN(THETA)
433 CT = COS(THETA)
434 PHI = ATAN2(-D(4),D(3))
435 CP = COS(PHI)
436 SP = SIN(PHI)
437
438 DD(1) = 0.5D0 * ( DTOT + DPOL )
439 DD(2) = 0.5D0 * ( DTOT - DPOL )
440
441C Find diagonal elements of the gradient
442 DO IX = 1,3
443 GDD(IX,1) = GD(IX,1)*C2**2 + GD(IX,2)*S2**2 +
444 . 2.d0*C2*S2*(GD(IX,3)*CP - GD(IX,4)*SP)
445 GDD(IX,2) = GD(IX,1)*S2**2 + GD(IX,2)*C2**2 -
446 . 2.d0*C2*S2*(GD(IX,3)*CP - GD(IX,4)*SP)
447 ENDDO
448 ELSE
449 NS = nspin
450 DO 20 IS = 1,nspin
451cag Avoid negative densities
452 DD(IS) = max(D(IS),0.0d0)
453 DO 30 IX = 1,3
454 GDD(IX,IS) = GD(IX,IS)
455 30 CONTINUE
456 20 CONTINUE
457 ENDIF
458
459 IF (AUTHOR.EQ.'PBE' .OR. AUTHOR.EQ.'pbe') THEN
460 CALL PBEXC( IREL, NS, DD, GDD,
461 . EPSX, EPSC, DEXDN, DECDN, DEXDGN, DECDGN )
462cmvfs
463 ELSE IF (AUTHOR.EQ.'RPBE'.OR.AUTHOR.EQ.'rpbe') THEN
464 CALL RPBEXC( IREL, NS, DD, GDD,
465 . EPSX, EPSC, DEXDN, DECDN, DEXDGN, DECDGN )
466cmvfs
467 ELSE IF (AUTHOR.EQ.'WC'.OR.AUTHOR.EQ.'wc') THEN
468 CALL WCXC( IREL, NS, DD, GDD,
469 . EPSX, EPSC, DEXDN, DECDN, DEXDGN, DECDGN )
470cea
471 ELSE IF (AUTHOR.EQ.'REVPBE'.OR.AUTHOR.EQ.'revpbe'
472 . .OR.AUTHOR.EQ.'revPBE') THEN
473 CALL REVPBEXC( IREL, NS, DD, GDD,
474 . EPSX, EPSC, DEXDN, DECDN, DEXDGN, DECDGN )
475cag
476 ELSE IF (AUTHOR.EQ.'LYP'.OR.AUTHOR.EQ.'lyp') THEN
477 CALL BLYPXC( NS, DD, GDD, EPSX, EPSC, dEXdn, dECdn,
478 . DEXDGN, DECDGN)
479cag
480 ELSEIF (AUTHOR.EQ.'PW91' .OR. AUTHOR.EQ.'pw91') THEN
481 CALL PW91XC( IREL, NS, DD, GDD,
482 . EPSX, EPSC, DEXDN, DECDN, DEXDGN, DECDGN )
483cjdg
484 ELSEIF (AUTHOR.EQ.'PBESOL'.OR.AUTHOR.EQ.'pbesol'
485 . .OR.AUTHOR.EQ.'PBEsol') THEN
486 CALL PBESOLXC( IREL, NS, DD, GDD,
487 . EPSX, EPSC, DEXDN, DECDN, DEXDGN, DECDGN )
488 ELSE
489 call die('GGAXC: Unknown author ' // trim(AUTHOR))
490 ENDIF
491
492 IF (nspin .EQ. 4) THEN
493C Find dE/dD(ispin) = dE/dDup * dDup/dD(ispin) +
494C dE/dDdown * dDown/dD(ispin)
495C Note convention:
496C DEDD(1)=dE/dD11, DEDD(2)=dE/dD22,
497C DEDD(3)=Re(dE/dD12)=Re(dE/dD21),
498C DEDD(4)=Im(dE/dD12)=-Im(dE/D21)
499C
500 VPOL = (DEXDN(1)-DEXDN(2)) * CT
501 DEXDD(1) = 0.5D0 * ( DEXDN(1) + DEXDN(2) + VPOL )
502 DEXDD(2) = 0.5D0 * ( DEXDN(1) + DEXDN(2) - VPOL )
503 DEXDD(3) = 0.5d0 * (DEXDN(1)-DEXDN(2)) * ST * CP
504 DEXDD(4) =-0.5d0 * (DEXDN(1)-DEXDN(2)) * ST * SP
505 VPOL = (DECDN(1)-DECDN(2)) * CT
506 DECDD(1) = 0.5D0 * ( DECDN(1) + DECDN(2) + VPOL )
507 DECDD(2) = 0.5D0 * ( DECDN(1) + DECDN(2) - VPOL )
508 DECDD(3) = 0.5d0 * (DECDN(1)-DECDN(2)) * ST * CP
509 DECDD(4) =-0.5d0 * (DECDN(1)-DECDN(2)) * ST * SP
510C Gradient terms
511 DO 40 IX = 1,3
512 DEXDGD(IX,1) = DEXDGN(IX,1)*C2**2 + DEXDGN(IX,2)*S2**2
513 DEXDGD(IX,2) = DEXDGN(IX,1)*S2**2 + DEXDGN(IX,2)*C2**2
514 DEXDGD(IX,3) = 0.5D0*(DEXDGN(IX,1) - DEXDGN(IX,2))*ST*CP
515 DEXDGD(IX,4) =-0.5D0*(DEXDGN(IX,1) - DEXDGN(IX,2))*ST*SP
516 DECDGD(IX,1) = DECDGN(IX,1)*C2**2 + DECDGN(IX,2)*S2**2
517 DECDGD(IX,2) = DECDGN(IX,1)*S2**2 + DECDGN(IX,2)*C2**2
518 DECDGD(IX,3) = 0.5D0*(DECDGN(IX,1) - DECDGN(IX,2))*ST*CP
519 DECDGD(IX,4) =-0.5D0*(DECDGN(IX,1) - DECDGN(IX,2))*ST*SP
520 40 CONTINUE
521 ELSE
522 DO 60 IS = 1,nspin
523 DEXDD(IS) = DEXDN(IS)
524 DECDD(IS) = DECDN(IS)
525 DO 50 IX = 1,3
526 DEXDGD(IX,IS) = DEXDGN(IX,IS)
527 DECDGD(IX,IS) = DECDGN(IX,IS)
528 50 CONTINUE
529 60 CONTINUE
530 ENDIF
531
532 END
533
534
535 SUBROUTINE LDAXC( AUTHOR, IREL, nspin, D, EPSX, EPSC, VX, VC,
536 . DVXDN, DVCDN )
537
538C ******************************************************************
539C Finds the exchange and correlation energies and potentials, in the
540C Local (spin) Density Approximation.
541C Written by L.C.Balbas and J.M.Soler, Dec'96.
542C Non-collinear spin added by J.M.Soler, May'98
543C *********** INPUT ************************************************
544C CHARACTER*(*) AUTHOR : Parametrization desired:
545C 'CA' or 'PZ' => LSD Perdew & Zunger, PRB 23, 5075 (1981)
546C 'PW92' => LSD Perdew & Wang, PRB, 45, 13244 (1992)
547C Uppercase is optional
548C INTEGER IREL : Relativistic exchange? (0=>no, 1=>yes)
549C INTEGER nspin : nspin=1 => unpolarized; nspin=2 => polarized;
550C nspin=4 => non-collinear polarization
551C REAL*8 D(nspin) : Local (spin) density. For non-collinear
552C polarization, the density matrix is given by:
553C D(1)=D11, D(2)=D22, D(3)=Real(D12), D(4)=Im(D12)
554C *********** OUTPUT ***********************************************
555C REAL*8 EPSX, EPSC : Exchange and correlation energy densities
556C REAL*8 VX(nspin), VC(nspin) : Exchange and correlation potentials,
557C defined as dExc/dD(ispin)
558C REAL*8 DVXDN(nspin,nspin) : Derivative of exchange potential with
559C respect the charge density, defined
560C as DVx(spin1)/Dn(spin2)
561C REAL*8 DVCDN(nspin,nspin) : Derivative of correlation potential
562C respect the charge density, defined
563C as DVc(spin1)/Dn(spin2)
564C *********** UNITS ************************************************
565C Lengths in Bohr, energies in Hartrees
566C ******************************************************************
567
568 use precision, only : dp
569 use sys, only : die
570
571 implicit none
572
573 CHARACTER*(*) AUTHOR
574 INTEGER IREL, nspin
575 real(dp) D(nspin), EPSC, EPSX, VX(nspin), VC(nspin),
576 . DVXDN(nspin,nspin), DVCDN(nspin,nspin)
577
578 INTEGER IS, NS, ISPIN1, ISPIN2
579 real(dp) DD(2), DPOL, DTOT, TINY, VCD(2), VPOL, VXD(2)
580
581 PARAMETER ( TINY = 1.D-12 )
582
583 IF (nspin .EQ. 4) THEN
584C Find eigenvalues of density matrix (up and down densities
585C along the spin direction)
586C Note: D(1)=D11, D(2)=D22, D(3)=Real(D12), D(4)=Im(D12)
587 NS = 2
588 DTOT = D(1) + D(2)
589 DPOL = SQRT( (D(1)-D(2))**2 + 4.D0*(D(3)**2+D(4)**2) )
590 DD(1) = 0.5D0 * ( DTOT + DPOL )
591 DD(2) = 0.5D0 * ( DTOT - DPOL )
592 ELSE
593 NS = nspin
594 DO 10 IS = 1,nspin
595cag Avoid negative densities
596 DD(IS) = max(D(IS),0.0d0)
597 10 CONTINUE
598 ENDIF
599
600
601 DO ISPIN2 = 1, nspin
602 DO ISPIN1 = 1, nspin
603 DVXDN(ISPIN1,ISPIN2) = 0.D0
604 DVCDN(ISPIN1,ISPIN2) = 0.D0
605 ENDDO
606 ENDDO
607
608 IF ( AUTHOR.EQ.'CA' .OR. AUTHOR.EQ.'ca' .OR.
609 . AUTHOR.EQ.'PZ' .OR. AUTHOR.EQ.'pz') THEN
610 CALL PZXC( IREL, NS, DD, EPSX, EPSC, VXD, VCD, DVXDN, DVCDN )
611 ELSEIF ( AUTHOR.EQ.'PW92' .OR. AUTHOR.EQ.'pw92' ) THEN
612 CALL PW92XC( IREL, NS, DD, EPSX, EPSC, VXD, VCD )
613 ELSE
614 call die('LDAXC: Unknown author ' // trim(AUTHOR))
615 ENDIF
616
617 IF (nspin .EQ. 4) THEN
618C Find dE/dD(ispin) = dE/dDup * dDup/dD(ispin) +
619C dE/dDdown * dDown/dD(ispin)
620 VPOL = (VXD(1)-VXD(2)) * (D(1)-D(2)) / (DPOL+TINY)
621 VX(1) = 0.5D0 * ( VXD(1) + VXD(2) + VPOL )
622 VX(2) = 0.5D0 * ( VXD(1) + VXD(2) - VPOL )
623 VX(3) = (VXD(1)-VXD(2)) * D(3) / (DPOL+TINY)
624 VX(4) = (VXD(1)-VXD(2)) * D(4) / (DPOL+TINY)
625 VPOL = (VCD(1)-VCD(2)) * (D(1)-D(2)) / (DPOL+TINY)
626 VC(1) = 0.5D0 * ( VCD(1) + VCD(2) + VPOL )
627 VC(2) = 0.5D0 * ( VCD(1) + VCD(2) - VPOL )
628 VC(3) = (VCD(1)-VCD(2)) * D(3) / (DPOL+TINY)
629 VC(4) = (VCD(1)-VCD(2)) * D(4) / (DPOL+TINY)
630 ELSE
631 DO 20 IS = 1,nspin
632 VX(IS) = VXD(IS)
633 VC(IS) = VCD(IS)
634 20 CONTINUE
635 ENDIF
636 END
637
638
639 SUBROUTINE PBEXC( IREL, nspin, Dens, GDens,
640 . EX, EC, DEXDD, DECDD, DEXDGD, DECDGD )
641
642C *********************************************************************
643C Implements Perdew-Burke-Ernzerhof Generalized-Gradient-Approximation.
644C Ref: J.P.Perdew, K.Burke & M.Ernzerhof, PRL 77, 3865 (1996)
645C Written by L.C.Balbas and J.M.Soler. December 1996. Version 0.5.
646C ******** INPUT ******************************************************
647C INTEGER IREL : Relativistic-exchange switch (0=No, 1=Yes)
648C INTEGER nspin : Number of spin polarizations (1 or 2)
649C REAL*8 Dens(nspin) : Total electron density (if nspin=1) or
650C spin electron density (if nspin=2)
651C REAL*8 GDens(3,nspin) : Total or spin density gradient
652C ******** OUTPUT *****************************************************
653C REAL*8 EX : Exchange energy density
654C REAL*8 EC : Correlation energy density
655C REAL*8 DEXDD(nspin) : Partial derivative
656C d(DensTot*Ex)/dDens(ispin),
657C where DensTot = Sum_ispin( Dens(ispin) )
658C For a constant density, this is the
659C exchange potential
660C REAL*8 DECDD(nspin) : Partial derivative
661C d(DensTot*Ec)/dDens(ispin),
662C where DensTot = Sum_ispin( Dens(ispin) )
663C For a constant density, this is the
664C correlation potential
665C REAL*8 DEXDGD(3,nspin): Partial derivative
666C d(DensTot*Ex)/d(GradDens(i,ispin))
667C REAL*8 DECDGD(3,nspin): Partial derivative
668C d(DensTot*Ec)/d(GradDens(i,ispin))
669C ********* UNITS ****************************************************
670C Lengths in Bohr
671C Densities in electrons per Bohr**3
672C Energies in Hartrees
673C Gradient vectors in cartesian coordinates
674C ********* ROUTINES CALLED ******************************************
675C EXCHNG, PW92C
676C ********************************************************************
677
678 use precision, only : dp
679
680 implicit none
681 INTEGER IREL, nspin
682 real(dp) Dens(nspin), DECDD(nspin), DECDGD(3,nspin),
683 . DEXDD(nspin), DEXDGD(3,nspin), GDens(3,nspin)
684
685C Internal variables
686 INTEGER
687 . IS, IX
688
689 real(dp)
690 . A, BETA, D(2), DADD, DECUDD, DENMIN,
691 . DF1DD, DF2DD, DF3DD, DF4DD, DF1DGD, DF3DGD, DF4DGD,
692 . DFCDD(2), DFCDGD(3,2), DFDD, DFDGD, DFXDD(2), DFXDGD(3,2),
693 . DHDD, DHDGD, DKFDD, DKSDD, DPDD, DPDZ, DRSDD,
694 . DS(2), DSDD, DSDGD, DT, DTDD, DTDGD, DZDD(2),
695 . EC, ECUNIF, EX, EXUNIF,
696 . F, F1, F2, F3, F4, FC, FX, FOUTHD,
697 . GAMMA, GD(3,2), GDM(2), GDMIN, GDMS, GDMT, GDS, GDT(3),
698 . H, HALF, KAPPA, KF, KFS, KS, MU, PHI, PI, RS, S,
699 . T, THD, THRHLF, TWO, TWOTHD, VCUNIF(2), VXUNIF(2), ZETA
700
701C Lower bounds of density and its gradient to avoid divisions by zero
702 PARAMETER ( DENMIN = 1.D-12 )
703 PARAMETER ( GDMIN = 1.D-12 )
704
705C Fix some numerical parameters
706 PARAMETER ( FOUTHD=4.D0/3.D0, HALF=0.5D0,
707 . THD=1.D0/3.D0, THRHLF=1.5D0,
708 . TWO=2.D0, TWOTHD=2.D0/3.D0 )
709
710C Fix some more numerical constants
711 PI = 4 * ATAN(1.D0)
712 BETA = 0.066725D0
713 GAMMA = (1 - LOG(TWO)) / PI**2
714 MU = BETA * PI**2 / 3
715 KAPPA = 0.804D0
716
717C Translate density and its gradient to new variables
718 IF (nspin .EQ. 1) THEN
719 D(1) = HALF * Dens(1)
720 D(2) = D(1)
721 DT = MAX( DENMIN, Dens(1) )
722 DO 10 IX = 1,3
723 GD(IX,1) = HALF * GDens(IX,1)
724 GD(IX,2) = GD(IX,1)
725 GDT(IX) = GDens(IX,1)
726 10 CONTINUE
727 ELSE
728 D(1) = Dens(1)
729 D(2) = Dens(2)
730 DT = MAX( DENMIN, Dens(1)+Dens(2) )
731 DO 20 IX = 1,3
732 GD(IX,1) = GDens(IX,1)
733 GD(IX,2) = GDens(IX,2)
734 GDT(IX) = GDens(IX,1) + GDens(IX,2)
735 20 CONTINUE
736 ENDIF
737 GDM(1) = SQRT( GD(1,1)**2 + GD(2,1)**2 + GD(3,1)**2 )
738 GDM(2) = SQRT( GD(1,2)**2 + GD(2,2)**2 + GD(3,2)**2 )
739 GDMT = SQRT( GDT(1)**2 + GDT(2)**2 + GDT(3)**2 )
740 GDMT = MAX( GDMIN, GDMT )
741
742C Find local correlation energy and potential
743 CALL PW92C( 2, D, ECUNIF, VCUNIF )
744
745C Find total correlation energy
746 RS = ( 3 / (4*PI*DT) )**THD
747 KF = (3 * PI**2 * DT)**THD
748 KS = SQRT( 4 * KF / PI )
749 ZETA = ( D(1) - D(2) ) / DT
750 ZETA = MAX( -1.D0+DENMIN, ZETA )
751 ZETA = MIN( 1.D0-DENMIN, ZETA )
752 PHI = HALF * ( (1+ZETA)**TWOTHD + (1-ZETA)**TWOTHD )
753 T = GDMT / (2 * PHI * KS * DT)
754 F1 = ECUNIF / GAMMA / PHI**3
755 F2 = EXP(-F1)
756 A = BETA / GAMMA / (F2-1)
757 F3 = T**2 + A * T**4
758 F4 = BETA/GAMMA * F3 / (1 + A*F3)
759 H = GAMMA * PHI**3 * LOG( 1 + F4 )
760 FC = ECUNIF + H
761
762C Find correlation energy derivatives
763 DRSDD = - (THD * RS / DT)
764 DKFDD = THD * KF / DT
765 DKSDD = HALF * KS * DKFDD / KF
766 DZDD(1) = 1 / DT - ZETA / DT
767 DZDD(2) = - (1 / DT) - ZETA / DT
768 DPDZ = HALF * TWOTHD * ( 1/(1+ZETA)**THD - 1/(1-ZETA)**THD )
769 DO 40 IS = 1,2
770 DECUDD = ( VCUNIF(IS) - ECUNIF ) / DT
771 DPDD = DPDZ * DZDD(IS)
772 DTDD = (- T) * ( DPDD/PHI + DKSDD/KS + 1/DT )
773 DF1DD = F1 * ( DECUDD/ECUNIF - 3*DPDD/PHI )
774 DF2DD = (- F2) * DF1DD
775 DADD = (- A) * DF2DD / (F2-1)
776 DF3DD = (2*T + 4*A*T**3) * DTDD + DADD * T**4
777 DF4DD = F4 * ( DF3DD/F3 - (DADD*F3+A*DF3DD)/(1+A*F3) )
778 DHDD = 3 * H * DPDD / PHI
779 DHDD = DHDD + GAMMA * PHI**3 * DF4DD / (1+F4)
780 DFCDD(IS) = VCUNIF(IS) + H + DT * DHDD
781
782 DO 30 IX = 1,3
783 DTDGD = (T / GDMT) * GDT(IX) / GDMT
784 DF3DGD = DTDGD * ( 2 * T + 4 * A * T**3 )
785 DF4DGD = F4 * DF3DGD * ( 1/F3 - A/(1+A*F3) )
786 DHDGD = GAMMA * PHI**3 * DF4DGD / (1+F4)
787 DFCDGD(IX,IS) = DT * DHDGD
788 30 CONTINUE
789 40 CONTINUE
790
791C Find exchange energy and potential
792 FX = 0
793 DO 60 IS = 1,2
794 DS(IS) = MAX( DENMIN, 2 * D(IS) )
795 GDMS = MAX( GDMIN, 2 * GDM(IS) )
796 KFS = (3 * PI**2 * DS(IS))**THD
797 S = GDMS / (2 * KFS * DS(IS))
798 F1 = 1 + MU * S**2 / KAPPA
799 F = 1 + KAPPA - KAPPA / F1
800c
801c Note nspin=1 in call to exchng...
802c
803 CALL EXCHNG( IREL, 1, DS(IS), EXUNIF, VXUNIF(IS) )
804 FX = FX + DS(IS) * EXUNIF * F
805
806 DKFDD = THD * KFS / DS(IS)
807 DSDD = S * ( -(DKFDD/KFS) - 1/DS(IS) )
808 DF1DD = 2 * (F1-1) * DSDD / S
809 DFDD = KAPPA * DF1DD / F1**2
810 DFXDD(IS) = VXUNIF(IS) * F + DS(IS) * EXUNIF * DFDD
811
812 DO 50 IX = 1,3
813 GDS = 2 * GD(IX,IS)
814 DSDGD = (S / GDMS) * GDS / GDMS
815 DF1DGD = 2 * MU * S * DSDGD / KAPPA
816 DFDGD = KAPPA * DF1DGD / F1**2
817 DFXDGD(IX,IS) = DS(IS) * EXUNIF * DFDGD
818 50 CONTINUE
819 60 CONTINUE
820 FX = HALF * FX / DT
821
822C Set output arguments
823 EX = FX
824 EC = FC
825 DO 90 IS = 1,nspin
826 DEXDD(IS) = DFXDD(IS)
827 DECDD(IS) = DFCDD(IS)
828 DO 80 IX = 1,3
829 DEXDGD(IX,IS) = DFXDGD(IX,IS)
830 DECDGD(IX,IS) = DFCDGD(IX,IS)
831 80 CONTINUE
832 90 CONTINUE
833
834 END
835
836 SUBROUTINE REVPBEXC( IREL, nspin, Dens, GDens,
837 . EX, EC, DEXDD, DECDD, DEXDGD, DECDGD )
838
839C *********************************************************************
840C Implements revPBE: revised Perdew-Burke-Ernzerhof GGA.
841C Ref: Y. Zhang & W. Yang, Phys. Rev. Lett. 80, 890 (1998).
842C Written by E. Artacho in January 2006 by modifying the PBE routine of
843C L.C.Balbas and J.M.Soler. December 1996. Version 0.5.
844C ******** INPUT ******************************************************
845C INTEGER IREL : Relativistic-exchange switch (0=No, 1=Yes)
846C INTEGER nspin : Number of spin polarizations (1 or 2)
847C REAL*8 Dens(nspin) : Total electron density (if nspin=1) or
848C spin electron density (if nspin=2)
849C REAL*8 GDens(3,nspin) : Total or spin density gradient
850C ******** OUTPUT *****************************************************
851C REAL*8 EX : Exchange energy density
852C REAL*8 EC : Correlation energy density
853C REAL*8 DEXDD(nspin) : Partial derivative
854C d(DensTot*Ex)/dDens(ispin),
855C where DensTot = Sum_ispin( Dens(ispin) )
856C For a constant density, this is the
857C exchange potential
858C REAL*8 DECDD(nspin) : Partial derivative
859C d(DensTot*Ec)/dDens(ispin),
860C where DensTot = Sum_ispin( Dens(ispin) )
861C For a constant density, this is the
862C correlation potential
863C REAL*8 DEXDGD(3,nspin): Partial derivative
864C d(DensTot*Ex)/d(GradDens(i,ispin))
865C REAL*8 DECDGD(3,nspin): Partial derivative
866C d(DensTot*Ec)/d(GradDens(i,ispin))
867C ********* UNITS ****************************************************
868C Lengths in Bohr
869C Densities in electrons per Bohr**3
870C Energies in Hartrees
871C Gradient vectors in cartesian coordinates
872C ********* ROUTINES CALLED ******************************************
873C EXCHNG, PW92C
874C ********************************************************************
875
876 use precision, only : dp
877
878 implicit none
879 INTEGER IREL, nspin
880 real(dp) Dens(nspin), DECDD(nspin), DECDGD(3,nspin),
881 . DEXDD(nspin), DEXDGD(3,nspin), GDens(3,nspin)
882
883C Internal variables
884 INTEGER
885 . IS, IX
886
887 real(dp)
888 . A, BETA, D(2), DADD, DECUDD, DENMIN,
889 . DF1DD, DF2DD, DF3DD, DF4DD, DF1DGD, DF3DGD, DF4DGD,
890 . DFCDD(2), DFCDGD(3,2), DFDD, DFDGD, DFXDD(2), DFXDGD(3,2),
891 . DHDD, DHDGD, DKFDD, DKSDD, DPDD, DPDZ, DRSDD,
892 . DS(2), DSDD, DSDGD, DT, DTDD, DTDGD, DZDD(2),
893 . EC, ECUNIF, EX, EXUNIF,
894 . F, F1, F2, F3, F4, FC, FX, FOUTHD,
895 . GAMMA, GD(3,2), GDM(2), GDMIN, GDMS, GDMT, GDS, GDT(3),
896 . H, HALF, KAPPA, KF, KFS, KS, MU, PHI, PI, RS, S,
897 . T, THD, THRHLF, TWO, TWOTHD, VCUNIF(2), VXUNIF(2), ZETA
898
899C Lower bounds of density and its gradient to avoid divisions by zero
900 PARAMETER ( DENMIN = 1.D-12 )
901 PARAMETER ( GDMIN = 1.D-12 )
902
903C Fix some numerical parameters
904 PARAMETER ( FOUTHD=4.D0/3.D0, HALF=0.5D0,
905 . THD=1.D0/3.D0, THRHLF=1.5D0,
906 . TWO=2.D0, TWOTHD=2.D0/3.D0 )
907
908C Fix some more numerical constants
909 PI = 4 * ATAN(1.D0)
910 BETA = 0.066725D0
911 GAMMA = (1 - LOG(TWO)) / PI**2
912 MU = BETA * PI**2 / 3
913cea The only modification w.r.t. PBE in this following line.
914 KAPPA = 1.245D0
915
916C Translate density and its gradient to new variables
917 IF (nspin .EQ. 1) THEN
918 D(1) = HALF * Dens(1)
919 D(2) = D(1)
920 DT = MAX( DENMIN, Dens(1) )
921 DO 10 IX = 1,3
922 GD(IX,1) = HALF * GDens(IX,1)
923 GD(IX,2) = GD(IX,1)
924 GDT(IX) = GDens(IX,1)
925 10 CONTINUE
926 ELSE
927 D(1) = Dens(1)
928 D(2) = Dens(2)
929 DT = MAX( DENMIN, Dens(1)+Dens(2) )
930 DO 20 IX = 1,3
931 GD(IX,1) = GDens(IX,1)
932 GD(IX,2) = GDens(IX,2)
933 GDT(IX) = GDens(IX,1) + GDens(IX,2)
934 20 CONTINUE
935 ENDIF
936 GDM(1) = SQRT( GD(1,1)**2 + GD(2,1)**2 + GD(3,1)**2 )
937 GDM(2) = SQRT( GD(1,2)**2 + GD(2,2)**2 + GD(3,2)**2 )
938 GDMT = SQRT( GDT(1)**2 + GDT(2)**2 + GDT(3)**2 )
939 GDMT = MAX( GDMIN, GDMT )
940
941C Find local correlation energy and potential
942 CALL PW92C( 2, D, ECUNIF, VCUNIF )
943
944C Find total correlation energy
945 RS = ( 3 / (4*PI*DT) )**THD
946 KF = (3 * PI**2 * DT)**THD
947 KS = SQRT( 4 * KF / PI )
948 ZETA = ( D(1) - D(2) ) / DT
949 ZETA = MAX( -1.D0+DENMIN, ZETA )
950 ZETA = MIN( 1.D0-DENMIN, ZETA )
951 PHI = HALF * ( (1+ZETA)**TWOTHD + (1-ZETA)**TWOTHD )
952 T = GDMT / (2 * PHI * KS * DT)
953 F1 = ECUNIF / GAMMA / PHI**3
954 F2 = EXP(-F1)
955 A = BETA / GAMMA / (F2-1)
956 F3 = T**2 + A * T**4
957 F4 = BETA/GAMMA * F3 / (1 + A*F3)
958 H = GAMMA * PHI**3 * LOG( 1 + F4 )
959 FC = ECUNIF + H
960
961C Find correlation energy derivatives
962 DRSDD = - (THD * RS / DT)
963 DKFDD = THD * KF / DT
964 DKSDD = HALF * KS * DKFDD / KF
965 DZDD(1) = 1 / DT - ZETA / DT
966 DZDD(2) = - (1 / DT) - ZETA / DT
967 DPDZ = HALF * TWOTHD * ( 1/(1+ZETA)**THD - 1/(1-ZETA)**THD )
968 DO 40 IS = 1,2
969 DECUDD = ( VCUNIF(IS) - ECUNIF ) / DT
970 DPDD = DPDZ * DZDD(IS)
971 DTDD = (- T) * ( DPDD/PHI + DKSDD/KS + 1/DT )
972 DF1DD = F1 * ( DECUDD/ECUNIF - 3*DPDD/PHI )
973 DF2DD = (- F2) * DF1DD
974 DADD = (- A) * DF2DD / (F2-1)
975 DF3DD = (2*T + 4*A*T**3) * DTDD + DADD * T**4
976 DF4DD = F4 * ( DF3DD/F3 - (DADD*F3+A*DF3DD)/(1+A*F3) )
977 DHDD = 3 * H * DPDD / PHI
978 DHDD = DHDD + GAMMA * PHI**3 * DF4DD / (1+F4)
979 DFCDD(IS) = VCUNIF(IS) + H + DT * DHDD
980
981 DO 30 IX = 1,3
982 DTDGD = (T / GDMT) * GDT(IX) / GDMT
983 DF3DGD = DTDGD * ( 2 * T + 4 * A * T**3 )
984 DF4DGD = F4 * DF3DGD * ( 1/F3 - A/(1+A*F3) )
985 DHDGD = GAMMA * PHI**3 * DF4DGD / (1+F4)
986 DFCDGD(IX,IS) = DT * DHDGD
987 30 CONTINUE
988 40 CONTINUE
989
990C Find exchange energy and potential
991 FX = 0
992 DO 60 IS = 1,2
993 DS(IS) = MAX( DENMIN, 2 * D(IS) )
994 GDMS = MAX( GDMIN, 2 * GDM(IS) )
995 KFS = (3 * PI**2 * DS(IS))**THD
996 S = GDMS / (2 * KFS * DS(IS))
997 F1 = 1 + MU * S**2 / KAPPA
998 F = 1 + KAPPA - KAPPA / F1
999c
1000c Note nspin=1 in call to exchng...
1001c
1002 CALL EXCHNG( IREL, 1, DS(IS), EXUNIF, VXUNIF(IS) )
1003 FX = FX + DS(IS) * EXUNIF * F
1004
1005 DKFDD = THD * KFS / DS(IS)
1006 DSDD = S * ( -(DKFDD/KFS) - 1/DS(IS) )
1007 DF1DD = 2 * (F1-1) * DSDD / S
1008 DFDD = KAPPA * DF1DD / F1**2
1009 DFXDD(IS) = VXUNIF(IS) * F + DS(IS) * EXUNIF * DFDD
1010
1011 DO 50 IX = 1,3
1012 GDS = 2 * GD(IX,IS)
1013 DSDGD = (S / GDMS) * GDS / GDMS
1014 DF1DGD = 2 * MU * S * DSDGD / KAPPA
1015 DFDGD = KAPPA * DF1DGD / F1**2
1016 DFXDGD(IX,IS) = DS(IS) * EXUNIF * DFDGD
1017 50 CONTINUE
1018 60 CONTINUE
1019 FX = HALF * FX / DT
1020
1021C Set output arguments
1022 EX = FX
1023 EC = FC
1024 DO 90 IS = 1,nspin
1025 DEXDD(IS) = DFXDD(IS)
1026 DECDD(IS) = DFCDD(IS)
1027 DO 80 IX = 1,3
1028 DEXDGD(IX,IS) = DFXDGD(IX,IS)
1029 DECDGD(IX,IS) = DFCDGD(IX,IS)
1030 80 CONTINUE
1031 90 CONTINUE
1032
1033 END
1034
1035
1036 SUBROUTINE PW91XC( IREL, nspin, Dens, GDens,
1037 . EX, EC, DEXDD, DECDD, DEXDGD, DECDGD )
1038
1039C *********************************************************************
1040C Implements Perdew-Wang91 Generalized-Gradient-Approximation.
1041C Ref: JCP 100, 1290 (1994)
1042C Written by J.L. Martins August 2000
1043C ******** INPUT ******************************************************
1044C INTEGER IREL : Relativistic-exchange switch (0=No, 1=Yes)
1045C INTEGER nspin : Number of spin polarizations (1 or 2)
1046C REAL*8 Dens(nspin) : Total electron density (if nspin=1) or
1047C spin electron density (if nspin=2)
1048C REAL*8 GDens(3,nspin) : Total or spin density gradient
1049C ******** OUTPUT *****************************************************
1050C REAL*8 EX : Exchange energy density
1051C REAL*8 EC : Correlation energy density
1052C REAL*8 DEXDD(nspin) : Partial derivative
1053C d(DensTot*Ex)/dDens(ispin),
1054C where DensTot = Sum_ispin( Dens(ispin) )
1055C For a constant density, this is the
1056C exchange potential
1057C REAL*8 DECDD(nspin) : Partial derivative
1058C d(DensTot*Ec)/dDens(ispin),
1059C where DensTot = Sum_ispin( Dens(ispin) )
1060C For a constant density, this is the
1061C correlation potential
1062C REAL*8 DEXDGD(3,nspin): Partial derivative
1063C d(DensTot*Ex)/d(GradDens(i,ispin))
1064C REAL*8 DECDGD(3,nspin): Partial derivative
1065C d(DensTot*Ec)/d(GradDens(i,ispin))
1066C ********* UNITS ****************************************************
1067C Lengths in Bohr
1068C Densities in electrons per Bohr**3
1069C Energies in Hartrees
1070C Gradient vectors in cartesian coordinates
1071C ********* ROUTINES CALLED ******************************************
1072C EXCHNG, PW92C
1073C ********************************************************************
1074
1075 use precision, only : dp
1076
1077 implicit none
1078 INTEGER IREL, nspin
1079 real(dp) Dens(nspin), DECDD(nspin), DECDGD(3,nspin),
1080 . DEXDD(nspin), DEXDGD(3,nspin), GDens(3,nspin)
1081
1082C Internal variables
1083 INTEGER
1084 . IS, IX
1085 real(dp)
1086 . A, BETA, D(2), DADD, DECUDD, DENMIN,
1087 . DF1DD, DF2DD, DF3DD, DF4DD, DF3DGD, DF4DGD,
1088 . DFCDD(2), DFCDGD(3,2), DFDGD, DFXDD(2), DFXDGD(3,2),
1089 . DHDD, DHDGD, DKFDD, DKSDD, DPDD, DPDZ, DRSDD,
1090 . DS(2), DSDD, DSDGD, DT, DTDD, DTDGD, DZDD(2),
1091 . EC, ECUNIF, EX, EXUNIF,
1092 . F, F1, F2, F3, F4, FC, FX, FOUTHD,
1093 . GAMMA, GD(3,2), GDM(2), GDMIN, GDMS, GDMT, GDS, GDT(3),
1094 . H, HALF, KF, KFS, KS, PHI, PI, RS, S,
1095 . T, THD, THRHLF, TWO, TWOTHD, VCUNIF(2), VXUNIF(2), ZETA
1096
1097 real(dp) F5, F6, F7, F8, ASINHS
1098 real(dp) DF5DD,DF6DD,DF7DD,DF8DD
1099 real(dp) DF1DS, DF2DS, DF3DS, DFDS, DF7DGD
1100
1101C Lower bounds of density and its gradient to avoid divisions by zero
1102 PARAMETER ( DENMIN = 1.D-12 )
1103 PARAMETER ( GDMIN = 1.D-12 )
1104
1105C Fix some numerical parameters
1106 PARAMETER ( FOUTHD=4.D0/3.D0, HALF=0.5D0,
1107 . THD=1.D0/3.D0, THRHLF=1.5D0,
1108 . TWO=2.D0, TWOTHD=2.D0/3.D0 )
1109
1110C Fix some more numerical constants
1111 PI = 4.0_dp * ATAN(1.0_dp)
1112 BETA = 15.75592_dp * 0.004235_dp
1113 GAMMA = BETA**2 / (2.0_dp * 0.09_dp)
1114
1115C Translate density and its gradient to new variables
1116 IF (nspin .EQ. 1) THEN
1117 D(1) = HALF * Dens(1)
1118 D(2) = D(1)
1119 DT = MAX( DENMIN, Dens(1) )
1120 DO 10 IX = 1,3
1121 GD(IX,1) = HALF * GDens(IX,1)
1122 GD(IX,2) = GD(IX,1)
1123 GDT(IX) = GDens(IX,1)
1124 10 CONTINUE
1125 ELSE
1126 D(1) = Dens(1)
1127 D(2) = Dens(2)
1128 DT = MAX( DENMIN, Dens(1)+Dens(2) )
1129 DO 20 IX = 1,3
1130 GD(IX,1) = GDens(IX,1)
1131 GD(IX,2) = GDens(IX,2)
1132 GDT(IX) = GDens(IX,1) + GDens(IX,2)
1133 20 CONTINUE
1134 ENDIF
1135 GDM(1) = SQRT( GD(1,1)**2 + GD(2,1)**2 + GD(3,1)**2 )
1136 GDM(2) = SQRT( GD(1,2)**2 + GD(2,2)**2 + GD(3,2)**2 )
1137 GDMT = SQRT( GDT(1)**2 + GDT(2)**2 + GDT(3)**2 )
1138 GDMT = MAX( GDMIN, GDMT )
1139
1140C Find local correlation energy and potential
1141 CALL PW92C( 2, D, ECUNIF, VCUNIF )
1142
1143C Find total correlation energy
1144 RS = ( 3 / (4*PI*DT) )**THD
1145 KF = (3 * PI**2 * DT)**THD
1146 KS = SQRT( 4 * KF / PI )
1147 S = GDMT / (2 * KF * DT)
1148 T = GDMT / (2 * KS * DT)
1149 ZETA = ( D(1) - D(2) ) / DT
1150 ZETA = MAX( -1.D0+DENMIN, ZETA )
1151 ZETA = MIN( 1.D0-DENMIN, ZETA )
1152 PHI = HALF * ( (1+ZETA)**TWOTHD + (1-ZETA)**TWOTHD )
1153 F1 = ECUNIF / GAMMA / PHI**3
1154 F2 = EXP(-F1)
1155 A = BETA / GAMMA / (F2-1)
1156 F3 = T**2 + A * T**4
1157 F4 = BETA/GAMMA * F3 / (1 + A*F3)
1158 F5 = 0.002568D0 + 0.023266D0*RS + 7.389D-6*RS**2
1159 F6 = 1.0D0 + 8.723D0*RS + 0.472D0*RS**2 + 0.07389D0*RS**3
1160 F7 = EXP(-100.0D0 * S**2 * PHI**4)
1161 F8 = 15.75592D0*(0.001667212D0 + F5/F6 -0.004235D0 +
1162 . 3.0D0*0.001667212D0/7.0D0)
1163 H = GAMMA * PHI**3 * LOG( 1 + F4 ) + F8 * T**2 * F7
1164 FC = ECUNIF + H
1165
1166C Find correlation energy derivatives
1167 DRSDD = - THD * RS / DT
1168 DKFDD = THD * KF / DT
1169 DKSDD = HALF * KS * DKFDD / KF
1170 DZDD(1) = 1 / DT - ZETA / DT
1171 DZDD(2) = - 1 / DT - ZETA / DT
1172 DPDZ = HALF * TWOTHD * ( 1/(1+ZETA)**THD - 1/(1-ZETA)**THD )
1173 DO 40 IS = 1,2
1174 DECUDD = ( VCUNIF(IS) - ECUNIF ) / DT
1175 DPDD = DPDZ * DZDD(IS)
1176 DTDD = - T * ( DPDD/PHI + DKSDD/KS + 1/DT )
1177 DSDD = - S * ( DPDD/PHI + DKFDD/KF + 1/DT )
1178 DF1DD = F1 * ( DECUDD/ECUNIF - 3*DPDD/PHI )
1179 DF2DD = - F2 * DF1DD
1180 DADD = - A * DF2DD / (F2-1)
1181 DF3DD = (2*T + 4*A*T**3) * DTDD + DADD * T**4
1182 DF4DD = F4 * ( DF3DD/F3 - (DADD*F3+A*DF3DD)/(1+A*F3) )
1183 DF5DD = (0.023266D0 + 2.0D0*7.389D-6*RS)*DRSDD
1184 DF6DD = (8.723D0 + 2.0D0*0.472D0*RS
1185 . + 3.0D0*0.07389D0*RS**2)*DRSDD
1186 DF7DD = -200.0D0 * S * PHI**4 * DSDD * F7
1187 . -100.0D0 * S**2 * 4.0D0* PHI**3 * DPDD * F7
1188 DF8DD = 15.75592D0 * DF5DD/F6 - 15.75592D0*F5*DF6DD / F6**2
1189 DHDD = 3 * H * DPDD / PHI
1190 DHDD = DHDD + GAMMA * PHI**3 * DF4DD / (1+F4)
1191 DHDD = DHDD + DF8DD * T**2 * F7
1192 DHDD = DHDD + F8 * 2*T*DTDD *F7
1193 DHDD = DHDD + F8 * T**2 * DF7DD
1194
1195 DFCDD(IS) = VCUNIF(IS) + H + DT * DHDD
1196 DO 30 IX = 1,3
1197 DTDGD = (T / GDMT) * GDT(IX) / GDMT
1198 DSDGD = (S / GDMT) * GDT(IX) / GDMT
1199 DF3DGD = DTDGD * ( 2 * T + 4 * A * T**3 )
1200 DF4DGD = F4 * DF3DGD * ( 1/F3 - A/(1+A*F3) )
1201 DF7DGD = -200.0D0 * S * PHI**4 * DSDGD * F7
1202 DHDGD = GAMMA * PHI**3 * DF4DGD / (1+F4)
1203 DHDGD = DHDGD + F8 * 2*T*DTDGD *F7 + F8 * T**2 *DF7DGD
1204 DFCDGD(IX,IS) = DT * DHDGD
1205 30 CONTINUE
1206 40 CONTINUE
1207
1208C Find exchange energy and potential
1209 FX = 0
1210 DO 60 IS = 1,2
1211 DS(1) = MAX( DENMIN, 2 * D(IS) )
1212 GDMS = MAX( GDMIN, 2 * GDM(IS) )
1213 KFS = (3 * PI**2 * DS(1))**THD
1214 S = GDMS / (2 * KFS * DS(1))
1215 F4 = SQRT(1.0D0 + (7.7956D0*S)**2)
1216 ASINHS = LOG(7.7956D0*S + F4)
1217 F1 = 1.0D0 + 0.19645D0 * S * ASINHS
1218 F2 = 0.2743D0 - 0.15084D0*EXP(-100.0D0*S*S)
1219 F3 = 1.0D0 / (F1 + 0.004D0 * S*S*S*S)
1220 F = (F1 + F2 * S*S ) * F3
1221 .
1222 CALL EXCHNG( IREL, 1, DS, EXUNIF, VXUNIF )
1223 FX = FX + DS(1) * EXUNIF * F
1224
1225 DKFDD = THD * KFS / DS(1)
1226 DSDD = S * ( -DKFDD/KFS - 1/DS(1) )
1227 DF1DS = 0.19645D0 * ASINHS +
1228 . 0.19645D0 * S * 7.7956D0 / F4
1229 DF2DS = 0.15084D0*200.0D0*S*EXP(-100.0D0*S*S)
1230 DF3DS = - F3*F3 * (DF1DS + 4.0D0*0.004D0 * S*S*S)
1231 DFDS = DF1DS * F3 + DF2DS * S*S * F3 + 2.0D0 * S * F2 * F3
1232 . + (F1 + F2 * S*S ) * DF3DS
1233 DFXDD(IS) = VXUNIF(1) * F + DS(1) * EXUNIF * DFDS * DSDD
1234
1235 DO 50 IX = 1,3
1236 GDS = 2 * GD(IX,IS)
1237 DSDGD = (S / GDMS) * GDS / GDMS
1238 DFDGD = DFDS * DSDGD
1239 DFXDGD(IX,IS) = DS(1) * EXUNIF * DFDGD
1240 50 CONTINUE
1241 60 CONTINUE
1242 FX = HALF * FX / DT
1243
1244C Set output arguments
1245 EX = FX
1246 EC = FC
1247 DO 90 IS = 1,nspin
1248 DEXDD(IS) = DFXDD(IS)
1249 DECDD(IS) = DFCDD(IS)
1250 DO 80 IX = 1,3
1251 DEXDGD(IX,IS) = DFXDGD(IX,IS)
1252 DECDGD(IX,IS) = DFCDGD(IX,IS)
1253 80 CONTINUE
1254 90 CONTINUE
1255
1256 END
1257
1258
1259
1260 SUBROUTINE PW92C( nspin, Dens, EC, VC )
1261
1262C ********************************************************************
1263C Implements the Perdew-Wang'92 local correlation (beyond RPA).
1264C Ref: J.P.Perdew & Y.Wang, PRB, 45, 13244 (1992)
1265C Written by L.C.Balbas and J.M.Soler. Dec'96. Version 0.5.
1266C ********* INPUT ****************************************************
1267C INTEGER nspin : Number of spin polarizations (1 or 2)
1268C REAL*8 Dens(nspin) : Local (spin) density
1269C ********* OUTPUT ***************************************************
1270C REAL*8 EC : Correlation energy density
1271C REAL*8 VC(nspin) : Correlation (spin) potential
1272C ********* UNITS ****************************************************
1273C Densities in electrons per Bohr**3
1274C Energies in Hartrees
1275C ********* ROUTINES CALLED ******************************************
1276C None
1277C ********************************************************************
1278
1279 use precision, only : dp
1280
1281C Next line is nonstandard but may be supressed
1282 implicit none
1283
1284C Argument types and dimensions
1285 INTEGER nspin
1286 real(dp) Dens(nspin), EC, VC(nspin)
1287
1288C Internal variable declarations
1289 INTEGER IG
1290 real(dp) A(0:2), ALPHA1(0:2), B, BETA(0:2,4), C,
1291 . DBDRS, DECDD(2), DECDRS, DECDZ, DENMIN, DFDZ,
1292 . DGDRS(0:2), DCDRS, DRSDD, DTOT, DZDD(2),
1293 . F, FPP0, FOUTHD, G(0:2), HALF, ONE,
1294 . P(0:2), PI, RS, THD, THRHLF, ZETA
1295
1296C Add tiny numbers to avoid numerical errors
1297 PARAMETER ( DENMIN = 1.D-12 )
1298 PARAMETER ( ONE = 1.D0 + 1.D-12 )
1299
1300C Fix some numerical constants
1301 PARAMETER ( FOUTHD=4.D0/3.D0, HALF=0.5D0,
1302 . THD=1.D0/3.D0, THRHLF=1.5D0 )
1303
1304C Parameters from Table I of Perdew & Wang, PRB, 45, 13244 (92)
1305 DATA P / 1.00d0, 1.00d0, 1.00d0 /
1306 DATA A / 0.031091d0, 0.015545d0, 0.016887d0 /
1307 DATA ALPHA1 / 0.21370d0, 0.20548d0, 0.11125d0 /
1308 DATA BETA / 7.5957d0, 14.1189d0, 10.357d0,
1309 . 3.5876d0, 6.1977d0, 3.6231d0,
1310 . 1.6382d0, 3.3662d0, 0.88026d0,
1311 . 0.49294d0, 0.62517d0, 0.49671d0 /
1312
1313C Find rs and zeta
1314 PI = 4 * ATAN(1.D0)
1315 IF (nspin .EQ. 1) THEN
1316 DTOT = MAX( DENMIN, Dens(1) )
1317 ZETA = 0
1318 RS = ( 3 / (4*PI*DTOT) )**THD
1319C Find derivatives dRs/dDens and dZeta/dDens
1320 DRSDD = (- RS) / DTOT / 3
1321 DZDD(1) = 0
1322 ELSE
1323 DTOT = MAX( DENMIN, Dens(1)+Dens(2) )
1324 ZETA = ( Dens(1) - Dens(2) ) / DTOT
1325 RS = ( 3 / (4*PI*DTOT) )**THD
1326 DRSDD = (- RS) / DTOT / 3
1327 DZDD(1) = (ONE - ZETA) / DTOT
1328 DZDD(2) = - (ONE + ZETA) / DTOT
1329 ENDIF
1330
1331C Find eps_c(rs,0)=G(0), eps_c(rs,1)=G(1) and -alpha_c(rs)=G(2)
1332C using eq.(10) of cited reference (Perdew & Wang, PRB, 45, 13244 (92))
1333 DO 20 IG = 0,2
1334 B = BETA(IG,1) * RS**HALF +
1335 . BETA(IG,2) * RS +
1336 . BETA(IG,3) * RS**THRHLF +
1337 . BETA(IG,4) * RS**(P(IG)+1)
1338 DBDRS = BETA(IG,1) * HALF / RS**HALF +
1339 . BETA(IG,2) +
1340 . BETA(IG,3) * THRHLF * RS**HALF +
1341 . BETA(IG,4) * (P(IG)+1) * RS**P(IG)
1342 C = 1 + 1 / (2 * A(IG) * B)
1343 DCDRS = - ( (C-1) * DBDRS / B )
1344 G(IG) = (- 2) * A(IG) * ( 1 + ALPHA1(IG)*RS ) * LOG(C)
1345 DGDRS(IG) = (- 2) *A(IG) * ( ALPHA1(IG) * LOG(C) +
1346 . (1+ALPHA1(IG)*RS) * DCDRS / C )
1347 20 CONTINUE
1348
1349C Find f''(0) and f(zeta) from eq.(9)
1350 C = 1 / (2**FOUTHD - 2)
1351 FPP0 = 8 * C / 9
1352 F = ( (ONE+ZETA)**FOUTHD + (ONE-ZETA)**FOUTHD - 2 ) * C
1353 DFDZ = FOUTHD * ( (ONE+ZETA)**THD - (ONE-ZETA)**THD ) * C
1354
1355C Find eps_c(rs,zeta) from eq.(8)
1356 EC = G(0) - G(2) * F / FPP0 * (ONE-ZETA**4) +
1357 . (G(1)-G(0)) * F * ZETA**4
1358 DECDRS = DGDRS(0) - DGDRS(2) * F / FPP0 * (ONE-ZETA**4) +
1359 . (DGDRS(1)-DGDRS(0)) * F * ZETA**4
1360 DECDZ = (- G(2)) / FPP0 * ( DFDZ*(ONE-ZETA**4) - F*4*ZETA**3 ) +
1361 . (G(1)-G(0)) * ( DFDZ*ZETA**4 + F*4*ZETA**3 )
1362
1363C Find correlation potential
1364 IF (nspin .EQ. 1) THEN
1365 DECDD(1) = DECDRS * DRSDD
1366 VC(1) = EC + DTOT * DECDD(1)
1367 ELSE
1368 DECDD(1) = DECDRS * DRSDD + DECDZ * DZDD(1)
1369 DECDD(2) = DECDRS * DRSDD + DECDZ * DZDD(2)
1370 VC(1) = EC + DTOT * DECDD(1)
1371 VC(2) = EC + DTOT * DECDD(2)
1372 ENDIF
1373
1374 END
1375
1376
1377
1378 SUBROUTINE PW92XC( IREL, nspin, Dens, EPSX, EPSC, VX, VC )
1379
1380C ********************************************************************
1381C Implements the Perdew-Wang'92 LDA/LSD exchange correlation
1382C Ref: J.P.Perdew & Y.Wang, PRB, 45, 13244 (1992)
1383C Written by L.C.Balbas and J.M.Soler. Dec'96. Version 0.5.
1384C ********* INPUT ****************************************************
1385C INTEGER IREL : Relativistic-exchange switch (0=No, 1=Yes)
1386C INTEGER nspin : Number of spin polarizations (1 or 2)
1387C REAL*8 Dens(nspin) : Local (spin) density
1388C ********* OUTPUT ***************************************************
1389C REAL*8 EPSX : Exchange energy density
1390C REAL*8 EPSC : Correlation energy density
1391C REAL*8 VX(nspin) : Exchange (spin) potential
1392C REAL*8 VC(nspin) : Correlation (spin) potential
1393C ********* UNITS ****************************************************
1394C Densities in electrons per Bohr**3
1395C Energies in Hartrees
1396C ********* ROUTINES CALLED ******************************************
1397C EXCHNG, PW92C
1398C ********************************************************************
1399
1400 use precision, only : dp
1401
1402 implicit none
1403 INTEGER IREL, nspin
1404 real(dp) Dens(nspin), EPSX, EPSC, VC(nspin), VX(nspin)
1405
1406 CALL EXCHNG( IREL, nspin, Dens, EPSX, VX )
1407 CALL PW92C( nspin, Dens, EPSC, VC )
1408 END
1409
1410
1411
1412 SUBROUTINE PZXC( IREL, NSP, DS, EX, EC, VX, VC, DVXDN, DVCDN )
1413
1414C *****************************************************************
1415C Perdew-Zunger parameterization of Ceperley-Alder exchange and
1416C correlation. Ref: Perdew & Zunger, Phys. Rev. B 23 5075 (1981).
1417C Adapted by J.M.Soler from routine velect of Froyen's
1418C pseudopotential generation program. Madrid, Jan'97.
1419C **** Input *****************************************************
1420C INTEGER IREL : relativistic-exchange switch (0=no, 1=yes)
1421C INTEGER NSP : spin-polarizations (1=>unpolarized, 2=>polarized)
1422C REAL*8 DS(NSP) : total (nsp=1) or spin (nsp=2) electron density
1423C **** Output *****************************************************
1424C REAL*8 EX : exchange energy density
1425C REAL*8 EC : correlation energy density
1426C REAL*8 VX(NSP) : (spin-dependent) exchange potential
1427C REAL*8 VC(NSP) : (spin-dependent) correlation potential
1428C REAL*8 DVXDN(NSP,NSP): Derivative of the exchange potential
1429C respect the charge density,
1430C Dvx(spin1)/Dn(spin2)
1431C REAL*8 DVCDN(NSP,NSP): Derivative of the correlation potential
1432C respect the charge density,
1433C Dvc(spin1)/Dn(spin2)
1434C **** Units *******************************************************
1435C Densities in electrons/Bohr**3
1436C Energies in Hartrees
1437C *****************************************************************
1438
1439 use precision, only: dp
1440
1441 implicit none
1442
1443 integer :: nsp, irel, isp1, isp2, isp
1444 real(dp) :: DS(NSP), VX(NSP), VC(NSP),
1445 . DVXDN(NSP,NSP), DVCDN(NSP,NSP)
1446 real(dp), parameter ::
1447 $ ZERO=0.D0,ONE=1.D0,PFIVE=.5D0,OPF=1.5D0,PNN=.99D0,
1448 $ PTHREE=0.3D0,PSEVF=0.75D0,C0504=0.0504D0,
1449 $ C0254=0.0254D0,C014=0.014D0,C0406=0.0406D0,
1450 $ C15P9=15.9D0,C0666=0.0666D0,C11P4=11.4D0,
1451 $ C045=0.045D0,C7P8=7.8D0,C88=0.88D0,C20P59=20.592D0,
1452 $ C3P52=3.52D0,C0311=0.0311D0,C0014=0.0014D0,
1453 $ C0538=0.0538D0,C0096=0.0096D0,C096=0.096D0,
1454 $ C0622=0.0622D0,C004=0.004D0,C0232=0.0232D0,
1455 $ C1686=0.1686D0,C1P398=1.3981D0,C2611=0.2611D0,
1456 $ C2846=0.2846D0,C1P053=1.0529D0,C3334=0.3334D0
1457
1458C Ceperly-Alder 'ca' constants. Internal energies in Rydbergs.
1459 real(dp), parameter ::
1460 $ CON1=1.D0/6, CON2=0.008D0/3, CON3=0.3502D0/3,
1461 $ CON4=0.0504D0/3, CON5=0.0028D0/3, CON6=0.1925D0/3,
1462 $ CON7=0.0206D0/3, CON8=9.7867D0/6, CON9=1.0444D0/3,
1463 $ CON10=7.3703D0/6, CON11=1.3336D0/3
1464
1465C X-alpha parameter:
1466 real(dp), PARAMETER :: ALP = 2.D0 / 3.D0
1467
1468C Other variables converted into parameters by J.M.Soler
1469 real(dp), parameter ::
1470 $ TINY = 1.D-6 ,
1471 $ PI = 3.14159265358979312_dp,
1472 $ TWO = 2.0D0,
1473 $ HALF = 0.5D0,
1474 $ TRD = 1.D0 / 3.D0,
1475 $ FTRD = 4.D0 / 3.D0,
1476 $ TFTM = 0.51984209978974638D0,
1477 $ A0 = 0.52106176119784808D0,
1478 $ CRS = 0.620350490899400087D0,
1479 $ CXP = (- 3.D0) * ALP / (PI*A0),
1480 $ CXF = 1.25992104989487319D0
1481
1482 real(dp) :: d1, d2, d, z, fz, fzp
1483 real(dp) :: ex, ec, dfzpdn, rs, vxp, exp_var
1484 real(dp) :: beta, sb, alb, vxf, exf, dvxpdn
1485 real(dp) :: dvxfdn, sqrs, te, be, ecp, vcp
1486 real(dp) :: dtedn, be2, dbedn, dvcpdn, decpdn
1487 real(dp) :: ecf, vcf, dvcfdn, decfdn, rslog
1488
1489
1490C Find density and polarization
1491 IF (NSP .EQ. 2) THEN
1492 D1 = MAX(DS(1),ZERO)
1493 D2 = MAX(DS(2),ZERO)
1494 D = D1 + D2
1495 IF (D .LE. ZERO) THEN
1496 EX = ZERO
1497 EC = ZERO
1498 VX(1) = ZERO
1499 VX(2) = ZERO
1500 VC(1) = ZERO
1501 VC(2) = ZERO
1502 RETURN
1503 ENDIF
1504c
1505c Robustness enhancement by Jose Soler (August 2002)
1506c
1507 Z = (D1 - D2) / D
1508 IF (Z .LE. -ONE) THEN
1509 FZ = (TWO**FTRD-TWO)/TFTM
1510 FZP = -FTRD*TWO**TRD/TFTM
1511 DFZPDN = FTRD*TRD*TWO**(-ALP)/TFTM
1512 ELSEIF (Z .GE. ONE) THEN
1513 FZ = (TWO**FTRD-TWO)/TFTM
1514 FZP = FTRD*TWO**TRD/TFTM
1515 DFZPDN = FTRD*TRD*TWO**(-ALP)/TFTM
1516 ELSE
1517 FZ = ((ONE+Z)**FTRD+(ONE-Z)**FTRD-TWO)/TFTM
1518 FZP = FTRD*((ONE+Z)**TRD-(ONE-Z)**TRD)/TFTM
1519 DFZPDN = FTRD*TRD*((ONE+Z)**(-ALP) + (ONE-Z)**(-ALP))/TFTM
1520 ENDIF
1521 ELSE
1522 D = DS(1)
1523 IF (D .LE. ZERO) THEN
1524 EX = ZERO
1525 EC = ZERO
1526 VX(1) = ZERO
1527 VC(1) = ZERO
1528 RETURN
1529 ENDIF
1530 Z = ZERO
1531 FZ = ZERO
1532 FZP = ZERO
1533 ENDIF
1534 RS = CRS / D**TRD
1535
1536C Exchange
1537 VXP = CXP / RS
1538 EXP_VAR = 0.75D0 * VXP
1539 IF (IREL .EQ. 1) THEN
1540 BETA = C014/RS
1541 IF (BETA .LT. TINY) THEN
1542 SB = ONE + HALF*BETA**2
1543 ALB = BETA
1544 ELSE
1545 SB = SQRT(1+BETA*BETA)
1546 ALB = LOG(BETA+SB)
1547 ENDIF
1548 VXP = VXP * (-PFIVE + OPF * ALB / (BETA*SB))
1549 EXP_VAR = EXP_VAR *(ONE-OPF*((BETA*SB-ALB)/BETA**2)**2)
1550 ENDIF
1551 VXF = CXF * VXP
1552 EXF = CXF * EXP_VAR
1553 DVXPDN = TRD * VXP / D
1554 DVXFDN = TRD * VXF / D
1555
1556C Correlation
1557 IF (RS .GT. ONE) THEN
1558 SQRS=SQRT(RS)
1559 TE = ONE+CON10*SQRS+CON11*RS
1560 BE = ONE+C1P053*SQRS+C3334*RS
1561 ECP = -(C2846/BE)
1562 VCP = ECP*TE/BE
1563 DTEDN = ((CON10 * SQRS *HALF) + CON11 * RS)*(-TRD/D)
1564 BE2 = BE * BE
1565 DBEDN = ((C1P053 * SQRS *HALF) + C3334 * RS)*(-TRD/D)
1566 DVCPDN = -(C2846/BE2)*(DTEDN - 2.0D0 * TE * DBEDN/BE)
1567 DECPDN = (C2846/BE2)*DBEDN
1568 TE = ONE+CON8*SQRS+CON9*RS
1569 BE = ONE+C1P398*SQRS+C2611*RS
1570 ECF = -(C1686/BE)
1571 VCF = ECF*TE/BE
1572 DTEDN = ((CON8 * SQRS * HALF) + CON9 * RS)*(-TRD/D)
1573 BE2 = BE * BE
1574 DBEDN = ((C1P398 * SQRS * HALF) + C2611 * RS)*(-TRD/D)
1575 DVCFDN = -(C1686/BE2)*(DTEDN - 2.0D0 * TE * DBEDN/BE)
1576 DECFDN = (C1686/BE2)*DBEDN
1577 ELSE
1578 RSLOG=LOG(RS)
1579 ECP=(C0622+C004*RS)*RSLOG-C096-C0232*RS
1580 VCP=(C0622+CON2*RS)*RSLOG-CON3-CON4*RS
1581 DVCPDN = (CON2*RS*RSLOG + (CON2-CON4)*RS + C0622)*(-TRD/D)
1582 DECPDN = (C004*RS*RSLOG + (C004-C0232)*RS + C0622)*(-TRD/D)
1583 ECF=(C0311+C0014*RS)*RSLOG-C0538-C0096*RS
1584 VCF=(C0311+CON5*RS)*RSLOG-CON6-CON7*RS
1585 DVCFDN = (CON5*RS*RSLOG + (CON5-CON7)*RS + C0311)*(-TRD/D)
1586 DECFDN = (C0014*RS*RSLOG + (C0014-C0096)*RS + C0311)*(-TRD/D)
1587 ENDIF
1588
1589 ISP1 = 1
1590 ISP2 = 2
1591
1592C Find up and down potentials
1593 IF (NSP .EQ. 2) THEN
1594 EX = EXP_VAR + FZ*(EXF-EXP_VAR)
1595 EC = ECP + FZ*(ECF-ECP)
1596 VX(1) = VXP + FZ*(VXF-VXP) + (ONE-Z)*FZP*(EXF-EXP_VAR)
1597 VX(2) = VXP + FZ*(VXF-VXP) - (ONE+Z)*FZP*(EXF-EXP_VAR)
1598 VC(1) = VCP + FZ*(VCF-VCP) + (ONE-Z)*FZP*(ECF-ECP)
1599 VC(2) = VCP + FZ*(VCF-VCP) - (ONE+Z)*FZP*(ECF-ECP)
1600
1601C Derivatives of exchange potential respect the density
1602
1603 DVXDN(ISP1,ISP1) =
1604 . DVXPDN
1605 . + FZP*(VXF-VXP-EXF+EXP_VAR)*( 2.D0*D2/(D*D) )
1606 . + FZ*(DVXFDN-DVXPDN)+(1-Z)*FZP*(VXF-VXP)/(4.D0*D)
1607 . + (1-Z)*DFZPDN*(EXF-EXP_VAR)*( 2.D0*D2/(D*D) )
1608 DVXDN(ISP1,ISP2) =
1609 . DVXPDN
1610 . + FZP*(VXF-VXP-EXF+EXP_VAR)*(-2.D0*D1/(D*D) )
1611 . + FZ*(DVXFDN-DVXPDN)+(1-Z)*FZP*(VXF-VXP)/(4.D0*D)
1612 . + (1-Z)*DFZPDN*(EXF-EXP_VAR)*( -2.D0*D1/(D*D) )
1613 DVXDN(ISP2,ISP1) =
1614 . DVXPDN
1615 . + FZP*(VXF-VXP-EXF+EXP_VAR)*( 2.D0*D2/(D*D) )
1616 . + FZ*(DVXFDN-DVXPDN)-(1+Z)*FZP*(VXF-VXP)/(4.D0*D)
1617 . - (1+Z)*DFZPDN*(EXF-EXP_VAR)*( 2.D0*D2/(D*D) )
1618 DVXDN(ISP2,ISP2) =
1619 . DVXPDN
1620 . + FZP*(VXF-VXP-EXF+EXP_VAR)*(-2.D0*D1/(D*D) )
1621 . + FZ*(DVXFDN-DVXPDN)-(1+Z)*FZP*(VXF-VXP)/(4.D0*D)
1622 . - (1+Z)*DFZPDN*(EXF-EXP_VAR)*( -2.D0*D1/(D*D) )
1623
1624C Derivatives of correlation potential respect the density
1625
1626 DVCDN(ISP1,ISP1) =
1627 . DVCPDN
1628 . + FZP*(VCF-VCP-ECF+ECP)*( 2.D0*D2/(D*D) )
1629 . + FZ*(DVCFDN-DVCPDN)+ (1-Z)*FZP*(DECFDN-DECPDN)
1630 . + (1-Z)*DFZPDN*(ECF-ECP)*( 2.D0*D2/(D*D) )
1631 DVCDN(ISP1,ISP2) =
1632 . DVCPDN
1633 . + FZP*(VCF-VCP-ECF+ECP)*(-2.D0*D1/(D*D) )
1634 . + FZ*(DVCFDN-DVCPDN)+ (1-Z)*FZP*(DECFDN-DECPDN)
1635 . + (1-Z)*DFZPDN*(ECF-ECP)*( -2.D0*D1/(D*D) )
1636 DVCDN(ISP2,ISP1) =
1637 . DVCPDN
1638 . + FZP*(VCF-VCP-ECF+ECP)*( 2.D0*D2/(D*D) )
1639 . + FZ*(DVCFDN-DVCPDN)- (1+Z)*FZP*(DECFDN-DECPDN)
1640 . - (1+Z)*DFZPDN*(ECF-ECP)*( 2.D0*D2/(D*D) )
1641 DVCDN(ISP2,ISP2) =
1642 . DVCPDN
1643 . + FZP*(VCF-VCP-ECF+ECP)*(-2.D0*D1/(D*D) )
1644 . + FZ*(DVCFDN-DVCPDN)- (1+Z)*FZP*(DECFDN-DECPDN)
1645 . - (1+Z)*DFZPDN*(ECF-ECP)*( -2.D0*D1/(D*D) )
1646
1647 ELSE
1648 EX = EXP_VAR
1649 EC = ECP
1650 VX(1) = VXP
1651 VC(1) = VCP
1652 DVXDN(1,1) = DVXPDN
1653 DVCDN(1,1) = DVCPDN
1654 ENDIF
1655
1656C Change from Rydbergs to Hartrees
1657 EX = HALF * EX
1658 EC = HALF * EC
1659 DO 10 ISP = 1,NSP
1660 VX(ISP) = HALF * VX(ISP)
1661 VC(ISP) = HALF * VC(ISP)
1662 DO 5 ISP2 = 1,NSP
1663 DVXDN(ISP,ISP2) = HALF * DVXDN(ISP,ISP2)
1664 DVCDN(ISP,ISP2) = HALF * DVCDN(ISP,ISP2)
1665 5 CONTINUE
1666 10 CONTINUE
1667 END
1668
1669 subroutine blypxc(nspin,dens,gdens,EX,EC,
1670 . dEXdd,dECdd,dEXdgd,dECdgd)
1671c ***************************************************************
1672c Implements Becke gradient exchange functional (A.D.
1673c Becke, Phys. Rev. A 38, 3098 (1988)) and Lee, Yang, Parr
1674c correlation functional (C. Lee, W. Yang, R.G. Parr, Phys. Rev. B
1675c 37, 785 (1988)), as modificated by Miehlich,Savin,Stoll and Preuss,
1676c Chem. Phys. Lett. 157,200 (1989). See also Johnson, Gill and Pople,
1677c J. Chem. Phys. 98, 5612 (1993). Some errors were detected in this
1678c last paper, so not all of the expressions correspond exactly to those
1679c implemented here.
1680c Written by Maider Machado. July 1998.
1681c **************** INPUT ********************************************
1682c integer nspin : Number of spin polarizations (1 or 2)
1683c real*8 dens(nspin) : Total electron density (if nspin=1) or
1684c spin electron density (if nspin=2)
1685c real*8 gdens(3,nspin) : Total or spin density gradient
1686c ******** OUTPUT *****************************************************
1687c real*8 ex : Exchange energy density
1688c real*8 ec : Correlation energy density
1689c real*8 dexdd(nspin) : Partial derivative
1690c d(DensTot*Ex)/dDens(ispin),
1691c where DensTot = Sum_ispin( Dens(ispin) )
1692c For a constant density, this is the
1693c exchange potential
1694c real*8 decdd(nspin) : Partial derivative
1695c d(DensTot*Ec)/dDens(ispin),
1696c where DensTot = Sum_ispin( Dens(ispin) )
1697c For a constant density, this is the
1698c correlation potential
1699c real*8 dexdgd(3,nspin): Partial derivative
1700c d(DensTot*Ex)/d(GradDens(i,ispin))
1701c real*8 decdgd(3,nspin): Partial derivative
1702c d(DensTot*Ec)/d(GradDens(i,ispin))
1703c ********* UNITS ****************************************************
1704c Lengths in Bohr
1705c Densities in electrons per Bohr**3
1706c Energies in Hartrees
1707c Gradient vectors in cartesian coordinates
1708c ********************************************************************
1709
1710 use precision, only : dp
1711
1712 implicit none
1713
1714 integer nspin
1715 real(dp) dens(nspin), gdens(3,nspin), EX, EC,
1716 . dEXdd(nspin), dECdd(nspin), dEXdgd(3,nspin),
1717 . dECdgd(3,nspin)
1718
1719c Internal variables
1720 integer is,ix
1721 real(dp) pi, beta, thd, tthd, thrhlf, half, fothd,
1722 . d(2),gd(3,2),dmin, ash,gdm(2),denmin,dt,
1723 . g(2),x(2),a,b,c,dd,onzthd,gdmin,
1724 . ga, gb, gc,becke,dbecgd(3,2),
1725 . dgdx(2), dgdxa, dgdxb, dgdxc,dgdxd,dbecdd(2),
1726 . den,omega, domega, delta, ddelta,cf,
1727 . gam11, gam12, gam22, LYPa, LYPb1,
1728 . LYPb2,dLYP11,dLYP12,dLYP22,LYP,
1729 . dd1g11,dd1g12,dd1g22,dd2g12,dd2g11,dd2g22,
1730 . dLYPdd(2),dg11dd(3,2),dg22dd(3,2),
1731 . dLYPgd(3,2)
1732
1733c Lower bounds of density and its gradient to avoid divisions by zero
1734 parameter ( denmin=1.d-8 )
1735 parameter (gdmin=1.d-8)
1736 parameter (dmin=1.d-5)
1737
1738c Fix some numerical parameters
1739 parameter ( thd = 1.d0/3.d0, tthd=2.d0/3.d0 )
1740 parameter ( thrhlf=1.5d0, half=0.5d0,
1741 . fothd=4.d0/3.d0, onzthd=11.d0/3.d0)
1742
1743c Empirical parameter for Becke exchange functional (a.u.)
1744 parameter(beta= 0.0042d0)
1745
1746c Constants for LYP functional (a.u.)
1747 parameter(a=0.04918d0, b=0.132d0, c=0.2533d0, dd=0.349d0)
1748
1749 pi= 4*atan(1.d0)
1750
1751
1752c Translate density and its gradient to new variables
1753 if (nspin .eq. 1) then
1754 d(1) = half * dens(1)
1755 d(1) = max(denmin,d(1))
1756 d(2) = d(1)
1757 dt = max( denmin, dens(1) )
1758 do ix = 1,3
1759 gd(ix,1) = half * gdens(ix,1)
1760 gd(ix,2) = gd(ix,1)
1761 enddo
1762 else
1763 d(1) = dens(1)
1764 d(2) = dens(2)
1765 do is=1,2
1766 d(is) = max (denmin,d(is))
1767 enddo
1768 dt = max( denmin, dens(1)+dens(2) )
1769 do ix = 1,3
1770 gd(ix,1) = gdens(ix,1)
1771 gd(ix,2) = gdens(ix,2)
1772 enddo
1773 endif
1774
1775 gdm(1) = sqrt( gd(1,1)**2 + gd(2,1)**2 + gd(3,1)**2 )
1776 gdm(2) = sqrt( gd(1,2)**2 + gd(2,2)**2 + gd(3,2)**2 )
1777
1778 do is=1,2
1779 gdm(is)= max(gdm(is),gdmin)
1780 enddo
1781
1782c Find Becke exchange energy
1783 ga = -thrhlf*(3.d0/4.d0/pi)**thd
1784 do is=1,2
1785 if(d(is).lt.dmin) then
1786 g(is)=ga
1787 else
1788 x(is) = gdm(is)/d(is)**fothd
1789 gb = beta*x(is)**2
1790 ash=log(x(is)+sqrt(x(is)**2+1))
1791 gc = 1+6*beta*x(is)*ash
1792 g(is) = ga-gb/gc
1793 endif
1794 enddo
1795
1796c Density of energy
1797 becke=(g(1)*d(1)**fothd+g(2)*d(2)**fothd)/dt
1798
1799
1800c Exchange energy derivatives
1801 do is=1,2
1802 if(d(is).lt.dmin)then
1803 dbecdd(is)=0.
1804 do ix=1,3
1805 dbecgd(ix,is)=0.
1806 enddo
1807 else
1808 dgdxa=6*beta**2*x(is)**2
1809 ash=log(x(is)+sqrt(x(is)**2+1))
1810 dgdxb=x(is)/sqrt(x(is)**2+1)-ash
1811 dgdxc=-2*beta*x(is)
1812 dgdxd=(1+6*beta*x(is)*ash)**2
1813 dgdx(is)=(dgdxa*dgdxb+dgdxc)/dgdxd
1814 dbecdd(is)=fothd*d(is)**thd*(g(is)-x(is)*dgdx(is))
1815 do ix=1,3
1816 dbecgd(ix,is)=d(is)**(-fothd)*dgdx(is)*gd(ix,is)/x(is)
1817 enddo
1818 endif
1819 enddo
1820
1821c Lee-Yang-Parr correlation energy
1822 den=1+dd*dt**(-thd)
1823 omega=dt**(-onzthd)*exp(-c*dt**(-thd))/den
1824 delta=c*dt**(-thd)+dd*dt**(-thd)/den
1825 cf=3.*(3*pi**2)**tthd/10.
1826 gam11=gdm(1)**2
1827 gam12=gd(1,1)*gd(1,2)+gd(2,1)*gd(2,2)+gd(3,1)*gd(3,2)
1828 gam22=gdm(2)**2
1829 LYPa=-4*a*d(1)*d(2)/(den*dt)
1830 LYPb1=2**onzthd*cf*a*b*omega*d(1)*d(2)
1831 LYPb2=d(1)**(8./3.)+d(2)**(8./3.)
1832 dLYP11=-a*b*omega*(d(1)*d(2)/9.*(1.-3.*delta-(delta-11.)
1833 .*d(1)/dt)-d(2)**2)
1834 dLYP12=-a*b*omega*(d(1)*d(2)/9.*(47.-7.*delta)
1835 .-fothd*dt**2)
1836 dLYP22=-a*b*omega*(d(1)*d(2)/9.*(1.-3.*delta-(delta-11.)*
1837 .d(2)/dt)-d(1)**2)
1838
1839c Density of energy
1840 LYP=(LYPa-LYPb1*LYPb2+dLYP11*gam11+dLYP12*gam12
1841 .+dLYP22*gam22)/dt
1842
1843c Correlation energy derivatives
1844 domega=-thd*dt**(-fothd)*omega*(11.*dt**thd-c-dd/den)
1845 ddelta=thd*(dd**2*dt**(-5./3.)/den**2-delta/dt)
1846
1847c Second derivatives with respect to the density
1848 dd1g11=domega/omega*dLYP11-a*b*omega*(d(2)/9.*
1849 . (1.-3.*delta-2*(delta-11.)*d(1)/dt)-d(1)*d(2)/9.*
1850 . ((3.+d(1)/dt)*ddelta-(delta-11.)*d(1)/dt**2))
1851
1852 dd1g12=domega/omega*dLYP12-a*b*omega*(d(2)/9.*
1853 . (47.-7.*delta)-7./9.*d(1)*d(2)*ddelta-8./3.*dt)
1854
1855 dd1g22=domega/omega*dLYP22-a*b*omega*(1./9.*d(2)
1856 . *(1.-3.*delta-(delta-11.)*d(2)/dt)-d(1)*d(2)/9.*
1857 . ((3.+d(2)/dt)*ddelta-(delta-11.)*d(2)/dt**2)-2*d(1))
1858
1859
1860 dd2g22=domega/omega*dLYP22-a*b*omega*(d(1)/9.*
1861 . (1.-3.*delta-2*(delta-11.)*d(2)/dt)-d(1)*d(2)/9.*
1862 . ((3+d(2)/dt)*ddelta-(delta-11.)*d(2)/dt**2))
1863
1864
1865 dd2g12=domega/omega*dLYP12-a*b*omega*(d(1)/9.*
1866 . (47.-7.*delta)-7./9.*d(1)*d(2)*ddelta-8./3.*dt)
1867
1868 dd2g11=domega/omega*dLYP11-a*b*omega*(1./9.*d(1)
1869 . *(1.-3.*delta-(delta-11.)*d(1)/dt)-d(1)*d(2)/9.*
1870 . ((3.+d(1)/dt)*ddelta-(delta-11.)*d(1)/dt**2)-2*d(2))
1871
1872
1873 dLYPdd(1)=-4*a/den*d(1)*d(2)/dt*
1874 . (thd*dd*dt**(-fothd)/den
1875 . +1./d(1)-1./dt)-2**onzthd*cf*a*b*(domega*d(1)*d(2)*
1876 . (d(1)**(8./3.)+d(2)**(8./3.))+omega*d(2)*(onzthd*
1877 . d(1)**(8./3.)+d(2)**(8./3.)))+dd1g11*gam11+
1878 . dd1g12*gam12+dd1g22*gam22
1879
1880
1881 dLYPdd(2)=-4*a/den*d(1)*d(2)/dt*(thd*dd*dt**(-fothd)/den
1882 . +1./d(2)-1./dt)-2**onzthd*cf*a*b*(domega*d(1)*d(2)*
1883 . (d(1)**(8./3.)+d(2)**(8./3.))+omega*d(1)*(onzthd*
1884 . d(2)**(8./3.)+d(1)**(8./3.)))+dd2g22*gam22+
1885 . dd2g12*gam12+dd2g11*gam11
1886
1887
1888c second derivatives with respect to the density gradient
1889
1890 do is=1,2
1891 do ix=1,3
1892 dg11dd(ix,is)=2*gd(ix,is)
1893 dg22dd(ix,is)=2*gd(ix,is)
1894 enddo
1895 enddo
1896 do ix=1,3
1897 dLYPgd(ix,1)=dLYP11*dg11dd(ix,1)+dLYP12*gd(ix,2)
1898 dLYPgd(ix,2)=dLYP22*dg22dd(ix,2)+dLYP12*gd(ix,1)
1899 enddo
1900
1901
1902 EX=becke
1903 EC=LYP
1904 do is=1,nspin
1905 dEXdd(is)=dbecdd(is)
1906 dECdd(is)=dLYPdd(is)
1907 do ix=1,3
1908 dEXdgd(ix,is)=dbecgd(ix,is)
1909 dECdgd(ix,is)=dLYPgd(ix,is)
1910 enddo
1911 enddo
1912 end
1913
1914 SUBROUTINE RPBEXC( IREL, nspin, Dens, GDens,
1915 . EX, EC, DEXDD, DECDD, DEXDGD, DECDGD )
1916
1917C *********************************************************************
1918C Implements Hammer's RPBE Generalized-Gradient-Approximation (GGA).
1919C A revision of PBE (Perdew-Burke-Ernzerhof)
1920C Ref: Hammer, Hansen & Norskov, PRB 59, 7413 (1999) and
1921C J.P.Perdew, K.Burke & M.Ernzerhof, PRL 77, 3865 (1996)
1922C
1923C Written by M.V. Fernandez-Serra. March 2004. On the PBE routine of
1924C L.C.Balbas and J.M.Soler. December 1996. Version 0.5.
1925C ******** INPUT ******************************************************
1926C INTEGER IREL : Relativistic-exchange switch (0=No, 1=Yes)
1927C INTEGER nspin : Number of spin polarizations (1 or 2)
1928C REAL*8 Dens(nspin) : Total electron density (if nspin=1) or
1929C spin electron density (if nspin=2)
1930C REAL*8 GDens(3,nspin) : Total or spin density gradient
1931C ******** OUTPUT *****************************************************
1932C REAL*8 EX : Exchange energy density
1933C REAL*8 EC : Correlation energy density
1934C REAL*8 DEXDD(nspin) : Partial derivative
1935C d(DensTot*Ex)/dDens(ispin),
1936C where DensTot = Sum_ispin( Dens(ispin) )
1937C For a constant density, this is the
1938C exchange potential
1939C REAL*8 DECDD(nspin) : Partial derivative
1940C d(DensTot*Ec)/dDens(ispin),
1941C where DensTot = Sum_ispin( Dens(ispin) )
1942C For a constant density, this is the
1943C correlation potential
1944C REAL*8 DEXDGD(3,nspin): Partial derivative
1945C d(DensTot*Ex)/d(GradDens(i,ispin))
1946C REAL*8 DECDGD(3,nspin): Partial derivative
1947C d(DensTot*Ec)/d(GradDens(i,ispin))
1948C ********* UNITS ****************************************************
1949C Lengths in Bohr
1950C Densities in electrons per Bohr**3
1951C Energies in Hartrees
1952C Gradient vectors in cartesian coordinates
1953C ********* ROUTINES CALLED ******************************************
1954C EXCHNG, PW92C
1955C ********************************************************************
1956
1957 use precision, only : dp
1958
1959 implicit none
1960 INTEGER IREL, nspin
1961 real(dp) Dens(nspin), DECDD(nspin), DECDGD(3,nspin),
1962 . DEXDD(nspin), DEXDGD(3,nspin), GDens(3,nspin)
1963
1964C Internal variables
1965 INTEGER
1966 . IS, IX
1967
1968 real(dp)
1969 . A, BETA, D(2), DADD, DECUDD, DENMIN,
1970 . DF1DD, DF2DD, DF3DD, DF4DD, DF1DGD, DF3DGD, DF4DGD,
1971 . DFCDD(2), DFCDGD(3,2), DFDD, DFDGD, DFXDD(2), DFXDGD(3,2),
1972 . DHDD, DHDGD, DKFDD, DKSDD, DPDD, DPDZ, DRSDD,
1973 . DS(2), DSDD, DSDGD, DT, DTDD, DTDGD, DZDD(2),
1974 . EC, ECUNIF, EX, EXUNIF,
1975 . F, F1, F2, F3, F4, FC, FX, FOUTHD,
1976 . GAMMA, GD(3,2), GDM(2), GDMIN, GDMS, GDMT, GDS, GDT(3),
1977 . H, HALF, KAPPA, KF, KFS, KS, MU, PHI, PI, RS, S,
1978 . T, THD, THRHLF, TWO, TWOTHD, VCUNIF(2), VXUNIF(2), ZETA
1979
1980C Lower bounds of density and its gradient to avoid divisions by zero
1981 PARAMETER ( DENMIN = 1.D-12 )
1982 PARAMETER ( GDMIN = 1.D-12 )
1983
1984C Fix some numerical parameters
1985 PARAMETER ( FOUTHD=4.D0/3.D0, HALF=0.5D0,
1986 . THD=1.D0/3.D0, THRHLF=1.5D0,
1987 . TWO=2.D0, TWOTHD=2.D0/3.D0 )
1988
1989C Fix some more numerical constants
1990 PI = 4 * ATAN(1.D0)
1991 BETA = 0.066725D0
1992 GAMMA = (1 - LOG(TWO)) / PI**2
1993 MU = BETA * PI**2 / 3
1994 KAPPA = 0.804D0
1995
1996C Translate density and its gradient to new variables
1997 IF (nspin .EQ. 1) THEN
1998 D(1) = HALF * Dens(1)
1999 D(2) = D(1)
2000 DT = MAX( DENMIN, Dens(1) )
2001 DO 10 IX = 1,3
2002 GD(IX,1) = HALF * GDens(IX,1)
2003 GD(IX,2) = GD(IX,1)
2004 GDT(IX) = GDens(IX,1)
2005 10 CONTINUE
2006 ELSE
2007 D(1) = Dens(1)
2008 D(2) = Dens(2)
2009 DT = MAX( DENMIN, Dens(1)+Dens(2) )
2010 DO 20 IX = 1,3
2011 GD(IX,1) = GDens(IX,1)
2012 GD(IX,2) = GDens(IX,2)
2013 GDT(IX) = GDens(IX,1) + GDens(IX,2)
2014 20 CONTINUE
2015 ENDIF
2016 GDM(1) = SQRT( GD(1,1)**2 + GD(2,1)**2 + GD(3,1)**2 )
2017 GDM(2) = SQRT( GD(1,2)**2 + GD(2,2)**2 + GD(3,2)**2 )
2018 GDMT = SQRT( GDT(1)**2 + GDT(2)**2 + GDT(3)**2 )
2019 GDMT = MAX( GDMIN, GDMT )
2020
2021C Find local correlation energy and potential
2022 CALL PW92C( 2, D, ECUNIF, VCUNIF )
2023
2024C Find total correlation energy
2025 RS = ( 3 / (4*PI*DT) )**THD
2026 KF = (3 * PI**2 * DT)**THD
2027 KS = SQRT( 4 * KF / PI )
2028 ZETA = ( D(1) - D(2) ) / DT
2029 ZETA = MAX( -1.D0+DENMIN, ZETA )
2030 ZETA = MIN( 1.D0-DENMIN, ZETA )
2031 PHI = HALF * ( (1+ZETA)**TWOTHD + (1-ZETA)**TWOTHD )
2032 T = GDMT / (2 * PHI * KS * DT)
2033 F1 = ECUNIF / GAMMA / PHI**3
2034 F2 = EXP(-F1)
2035 A = BETA / GAMMA / (F2-1)
2036 F3 = T**2 + A * T**4
2037 F4 = BETA/GAMMA * F3 / (1 + A*F3)
2038 H = GAMMA * PHI**3 * LOG( 1 + F4 )
2039 FC = ECUNIF + H
2040
2041C Find correlation energy derivatives
2042 DRSDD = - (THD * RS / DT)
2043 DKFDD = THD * KF / DT
2044 DKSDD = HALF * KS * DKFDD / KF
2045 DZDD(1) = 1 / DT - ZETA / DT
2046 DZDD(2) = - (1 / DT) - ZETA / DT
2047 DPDZ = HALF * TWOTHD * ( 1/(1+ZETA)**THD - 1/(1-ZETA)**THD )
2048 DO 40 IS = 1,2
2049 DECUDD = ( VCUNIF(IS) - ECUNIF ) / DT
2050 DPDD = DPDZ * DZDD(IS)
2051 DTDD = (- T) * ( DPDD/PHI + DKSDD/KS + 1/DT )
2052 DF1DD = F1 * ( DECUDD/ECUNIF - 3*DPDD/PHI )
2053 DF2DD = (- F2) * DF1DD
2054 DADD = (- A) * DF2DD / (F2-1)
2055 DF3DD = (2*T + 4*A*T**3) * DTDD + DADD * T**4
2056 DF4DD = F4 * ( DF3DD/F3 - (DADD*F3+A*DF3DD)/(1+A*F3) )
2057 DHDD = 3 * H * DPDD / PHI
2058 DHDD = DHDD + GAMMA * PHI**3 * DF4DD / (1+F4)
2059 DFCDD(IS) = VCUNIF(IS) + H + DT * DHDD
2060
2061 DO 30 IX = 1,3
2062 DTDGD = (T / GDMT) * GDT(IX) / GDMT
2063 DF3DGD = DTDGD * ( 2 * T + 4 * A * T**3 )
2064 DF4DGD = F4 * DF3DGD * ( 1/F3 - A/(1+A*F3) )
2065 DHDGD = GAMMA * PHI**3 * DF4DGD / (1+F4)
2066 DFCDGD(IX,IS) = DT * DHDGD
2067 30 CONTINUE
2068 40 CONTINUE
2069
2070C Find exchange energy and potential
2071 FX = 0
2072 DO 60 IS = 1,2
2073 DS(IS) = MAX( DENMIN, 2 * D(IS) )
2074 GDMS = MAX( GDMIN, 2 * GDM(IS) )
2075 KFS = (3 * PI**2 * DS(IS))**THD
2076 S = GDMS / (2 * KFS * DS(IS))
2077cea Hammer's RPBE (Hammer, Hansen & Norskov PRB 59 7413 (99)
2078cea F1 = DEXP( - MU * S**2 / KAPPA)
2079cea F = 1 + KAPPA * (1 - F1)
2080cea Following is standard PBE
2081cea F1 = 1 + MU * S**2 / KAPPA
2082cea F = 1 + KAPPA - KAPPA / F1
2083cea (If revPBE Zhang & Yang, PRL 80,890(1998),change PBE's KAPPA to 1.245)
2084 F1 = DEXP( - MU * S**2 / KAPPA)
2085 F = 1 + KAPPA * (1 - F1)
2086
2087c Note nspin=1 in call to exchng...
2088
2089 CALL EXCHNG( IREL, 1, DS(IS), EXUNIF, VXUNIF(IS) )
2090 FX = FX + DS(IS) * EXUNIF * F
2091
2092cMVFS The derivatives of F also need to be changed for Hammer's RPBE.
2093cMVFS DF1DD = 2 * F1 * DSDD * ( - MU * S / KAPPA)
2094cMVFS DF1DGD= 2 * F1 * DSDGD * ( - MU * S / KAPPA)
2095cMVFS DFDD = -1 * KAPPA * DF1DD
2096cMVFS DFDGD = -1 * KAPPA * DFDGD
2097
2098 DKFDD = THD * KFS / DS(IS)
2099 DSDD = S * ( -(DKFDD/KFS) - 1/DS(IS) )
2100c DF1DD = 2 * (F1-1) * DSDD / S
2101c DFDD = KAPPA * DF1DD / F1**2
2102 DF1DD = 2* F1 * DSDD * ( - MU * S / KAPPA)
2103 DFDD = -1 * KAPPA * DF1DD
2104 DFXDD(IS) = VXUNIF(IS) * F + DS(IS) * EXUNIF * DFDD
2105
2106 DO 50 IX = 1,3
2107 GDS = 2 * GD(IX,IS)
2108 DSDGD = (S / GDMS) * GDS / GDMS
2109c DF1DGD = 2 * MU * S * DSDGD / KAPPA
2110c DFDGD = KAPPA * DF1DGD / F1**2
2111 DF1DGD =2*F1 * DSDGD * ( - MU * S / KAPPA)
2112 DFDGD = -1 * KAPPA * DF1DGD
2113 DFXDGD(IX,IS) = DS(IS) * EXUNIF * DFDGD
2114 50 CONTINUE
2115 60 CONTINUE
2116 FX = HALF * FX / DT
2117
2118C Set output arguments
2119 EX = FX
2120 EC = FC
2121 DO 90 IS = 1,nspin
2122 DEXDD(IS) = DFXDD(IS)
2123 DECDD(IS) = DFCDD(IS)
2124 DO 80 IX = 1,3
2125 DEXDGD(IX,IS) = DFXDGD(IX,IS)
2126 DECDGD(IX,IS) = DFCDGD(IX,IS)
2127 80 CONTINUE
2128 90 CONTINUE
2129
2130 END
2131 SUBROUTINE WCXC( IREL, nspin, Dens, GDens,
2132 . EX, EC, DEXDD, DECDD, DEXDGD, DECDGD )
2133
2134C *********************************************************************
2135C Implements Wu-Cohen Generalized-Gradient-Approximation.
2136C Ref: Z. Wu and R. E. Cohen PRB 73, 235116 (2006)
2137C Written by Marivi Fernandez-Serra, with contributions by
2138C Julian Gale and Alberto Garcia,
2139C over the PBEXC subroutine of L.C.Balbas and J.M.Soler.
2140C September, 2006.
2141C ******** INPUT ******************************************************
2142C INTEGER IREL : Relativistic-exchange switch (0=No, 1=Yes)
2143C INTEGER nspin : Number of spin polarizations (1 or 2)
2144C REAL*8 Dens(nspin) : Total electron density (if nspin=1) or
2145C spin electron density (if nspin=2)
2146C REAL*8 GDens(3,nspin) : Total or spin density gradient
2147C ******** OUTPUT *****************************************************
2148C REAL*8 EX : Exchange energy density
2149C REAL*8 EC : Correlation energy density
2150C REAL*8 DEXDD(nspin) : Partial derivative
2151C d(DensTot*Ex)/dDens(ispin),
2152C where DensTot = Sum_ispin( Dens(ispin) )
2153C For a constant density, this is the
2154C exchange potential
2155C REAL*8 DECDD(nspin) : Partial derivative
2156C d(DensTot*Ec)/dDens(ispin),
2157C where DensTot = Sum_ispin( Dens(ispin) )
2158C For a constant density, this is the
2159C correlation potential
2160C REAL*8 DEXDGD(3,nspin): Partial derivative
2161C d(DensTot*Ex)/d(GradDens(i,ispin))
2162C REAL*8 DECDGD(3,nspin): Partial derivative
2163C d(DensTot*Ec)/d(GradDens(i,ispin))
2164C ********* UNITS ****************************************************
2165C Lengths in Bohr
2166C Densities in electrons per Bohr**3
2167C Energies in Hartrees
2168C Gradient vectors in cartesian coordinates
2169C ********* ROUTINES CALLED ******************************************
2170C EXCHNG, PW92C
2171C ********************************************************************
2172
2173 use precision, only : dp
2174
2175 implicit none
2176 INTEGER IREL, nspin
2177 real(dp) Dens(nspin), DECDD(nspin), DECDGD(3,nspin),
2178 . DEXDD(nspin), DEXDGD(3,nspin), GDens(3,nspin)
2179
2180C Internal variables
2181 INTEGER
2182 . IS, IX
2183
2184 real(dp)
2185 . A, BETA, D(2), DADD, DECUDD, DENMIN,
2186 . DF1DD, DF2DD, DF3DD, DF4DD, DF1DGD, DF3DGD, DF4DGD,
2187 . DFCDD(2), DFCDGD(3,2), DFDD, DFDGD, DFXDD(2), DFXDGD(3,2),
2188 . DHDD, DHDGD, DKFDD, DKSDD, DPDD, DPDZ, DRSDD,
2189 . DS(2), DSDD, DSDGD, DT, DTDD, DTDGD, DZDD(2),
2190 . XWC, DXWCDS, CWC,
2191 . EC, ECUNIF, EX, EXUNIF,
2192 . F, F1, F2, F3, F4, FC, FX, FOUTHD,
2193 . GAMMA, GD(3,2), GDM(2), GDMIN, GDMS, GDMT, GDS, GDT(3),
2194 . H, HALF, KAPPA, KF, KFS, KS, MU, PHI, PI, RS, S,
2195 . TEN81,
2196 . T, THD, THRHLF, TWO, TWOTHD, VCUNIF(2), VXUNIF(2), ZETA
2197
2198C Lower bounds of density and its gradient to avoid divisions by zero
2199 PARAMETER ( DENMIN = 1.D-12 )
2200 PARAMETER ( GDMIN = 1.D-12 )
2201
2202C Fix some numerical parameters
2203 PARAMETER ( FOUTHD=4.D0/3.D0, HALF=0.5D0,
2204 . THD=1.D0/3.D0, THRHLF=1.5D0,
2205 . TWO=2.D0, TWOTHD=2.D0/3.D0 )
2206 PARAMETER ( TEN81 = 10.0d0/81.0d0 )
2207
2208C Fix some more numerical constants
2209 PI = 4 * ATAN(1.D0)
2210 BETA = 0.066725D0
2211 GAMMA = (1 - LOG(TWO)) / PI**2
2212 MU = BETA * PI**2 / 3
2213 KAPPA = 0.804D0
2214 CWC = 0.0079325D0
2215
2216C Translate density and its gradient to new variables
2217 IF (nspin .EQ. 1) THEN
2218 D(1) = HALF * Dens(1)
2219 D(2) = D(1)
2220 DT = MAX( DENMIN, Dens(1) )
2221 DO 10 IX = 1,3
2222 GD(IX,1) = HALF * GDens(IX,1)
2223 GD(IX,2) = GD(IX,1)
2224 GDT(IX) = GDens(IX,1)
2225 10 CONTINUE
2226 ELSE
2227 D(1) = Dens(1)
2228 D(2) = Dens(2)
2229 DT = MAX( DENMIN, Dens(1)+Dens(2) )
2230 DO 20 IX = 1,3
2231 GD(IX,1) = GDens(IX,1)
2232 GD(IX,2) = GDens(IX,2)
2233 GDT(IX) = GDens(IX,1) + GDens(IX,2)
2234 20 CONTINUE
2235 ENDIF
2236 GDM(1) = SQRT( GD(1,1)**2 + GD(2,1)**2 + GD(3,1)**2 )
2237 GDM(2) = SQRT( GD(1,2)**2 + GD(2,2)**2 + GD(3,2)**2 )
2238 GDMT = SQRT( GDT(1)**2 + GDT(2)**2 + GDT(3)**2 )
2239 GDMT = MAX( GDMIN, GDMT )
2240
2241C Find local correlation energy and potential
2242 CALL PW92C( 2, D, ECUNIF, VCUNIF )
2243
2244C Find total correlation energy
2245 RS = ( 3 / (4*PI*DT) )**THD
2246 KF = (3 * PI**2 * DT)**THD
2247 KS = SQRT( 4 * KF / PI )
2248 ZETA = ( D(1) - D(2) ) / DT
2249 ZETA = MAX( -1.D0+DENMIN, ZETA )
2250 ZETA = MIN( 1.D0-DENMIN, ZETA )
2251 PHI = HALF * ( (1+ZETA)**TWOTHD + (1-ZETA)**TWOTHD )
2252 T = GDMT / (2 * PHI * KS * DT)
2253 F1 = ECUNIF / GAMMA / PHI**3
2254 F2 = EXP(-F1)
2255 A = BETA / GAMMA / (F2-1)
2256 F3 = T**2 + A * T**4
2257 F4 = BETA/GAMMA * F3 / (1 + A*F3)
2258 H = GAMMA * PHI**3 * LOG( 1 + F4 )
2259 FC = ECUNIF + H
2260
2261C Find correlation energy derivatives
2262 DRSDD = - (THD * RS / DT)
2263 DKFDD = THD * KF / DT
2264 DKSDD = HALF * KS * DKFDD / KF
2265 DZDD(1) = 1 / DT - ZETA / DT
2266 DZDD(2) = - (1 / DT) - ZETA / DT
2267 DPDZ = HALF * TWOTHD * ( 1/(1+ZETA)**THD - 1/(1-ZETA)**THD )
2268 DO 40 IS = 1,2
2269 DECUDD = ( VCUNIF(IS) - ECUNIF ) / DT
2270 DPDD = DPDZ * DZDD(IS)
2271 DTDD = (- T) * ( DPDD/PHI + DKSDD/KS + 1/DT )
2272 DF1DD = F1 * ( DECUDD/ECUNIF - 3*DPDD/PHI )
2273 DF2DD = (- F2) * DF1DD
2274 DADD = (- A) * DF2DD / (F2-1)
2275 DF3DD = (2*T + 4*A*T**3) * DTDD + DADD * T**4
2276 DF4DD = F4 * ( DF3DD/F3 - (DADD*F3+A*DF3DD)/(1+A*F3) )
2277 DHDD = 3 * H * DPDD / PHI
2278 DHDD = DHDD + GAMMA * PHI**3 * DF4DD / (1+F4)
2279 DFCDD(IS) = VCUNIF(IS) + H + DT * DHDD
2280
2281 DO 30 IX = 1,3
2282 DTDGD = (T / GDMT) * GDT(IX) / GDMT
2283 DF3DGD = DTDGD * ( 2 * T + 4 * A * T**3 )
2284 DF4DGD = F4 * DF3DGD * ( 1/F3 - A/(1+A*F3) )
2285 DHDGD = GAMMA * PHI**3 * DF4DGD / (1+F4)
2286 DFCDGD(IX,IS) = DT * DHDGD
2287 30 CONTINUE
2288 40 CONTINUE
2289
2290C Find exchange energy and potential
2291 FX = 0
2292 DO 60 IS = 1,2
2293 DS(IS) = MAX( DENMIN, 2 * D(IS) )
2294 GDMS = MAX( GDMIN, 2 * GDM(IS) )
2295 KFS = (3 * PI**2 * DS(IS))**THD
2296 S = GDMS / (2 * KFS * DS(IS))
2297c
2298c For PBE:
2299c
2300c x = MU * S**2
2301c dxds = 2*MU*S
2302c
2303c Wu-Cohen form:
2304c
2305 XWC= TEN81 * s**2 + (MU- TEN81) *
2306 . S**2 * exp(-S**2) + log(1+ CWC * S**4)
2307 DXWCDS = 2 * TEN81 * S + (MU - TEN81) * exp(-S**2) *
2308 . 2*S * (1 - S*S) + 4 * CWC * S**3 / (1 + CWC * S**4)
2309c-------------------
2310
2311 F1 = 1 + XWC / KAPPA
2312 F = 1 + KAPPA - KAPPA / F1
2313c
2314c Note nspin=1 in call to exchng...
2315c
2316 CALL EXCHNG( IREL, 1, DS(IS), EXUNIF, VXUNIF(IS) )
2317 FX = FX + DS(IS) * EXUNIF * F
2318
2319 DKFDD = THD * KFS / DS(IS)
2320 DSDD = S * ( -(DKFDD/KFS) - 1/DS(IS) )
2321 DF1DD = DXWCDS * DSDD / KAPPA
2322 DFDD = KAPPA * DF1DD / F1**2
2323 DFXDD(IS) = VXUNIF(IS) * F + DS(IS) * EXUNIF * DFDD
2324
2325 DO 50 IX = 1,3
2326 GDS = 2 * GD(IX,IS)
2327 DSDGD = (S / GDMS) * GDS / GDMS
2328 DF1DGD = DXWCDS * DSDGD / KAPPA
2329 DFDGD = KAPPA * DF1DGD / F1**2
2330 DFXDGD(IX,IS) = DS(IS) * EXUNIF * DFDGD
2331 50 CONTINUE
2332 60 CONTINUE
2333 FX = HALF * FX / DT
2334
2335C Set output arguments
2336 EX = FX
2337 EC = FC
2338 DO 90 IS = 1,nspin
2339 DEXDD(IS) = DFXDD(IS)
2340 DECDD(IS) = DFCDD(IS)
2341 DO 80 IX = 1,3
2342 DEXDGD(IX,IS) = DFXDGD(IX,IS)
2343 DECDGD(IX,IS) = DFCDGD(IX,IS)
2344 80 CONTINUE
2345 90 CONTINUE
2346
2347 END
2348
2349 SUBROUTINE PBESOLXC( IREL, nspin, Dens, GDens,
2350 . EX, EC, DEXDD, DECDD, DEXDGD, DECDGD )
2351
2352C *********************************************************************
2353C Implements Perdew-Burke-Ernzerhof Generalized-Gradient-Approximation.
2354C with the revised parameters for solids (PBEsol).
2355C Ref: J.P.Perdew et al, PRL 100, 136406 (2008)
2356C Written by L.C.Balbas and J.M.Soler for PBE. December 1996.
2357C Modified by J.D. Gale for PBEsol. May 2009.
2358C ******** INPUT ******************************************************
2359C INTEGER IREL : Relativistic-exchange switch (0=No, 1=Yes)
2360C INTEGER nspin : Number of spin polarizations (1 or 2)
2361C REAL*8 Dens(nspin) : Total electron density (if nspin=1) or
2362C spin electron density (if nspin=2)
2363C REAL*8 GDens(3,nspin) : Total or spin density gradient
2364C ******** OUTPUT *****************************************************
2365C REAL*8 EX : Exchange energy density
2366C REAL*8 EC : Correlation energy density
2367C REAL*8 DEXDD(nspin) : Partial derivative
2368C d(DensTot*Ex)/dDens(ispin),
2369C where DensTot = Sum_ispin( Dens(ispin) )
2370C For a constant density, this is the
2371C exchange potential
2372C REAL*8 DECDD(nspin) : Partial derivative
2373C d(DensTot*Ec)/dDens(ispin),
2374C where DensTot = Sum_ispin( Dens(ispin) )
2375C For a constant density, this is the
2376C correlation potential
2377C REAL*8 DEXDGD(3,nspin): Partial derivative
2378C d(DensTot*Ex)/d(GradDens(i,ispin))
2379C REAL*8 DECDGD(3,nspin): Partial derivative
2380C d(DensTot*Ec)/d(GradDens(i,ispin))
2381C ********* UNITS ****************************************************
2382C Lengths in Bohr
2383C Densities in electrons per Bohr**3
2384C Energies in Hartrees
2385C Gradient vectors in cartesian coordinates
2386C ********* ROUTINES CALLED ******************************************
2387C EXCHNG, PW92C
2388C ********************************************************************
2389
2390 use precision, only : dp
2391
2392 implicit none
2393 INTEGER IREL, nspin
2394 real(dp) Dens(nspin), DECDD(nspin), DECDGD(3,nspin),
2395 . DEXDD(nspin), DEXDGD(3,nspin), GDens(3,nspin)
2396
2397C Internal variables
2398 INTEGER
2399 . IS, IX
2400
2401 real(dp)
2402 . A, BETA, D(2), DADD, DECUDD, DENMIN,
2403 . DF1DD, DF2DD, DF3DD, DF4DD, DF1DGD, DF3DGD, DF4DGD,
2404 . DFCDD(2), DFCDGD(3,2), DFDD, DFDGD, DFXDD(2), DFXDGD(3,2),
2405 . DHDD, DHDGD, DKFDD, DKSDD, DPDD, DPDZ, DRSDD,
2406 . DS(2), DSDD, DSDGD, DT, DTDD, DTDGD, DZDD(2),
2407 . EC, ECUNIF, EX, EXUNIF,
2408 . F, F1, F2, F3, F4, FC, FX, FOUTHD,
2409 . GAMMA, GD(3,2), GDM(2), GDMIN, GDMS, GDMT, GDS, GDT(3),
2410 . H, HALF, KAPPA, KF, KFS, KS, MU, PHI, PI, RS, S,
2411 . T, THD, THRHLF, TWO, TWOTHD, VCUNIF(2), VXUNIF(2), ZETA
2412
2413C Lower bounds of density and its gradient to avoid divisions by zero
2414 PARAMETER ( DENMIN = 1.D-12 )
2415 PARAMETER ( GDMIN = 1.D-12 )
2416
2417C Fix some numerical parameters
2418 PARAMETER ( FOUTHD=4.D0/3.D0, HALF=0.5D0,
2419 . THD=1.D0/3.D0, THRHLF=1.5D0,
2420 . TWO=2.D0, TWOTHD=2.D0/3.D0 )
2421
2422C Fix some more numerical constants
2423 PI = 4 * ATAN(1.D0)
2424 BETA = 0.046d0
2425 GAMMA = (1 - LOG(TWO)) / PI**2
2426 MU = 10.0d0/81.0d0
2427 KAPPA = 0.804D0
2428
2429C Translate density and its gradient to new variables
2430 IF (nspin .EQ. 1) THEN
2431 D(1) = HALF * Dens(1)
2432 D(2) = D(1)
2433 DT = MAX( DENMIN, Dens(1) )
2434 DO 10 IX = 1,3
2435 GD(IX,1) = HALF * GDens(IX,1)
2436 GD(IX,2) = GD(IX,1)
2437 GDT(IX) = GDens(IX,1)
2438 10 CONTINUE
2439 ELSE
2440 D(1) = Dens(1)
2441 D(2) = Dens(2)
2442 DT = MAX( DENMIN, Dens(1)+Dens(2) )
2443 DO 20 IX = 1,3
2444 GD(IX,1) = GDens(IX,1)
2445 GD(IX,2) = GDens(IX,2)
2446 GDT(IX) = GDens(IX,1) + GDens(IX,2)
2447 20 CONTINUE
2448 ENDIF
2449 GDM(1) = SQRT( GD(1,1)**2 + GD(2,1)**2 + GD(3,1)**2 )
2450 GDM(2) = SQRT( GD(1,2)**2 + GD(2,2)**2 + GD(3,2)**2 )
2451 GDMT = SQRT( GDT(1)**2 + GDT(2)**2 + GDT(3)**2 )
2452 GDMT = MAX( GDMIN, GDMT )
2453
2454C Find local correlation energy and potential
2455 CALL PW92C( 2, D, ECUNIF, VCUNIF )
2456
2457C Find total correlation energy
2458 RS = ( 3 / (4*PI*DT) )**THD
2459 KF = (3 * PI**2 * DT)**THD
2460 KS = SQRT( 4 * KF / PI )
2461 ZETA = ( D(1) - D(2) ) / DT
2462 ZETA = MAX( -1.D0+DENMIN, ZETA )
2463 ZETA = MIN( 1.D0-DENMIN, ZETA )
2464 PHI = HALF * ( (1+ZETA)**TWOTHD + (1-ZETA)**TWOTHD )
2465 T = GDMT / (2 * PHI * KS * DT)
2466 F1 = ECUNIF / GAMMA / PHI**3
2467 F2 = EXP(-F1)
2468 A = BETA / GAMMA / (F2-1)
2469 F3 = T**2 + A * T**4
2470 F4 = BETA/GAMMA * F3 / (1 + A*F3)
2471 H = GAMMA * PHI**3 * LOG( 1 + F4 )
2472 FC = ECUNIF + H
2473
2474C Find correlation energy derivatives
2475 DRSDD = - (THD * RS / DT)
2476 DKFDD = THD * KF / DT
2477 DKSDD = HALF * KS * DKFDD / KF
2478 DZDD(1) = 1 / DT - ZETA / DT
2479 DZDD(2) = - (1 / DT) - ZETA / DT
2480 DPDZ = HALF * TWOTHD * ( 1/(1+ZETA)**THD - 1/(1-ZETA)**THD )
2481 DO 40 IS = 1,2
2482 DECUDD = ( VCUNIF(IS) - ECUNIF ) / DT
2483 DPDD = DPDZ * DZDD(IS)
2484 DTDD = (- T) * ( DPDD/PHI + DKSDD/KS + 1/DT )
2485 DF1DD = F1 * ( DECUDD/ECUNIF - 3*DPDD/PHI )
2486 DF2DD = (- F2) * DF1DD
2487 DADD = (- A) * DF2DD / (F2-1)
2488 DF3DD = (2*T + 4*A*T**3) * DTDD + DADD * T**4
2489 DF4DD = F4 * ( DF3DD/F3 - (DADD*F3+A*DF3DD)/(1+A*F3) )
2490 DHDD = 3 * H * DPDD / PHI
2491 DHDD = DHDD + GAMMA * PHI**3 * DF4DD / (1+F4)
2492 DFCDD(IS) = VCUNIF(IS) + H + DT * DHDD
2493
2494 DO 30 IX = 1,3
2495 DTDGD = (T / GDMT) * GDT(IX) / GDMT
2496 DF3DGD = DTDGD * ( 2 * T + 4 * A * T**3 )
2497 DF4DGD = F4 * DF3DGD * ( 1/F3 - A/(1+A*F3) )
2498 DHDGD = GAMMA * PHI**3 * DF4DGD / (1+F4)
2499 DFCDGD(IX,IS) = DT * DHDGD
2500 30 CONTINUE
2501 40 CONTINUE
2502
2503C Find exchange energy and potential
2504 FX = 0
2505 DO 60 IS = 1,2
2506 DS(IS) = MAX( DENMIN, 2 * D(IS) )
2507 GDMS = MAX( GDMIN, 2 * GDM(IS) )
2508 KFS = (3 * PI**2 * DS(IS))**THD
2509 S = GDMS / (2 * KFS * DS(IS))
2510 F1 = 1 + MU * S**2 / KAPPA
2511 F = 1 + KAPPA - KAPPA / F1
2512c
2513c Note nspin=1 in call to exchng...
2514c
2515 CALL EXCHNG( IREL, 1, DS(IS), EXUNIF, VXUNIF(IS) )
2516 FX = FX + DS(IS) * EXUNIF * F
2517
2518 DKFDD = THD * KFS / DS(IS)
2519 DSDD = S * ( -(DKFDD/KFS) - 1/DS(IS) )
2520 DF1DD = 2 * (F1-1) * DSDD / S
2521 DFDD = KAPPA * DF1DD / F1**2
2522 DFXDD(IS) = VXUNIF(IS) * F + DS(IS) * EXUNIF * DFDD
2523
2524 DO 50 IX = 1,3
2525 GDS = 2 * GD(IX,IS)
2526 DSDGD = (S / GDMS) * GDS / GDMS
2527 DF1DGD = 2 * MU * S * DSDGD / KAPPA
2528 DFDGD = KAPPA * DF1DGD / F1**2
2529 DFXDGD(IX,IS) = DS(IS) * EXUNIF * DFDGD
2530 50 CONTINUE
2531 60 CONTINUE
2532 FX = HALF * FX / DT
2533
2534C Set output arguments
2535 EX = FX
2536 EC = FC
2537 DO 90 IS = 1,nspin
2538 DEXDD(IS) = DFXDD(IS)
2539 DECDD(IS) = DFCDD(IS)
2540 DO 80 IX = 1,3
2541 DEXDGD(IX,IS) = DFXDGD(IX,IS)
2542 DECDGD(IX,IS) = DFCDGD(IX,IS)
2543 80 CONTINUE
2544 90 CONTINUE
2545
2546 END
2547
25480
=== modified file 'Util/Gen-basis/Makefile'
--- Util/Gen-basis/Makefile 2018-10-16 11:10:27 +0000
+++ Util/Gen-basis/Makefile 2019-01-30 13:43:54 +0000
@@ -53,7 +53,7 @@
53 basis_specs.o atom.o memoryinfo.o memory.o periodic_table.o\53 basis_specs.o atom.o memoryinfo.o memory.o periodic_table.o\
54 pseudopotential.o pxf.o dot.o atom_options.o ldau_specs.o arw.o \54 pseudopotential.o pxf.o dot.o atom_options.o ldau_specs.o arw.o \
55 timer.o xml.o m_walltime.o read_xc_info.o gen-basis.o $(SYSOBJ) \55 timer.o xml.o m_walltime.o read_xc_info.o gen-basis.o $(SYSOBJ) \
56 xc.o bsc_xcmod.o m_cite.o local_sys.o56 m_cite.o local_sys.o
5757
58OBJS_IONCAT=f2kcli.o m_getopts.o basis_types.o precision.o parallel.o \58OBJS_IONCAT=f2kcli.o m_getopts.o basis_types.o precision.o parallel.o \
59 parsing.o m_io.o io.o alloc.o atom_options.o basis_io.o atm_transfer.o atm_types.o \59 parsing.o m_io.o io.o alloc.o atom_options.o basis_io.o atm_transfer.o atm_types.o \
@@ -61,7 +61,7 @@
61 pseudopotential.o chemical.o m_filter.o \61 pseudopotential.o chemical.o m_filter.o \
62 basis_specs.o atom.o memoryinfo.o m_memory.o periodic_table.o pxf.o \62 basis_specs.o atom.o memoryinfo.o m_memory.o periodic_table.o pxf.o \
63 atmfuncs.o spher_harm.o interpolation.o old_atmfuncs.o arw.o \63 atmfuncs.o spher_harm.o interpolation.o old_atmfuncs.o arw.o \
64 local_sys.o xc.o bsc_xcmod.o xml.o m_walltime.o ioncat.o ldau_specs.o m_cite.o $(SYSOBJ)64 local_sys.o xml.o m_walltime.o ioncat.o ldau_specs.o m_cite.o $(SYSOBJ)
6565
6666
67#67#
@@ -138,9 +138,9 @@
138atm_transfer.o: periodic_table.o radial.o138atm_transfer.o: periodic_table.o radial.o
139atm_types.o: precision.o radial.o139atm_types.o: precision.o radial.o
140atmfuncs.o: atm_types.o local_sys.o precision.o radial.o spher_harm.o140atmfuncs.o: atm_types.o local_sys.o precision.o radial.o spher_harm.o
141atom.o: atmparams.o atom_options.o basis_specs.o basis_types.o bsc_xcmod.o141atom.o: atmparams.o atom_options.o basis_specs.o basis_types.o interpolation.o
142atom.o: interpolation.o local_sys.o m_filter.o old_atmfuncs.o periodic_table.o142atom.o: local_sys.o m_filter.o old_atmfuncs.o periodic_table.o precision.o
143atom.o: precision.o pseudopotential.o143atom.o: pseudopotential.o
144atom_graph.o: alloc.o atm_types.o atmfuncs.o class_OrbitalDistribution.o144atom_graph.o: alloc.o atm_types.o atmfuncs.o class_OrbitalDistribution.o
145atom_graph.o: class_SpData1D.o class_SpData2D.o class_SpData2D.o145atom_graph.o: class_SpData1D.o class_SpData2D.o class_SpData2D.o
146atom_graph.o: class_Sparsity.o intrinsic_missing.o ldau_specs.o local_sys.o146atom_graph.o: class_Sparsity.o intrinsic_missing.o ldau_specs.o local_sys.o
@@ -169,16 +169,14 @@
169broadcast_projections.o: m_trialorbitalclass.o parallel.o siesta2wannier90.o169broadcast_projections.o: m_trialorbitalclass.o parallel.o siesta2wannier90.o
170broyden_optim.o: local_sys.o m_broyddj_nocomm.o m_memory.o parallel.o170broyden_optim.o: local_sys.o m_broyddj_nocomm.o m_memory.o parallel.o
171broyden_optim.o: precision.o siesta_options.o units.o171broyden_optim.o: precision.o siesta_options.o units.o
172bsc_cellxc.o: alloc.o bsc_xcmod.o cellxc_mod.o local_sys.o mesh.o172bsc_cellxc.o: alloc.o local_sys.o mesh.o moremeshsubs.o parallel.o
173bsc_cellxc.o: moremeshsubs.o parallel.o parallelsubs.o precision.o173bsc_cellxc.o: parallelsubs.o precision.o
174bsc_xcmod.o: local_sys.o parallel.o precision.o
175cart2frac.o: local_sys.o precision.o174cart2frac.o: local_sys.o precision.o
176cell_broyden_optim.o: local_sys.o m_broyddj_nocomm.o parallel.o precision.o175cell_broyden_optim.o: local_sys.o m_broyddj_nocomm.o parallel.o precision.o
177cell_broyden_optim.o: units.o zmatrix.o176cell_broyden_optim.o: units.o zmatrix.o
178cell_fire_optim.o: alloc.o local_sys.o m_fire.o m_memory.o parallel.o177cell_fire_optim.o: alloc.o local_sys.o m_fire.o m_memory.o parallel.o
179cell_fire_optim.o: precision.o siesta_options.o zmatrix.o178cell_fire_optim.o: precision.o siesta_options.o zmatrix.o
180cellsubs.o: precision.o179cellsubs.o: precision.o
181cellxc_mod.o: bsc_xcmod.o local_sys.o
182cgvc.o: alloc.o conjgr_old.o local_sys.o m_mpi_utils.o parallel.o precision.o180cgvc.o: alloc.o conjgr_old.o local_sys.o m_mpi_utils.o parallel.o precision.o
183cgvc.o: units.o181cgvc.o: units.o
184cgvc_zmatrix.o: alloc.o conjgr.o local_sys.o m_mpi_utils.o parallel.o182cgvc_zmatrix.o: alloc.o conjgr.o local_sys.o m_mpi_utils.o parallel.o
@@ -239,13 +237,13 @@
239detover.o: alloc.o linpack.o parallel.o parallelsubs.o precision.o237detover.o: alloc.o linpack.o parallel.o parallelsubs.o precision.o
240dfscf.o: alloc.o atm_types.o atmfuncs.o atomlist.o listsc.o local_sys.o mesh.o238dfscf.o: alloc.o atm_types.o atmfuncs.o atomlist.o listsc.o local_sys.o mesh.o
241dfscf.o: meshdscf.o meshphi.o parallel.o parallelsubs.o precision.o239dfscf.o: meshdscf.o meshphi.o parallel.o parallelsubs.o precision.o
242dhscf.o: alloc.o atmfuncs.o bsc_xcmod.o cellxc_mod.o delk.o dfscf.o240dhscf.o: alloc.o atmfuncs.o delk.o dfscf.o doping_uniform.o files.o forhar.o
243dhscf.o: doping_uniform.o files.o forhar.o iogrid_netcdf.o local_sys.o241dhscf.o: iogrid_netcdf.o local_sys.o m_charge_add.o m_efield.o m_hartree_add.o
244dhscf.o: m_charge_add.o m_efield.o m_hartree_add.o m_iorho.o m_mesh_node.o242dhscf.o: m_iorho.o m_mesh_node.o m_ncdf_io.o m_ncdf_siesta.o
245dhscf.o: m_ncdf_io.o m_ncdf_siesta.o m_partial_charges.o m_rhog.o m_spin.o243dhscf.o: m_partial_charges.o m_rhog.o m_spin.o m_ts_global_vars.o
246dhscf.o: m_ts_global_vars.o m_ts_hartree.o m_ts_options.o m_ts_voltage.o mesh.o244dhscf.o: m_ts_hartree.o m_ts_options.o m_ts_voltage.o mesh.o meshdscf.o
247dhscf.o: meshdscf.o meshsubs.o moremeshsubs.o parallel.o parsing.o precision.o245dhscf.o: meshsubs.o moremeshsubs.o parallel.o parsing.o precision.o rhofft.o
248dhscf.o: rhofft.o rhoofd.o siesta_options.o units.o vmat.o246dhscf.o: rhoofd.o siesta_options.o units.o vmat.o
249diag.o: alloc.o diag_option.o local_sys.o parallel.o precision.o247diag.o: alloc.o diag_option.o local_sys.o parallel.o precision.o
250diag2g.o: fermid.o intrinsic_missing.o local_sys.o parallel.o parallelsubs.o248diag2g.o: fermid.o intrinsic_missing.o local_sys.o parallel.o parallelsubs.o
251diag2g.o: precision.o249diag2g.o: precision.o
@@ -295,13 +293,13 @@
295fft.o: alloc.o fft1d.o local_sys.o m_timer.o mesh.o parallel.o parallelsubs.o293fft.o: alloc.o fft1d.o local_sys.o m_timer.o mesh.o parallel.o parallelsubs.o
296fft.o: precision.o294fft.o: precision.o
297fft1d.o: local_sys.o parallel.o precision.o295fft1d.o: local_sys.o parallel.o precision.o
298final_H_f_stress.o: alloc.o atomlist.o class_SpData2D.o compute_max_diff.o296final_H_f_stress.o: alloc.o atomlist.o class_SpData1D.o class_SpData2D.o
299final_H_f_stress.o: dnaefs.o files.o grdsam.o kinefsm.o ldau.o ldau_specs.o297final_H_f_stress.o: compute_max_diff.o dnaefs.o files.o grdsam.o kinefsm.o
300final_H_f_stress.o: local_sys.o m_dipol.o m_energies.o m_forces.o m_hsx.o298final_H_f_stress.o: ldau.o ldau_specs.o local_sys.o m_dipol.o m_energies.o
301final_H_f_stress.o: m_mpi_utils.o m_ncdf_siesta.o m_ntm.o m_spin.o m_stress.o299final_H_f_stress.o: m_forces.o m_hsx.o m_mpi_utils.o m_ncdf_siesta.o m_ntm.o
302final_H_f_stress.o: m_ts_io.o m_ts_kpoints.o m_ts_options.o metaforce.o300final_H_f_stress.o: m_spin.o m_stress.o m_ts_io.o m_ts_kpoints.o m_ts_options.o
303final_H_f_stress.o: molecularmechanics.o naefs.o nlefsm.o overfsm.o parallel.o301final_H_f_stress.o: metaforce.o molecularmechanics.o naefs.o nlefsm.o overfsm.o
304final_H_f_stress.o: siesta_geom.o siesta_options.o sparse_matrices.o302final_H_f_stress.o: parallel.o siesta_geom.o siesta_options.o sparse_matrices.o
305final_H_f_stress.o: spinorbit.o units.o303final_H_f_stress.o: spinorbit.o units.o
306find_kgrid.o: alloc.o minvec.o parallel.o precision.o units.o304find_kgrid.o: alloc.o minvec.o parallel.o precision.o units.o
307fire_optim.o: alloc.o m_fire.o m_mpi_utils.o parallel.o precision.o305fire_optim.o: alloc.o m_fire.o m_mpi_utils.o parallel.o precision.o
@@ -678,8 +676,8 @@
678meshdscf.o: alloc.o atomlist.o m_dscfcomm.o meshphi.o parallel.o parallelsubs.o676meshdscf.o: alloc.o atomlist.o m_dscfcomm.o meshphi.o parallel.o parallelsubs.o
679meshdscf.o: precision.o677meshdscf.o: precision.o
680meshphi.o: alloc.o precision.o678meshphi.o: alloc.o precision.o
681meshsubs.o: alloc.o atm_types.o atmfuncs.o cellsubs.o cellxc_mod.o chkgmx.o679meshsubs.o: alloc.o atm_types.o atmfuncs.o cellsubs.o chkgmx.o fft1d.o
682meshsubs.o: fft1d.o local_sys.o mesh.o meshphi.o moremeshsubs.o parallel.o680meshsubs.o: local_sys.o mesh.o meshphi.o moremeshsubs.o parallel.o
683meshsubs.o: parallelsubs.o precision.o radial.o siesta_cml.o681meshsubs.o: parallelsubs.o precision.o radial.o siesta_cml.o
684metaforce.o: alloc.o local_sys.o parallel.o precision.o682metaforce.o: alloc.o local_sys.o parallel.o precision.o
685minvec.o: cellsubs.o local_sys.o precision.o sorting.o683minvec.o: cellsubs.o local_sys.o precision.o sorting.o
@@ -777,9 +775,9 @@
777rhoofd.o: precision.o775rhoofd.o: precision.o
778rhoofdsp.o: alloc.o atm_types.o atmfuncs.o atomlist.o listsc.o local_sys.o776rhoofdsp.o: alloc.o atm_types.o atmfuncs.o atomlist.o listsc.o local_sys.o
779rhoofdsp.o: mesh.o meshdscf.o meshphi.o precision.o777rhoofdsp.o: mesh.o meshdscf.o meshphi.o precision.o
780save_density_matrix.o: atomlist.o files.o iodm_netcdf.o m_energies.o m_iodm.o778save_density_matrix.o: atomlist.o class_SpData2D.o files.o iodm_netcdf.o
781save_density_matrix.o: m_matio.o m_ncdf_siesta.o m_spin.o m_steps.o779save_density_matrix.o: m_energies.o m_iodm.o m_matio.o m_ncdf_siesta.o m_spin.o
782save_density_matrix.o: m_ts_global_vars.o m_ts_iodm.o m_ts_options.o780save_density_matrix.o: m_steps.o m_ts_global_vars.o m_ts_iodm.o m_ts_options.o
783save_density_matrix.o: precision.o siesta_geom.o siesta_options.o781save_density_matrix.o: precision.o siesta_geom.o siesta_options.o
784save_density_matrix.o: sparse_matrices.o782save_density_matrix.o: sparse_matrices.o
785savepsi.o: alloc.o parallel.o parallelsubs.o precision.o783savepsi.o: alloc.o parallel.o parallelsubs.o precision.o
@@ -842,17 +840,16 @@
842siesta_forces.o: siesta_master.o siesta_options.o sparse_matrices.o840siesta_forces.o: siesta_master.o siesta_options.o sparse_matrices.o
843siesta_forces.o: state_analysis.o state_init.o timer.o units.o write_subs.o841siesta_forces.o: state_analysis.o state_init.o timer.o units.o write_subs.o
844siesta_geom.o: precision.o842siesta_geom.o: precision.o
845siesta_init.o: alloc.o atomlist.o bands.o bsc_xcmod.o843siesta_init.o: alloc.o atomlist.o bands.o class_Fstack_Pair_Geometry_SpData2D.o
846siesta_init.o: class_Fstack_Pair_Geometry_SpData2D.o diag_option.o files.o844siesta_init.o: diag_option.o files.o flook_siesta.o ioxv.o kpoint_grid.o
847siesta_init.o: flook_siesta.o ioxv.o kpoint_grid.o kpoint_pdos.o ksvinit.o845siesta_init.o: kpoint_pdos.o ksvinit.o local_sys.o m_check_walltime.o m_cite.o
848siesta_init.o: local_sys.o m_check_walltime.o m_cite.o m_energies.o m_eo.o846siesta_init.o: m_energies.o m_eo.o m_fixed.o m_forces.o m_iostruct.o
849siesta_init.o: m_fixed.o m_forces.o m_iostruct.o m_mpi_utils.o m_new_dm.o847siesta_init.o: m_mpi_utils.o m_new_dm.o m_rmaxh.o m_spin.o m_steps.o
850siesta_init.o: m_rmaxh.o m_spin.o m_steps.o m_supercell.o m_timer.o848siesta_init.o: m_supercell.o m_timer.o m_wallclock.o metaforce.o
851siesta_init.o: m_wallclock.o metaforce.o molecularmechanics.o object_debug.o849siesta_init.o: molecularmechanics.o object_debug.o parallel.o parallelsubs.o
852siesta_init.o: parallel.o parallelsubs.o projected_DOS.o siesta_cmlsubs.o850siesta_init.o: projected_DOS.o siesta_cmlsubs.o siesta_dicts.o siesta_geom.o
853siesta_init.o: siesta_dicts.o siesta_geom.o siesta_options.o sparse_matrices.o851siesta_init.o: siesta_options.o sparse_matrices.o struct_init.o timer.o
854siesta_init.o: struct_init.o timer.o timestamp.o ts_init.o units.o writewave.o852siesta_init.o: timestamp.o ts_init.o units.o writewave.o zmatrix.o
855siesta_init.o: zmatrix.o
856siesta_master.o: iopipes.o iosockets.o local_sys.o precision.o853siesta_master.o: iopipes.o iosockets.o local_sys.o precision.o
857siesta_move.o: atomlist.o broyden_optim.o cell_broyden_optim.o854siesta_move.o: atomlist.o broyden_optim.o cell_broyden_optim.o
858siesta_move.o: cell_fire_optim.o dynamics.o fire_optim.o flook_siesta.o ioxv.o855siesta_move.o: cell_fire_optim.o dynamics.o fire_optim.o flook_siesta.o ioxv.o
@@ -926,7 +923,6 @@
926writewave.o: alloc.o atmfuncs.o atomlist.o densematrix.o diag.o diag_option.o923writewave.o: alloc.o atmfuncs.o atomlist.o densematrix.o diag.o diag_option.o
927writewave.o: get_kpoints_scale.o kpoint_grid.o local_sys.o m_spin.o parallel.o924writewave.o: get_kpoints_scale.o kpoint_grid.o local_sys.o m_spin.o parallel.o
928writewave.o: parallelsubs.o precision.o siesta_geom.o units.o925writewave.o: parallelsubs.o precision.o siesta_geom.o units.o
929xc.o: alloc.o bsc_xcmod.o local_sys.o precision.o
930xml.o: precision.o926xml.o: precision.o
931zm_broyden_optim.o: local_sys.o m_broyddj_nocomm.o parallel.o precision.o927zm_broyden_optim.o: local_sys.o m_broyddj_nocomm.o parallel.o precision.o
932zm_broyden_optim.o: units.o zmatrix.o928zm_broyden_optim.o: units.o zmatrix.o
933929
=== modified file 'version.info'
--- version.info 2019-01-30 11:09:09 +0000
+++ version.info 2019-01-30 13:43:54 +0000
@@ -1,1 +1,7 @@
1<<<<<<< TREE
1siesta-4.1-10592siesta-4.1-1059
3=======
4siesta-4.1-1050--xc-4
5
6
7>>>>>>> MERGE-SOURCE

Subscribers

People subscribed via source and target branches