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
6 changes: 5 additions & 1 deletion src/Control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ void Control::print(std::ostream& os)
<< conv_tol << std::endl;
os << std::fixed;
os << " Density matrix mixing = " << dm_mix << std::endl;
os << " Density matrix tol = " << dm_tol << std::endl;
if (DMEigensolver() == DMEigensolverType::Eigensolver)
{
os << " Density matrix computation algorithm = "
Expand Down Expand Up @@ -439,7 +440,7 @@ void Control::sync(void)
memset(&int_buffer[0], 0, size_int_buffer * sizeof(int));
}

const short size_float_buffer = 43;
const short size_float_buffer = 44;
float* float_buffer = new float[size_float_buffer];
if (mype_ == 0)
{
Expand Down Expand Up @@ -485,6 +486,7 @@ void Control::sync(void)
float_buffer[40] = threshold_eigenvalue_gram_quench_;
float_buffer[41] = pair_mlwf_distance_threshold_;
float_buffer[42] = e0_;
float_buffer[43] = dm_tol;
}
else
{
Expand Down Expand Up @@ -680,6 +682,7 @@ void Control::sync(void)
threshold_eigenvalue_gram_quench_ = float_buffer[40];
pair_mlwf_distance_threshold_ = float_buffer[41];
e0_ = float_buffer[42];
dm_tol = float_buffer[43];
max_electronic_steps_loose_ = max_electronic_steps;

delete[] short_buffer;
Expand Down Expand Up @@ -1720,6 +1723,7 @@ void Control::setOptions(const boost::program_options::variables_map& vm)
lrs_extrapolation = 10;

dm_mix = vm["DensityMatrix.mixing"].as<float>();
dm_tol = vm["DensityMatrix.tol"].as<float>();
dm_inner_steps = vm["DensityMatrix.nb_inner_it"].as<short>();
dm_use_old_ = vm["DensityMatrix.use_old"].as<bool>() ? 1 : 0;
str = vm["DensityMatrix.algo"].as<std::string>();
Expand Down
34 changes: 19 additions & 15 deletions src/MVPSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ MVPSolver<OrbitalsType, MatrixType>::MVPSolver(MPI_Comm comm, std::ostream& os,
Electrostatic* electrostat, MGmol<OrbitalsType>* mgmol_strategy,
const int numst, const double kbT,
const std::vector<std::vector<int>>& global_indexes,
const short n_inner_steps, const double mixing, const bool use_old_dm)
const short n_inner_steps, const double mixing, const double tol_de0,
const bool use_old_dm)
: comm_(comm),
os_(os),
n_inner_steps_(n_inner_steps),
use_old_dm_(use_old_dm),
ions_(ions),
numst_(numst),
mixing_(mixing)
mixing_(mixing),
tol_de0_(tol_de0)
{
Control& ct = *(Control::instance());
if (onpe0 && ct.verbose > 0)
Expand Down Expand Up @@ -208,7 +210,6 @@ int MVPSolver<OrbitalsType, MatrixType>::solve(OrbitalsType& orbitals)

kbpsi.computeHvnlMatrix(&kbpsi, ions_, h11_nl);

const double tol_de0 = 1.e-12;
for (int inner_it = 0; inner_it < n_inner_steps_; inner_it++)
{
if (onpe0 && ct.verbose > 1)
Expand Down Expand Up @@ -268,30 +269,33 @@ int MVPSolver<OrbitalsType, MatrixType>::solve(OrbitalsType& orbitals)
MatrixType delta_dm("delta_dm", numst_, numst_);
delta_dm = target;
delta_dm -= dmInit;

double de0 = evaluateDerivative(dmInit, delta_dm, ts0);

// check for convergence
if (std::abs(de0) < tol_de0_ && inner_it > 0)
{
if (onpe0 && ct.verbose > 0)
std::cout << "MVP: de0 = " << de0
<< ", convergence achieved" << std::endl;
break;
}

double beta = 0.;
if (mixing_ > 0.)
{
beta = mixing_;
if (onpe0 && ct.verbose > 1)
if (onpe0 && ct.verbose > 0)
{
os_ << "MVP with beta = " << beta << std::endl;
if (ct.verbose > 1)
os_ << "MVP with beta = " << beta << std::endl;
os_ << std::setprecision(12);
os_ << std::fixed << "MVP inner iteration " << inner_it
<< ", E0=" << e0 << std::endl;
}
}
else
{
double de0 = evaluateDerivative(dmInit, delta_dm, ts0);

if (std::abs(de0) < tol_de0 && inner_it > 0)
{
if (onpe0 && ct.verbose > 0)
std::cout << "MVP: de0 = " << de0
<< ", convergence achieved" << std::endl;
break;
}

//
// evaluate free energy at beta=1
//
Expand Down
8 changes: 7 additions & 1 deletion src/MVPSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class MVPSolver
int numst_;
double mixing_;

/*!
* tolerance on energy slope in inner iterations
*/
double tol_de0_;

Rho<OrbitalsType>* rho_;
Energy<OrbitalsType>* energy_;
Electrostatic* electrostat_;
Expand All @@ -57,7 +62,8 @@ class MVPSolver
Electrostatic* electrostat, MGmol<OrbitalsType>* mgmol_strategy,
const int numst, const double kbT,
const std::vector<std::vector<int>>& global_indexes,
const short n_inner_steps, const double mixing, const bool use_old_dm);
const short n_inner_steps, const double mixing, const double tol_de0,
const bool use_old_dm);
~MVPSolver();

int solve(OrbitalsType& orbitals);
Expand Down
2 changes: 1 addition & 1 deletion src/MVP_DMStrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int MVP_DMStrategy<OrbitalsType, MatrixType>::update(OrbitalsType& orbitals)

MVPSolver<OrbitalsType, MatrixType> solver(comm_, os_, ions_, rho_, energy_,
electrostat_, mgmol_strategy_, ct.numst, ct.occ_width, global_indexes_,
ct.dm_inner_steps, ct.dm_mix, use_old_dm_);
ct.dm_inner_steps, ct.dm_mix, ct.dm_tol, use_old_dm_);

return solver.solve(orbitals);
}
Expand Down
4 changes: 3 additions & 1 deletion src/read_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ int read_config(int argc, char** argv, po::variables_map& vm,
po::value<short>()->default_value(0),
"Flag for computing new centers from extrapolated orbitals.")(
"DensityMatrix.mixing", po::value<float>()->default_value(-1.),
"Mixing coefficient for Density Matrix")("DensityMatrix.solver",
"Mixing coefficient for Density Matrix")("DensityMatrix.tol",
po::value<float>()->default_value(1.e-12),
"Tolerance for Density Matrix convergence")("DensityMatrix.solver",
po::value<std::string>()->default_value("Mixing"),
"Algorithm for updating Density Matrix: Mixing, MVP, HMVP")(
"DensityMatrix.nb_inner_it", po::value<short>()->default_value(3),
Expand Down