Skip to content

Commit

Permalink
MGmol::loadOrbitalFromRestartFile
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer2368 committed Apr 19, 2024
1 parent 85df951 commit 7c728e1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/MGmol.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ class MGmol : public MGmolInterface
{
forces_->force(orbitals, ions);
}

OrbitalsType* loadOrbitalFromRestartFile(const std::string filename);
};
// Instantiate static variables here to avoid clang warnings
template <class OrbitalsType>
Expand Down
57 changes: 57 additions & 0 deletions src/md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,5 +686,62 @@ void MGmol<OrbitalsType>::md(OrbitalsType** orbitals, Ions& ions)
delete orbitals_extrapol_;
}

template <class OrbitalsType>
OrbitalsType* MGmol<OrbitalsType>::loadOrbitalFromRestartFile(const std::string filename)
{
MGmol_MPI& mmpi(*(MGmol_MPI::instance()));
Control& ct = *(Control::instance());
Mesh* mymesh = Mesh::instance();
const pb::PEenv& myPEenv = mymesh->peenv();
const pb::Grid& mygrid = mymesh->grid();
// const unsigned gdim[3] = { mygrid.gdim(0), mygrid.gdim(1), mygrid.gdim(2) };

assert(ct.restart_info > 2);

HDFrestart h5file(filename, myPEenv, ct.out_restart_file_type);

OrbitalsType *restart_orbitals = new OrbitalsType("ForLoading", *current_orbitals_, false);

// TODO(kevin): do we need to copy the current orbitals?
if (!orbitals_extrapol_->getRestartData(*restart_orbitals))
restart_orbitals->assign(*current_orbitals_);

int ierr = restart_orbitals->read_func_hdf5(h5file);
mmpi.allreduce(&ierr, 1, MPI_MIN);

if (ierr < 0)
{
if (onpe0)
(*MPIdata::serr)
<< "loadRestartFile: cannot read ...restart_orbitals..."
<< std::endl;
return NULL;
}

ierr = h5file.close();
mmpi.allreduce(&ierr, 1, MPI_MIN);
if (ierr < 0)
{
if (onpe0)
(*MPIdata::serr)
<< "loadRestartFile: cannot close file..." << std::endl;
return NULL;
}

// TODO(kevin): Do we need this routine?
restart_orbitals->applyMask();

/*
In returning restart_orbitals,
we hope that the wavefunctions in restart_orbitals are all set from restart file.
At least the following functions return proper data loaded from the file:
restart_orbitals->getLocNumpt()
restart_orbitals->chromatic_number()
restart_orbitals->getPsi(idx) (for int idx)
*/
return restart_orbitals;
}

template class MGmol<LocGridOrbitals>;
template class MGmol<ExtendedGridOrbitals>;

0 comments on commit 7c728e1

Please sign in to comment.