Path Integral Quantum Monte Carlo
path.h
Go to the documentation of this file.
1 
9 #ifndef PATH_H
10 #define PATH_H
11 
12 #include "common.h"
13 #include "constants.h"
14 #include "container.h"
15 #include "worm.h"
16 
17 class LookupTable;
18 
19 // ========================================================================
20 // Path Class
21 // ========================================================================
29 class Path {
30 
31  public:
32  Path (const Container *, LookupTable &, int, const Array<dVec,1>&, int numberBroken = 0);
33  ~Path();
34 
35  /* Path* clone() const{ return new Path(*this); } */
36 
37  const int numTimeSlices;
38  int breakSlice;
39  vector<int> brokenWorldlinesL;
40  vector<int> brokenWorldlinesR;
41  vector<int> closedWorldlines;
42 
43  const Container *boxPtr;
45 
47 
48  Array <int,1> numBeadsAtSlice;
49 
51  int getNumParticles() const {return beads.extent(secondDim);}
52 
54  int getTrueNumParticles() const {return ( worm.getNumBeadsOn() / numTimeSlices );}
55 
57  const dVec& operator() (int slice, int ptcl) const {
58  PIMC_ASSERT(slice>=0 && slice < numTimeSlices);
59  return beads(slice,ptcl); }
61  dVec& operator() (int slice, int ptcl) {
62  PIMC_ASSERT(slice>=0 && slice < numTimeSlices);
63  return beads(slice,ptcl); }
65  const dVec& operator() (const beadLocator &beadIndex) const {
66  PIMC_ASSERT(beadIndex[0]>=0 && beadIndex[0]<numTimeSlices);
67  return beads(beadIndex); }
69  dVec& operator() (const beadLocator &beadIndex) {
70  PIMC_ASSERT(beadIndex[0]>=0 && beadIndex[0]<numTimeSlices);
71  return beads(beadIndex); }
72 
74  dVec getVelocity(const beadLocator&) const;
75 
77  dVec getSeparation(const beadLocator&, const beadLocator&) const;
78 
80  template<class Tstream> void printLinks(Tstream &);
81 
83  void outputConfig(int) const;
84 
86  beadLocator& next(int slice, int ptcl) {return nextLink(slice,ptcl);}
88  const beadLocator& next(int slice, int ptcl) const {return nextLink(slice,ptcl);}
90  beadLocator& next(const beadLocator &beadIndex) {return nextLink(beadIndex);}
92  const beadLocator& next(const beadLocator &beadIndex) const {return nextLink(beadIndex);}
93 
95  beadLocator& prev(int slice, int ptcl) {return prevLink(slice,ptcl);}
97  const beadLocator& prev(int slice, int ptcl) const {return prevLink(slice,ptcl);}
99  beadLocator& prev(const beadLocator &beadIndex) {return prevLink(beadIndex);}
101  const beadLocator& prev(const beadLocator &beadIndex) const {return prevLink(beadIndex);}
102 
104  beadLocator next(int,int,int) const;
105  beadLocator next(const beadLocator&,int) const;
106 
108  beadLocator prev(int,int,int) const;
109  beadLocator prev(const beadLocator&,int) const;
110 
112  beadLocator addBead(const int, const dVec &);
114  beadLocator addNextBead(const beadLocator&, const dVec &);
116  beadLocator addPrevBead(const beadLocator&, const dVec &);
117 
119  void delBead(const beadLocator&);
124 
126  void breakLink(const beadLocator&);
128  void makeLink(const beadLocator&,const beadLocator&);
130  void removeCenterLink(const beadLocator&);
132  void addCenterLink(const beadLocator&,const beadLocator&);
134  bool isBroken(const beadLocator&) const;
136  double breakFactor(const beadLocator&,const beadLocator&) const;
138  bool inSubregionA(const beadLocator&) const;
139  bool inSubregionB(const beadLocator&) const;
141  bool checkSubregionLinks() const;
142 
144  void updateBead(const beadLocator&, const dVec&);
145 
147  void printWormConfig(Array <beadLocator,1> &);
148 
150  void leftPack();
151 
153  void resetBrokenClosedVecs();
154 
155  private:
156  friend class PathIntegralMonteCarlo; // Friends for I/O
157 
158  Array<dVec,2> beads; // The wordline array
159  Array<beadLocator,2> prevLink, nextLink; // Bead connection matrices
160 
161  beadLocator lastBeadIndex; // Holds the index of the last bead on a slice
162 };
163 
164 /* inline Path* new_clone(Path const& other){ */
165 /* return other.clone(); */
166 /* } */
167 
168 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
169 // INLINE FUNCTION DEFINITIONS
170 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
171 
173 inline dVec Path::getSeparation(const beadLocator &bead1, const beadLocator &bead2) const {
174  dVec sep;
175  sep = (*this)(bead1) - (*this)(bead2);
176  boxPtr->putInBC(sep);
177  return sep;
178 }
179 
180 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
181 
183 inline dVec Path::getVelocity (const beadLocator &beadIndex) const {
184  dVec vel;
185 
186  if (all(beadIndex==XXX) || all(next(beadIndex)==XXX)) {
187  vel = 0.0;
188  return (vel);
189  }
190 
191  /* Calculate the 'velocity' and implement periodic boundary conditions */
192  vel = beads(next(beadIndex)) - beads(beadIndex);
193  boxPtr->putInBC(vel);
194 
195  return (vel);
196 }
197 
198 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
199 
201 inline beadLocator Path::next(int slice, int ptcl, int numLinks) const {
202  PIMC_ASSERT(slice>=0 && slice<numTimeSlices && ptcl>=0);
203  beadLocator bI;
204  bI = slice,ptcl;
205  for (int m = 0; m < numLinks; m++)
206  bI = next(bI);
207  return bI;
208 }
209 
210 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
211 
213 inline beadLocator Path::next(const beadLocator &beadIndex, int numLinks) const {
214  PIMC_ASSERT(beadIndex[0]>=0 && beadIndex[0]<numTimeSlices && beadIndex[1]>=0);
215  beadLocator bI;
216  bI = beadIndex;
217  for (int m = 0; m < numLinks; m++)
218  bI = next(bI);
219  return bI;
220 }
221 
222 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
223 
225 inline beadLocator Path::prev(int slice, int ptcl, int numLinks) const {
226  PIMC_ASSERT(slice>=0 && slice<numTimeSlices && ptcl>=0);
227  beadLocator bI;
228  bI = slice,ptcl;
229  for (int m = 0; m < numLinks; m++)
230  bI = prev(bI);
231  return bI;
232 }
233 
234 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
235 
237 inline beadLocator Path::prev(const beadLocator &beadIndex, int numLinks) const {
238  PIMC_ASSERT(beadIndex[0]>=0 && beadIndex[0]<numTimeSlices && beadIndex[1]>=0);
239  beadLocator bI;
240  bI = beadIndex;
241  for (int m = 0; m < numLinks; m++)
242  bI = prev(bI);
243  return bI;
244 }
245 
246 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
247 
249 template<class Tstream>
250 void Path::printLinks(Tstream &outStream) {
251  int numParticles = getNumParticles();
252  for (int m = numTimeSlices-1; m >= 0; m--) {
253  beadLocator beadIndex;
254  for (int n = 0; n < numParticles; n++) {
255  beadIndex = m,n;
256  outStream << setw(2) << prevLink(beadIndex)[1] << " ";
257  }
258 
259  outStream << "\t";
260  for (int n = 0; n < numParticles; n++) {
261  beadIndex = m,n;
262  outStream << setw(2) << nextLink(beadIndex)[1] << " ";
263  }
264  outStream << endl;
265  }
266  outStream << endl;
267 }
268 
269 #endif
The base class which holds details on the generalized box that our system will be simulated inside of...
Definition: container.h:24
void putInBC(dVec &r) const
Place a vector in boundary conditions.
Definition: container.h:50
The particle (bead) lookup table.
Definition: lookuptable.h:29
The main driver class for the entire path integral monte carlo program.
Definition: pimc.h:37
The space-time trajectories.
Definition: path.h:29
const beadLocator & prev(const beadLocator &beadIndex) const
Move one link backward in imaginary time.
Definition: path.h:101
bool inSubregionA(const beadLocator &) const
Checks to see if bead is in subregion A/B at break slice + 1.
Definition: path.cpp:518
~Path()
Destructor.
Definition: path.cpp:117
int getNumParticles() const
Get the size of the worldline array.
Definition: path.h:51
beadLocator delBeadGetNext(const beadLocator &)
Delete a bead and move forwards.
Definition: path.cpp:326
Path(const Container *, LookupTable &, int, const Array< dVec, 1 > &, int numberBroken=0)
Constructor.
Definition: path.cpp:28
void resetBrokenClosedVecs()
Reset broken/closed worldline vectors.
Definition: path.cpp:459
void leftPack()
Initialize any loaded state by left packing the array.
Definition: path.cpp:130
beadLocator delBeadGetPrev(const beadLocator &)
Delete a bead and move backwards.
Definition: path.cpp:309
void outputConfig(int) const
Output the world-line configurations in a generic format.
Definition: path.cpp:576
dVec getVelocity(const beadLocator &) const
Return the velocity between two time slices of a given particle as a ndim-vector.
Definition: path.h:183
vector< int > closedWorldlines
A list of particles with closed worldlines on left of break.
Definition: path.h:41
vector< int > brokenWorldlinesR
A list of particles with broken worldlines on right of break.
Definition: path.h:40
beadLocator & next(const beadLocator &beadIndex)
Move one link forward in imaginary time.
Definition: path.h:90
bool checkSubregionLinks() const
Check if only subregion worldlines are broken, for debugging.
Definition: path.cpp:545
void delBead(const beadLocator &)
Remove a bead from the world-line configuration.
Definition: path.cpp:344
void printWormConfig(Array< beadLocator, 1 > &)
Used when debugging worm configurations.
Definition: path.cpp:743
bool isBroken(const beadLocator &) const
Checks to see if worldline is broken.
Definition: path.cpp:492
const dVec & operator()(int slice, int ptcl) const
Operator Overloading to skip having to specifically grab .beads
Definition: path.h:57
void makeLink(const beadLocator &, const beadLocator &)
Make a link between beads.
Definition: path.cpp:415
dVec getSeparation(const beadLocator &, const beadLocator &) const
Return the separation vector between two particles in the same timeslice.
Definition: path.h:173
vector< int > brokenWorldlinesL
A list of particles with broken worldlines on left of break.
Definition: path.h:39
void removeCenterLink(const beadLocator &)
Break the link to right of bead t center slice AND update lists.
Definition: path.cpp:423
double breakFactor(const beadLocator &, const beadLocator &) const
Returns factor for broken worldines.
Definition: path.cpp:502
const int numTimeSlices
A local constant copy of the number of time slices.
Definition: path.h:37
const beadLocator & next(const beadLocator &beadIndex) const
Move one link forward in imaginary time.
Definition: path.h:92
beadLocator addPrevBead(const beadLocator &, const dVec &)
Add a bead at the previous time slice.
Definition: path.cpp:221
Array< int, 1 > numBeadsAtSlice
The number of active beads at a given time slice.
Definition: path.h:48
int breakSlice
The location of the break in the path (0=>no break)
Definition: path.h:38
beadLocator addBead(const int, const dVec &)
Add a bead to the worldline configuration at a given slice.
Definition: path.cpp:250
void addCenterLink(const beadLocator &, const beadLocator &)
Make a link between beads at center slice AND update lists.
Definition: path.cpp:441
bool inSubregionB(const beadLocator &) const
Check if bead is in subregion B.
Definition: path.cpp:533
void printLinks(Tstream &)
Output bead-link info, used for debugging.
Definition: path.h:250
void updateBead(const beadLocator &, const dVec &)
Update the position of a bead in the worldine configuration.
Definition: path.cpp:182
beadLocator & next(int slice, int ptcl)
Move one link forward in imaginary time.
Definition: path.h:86
const beadLocator & prev(int slice, int ptcl) const
Move one link backward in imaginary time.
Definition: path.h:97
const Container * boxPtr
A constant reference to the container class.
Definition: path.h:43
Worm worm
Details on the worm.
Definition: path.h:44
beadLocator & prev(int slice, int ptcl)
Move one link backward in imaginary time.
Definition: path.h:95
beadLocator addNextBead(const beadLocator &, const dVec &)
Add a bead at the next time slice.
Definition: path.cpp:194
LookupTable & lookup
A reference to the nearest neighbor lookup table.
Definition: path.h:46
void breakLink(const beadLocator &)
Break the link to right of bead.
Definition: path.cpp:406
int getTrueNumParticles() const
The number of active particles.
Definition: path.h:54
const beadLocator & next(int slice, int ptcl) const
Move one link forward in imaginary time.
Definition: path.h:88
beadLocator & prev(const beadLocator &beadIndex)
Move one link backward in imaginary time.
Definition: path.h:99
Contains information on the worm.
Definition: worm.h:25
int getNumBeadsOn() const
Return the number of active beads.
Definition: worm.h:88
Global common header with shared dependencies and methods.
TinyVector< int, 2 > beadLocator
time-slice,bead-number world line index
Definition: common.h:117
TinyVector< double, NDIM > dVec
A NDIM-vector of type double.
Definition: common.h:111
#define PIMC_ASSERT(X)
Rename assert method.
Definition: common.h:64
#define XXX
Used to refer to a nonsense beadIndex.
Definition: common.h:98
ConstantParameters class definition.
The simulation cell.
Worm class definition.