An example demonstrating the computation of Piola and Cauchy stress tensors using hardy and virial spherical averaging domains, and 1D and 2D grids
- Open the configuration file (*.data in MDStressLab format) and read the number of particles
21 int numberOfParticles;
22 int referenceAndFinal=
true;
23 std::string configFileName=
"config.data";
24 std::ifstream file(configFileName);
25 if(!file)
MY_ERROR(
"ERROR: config.data could not be opened for reading!\n");
26 file >> numberOfParticles;
27 if (numberOfParticles < 0)
MY_ERROR(
"Error: Negative number of particles.\n");
#define MY_ERROR(message)
- Initialize the BoxConfiguration and read the reference and current atomic coordinates from the configuration file. The reference configuration is an fcc Ar crystal in the relaxed state. The deformed/current configuration is the reference crystal strained in the \(y\)-direction.
32 body.
read(configFileName,referenceAndFinal);
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.
- Initialize the Kim model
36 std::string modelname=
"LJ_Smoothed_Bernardes_1958_Ar__MO_764178710049_001";
- Create 1D and 2D grids
Eigen::Matrix< double, 1, DIM, Eigen::RowMajor > Vector3d
- Construct hardy and virial MethodSphere objects
Implements radially symmetric weighting functions (Hardy, Virial) and its associated bond function fo...
- Construct Stress objects using the MethodSphere and Grid objects
- Calculate stresses. The following snippet shows that stresses can be calculated all at once or with various combinations.
69 std::tie(hardyCauchy));
72 std::tie(virialPiola));
75 std::tie(hardyPiola,virialPiola),
76 std::tie(hardyCauchy,virialCauchy));
int calculateStress(const BoxConfiguration &body, Kim &kim, std::tuple<> stress, const bool &projectForces=false)
- Write stresses
- We compare our results with the exact results for unit testing purposes.
88 compareStress(
"hardyCauchy");
89 compareStress(
"hardyPiola");
90 compareStress(
"virialCauchy");
91 compareStress(
"virialPiola");
Visual comparison
Full code:
16#include "../compareStress.cpp"
21 int numberOfParticles;
22 int referenceAndFinal=
true;
23 std::string configFileName=
"config.data";
24 std::ifstream file(configFileName);
25 if(!file)
MY_ERROR(
"ERROR: config.data could not be opened for reading!\n");
26 file >> numberOfParticles;
27 if (numberOfParticles < 0)
MY_ERROR(
"Error: Negative number of particles.\n");
32 body.
read(configFileName,referenceAndFinal);
36 std::string modelname=
"LJ_Smoothed_Bernardes_1958_Ar__MO_764178710049_001";
69 std::tie(hardyCauchy));
72 std::tie(virialPiola));
75 std::tie(hardyPiola,virialPiola),
76 std::tie(hardyCauchy,virialCauchy));
88 compareStress(
"hardyCauchy");
89 compareStress(
"hardyPiola");
90 compareStress(
"virialCauchy");
91 compareStress(
"virialPiola");