Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions source/source_estate/module_pot/pot_xc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "source_base/timer.h"
#include "source_hamilt/module_xc/xc_functional.h"
#include "source_io/module_parameter/parameter.h"

#ifdef USE_LIBXC
#include "source_hamilt/module_xc/libxc_abacus.h"
Expand All @@ -24,7 +25,8 @@ void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, Module
{
#ifdef USE_LIBXC
const std::tuple<double, double, ModuleBase::matrix, ModuleBase::matrix> etxc_vtxc_v
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), nrxx_current, ucell->omega, ucell->tpiba, chg);
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), nrxx_current, ucell->omega, ucell->tpiba, chg,
PARAM.inp.nspin);
*(this->etxc_) = std::get<0>(etxc_vtxc_v);
*(this->vtxc_) = std::get<1>(etxc_vtxc_v);
v_eff += std::get<2>(etxc_vtxc_v);
Expand All @@ -36,7 +38,10 @@ void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, Module
else
{
const std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v
= XC_Functional::v_xc(nrxx_current, chg, ucell);
= XC_Functional::v_xc(nrxx_current, chg, ucell,
PARAM.inp.nspin,
PARAM.globalv.domag,
PARAM.globalv.domag_z);
*(this->etxc_) = std::get<0>(etxc_vtxc_v);
*(this->vtxc_) = std::get<1>(etxc_vtxc_v);
v_eff += std::get<2>(etxc_vtxc_v);
Expand Down
11 changes: 9 additions & 2 deletions source/source_estate/module_pot/pot_xc_fdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "pot_xc_fdm.h"
#include "source_hamilt/module_xc/xc_functional.h"
#include "source_io/module_parameter/parameter.h"

namespace elecstate
{
Expand All @@ -20,7 +21,10 @@ PotXC_FDM::PotXC_FDM(
this->fixed_mode = false;

const std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v_0
= XC_Functional::v_xc(this->chg_0->nrxx, this->chg_0, ucell);
= XC_Functional::v_xc(this->chg_0->nrxx, this->chg_0, ucell,
PARAM.inp.nspin,
PARAM.globalv.domag,
PARAM.globalv.domag_z);
this->v_xc_0 = std::get<2>(etxc_vtxc_v_0);
}

Expand All @@ -47,7 +51,10 @@ void PotXC_FDM::cal_v_eff(
}

const std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v_01
= XC_Functional::v_xc(chg_01.nrxx, &chg_01, ucell);
= XC_Functional::v_xc(chg_01.nrxx, &chg_01, ucell,
PARAM.inp.nspin,
PARAM.globalv.domag,
PARAM.globalv.domag_z);
const ModuleBase::matrix &v_xc_01 = std::get<2>(etxc_vtxc_v_01);

v_eff += v_xc_01 - this->v_xc_0;
Expand Down
8 changes: 6 additions & 2 deletions source/source_hamilt/module_xc/libxc_abacus.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,19 @@ namespace XC_Functional_Libxc
const double &omega, // volume of cell
const double tpiba,
const Charge* const chr, // charge density
const std::map<int, double>* scaling_factor = nullptr); // added by jghan, 2024-10-10
const int nspin,
const bool domag,
const bool domag_z,
const std::map<int, double>* scaling_factor);
Comment thread
mohanchen marked this conversation as resolved.

// for mGGA functional
extern std::tuple<double, double, ModuleBase::matrix, ModuleBase::matrix> v_xc_meta(
const std::vector<int> &func_id,
const int &nrxx, // number of real-space grid
const double &omega, // volume of cell
const double tpiba,
const Charge* const chr);
const Charge* const chr,
const int nspin);


