Skip to content

Commit

Permalink
Merged in pdosBugFix (pull request #641)
Browse files Browse the repository at this point in the history
highestStateForResidualComputation Fixed

Approved-by: Kartick Ramakrishnan
Approved-by: Nikhil Kodali
Approved-by: Phani Motamarri
  • Loading branch information
nandis99 committed Dec 10, 2024
2 parents f70f675 + f632157 commit acfdd00
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 40 deletions.
3 changes: 1 addition & 2 deletions include/dft.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ namespace dftfe
* @brief Number of Kohn-Sham eigen values to be computed
*/
unsigned int d_numEigenValues;
unsigned int d_highestStateForNscfCalculation;
unsigned int d_highestStateForResidualComputation;
/**
* @brief Number of Kohn-Sham eigen values to be computed in the Rayleigh-Ritz step
* after spectrum splitting.
Expand Down Expand Up @@ -1189,7 +1189,6 @@ namespace dftfe
*/
void
compute_tdos(const std::vector<std::vector<double>> &eigenValuesInput,
const unsigned int highestStateOfInterest,
const std::string & fileName);

void
Expand Down
14 changes: 6 additions & 8 deletions src/dft/dft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,13 @@ namespace dftfe
pcout << "Setting netcharge " << d_dftParamsPtr->netCharge << std::endl;

if (d_dftParamsPtr->solverMode == "NSCF" &&
d_dftParamsPtr->numberEigenValues == 0 &&
d_dftParamsPtr->highestStateOfInterestForChebFiltering != 0)
{
d_numEigenValues =
d_numEigenValues = std::max(
static_cast<double>(d_dftParamsPtr->numberEigenValues),
std::max(d_dftParamsPtr->highestStateOfInterestForChebFiltering * 1.1,
d_dftParamsPtr->highestStateOfInterestForChebFiltering +
10.0);
10.0));
if (d_dftParamsPtr->verbosity >= 1)
{
pcout
Expand Down Expand Up @@ -2002,7 +2002,7 @@ namespace dftfe
interpoolcomm,
d_dftParamsPtr,
fermiEnergy,
d_highestStateForNscfCalculation);
d_highestStateForResidualComputation);
}
#ifdef DFTFE_WITH_DEVICE
else if constexpr (dftfe::utils::MemorySpace::DEVICE == memorySpace)
Expand All @@ -2021,7 +2021,7 @@ namespace dftfe
interpoolcomm,
d_dftParamsPtr,
fermiEnergy,
d_highestStateForNscfCalculation);
d_highestStateForResidualComputation);
}

#endif
Expand Down Expand Up @@ -2052,9 +2052,7 @@ namespace dftfe
writeGSElectronDensity("densityQuadData.txt");

if (d_dftParamsPtr->writeDosFile)
compute_tdos(eigenValues,
d_dftParamsPtr->highestStateOfInterestForChebFiltering,
"dosData.out");
compute_tdos(eigenValues, "dosData.out");

if (d_dftParamsPtr->writeLdosFile)
compute_ldos(eigenValues, "ldosData.out");
Expand Down
8 changes: 4 additions & 4 deletions src/dft/dos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ namespace dftfe
void
dftClass<FEOrder, FEOrderElectro, memorySpace>::compute_tdos(
const std::vector<std::vector<double>> &eigenValuesInput,
const unsigned int highestStateOfInterest,
const std::string & dosFileName)
{
computing_timer.enter_subsection("DOS computation");

// from 0th spin as this is only to get a printing range
std::vector<double> eigenValuesAllkPoints;
for (int kPoint = 0; kPoint < d_kPointWeights.size(); ++kPoint)
for (int statesIter = 0; statesIter <= d_highestStateForNscfCalculation;
for (int statesIter = 0;
statesIter <= d_highestStateForResidualComputation;
++statesIter)
eigenValuesAllkPoints.push_back(eigenValuesInput[kPoint][statesIter]);

Expand Down Expand Up @@ -206,7 +206,7 @@ namespace dftfe
++spinType)
{
for (unsigned int statesIter = 0;
statesIter <= d_highestStateForNscfCalculation;
statesIter <= d_highestStateForResidualComputation;
++statesIter)
{
double term1 =
Expand Down Expand Up @@ -252,7 +252,7 @@ namespace dftfe
for (int kPoint = 0; kPoint < d_kPointWeights.size(); ++kPoint)
{
for (unsigned int statesIter = 0;
statesIter <= d_highestStateForNscfCalculation;
statesIter <= d_highestStateForResidualComputation;
++statesIter)
{
double term1 =
Expand Down
16 changes: 6 additions & 10 deletions src/dft/kohnShamEigenSolve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ namespace dftfe
maxHighestOccupiedStateResNorm =
dealii::Utilities::MPI::max(maxHighestOccupiedStateResNorm,
interpoolcomm);
d_highestStateForNscfCalculation = highestState;
d_highestStateForResidualComputation = highestState;
return maxHighestOccupiedStateResNorm;
}
// compute the maximum of the residual norm of the highest occupied state
Expand Down Expand Up @@ -1043,7 +1043,7 @@ namespace dftfe
residualNormWaveFunctionsAllkPoints[kPoint]
[highestOccupiedState];
}
d_highestStateForNscfCalculation = highestOccupiedState;
d_highestStateForResidualComputation = highestOccupiedState;
}
}
else
Expand Down Expand Up @@ -1075,14 +1075,10 @@ namespace dftfe
highestOccupiedState = i;
}

