LDAFunctional.C 5.79 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19 20 21 22 23 24 25 26
// LDAFunctional.C
//
// LDA Exchange-correlation energy and potential
// Ceperley & Alder, parametrized by Perdew and Zunger
//
////////////////////////////////////////////////////////////////////////////////

#include <cmath>
#include <cassert>
#include <vector>
#include "LDAFunctional.h"

27
void LDAFunctional::setxc(void)
Francois Gygi committed
28 29 30 31 32 33 34
{
  if ( _np == 0 ) return;
  if ( _nspin == 1 )
  {
    assert(rho != 0);
    assert(exc != 0);
    assert(vxc1 != 0);
Francois Gygi committed
35
    #pragma omp parallel for
Francois Gygi committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    for ( int ir = 0; ir < _np; ir++ )
    {
      xc_unpolarized(rho[ir],exc[ir],vxc1[ir]);
    }
  }
  else
  {
    // spin polarized
    assert(rho_up != 0);
    assert(rho_dn != 0);
    assert(exc != 0);
    assert(vxc1_up != 0);
    assert(vxc1_dn != 0);
    const double fz_prefac = 1.0 / ( cbrt(2.0)*2.0 - 2.0 );
    const double dfz_prefac = (4.0/3.0) * fz_prefac;
Francois Gygi committed
51
    #pragma omp parallel for
Francois Gygi committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    for ( int ir = 0; ir < _np; ir++ )
    {
      double excir = 0.0;
      double v_up = 0.0;
      double v_dn = 0.0;

      double roe_up = rho_up[ir];
      double roe_dn = rho_dn[ir];
      double roe = roe_up + roe_dn;

      if ( roe > 0.0 )
      {
        double zeta = ( roe_up - roe_dn ) / roe;

        double zp1 = 1.0 + zeta;
        double zm1 = 1.0 - zeta;
        double zp1_13 = cbrt(zp1);
        double zm1_13 = cbrt(zm1);
        double fz = fz_prefac * ( zp1_13 * zp1 + zm1_13 * zm1 - 2.0 );
        double dfz = dfz_prefac * ( zp1_13 - zm1_13 );

        double xc_u, xc_p, v_u, v_p;
        xc_unpolarized(roe,xc_u,v_u);
        xc_polarized(roe,xc_p,v_p);

        double xc_pu = xc_p - xc_u;
        excir = xc_u + fz * xc_pu;

        double v = v_u + fz * ( v_p - v_u );
        v_up = v + xc_pu * (  1.0 - zeta ) * dfz;
        v_dn = v + xc_pu * ( -1.0 - zeta ) * dfz;
      }

      vxc1_up[ir] = v_up;
      vxc1_dn[ir] = v_dn;
      exc[ir] = excir;
    }
  }
}

