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
1 change: 0 additions & 1 deletion src/HDFrestart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,6 @@ int HDFrestart::readAtomicData(
stripLeadingAndTrailingBlanks(t);
// std::cout<<"stripped name="<<t<<std::endl;

assert(t.size() > 0);
data.push_back(t);
}

Expand Down
45 changes: 21 additions & 24 deletions src/KBPsiMatrixSparse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@

#include "Control.h"
#include "ExtendedGridOrbitals.h"
#include "Ions.h"
#include "LocGridOrbitals.h"
#include "MGmol_MPI.h"
#include "Mesh.h"
#include "ProjectedMatrices.h"
#include "ProjectedMatricesSparse.h"
#include "ReplicatedMatrix.h"
#include "SquareSubMatrix2DistMatrix.h"

#include <limits.h>

#define Ry2Ha 0.5;

Timer KBPsiMatrixSparse::global_sum_tm_("KBPsiMatrixSparse::global_sum");
Expand Down Expand Up @@ -133,7 +132,7 @@ void KBPsiMatrixSparse::globalSumKBpsi()
// Loop over the ions with projectors overlapping with local subdomain
// and evaluate <KB|psi> for some state.
template <class T>
void KBPsiMatrixSparse::computeKBpsi(Ions& ions, T& orbitals,
void KBPsiMatrixSparse::computeKBpsi(const Ions& ions, T& orbitals,
const int first_color, const int nb_colors, const bool flag)
{
assert(first_color >= 0);
Expand Down Expand Up @@ -189,7 +188,7 @@ void KBPsiMatrixSparse::computeKBpsi(Ions& ions, T& orbitals,
// Loop over the ions
if (gid != -1)
{
for (auto ion : ions.overlappingNL_ions())
for (const auto& ion : ions.overlappingNL_ions())
{
computeLocalElement(
*ion, gid, iloc, ppsi + color * ldsize, flag);
Expand All @@ -211,8 +210,8 @@ void KBPsiMatrixSparse::computeKBpsi(Ions& ions, T& orbitals,
compute_kbpsi_tm_.stop();
}

void KBPsiMatrixSparse::computeKBpsi(
Ions& ions, pb::GridFunc<ORBDTYPE>* phi, const int istate, const bool flag)
void KBPsiMatrixSparse::computeKBpsi(const Ions& ions,
pb::GridFunc<ORBDTYPE>* phi, const int istate, const bool flag)
{
assert(lapop_ != nullptr);
compute_kbpsi_tm_.start();
Expand All @@ -238,7 +237,7 @@ void KBPsiMatrixSparse::computeKBpsi(
for (int iloc = 0; iloc < subdivx; iloc++)
{
// Loop over the ions
for (auto ion : ions.overlappingNL_ions())
for (const auto& ion : ions.overlappingNL_ions())
{
computeLocalElement(*ion, istate, iloc, ppsi, flag);
}
Expand All @@ -251,7 +250,7 @@ void KBPsiMatrixSparse::computeKBpsi(

void KBPsiMatrixSparse::scaleWithKBcoeff(const Ions& ions)
{
for (auto ion : ions.overlappingNL_ions())
for (const auto& ion : ions.overlappingNL_ions())
{
std::vector<int> gids;
ion->getGidsNLprojs(gids);
Expand All @@ -266,8 +265,8 @@ void KBPsiMatrixSparse::scaleWithKBcoeff(const Ions& ions)

// loop over states to multiply kbpsi_[st][gid] and kbBpsi_[st][gid]
// by coeff
(*kbpsimat_).scaleRow(gid, coeff);
if (lapop_) (*kbBpsimat_).scaleRow(gid, coeff);
kbpsimat_->scaleRow(gid, coeff);
if (lapop_) kbBpsimat_->scaleRow(gid, coeff);
}
}
}
Expand Down Expand Up @@ -454,7 +453,7 @@ SquareSubMatrix<double> KBPsiMatrixSparse::computeHvnlMatrix(

// Loop over ions centered on current PE only
// (distribution of work AND Hvnlij contributions)
for (auto ion : ions.local_ions())
for (const auto& ion : ions.local_ions())
{
computeHvnlMatrix((KBPsiMatrixSparse*)kbpsi2, *ion, Aij);
}
Expand All @@ -473,7 +472,7 @@ void KBPsiMatrixSparse::computeHvnlMatrix(

// Loop over ions centered on current PE only
// (distribution of work AND Hvnlij contributions)
for (auto ion : ions.local_ions())
for (const auto& ion : ions.local_ions())
{
computeHvnlMatrix((KBPsiMatrixSparse*)kbpsi2, *ion, mat);
}
Expand Down Expand Up @@ -538,14 +537,14 @@ void KBPsiMatrixSparse::getPsiKBPsiSym(
{
// loop over all the ions
// parallelization over ions by including only those centered in subdomain
for (auto& ion : ions.local_ions())
for (const auto& ion : ions.local_ions())
{
getPsiKBPsiSym(*ion, sm);
}
}

template <class T>
void KBPsiMatrixSparse::computeAll(Ions& ions, T& orbitals)
void KBPsiMatrixSparse::computeAll(const Ions& ions, T& orbitals)
{
assert(count_proj_subdomain_ == ions.countProjectorsSubdomain());

Expand Down Expand Up @@ -603,7 +602,7 @@ double KBPsiMatrixSparse::getEvnl(
double trace = 0.0;
// loop over all the ions
// parallelization over ions by including only those centered in subdomain
for (auto& ion : ions.local_ions())
for (const auto& ion : ions.local_ions())
{
std::vector<int> gids;
ion->getGidsNLprojs(gids);
Expand All @@ -618,10 +617,9 @@ double KBPsiMatrixSparse::getEvnl(

/* gather trace result */
MGmol_MPI& mmpi = *(MGmol_MPI::instance());
MPI_Comm comm = mmpi.commSpin();

double evnl = 0.0;
MPI_Allreduce(&trace, &evnl, 1, MPI_DOUBLE, MPI_SUM, comm);
mmpi.allreduce(&trace, &evnl, 1, MPI_SUM);

return evnl * Ry2Ha;
}
Expand All @@ -637,7 +635,7 @@ double KBPsiMatrixSparse::getEvnl(const Ions& ions,
double trace = 0.0;
// loop over all the ions
// parallelization over ions by including only those centered in subdomain
for (auto& ion : ions.local_ions())
for (const auto& ion : ions.local_ions())
{
std::vector<int> gids;
ion->getGidsNLprojs(gids);
Expand All @@ -652,10 +650,9 @@ double KBPsiMatrixSparse::getEvnl(const Ions& ions,

/* gather trace result */
MGmol_MPI& mmpi = *(MGmol_MPI::instance());
MPI_Comm comm = mmpi.commSpin();

double evnl = 0.0;
MPI_Allreduce(&trace, &evnl, 1, MPI_DOUBLE, MPI_SUM, comm);
mmpi.allreduce(&trace, &evnl, 1, MPI_SUM);

return evnl * Ry2Ha;
}
Expand Down Expand Up @@ -736,12 +733,12 @@ double KBPsiMatrixSparse::getTraceDM(
return trace;
}

template void KBPsiMatrixSparse::computeKBpsi(Ions& ions,
template void KBPsiMatrixSparse::computeKBpsi(const Ions& ions,
LocGridOrbitals& orbitals, const int first_color, const int nb_colors,
const bool flag);
template void KBPsiMatrixSparse::computeAll(Ions&, LocGridOrbitals&);
template void KBPsiMatrixSparse::computeAll(const Ions&, LocGridOrbitals&);

template void KBPsiMatrixSparse::computeKBpsi(Ions& ions,
template void KBPsiMatrixSparse::computeKBpsi(const Ions& ions,
ExtendedGridOrbitals& orbitals, const int first_color, const int nb_colors,
const bool flag);
template void KBPsiMatrixSparse::computeAll(Ions&, ExtendedGridOrbitals&);
template void KBPsiMatrixSparse::computeAll(const Ions&, ExtendedGridOrbitals&);
15 changes: 6 additions & 9 deletions src/KBPsiMatrixSparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

#include "DataDistribution.h"
#include "DensityMatrixSparse.h"
#include "Ions.h"
#include "KBPsiMatrixInterface.h"
#include "ProjectedMatricesSparse.h"
#include "SquareSubMatrix.h"
#include "VariableSizeMatrix.h"

Expand All @@ -23,11 +25,6 @@
#include <cassert>
#include <limits.h>

class Ions;
class Ion;
class ProjectedMatricesInterface;
class ProjectedMatricesSparse;

class KBPsiMatrixSparse : public KBPsiMatrixInterface
{
static Timer global_sum_tm_;
Expand Down Expand Up @@ -79,8 +76,8 @@ class KBPsiMatrixSparse : public KBPsiMatrixInterface
void getPsiKBPsiSym(const Ions& ions, VariableSizeMatrix<sparserow>& sm);
void getPsiKBPsiSym(const Ion& ion, VariableSizeMatrix<sparserow>& sm);
template <class OrbitalsType>
void computeKBpsi(Ions& ions, OrbitalsType& orbitals, const int first_color,
const int nb_colors, const bool flag);
void computeKBpsi(const Ions& ions, OrbitalsType& orbitals,
const int first_color, const int nb_colors, const bool flag);
void clearData();

public:
Expand All @@ -105,7 +102,7 @@ class KBPsiMatrixSparse : public KBPsiMatrixInterface
double getEvnl(
const Ions& ions, ProjectedMatrices<MatrixType>* proj_matrices);
void computeKBpsi(
Ions& ions, pb::GridFunc<ORBDTYPE>*, const int, const bool flag);
const Ions& ions, pb::GridFunc<ORBDTYPE>*, const int, const bool flag);
double getValIonState(const int gid, const int st) const
{
return (*kbpsimat_).get_value(gid, st);
Expand All @@ -127,7 +124,7 @@ class KBPsiMatrixSparse : public KBPsiMatrixInterface
const Ions& ions, ProjectedMatricesInterface* proj_matrices) const;

template <class T>
void computeAll(Ions& ions, T& orbitals);
void computeAll(const Ions& ions, T& orbitals);
void setup(const Ions& ions);

double getTraceDM(
Expand Down
18 changes: 9 additions & 9 deletions src/MGmol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ int MGmol<OrbitalsType>::initial()
}

// Initialize the nuclear local potential and the compensating charges
if (ct.verbose > 0) printWithTimeStamp("initNuc()...", os_);
initNuc(*ions_);
if (ct.verbose > 0) printWithTimeStamp("setupPotentials()...", os_);
setupPotentials(*ions_);

// initialize Rho
if (ct.verbose > 0) printWithTimeStamp("Initialize Rho...", os_);
Expand Down Expand Up @@ -415,9 +415,6 @@ int MGmol<OrbitalsType>::initial()
current_orbitals_->checkCond(100000., ct.AtomsMove());
}

if (ct.verbose > 0) printWithTimeStamp("Setup kbpsi...", os_);
g_kbpsi_->setup(*ions_);

if (ct.restart_info == 0)
{
if (ct.verbose > 0) printWithTimeStamp("update_pot...", os_);
Expand Down Expand Up @@ -817,7 +814,7 @@ double get_trilinval(const double xc, const double yc, const double zc,
#endif

template <class OrbitalsType>
void MGmol<OrbitalsType>::initNuc(Ions& ions)
void MGmol<OrbitalsType>::setupPotentials(Ions& ions)
{
init_nuc_tm_.start();

Expand All @@ -829,9 +826,12 @@ void MGmol<OrbitalsType>::initNuc(Ions& ions)
// initialize poentials based on ionic positions and their species
pot.initialize(ions);

if (ct.verbose > 0) printWithTimeStamp("Setup kbpsi...", os_);
g_kbpsi_->setup(*ions_);

electrostat_->setupRhoc(pot.rho_comp());

if (onpe0 && ct.verbose > 3) os_ << " initNuc done" << std::endl;
if (onpe0 && ct.verbose > 3) os_ << " setupPotentials done" << std::endl;

init_nuc_tm_.stop();
}
Expand Down Expand Up @@ -1428,7 +1428,7 @@ double MGmol<OrbitalsType>::evaluateEnergyAndForces(Orbitals* orbitals,

ions_->setPositions(tau, atnumbers);

moveVnuc(*ions_);
setupPotentials(*ions_);

double eks = 0.;
OrbitalsType* dorbitals = dynamic_cast<OrbitalsType*>(orbitals);
Expand All @@ -1450,7 +1450,7 @@ double MGmol<OrbitalsType>::evaluateDMandEnergyAndForces(Orbitals* orbitals,

ions_->setPositions(tau, atnumbers);

moveVnuc(*ions_);
setupPotentials(*ions_);

// initialize electronic density
rho_->update(*dorbitals);
Expand Down
2 changes: 1 addition & 1 deletion src/MGmol.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class MGmol : public MGmolInterface

void getAtomicNumbers(std::vector<short>& an);

void initNuc(Ions& ions);
void setupPotentials(Ions& ions);
void initKBR();

void printEigAndOcc();
Expand Down
2 changes: 1 addition & 1 deletion src/md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void MGmol<OrbitalsType>::moveVnuc(Ions& ions)

// Update items that change when the ionic coordinates change
pot.axpVcompToVh(1.);
initNuc(ions);
setupPotentials(ions);
pot.axpVcompToVh(-1.);

proj_matrices_->setHiterativeIndex(-1, -1);
Expand Down
1 change: 0 additions & 1 deletion src/quench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ int MGmol<OrbitalsType>::quench(OrbitalsType& orbitals, Ions& ions,
// get actual indexes of stored functions
const std::vector<std::vector<int>>& gids(orbitals.getOverlappingGids());

g_kbpsi_->setup(*ions_);
electrostat_->setup(ct.vh_its);
rho_->setup(ct.getOrthoType(), gids);

Expand Down