Skip to content

Commit 072363b

Browse files
knikhil1995phanimotamarri
authored andcommitted
Merged in groupSymmetryBugFixes (pull request #691)
Group Symmetry Bug Fixes Approved-by: Phani Motamarri Approved-by: Sambit Das
2 parents a884bfb + 94dda1c commit 072363b

9 files changed

Lines changed: 83 additions & 58 deletions

‎include/exchangeCorrelationFunctionalEvaluation.def‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@
3333
#ifndef UTILS
3434
#define UTILS
3535

36-
#define M_SQRTPI 1.772453850905516027298167483341145182798L
37-
#define M_CBRTPI 1.464591887561523263020142527263790391739L
38-
#define M_SQRT3 1.732050807568877293527446341505872366943L
39-
#define M_CBRT2 1.259921049894873164767210607278228350570L
40-
#define M_CBRT3 1.442249570307408382321638310780109588392L
41-
#define M_CBRT4 1.587401051968199474751705639272308260391L
42-
#define M_CBRT5 1.709975946676696989353108872543860109868L
43-
#define M_CBRT6 1.817120592832139658891211756327260502428L
44-
#define M_CBRT7 1.912931182772389101199116839548760282862L
45-
#define M_CBRT9 2.080083823051904114530056824357885386338L
36+
#define M_SQRTPI 1.772453850905516027298167483341145182798
37+
#define M_CBRTPI 1.464591887561523263020142527263790391739
38+
#define M_SQRT3 1.732050807568877293527446341505872366943
39+
#define M_CBRT2 1.259921049894873164767210607278228350570
40+
#define M_CBRT3 1.442249570307408382321638310780109588392
41+
#define M_CBRT4 1.587401051968199474751705639272308260391
42+
#define M_CBRT5 1.709975946676696989353108872543860109868
43+
#define M_CBRT6 1.817120592832139658891211756327260502428
44+
#define M_CBRT7 1.912931182772389101199116839548760282862
45+
#define M_CBRT9 2.080083823051904114530056824357885386338
4646
#define M_PI 3.14159265358979323846
4747
#define POW_1_3(x) pow((x), 1.0/3.0)
4848
#define POW_3_2(x) pow((x), 3.0/2.0)

‎include/geometryOptimizationClass.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace dftfe
6565
dftBase *d_dftPtr;
6666

6767
// restart parameters
68-
const bool d_isRestart;
68+
bool d_isRestart;
6969
const std::string d_restartFilesPath;
7070
const dftfe::Int d_verbosity;
7171
// status parameters

‎include/groupSymmetry.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ namespace dftfe
122122
const bool d_isTimeReversal;
123123
const bool d_isGroupSymmetry;
124124

125-
std::vector<std::map<dftfe::uInt, dftfe::uInt>>
126-
localDoFIndexToPointIndexMap;
125+
std::vector<std::vector<dftfe::uInt>> localDoFIndexToPointIndexMap;
127126
mutable dealii::Utilities::MPI::RemotePointEvaluation<3, 3>
128127
remotePointCache;
129128
std::vector<dealii::Point<3>> requiredPointCoordinates;

‎src/dft/initkPointData.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ namespace dftfe
427427
del[0] * (std::floor((i / (nkz * nky)))) + dkx;
428428
for (dftfe::uInt dir = 0; dir < 3; ++dir)
429429
{
430-
if (d_kPointCoordinatesFrac[3 * i + dir] > (0.5 + 1.0E-10))
430+
if (d_kPointCoordinatesFrac[3 * i + dir] >= 0.5)
431431
d_kPointCoordinatesFrac[3 * i + dir] =
432432
d_kPointCoordinatesFrac[3 * i + dir] - 1.0;
433433
}

‎src/geoOpt/geometryOptimizationClass.cc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ namespace dftfe
301301
d_mpiCommParent);
302302
if (d_optMode == 2 && d_status == 1)
303303
{
304-
d_dftPtr->trivialSolveForStress();
304+
if (!d_isRestart)
305+
d_dftPtr->trivialSolveForStress();
306+
else
307+
d_dftPtr->solve(false, true);
305308
}
306309
if (d_status == 1)
307310
{
@@ -323,6 +326,7 @@ namespace dftfe
323326
++d_cycle;
324327
}
325328
}
329+
d_isRestart = false;
326330
}
327331
}
328332

