Skip to content

Commit 8329a97

Browse files
committed
change magnetism.cpp
1 parent 088428c commit 8329a97

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

source/module_elecstate/elecstate_energy.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ double ElecState::cal_delta_eband(const UnitCell& ucell) const
137137
{
138138
v_ofk = this->pot->get_effective_vofk(0);
139139
// cause in the get_effective_vofk, the func will return nullptr
140-
assert(v_ofk!=nullptr);
141-
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
140+
if(v_ofk!=nullptr)
142141
{
143-
deband_aux -= this->charge->kin_r[0][ir] * v_ofk[ir];
142+
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
143+
{
144+
deband_aux -= this->charge->kin_r[0][ir] * v_ofk[ir];
145+
}
144146
}
145147
}
146148

@@ -154,10 +156,12 @@ double ElecState::cal_delta_eband(const UnitCell& ucell) const
154156
if (v_ofk_flag)
155157
{
156158
v_ofk = this->pot->get_effective_vofk(1);
157-
assert(v_ofk!=nullptr);
158-
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
159+
if(v_ofk!=nullptr)
159160
{
160-
deband_aux -= this->charge->kin_r[1][ir] * v_ofk[ir];
161+
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)
162+
{
163+
deband_aux -= this->charge->kin_r[1][ir] * v_ofk[ir];
164+
}
161165
}
162166
}
163167
}

source/module_elecstate/magnetism.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55

66
Magnetism::Magnetism()
77
{
8+
tot_magnetization = 0.0;
9+
abs_magnetization = 0.0;
10+
std::fill(tot_magnetization_nc, tot_magnetization_nc + 3, 0.0);
11+
std::fill(ux_, ux_ + 3, 0.0);
812
}
913

1014
Magnetism::~Magnetism()
1115
{
16+
delete[] start_magnetization;
1217
}
1318

1419
void Magnetism::compute_magnetization(const double& omega,

source/module_elecstate/magnetism.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class Magnetism
1717
double *start_magnetization=nullptr;
1818

1919
// tot_magnetization : majority spin - minority spin (nelup - neldw).
20-
double tot_magnetization=0.0;
20+
double tot_magnetization;
2121
double tot_magnetization_nc[3]={0.0};
22-
double abs_magnetization=0.0;
22+
double abs_magnetization;
2323

2424
void compute_magnetization(const double& omega,
2525
const int& nrxx,

source/module_elecstate/module_charge/charge.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,10 @@ void Charge::atomic_rho(const int spin_number_need,
326326
{
327327
// check the start magnetization
328328
const int startmag_type = [&]() -> int {
329-
if (ucell.magnet.start_magnetization[it] != 0.0) {
329+
if (ucell.magnet.start_magnetization[it] != 0.0)
330+
{
330331
return 1;
331-
}
332+
}
332333
return 2;
333334
}();
334335
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_warning, "startmag_type", startmag_type);

0 commit comments

Comments
 (0)