4 #include <gsl/gsl_rng.h>
9 #include "latlib/neigh.h"
12 #define EPSILONPHI 0.5
14 class sim : public o815::sim {
19 complex<double> *U, *phi;
20 double kappa[2], lambda[2], beta;
27 double rhoPhi(const int& iphi, const int& x0, const complex<double>& candPhi);
28 double rhoU(const int& x0, const int& nu0, const complex<double>& candU);
29 int updatePhi(const int& iphi, const int& x0);
30 int updateU(const int& x0, const int& nu0);
33 sim::sim(o815 *_O815) : o815::sim( _O815,
34 sizeof(complex<double>)*
35 _O815->comargs.lsize[0]*_O815->comargs.lsize[0]*_O815->comargs.lsize[0]*_O815->comargs.lsize[1]*(2+4) ) {
39 lsize4 = _O815->comargs.lsize[0]*_O815->comargs.lsize[0]*_O815->comargs.lsize[0]*_O815->comargs.lsize[1];
41 nb = new neigh(4, _O815->comargs.lsize[0], _O815->comargs.lsize[0], _O815->comargs.lsize[0], _O815->comargs.lsize[1]);
43 phi = (complex<double>*)confMem;
44 U = (complex<double>*)(confMem + sizeof(complex<double>)*lsize4*2);
46 gettimeofday(&tv, NULL);
47 rangsl = gsl_rng_alloc(gsl_rng_ranlxs0);
48 gsl_rng_set(rangsl, 1000000 * tv.tv_sec + tv.tv_usec);
51 void sim::_makeSweep() {
52 for( int ix=0; ix<lsize4; ix++ ) {
53 for( int inu=0; inu<4; inu++) updateU(ix, inu);
54 for( int iphi=0; iphi<2; iphi++) updatePhi(iphi, ix);
58 void sim::_newParas() {
59 kappa[0] = (*O815->paraQ)["kappaone"];
60 kappa[1] = (*O815->paraQ)["kappatwo"];
61 lambda[0] = (*O815->paraQ)["lambdaone"];
62 lambda[1] = (*O815->paraQ)["lambdatwo"];
63 beta = (*O815->paraQ)["beta"];
66 void sim::_resetConfig() {
67 for(int ix=0; ix<lsize4; ix++) {
68 for(int i=0; i<2; i++) phi[ i*lsize4 + ix ] = 0;
69 for(int nu=0; nu<4; nu++) U[ ix*4 + nu ] = 1;
73 int sim::updateU(const int& x0, const int& nu0)
75 complex<double> candU = U[x0*4+nu0] * polar(1.0, 2*EPSILONU*( 0.5 - gsl_rng_uniform(rangsl) ));
77 if ( gsl_rng_uniform(rangsl) <= rhoU(x0, nu0, candU) ) {
78 U[x0*4 + nu0] = candU;
85 int sim::updatePhi(const int& iphi, const int& x0)
87 complex<double> candPhi = phi[ iphi*lsize4 + x0 ] +
88 complex<double>(2*EPSILONPHI*( 0.5 - gsl_rng_uniform(rangsl) ),
89 2*EPSILONPHI*( 0.5 - gsl_rng_uniform(rangsl) ));
91 if ( gsl_rng_uniform(rangsl) <= rhoPhi(iphi, x0, candPhi) ) {
92 phi[ iphi*lsize4 + x0 ] = candPhi;
99 double sim::rhoPhi(const int& iphi, const int& x0, const complex<double>& candPhi)
103 for( int mu=0; mu<4; mu++) {
105 deltaS += 2 * real( conj(phi[ iphi*lsize4 + x0 ]) * U[ x0*4 + mu ] * phi[ iphi*lsize4 + (*nb)[x0*8+mu] ] );
106 deltaS += 2 * real( conj(phi[ iphi*lsize4 + x0 ]) * conj(U[ (*nb)[x0*8+mu+4]*4 + mu ]) * phi[ iphi*lsize4 + (*nb)[x0*8+mu+4] ] );
107 deltaS -= 2 * real( conj(candPhi) * U[ x0*4 + mu ] * phi[ iphi*lsize4 + (*nb)[x0*8+mu] ] );
108 deltaS -= 2 * real( conj(candPhi) * conj(U[ (*nb)[x0*8+mu+4]*4 + mu ]) * phi[ iphi*lsize4 + (*nb)[x0*8+mu+4] ] );
110 else if( iphi == 1 ) {
111 deltaS += 2 * real( conj(phi[ iphi*lsize4 + x0 ]) * conj(U[ x0*4 + mu ]) * phi[ iphi*lsize4 + (*nb)[x0*8+mu] ] );
112 deltaS += 2 * real( conj(phi[ iphi*lsize4 + x0 ]) * U[ (*nb)[x0*8+mu+4]*4 + mu ] * phi[ iphi*lsize4 + (*nb)[x0*8+mu+4] ] );
113 deltaS -= 2 * real( conj(candPhi) * conj(U[ x0*4 + mu ]) * phi[ iphi*lsize4 + (*nb)[x0*8+mu] ] );
114 deltaS -= 2 * real( conj(candPhi) * U[ (*nb)[x0*8+mu+4]*4 + mu ] * phi[ iphi*lsize4 + (*nb)[x0*8+mu+4] ] );
118 deltaS -= kappa[iphi] * norm(phi[ iphi*lsize4 + x0 ]);
119 deltaS += kappa[iphi] * norm(candPhi);
121 deltaS -= lambda[iphi] * pow(norm(phi[ iphi*lsize4 + x0 ]),2);
122 deltaS += lambda[iphi] * pow(norm(candPhi),2);
127 double sim::rhoU(const int& x0, const int& nu0, const complex<double>& candU)
131 for( int nu=0; nu<4; nu++ ) {
132 if( nu == nu0 ) continue;
133 deltaS += beta * real( U[x0*4+nu0] * U[ (*nb)[x0*8+nu0]*4 + nu ] * conj(U[ (*nb)[x0*8+nu]*4 + nu0 ]) * conj(U[ x0*4 + nu ]) );
134 deltaS += beta * real( U[ (*nb)[x0*8+nu+4]*4 + nu0 ] * U[ (*nb)[ (*nb)[x0*8+nu+4]*8+nu0 ]*4 + nu ] * conj(U[ x0*4 + nu0 ]) * conj(U[ (*nb)[x0*8+nu+4]*4 + nu ]) );
135 deltaS -= beta * real( candU * U[ (*nb)[x0*8+nu0]*4 + nu ] * conj(U[ (*nb)[x0*8+nu]*4 + nu0 ]) * conj(U[ x0*4 + nu ]) );
136 deltaS -= beta * real( U[ (*nb)[x0*8+nu+4]*4 + nu0 ] * U[ (*nb)[ (*nb)[x0*8+nu+4]*8+nu0 ]*4 + nu ] * conj(candU) * conj(U[ (*nb)[x0*8+nu+4]*4 + nu ]) );
139 deltaS += 2 * real( conj(phi[ 0*lsize4 + x0 ]) * U[ x0*4 + nu0 ] * phi[ 0*lsize4 + (*nb)[x0*8+nu0] ] );
140 deltaS -= 2 * real( conj(phi[ 0*lsize4 + x0 ]) * candU * phi[ 0*lsize4 + (*nb)[x0*8+nu0] ] );
142 deltaS += 2 * real( conj(phi[ 1*lsize4 + x0 ]) * conj(U[ x0*4 + nu0 ]) * phi[ 1*lsize4 + (*nb)[x0*8+nu0] ] );
143 deltaS -= 2 * real( conj(phi[ 1*lsize4 + x0 ]) * conj(candU) * phi[ 1*lsize4 + (*nb)[x0*8+nu0] ] );