1#ifndef MADNESS_CHEM_XCFUNCTIONAL_H__INCLUDED
2#define MADNESS_CHEM_XCFUNCTIONAL_H__INCLUDED
15#include <madness/tensor/tensor.h>
24#ifdef MADNESS_HAS_LIBXC
35 int x_rks_s__(
const double *r__,
double *
f,
double * dfdra);
36 int c_rks_vwn5__(
const double *r__,
double *
f,
double * dfdra);
37 double* rho = t.
ptr();
38 for (
int i=0; i<t.
size(); i++) {
39 double r = std::max(rho[i],1
e-12);
167 if (rho <= 0.0)
return 0.0;
177#ifdef MADNESS_HAS_LIBXC
204#ifdef MADNESS_HAS_LIBXC
205 std::vector< std::pair<xc_func_type*,double> > funcs;
238 const bool need_response)
const;
257 static void polyn(
const double x,
double&
p,
double& dpdx) {
260 static const double xmin = 1.e-6;
261 static const double xmax = 5.e-5;
263 static const double xmax2 = xmax*xmax;
264 static const double xmax3 = xmax2*xmax;
265 static const double xmin2 = xmin*xmin;
266 static const double xmin3 = xmin2*xmin;
267 static const double r = 1.0/((xmax-xmin)*(-xmin3+(3.0*xmin2+(-3.0*xmin+xmax)*xmax)*xmax));
268 static const double a0 = xmax3*xmin*(xmax-4.0*xmin)*r;
269 static const double a = xmin2*(xmin2+(-4.0*xmin+18.0*xmax)*xmax)*r;
270 static const double b = -6.0*xmin*xmax*(3.0*xmax+2.0*xmin)*r;
271 static const double c = (4.0*xmin2+(20.0*xmin+6.0*xmax)*xmax)*r;
272 static const double d = -(8.0*xmax+7.0*xmin)*r;
273 static const double e = 3.0*r;
284 p = a0+(
a+(
b+(
c+(
d+
e*x)*x)*x)*x)*x;
285 dpdx =
a+(2.0*
b+(3.0*
c+(4.0*
d+5.0*
e*x)*x)*x)*x;
317 if (refrho<
thresh) rho=0.0;
329 void initialize(
const std::string& input_line,
bool polarized,
World& world,
330 const bool verbose=
false);
359#ifdef MADNESS_HAS_LIBXC
360 return !funcs.empty();
439 const int ispin)
const;
456 std::vector<madness::Tensor<double> >
fxc_apply(
463 double lo=1
e-6, hi=1
e+1, s=std::pow(hi/
lo, 1.0/(npt-1));
466 for (
int i=0; i<npt; i++) {
470 std::vector< madness::Tensor<double> > t(13);
477 std::vector<madness::Tensor<double> > va =
vxc(t,0);
478 for (
long i=0; i<npt; i++) {
479 printf(
"%.3e %.3e %.3e\n", rho[i],
f[i], va[0][i]);
514 "nemo_u1_functors wants U1_{x,y,z} and |U1|^2, in that order");
527 const long npt = qx.
dim(0);
534 "nemo_u1_functors: quadrature order does not match "
535 "the xc arguments -- k changed after construction");
536 const double h = std::pow(0.5,
double(key.
level()));
540 const long dims[3] = {npt, npt, npt};
543 for (
int q = 0;
q < 4; ++
q) {
552 for (
long i = 0; i < npt; ++i) {
554 for (
long j = 0; j < npt; ++j) {
556 for (
long k = 0;
k < npt; ++
k, ++idx) {
558 for (
int q = 0;
q < 4; ++
q)
p[
q][idx] = (*
f[
q])(
c);
568 std::vector<std::shared_ptr<functorT> >
f;
584 std::vector<madness::Tensor<double> > tt(t);
607 std::size_t result_size=4;
621 std::vector<madness::Tensor<double> > tt(t);
double q(double t)
Definition DKops.h:18
This header should include pretty much everything needed for the parallel runtime.
long dim(int i) const
Returns the size of dimension i.
Definition basetensor.h:147
long size() const
Returns the number of elements in the tensor.
Definition basetensor.h:138
FunctionCommonData holds all Function data common for given k.
Definition function_common_data.h:52
Tensor< double > quad_x
quadrature points
Definition function_common_data.h:99
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:101
static const Tensor< double > & get_cell_width()
Returns the width of each user cell dimension.
Definition funcdefaults.h:390
static const Tensor< double > & get_cell()
Gets the user cell for the simulation.
Definition funcdefaults.h:352
Abstract base class interface required for functors used as input to Functions.
Definition function_interface.h:68
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:70
Level level() const
Definition key.h:169
const Vector< Translation, NDIM > & translation() const
Definition key.h:174
A tensor is a multidimensional array.
Definition tensor.h:318
T * ptr()
Returns a pointer to the internal data.
Definition tensor.h:1841
A simple, fixed dimension vector.
Definition vector.h:64
A parallel world class.
Definition world.h:134
Simplified interface to XC functionals.
Definition xcfunctional.h:49
bool has_fxc() const
Returns true if the second derivative of the functional is available (not yet supported)
Definition xcfunctional_ldaonly.cc:76
bool is_dft() const
Returns true if there is a DFT functional (false probably means Hatree-Fock exchange only)
Definition xcfunctional_ldaonly.cc:72
double get_tautol() const
return the floor for the kinetic energy density
Definition xcfunctional.h:141
double rhomin
what munge() puts in place of a density
Definition xcfunctional.h:186
static constexpr double default_tauwmargin
Definition xcfunctional.h:184
std::vector< madness::Tensor< double > > vxc(const std::vector< madness::Tensor< double > > &t, const int ispin) const
Computes components of the potential (derivative of the energy functional) at np points.
Definition xcfunctional_ldaonly.cc:128
static constexpr double default_rhomin
our lda will divide by rho
Definition xcfunctional.h:180
bool is_lda() const
Returns true if the potential is lda.
Definition xcfunctional_ldaonly.cc:52
double tau_w_bound(const double sigma, const double rho) const
the von Weizsaecker lower bound on tau, as the clamp actually applies it
Definition xcfunctional.h:166
double get_rhotol() const
return the munging threshold for the density
Definition xcfunctional.h:134
static const int number_xc_args
max number of intermediates
Definition xcfunctional.h:131
void plot() const
Crude function to plot the energy and potential functionals.
Definition xcfunctional.h:461
madness::Tensor< double > exc(const std::vector< madness::Tensor< double > > &t) const
Computes the energy functional at given points.
Definition xcfunctional_ldaonly.cc:86
bool is_spin_polarized() const
Returns true if the functional is spin_polarized.
Definition xcfunctional.h:367
xc_arg
Definition xcfunctional.h:68
@ enum_Ga_y
[MRA, smooth]
Definition xcfunctional.h:120
@ enum_zetab_y
Definition xcfunctional.h:84
@ enum_zetab_z
Definition xcfunctional.h:85
@ enum_Ga_z
[MRA, smooth]
Definition xcfunctional.h:121
@ enum_Ga_x
[MRA, smooth]
Definition xcfunctional.h:119
@ enum_ddens_pty
Definition xcfunctional.h:94
@ enum_zetaa_y
Definition xcfunctional.h:81
@ enum_sigtot
Definition xcfunctional.h:77
@ enum_zetab_x
Definition xcfunctional.h:83
@ enum_u1_x
[functor, never MRA]
Definition xcfunctional.h:126
@ enum_taua
alpha kinetic energy density
Definition xcfunctional.h:72
@ enum_nb
beta counterpart [MRA, smooth]
Definition xcfunctional.h:118
@ enum_gradfb
beta counterpart [MRA, smooth]
Definition xcfunctional.h:116
@ enum_nemo_R2
, the ncf squared [MRA, smooth]
Definition xcfunctional.h:114
@ enum_taub
beta kinetic energy density
Definition xcfunctional.h:73
@ enum_rho_pt
perturbed density (CPHF, TDKS)
Definition xcfunctional.h:71
@ enum_Gb_z
beta counterpart [MRA, smooth]
Definition xcfunctional.h:124
@ enum_gradfa
[MRA, smooth]
Definition xcfunctional.h:115
@ enum_sbb
Definition xcfunctional.h:76
@ enum_saa
Definition xcfunctional.h:74
@ enum_u1sq
[functor, never MRA]
Definition xcfunctional.h:129
@ enum_rhob
beta density
Definition xcfunctional.h:70
@ enum_Gb_y
beta counterpart [MRA, smooth]
Definition xcfunctional.h:123
@ enum_u1_z
[functor, never MRA]
Definition xcfunctional.h:128
@ enum_Gb_x
beta counterpart [MRA, smooth]
Definition xcfunctional.h:122
@ enum_zetaa_x
Definition xcfunctional.h:80
@ enum_sab
Definition xcfunctional.h:75
@ enum_zetaa_z
Definition xcfunctional.h:82
@ enum_sigma_pta_div_rho
Definition xcfunctional.h:78
@ enum_na
[MRA, smooth]
Definition xcfunctional.h:117
@ enum_u1_y
[functor, never MRA]
Definition xcfunctional.h:127
@ enum_sigma_ptb_div_rho
Definition xcfunctional.h:79
@ enum_ddens_ptx
Definition xcfunctional.h:93
@ enum_rhoa
alpha density
Definition xcfunctional.h:69
@ enum_ddens_ptz
Definition xcfunctional.h:95
bool is_meta() const
Returns true if the potential is meta gga (needs the kinetic energy density)
Definition xcfunctional_ldaonly.cc:60
static double munge_old(double rho)
Definition xcfunctional.h:289
bool is_gga() const
Returns true if the potential is gga (needs first derivatives)
Definition xcfunctional_ldaonly.cc:56
std::vector< madness::Tensor< double > > fxc_apply(const std::vector< madness::Tensor< double > > &t, const int ispin) const
compute the second derivative of the XC energy wrt the density and apply
Definition xcfunctional_ldaonly.cc:176
double get_tauwmargin() const
return the margin by which the von Weizsaecker clamp overshoots
Definition xcfunctional.h:144
~XCfunctional()
Destructor.
Definition xcfunctional_ldaonly.cc:50
bool uses_libxc_backend() const
Returns true when libxc is the active XC backend for this functional.
Definition xcfunctional.h:358
static constexpr double default_tautol
Definition xcfunctional.h:183
double hf_exchange_coefficient() const
Returns the value of the hf exact exchange coefficient.
Definition xcfunctional.h:379
void make_libxc_args(const std::vector< madness::Tensor< double > > &t, madness::Tensor< double > &rho, madness::Tensor< double > &sigma, madness::Tensor< double > &tau, madness::Tensor< double > &rho_pt, madness::Tensor< double > &sigma_pt, std::vector< madness::Tensor< double > > &drho, std::vector< madness::Tensor< double > > &drho_pt, const bool need_response) const
convert the raw density (gradient) data to be used by the xc operators
Definition xcfunctional_ldaonly.cc:181
double hf_coeff
Factor multiplying HF exchange (+1.0 gives HF)
Definition xcfunctional.h:174
void reset_screening_defaults()
put the configurable screening thresholds back to their defaults
Definition xcfunctional.h:197
bool needs_sigma() const
Returns true if the functional needs the reduced density gradients sigma.
Definition xcfunctional_ldaonly.cc:64
bool needs_tau() const
Returns true if the functional needs the kinetic energy density tau.
Definition xcfunctional_ldaonly.cc:68
static void polyn(const double x, double &p, double &dpdx)
Smoothly switches between constant (x<xmin) and linear function (x>xmax)
Definition xcfunctional.h:257
bool has_kxc() const
Returns true if the third derivative of the functional is available (not yet supported)
Definition xcfunctional_ldaonly.cc:81
double tautol
floor for the kinetic energy density, see initialize
Definition xcfunctional.h:188
bool spin_polarized
True if the functional is spin polarized.
Definition xcfunctional.h:173
void initialize(const std::string &input_line, bool polarized, World &world, const bool verbose=false)
Initialize the object from the user input data.
Definition xcfunctional_ldaonly.cc:19
XCfunctional()
Default constructor is required.
Definition xcfunctional.h:323
double binary_munge(double rho, double refrho, const double thresh) const
zero a quantity where the reference density is small
Definition xcfunctional.h:316
int nderiv
Jacob's ladder rung; 0: lda, 1: gga, 2: mgga.
Definition xcfunctional.h:175
double munge(double rho) const
simple munging for the density only (LDA)
Definition xcfunctional.h:298
double rhotol
See initialize and munge*.
Definition xcfunctional.h:187
double tauwmargin
von Weizsaecker clamp overshoot, see tau_w_bound
Definition xcfunctional.h:189
static constexpr double default_rhotol
Definition xcfunctional.h:182
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
const double sigma
Definition dielectric.cc:185
static double lo
Definition dirac-hatom.cc:23
static const double v
Definition hatom_sf_dirac.cc:20
Multidimension Key for MRA tree and associated iterators.
Macros and tools pertaining to the configuration of MADNESS.
#define MADNESS_PRAGMA_CLANG(x)
Definition madness_config.h:200
#define MADNESS_PRAGMA_GCC(x)
Definition madness_config.h:205
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
NDIM & f
Definition mra.h:2668
int x_rks_s__(const double *r__, double *f, double *dfdra)
Definition lda.cc:58
int c_rks_vwn5__(const double *r__, double *f, double *dfdra)
Definition lda.cc:116
static const double b
Definition nonlinschro.cc:119
static const double d
Definition nonlinschro.cc:121
static const double a
Definition nonlinschro.cc:118
static const double c
Definition relops.cc:10
static const double thresh
Definition rk.cc:45
static const long k
Definition rk.cc:44
the cuspy half of the nemo tau decomposition, supplied pointwise
Definition xcfunctional.h:503
madness::FunctionCommonData< double, 3 > cdata
Definition xcfunctional.h:569
std::vector< std::shared_ptr< functorT > > f
Definition xcfunctional.h:568
madness::FunctionFunctorInterface< double, 3 > functorT
Definition xcfunctional.h:504
bool active() const
Definition xcfunctional.h:517
nemo_u1_functors(const std::vector< std::shared_ptr< functorT > > &u1)
Definition xcfunctional.h:510
void append(const madness::Key< 3 > &key, std::vector< madness::Tensor< double > > &t) const
write U1 and |U1|^2 at this box's quadrature points into t[enum_u1*]
Definition xcfunctional.h:520
nemo_u1_functors()
Definition xcfunctional.h:506
Class to compute the energy functional.
Definition xcfunctional.h:573
nemo_u1_functors u1
empty without a nuclear correlation factor
Definition xcfunctional.h:575
xc_functional(const XCfunctional &xc)
Definition xcfunctional.h:577
madness::Tensor< double > operator()(const madness::Key< 3 > &key, const std::vector< madness::Tensor< double > > &t) const
Definition xcfunctional.h:580
const XCfunctional * xc
Definition xcfunctional.h:574
xc_functional(const XCfunctional &xc, const nemo_u1_functors &u1)
Definition xcfunctional.h:578
Class to compute terms of the kernel.
Definition xcfunctional.h:629
const FunctionCommonData< double, 3 > & cdata
Definition xcfunctional.h:632
const int ispin
Definition xcfunctional.h:631
std::size_t get_result_size() const
Definition xcfunctional.h:639
std::vector< madness::Tensor< double > > operator()(const madness::Key< 3 > &key, const std::vector< madness::Tensor< double > > &t) const
Definition xcfunctional.h:645
const XCfunctional * xc
Definition xcfunctional.h:630
xc_kernel_apply(const XCfunctional &xc, int ispin)
Definition xcfunctional.h:634
Compute the spin-restricted LDA potential using unaryop (only for the initial guess)
Definition xcfunctional.h:30
void operator()(const Key< 3 > &key, Tensor< double > &t) const
Definition xcfunctional.h:33
xc_lda_potential()
Definition xcfunctional.h:31
Class to compute terms of the potential.
Definition xcfunctional.h:592
xc_potential(const XCfunctional &xc, int ispin)
Definition xcfunctional.h:597
std::size_t get_result_size() const
Definition xcfunctional.h:603
xc_potential(const XCfunctional &xc, int ispin, const nemo_u1_functors &u1)
Definition xcfunctional.h:599
const XCfunctional * xc
Definition xcfunctional.h:593
std::vector< madness::Tensor< double > > operator()(const madness::Key< 3 > &key, const std::vector< madness::Tensor< double > > &t) const
Definition xcfunctional.h:615
const int ispin
Definition xcfunctional.h:594
nemo_u1_functors u1
empty without a nuclear correlation factor
Definition xcfunctional.h:595
void e()
Definition test_sig.cc:75
double h(const coord_1d &r)
Definition testgconv.cc:175