oILAB
Loading...
Searching...
No Matches
testLattice.cpp

This example demonstrates the use of Lattice class

  1. Initializing a lattice
    Eigen::Matrix3d A;
    A << 0.5, 0.5, 0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.5;
    Lattice<3> L(A);
    std::cout << "Lattice basis:" << std::endl;
    std::cout << L.latticeBasis << std::endl;
    std::cout << "Reciprocal lattice basis:" << std::endl;
    std::cout << L.reciprocalBasis << std::endl;
  2. Initializing a lattice vector
    std::cout << "Creating a zero lattice vector u:" << std::endl;
    LatticeVector<3> u(L);
    std::cout << u << std::endl;
    1. Modifying its integer coordinates
      std::cout << "Modifying u:" << std::endl;
      u << 2, 1, 3;
      std::cout << u << std::endl;
      std::cout << "Cartesian coordinates of u:" << std::endl;
      std::cout << u.cartesian() << std::endl;
      std::cout << "Recover lattice vector from its cartesian components:";
      std::cout << L.latticeVector(u.cartesian()) << std::endl;
    2. Initializing using Cartesian coordinates
      std::cout << "Create a lattice vector using cartesian coordinates: 1.5,2,3.5"
      << std::endl;
      Eigen::Vector3d vCoords;
      vCoords << 1.5, 2, 3.5;
      LatticeVector<3> v(vCoords, L);
      std::cout << "Integer coordinates of v:" << std::endl;
      std::cout << v << std::endl;
    3. Initializing using Cartesian coordinates may fail if they don't describe a lattice point
      try {
      // This fails
      Eigen::Vector3d wCoords;
      wCoords << 1.8, 2, 3.5;
      LatticeVector<3> w(wCoords, L);
      } catch (std::runtime_error &e) {
      std::cout << e.what() << std::endl;
      }
  3. Lattice vector algebra
    v << 1, 1, 2;
    LatticeVector<3> w = 2 * u + 6 * v;
    std::cout << "Integer coordinates of w:" << std::endl;
    std::cout << w << std::endl;
    std::cout << "Cartesian coordinates of w:" << std::endl;
    std::cout << w.cartesian() << std::endl;
  4. Lattice direction from a lattice vector
    std::cout << "Lattice direction along w:" << std::endl;
    LatticeDirection<3> wDir(w);
    std::cout << wDir << std::endl;
  5. Creating a reciprocal lattice vector
    std::cout << "Creating a reciprocal lattice vector r:" << std::endl;
    ReciprocalLatticeVector<3> r(L);
    r << 3, 6, 9;
    std::cout << r << std::endl;
    std::cout << "Cartesian coordinates of the reciprocal lattice vector r:"
    << std::endl;
    std::cout << r.cartesian() << std::endl;
  6. Reciprocal lattice direction from a reciprocal lattice vector
    std::cout << "Reciprocal lattice direction along r:" << std::endl;
    ReciprocalLatticeDirection<3> s(r);
    std::cout << s << std::endl;
  7. Get reciprocal lattice vector from a reciprocal lattice direction. This may be required to access functions that accept a vector as an input.
    std::cout << "Recover the reciprocal lattice vector from the reciprocal "
    "lattice direction s:"
    << std::endl;
    ReciprocalLatticeVector<3> t = s.reciprocalLatticeVector();
    std::cout << t << std::endl;
  8. Get a lattice direction along a given cartesian vector. CAUTION: This will fail if the cartesian vector is not a lattice vector.
    LatticeDirection<3> latticeDirectionAlong_s =
    L.latticeDirection(s.cartesian());
    std::cout << "Lattice direction along s = " << std::endl;
    std::cout << latticeDirectionAlong_s << std::endl;
  9. Get the stacking along a lattice plane
    std::cout << "Stacking of the lattice plane described by s = " << s.stacking()
    << std::endl;
  10. The cross product of two lattice vectors is a reciprocal lattice direction. Similarly, the cross product of two reciprocal lattice vectors is a lattice direction. The cross product is enabled only for dim=3
    ReciprocalLatticeDirection<3> uxv(u.cross(v));
    std::cout << "The cross product of the lattice vectors u and v is a lattice "
    "direction: "
    << uxv << std::endl;
    ReciprocalLatticeVector<3> q(L);
    q << 7, 9, 11;
    std::cout << "Reciprocal lattice vector q = " << std::endl;
    std::cout << q << std::endl;
    LatticeDirection<3> qxr(q.cross(r));
    std::cout << "The cross product of two reciprocal lattice vectors q and r is "
    "a lattice direction: "
    << qxr << std::endl;
  11. Output a configuration of lattice points bounded by three lattice vectors (named boxVectors) of a 3D lattice.
    std::vector<LatticeVector<3>> boxVectors;
    boxVectors.push_back(LatticeVector<3>(u, L));
    boxVectors.push_back(LatticeVector<3>(v, L));
    boxVectors.push_back(
    LatticeVector<3>(latticeDirectionAlong_s.latticeVector(), L));
    std::cout << "Outputting a configuration of lattice points bounded by three "
    "box vectors: "
    << std::endl;
    for (const auto &vector : boxVectors)
    std::cout << vector.cartesian().transpose() << std::endl;
    L.box(boxVectors, "lattice.txt");
  12. Create a 2D lattice and output its lattice points bounded by two lattice vectors (named boxVectors) of a 2D lattice.
    Eigen::Matrix2d B;
    B << 1.0, 0.0, 0.5, 1.0;
    Lattice<2> L2(B);
    LatticeVector<2> b1(L2);
    b1 << 1, 13;
    LatticeVector<2> b2(L2);
    b2 << 2, 7;
    std::cout << "Outputting a configuration of lattice points bounded by two "
    "box vectors: "
    << std::endl;
    std::cout << b1.cartesian().transpose() << std::endl;
    std::cout << b2.cartesian().transpose() << std::endl;
    L2.box(std::vector<LatticeVector<2>>{-1 * b1, b2}, "lattice2.txt");

