Skip to content

Commit

Permalink
Sort the SymmList to avoid the result to change for each run.
Browse files Browse the repository at this point in the history
  • Loading branch information
ttadano committed Feb 19, 2016
1 parent c2f99e6 commit 3eb2e84
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
31 changes: 17 additions & 14 deletions alm/symmetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,27 @@ void Symmetry::setup_symmetry_operation(int nat, unsigned int &nsym,
std::cout << " This can take a while for a large supercell." << std::endl << std::endl;

findsym(nat, aa, x, SymmList);
// The order in SymmList changes for each run because it was generated
// with OpenMP. Therefore, we sort the list here to have the same result.
std::sort(SymmList.begin()+1,SymmList.end());
nsym = SymmList.size();

if (is_printsymmetry) {
std::ofstream ofs_sym;
std::ofstream ofs_sym;
std::cout << " PRINTSYM = 1: Symmetry information will be stored in SYMM_INFO file."
<< std::endl << std::endl;
<< std::endl << std::endl;
ofs_sym.open(file_sym.c_str(), std::ios::out);
ofs_sym << nsym << std::endl;

for (std::vector<SymmetryOperation>::iterator p = SymmList.begin(); p != SymmList.end(); ++p) {
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
ofs_sym << std::setw(4) << (*p).rot[i][j];
}
for (j = 0; j < 3; ++j) {
ofs_sym << std::setw(4) << (*p).rot[i][j];
}
}
ofs_sym << " ";
for (i = 0; i < 3; ++i) {
ofs_sym << std::setprecision(15) << std::setw(20) << (*p).tran[i];
ofs_sym << std::setprecision(15) << std::setw(20) << (*p).tran[i];
}
ofs_sym << std::endl;
}
Expand All @@ -170,7 +173,7 @@ void Symmetry::setup_symmetry_operation(int nat, unsigned int &nsym,
std::cout << " NSYM = 1 : Only the identity matrix will be considered." << std::endl << std::endl;

int rot_tmp[3][3];
double tran_tmp[3];
double tran_tmp[3];

for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
Expand All @@ -191,20 +194,20 @@ void Symmetry::setup_symmetry_operation(int nat, unsigned int &nsym,

int nsym2;
int rot_tmp[3][3];
double tran_tmp[3];
std::ifstream ifs_sym;
double tran_tmp[3];
std::ifstream ifs_sym;

ifs_sym.open(file_sym.c_str(), std::ios::in);
ifs_sym >> nsym2;

if (nsym != nsym2) error->exit("setup_symmetry_operations",
"nsym in the given file and the input file are not consistent.");
"nsym in the given file and the input file are not consistent.");

for (i = 0; i < nsym; ++i) {
ifs_sym >> rot_tmp[0][0] >> rot_tmp[0][1] >> rot_tmp[0][2]
>> rot_tmp[1][0] >> rot_tmp[1][1] >> rot_tmp[1][2]
>> rot_tmp[2][0] >> rot_tmp[2][1] >> rot_tmp[2][2]
>> tran_tmp[0] >> tran_tmp[1] >> tran_tmp[2];
>> rot_tmp[1][0] >> rot_tmp[1][1] >> rot_tmp[1][2]
>> rot_tmp[2][0] >> rot_tmp[2][1] >> rot_tmp[2][2]
>> tran_tmp[0] >> tran_tmp[1] >> tran_tmp[2];

SymmList.push_back(SymmetryOperation(rot_tmp, tran_tmp));
}
Expand Down Expand Up @@ -903,7 +906,7 @@ void Symmetry::print_symmetrized_coordinate(double **x)
}
}

std::cout << "Symmetrically Averaged Coordinate" << std::endl;
std::cout << "Symmetry Averaged Coordinate" << std::endl;
for (i = 0; i < nat; ++i) {
for (j = 0; j < 3; ++j) {
std::cout << std::setw(20) << std::scientific << std::setprecision(9) << x_avg[i][j];
Expand Down
15 changes: 15 additions & 0 deletions alm/symmetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ namespace ALM_NS {
tran[i] = tran_in[i];
}
}

bool operator<(const SymmetryOperation &a) const {
std::vector<double> v1, v2;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
v1.push_back(rot[i][j]);
v2.push_back(a.rot[i][j]);
}
}
for (int i = 0; i < 3; ++i) {
v1.push_back(tran[i]);
v2.push_back(a.tran[i]);
}
return std::lexicographical_compare(v1.begin(),v1.end(),v2.begin(),v2.end());
}
};

class RotationMatrix {
Expand Down

0 comments on commit 3eb2e84

Please sign in to comment.