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
2 changes: 2 additions & 0 deletions source/module_cell/test/unitcell_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ TEST_F(UcellTest, CalUx1)
ucell->atoms[0].m_loc_[0].set(0, -1, 0);
ucell->atoms[1].m_loc_[0].set(1, 1, 1);
ucell->atoms[1].m_loc_[1].set(0, 0, 0);
PARAM.input.nspin = 4;
elecstate::cal_ux(*ucell);
EXPECT_FALSE(ucell->magnet.lsign_);
EXPECT_DOUBLE_EQ(ucell->magnet.ux_[0], 0);
Expand All @@ -1051,6 +1052,7 @@ TEST_F(UcellTest, CalUx2)
ucell->atoms[1].m_loc_[0].set(1, 1, 1);
ucell->atoms[1].m_loc_[1].set(0, 0, 0);
//(0,0,0) is also parallel to (1,1,1)
PARAM.input.nspin = 4;
elecstate::cal_ux(*ucell);
EXPECT_TRUE(ucell->magnet.lsign_);
EXPECT_NEAR(ucell->magnet.ux_[0], 0.57735, 1e-5);
Expand Down
6 changes: 6 additions & 0 deletions source/module_elecstate/cal_ux.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#include "cal_ux.h"
#include "module_parameter/parameter.h"

namespace elecstate {

void cal_ux(UnitCell& ucell) {
if (PARAM.inp.nspin != 4)
{
return;
}

double amag, uxmod;
int starting_it = 0;
int starting_ia = 0;
Expand Down
1 change: 1 addition & 0 deletions source/module_elecstate/cal_ux.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace elecstate {

// Only for npsin = 4
void cal_ux(UnitCell& ucell);

bool judge_parallel(double a[3], ModuleBase::Vector3<double> b);
Expand Down
10 changes: 2 additions & 8 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
// rho1 and rho2 are the same rho.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);

//! update the potentials by using new electron charge density
this->pelec->pot->update_from_charge(this->pelec->charge, &ucell);
Expand Down Expand Up @@ -841,10 +838,7 @@ void ESolver_KS_LCAO<TK, TR>::update_pot(UnitCell& ucell, const int istep, const

if (!this->conv_esolver)
{
if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);
this->pelec->pot->update_from_charge(this->pelec->charge, &ucell);
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
}
Expand Down
5 changes: 1 addition & 4 deletions source/module_esolver/esolver_ks_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,7 @@ void ESolver_KS_LCAO_TDDFT::update_pot(UnitCell& ucell, const int istep, const i
// Calculate new potential according to new Charge Density
if (!this->conv_esolver)
{
if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);
this->pelec->pot->update_from_charge(this->pelec->charge, &ucell);
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
}
Expand Down
10 changes: 2 additions & 8 deletions source/module_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,7 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)

//! cal_ux should be called before init_scf because
//! the direction of ux is used in noncoline_rho
if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);

//! calculate the total local pseudopotential in real space
this->pelec->init_scf(istep, this->sf.strucFac, this->ppcell.numeric, ucell.symm, (void*)this->pw_wfc);
Expand Down Expand Up @@ -472,10 +469,7 @@ void ESolver_KS_PW<T, Device>::update_pot(UnitCell& ucell, const int istep, cons
{
if (!this->conv_esolver)
{
if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);
this->pelec->pot->update_from_charge(this->pelec->charge, &ucell);
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
#ifdef __MPI
Expand Down
5 changes: 1 addition & 4 deletions source/module_esolver/esolver_of.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell)
void ESolver_OF::update_potential(UnitCell& ucell)
{
// (1) get dL/dphi
if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);

this->pelec->pot->update_from_charge(pelec->charge, &ucell); // Hartree + XC + external
this->kinetic_potential(pelec->charge->rho,
Expand Down
10 changes: 2 additions & 8 deletions source/module_esolver/esolver_of_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ void ESolver_OF::cal_potential(double* ptemp_phi, double* rdLdphi, UnitCell& uce
}
}

if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);
this->pelec->pot->update_from_charge(this->ptemp_rho_, &ucell);
ModuleBase::matrix& vr_eff = this->pelec->pot->get_effective_v();

Expand Down Expand Up @@ -173,10 +170,7 @@ void ESolver_OF::cal_dEdtheta(double** ptemp_phi, Charge* temp_rho, UnitCell& uc
{
double* dphi_dtheta = new double[this->pw_rho->nrxx];

if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);
this->pelec->pot->update_from_charge(temp_rho, &ucell);
ModuleBase::matrix& vr_eff = this->pelec->pot->get_effective_v();

Expand Down
5 changes: 1 addition & 4 deletions source/module_esolver/lcao_before_scf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
// cal_ux should be called before init_scf because
// the direction of ux is used in noncoline_rho
//=========================================================
if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);

// Peize Lin add 2016-12-03
#ifdef __EXX // set xc type before the first cal of xc in pelec->init_scf
Expand Down
5 changes: 1 addition & 4 deletions source/module_esolver/lcao_others.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,7 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
// cal_ux should be called before init_scf because
// the direction of ux is used in noncoline_rho
//=========================================================
if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell);
}
elecstate::cal_ux(ucell);

// pelec should be initialized before these calculations
this->pelec->init_scf(istep, this->sf.strucFac, this->ppcell.numeric, ucell.symm);
Expand Down
5 changes: 1 addition & 4 deletions source/module_hamilt_pw/hamilt_pwdft/forces_cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ void Forces<FPTYPE, Device>::cal_force_cc(ModuleBase::matrix& forcecc,
}
else
{
if (PARAM.inp.nspin == 4)
{
elecstate::cal_ux(ucell_in);
}
elecstate::cal_ux(ucell_in);
const auto etxc_vtxc_v = XC_Functional::v_xc(rho_basis->nrxx, chr, &ucell_in);

// etxc = std::get<0>(etxc_vtxc_v);
Expand Down
5 changes: 1 addition & 4 deletions source/module_hamilt_pw/hamilt_pwdft/stress_func_cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ void Stress_Func<FPTYPE, Device>::stress_cc(ModuleBase::matrix& sigma,
}
else
{
if(PARAM.inp.nspin==4)
{
elecstate::cal_ux(GlobalC::ucell);
}
elecstate::cal_ux(GlobalC::ucell);
const auto etxc_vtxc_v = XC_Functional::v_xc(rho_basis->nrxx, chr, &GlobalC::ucell);
// etxc = std::get<0>(etxc_vtxc_v); // may delete?
// vtxc = std::get<1>(etxc_vtxc_v); // may delete?
Expand Down
Loading