Full code:

#include "../../include/Lattices/LatticeModule.h"
#include <fstream>
#include <vector>
using namespace oILAB;
int main() {
Eigen::Matrix3d A;
A << 0.5, 0.5, 0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.5;
Lattice<3> L(A);
std::cout << "Lattice basis:" << std::endl;
std::cout << L.latticeBasis << std::endl;
std::cout << "Reciprocal lattice basis:" << std::endl;
std::cout << L.reciprocalBasis << std::endl;
std::cout << "Creating a zero lattice vector u:" << std::endl;
std::cout << u << std::endl;
std::cout << "Modifying u:" << std::endl;
u << 2, 1, 3;
std::cout << u << std::endl;
std::cout << "Cartesian coordinates of u:" << std::endl;
std::cout << u.cartesian() << std::endl;
std::cout << "Recover lattice vector from its cartesian components:";
std::cout << L.latticeVector(u.cartesian()) << std::endl;
std::cout << "Create a lattice vector using cartesian coordinates: 1.5,2,3.5"
<< std::endl;
Eigen::Vector3d vCoords;
vCoords << 1.5, 2, 3.5;
LatticeVector<3> v(vCoords, L);
std::cout << "Integer coordinates of v:" << std::endl;
std::cout << v << std::endl;
try {
// This fails
Eigen::Vector3d wCoords;
wCoords << 1.8, 2, 3.5;
LatticeVector<3> w(wCoords, L);
} catch (std::runtime_error &e) {
std::cout << e.what() << std::endl;
}
v << 1, 1, 2;
LatticeVector<3> w = 2 * u + 6 * v;
std::cout << "Integer coordinates of w:" << std::endl;
std::cout << w << std::endl;
std::cout << "Cartesian coordinates of w:" << std::endl;
std::cout << w.cartesian() << std::endl;
std::cout << "Lattice direction along w:" << std::endl;
std::cout << wDir << std::endl;
std::cout << "Creating a reciprocal lattice vector r:" << std::endl;
r << 3, 6, 9;
std::cout << r << std::endl;
std::cout << "Cartesian coordinates of the reciprocal lattice vector r:"
<< std::endl;
std::cout << r.cartesian() << std::endl;
std::cout << "Reciprocal lattice direction along r:" << std::endl;
std::cout << s << std::endl;
std::cout << "Recover the reciprocal lattice vector from the reciprocal "
"lattice direction s:"
<< std::endl;
std::cout << t << std::endl;
LatticeDirection<3> latticeDirectionAlong_s =
std::cout << "Lattice direction along s = " << std::endl;
std::cout << latticeDirectionAlong_s << std::endl;
std::cout << "Stacking of the lattice plane described by s = " << s.stacking()
<< std::endl;
std::cout << "The cross product of the lattice vectors u and v is a lattice "
"direction: "
<< uxv << std::endl;
q << 7, 9, 11;
std::cout << "Reciprocal lattice vector q = " << std::endl;
std::cout << q << std::endl;
std::cout << "The cross product of two reciprocal lattice vectors q and r is "
"a lattice direction: "
<< qxr << std::endl;
std::vector<LatticeVector<3>> boxVectors;
boxVectors.push_back(LatticeVector<3>(u, L));
boxVectors.push_back(LatticeVector<3>(v, L));
boxVectors.push_back(
LatticeVector<3>(latticeDirectionAlong_s.latticeVector(), L));
std::cout << "Outputting a configuration of lattice points bounded by three "
"box vectors: "
<< std::endl;
for (const auto &vector : boxVectors)
std::cout << vector.cartesian().transpose() << std::endl;
L.box(boxVectors, "lattice.txt");
Eigen::Matrix2d B;
B << 1.0, 0.0, 0.5, 1.0;
Lattice<2> L2(B);
b1 << 1, 13;
b2 << 2, 7;
std::cout << "Outputting a configuration of lattice points bounded by two "
"box vectors: "
<< std::endl;
std::cout << b1.cartesian().transpose() << std::endl;
std::cout << b2.cartesian().transpose() << std::endl;
L2.box(std::vector<LatticeVector<2>>{-1 * b1, b2}, "lattice2.txt");
return 0;
}
Lattice class.
Definition Lattice.h:31
LatticeDirection< dim > latticeDirection(const VectorDimD &d, const double &tol=FLT_EPSILON) const
Returns the lattice direction along a vector.
Definition Lattice.cpp:54
LatticeVector< dim > latticeVector(const VectorDimD &p) const
Returns a lattice vector (in the current lattice) with Cartesian coordinates p.
Definition Lattice.cpp:153
const MatrixDimD reciprocalBasis
Definition Lattice.h:42
std::enable_if< dm==3, std::vector< LatticeVector< dim > > >::type box(const std::vector< LatticeVector< dim > > &boxVectors, const std::string &filename="") const
Definition Lattice.cpp:465
const MatrixDimD latticeBasis
Definition Lattice.h:41
LatticeVector class.
std::enable_if< dm==2, ReciprocalLatticeDirection< dm > >::type cross(const LatticeVector< dm > &other) const
VectorDimD cartesian() const
std::enable_if< dm==2, LatticeDirection< dim > >::type cross(const ReciprocalLatticeVector< dim > &other) const
int main(int argc, char **argv)
Definition main.cpp:12
LatticeDirection class.
const LatticeVector< dim > & latticeVector() const
const ReciprocalLatticeVector< dim > & reciprocalLatticeVector() const
Returns a constant reference to the base class (ReciprocalLatticeVector)
int stacking() const
Returns the number of planes in the stacking sequence.