Path Integral Quantum Monte Carlo
container.h
Go to the documentation of this file.
1 
9 #ifndef CONTAINER_H
10 #define CONTAINER_H
11 
12 #include "common.h"
13 
14 // ========================================================================
15 // Container Class
16 // ========================================================================
24 class Container {
25  public:
26  Container();
27  virtual ~Container();
28 
29  TinyVector <unsigned int, NDIM> periodic;
30 
34 
35  double volume;
36  double rcut2;
37  double maxSep;
38 
39  string name;
40 
41  int numGrid;
43 
45 
50  void putInBC(dVec & r) const {
51  r -= pSide*blitz::floor(r*sideInv + 0.5);
52  /* int k; */
53  /* for (int i = 0; i < NDIM; ++i) { */
54  /* k = int(r[i]*sideInv[i] + ((r[i]>=0.0)?0.5:-0.5)); */
55  /* r[i] -= k*pSide[i]; */
56  /* } */
57  }
58 
59  /* An old version */
60  /* void putInBC1(dVec & r) const { */
61  /* for (int i = 0; i < NDIM; ++i) { */
62  /* r[i] -= (r[i] >= 0.5*side[i])*pSide[i]; */
63  /* r[i] += (r[i] < -0.5*side[i])*pSide[i]; */
64  /* } */
65  /* } */
66 
67  /* Place a vector in boundary conditions. */
68  void putInBC1(dVec & r) const {
69  for (int i = 0; i < NDIM; ++i) {
70  while (r[i] >= 0.5*side[i] && periodic[i])
71  r[i] -= pSide[i];
72  while (r[i] < -0.5*side[i] && periodic[i])
73  r[i] += pSide[i];
74  }
75  }
76 
78  virtual void putInside(dVec &) const = 0;
79 
81  virtual dVec randPosition(MTRand &) const = 0;
82 
84  virtual dVec randUpdate(MTRand &, const dVec &) const = 0;
85 
87  virtual int gridIndex(const dVec &) const = 0;
88 
90  virtual double gridBoxVolume(const int) const = 0;
91 
93  double gridRadius2(const int) const;
94 
95 
96  protected:
98 };
99 
100 // ========================================================================
101 // Prism Class
102 // ========================================================================
106 class Prism: public Container {
107  public:
108  Prism(const double, const int);
109  Prism(const dVec &, const iVec &_periodic=1);
110  ~Prism();
111 
113  void putInside(dVec &r) const {
114  putInBC(r);
115 
116  /* This is slow! Try function pointers? Or create a separate hard
117  * top box? */
118  if (!fullyPeriodic) {
119  for (int i = 0; i < NDIM; i++) {
120  if (!periodic[i]) {
121  if (r[i] >= 0.5*side[i])
122  r[i] = 0.5*side[i] - 2*EPS;
123  if (r[i] < -0.5*side[i])
124  r[i] = -0.5*side[i] + 2*EPS;
125  }
126  }
127  }
128  }
129 
130  dVec randPosition(MTRand &) const;
131  dVec randUpdate(MTRand &, const dVec &) const;
132  int gridIndex(const dVec &) const;
133  double gridBoxVolume(const int) const;
134 };
135 
136 // ========================================================================
137 // Cylinder Class
138 // ========================================================================
143 class Cylinder: public Container {
144  public:
145  Cylinder(const double, const double, const int);
146  Cylinder(const double, const double);
147  ~Cylinder();
148 
149  /* Place a vector inside the cylinder */
150  void putInside(dVec &r) const;
151 
152  /* The various types of random positions inside the cylinder */
153  dVec randPosition(MTRand &) const;
154  dVec randUpdate(MTRand &, const dVec &) const;
155 
156  dVec randUpdateJumpShell(MTRand &, const dVec &) const;
157  dVec randUpdateSmall(MTRand &, const dVec &) const;
158 
159  int gridIndex(const dVec &) const;
160  double gridBoxVolume(const int) const;
161 };
162 #endif
The base class which holds details on the generalized box that our system will be simulated inside of...
Definition: container.h:24
dVec gridSize
The grid size in each dimension.
Definition: container.h:44
Container()
Initialize all variables.
Definition: container.cpp:20
virtual dVec randPosition(MTRand &) const =0
Random position inside a box.
double volume
The volume of the container in A^3.
Definition: container.h:35
int numGrid
The number of grid boxes for the position grid.
Definition: container.h:41
dVec sideInv
The inverse box dimensions.
Definition: container.h:32
dVec pSide
Periodic * side.
Definition: container.h:97
TinyVector< unsigned int, NDIM > periodic
Determines which dimensions have periodic bc.
Definition: container.h:29
dVec sideInv2
2 times the inverse box dimensions
Definition: container.h:33
virtual double gridBoxVolume(const int) const =0
The physical size of a NDIM-dimensional grid box.
virtual dVec randUpdate(MTRand &, const dVec &) const =0
Random updated position inside a box.
double gridRadius2(const int) const
The radius of a grid box.
Definition: container.cpp:51
double rcut2
The smallest separation squared.
Definition: container.h:36
string name
The name of the container.
Definition: container.h:39
void putInBC(dVec &r) const
Place a vector in boundary conditions.
Definition: container.h:50
virtual int gridIndex(const dVec &) const =0
Map a position into a grid index.
bool fullyPeriodic
Is the prism fully periodic?
Definition: container.h:42
virtual void putInside(dVec &) const =0
Place a vector inside the simulation cell.
dVec side
The linear dimensions of the box.
Definition: container.h:31
virtual ~Container()
Empty destructor.
Definition: container.cpp:42
double maxSep
The maximum possible separation for 2 beads on the same timeslice.
Definition: container.h:37
A three dimensional cylinder with fixed boundary conditions in the x and y directions and periodic bo...
Definition: container.h:143
~Cylinder()
Destructor.
Definition: container.cpp:335
dVec randUpdateJumpShell(MTRand &, const dVec &) const
Return a random position close to the supplied one.
Definition: container.cpp:369
dVec randUpdateSmall(MTRand &, const dVec &) const
Return a random position close to the supplied one.
Definition: container.cpp:397
Cylinder(const double, const double, const int)
Create a cylinder given density, radius and number of particles.
Definition: container.cpp:229
dVec randPosition(MTRand &) const
Return a random position inside the cylinder.
Definition: container.cpp:342
double gridBoxVolume(const int) const
Given a grid index, return the hyper volume of the associated grid box.
Definition: container.cpp:470
dVec randUpdate(MTRand &, const dVec &) const
Return a random position close to the supplied one.
Definition: container.cpp:357
void putInside(dVec &r) const
Make sure that a suplied vector is put inside the cylinder.
Definition: container.cpp:408
int gridIndex(const dVec &) const
Given a particle position, return a single integer which maps to a unique grid position.
Definition: container.cpp:432
A NDIM-dimensional hyperprism with periodic boundary conditions.
Definition: container.h:106
double gridBoxVolume(const int) const
Given a grid index, return the hyper volume of the associated grid box.
Definition: container.cpp:212
~Prism()
Empty destructor.
Definition: container.cpp:146
dVec randPosition(MTRand &) const
Return a random position inside the cube.
Definition: container.cpp:152
Prism(const double, const int)
Create a NDIM-dimensional hyperprism given density and number of particles.
Definition: container.cpp:82
int gridIndex(const dVec &) const
Given a particle position, return a single integer which maps to a unique grid position.
Definition: container.cpp:192
void putInside(dVec &r) const
For PBC, this is identical to putInBC.
Definition: container.h:113
dVec randUpdate(MTRand &, const dVec &) const
Return a random position close to the supplied one.
Definition: container.cpp:162
Global common header with shared dependencies and methods.
#define NDIM
Number of spatial dimnsions.
Definition: common.h:71
#define EPS
A small number.
Definition: common.h:94
TinyVector< double, NDIM > dVec
A NDIM-vector of type double.
Definition: common.h:111
TinyVector< int, NDIM > iVec
A NDIM-vector of type integer.
Definition: common.h:114