void LDAFunctional::xc_unpolarized(const double rh, double &ee, double &vv)
{
94
  // compute LDA xc energy and potential, unpolarized
Francois Gygi committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108
  // const double third=1.0/3.0;
  // c1 is (3.D0/(4.D0*pi))**third
  const double c1 = 0.6203504908994001;
  // alpha = (4/(9*pi))**third = 0.521061761198
  // const double alpha = 0.521061761198;
  // c2 = -(3/(4*pi)) / alpha = -0.458165293283
  // const double c2 = -0.458165293283;
  // c3 = (4/3) * c2 = -0.610887057711
  const double c3 = -0.610887057711;

  const double A  =  0.0311;
  const double B  = -0.048;
  const double b1 =  1.0529;
  const double b2 =  0.3334;
109
  const double G  = -0.1423;
110

111 112 113 114 115
  // C from the PZ paper: const double C  =  0.0020;
  // D from the PZ paper: const double D  = -0.0116;
  // C and D by matching Ec and Vc at rs=1
  const double D = G / ( 1.0 + b1 + b2 ) - B;
  const double C = -A - D - G * ( (b1/2.0 + b2) / ((1.0+b1+b2)*(1.0+b1+b2)));
116

Francois Gygi committed
117 118 119 120 121 122 123 124 125 126 127 128 129
  ee = 0.0;
  vv = 0.0;

  if ( rh > 0.0 )
  {
    double ro13 = cbrt(rh);
    double rs = c1 / ro13;

    double ex=0.0,vx=0.0,ec=0.0,vc=0.0;

    // Next line : exchange part in Hartree units
    vx = c3 / rs;
    ex = 0.75 * vx;
130

Francois Gygi committed
131 132 133 134 135 136 137 138 139 140 141 142 143
    // Next lines : Ceperley & Alder correlation (Zunger & Perdew)
    if ( rs < 1.0 )
    {
      double logrs = log(rs);
      ec = A * logrs + B + C * rs * logrs + D * rs;
      vc = A * logrs + ( B - A / 3.0 ) +
           (2.0/3.0) * C * rs * logrs +
           ( ( 2.0 * D - C ) / 3.0 ) * rs;
    }
    else
    {
      double sqrtrs = sqrt(rs);
      double den = 1.0 + b1 * sqrtrs + b2 * rs;
144
      ec = G / den;
Francois Gygi committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
      vc = ec * ( 1.0 + (7.0/6.0) * b1 * sqrtrs +
                  (4.0/3.0) * b2 * rs ) / den;
    }
    ee = ex + ec;
    vv = vx + vc;
  }
}

void LDAFunctional::xc_polarized(const double rh, double &ee, double &vv)
{
  // compute LDA polarized XC energy and potential

  // const double third=1.0/3.0;
  // c1 is (3.D0/(4.D0*pi))**third
  const double c1 = 0.6203504908994001;
  // alpha = (4/(9*pi))**third = 0.521061761198
  // const double alpha = 0.521061761198;
  // c2 = -(3/(4*pi)) / alpha = -0.458165293283
  // const double c2 = -0.458165293283;
  // c3 = (4/3) * c2 = -0.610887057711
  // const double c3 = -0.610887057711;
166
  // c4 = 2**third * c3
Francois Gygi committed
167 168 169 170 171 172
  const double c4 = -0.769669463118;

  const double A =  0.01555;
  const double B = -0.0269;
  const double b1  =  1.3981;
  const double b2  =  0.2611;
173 174 175 176 177 178
  const double G   = -0.0843;
  // C from PZ paper: const double C   =  0.0007;
  // D from PZ paper: const double D   = -0.0048;
  // C and D by matching Ec and Vc at rs=1
  const double D = G / ( 1.0 + b1 + b2 ) - B;
  const double C = -A - D - G * ( (b1/2.0 + b2) / ((1.0+b1+b2)*(1.0+b1+b2)));
Francois Gygi committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192

  ee = 0.0;
  vv = 0.0;

  if ( rh > 0.0 )
  {
    double ro13 = cbrt(rh);
    double rs = c1 / ro13;

    double ex=0.0,vx=0.0,ec=0.0,vc=0.0;

    // Next line : exchange part in Hartree units
    vx = c4 / rs;
    ex = 0.75 * vx;
193

Francois Gygi committed
194 195 196 197 198 199 200 201 202 203 204 205 206
    // Next lines : Ceperley & Alder correlation (Zunger & Perdew)
    if ( rs < 1.0 )
    {
      double logrs = log(rs);
      ec = A * logrs + B + C * rs * logrs + D * rs;
      vc = A * logrs + ( B - A / 3.0 ) +
           (2.0/3.0) * C * rs * logrs +
           ( ( 2.0 * D - C ) / 3.0 ) * rs;
    }
    else
    {
      double sqrtrs = sqrt(rs);
      double den = 1.0 + b1 * sqrtrs + b2 * rs;
207
      ec = G / den;
Francois Gygi committed
208 209 210 211 212 213 214
      vc = ec * ( 1.0 + (7.0/6.0) * b1 * sqrtrs +
                  (4.0/3.0) * b2 * rs ) / den;
    }
    ee = ex + ec;
    vv = vx + vc;
  }
}