25#ifndef __XC_FUNCTIONAL_HPP__
26#define __XC_FUNCTIONAL_HPP__
31#include "xc_functional_base.hpp"
33#if defined(SIRIUS_USE_VDWXC)
35#if SIRIUS_HAVE_VDWXC_MPI
48#if defined(SIRIUS_USE_VDWXC)
49 vdwxc_data handler_vdw_{
nullptr};
50 bool vdw_functional_{
false};
62 const std::string libxc_name__,
int num_spins__)
66#if defined(SIRIUS_USE_VDWXC)
68 if (this->libxc_initialized_) {
74 bool test = (libxc_name_ ==
"XC_FUNC_VDWDF");
75 test = test || (libxc_name_ ==
"XC_FUNC_VDWDF2");
76 test = test || (libxc_name_ ==
"XC_FUNC_VDWDFCX");
80 if (libxc_name__ ==
"XC_FUNC_VDWDF") {
84 if (libxc_name__ ==
"XC_FUNC_VDWDF2") {
88 if (libxc_name__ ==
"XC_FUNC_VDWDFCX") {
93 if (num_spins__ == 1) {
95 handler_vdw_ = vdwxc_new(func_);
98 handler_vdw_ = vdwxc_new_spin(func_);
103 s <<
"VDW functional lib could not be initialized";
107 double v1[3] = { lattice_vectors__(0, 0), lattice_vectors__(1, 0), lattice_vectors__(2, 0) };
108 double v2[3] = { lattice_vectors__(0, 1), lattice_vectors__(1, 1), lattice_vectors__(2, 1) };
109 double v3[3] = { lattice_vectors__(0, 2), lattice_vectors__(1, 2), lattice_vectors__(2, 2) };
110 vdwxc_set_unit_cell(handler_vdw_,
116 v3[0], v3[1], v3[2]);
118 vdwxc_init_serial(handler_vdw_);
120#if SIRIUS_HAVE_VDWXC_MPI
121 vdwxc_init_mpi(handler_vdw_, fft__.communicator());
123 vdwxc_init_serial(handler_vdw_);
126 vdw_functional_ =
true;
131 s <<
"XC functional " << libxc_name__ <<
" is unknown";
135 if (this->libxc_initialized_) {
140 s <<
"XC functional " << libxc_name__ <<
" is unknown";
149#if defined(SIRIUS_USE_VDWXC)
150 this->handler_vdw_ = src__.handler_vdw_;
151 this->vdw_functional_ = src__.vdw_functional_;
152 src__.vdw_functional_ =
false;
158#if defined(SIRIUS_USE_VDWXC)
159 if (this->vdw_functional_) {
160 vdwxc_finalize(&this->handler_vdw_);
161 this->vdw_functional_ =
false;
167 const std::string refs()
const
169#if defined(SIRIUS_USE_VDWXC)
171 if (vdw_functional_) {
172 s <<
"==============================================================================\n";
174 s <<
"Warning : these functionals should be used in combination with GGA functionals\n";
176 s <<
"==============================================================================\n";
178 s <<
"A. H. Larsen, M. Kuisma, J. Löfgren, Y. Pouillon, P. Erhart, and P. Hyldgaard, ";
179 s <<
"Modelling Simul. Mater. Sci. Eng. 25, 065004 (2017) (10.1088/1361-651X/aa7320)\n";
183 return XC_functional_base::refs();
188#if defined(SIRIUS_USE_VDWXC)
189 if (this->vdw_functional_ ==
true) {
190 return XC_FAMILY_UNKNOWN;
193 return XC_functional_base::family();
198#if defined(SIRIUS_USE_VDWXC)
199 return this->vdw_functional_;
205 void vdw_update_unit_cell(spfft::Transform
const& fft__,
r3::matrix<double> const& lattice_vectors__)
207 #ifdef SIRIUS_USE_VDWXC
209 double v1[3] = {lattice_vectors__(0, 0), lattice_vectors__(1, 0), lattice_vectors__(2, 0)};
210 double v2[3] = {lattice_vectors__(0, 1), lattice_vectors__(1, 1), lattice_vectors__(2, 1)};
211 double v3[3] = {lattice_vectors__(0, 2), lattice_vectors__(1, 2), lattice_vectors__(2, 2)};
213 vdwxc_set_unit_cell(handler_vdw_, fft__.dim_x(), fft__.dim_y(), fft__.dim_z(), v1[0], v1[1], v1[2], v2[0],
214 v2[1], v2[2], v3[0], v3[1], v3[2]);
222#if defined(SIRIUS_USE_VDWXC)
223 if (this->vdw_functional_ ==
true) {
227 return XC_functional_base::kind();
230#if defined(SIRIUS_USE_VDWXC)
232 void get_vdw(
double* rho,
239 RTE_THROW(
"Error wrong vdw XC");
241 energy__[0] = vdwxc_calculate(handler_vdw_, rho, sigma, vrho, vsigma);
245 void get_vdw(
double *rho_up,
double *rho_down,
246 double *sigma_up,
double *sigma_down,
247 double *vrho_up,
double *vrho_down,
248 double *vsigma_up,
double *vsigma_down,
252 RTE_THROW(
"Error wrong XC");
255 energy__[0] = vdwxc_calculate_spin(handler_vdw_, rho_up, rho_down,
256 sigma_up , sigma_down,
258 vsigma_up, vsigma_down);
Interface class to Libxc.
Interface class to Libxc.
MPI communicator wrapper.
int size() const
Size of the communicator (number of ranks).
Contains helper functions for the interface with SpFFT library.
Namespace of the SIRIUS library.
Simple classes and functions to work with vectors and matrices of the R^3 space.