A parallel C++ Library for Simulations in the Heisenberg Model
grid.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <cmath>
5 #include <cstdlib>
6 #include <ctime>
7 #include <iostream>
8 #include <hdf5.h>
9 #include <random>
10 
11 #include <cuda_runtime.h>
12 #include <thrust/host_vector.h>
13 #include <thrust/device_vector.h>
14 
15 namespace HB
16 {
18  typedef struct {
19  size_t up;
20  size_t right;
21  size_t back;
22  size_t down;
23  size_t left;
24  size_t front;
25  }NB;
26 
28  typedef struct {
29  float phi;
30  float theta;
31  }Spin;
32 
34  template<class T>
35  class Grid
36  {
37  public:
38  Grid() = default;
39 
40  /*****************************************************************/
43  Grid(const short int spatialDimensions, const dim3 gridSize) : mDim(dim), mGridSize(gridSize)
44  {
45  mGridData.resize(gridSize.x*gridSize.y*gridSize.z);
46  };
47 
48  /*******************************************************************/
53 
54  /*****************************************************************/
57  void setGridSize(const dim3 gridSize)
58  {
59  mGridSize = gridSize;
60 
61  mGridData.resize(gridSize.x*gridSize.y*gridSize.z);
62  }
63 
64  dim3 getGridSize() const
65  {
66  return mGridSize;
67  }
68 
69  thrust::host_vector<T> getGridData() const
70  {
71  return mGridData;
72  }
73 
74  void setGridData(const thrust::host_vector<T> &gridData)
75  {
76  mGridData = gridData;
77  }
78 
79  thrust::host_vector<NB> getNeighbourTable() const
80  {
81  return mNeighbourTable;
82  }
83 
84  void setNeighbourTable(const thrust::host_vector<NB> &neighbourTable)
85  {
86  mNeighbourTable = neighbourTable;
87  }
88 
89  T getSpin(const dim3 index) const
90  {
91  size_t idx = index.x*mGridSize.x +
92  index.y*mGridSize.x*mGridSize.y +
93  index.z;
94  return mGridData[idx];
95  }
96 
97  void setSpin(const dim3 index, const T spin)
98  {
99  size_t idx = index.x*mGridSize.x +
100  index.y*mGridSize.x*mGridSize.y +
101  index.z;
102  mGridData[idx] = spin;
103  }
104 
105  NB getNeighbours(const dim3 index) const
106  {
107  size_t idx = index.x*mGridSize.x +
108  index.y*mGridSize.x*mGridSize.y +
109  index.z;
110  return mNeighbourTable[idx];
111  }
112 
113  short int getDim() const {return mDim;}
114 
115  void setDim(const short int dim) {mDim = dim;}
116 
117  /*****************************************************************/
120  void hotStart();
121 
122  /*****************************************************************/
126  void coldStart();
127 
128  /************************************************************************************************/
133  herr_t saveGrid(const std::string path);
134 
135  /************************************************************************************************/
138  /*void upload(Grid<T> &deviceGrid)
139  {
140  deviceGrid.setGridData(mGridData);
141  deviceGrid.setNeighbourTable(mNeighbourTable);
142  }*/
143 
144  /************************************************************************************************/
147  /*void download(Grid<T> &deviceGrid)
148  {
149  mGridData = deviceGrid.getGridData();
150  }*/
151 
152  private:
153  dim3 mGridSize;
154  short int mDim;
155  thrust::host_vector<T> mGridData;
156  thrust::host_vector<NB> mNeighbourTable;
157  };
158 }
HB::NB::up
size_t up
Definition: grid.h:19
HB::Grid::calcNeighbourTable
void calcNeighbourTable()
generates a table of the neighbouring points of each spin and stores it
HB::NB
A struct containing six neighbour inidices of a spin in three dimensions.
Definition: grid.h:18
HB::Grid::setSpin
void setSpin(const dim3 index, const T spin)
Definition: grid.h:97
HB::NB::left
size_t left
Definition: grid.h:23
HB::Grid::getSpin
T getSpin(const dim3 index) const
Definition: grid.h:89
HB::Grid::setGridSize
void setGridSize(const dim3 gridSize)
sets grid size nad resizes grid
Definition: grid.h:57
HB::Grid::mGridData
thrust::host_vector< T > mGridData
Definition: grid.h:155
HB::NB::front
size_t front
Definition: grid.h:24
HB::Grid::mDim
short int mDim
Definition: grid.h:154
HB::Grid::setNeighbourTable
void setNeighbourTable(const thrust::host_vector< NB > &neighbourTable)
Definition: grid.h:84
HB::Grid::setDim
void setDim(const short int dim)
Definition: grid.h:115
HB::Grid::getGridSize
dim3 getGridSize() const
Definition: grid.h:64
HB::Grid::getGridData
thrust::host_vector< T > getGridData() const
Definition: grid.h:69
HB::Grid::Grid
Grid(const short int spatialDimensions, const dim3 gridSize)
constructs a grid and allocates memory
Definition: grid.h:43
HB::Grid::getNeighbourTable
thrust::host_vector< NB > getNeighbourTable() const
Definition: grid.h:79
HB::Grid::Grid
Grid()=default
HB::Grid::hotStart
void hotStart()
initializes all spins randomly between 0 and 2*pi
HB::Grid::coldStart
void coldStart()
initializes all spins as up, i.e. mGrid.x[...] = 0.5*pi and mGrid.y[...] = 0
HB::Spin
A class storing spin values represented by two angles.
Definition: grid.h:28
HB::NB::down
size_t down
Definition: grid.h:22
HB::NB::right
size_t right
Definition: grid.h:20
HB
Definition: grid.h:16
HB::Spin::phi
float phi
Definition: grid.h:29
HB::Grid::setGridData
void setGridData(const thrust::host_vector< T > &gridData)
Definition: grid.h:74
HB::Grid
A class storing spin values as a grid and certain meta information.
Definition: grid.h:36
HB::NB::back
size_t back
Definition: grid.h:21
HB::Spin::theta
float theta
Definition: grid.h:30
HB::Grid::saveGrid
herr_t saveGrid(const std::string path)
saves grid as hdf5 file
HB::Grid::mGridSize
dim3 mGridSize
copies grid and table to device
Definition: grid.h:153
HB::Grid::getNeighbours
NB getNeighbours(const dim3 index) const
Definition: grid.h:105
HB::Grid::getDim
short int getDim() const
Definition: grid.h:113
HB::Grid::mNeighbourTable
thrust::host_vector< NB > mNeighbourTable
Definition: grid.h:156