//-------------------
Expand Down
18 changes: 10 additions & 8 deletions source/source_hamilt/module_xc/libxc_pot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
const double &omega, // volume of cell
const double tpiba,
const Charge* const chr,
const int nspin_in,
const bool domag,
const bool domag_z,
const std::map<int, double>* scaling_factor)
{
ModuleBase::TITLE("XC_Functional_Libxc","v_xc_libxc");
ModuleBase::timer::start("XC_Functional_Libxc","v_xc_libxc");

const int nspin =
(PARAM.inp.nspin == 1 || ( PARAM.inp.nspin ==4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z))
(nspin_in == 1 || ( nspin_in ==4 && !domag && !domag_z))
? 1 : 2;

//----------------------------------------------------------
Expand Down Expand Up @@ -56,7 +59,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
// converting rho
std::vector<double> rho;
std::vector<double> amag;
if(1==nspin || 2==PARAM.inp.nspin)
if(1==nspin || 2==nspin_in)
{
rho = XC_Functional_Libxc::convert_rho(nspin, nrxx, chr);
}
Expand Down Expand Up @@ -167,7 +170,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
v += std::get<1>(vtxc_v) * factor;
} // end for( xc_func_type &func : funcs )

if(4==PARAM.inp.nspin)
if(4==nspin_in)
{
v = XC_Functional_Libxc::convert_v_nspin4(nrxx, chr, amag, v);
}
Expand Down Expand Up @@ -207,7 +210,8 @@ std::tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional_Li
const int &nrxx, // number of real-space grid
const double &omega, // volume of cell
const double tpiba,
const Charge* const chr)
const Charge* const chr,
const int nspin)
{
ModuleBase::TITLE("XC_Functional_Libxc","v_xc_meta");
ModuleBase::timer::start("XC_Functional_Libxc","v_xc_meta");
Expand All @@ -217,17 +221,15 @@ std::tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional_Li
//output of the subroutine
double etxc = 0.0;
double vtxc = 0.0;
ModuleBase::matrix v(PARAM.inp.nspin,nrxx);
ModuleBase::matrix vofk(PARAM.inp.nspin,nrxx);
ModuleBase::matrix v(nspin,nrxx);
ModuleBase::matrix vofk(nspin,nrxx);

//----------------------------------------------------------
// xc_func_type is defined in Libxc package
// to understand the usage of xc_func_type,
// use can check on website, for example:
// https://www.tddft.org/programs/libxc/manual/libxc-5.1.x/
//----------------------------------------------------------

const int nspin = PARAM.inp.nspin;
std::vector<xc_func_type> funcs = XC_Functional_Libxc::init_func(
/* func_id = */ func_id,
/* xc_polarized = */ (1==nspin) ? XC_UNPOLARIZED:XC_POLARIZED);
Expand Down
25 changes: 13 additions & 12 deletions source/source_hamilt/module_xc/test/test_xc3.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "gtest/gtest.h"
#include "xctest.h"
#define private public
#include "source_io/module_parameter/parameter.h"
#undef private
#include "../xc_functional.h"
#include "../exx_info.h"
#include "xc3_mock.h"
Expand Down Expand Up @@ -37,6 +34,14 @@ class XCTest_GRADCORR : public XCTest

void SetUp()
{
// Define variables for parameters
int nspin1 = 1;
int nspin2 = 2;
int nspin4 = 4;
bool domag = false;
bool domag_z = false;
bool domag_true = true;

ModulePW::PW_Basis rhopw;
UnitCell ucell;
Charge chr;
Expand Down Expand Up @@ -84,17 +89,13 @@ class XCTest_GRADCORR : public XCTest

XC_Functional::set_xc_type("PBE");

PARAM.input.nspin = 1;
XC_Functional::gradcorr(et1,vt1,v1,&chr,&rhopw,&ucell,stress1,false);
XC_Functional::gradcorr(et1,vt1,v1,&chr,&rhopw,&ucell,stress1,true);
XC_Functional::gradcorr(et1,vt1,v1,&chr,&rhopw,&ucell,stress1,false,nspin1,domag,domag_z);
XC_Functional::gradcorr(et1,vt1,v1,&chr,&rhopw,&ucell,stress1,true,nspin1,domag,domag_z);

PARAM.input.nspin = 2;
XC_Functional::gradcorr(et2,vt2,v2,&chr,&rhopw,&ucell,stress2,false);
XC_Functional::gradcorr(et2,vt2,v2,&chr,&rhopw,&ucell,stress2,true);
XC_Functional::gradcorr(et2,vt2,v2,&chr,&rhopw,&ucell,stress2,false,nspin2,domag,domag_z);
XC_Functional::gradcorr(et2,vt2,v2,&chr,&rhopw,&ucell,stress2,true,nspin2,domag,domag_z);

PARAM.input.nspin = 4;
PARAM.sys.domag = true;
XC_Functional::gradcorr(et4,vt4,v4,&chr,&rhopw,&ucell,stress4,false);
XC_Functional::gradcorr(et4,vt4,v4,&chr,&rhopw,&ucell,stress4,false,nspin4,domag_true,domag_z);
}
};

