QMCPACK
CrystalLattice.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
12 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
13 //
14 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
15 //////////////////////////////////////////////////////////////////////////////////////
16 
17 
18 /**@file CrystalLattice.cpp
19  *@brief Member function definitions of CrystalLattice<T,D>, included by CrystalLattice.h
20  */
21 #include "LatticeAnalyzer.h"
22 
23 namespace qmcplusplus
24 {
25 /*! \fn CrystalLattice::CrystalLattice()
26  * Default constructor. Initialized to a \p 1x1x1 cubic supercell.
27  */
28 template<class T, unsigned D>
30 {
31  explicitly_defined = false;
32  BoxBConds = 0;
33  VacuumScale = 1.0;
34  R.diagonal(1e10);
35  G = R;
36  M = R;
37  Volume = 1;
38  reset();
39 }
40 
41 template<class T, unsigned D>
42 template<class TT>
44 {
45  explicitly_defined = true;
46  R = lat;
47  reset();
48 }
49 
50 template<class T, unsigned D>
52 {
53  G = inverse(R); //G = transpose(Inverse(R));
54  Gt = transpose(G);
55  Volume = std::abs(det(R));
56  //M = dot(transpose(R),R);
57  M = dot(R, transpose(R));
58  T t = TWOPI * TWOPI;
59  Mg = t * dot(transpose(G), G);
60  for (int i = 0; i < D; ++i)
61  for (int j = 0; j < D; ++j)
62  Rv[i][j] = R(i, j);
63  for (int i = 0; i < D; ++i)
64  for (int j = 0; j < D; ++j)
65  Gv[i][j] = G(j, i);
66  for (int i = 0; i < D; ++i)
67  {
68  Length[i] = std::sqrt(dot(Rv[i], Rv[i]));
69  OneOverLength[i] = 1.0 / Length[i];
70  }
71  Center = 0.0;
72  for (int i = 0; i < D; ++i)
73  Center += Rv[i];
74  Center *= .5;
75  //analysis of a lattice using LatticeAnalyzer
77  SuperCellEnum = ldesc(BoxBConds);
78  DiagonalOnly = ldesc.isDiagonalOnly(R);
79  ABC = ldesc.calcSolidAngles(Rv, OneOverLength);
80  WignerSeitzRadius = ldesc.calcWignerSeitzRadius(Rv);
81  WignerSeitzRadius_G = ldesc.calcWignerSeitzRadius(Gv);
82  SimulationCellRadius = ldesc.calcSimulationCellRadius(Rv);
83  // set equal WignerSeitzRadius and SimulationCellRadius when they are very close.
84  if (WignerSeitzRadius > SimulationCellRadius &&
85  WignerSeitzRadius - SimulationCellRadius <= WignerSeitzRadius * std::numeric_limits<float>::epsilon() * 2)
86  WignerSeitzRadius = SimulationCellRadius;
87  CellRadiusSq = SimulationCellRadius * SimulationCellRadius;
88 }
89 
90 /*! \fn CrystalLattice<T,D>::operator*=(T sc)
91  * \param sc A scaling factor.
92  * \brief Rescale this supercell by a scalar.
93  */
94 template<class T, unsigned D>
96 {
97  R *= sc;
98  reset();
99  return *this;
100 }
101 
102 template<class T, unsigned D>
103 void CrystalLattice<T, D>::print(std::ostream& os, int level) const
104 {
105  /*\note level == 0: print only the lattice vectors
106  * level == 1: lattice vectors, boundary conditions, grid
107  * level == 2: + all the internal values
108  */
109  std::string unit_name = "bohr";
110 
111  std::string lattice_name = " Lattice (" + unit_name + "):";
112  std::string pad(lattice_name.length(), ' ');
113  os << lattice_name;
114  for (int i = 0; i < D; ++i)
115  {
116  if (i > 0)
117  {
118  os << pad;
119  }
120  os << Rv[i] << std::endl;
121  }
122  if (level > 0)
123  {
124  os << std::endl;
125  os << " Boundary Conditions: ";
126  for (int i = 0; i < D; ++i)
127  {
128  if (BoxBConds[i])
129  os << " p ";
130  else
131  os << " n ";
132  }
133  os << std::endl;
134  if (VacuumScale != 1.0)
135  os << " Vacuum scale: " << VacuumScale << std::endl;
136  }
137  if (level > 1)
138  {
139  os << std::endl;
140  os << " Volume (bohr^3) = " << Volume << std::endl;
141  os << std::endl;
142  os << " Reciprocal vectors without 2*pi.\n";
143  for (int i = 0; i < D; ++i)
144  os << " g_" << i + 1 << " = " << Gv[i] << std::endl;
145  os << std::endl;
146  os << " Metric tensor in real-space.\n";
147  for (int i = 0; i < D; ++i)
148  {
149  os << " h_" << i + 1 << " = ";
150  for (int j = 0; j < D; ++j)
151  {
152  os << M(i, j) << " ";
153  }
154  os << std::endl;
155  }
156  os << std::endl;
157  os << " Metric tensor in g-space.\n";
158  for (int i = 0; i < D; ++i)
159  {
160  os << " h_" << i + 1 << " = ";
161  for (int j = 0; j < D; ++j)
162  {
163  os << Mg(i, j) << " ";
164  }
165  os << std::endl;
166  }
167  }
168 }
169 
170 template<class T, unsigned D>
171 inline bool operator==(const CrystalLattice<T, D>& lhs, const CrystalLattice<T, D>& rhs)
172 {
173  for (int i = 0; i < D * D; ++i)
174  if (std::abs(lhs.R[i] - rhs.R[i]) > std::numeric_limits<T>::epsilon())
175  return false;
176  return true;
177 }
178 
179 template<class T, unsigned D>
180 inline bool operator!=(const CrystalLattice<T, D>& lhs, const CrystalLattice<T, D>& rhs)
181 {
182  return !(lhs == rhs);
183 }
184 
185 } // namespace qmcplusplus
void set(const Tensor< TT, D > &lat)
set the lattice vector from the command-line options
a class that defines a supercell in D-dimensional Euclean space.
void reset()
Evaluate the reciprocal vectors, volume and metric tensor.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
Definition: TensorOps.h:838
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
bool operator==(const Matrix< T, Alloc > &lhs, const Matrix< T, Alloc > &rhs)
Definition: OhmmsMatrix.h:388
CrystalLattice< T, D > & operator*=(T sc)
scale the lattice vectors by sc.
void print(std::ostream &, int level=2) const
Print out CrystalLattice Data.
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
AntiSymTensor< T, D > transpose(const AntiSymTensor< T, D > &rhs)
CrystalLattice()
default constructor, assign a huge supercell
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
generic class to analyze a Lattice
Tensor< T, D > inverse(const Tensor< T, D > &a)
Definition: TensorOps.h:879
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
Tensor_t R
Real-space unit vectors. R(i,j) i=vector and j=x,y,z.
bool operator!=(const Matrix< T, Alloc > &lhs, const Matrix< T, Alloc > &rhs)
Definition: OhmmsMatrix.h:403