Regression test for LDAD stress under non-orthogonal periodic boundary conditions. The test uses a skew representation of the same crystal as testLDADSW, computes Piola and Cauchy LDAD stresses, and compares stress components against the orthogonal reference results while allowing the grid coordinates to differ by the periodic representation.
15void checkSkewedBox(
const Matrix3d& box,
const std::string& name)
17 if (std::abs(box.col(0).dot(box.col(1))) <
epsilon ||
18 std::abs(box.col(0).dot(box.col(2))) <
epsilon ||
19 std::abs(box.col(1).dot(box.col(2))) <
epsilon)
20 MY_ERROR(name +
" is not non-orthogonal.");
23template<
typename TMethod, StressType stressType>
25 const std::string& referenceFilename)
27 std::ifstream fileReference(referenceFilename);
28 if(!fileReference)
MY_ERROR(
"ERROR: " + referenceFilename +
" could not be opened for reading!");
31 fileReference >> ngridReference;
32 if(stress.
field.size() != ngridReference)
33 MY_ERROR(
"Test failed in " + referenceFilename +
". Number of grid points do not match.");
36 std::getline(fileReference,line);
37 std::getline(fileReference,line);
39 double maxDifference= 0.0;
40 for (
int i_point=0; i_point<ngridReference; ++i_point)
43 double sxx,syy,szz,sxy,sxz,syz;
44 fileReference >> x >> y >> z >> sxx >> syy >> szz >> sxy >> sxz >> syz;
47 maxDifference= std::max(maxDifference,std::abs(value(0,0)-sxx));
48 maxDifference= std::max(maxDifference,std::abs(value(1,1)-syy));
49 maxDifference= std::max(maxDifference,std::abs(value(2,2)-szz));
50 maxDifference= std::max(maxDifference,std::abs(value(0,1)-sxy));
51 maxDifference= std::max(maxDifference,std::abs(value(0,2)-sxz));
52 maxDifference= std::max(maxDifference,std::abs(value(1,2)-syz));
55 const double tolerance= 1e-8;
56 if (maxDifference > tolerance)
58 std::cout <<
"Maximum stress-component difference = " << maxDifference << std::endl;
59 std::cout <<
"Tolerance = " << tolerance << std::endl;
60 MY_ERROR(
"Non-orthogonal PBC stress regression failed against " + referenceFilename);
67 int numberOfParticles;
68 int referenceAndFinal=
true;
69 std::string configFileName=
"config.data";
70 std::string modelname=
"SW_StillingerWeber_1985_Si__MO_405512056662_005";
72 std::ifstream file(configFileName);
73 if(!file)
MY_ERROR(
"ERROR: config.data could not be opened for reading!");
75 file >> numberOfParticles;
76 if (numberOfParticles < 0)
MY_ERROR(
"Error: Negative number of particles.\n");
79 body.
read(configFileName,referenceAndFinal);
80 checkSkewedBox(body.reference_box,
"Reference box");
81 checkSkewedBox(body.box,
"Current box");
87 gridFromFile_ref.read(
"grid_pk1.data");
90 gridFromFile_def.read(
"grid_cauchy.data");
93 ldadVectors_ref << 5.43094977840521, 0.0, 0.0,
94 0.0, 5.43094977840521, 0.0,
95 0.0, 0.0, 5.43094977840521;
104 ldad_constant_stress_ref.write();
106 ldad_trigonometric_stress_ref.write();
109 ldadVectors_def << 5.43094977840521, 0.0, 0.0,
110 0.0, 5.4852592761892621, 0.0,
111 0.0, 0.0, 5.43094977840521;
120 ldad_constant_stress_def.write();
122 ldad_trigonometric_stress_def.write();
124 compareStressComponentsToReference(ldad_constant_stress_ref,
"ldad_constant_refReference.stress");
125 compareStressComponentsToReference(ldad_constant_stress_def,
"ldad_constant_defReference.stress");
126 compareStressComponentsToReference(ldad_trigonometric_stress_ref,
"ldad_trigonometric_refReference.stress");
127 compareStressComponentsToReference(ldad_trigonometric_stress_def,
"ldad_trigonometric_defReference.stress");
int calculateStress(const BoxConfiguration &body, Kim &kim, std::tuple<> stress, const bool &projectForces=false)
Represents a particle configuration including simulation box information.
void read(std::string configFileName, int referenceAndFinal)
A function to read the properties of atoms from a file in a MDStressLab format.
Lattice-dependent averaging-domain method.
Three-dimensional stress field on a grid.
std::vector< Matrix3d > field
A three-dimensional stress field.
#define MY_ERROR(message)
Eigen::Matrix< double, DIM, DIM, Eigen::RowMajor > Matrix3d