‎src/symmetry/groupSymmetry.cc‎

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ namespace dftfe
9595
d_domainBoundingVectorsInverse.copyFrom(inv3(d_domainBoundingVectors));
9696
if (d_isGroupSymmetry)
9797
{
98-
const dftfe::Int max_size = 500;
98+
const dftfe::Int max_size = 2000;
9999
int rotation[max_size][3][3];
100100
double translation[max_size][3];
101101
double lattice[3][3];
102102
double position[d_numAtoms][3];
103103
int types[d_numAtoms];
104104
for (dftfe::uInt iVec = 0; iVec < 3; ++iVec)
105105
for (dftfe::uInt jDim = 0; jDim < 3; ++jDim)
106-
lattice[iVec][jDim] = d_domainBoundingVectors[3 * iVec + jDim];
106+
lattice[jDim][iVec] = d_domainBoundingVectors[3 * iVec + jDim];
107107
for (dftfe::uInt iAtom = 0; iAtom < d_numAtoms; ++iAtom)
108108
{
109109
types[iAtom] = atomLocationsFractional[iAtom][0];
@@ -118,7 +118,7 @@ namespace dftfe
118118
position,
119119
types,
120120
d_numAtoms,
121-
1e-5);
121+
1e-8);
122122
else
123123
{
124124
int equivalent_atoms[d_numAtoms];
@@ -136,25 +136,25 @@ namespace dftfe
136136
types,
137137
spins,
138138
d_numAtoms,
139-
1e-5);
139+
1e-8);
140140
}
141141
d_symmMat.reserve(d_numSymm);
142142
d_symmMatInverse.reserve(d_numSymm);
143143
d_translation.reserve(d_numSymm);
144144
dftfe::uInt numSymm = 0;
145145
for (dftfe::uInt iSymm = 0; iSymm < d_numSymm; ++iSymm)
146-
if (std::abs(translation[iSymm][0]) < 1e-8 &&
147-
std::abs(translation[iSymm][1]) < 1e-8 &&
148-
std::abs(translation[iSymm][2]) < 1e-8)
149-
{
150-
d_symmMat.push_back(std::vector<double>(9, 0.0));
151-
d_translation.push_back(std::vector<double>(3, 0.0));
152-
for (dftfe::uInt jDim = 0; jDim < 3; ++jDim)
146+
{
147+
d_symmMat.push_back(std::vector<double>(9, 0.0));
148+
d_translation.push_back(std::vector<double>(3, 0.0));
149+
for (dftfe::uInt jDim = 0; jDim < 3; ++jDim)
150+
{
151+
d_translation.back()[jDim] = translation[iSymm][jDim];
153152
for (dftfe::uInt kDim = 0; kDim < 3; ++kDim)
154153
d_symmMat.back()[kDim * 3 + jDim] =
155154
static_cast<double>(rotation[iSymm][jDim][kDim]);
156-
d_symmMatInverse.push_back(inv3(d_symmMat.back()));
157-
}
155+
}
156+
d_symmMatInverse.push_back(inv3(d_symmMat.back()));
157+
}
158158
d_symmMat.shrink_to_fit();
159159
d_symmMatInverse.shrink_to_fit();
160160
d_translation.shrink_to_fit();
@@ -262,7 +262,7 @@ namespace dftfe
262262
for (int kDim = 0; kDim < 3; ++kDim)
263263
dot += m[iDim * 3 + kDim] * m[jDim * 3 + kDim];
264264
double orthoVal = iDim == jDim ? 1.0 : 0.0;
265-
if (std::fabs(dot - orthoVal) > 1e-6)
265+
if (std::fabs(dot - orthoVal) > 1e-8)
266266
return false;
267267
}
268268
}
@@ -295,7 +295,7 @@ namespace dftfe
295295
std::vector<dftfe::Int> kPointSymmetryMap(numKPoints, -1);
296296
auto wrap = [](double x) {
297297
double r = std::remainder(x, 1.0);
298-
return (r <= -0.5 ? 0.5 : r);
298+
return (r >= 0.5 ? r - 1.0 : r);
299299
};
300300
auto periodicDist = [](double a, double b) noexcept {
301301
double d = std::fabs(a - b);
@@ -384,7 +384,9 @@ namespace dftfe
384384
requiredPointCoordinates.clear();
385385
requiredPointCoordinates.reserve(d_numSymm * nodalCoordinates.size());
386386
localDoFIndexToPointIndexMap.clear();
387-
localDoFIndexToPointIndexMap.resize(d_numSymm);
387+
localDoFIndexToPointIndexMap.resize(
388+
d_numSymm, std::vector<dftfe::uInt>(dofHandler.n_locally_owned_dofs()));
389+
std::map<std::array<std::int64_t, 3>, dftfe::uInt> pointToPointIndexMap;
388390
for (dftfe::uInt iSymm = 0; iSymm < d_numSymm; ++iSymm)
389391
for (dealii::IndexSet::ElementIterator it = locallyOwnedNodes.begin();
390392
it != locallyOwnedNodes.end();
@@ -409,7 +411,7 @@ namespace dftfe
409411
for (dftfe::uInt jDim = 0; jDim < 3; ++jDim)
410412
transformedNodeCoordinatesFrac[iDim] +=
411413
d_symmMatInverse[iSymm][jDim * 3 + iDim] *
412-
currentNodeCoordinatesFrac[jDim];
414+
(currentNodeCoordinatesFrac[jDim] - d_translation[iSymm][jDim]);
413415
for (dftfe::uInt iDim = 0; iDim < 3; ++iDim)
414416
transformedNodeCoordinatesFrac[iDim] =
415417
transformedNodeCoordinatesFrac[iDim] -
@@ -421,10 +423,30 @@ namespace dftfe
421423
transformedNodeCoordinatesCart[iDim] +=
422424
d_domainBoundingVectors[3 * jDim + iDim] *
423425
transformedNodeCoordinatesFrac[jDim];
424-
requiredPointCoordinates.push_back(transformedNodeCoordinatesCart);
425-
localDoFIndexToPointIndexMap[iSymm][locallyOwnedNodes
426-
.index_within_set(*it)] =
427-
requiredPointCoordinates.size() - 1;
426+
std::array<std::int64_t, 3> roundedCoords;
427+
roundedCoords[0] =
428+
std::llround(transformedNodeCoordinatesCart[0] * 1e8);
429+
roundedCoords[1] =
430+
std::llround(transformedNodeCoordinatesCart[1] * 1e8);
431+
roundedCoords[2] =
432+
std::llround(transformedNodeCoordinatesCart[2] * 1e8);
433+
auto pointIterator = pointToPointIndexMap.find(roundedCoords);
434+
if (pointIterator != pointToPointIndexMap.end())
435+
{
436+
localDoFIndexToPointIndexMap[iSymm][locallyOwnedNodes
437+
.index_within_set(*it)] =
438+
pointIterator->second;
439+
}
440+
else
441+
{
442+
requiredPointCoordinates.push_back(
443+
transformedNodeCoordinatesCart);
444+
localDoFIndexToPointIndexMap[iSymm][locallyOwnedNodes
445+
.index_within_set(*it)] =
446+
requiredPointCoordinates.size() - 1;
447+
pointToPointIndexMap[roundedCoords] =
448+
requiredPointCoordinates.size() - 1;
449+
}
428450
}
429451
requiredPointCoordinates.shrink_to_fit();
430452
remotePointCache.reinit(requiredPointCoordinates,
@@ -454,14 +476,15 @@ namespace dftfe
454476
for (dftfe::uInt iSymm = 0; iSymm < d_numSymm; ++iSymm)
455477
for (dftfe::uInt iPoint = 0; iPoint < numPoints; ++iPoint)
456478
{
457-
std::vector<double> transformedPoint = d_translation[iSymm];
479+
std::vector<double> transformedPoint = {0.0, 0.0, 0.0};
458480
for (dftfe::uInt jDim = 0; jDim < 3; ++jDim)
459-
transformedPoint[jDim] += d_symmMatInverse[iSymm][0 * 3 + jDim] *
460-
globalPointCoords[3 * iPoint + 0] +
461-
d_symmMatInverse[iSymm][1 * 3 + jDim] *
462-
globalPointCoords[3 * iPoint + 1] +
463-
d_symmMatInverse[iSymm][2 * 3 + jDim] *
464-
globalPointCoords[3 * iPoint + 2];
481+
transformedPoint[jDim] =
482+
d_symmMatInverse[iSymm][0 * 3 + jDim] *
483+
(globalPointCoords[3 * iPoint + 0] - d_translation[iSymm][0]) +
484+
d_symmMatInverse[iSymm][1 * 3 + jDim] *
485+
(globalPointCoords[3 * iPoint + 1] - d_translation[iSymm][1]) +
486+
d_symmMatInverse[iSymm][2 * 3 + jDim] *
487+
(globalPointCoords[3 * iPoint + 2] - d_translation[iSymm][2]);
465488
for (dftfe::uInt jDim = 0; jDim < 3; ++jDim)
466489
transformedPoint[jDim] =
467490
transformedPoint[jDim] - std::floor(transformedPoint[jDim]);
@@ -500,8 +523,7 @@ namespace dftfe
500523
for (dftfe::uInt iDoF = 0; iDoF < scalarField.locally_owned_size();
501524
++iDoF)
502525
scalarField.local_element(iDoF) +=
503-
pointValues[localDoFIndexToPointIndexMap[iSymm].find(iDoF)->second] /
504-
d_numSymm;
526+
pointValues[localDoFIndexToPointIndexMap[iSymm][iDoF]] / d_numSymm;
505527
}
506528

507529
void

‎tests/dft/pseudopotential/complex/graphene_01.mpirun=4.output‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ SCF iterations converged to the specified tolerance after: 12 iterations.
3838

3939
Energy computations (Hartree)
4040
-------------------
41-
Total energy: -11.40431266
41+
Total energy: -11.40446008

‎tests/dft/pseudopotential/complex/hcpMgPrim_03.mpirun=3.output‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ SCF iterations converged to the specified tolerance after: 8 iterations.
3838

3939
Energy computations (Hartree)
4040
-------------------
41-
Total energy: -138.26521905
41+
Total energy: -138.26447132
4242

4343
Absolute values of ion forces (Hartree/Bohr)
4444
--------------------------------------------------------------------------------------------
45-
AtomId 0: 0.000457,0.000290,0.000000
46-
AtomId 1: 0.004977,0.002185,0.000000
45+
AtomId 0: 0.000000,0.000000,0.000000
46+
AtomId 1: 0.000000,0.000000,0.000000
4747
--------------------------------------------------------------------------------------------
4848

4949
Absolute value of cell stress (Hartree/Bohr^3)
5050
------------------------------------------------------------------------
51-
0.004726 0.001332 0.000000
52-
0.001332 0.003188 0.000000
53-
0.000000 0.000000 0.002414
51+
0.003849 0.000000 0.000000
52+
0.000000 0.003849 0.000000
53+
0.000000 0.000000 0.002494
5454
------------------------------------------------------------------------

‎tests/dft/pseudopotential/complex/hcpMgPrim_03.mpirun=5.output‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ SCF iterations converged to the specified tolerance after: 8 iterations.
3838

3939
Energy computations (Hartree)
4040
-------------------
41-
Total energy: -138.26521905
41+
Total energy: -138.26447132
4242

4343
Absolute values of ion forces (Hartree/Bohr)
4444
--------------------------------------------------------------------------------------------
45-
AtomId 0: 0.000457,0.000290,0.000000
46-
AtomId 1: 0.004977,0.002185,0.000000
45+
AtomId 0: 0.000000,0.000000,0.000000
46+
AtomId 1: 0.000000,0.000000,0.000000
4747
--------------------------------------------------------------------------------------------
4848

4949
Absolute value of cell stress (Hartree/Bohr^3)
5050
------------------------------------------------------------------------
51-
0.004726 0.001332 0.000000
52-
0.001332 0.003188 0.000000
53-
0.000000 0.000000 0.002414
51+
0.003849 0.000000 0.000000
52+
0.000000 0.003849 0.000000
53+
0.000000 0.000000 0.002494
5454
------------------------------------------------------------------------

0 commit comments

Comments
 (0)