Expand Down
37 changes: 22 additions & 15 deletions source/source_hamilt/module_xc/test/test_xc5.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "../xc_functional.h"
#include "../libxc_abacus.h"
#include "gtest/gtest.h"
#define private public
#include "source_io/module_parameter/parameter.h"
#undef private
#include "xctest.h"
#include "../exx_info.h"
#include "xc3_mock.h"
Expand Down Expand Up @@ -32,6 +29,12 @@ class XCTest_VXC : public XCTest

void SetUp()
{
// Define variables for parameters
int nspin1 = 1;
int nspin2 = 2;
bool domag = false;
bool domag_z = false;

ModulePW::PW_Basis rhopw;
UnitCell ucell;
Charge chr;
Expand Down Expand Up @@ -75,16 +78,14 @@ class XCTest_VXC : public XCTest

XC_Functional::set_xc_type("PBE");

PARAM.input.nspin = 1;
std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v
= XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell);
= XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell,nspin1,domag,domag_z);
et1 = std::get<0>(etxc_vtxc_v);
vt1 = std::get<1>(etxc_vtxc_v);
v1 = std::get<2>(etxc_vtxc_v);

PARAM.input.nspin = 2;
etxc_vtxc_v
= XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell);
= XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell,nspin2,domag,domag_z);
et2 = std::get<0>(etxc_vtxc_v);
vt2 = std::get<1>(etxc_vtxc_v);
v2 = std::get<2>(etxc_vtxc_v);
Expand Down Expand Up @@ -130,6 +131,12 @@ class XCTest_VXC_Libxc : public XCTest

void SetUp()
{
// Define variables for parameters
int nspin1 = 1;
int nspin2 = 2;
bool domag = false;
bool domag_z = false;

ModulePW::PW_Basis rhopw;
UnitCell ucell;
Charge chr;
Expand Down Expand Up @@ -173,16 +180,14 @@ class XCTest_VXC_Libxc : public XCTest

XC_Functional::set_xc_type("GGA_X_PBE+GGA_C_PBE");

PARAM.input.nspin = 1;
std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v
= XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell);
= XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell,nspin1,domag,domag_z);
et1 = std::get<0>(etxc_vtxc_v);
vt1 = std::get<1>(etxc_vtxc_v);
v1 = std::get<2>(etxc_vtxc_v);

PARAM.input.nspin = 2;
etxc_vtxc_v
= XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell);
= XC_Functional::v_xc(rhopw.nrxx,&chr,&ucell,nspin2,domag,domag_z);
et2 = std::get<0>(etxc_vtxc_v);
vt2 = std::get<1>(etxc_vtxc_v);
v2 = std::get<2>(etxc_vtxc_v);
Expand Down Expand Up @@ -228,6 +233,10 @@ class XCTest_VXC_meta : public XCTest

