]> git.treefish.org Git - phys/heatbath.git/blob - sim-nonmetro.hpp
...
[phys/heatbath.git] / sim-nonmetro.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 class sim : public o815::sim {
11 public:
12   struct siteconf {
13     complex<double> phi;
14   };
15   sim(o815 *_O815);
16   siteconf* conf;
17   unsigned int LSIZE2;
18   double M;
19   double m;
20   neigh *nb;
21
22 private:
23   void _makeSweep();
24   void _newParas();
25   gsl_rng* rangsl;
26   void updatePhi (const int& x);
27   static double magnYOfR (const double& r);
28 };
29
30 double sim::magnYOfR (const double& r) 
31 {
32   return sqrt( -std::log(1-r) );
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::updatePhi (const int& x) 
49 {
50   complex<double> V=0;
51   complex<double> Y;
52
53   for (int nu=0; nu<4; nu++)
54     V += conf[ (*nb)[x*4+nu] ].phi;
55
56   Y = sqrt(M) * conf[x].phi - V / sqrt(M);
57
58 #if defined(ALGORITHM_AHBMHB) || defined(ALGORITHM_AHBMOR) || defined(ALGORITHM_AHBM0)
59   Y = polar( abs(Y), gsl_rng_uniform(rangsl) * 2*M_PI );
60 #elif defined(ALGORITHM_AORMHB) || defined(ALGORITHM_AORMOR) || defined(ALGORITHM_AORM0)
61   const double V2diff = pow(real(V), 2) - pow(imag(V), 2);
62   const double Vprod = real(V)*imag(V);
63   Y = complex<double> ( + real(Y) * V2diff + 2 * imag(Y) * Vprod,
64                         - imag(Y) * V2diff + 2 * real(Y) * Vprod ) / norm(V);
65 #endif
66   
67 #if defined(ALGORITHM_AHBMHB) || defined(ALGORITHM_AORMHB) || defined(ALGORITHM_A0MHB)
68   Y = polar( magnYOfR( gsl_rng_uniform(rangsl) ), arg(Y) );
69 #elif defined(ALGORITHM_AHBMOR) || defined(ALGORITHM_AORMOR) || defined(ALGORITHM_A0MOR)
70   Y = polar( magnYOfR( exp( -norm(Y) ) ), arg(Y) );
71 #endif
72
73   conf[x].phi = Y / sqrt(M) + V / M;
74 }
75
76 void sim::_makeSweep() {  
77   for (int ichecker=0; ichecker<2; ichecker++)
78     for (int it=0; it<O815->comargs.lsize[0]; it++)
79       for (int iy=(it+ichecker)%2; iy<O815->comargs.lsize[1]; iy+=2)
80         updatePhi( it*O815->comargs.lsize[1] + iy );
81 }
82
83 void sim::_newParas() {
84   m = (*O815->paraQ)["mass"];
85   M = pow( (*O815->paraQ)["mass"], 2 ) + 4;
86   *log << "SIM: Resetting fields." << endl << flush;
87
88   for (int ix=0; ix<LSIZE2; ix++)
89     conf[ix].phi = polar( 1., gsl_rng_uniform(rangsl) * 2*M_PI );
90 }
91
92 #endif