Skip to content

Commit a05ee08

Browse files
linpeizePeizeLin
andauthored
Feature: add class PotXC_FDM and Pot_Cosikr (#6962)
Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
1 parent 2087308 commit a05ee08

File tree

6 files changed

+185
-0
lines changed

6 files changed

+185
-0
lines changed

source/source_estate/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ list(APPEND objects
1818
module_pot/pot_ml_exx.cpp
1919
module_pot/pot_ml_exx_label.cpp
2020
module_pot/pot_sep.cpp
21+
module_pot/pot_xc_fdm.cpp
22+
module_pot/pot_cosikr.cpp
2123
module_charge/chgmixing.cpp
2224
module_charge/charge.cpp
2325
module_charge/charge_init.cpp
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2025-10-05
4+
//=======================
5+
6+
#include "pot_cosikr.h"
7+
8+
#include <cmath>
9+
10+
namespace elecstate
11+
{
12+
13+
Pot_Cosikr::Pot_Cosikr(
14+
const ModulePW::PW_Basis* rho_basis_in,
15+
const ModuleBase::Vector3<double> &kvec_d_in,
16+
const std::vector<double> &phase_in,
17+
const std::vector<double> &amplitude_in)
18+
:kvec_d(kvec_d_in),
19+
phase(phase_in),
20+
amplitude(amplitude_in)
21+
{
22+
this->rho_basis_ = rho_basis_in;
23+
this->dynamic_mode = true;
24+
this->fixed_mode = false;
25+
}
26+
27+
28+
void Pot_Cosikr::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix &v_eff)
29+
{
30+
ModuleBase::TITLE("Pot_Cosikr", "cal_v_eff");
31+
ModuleBase::timer::tick("Pot_Cosikr", "cal_veff");
32+
assert(v_eff.nr == this->phase.size());
33+
assert(v_eff.nr == this->amplitude.size());
34+
int ir = 0;
35+
for (int ix = 0; ix < this->rho_basis_->nx; ++ix)
36+
{
37+
const double phase_x = this->kvec_d.x * ix / this->rho_basis_->nx;
38+
for (int iy = 0; iy < this->rho_basis_->ny; ++iy)
39+
{
40+
const double phase_xy = phase_x + this->kvec_d.y * iy / this->rho_basis_->ny;
41+
for (int iz = this->rho_basis_->startz_current; iz < this->rho_basis_->startz_current + this->rho_basis_->nplane; ++iz)
42+
{
43+
const double phase_xyz = phase_xy + this->kvec_d.z * iz / this->rho_basis_->nz;
44+
for(int is=0; is<v_eff.nr; ++is)
45+
v_eff(is,ir) += this->amplitude[is] * std::cos((phase_xyz + this->phase[is]) * ModuleBase::TWO_PI);
46+
++ir;
47+
}
48+
}
49+
}
50+
ModuleBase::timer::tick("Pot_Cosikr", "cal_veff");
51+
}
52+
53+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2025-10-05
4+
//=======================
5+
6+
#ifndef POT_COSIKR_H
7+
#define POT_COSIKR_H
8+
9+
#include "pot_base.h"
10+
#include "source_base/vector3.h"
11+
12+
13+
namespace elecstate
14+
{
15+
16+
// ampitude * cos( 2pi*( k * r + phase ) )
17+
class Pot_Cosikr : public PotBase
18+
{
19+
public:
20+
Pot_Cosikr(
21+
const ModulePW::PW_Basis* rho_basis_in,
22+
const ModuleBase::Vector3<double> &kvec_d_in,
23+
const std::vector<double> &phase_in,
24+
const std::vector<double> &amplitude_in);
25+
26+
void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix &v_eff) override;
27+
28+
private:
29+
const ModuleBase::Vector3<double> kvec_d;
30+
const std::vector<double> phase;
31+
const std::vector<double> amplitude;
32+
};
33+
34+
}
35+
36+
#endif

source/source_estate/module_pot/pot_xc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "pot_xc.h"
22

33
#include "source_base/timer.h"
4+
#include "source_hamilt/module_xc/xc_functional.h"
45

56
#ifdef USE_LIBXC
67
#include "source_hamilt/module_xc/xc_functional_libxc.h"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2025-10-01
4+
//=======================
5+
6+
#include "pot_xc_fdm.h"
7+
#include "source_hamilt/module_xc/xc_functional.h"
8+
9+
namespace elecstate
10+
{
11+
12+
PotXC_FDM::PotXC_FDM(
13+
const ModulePW::PW_Basis* rho_basis_in,
14+
const Charge*const chg_0_in,
15+
const UnitCell*const ucell)
16+
: chg_0(chg_0_in)
17+
{
18+
this->rho_basis_ = rho_basis_in;
19+
this->dynamic_mode = true;
20+
this->fixed_mode = false;
21+
22+
const std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v_0
23+
= XC_Functional::v_xc(this->chg_0->nrxx, this->chg_0, ucell);
24+
this->v_xc_0 = std::get<2>(etxc_vtxc_v_0);
25+
}
26+
27+
void PotXC_FDM::cal_v_eff(
28+
const Charge*const chg_1,
29+
const UnitCell*const ucell,
30+
ModuleBase::matrix& v_eff)
31+
{
32+
ModuleBase::TITLE("PotXC_FDM", "cal_veff");
33+
ModuleBase::timer::tick("PotXC_FDM", "cal_veff");
34+
35+
assert(this->chg_0->nrxx == chg_1->nrxx);
36+
assert(this->chg_0->nspin == chg_1->nspin);
37+
38+
Charge chg_01;
39+
chg_01.set_rhopw(chg_1->rhopw);
40+
chg_01.allocate(chg_1->nspin, chg_01.kin_density());
41+
42+
for(int ir=0; ir<chg_01.nrxx; ++ir)
43+
{
44+
for(int is=0; is<chg_01.nspin; ++is)
45+
{ chg_01.rho[is][ir] = chg_0->rho[is][ir] + chg_1->rho[is][ir]; }
46+
chg_01.rho_core[ir] = chg_0->rho_core[ir] + chg_1->rho_core[ir];
47+
}
48+
49+
const std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v_01
50+
= XC_Functional::v_xc(chg_01.nrxx, &chg_01, ucell);
51+
const ModuleBase::matrix &v_xc_01 = std::get<2>(etxc_vtxc_v_01);
52+
53+
v_eff += v_xc_01 - this->v_xc_0;
54+
55+
ModuleBase::timer::tick("PotXC_FDM", "cal_veff");
56+
}
57+
58+
} // namespace elecstate
59+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2025-10-01
4+
//=======================
5+
6+
#ifndef POTXC_FDM_H
7+
#define POTXC_FDM_H
8+
9+
#include "pot_base.h"
10+
11+
namespace elecstate
12+
{
13+
14+
class PotXC_FDM : public PotBase
15+
{
16+
public:
17+
18+
PotXC_FDM(
19+
const ModulePW::PW_Basis* rho_basis_in,
20+
const Charge*const chg_0_in,
21+
const UnitCell*const ucell);
22+
23+
void cal_v_eff(
24+
const Charge*const chg_1,
25+
const UnitCell*const ucell,
26+
ModuleBase::matrix& v_eff) override;
27+
28+
const Charge*const chg_0 = nullptr;
29+
ModuleBase::matrix v_xc_0;
30+
};
31+
32+
} // namespace elecstate
33+
34+
#endif

0 commit comments

Comments
 (0)