d_highestStateForNscfCalculation = std::min(
d_numEigenValues - 1,
std::max(static_cast<unsigned int>(highestOccupiedState * 1.2),
highestOccupiedState +
5)); // 5 buffer states for dos and pdos plot
//(We need to take a call on this because the residual norm
// converges slowly if we go far from fermi energy)
for (unsigned int i = 0; i <= d_highestStateForNscfCalculation; i++)
d_highestStateForResidualComputation = highestOccupiedState;

for (unsigned int i = 0; i <= d_highestStateForResidualComputation;
i++)
{
if (residualNormWaveFunctionsAllkPoints[kPoint][i] >
maxHighestOccupiedStateResNorm)
Expand Down
30 changes: 14 additions & 16 deletions src/pseudo/oncv/atomCenteredPostProcessing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,9 @@ namespace dftfe
const double intervalSize =
dftParamsPtr->intervalSize / C_haToeV; // eV to Ha

double lowerBoundEpsilon = std::floor(eigenValuesAllkPoints[0]*100)/100;
double upperBoundEpsilon = std::ceil(eigenValuesAllkPoints[totalEigenValues - 1]*100)/100;
double lowerBoundEpsilon = std::floor(eigenValuesAllkPoints[0] * 100) / 100;
double upperBoundEpsilon =
std::ceil(eigenValuesAllkPoints[totalEigenValues - 1] * 100) / 100;

MPI_Allreduce(MPI_IN_PLACE,
&lowerBoundEpsilon,
Expand Down Expand Up @@ -973,9 +974,9 @@ namespace dftfe
dftParamsPtr->verbosity == 0 && atomId == 0)
{
double epsValueTrunc =
std::floor(100000 * epsValue * C_haToeV) /
100000;
pcout << std::fixed << std::setprecision(5) << std::setw(15) << epsValueTrunc << "\t";
std::floor(100000 * epsValue * C_haToeV) / 100000;
pcout << std::fixed << std::setprecision(5)
<< std::setw(15) << epsValueTrunc << "\t";
}

std::vector<double> pdosVec;
Expand Down Expand Up @@ -1032,17 +1033,15 @@ namespace dftfe
dftParamsPtr->verbosity == 0 && atomId == 0)
{
pcout << std::setw(15)
<< std::floor(100000 * pdosSumUp) /
100000
<< std::floor(100000 * pdosSumUp) / 100000
<< "\t";
for (auto it = pdosVec.begin();
it != pdosVec.end();
++it)
{
pcout << std::setw(15)
<< std::floor((*it) * 100000) /
100000
<< "\t";
<< std::floor((*it) * 100000) / 100000
<< "\t";
}
pcout << std::endl;
}
Expand All @@ -1066,13 +1065,12 @@ namespace dftfe
dftParamsPtr->verbosity == 0 && atomId == 0)
{
pcout << std::setw(15)
<< std::floor(pdosSumUp * 100000) /
100000
<< "\t";
pcout << std::setw(15)
<< std::floor(pdosSumDown * 100000) /
100000
<< std::floor(pdosSumUp * 100000) / 100000
<< "\t";
pcout
<< std::setw(15)
<< std::floor(pdosSumDown * 100000) / 100000
<< "\t";

for (auto it = pdosVec.begin();
it != pdosVec.begin() + pdosVec.size() / 2;
Expand Down

0 comments on commit acfdd00

Please sign in to comment.