oILAB
Loading...
Searching...
No Matches
testPlaneParallelLatticeDirections.cpp

This example demonstrates the computation of plane-parallel lattice basis and direction-orthogonal reciprocal lattice basis for a random reciprocal lattice direction and a random lattice direction, respectively.

  1. Set up the random number distribution for generating random input reciprocal and lattice directions
    std::random_device rd; // obtain a random number from hardware
    std::mt19937 gen(rd()); // seed the generator
    std::uniform_int_distribution<> distr(-10, 10); // define the range
  2. Instantiate a lattice
    const int dim= 5;
    Eigen::Matrix<double,dim,dim> A;
    A.setIdentity();
    std::cout << "Testing in dimension = " << dim << std::endl;
    Lattice<dim> lat(A);
  3. Form random reciprocal lattice and lattice directions
    Eigen::Vector<IntScalarType,dim> millerIndices;
    for (auto& element : millerIndices)
    element= distr(gen);
    millerIndices<< -3, 10, 9, -1, -9;
    ReciprocalLatticeDirection<dim> rDir(ReciprocalLatticeVector<dim>(millerIndices,lat));
    Eigen::Vector<IntScalarType,dim> latticeCoordinates;
    for (auto& element : latticeCoordinates)
    element= distr(gen);
    LatticeDirection<dim> lDir(LatticeVector<dim>(latticeCoordinates,lat));
  4. Compute the plane-parallel lattice basis
    auto directions= lat.planeParallelLatticeBasis(rDir,false);
    std::cout << "Plane parallel lattice basis: " << std::endl;
    for (auto it= directions.begin(); it!=directions.end(); ++it)
    {
    std::cout << it->latticeVector().transpose() << std::endl;
    }
  5. Test the plane-parallel lattice basis
    try {
    for (auto it = directions.begin(); it != directions.end(); ++it) {
    if (it == directions.begin())
    {
    if (rDir.dot(*it) != 1)
    throw std::runtime_error("The dot product of the input reciprocal vector and the first basis vector is not +1 or -1\n");
    }
    else
    {
    if (rDir.dot(*it) != 0)
    throw std::runtime_error(
    "One of the plane-parallel basis vector is not perpendicular to the input reciprocal lattice direction\n");
    }
    }
    }
  6. Compute the direction-orthogonal reciprocal lattice basis
    auto reciprocalDirections= lat.directionOrthogonalReciprocalLatticeBasis(lDir,false);
    std::cout << "Direction orthogonal reciprocal basis: " << std::endl;
    for (auto it= reciprocalDirections.begin(); it!=reciprocalDirections.end(); ++it)
    {
    std::cout << *it << std::endl;
    }
  7. Test the direction-orthogonal reciprocal lattice basis
    try {
    for (auto it = reciprocalDirections.begin(); it != reciprocalDirections.end(); ++it) {
    if (it == reciprocalDirections.begin())
    {
    if (lDir.dot(*it) != 1)
    throw std::runtime_error("The dot product of the input lattice direction and the first reciprocal basis vector is not +1 or -1\n");
    }
    else
    {
    if (lDir.dot(*it) != 0)
    throw std::runtime_error(
    "One of the direction-orthogonal reciprocal basis vector is not perpendicular to the input lattice direction\n");
    }
    }
    }

Full Code:

#include <TextFileParser.h>
#include <LatticeModule.h>
#include <random>
using namespace gbLAB;
int main()
{
using IntScalarType= long long int;
std::random_device rd; // obtain a random number from hardware
std::mt19937 gen(rd()); // seed the generator
std::uniform_int_distribution<> distr(-10, 10); // define the range
const int dim= 5;
Eigen::Matrix<double,dim,dim> A;
A.setIdentity();
std::cout << "Testing in dimension = " << dim << std::endl;
Lattice<dim> lat(A);
Eigen::Vector<IntScalarType,dim> millerIndices;
for (auto& element : millerIndices)
element= distr(gen);
millerIndices<< -3, 10, 9, -1, -9;
Eigen::Vector<IntScalarType,dim> latticeCoordinates;
for (auto& element : latticeCoordinates)
element= distr(gen);
LatticeDirection<dim> lDir(LatticeVector<dim>(latticeCoordinates,lat));
std::cout << "Input Miller index:" << rDir << std::endl;
auto directions= lat.planeParallelLatticeBasis(rDir,false);
std::cout << "Plane parallel lattice basis: " << std::endl;
for (auto it= directions.begin(); it!=directions.end(); ++it)
{
std::cout << it->latticeVector().transpose() << std::endl;
}
try {
for (auto it = directions.begin(); it != directions.end(); ++it) {
if (it == directions.begin())
{
if (rDir.dot(*it) != 1)
throw std::runtime_error("The dot product of the input reciprocal vector and the first basis vector is not +1 or -1\n");
}
else
{
if (rDir.dot(*it) != 0)
throw std::runtime_error(
"One of the plane-parallel basis vector is not perpendicular to the input reciprocal lattice direction\n");
}
}
}
catch (std::runtime_error& e){
std::cout << e.what() << std::endl;
return -1;
}
std::cout << "----------------------------------------------------" << std::endl;
// test the member function directionOrthogonalReciprocalLatticeBasis function
std::cout << "Input lattice direction :" << lDir.latticeVector().transpose() << std::endl;
auto reciprocalDirections= lat.directionOrthogonalReciprocalLatticeBasis(lDir,false);
std::cout << "Direction orthogonal reciprocal basis: " << std::endl;
for (auto it= reciprocalDirections.begin(); it!=reciprocalDirections.end(); ++it)
{
std::cout << *it << std::endl;
}
try {
for (auto it = reciprocalDirections.begin(); it != reciprocalDirections.end(); ++it) {
if (it == reciprocalDirections.begin())
{
if (lDir.dot(*it) != 1)
throw std::runtime_error("The dot product of the input lattice direction and the first reciprocal basis vector is not +1 or -1\n");
}
else
{
if (lDir.dot(*it) != 0)
throw std::runtime_error(
"One of the direction-orthogonal reciprocal basis vector is not perpendicular to the input lattice direction\n");
}
}
}
catch (std::runtime_error& e){
std::cout << e.what() << std::endl;
return -1;
}
return 0;
}
Lattice class.
Definition Lattice.h:34
std::vector< ReciprocalLatticeDirection< dim > > directionOrthogonalReciprocalLatticeBasis(const LatticeDirection< dim > &l, const bool &useRLLL=false) const
Given a lattice direction , this function returns a direction-orthogonal reciprocal lattice basis ,...
Definition Lattice.cpp:235
std::vector< LatticeDirection< dim > > planeParallelLatticeBasis(const ReciprocalLatticeDirection< dim > &l, const bool &useRLLL=false) const
Given a reciprocal lattice direction , this function returns a plane-parallel lattice basis ,...
Definition Lattice.cpp:169
LatticeVector class.
IntScalarType dot(const ReciprocalLatticeVector< dim > &other) const
IntScalarType dot(const LatticeVector< dim > &other) const
int main(int argc, char **argv)
Definition main.cpp:11
LatticeDirection class.
const LatticeVector< dim > & latticeVector() const