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
63 changes: 42 additions & 21 deletions source/source_base/module_mixing/broyden_mixing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ void Broyden_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function<double
}
}
}
double* work = new double[ndim_cal_dF]; // workspace
int* iwork = new int[ndim_cal_dF]; // ipiv
double* work = new double[std::max(1, 3 * ndim_cal_dF - 1)]; // workspace
char uu = 'U';
char vv = 'V';
int info = 0;
int m = 1;
int lwork = std::max(1, 3 * ndim_cal_dF - 1);
// gamma means the coeficients for mixing
// but now gamma store <dFi|Fm>, namely c
std::vector<double> gamma(ndim_cal_dF);
Expand All @@ -155,23 +155,45 @@ void Broyden_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function<double
gamma[i] = inner_product(dFi, FP_F);
}

// solve aG = c
dsysv_(&uu,
&ndim_cal_dF,
&m,
beta_tmp.c,
&ndim_cal_dF,
iwork,
gamma.data(),
&ndim_cal_dF,
work,
&ndim_cal_dF,
&info);

if (info != 0)
{
ModuleBase::WARNING_QUIT("Charge_Mixing", "Error when DSYSV.");
}
// solve aG = c with a truncated pseudo-inverse
std::vector<double> eigenvalues(ndim_cal_dF);
dsyev_(&vv,
&uu,
&ndim_cal_dF,
beta_tmp.c,
&ndim_cal_dF,
eigenvalues.data(),
work,
&lwork,
&info);
if (info != 0)
{
ModuleBase::WARNING_QUIT("Charge_Mixing", "Error when DSYEV.");
}
std::vector<double> gamma_eigen(ndim_cal_dF);
for (int i = 0; i < ndim_cal_dF; ++i)
{
for (int j = 0; j < ndim_cal_dF; ++j)
{
gamma_eigen[i] += beta_tmp(i, j) * gamma[j];
}
if (eigenvalues[i] > 1.0e-12 * eigenvalues[ndim_cal_dF - 1])
{
gamma_eigen[i] /= eigenvalues[i];
}
else
{
gamma_eigen[i] = 0.0;
}
}
std::fill(gamma.begin(), gamma.end(), 0.0);
for (int i = 0; i < ndim_cal_dF; ++i)
{
for (int j = 0; j < ndim_cal_dF; ++j)
{
gamma[i] += beta_tmp(j, i) * gamma_eigen[j];
}
}

// after solving, gamma store the coeficients for mixing
coef[mdata.start] = 1 + gamma[dFindex_move(0)];
Expand All @@ -182,7 +204,6 @@ void Broyden_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function<double
coef[mdata.index_move(-ndim_cal_dF)] = -gamma[dFindex_move(-ndim_cal_dF + 1)];

delete[] work;
delete[] iwork;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tests/05_rtTDDFT/13_NO_Taylor_TDDFT/INPUT
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ks_solver scalapack_gvx
mixing_type broyden
mixing_beta 0.7
mixing_gg0 0.0
scf_thr 1.0e-6
scf_thr 1.0e-10

cal_stress 1
stress_thr 1e-6
Expand Down
4 changes: 2 additions & 2 deletions tests/05_rtTDDFT/13_NO_Taylor_TDDFT/result.ref
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
etotref 18.66922016480692
etotperatomref 9.3346100824
etotref 18.6691608970
etotperatomref 9.3345804485
totalforceref 82.531062
totalstressref 170.582088
totaltimeref 1.54
Loading