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
4 changes: 3 additions & 1 deletion source/source_lcao/force_stress_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
&gd,
two_center_bundle.overlap_orb_onsite.get(),
orb.cutoffs(),
&dftu);
&dftu,
PARAM.inp.nspin,
PARAM.inp.onsite_radius);

tmpu.cal_force_stress(isforce, isstress, force_u, stress_u);
}
Expand Down
8 changes: 6 additions & 2 deletions source/source_lcao/hamilt_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ HamiltLCAO<TK, TR>::HamiltLCAO(const UnitCell& ucell,
&grid_d,
two_center_bundle.overlap_orb_onsite.get(),
orb.cutoffs(),
p_dftu);
p_dftu,
PARAM.inp.nspin,
PARAM.inp.onsite_radius);
}
this->getOperator()->add(plus_u);
}
Expand Down Expand Up @@ -399,7 +401,9 @@ HamiltLCAO<TK, TR>::HamiltLCAO(const UnitCell& ucell,
&grid_d,
two_center_bundle.overlap_orb_onsite.get(),
orb.cutoffs(),
p_dftu);
p_dftu,
PARAM.inp.nspin,
PARAM.inp.onsite_radius);
}
this->getOperator()->add(plus_u);
}
Expand Down
13 changes: 7 additions & 6 deletions source/source_lcao/module_dftu/dftu_nao_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "source_base/tool_title.h"
#include "source_cell/module_neighbor/sltk_grid_driver.h"
#include "source_lcao/module_operator_lcao/operator_lcao.h"
#include "source_io/module_parameter/parameter.h"
#include "source_base/parallel_reduce.h"

// Include the free function implementations for force/stress in real space
Expand All @@ -18,7 +17,9 @@ hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::DFTU(HS_Matrix_K<TK>* hsk_in,
const Grid_Driver* GridD_in,
const TwoCenterIntegrator* intor,
const std::vector<double>& orb_cutoff,
Plus_U* p_dftu)
Plus_U* p_dftu,
const int nspin_in,
const double onsite_radius)
: hamilt::OperatorLCAO<TK, TR>(hsk_in, kvec_d_in, hR_in), intor_(intor), orb_cutoff_(orb_cutoff)
{
this->cal_type = calculation_type::lcao_dftu;
Expand All @@ -28,9 +29,9 @@ hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::DFTU(HS_Matrix_K<TK>* hsk_in,
assert(this->ucell != nullptr);
#endif
// initialize HR to allocate sparse Nonlocal matrix memory
this->initialize_HR(GridD_in);
this->initialize_HR(GridD_in, onsite_radius);
// set nspin
this->nspin = PARAM.inp.nspin;
this->nspin = nspin_in;
}

// destructor
Expand All @@ -41,7 +42,7 @@ hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::~DFTU()

// initialize_HR()
template <typename TK, typename TR>
void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driver* GridD)
void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driver* GridD, const double onsite_radius)
{
ModuleBase::TITLE("DFTU", "initialize_HR");
ModuleBase::timer::start("DFTU", "initialize_HR");
Expand Down Expand Up @@ -75,7 +76,7 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driver
// When equal, the theoretical value of matrix element is zero,
// but the calculated value is not zero due to the numerical error, which would lead to result changes.
if (this->ucell->cal_dtau(iat0, iat1, R_index1).norm() * this->ucell->lat0
< orb_cutoff_[T1] + PARAM.inp.onsite_radius)
< orb_cutoff_[T1] + onsite_radius)
{
is_adj[ad1] = true;
}
Expand Down
6 changes: 4 additions & 2 deletions source/source_lcao/module_dftu/dftu_nao_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class DFTU<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
const Grid_Driver* gridD_in,
const TwoCenterIntegrator* intor,
const std::vector<double>& orb_cutoff,
Plus_U* p_dftu);
Plus_U* p_dftu,
const int nspin_in,
const double onsite_radius);
~DFTU<OperatorLCAO<TK, TR>>();

/**
Expand Down Expand Up @@ -93,7 +95,7 @@ class DFTU<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
* the size of HR will not change in DFTU,
* because I don't want to expand HR larger than Nonlocal operator caused by DFTU
*/
void initialize_HR(const Grid_Driver* gridD_in);
void initialize_HR(const Grid_Driver* gridD_in, const double onsite_radius);

