Path Integral Quantum Monte Carlo
Public Member Functions
Cylinder Class Reference

A three dimensional cylinder with fixed boundary conditions in the x and y directions and periodic boundary conditions in the z direction. More...

#include <container.h>

+ Inheritance diagram for Cylinder:
+ Collaboration diagram for Cylinder:

Public Member Functions

 Cylinder (const double, const double, const int)
 Create a cylinder given density, radius and number of particles. More...
 
 Cylinder (const double, const double)
 Create a cylinder given its radius and length. More...
 
 ~Cylinder ()
 Destructor.
 
void putInside (dVec &r) const
 Make sure that a suplied vector is put inside the cylinder.
 
dVec randPosition (MTRand &) const
 Return a random position inside the cylinder. More...
 
dVec randUpdate (MTRand &, const dVec &) const
 Return a random position close to the supplied one.
 
dVec randUpdateJumpShell (MTRand &, const dVec &) const
 Return a random position close to the supplied one. More...
 
dVec randUpdateSmall (MTRand &, const dVec &) const
 Return a random position close to the supplied one. More...
 
int gridIndex (const dVec &) const
 Given a particle position, return a single integer which maps to a unique grid position. More...
 
double gridBoxVolume (const int) const
 Given a grid index, return the hyper volume of the associated grid box. More...
 
- Public Member Functions inherited from Container
 Container ()
 Initialize all variables.
 
virtual ~Container ()
 Empty destructor.
 
void putInBC (dVec &r) const
 Place a vector in boundary conditions. More...
 
void putInBC1 (dVec &r) const
 
double gridRadius2 (const int) const
 The radius of a grid box. More...
 

Additional Inherited Members

- Data Fields inherited from Container
TinyVector< unsigned int, NDIMperiodic
 Determines which dimensions have periodic bc.
 
dVec side
 The linear dimensions of the box.
 
dVec sideInv
 The inverse box dimensions.
 
dVec sideInv2
 2 times the inverse box dimensions
 
double volume
 The volume of the container in A^3.
 
double rcut2
 The smallest separation squared.
 
double maxSep
 The maximum possible separation for 2 beads on the same timeslice.
 
string name
 The name of the container.
 
int numGrid
 The number of grid boxes for the position grid.
 
bool fullyPeriodic
 Is the prism fully periodic?
 
dVec gridSize
 The grid size in each dimension.
 
- Protected Attributes inherited from Container
dVec pSide
 Periodic * side.
 

Detailed Description

A three dimensional cylinder with fixed boundary conditions in the x and y directions and periodic boundary conditions in the z direction.

Definition at line 143 of file container.h.

Constructor & Destructor Documentation

◆ Cylinder() [1/2]

Cylinder::Cylinder ( const double  _rho,
const double  radius,
const int  numParticles 
)

Create a cylinder given density, radius and number of particles.

We create a 3d cylinder (otherwise exit) with periodic boundary conditions only in the z-direction. The radius is fixed, and the length is determined by the density in atoms/A^3.

Definition at line 229 of file container.cpp.

