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
27 changes: 27 additions & 0 deletions src/ProjectedMatrices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -745,13 +745,40 @@ int ProjectedMatrices<MatrixType>::writeDM(HDFrestart& h5f_file)
return dm_->write(h5f_file, name);
}

template <class MatrixType>
int ProjectedMatrices<MatrixType>::writeSavedDM(HDFrestart& h5f_file)
{
std::string name("/Density_Matrix_WF");

ReplicatedWorkSpace<double>& wspace(
ReplicatedWorkSpace<double>::instance());

const MatrixType* matrix = mat_X_old_.get();
wspace.initSquareMatrix(*matrix);

DISTMATDTYPE* work_matrix = wspace.square_matrix();

hid_t file_id = h5f_file.file_id();
return mgmol_tools::write_matrix(file_id, name, work_matrix, dim_);
}

template <class MatrixType>
int ProjectedMatrices<MatrixType>::readDM(HDFrestart& h5f_file)
{
std::string name("/Density_Matrix");
return dm_->read(h5f_file, name);
}

template <class MatrixType>
int ProjectedMatrices<MatrixType>::readWFDM(HDFrestart& h5f_file)
{
MGmol_MPI& mmpi = *(MGmol_MPI::instance());
mmpi.barrier();
if (mmpi.PE0()) std::cout << "ProjectedMatrices::readWFDM..." << std::endl;
std::string name("/Density_Matrix_WF");
return dm_->read(h5f_file, name);
}

template <class MatrixType>
void ProjectedMatrices<MatrixType>::printEigenvalues(std::ostream& os) const
{
Expand Down
2 changes: 2 additions & 0 deletions src/ProjectedMatrices.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ class ProjectedMatrices : public ProjectedMatricesInterface
double computeEntropyWithCheb(const double kbt);
double checkCond(const double tol, const bool flag = true) override;
int writeDM(HDFrestart& h5f_file) override;
int writeSavedDM(HDFrestart& h5f_file);
int readDM(HDFrestart& h5f_file) override;
int readWFDM(HDFrestart& h5f_file);
void printEigenvalues(std::ostream& os) const;
void updateDM(const int iterative_index) override;
void updateDMwithEigenstates(const int iterative_index);
Expand Down
16 changes: 16 additions & 0 deletions src/ProjectedMatricesInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ class ProjectedMatricesInterface : public ChebyshevApproximationFunction

return 0;
}
virtual int readWFDM(HDFrestart& h5f_file)
{
(void)h5f_file;

exitWithErrorMessage("readWFDM");

return 0;
}
virtual int writeDM(HDFrestart& h5f_file)
{
(void)h5f_file;
Expand All @@ -281,6 +289,14 @@ class ProjectedMatricesInterface : public ChebyshevApproximationFunction

return 0;
}
virtual int writeSavedDM(HDFrestart& h5f_file)
{
(void)h5f_file;

exitWithErrorMessage("writeSavedDM");

return 0;
}
virtual void updateDMwithChebApproximation(const int iterative_index)
{
(void)iterative_index;
Expand Down
18 changes: 18 additions & 0 deletions src/md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ int MGmol<OrbitalsType>::dumpMDrestartFile(OrbitalsType& orbitals, Ions& ions,
<< std::endl;
return ierr;
}

// write DM associated with non-extrapolated wavefunctions
// (last computed solution of KS equations)
proj_matrices_->writeSavedDM(h5file);
}

ierr = h5file.close();
Expand Down Expand Up @@ -579,6 +583,13 @@ void MGmol<OrbitalsType>::md(OrbitalsType** orbitals, Ions& ions)
lrs_->clearOldCenters();
}

// save DM for possible restart write
// note: extrapolation is going to modify it!
if ((ct.out_restart_info > 2)
&& (((md_iteration_ % ct.checkpoint) == 0)
|| (mdstep == ct.num_MD_steps)))
proj_matrices_->saveDM();

preWFextrapolation();

if (ct.dt > 0.
Expand Down Expand Up @@ -656,6 +667,7 @@ void MGmol<OrbitalsType>::md(OrbitalsType** orbitals, Ions& ions)
template <class OrbitalsType>
void MGmol<OrbitalsType>::loadRestartFile(const std::string filename)
{
if (onpe0) std::cout << "loadRestartFile..." << std::endl;
MGmol_MPI& mmpi(*(MGmol_MPI::instance()));
Control& ct = *(Control::instance());
Mesh* mymesh = Mesh::instance();
Expand All @@ -678,6 +690,12 @@ void MGmol<OrbitalsType>::loadRestartFile(const std::string filename)

global_exit(0);
}
if (!ct.fullyOccupied())
{
// overwrite DM with restart data in dataset Density_Matrix_WF
if (h5file.checkDataExists("Density_Matrix_WF"))
ierr = proj_matrices_->readWFDM(h5file);
}

ierr = h5file.close();
mmpi.allreduce(&ierr, 1, MPI_MIN);
Expand Down
2 changes: 1 addition & 1 deletion src/restart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int MGmol<OrbitalsType>::write_hdf5(HDFrestart& h5f_file,

if (!ct.fullyOccupied())
{
int ierr = proj_matrices_->writeDM(h5f_file);
ierr = proj_matrices_->writeDM(h5f_file);
if (ierr < 0) return ierr;
}
if (ct.isLocMode()
Expand Down