void SetUp()
{
// Define variables for parameters
int nspin1 = 1;
int nspin2 = 2;

ModulePW::PW_Basis rhopw;
UnitCell ucell;
Charge chr;
Expand Down Expand Up @@ -281,17 +290,15 @@ class XCTest_VXC_meta : public XCTest

XC_Functional::set_xc_type("SCAN");

PARAM.input.nspin = 1;
std::tuple<double, double, ModuleBase::matrix, ModuleBase::matrix> etxc_vtxc_v
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), rhopw.nrxx,ucell.omega,ucell.tpiba,&chr);
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), rhopw.nrxx,ucell.omega,ucell.tpiba,&chr,nspin1);
et1 = std::get<0>(etxc_vtxc_v);
vt1 = std::get<1>(etxc_vtxc_v);
v1 = std::get<2>(etxc_vtxc_v);
vtau1 = std::get<3>(etxc_vtxc_v);

PARAM.input.nspin = 2;
etxc_vtxc_v
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), rhopw.nrxx,ucell.omega,ucell.tpiba,&chr);
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), rhopw.nrxx,ucell.omega,ucell.tpiba,&chr,nspin2);
et2 = std::get<0>(etxc_vtxc_v);
vt2 = std::get<1>(etxc_vtxc_v);
v2 = std::get<2>(etxc_vtxc_v);
Expand Down
10 changes: 1 addition & 9 deletions source/source_hamilt/module_xc/test/xctest.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#ifndef XCTEST_H
#define XCTEST_H
#include "gtest/gtest.h"
#define private public
#include "source_io/module_parameter/parameter.h"
#undef private
class XCTest: public testing::Test
Comment thread
mohanchen marked this conversation as resolved.
{
public:
XCTest()
{
PARAM.input.basis_type = "";
PARAM.input.cal_force = 0;
PARAM.input.cal_stress = 0;
}
XCTest() {}
};
#endif
19 changes: 8 additions & 11 deletions source/source_hamilt/module_xc/xc_functional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,18 @@ void XC_Functional::set_xc_type(const std::string xc_func_in)
std::cerr << "\n OPTX untested please test,";
}

// if((func_type == 4 || func_type == 5) && PARAM.inp.basis_type == "pw")
// if((func_type == 4 || func_type == 5) && basis_type == "pw")
Comment thread
mohanchen marked this conversation as resolved.
// {
// ModuleBase::WARNING_QUIT("set_xc_type","hybrid functional not realized for planewave yet");
// }
if((func_type == 3 || func_type == 5) && PARAM.inp.nspin==4)
{
ModuleBase::WARNING_QUIT("set_xc_type","meta-GGA has not been implemented for nspin = 4 yet");
}

#ifndef __EXX
if((func_type == 4 || func_type == 5) && PARAM.inp.basis_type == "lcao")
{
ModuleBase::WARNING_QUIT("set_xc_type","compile with libri to use hybrid functional in lcao basis");
}
#endif
// Hybrid functional is now supported for both PW and LCAO basis
// #ifndef __EXX
Comment thread
mohanchen marked this conversation as resolved.
// if((func_type == 4 || func_type == 5) && basis_type == "lcao")
// {
// ModuleBase::WARNING_QUIT("set_xc_type","compile with libri to use hybrid functional in lcao basis");
// }
// #endif

#ifndef USE_LIBXC
if(xc_func == "SCAN" || xc_func == "HSE" || xc_func == "SCAN0"
Expand Down
11 changes: 9 additions & 2 deletions source/source_hamilt/module_xc/xc_functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class XC_Functional
static std::tuple<double, double, ModuleBase::matrix> v_xc(
const int &nrxx, // number of real-space grid
const Charge* const chr,
const UnitCell *ucell); // charge density
const UnitCell *ucell, // charge density
const int nspin,
const bool domag,
const bool domag_z);

//-------------------
// xc_functional.cpp
Expand Down Expand Up @@ -206,7 +209,11 @@ class XC_Functional
ModulePW::PW_Basis* rhopw,
const UnitCell* ucell,
std::vector<double>& stress_gga,
const bool is_stress = false);
const bool is_stress,
const int nspin,
const bool domag,
const bool domag_z);

template <typename T, typename Device,
typename Real = typename GetTypeReal<T>::type>

Expand Down
Loading
Loading