229  {
230 
231  /* We can only make a cylinder in 3 dimensions */
232  if (NDIM != 3) {
233  cerr << "You can only create a cylinder in 3 dimensions, change NDIM!"
234  << endl;
235  exit(EXIT_FAILURE);
236  }
237  else {
238  /* We can compute the linear length from the density, number of particles
239  * and radius */
240  double L = (1.0*numParticles)/(_rho * M_PI * radius * radius);
241 
242  /* We check to make sure that our aspect ratio is at least 2:1 */
243  if (L < 2.0*radius)
244  cerr << "L:r is smaller than 2:1!" << endl;
245 
246  /* Setup the prism size in each of the three dimensions which the
247  * cylinder will be inscribed insde of. We make it 2R X 2R X L */
248  side[0] = side[1] = 2.0 * radius;
249  side[2] = L;
250 
251  rcut2 = 0.25*side[2]*side[2];
252 
253  sideInv = 1.0/side;
254  sideInv2 = 2.0*sideInv;
255 
256  /* setup which dimensions have periodic boundary conditions, 1.0 for yes
257  * and 0.0 for no. */
258  periodic[0] = periodic[1] = 0;
259  periodic[2] = 1;
260 
261  pSide = periodic*side;
262 
263  /* Compute the maximum possible separation possible inside the box */
264  maxSep = sqrt(dot(side/(periodic + 1.0),side/(periodic + 1.0)));
265 
266  /* Compute the cylinder volume. We use the radius here instead of the actual
267  * side. This is the 'active' volume */
268  volume = M_PI*radius*radius*L;
269 
270  name = "Cylinder";
271 
272  /* The grid size for the lookup table */
274 
275  } // end else
276 }
dVec gridSize
The grid size in each dimension.
Definition: container.h:44
double volume
The volume of the container in A^3.
Definition: container.h:35
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
double rcut2
The smallest separation squared.
Definition: container.h:36
string name
The name of the container.
Definition: container.h:39
dVec side
The linear dimensions of the box.
Definition: container.h:31
double maxSep
The maximum possible separation for 2 beads on the same timeslice.
Definition: container.h:37
#define NDIM
Number of spatial dimnsions.
Definition: common.h:71
#define NGRIDSEP
Spatial separations to be used in each dimension of the particle position grid.
Definition: common.h:93

◆ Cylinder() [2/2]

Cylinder::Cylinder ( const double  radius,
const double  L 
)

Create a cylinder given its radius and length.

We create a 3d cylinder (otherwise exit) with periodic boundary conditions only in the z-direction. The radius and length are given in angstroms.

Parameters
LThe length of the cylinder
radiusThe radius of the cylinder

Definition at line 286 of file container.cpp.

286  {
287 
288  /* We can only make a cylinder in 3 dimensions */
289  if (NDIM != 3) {
290  cerr << "You can only create a cylinder in 3 dimensions, change NDIM!"
291  << endl;
292  exit(EXIT_FAILURE);
293  }
294  else {
295  /* We check to make sure that our aspect ratio is at least 2:1 */
296  if (L < 2.0*radius)
297  cerr << "L:r is smaller than 2:1!" << endl;
298 
299  /* Setup the prism size in each of the three dimensions which the
300  * cylinder will be inscribed insde of. We make it 2R X 2R X L
301  * to account for */
302  side[0] = side[1] = 2.0 * radius;
303  side[2] = L;
304 
305  rcut2 = 0.25*side[2]*side[2];
306 
307  sideInv = 1.0/side;
308  sideInv2 = 2.0*sideInv;
309 
310  /* setup which dimensions have periodic boundary conditions, 1 for yes
311  * and 0 for no. */
312  periodic[0] = periodic[1] = 0;
313  periodic[2] = 1;
314 
315  /* Compute the maximum possible separation possible inside the box */
316  maxSep = sqrt(dot(side/(periodic + 1.0),side/(periodic + 1.0)));
317 
318  pSide = periodic*side;
319 
320  /* Compute the cylinder volume. We use the radius here instead of the actual
321  * side. This is the 'active' volume */
322  volume = M_PI*radius*radius*L;
323 
324  name = "Cylinder";
325 
326  /* The grid size for the lookup table */
328 
329  } // end else
330 }

Member Function Documentation

◆ gridBoxVolume()

double Cylinder::gridBoxVolume ( const int  n) const
virtual

Given a grid index, return the hyper volume of the associated grid box.

Parameters
nThe grid index
Returns
The hyper volume of the grid box

Implements Container.

Definition at line 470 of file container.cpp.

470  {
471 
472  /* Get the first grid box index */
473  return blitz::product(gridSize);
474 }

◆ gridIndex()

int Cylinder::gridIndex ( const dVec pos) const
virtual

Given a particle position, return a single integer which maps to a unique grid position.

Used for correlating estimators with individual particle positions.

Parameters
posThe particle position
Returns
An integer representing a grid box number

Implements Container.

Definition at line 432 of file container.cpp.

