4 #include <gsl/gsl_rng.h>
8 #include "latlib/neigh.h"
10 class sim : public o815::sim {
26 void updatePhi (const int& x);
27 static double magnYOfR (const double& r);
30 double sim::magnYOfR (const double& r)
32 return sqrt( -std::log(1-r) );
35 sim::sim(o815 *_O815) : o815::sim( _O815,
37 (_O815->comargs.lsize[0]*_O815->comargs.lsize[1]) ) {
38 conf = (siteconf*)confMem;
40 rangsl = gsl_rng_alloc(gsl_rng_ranlxs0);
41 gsl_rng_set(rangsl, time(NULL));
43 LSIZE2 = _O815->comargs.lsize[0] * _O815->comargs.lsize[1];
45 nb = new neigh(2, _O815->comargs.lsize[0], _O815->comargs.lsize[1]);
48 void sim::updatePhi (const int& x)
53 for (int nu=0; nu<4; nu++)
54 V += conf[ (*nb)[x*4+nu] ].phi;
56 Y = sqrt(M) * conf[x].phi - V / sqrt(M);
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);
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) );
73 conf[x].phi = Y / sqrt(M) + V / M;
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 );
83 void sim::_newParas() {
84 m = (*O815->paraQ)["mass"];
85 M = pow( (*O815->paraQ)["mass"], 2 ) + 4;
86 *log << "SIM: Resetting fields." << endl << flush;
88 for (int ix=0; ix<LSIZE2; ix++)
89 conf[ix].phi = polar( 1., gsl_rng_uniform(rangsl) * 2*M_PI );