/**
* @brief calculate the <phi|alpha^I> overlap values and save them in this->nlm_tot
Expand Down
14 changes: 5 additions & 9 deletions source/source_lcao/module_dftu/test/dftu_lcao_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include <chrono>

// mock of DFTU
#define private public
#include "source_io/module_parameter/parameter.h"
#undef private
#include "../dftu_nao_op.h"
#include "source_lcao/module_dftu/dftu_nao.h"

Expand Down Expand Up @@ -99,8 +96,6 @@ class DFTUTest : public ::testing::Test
}
dftu.u_current = {U_test};
dftu.orbital_corr = {orbital_c_test};

PARAM.input.onsite_radius = 1.0;
}

void TearDown() override
Expand Down Expand Up @@ -147,13 +142,14 @@ class DFTUTest : public ::testing::Test
int my_rank = 0;
double U_test = 1.0;
int orbital_c_test = 2;
double onsite_radius_test = 1.0;
};

// using TEST_F to test DFTU
TEST_F(DFTUTest, constructHRd2d)
{
// test for nspin=1
PARAM.input.nspin = 1;
const int nspin = 1;
std::vector<ModuleBase::Vector3<double>> kvec_d_in(1, ModuleBase::Vector3<double>(0.0, 0.0, 0.0));
hamilt::HS_Matrix_K<double> hsk(paraV, true);
hsk.set_zero_hk();
Expand All @@ -167,7 +163,7 @@ TEST_F(DFTUTest, constructHRd2d)
}
std::chrono::high_resolution_clock::time_point start_time = std::chrono::high_resolution_clock::now();
hamilt::DFTU<hamilt::OperatorLCAO<double, double>>
op(&hsk, kvec_d_in, HR, ucell, &gd, &intor_, {1.0}, &dftu);
op(&hsk, kvec_d_in, HR, ucell, &gd, &intor_, {1.0}, &dftu, nspin, onsite_radius_test);
std::chrono::high_resolution_clock::time_point end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed_time
= std::chrono::duration_cast<std::chrono::duration<double>>(end_time - start_time);
Expand Down Expand Up @@ -219,7 +215,7 @@ TEST_F(DFTUTest, constructHRd2d)
TEST_F(DFTUTest, constructHRd2cd)
{
// test for nspin=2
PARAM.input.nspin = 2;
const int nspin = 2;
std::vector<ModuleBase::Vector3<double>> kvec_d_in(2, ModuleBase::Vector3<double>(0.0, 0.0, 0.0));
hamilt::HS_Matrix_K<std::complex<double>> hsk(paraV, true);
hsk.set_zero_hk();
Expand All @@ -232,7 +228,7 @@ TEST_F(DFTUTest, constructHRd2cd)
HR->get_wrapper()[i] = 0.0;
}
hamilt::DFTU<hamilt::OperatorLCAO<std::complex<double>, double>>
op(&hsk, kvec_d_in, HR, ucell, &gd, &intor_, {1.0}, &dftu);
op(&hsk, kvec_d_in, HR, ucell, &gd, &intor_, {1.0}, &dftu, nspin, onsite_radius_test);
op.contributeHR();
// check the occupations of dftu for spin-up
for (int iat = 0; iat < test_size; iat++)
Expand Down
8 changes: 2 additions & 6 deletions source/source_lcao/module_dftu/test/dftu_pw_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "gtest/gtest.h"
#include <complex>
#include <vector>
#define private public
#include "source_io/module_parameter/parameter.h"
#undef private
#include "source_base/matrix.h"
#include "source_pw/module_pwdft/dftu_base_tools.h"

Expand Down Expand Up @@ -40,15 +37,14 @@ TEST_F(DftuPwTest, EnergyWeightsAllNspin)
struct Case { int nspin; double expected_weight; double expected_diag; };
Case cases[] = {{1, 1.0, 0.5}, {2, 0.5, 0.5}, {4, 0.25, 1.0}};
for (const auto& c : cases) {
PARAM.input.nspin = c.nspin;
double weight_eu = 1;
switch (PARAM.inp.nspin) {
switch (c.nspin) {
case 1: weight_eu = 1.0; break;
case 2: weight_eu = 0.5; break;
case 4: weight_eu = 0.25; break;
default: break;
}
const double diag_coeff = PARAM.inp.nspin == 4 ? 1.0 : 0.5;
const double diag_coeff = c.nspin == 4 ? 1.0 : 0.5;
EXPECT_DOUBLE_EQ(weight_eu, c.expected_weight);
EXPECT_DOUBLE_EQ(diag_coeff, c.expected_diag);
}
Expand Down
Loading