432  {
433 
434  // /* Get the r and theta components */
435  // double r = sqrt(pos[0]*pos[0]+ pos[1]*pos[1]);
436  // double theta = atan2(pos[1],pos[0]);
437  // theta += (theta < 0.0)*2.0*M_PI;
438 
439  // /* Get the 3d vector index */
440  // iVec grid;
441  // grid[0] = static_cast<int>(abs(r-EPS)/(gridSize[0]+EPS));
442  // grid[1] = static_cast<int>(abs(theta-EPS)/(gridSize[1]+EPS));
443  // grid[2] = static_cast<int>(abs(pos[2] + 0.5*side[2] - EPS )/(gridSize[2] + EPS));
444 
445  // /* return the flattened index */
446  // int gNumber = grid[0]*NGRIDSEP*NGRIDSEP + grid[1]*NGRIDSEP + grid[2];
447 
448  // PIMC_ASSERT(gNumber<numGrid);
449  // return gNumber;
450 
451  int gNumber = 0;
452  for (int i = 0; i < NDIM; i++) {
453  int scale = 1;
454  for (int j = i+1; j < NDIM; j++)
455  scale *= NGRIDSEP;
456  gNumber += scale *
457  static_cast<int>(abs( pos[i] + 0.5*side[i] - EPS ) / (gridSize[i] + EPS));
458  }
459  PIMC_ASSERT(gNumber<numGrid);
460 
461  return gNumber;
462 }
int numGrid
The number of grid boxes for the position grid.
Definition: container.h:41
#define EPS
A small number.
Definition: common.h:94
#define PIMC_ASSERT(X)
Rename assert method.
Definition: common.h:64

◆ randPosition()

dVec Cylinder::randPosition ( MTRand &  random) const
virtual

Return a random position inside the cylinder.

See also
http://extremelearning.com.au/how-to-generate-uniformly-random-points-on-n-spheres-and-n-balls/

Implements Container.

Definition at line 342 of file container.cpp.

342  {
343 
344  dVec randPos;
345  double r = 0.5*side[0]*sqrt(random.randExc());
346  double phi = random.randExc(2.0*M_PI);
347  randPos[0] = r * cos(phi);
348  randPos[1] = r * sin(phi);
349  randPos[2] = side[2]*(-0.5 + random.randExc());
350 
351  return randPos;
352 }
TinyVector< double, NDIM > dVec
A NDIM-vector of type double.
Definition: common.h:111

◆ randUpdateJumpShell()

dVec Cylinder::randUpdateJumpShell ( MTRand &  random,
const dVec pos 
) const

Return a random position close to the supplied one.

Shell Jump

Definition at line 369 of file container.cpp.

369  {
370  dVec randPos;
371  randPos = pos;
372  double theta = atan2(pos[1],pos[0]);
373  double oldr = sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
374  double newr;
375 
376  if (random.rand() > 0.5)
377  newr = oldr + (1.00 + 2.50*random.rand());
378  else
379  newr = oldr - (1.00 + 2.50*random.rand());
380 
381  if (newr < 0.0)
382  newr *= -1.0;
383 
384  double ranTheta = M_PI*(-0.05 + 0.1*random.rand());
385  randPos[0] = newr*cos(theta + ranTheta);
386  randPos[1] = newr*sin(theta + ranTheta);
387  randPos[2] += constants()->displaceDelta()*(-0.5 + random.rand());
388 
389  putInside(randPos);
390  return randPos;
391 }
double displaceDelta() const
Get center of mass shift.
Definition: constants.h:54
void putInside(dVec &r) const
Make sure that a suplied vector is put inside the cylinder.
Definition: container.cpp:408
ConstantParameters * constants()
Global public access to the constants.
Definition: constants.h:201
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ randUpdateSmall()

dVec Cylinder::randUpdateSmall ( MTRand &  random,
const dVec pos 
) const

Return a random position close to the supplied one.

Same Shell.

Definition at line 397 of file container.cpp.

397  {
398  dVec randPos;
399  randPos = pos;
400  for (int i = 0; i < NDIM; i++)
401  randPos[i] += constants()->displaceDelta()*(-0.5 + random.rand());
402  putInside(randPos);
403  return randPos;
404 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: