4 #include <gsl/gsl_rng.h>
8 #include "latlib/neigh.h"
10 #define EPSILONPHI 0.5
12 class sim : public o815::sim {
26 int updatePhi (const int& x);
28 double SofPhi(const int& x, const complex<double>& phix);
29 double rhoPhi(const int& x, const complex<double>& phixCandidate);
34 sim::sim(o815 *_O815) : o815::sim( _O815,
36 (_O815->comargs.lsize[0]*_O815->comargs.lsize[1]) ) {
37 conf = (siteconf*)confMem;
39 rangsl = gsl_rng_alloc(gsl_rng_ranlxs0);
40 gsl_rng_set(rangsl, time(NULL));
42 LSIZE2 = _O815->comargs.lsize[0] * _O815->comargs.lsize[1];
44 nb = new neigh(2, _O815->comargs.lsize[0], _O815->comargs.lsize[1]);
47 void sim::_makeSweep() {
48 for (int ichecker=0; ichecker<2; ichecker++)
49 for (int it=0; it<O815->comargs.lsize[0]; it++)
50 for (int iy=(it+ichecker)%2; iy<O815->comargs.lsize[1]; iy+=2)
51 updatePhi( it*O815->comargs.lsize[1] + iy );
54 void sim::_newParas() {
55 M = pow( (*O815->paraQ)["mass"], 2 ) + 4;
56 *log << "SIM: Resetting fields." << endl << flush;
58 for (int ix=0; ix<LSIZE2; ix++)
62 int sim::updatePhi(const int& x) {
63 complex<double> phixCandidate = conf[x].phi +
64 complex<double> ( 2*EPSILONPHI*( 0.5 - gsl_rng_uniform(rangsl) ),
65 2*EPSILONPHI*( 0.5 - gsl_rng_uniform(rangsl) ) );
67 if ( gsl_rng_uniform(rangsl) < rhoPhi(x, phixCandidate) ) {
68 conf[x].phi = phixCandidate;
75 double sim::rhoPhi(const int& x, const complex<double>& phixCandidate) {
76 return exp( SofPhi(x, conf[x].phi) - SofPhi(x, phixCandidate) );
79 double sim::SofPhi(const int& x, const complex<double>& phix) {
80 double sofphi = M * norm(phix);
82 for (int nu=0; nu<4; nu++)
83 sofphi -= 2 * real( conj(phix) * conf[ (*nb)[x*4+nu] ].phi );