]> git.treefish.org Git - phys/heatbath.git/blob - sim-metro.hpp
...
[phys/heatbath.git] / sim-metro.hpp
1 #ifndef SIM_HPP
2 #define SIM_HPP
3
4 #include <gsl/gsl_rng.h>
5 #include <complex>
6 #include <math.h>
7
8 #include "latlib/neigh.h"
9
10 #define EPSILONPHI 0.5
11
12 class sim : public o815::sim {
13 public:
14   struct siteconf {
15     complex<double> phi;
16   };
17   sim(o815 *_O815);
18   siteconf* conf;
19   unsigned int LSIZE2;
20   double M;
21   double m;
22   neigh *nb;
23
24 private:
25   void _makeSweep();
26   void _newParas();
27   gsl_rng* rangsl;
28   int updatePhi (const int& x);
29   double SofPhi(const int& x, const complex<double>& phix);
30   double rhoPhi(const int& x, const complex<double>& phixCandidate);
31 };
32
33
34
35 sim::sim(o815 *_O815) : o815::sim( _O815, 
36                                    sizeof(siteconf)*
37                                    (_O815->comargs.lsize[0]*_O815->comargs.lsize[1]) ) {
38   conf = (siteconf*)confMem;
39
40   rangsl = gsl_rng_alloc(gsl_rng_ranlxs0);
41   gsl_rng_set(rangsl, time(NULL));
42
43   LSIZE2 = _O815->comargs.lsize[0] * _O815->comargs.lsize[1];
44
45   nb = new neigh(2, _O815->comargs.lsize[0], _O815->comargs.lsize[1]);
46 }
47
48 void sim::_makeSweep() {  
49   for (int ichecker=0; ichecker<2; ichecker++)
50     for (int it=0; it<O815->comargs.lsize[0]; it++)
51       for (int iy=(it+ichecker)%2; iy<O815->comargs.lsize[1]; iy+=2)
52         updatePhi( it*O815->comargs.lsize[1] + iy );
53 }
54
55 void sim::_newParas() {
56   m = (*O815->paraQ)["mass"];
57   M = pow( (*O815->paraQ)["mass"], 2 ) + 4;
58   *log << "SIM: Resetting fields." << endl << flush;
59
60   for (int ix=0; ix<LSIZE2; ix++)
61     conf[ix].phi = polar( 1., gsl_rng_uniform(rangsl) * 2*M_PI );
62 }
63
64 int sim::updatePhi(const int& x) {
65   complex<double> phixCandidate = conf[x].phi +
66     complex<double> ( 2*EPSILONPHI*( 0.5 - gsl_rng_uniform(rangsl) ), 
67                       2*EPSILONPHI*( 0.5 - gsl_rng_uniform(rangsl) ) );
68   
69   if ( gsl_rng_uniform(rangsl) < rhoPhi(x, phixCandidate) ) {
70     conf[x].phi = phixCandidate;
71     return 1;
72   }
73   
74   return 0;
75 }
76
77 double sim::rhoPhi(const int& x, const complex<double>& phixCandidate) {
78   return exp( SofPhi(x, conf[x].phi) - SofPhi(x, phixCandidate) );
79 }
80
81 double sim::SofPhi(const int& x, const complex<double>& phix) {
82   double sofphi = M * norm(phix);
83   
84   for (int nu=0; nu<4; nu++)
85     sofphi -= 2 * real( conj(phix) * conf[ (*nb)[x*4+nu] ].phi );
86   
87   return sofphi;
88 }
89
90 #endif