4 #include <gsl/gsl_rng.h>
8 #include "latlib/neigh.h"
10 #define EPSILONPHI 0.5
12 class sim : public o815::sim {
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);
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::_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 );
55 void sim::_newParas() {
56 m = (*O815->paraQ)["mass"];
57 M = pow( (*O815->paraQ)["mass"], 2 ) + 4;
58 *log << "SIM: Resetting fields." << endl << flush;
60 for (int ix=0; ix<LSIZE2; ix++)
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) ) );
69 if ( gsl_rng_uniform(rangsl) < rhoPhi(x, phixCandidate) ) {
70 conf[x].phi = phixCandidate;
77 double sim::rhoPhi(const int& x, const complex<double>& phixCandidate) {
78 return exp( SofPhi(x, conf[x].phi) - SofPhi(x, phixCandidate) );
81 double sim::SofPhi(const int& x, const complex<double>& phix) {
82 double sofphi = M * norm(phix);
84 for (int nu=0; nu<4; nu++)
85 sofphi -= 2 * real( conj(phix) * conf[ (*nb)[x*4+nu] ].phi );