SpinParser  1.0
Lattice.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 #include <array>
11 #include <vector>
12 #include <tuple>
13 #include "lib/Geometry.hpp"
14 #include "lib/Assert.hpp"
15 
16 struct SpinModel;
17 struct Lattice;
18 namespace LatticeModelFactory {
19  struct LatticeUnitCell;
20  struct SpinModelUnitCell;
21 
22  std::pair<Lattice *, SpinModel *> newLatticeModel(const LatticeModelFactory::LatticeUnitCell &uc, const LatticeModelFactory::SpinModelUnitCell &spinModelDefinition, const int latticeRange, const std::string &ldfPath);
23 };
24 
28 enum struct SpinComponent : int
29 {
30  X = 0,
31  Y = 1,
32  Z = 2,
33  None = 3
34 };
35 
47 {
48  friend std::pair<Lattice *, SpinModel *> LatticeModelFactory::newLatticeModel(const LatticeModelFactory::LatticeUnitCell &uc, const LatticeModelFactory::SpinModelUnitCell &spinModelDefinition, const int latticeRange, const std::string &ldfPath);
49  friend struct Lattice;
50 
51 public:
52  LatticeOverlap() : rid1(nullptr), rid2(nullptr), transformedX1(nullptr), transformedY1(nullptr), transformedZ1(nullptr), transformedX2(nullptr), transformedY2(nullptr), transformedZ2(nullptr), size(0) {}
53 
59  LatticeOverlap(const int size) : size(size)
60  {
61  rid1 = new int[size];
62  rid2 = new int[size];
63  transformedX1 = new SpinComponent[size];
64  transformedY1 = new SpinComponent[size];
65  transformedZ1 = new SpinComponent[size];
66  transformedX2 = new SpinComponent[size];
67  transformedY2 = new SpinComponent[size];
68  transformedZ2 = new SpinComponent[size];
69  }
70 
77  {
78  memcpy(rid1, rhs.rid1, size * sizeof(int));
79  memcpy(rid2, rhs.rid2, size * sizeof(int));
80  memcpy(transformedX1, rhs.transformedX1, size * sizeof(SpinComponent));
81  memcpy(transformedY1, rhs.transformedY1, size * sizeof(SpinComponent));
82  memcpy(transformedZ1, rhs.transformedZ1, size * sizeof(SpinComponent));
83  memcpy(transformedX2, rhs.transformedX2, size * sizeof(SpinComponent));
84  memcpy(transformedY2, rhs.transformedY2, size * sizeof(SpinComponent));
85  memcpy(transformedZ2, rhs.transformedZ2, size * sizeof(SpinComponent));
86  }
87 
88  int *rid1;
89  int *rid2;
90  SpinComponent *transformedX1;
91  SpinComponent *transformedY1;
92  SpinComponent *transformedZ1;
93  SpinComponent *transformedX2;
94  SpinComponent *transformedY2;
95  SpinComponent *transformedZ2;
96  int size;
97 
98 protected:
103  {
104  delete[] rid1;
105  delete[] rid2;
106  delete[] transformedX1;
107  delete[] transformedY1;
108  delete[] transformedZ1;
109  delete[] transformedX2;
110  delete[] transformedY2;
111  delete[] transformedZ2;
112  }
113 
121  {
122  size = rhs.size;
123  delete[] rid1;
124  rid1 = new int[size];
125  memcpy(rid1, rhs.rid1, size * sizeof(int));
126  delete[] rid2;
127  rid2 = new int[size];
128  memcpy(rid2, rhs.rid2, size * sizeof(int));
129  delete[] transformedX1;
130  transformedX1 = new SpinComponent[size];
131  memcpy(transformedX1, rhs.transformedX1, size * sizeof(SpinComponent));
132  delete[] transformedY1;
133  transformedY1 = new SpinComponent[size];
134  memcpy(transformedY1, rhs.transformedY1, size * sizeof(SpinComponent));
135  delete[] transformedZ1;
136  transformedZ1 = new SpinComponent[size];
137  memcpy(transformedZ1, rhs.transformedZ1, size * sizeof(SpinComponent));
138  delete[] transformedX2;
139  transformedX2 = new SpinComponent[size];
140  memcpy(transformedX2, rhs.transformedX2, size * sizeof(SpinComponent));
141  delete[] transformedY2;
142  transformedY2 = new SpinComponent[size];
143  memcpy(transformedY2, rhs.transformedY2, size * sizeof(SpinComponent));
144  delete[] transformedZ2;
145  transformedZ2 = new SpinComponent[size];
146  memcpy(transformedZ2, rhs.transformedZ2, size * sizeof(SpinComponent));
147 
148  return *this;
149  }
150 };
151 
158 {
159  int rid;
161 };
162 
167 {
168 friend struct Lattice;
169 
170 public:
174  LatticeIterator() : id(0) {}
175 
181  LatticeIterator(int id) : id(id) {}
182 
189  bool operator==(const LatticeIterator &rhs) const
190  {
191  return id == rhs.id;
192  }
193 
200  bool operator!=(const LatticeIterator &rhs) const
201  {
202  return id != rhs.id;
203  }
204 
211  int operator-(const LatticeIterator &rhs) const
212  {
213  return id - rhs.id;
214  }
215 
222  {
223  ++id;
224  return *this;
225  }
226 
233  {
234  --id;
235  return *this;
236  }
237 
238 protected:
239  int id;
240 };
241 
246 {
247 public:
257 
264  {
265  id = allowedIds[++offset];
266  return *this;
267  }
268 
275  {
276  id = allowedIds[--offset];
277  return *this;
278  }
279 
280 protected:
281  int offset;
282  int *allowedIds;
283 };
284 
297 struct Lattice
298 {
299  friend std::pair<Lattice *, SpinModel *> LatticeModelFactory::newLatticeModel(const LatticeModelFactory::LatticeUnitCell &uc, const LatticeModelFactory::SpinModelUnitCell &spinModelDefinition, const int latticeRange, const std::string &ldfPath);
300 
301 protected:
306  Lattice() : size(0), _dataSize(0), _symmetryTable(nullptr), _bufferSites(nullptr), _bufferInvertedSites(nullptr), _bufferOverlapMatrices(nullptr), _bufferBasis(nullptr), _bufferLatticeRange(nullptr) {};
307 
308 public:
313  {
314  delete[] _bufferBasis;
315  for (size_t b = 0; b < _basis.size(); ++b) delete[] _bufferLatticeRange[b];
316  delete[] _bufferLatticeRange;
317  delete[] _symmetryTable;
318  delete[] _bufferSites;
319  delete[] _bufferInvertedSites;
320  delete[] _bufferOverlapMatrices;
321  }
322 
329  {
330  return LatticeIterator(0);
331  }
332 
339  {
340  return LatticeIterator(0);
341  }
342 
349  {
350  return LatticeIterator(_dataSize);
351  }
352 
360  {
361  ASSERT(rid < size);
362  return LatticeIterator(rid);
363  }
364 
371  std::tuple<int, int, int, int> getSiteParameters(const LatticeIterator &site) const
372  {
373  ASSERT(site - begin() < _dataSize);
374  return _geometryTable[site.id];
375  }
376 
384  {
385  ASSERT(site - begin() < _dataSize);
386  return double(std::get<0>(_geometryTable[site.id])) * _bravaisLattice[0] + double(std::get<1>(_geometryTable[site.id])) * _bravaisLattice[1] + double(std::get<2>(_geometryTable[site.id])) * _bravaisLattice[2] + _basis[std::get<3>(_geometryTable[site.id])];
387  }
388 
397  int symmetryTransform(const LatticeIterator& i1, const LatticeIterator& i2) const
398  {
399  ASSERT(_symmetryTable[i1.id * _dataSize + i2.id].rid != -1);
400  return _symmetryTable[i1.id * _dataSize + i2.id].rid;
401  }
402 
412  int symmetryTransform(const LatticeIterator &i1, const LatticeIterator &i2, SpinComponent &spinComponent) const
413  {
414  ASSERT(_symmetryTable[i1.id * _dataSize + i2.id].rid != -1);
415  if (spinComponent != SpinComponent::None) spinComponent = _symmetryTable[i1.id * _dataSize + i2.id].spinPermutation[static_cast<int>(spinComponent)];
416  return _symmetryTable[i1.id * _dataSize + i2.id].rid;
417  }
418 
429  int symmetryTransform(const LatticeIterator &i1, const LatticeIterator &i2, SpinComponent &spinComponent1, SpinComponent &spinComponent2) const
430  {
431  ASSERT(_symmetryTable[i1.id * _dataSize + i2.id].rid != -1);
432  ASSERT(&spinComponent1 != &spinComponent2);
433 
434  if (spinComponent1 != SpinComponent::None) spinComponent1 = _symmetryTable[i1.id * _dataSize + i2.id].spinPermutation[static_cast<int>(spinComponent1)];
435  if (spinComponent2 != SpinComponent::None) spinComponent2 = _symmetryTable[i1.id * _dataSize + i2.id].spinPermutation[static_cast<int>(spinComponent2)];
436  return _symmetryTable[i1.id * _dataSize + i2.id].rid;
437  }
438 
450  int symmetryTransform(const LatticeIterator &i1, const LatticeIterator &i2, SpinComponent &spinComponent1, SpinComponent &spinComponent2, SpinComponent &spinComponent3) const
451  {
452  ASSERT(_symmetryTable[i1.id * _dataSize + i2.id].rid != -1);
453  ASSERT(&spinComponent1 != &spinComponent2);
454  ASSERT(&spinComponent2 != &spinComponent3);
455  ASSERT(&spinComponent1 != &spinComponent3);
456 
457  if (spinComponent1 != SpinComponent::None) spinComponent1 = _symmetryTable[i1.id * _dataSize + i2.id].spinPermutation[static_cast<int>(spinComponent1)];
458  if (spinComponent2 != SpinComponent::None) spinComponent2 = _symmetryTable[i1.id * _dataSize + i2.id].spinPermutation[static_cast<int>(spinComponent2)];
459  if (spinComponent3 != SpinComponent::None) spinComponent3 = _symmetryTable[i1.id * _dataSize + i2.id].spinPermutation[static_cast<int>(spinComponent3)];
460  return _symmetryTable[i1.id * _dataSize + i2.id].rid;
461  }
462 
470  const LatticeOverlap &getOverlap(const int rid) const
471  {
472  ASSERT(rid < size);
473  return _bufferOverlapMatrices[rid];
474  }
475 
482  {
483  return _bufferInvertedSites;
484  }
485 
492  {
493  return _bufferSites;
494  }
495 
504  {
505  ASSERT(std::get<0>(getSiteParameters(b)) == 0);
506  ASSERT(std::get<1>(getSiteParameters(b)) == 0);
507  ASSERT(std::get<2>(getSiteParameters(b)) == 0);
508  ASSERT(std::get<3>(getSiteParameters(b)) < _basis.size());
509 
511  }
512 
519  SublatticeIterator getRange(const int b) const
520  {
521  ASSERT(b < _basis.size());
523  }
524 
531  {
533  }
534 
535  std::vector<geometry::Vec3<double> > _bravaisLattice;
536  std::vector<geometry::Vec3<double> > _basis;
537 
538  int size;
539 
540 protected:
541  std::vector<std::tuple<int, int, int, int>> _geometryTable;
542 
543  int _dataSize;
544 
549 
552 };
ASSERT
#define ASSERT(...)
Ensure that the first argument is true. Optionally provide a message as the second argument,...
Definition: Assert.hpp:26
LatticeSiteDescriptor::spinPermutation
SpinComponent spinPermutation[3]
Spin permutation involved in the transformation.
Definition: Lattice.hpp:160
LatticeOverlap::operator=
LatticeOverlap & operator=(const LatticeOverlap &rhs)
Assignment operator.
Definition: Lattice.hpp:120
Lattice::zero
LatticeIterator zero() const
Retrieve iterator to the lattice site i1=(0,0,0,0).
Definition: Lattice.hpp:338
SublatticeIterator::allowedIds
int * allowedIds
List of representative ids that make up the sublattice. Memory is not owned by the iterator.
Definition: Lattice.hpp:282
LatticeOverlap::~LatticeOverlap
~LatticeOverlap()
Destroy the LatticeOverlap object.
Definition: Lattice.hpp:102
LatticeModelFactory::LatticeUnitCell
Representation of a lattice unit cell.
Definition: LatticeModelFactory.hpp:123
Lattice::~Lattice
~Lattice()
Destroy the Lattice object.
Definition: Lattice.hpp:312
SpinComponent
SpinComponent
Component of a spin operator.
Definition: Lattice.hpp:28
Lattice::symmetryTransform
int symmetryTransform(const LatticeIterator &i1, const LatticeIterator &i2) const
Transform a pair of lattice sites (i1,i2) and transform it to (0,i2'). The transformation may involve...
Definition: Lattice.hpp:397
Lattice::_bufferSites
LatticeSiteDescriptor * _bufferSites
List of transformed sites (0, rid), for all representatives rid.
Definition: Lattice.hpp:546
SpinComponent::None
@ None
No spin component specified.
LatticeIterator::operator--
virtual LatticeIterator & operator--()
Prefix decrement operator.
Definition: Lattice.hpp:232
Lattice::_geometryTable
std::vector< std::tuple< int, int, int, int > > _geometryTable
Internal storage of real space lattice site positions, stored as tuples (a0, a1, a2,...
Definition: Lattice.hpp:541
SublatticeIterator::offset
int offset
Offset relative to the first entry of SublatticeIterator::allowedIds.
Definition: Lattice.hpp:281
SublatticeIterator::SublatticeIterator
SublatticeIterator(int *allowedIds)
Construct a new SublatticeIterator object over a list of representative ids.
Definition: Lattice.hpp:256
SpinComponent::Z
@ Z
z-component of a spin.
SublatticeIterator::operator--
SublatticeIterator & operator--()
Prefix decrement operator.
Definition: Lattice.hpp:274
Lattice::begin
LatticeIterator begin() const
Retrieve iterator to first lattice site.
Definition: Lattice.hpp:328
Lattice::Lattice
Lattice()
Create an uninitialized lattice object.
Definition: Lattice.hpp:306
Lattice::_symmetryTable
LatticeSiteDescriptor * _symmetryTable
List of symmetry reductions of spin pairs (id1, id2) linearized as id1*_dataSize+id2....
Definition: Lattice.hpp:545
Lattice::getSiteParameters
std::tuple< int, int, int, int > getSiteParameters(const LatticeIterator &site) const
Get the coordinates of a specified lattice site, in units of a1, a2, a3, and b.
Definition: Lattice.hpp:371
Lattice::getRange
SublatticeIterator getRange(const int b) const
Retrieve an iterator over all sites which are within range of the lattice site (0,...
Definition: Lattice.hpp:519
Lattice::_dataSize
int _dataSize
Total number of all lattice that we store information about (equivalent to size of Lattice::_geometry...
Definition: Lattice.hpp:543
LatticeOverlap::LatticeOverlap
LatticeOverlap(const int size)
Construct a new LatticeOverlap object for a given number of sites.
Definition: Lattice.hpp:59
LatticeOverlap
Structure to describe the portion of the lattice that is relevant in terms of the form sum_j v(i1,...
Definition: Lattice.hpp:46
geometry::Vec3
Three-dimensional vector.
Definition: Geometry.hpp:21
Lattice::_bufferBasis
int * _bufferBasis
List of representative ids of all basis sites.
Definition: Lattice.hpp:550
LatticeIterator::LatticeIterator
LatticeIterator(int id)
Construct a new LatticeIterator object and initialize it to any representative id.
Definition: Lattice.hpp:181
Lattice::fromParametrization
LatticeIterator fromParametrization(const int rid) const
Retrieve iterator to the specified representative.
Definition: Lattice.hpp:359
LatticeOverlap::LatticeOverlap
LatticeOverlap(const LatticeOverlap &rhs)
Construct a new LatticeOverlap object from an existing one.
Definition: Lattice.hpp:76
Lattice::getBasis
SublatticeIterator getBasis() const
Retrieve iterator over all basis sites.
Definition: Lattice.hpp:530
LatticeIterator::operator++
virtual LatticeIterator & operator++()
Prefix increment operator.
Definition: Lattice.hpp:221
SublatticeIterator::operator++
SublatticeIterator & operator++()
Prefix increment operator.
Definition: Lattice.hpp:263
LatticeIterator::LatticeIterator
LatticeIterator()
Construct a new LatticeIterator object, which points to the representative id 0 per default.
Definition: Lattice.hpp:174
Assert.hpp
Lightweight macro library for assertions.
Lattice::_bufferInvertedSites
LatticeSiteDescriptor * _bufferInvertedSites
List of transformed sites (rid, 0), for all representatives rid.
Definition: Lattice.hpp:547
Geometry.hpp
Implementation of three- and four-dimensional vectors and matrices for geometric operations.
Lattice::getSitePosition
geometry::Vec3< double > getSitePosition(const LatticeIterator &site) const
Get the position of a lattice site in real space.
Definition: Lattice.hpp:383
Lattice::symmetryTransform
int symmetryTransform(const LatticeIterator &i1, const LatticeIterator &i2, SpinComponent &spinComponent) const
Transform a pair of lattice sites (i1,i2) and transform it to (0,i2'). The transformation may involve...
Definition: Lattice.hpp:412
Lattice::getOverlap
const LatticeOverlap & getOverlap(const int rid) const
Retrieve the lattice overlap of the reference site i1=(0,0,0,0) with some other representative lattic...
Definition: Lattice.hpp:470
SpinModel
Spin model representation.
Definition: SpinModel.hpp:19
SublatticeIterator
Sublattice iterator object.
Definition: Lattice.hpp:245
Lattice::_bufferOverlapMatrices
LatticeOverlap * _bufferOverlapMatrices
List of lattice overlaps, where the i-th entry is the overlap of the two tuples (0,...
Definition: Lattice.hpp:548
Lattice::end
LatticeIterator end() const
Retrieve iterator to the last+1 lattice site.
Definition: Lattice.hpp:348
SpinComponent::Y
@ Y
y-component of a spin.
LatticeIterator
Lattice iterator object.
Definition: Lattice.hpp:166
Lattice
Representation of a physical lattice, with symmetry information on two-point correlators.
Definition: Lattice.hpp:297
Lattice::getInvertedSites
const LatticeSiteDescriptor * getInvertedSites() const
List of two-spin correlators (i2,i1), where i1=(0,0,0,0) is the reference site and the list includes ...
Definition: Lattice.hpp:481
LatticeIterator::id
int id
Representative id which the iterator points to.
Definition: Lattice.hpp:239
LatticeModelFactory::newLatticeModel
std::pair< Lattice *, SpinModel * > newLatticeModel(const LatticeModelFactory::LatticeUnitCell &uc, const LatticeModelFactory::SpinModelUnitCell &spinModelDefinition, const int latticeRange, const std::string &ldfPath)
Create and return lattice and spin model objects from given unit cell definitions.
Definition: LatticeModelFactory.cpp:733
LatticeIterator::operator!=
bool operator!=(const LatticeIterator &rhs) const
Negative comparison operator.
Definition: Lattice.hpp:200
Lattice::_basis
std::vector< geometry::Vec3< double > > _basis
List of the positions of all basis sites within a lattice unit cell.
Definition: Lattice.hpp:536
Lattice::size
int size
Number representative sites.
Definition: Lattice.hpp:538
LatticeSiteDescriptor
Structure to specify a symmetry-transformed lattice site.
Definition: Lattice.hpp:157
Lattice::_bravaisLattice
std::vector< geometry::Vec3< double > > _bravaisLattice
List of the three bravais lattice vectors.
Definition: Lattice.hpp:535
Lattice::getSites
const LatticeSiteDescriptor * getSites() const
List of two-spin correlators (i1,i2), where i1=(0,0,0,0) is the reference site and the list includes ...
Definition: Lattice.hpp:491
LatticeIterator::operator-
int operator-(const LatticeIterator &rhs) const
Subtraction operator.
Definition: Lattice.hpp:211
Lattice::_bufferLatticeRange
int ** _bufferLatticeRange
Table of lists of all site ids in range of site (0,0,0,b).
Definition: Lattice.hpp:551
Lattice::symmetryTransform
int symmetryTransform(const LatticeIterator &i1, const LatticeIterator &i2, SpinComponent &spinComponent1, SpinComponent &spinComponent2) const
Transform a pair of lattice sites (i1,i2) and transform it to (0,i2'). The transformation may involve...
Definition: Lattice.hpp:429
LatticeSiteDescriptor::rid
int rid
Representative id of the transformed lattice site.
Definition: Lattice.hpp:159
Lattice::getRange
SublatticeIterator getRange(const LatticeIterator &b) const
Retrieve an iterator over all sites which are within range of the lattice site b, where b must descri...
Definition: Lattice.hpp:503
Lattice::symmetryTransform
int symmetryTransform(const LatticeIterator &i1, const LatticeIterator &i2, SpinComponent &spinComponent1, SpinComponent &spinComponent2, SpinComponent &spinComponent3) const
Transform a pair of lattice sites (i1,i2) and transform it to (0,i2'). The transformation may involve...
Definition: Lattice.hpp:450
LatticeModelFactory::SpinModelUnitCell
Spin model unit cell representation.
Definition: LatticeModelFactory.hpp:209
SpinComponent::X
@ X
x-component of a spin.
LatticeIterator::operator==
bool operator==(const LatticeIterator &rhs) const
Comparison operator.
Definition: Lattice.hpp:189