]> git.treefish.org Git - phys/heatbath.git/blob - sim-r+.hpp
Added r+ algorithm.
[phys/heatbath.git] / sim-r+.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 };
28
29
30
31 sim::sim(o815 *_O815) : o815::sim( _O815, 
32                                    sizeof(siteconf)*
33                                    (_O815->comargs.lsize[0]*_O815->comargs.lsize[1]) ) {
34   conf = (siteconf*)confMem;
35
36   rangsl = gsl_rng_alloc(gsl_rng_ranlxs0);
37   gsl_rng_set(rangsl, time(NULL));
38
39   LSIZE2 = _O815->comargs.lsize[0] * _O815->comargs.lsize[1];
40
41   nb = new neigh(2, _O815->comargs.lsize[0], _O815->comargs.lsize[1]);
42 }
43
44 void sim::updatePhi (const int& x) 
45 {
46   const double r = gsl_rng_uniform(rangsl);
47   complex<double> V=0;
48
49   for (int nu=0; nu<4; nu++)
50     V += conf[ (*nb)[x*4+nu] ].phi;
51
52   const double V2diff = pow(real(V), 2) - pow(imag(V), 2);
53   const double Vprod = real(V)*imag(V);
54   conf[x].phi = complex<double> ( + real(conf[x].phi) * V2diff + 2 * imag(conf[x].phi) * Vprod,
55                                   - imag(conf[x].phi) * V2diff + 2 * real(conf[x].phi) * Vprod ) / norm(V);
56
57   conf[x].phi = sqrt(std::log( 1./(1-r) )) / sqrt(M)
58     * polar(1.0, gsl_rng_uniform(rangsl) * 2*M_PI)
59     + V / M;
60 }
61
62 void sim::_makeSweep() {  
63   for (int ichecker=0; ichecker<2; ichecker++)
64     for (int it=0; it<O815->comargs.lsize[0]; it++)
65       for (int iy=(it+ichecker)%2; iy<O815->comargs.lsize[1]; iy+=2)
66         updatePhi( it*O815->comargs.lsize[1] + iy );
67 }
68
69 void sim::_newParas() {
70   m = (*O815->paraQ)["mass"];
71   M = pow( (*O815->paraQ)["mass"], 2 ) + 4;
72   *log << "SIM: Resetting fields." << endl << flush;
73
74   for (int ix=0; ix<LSIZE2; ix++)
75     conf[ix].phi = 1;
76 }
77
78 #endif