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;
26 double rhoPhi(const int& iphi, const int& x0, const complex<double>& candPhi);
27 double rhoU(const int& x0, const int& nu0, const complex<double>& candU);
28 int updatePhi(const int& iphi, const int& x0);
29 int updateU(const int& x0, const int& nu0);
32 sim::sim(o815 *_O815) : o815::sim( _O815,
33 sizeof(complex<double>)*
34 _O815->comargs.lsize[0]*_O815->comargs.lsize[0]*_O815->comargs.lsize[0]*_O815->comargs.lsize[1]*(2+4) ) {
38 lsize4 = _O815->comargs.lsize[0]*_O815->comargs.lsize[0]*_O815->comargs.lsize[0]*_O815->comargs.lsize[1];
40 nb = new neigh(4, _O815->comargs.lsize[0], _O815->comargs.lsize[0], _O815->comargs.lsize[0], _O815->comargs.lsize[1]);
42 phi = (complex<double>*)confMem;
43 U = (complex<double>*)(confMem + sizeof(complex<double>)*lsize4*2);
45 gettimeofday(&tv, NULL);
46 rangsl = gsl_rng_alloc(gsl_rng_ranlxs0);
47 gsl_rng_set(rangsl, 1000000 * tv.tv_sec + tv.tv_usec);
50 void sim::_makeSweep() {
51 for( int ix=0; ix<lsize4; ix++ ) {
52 for( int inu=0; inu<4; inu++) updateU(ix, inu);
53 for( int iphi=0; iphi<2; iphi++) updatePhi(iphi, ix);
57 void sim::_newParas() {
58 kappa[0] = (*O815->paraQ)["kappaone"];
59 kappa[1] = (*O815->paraQ)["kappatwo"];
60 lambda[0] = (*O815->paraQ)["lambdaone"];
61 lambda[1] = (*O815->paraQ)["lambdatwo"];
62 beta = (*O815->paraQ)["beta"];
64 for(int ix=0; ix<lsize4; ix++) {
65 for(int i=0; i<2; i++) phi[ i*lsize4 + ix ] = 0;
66 for(int nu=0; nu<4; nu++) U[ ix*4 + nu ] = 1;
70 int sim::updateU(const int& x0, const int& nu0)
72 complex<double> candU = U[x0*4+nu0] * polar(1.0, 2*EPSILONU*( 0.5 - gsl_rng_uniform(rangsl) ));
74 if ( gsl_rng_uniform(rangsl) <= rhoU(x0, nu0, candU) ) {
75 U[x0*4 + nu0] = candU;
82 int sim::updatePhi(const int& iphi, const int& x0)
84 complex<double> candPhi = phi[ iphi*lsize4 + x0 ] +
85 complex<double>(2*EPSILONPHI*( 0.5 - gsl_rng_uniform(rangsl) ),
86 2*EPSILONPHI*( 0.5 - gsl_rng_uniform(rangsl) ));
88 if ( gsl_rng_uniform(rangsl) <= rhoPhi(iphi, x0, candPhi) ) {
89 phi[ iphi*lsize4 + x0 ] = candPhi;
96 double sim::rhoPhi(const int& iphi, const int& x0, const complex<double>& candPhi)
100 for( int mu=0; mu<4; mu++) {
102 deltaS += 2 * real( conj(phi[ iphi*lsize4 + x0 ]) * U[ x0*4 + mu ] * phi[ iphi*lsize4 + (*nb)[x0*8+mu] ] );
103 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] ] );
104 deltaS -= 2 * real( conj(candPhi) * U[ x0*4 + mu ] * phi[ iphi*lsize4 + (*nb)[x0*8+mu] ] );
105 deltaS -= 2 * real( conj(candPhi) * conj(U[ (*nb)[x0*8+mu+4]*4 + mu ]) * phi[ iphi*lsize4 + (*nb)[x0*8+mu+4] ] );
107 else if( iphi == 1 ) {
108 deltaS += 2 * real( conj(phi[ iphi*lsize4 + x0 ]) * conj(U[ x0*4 + mu ]) * phi[ iphi*lsize4 + (*nb)[x0*8+mu] ] );
109 deltaS += 2 * real( conj(phi[ iphi*lsize4 + x0 ]) * U[ (*nb)[x0*8+mu+4]*4 + mu ] * phi[ iphi*lsize4 + (*nb)[x0*8+mu+4] ] );
110 deltaS -= 2 * real( conj(candPhi) * conj(U[ x0*4 + mu ]) * phi[ iphi*lsize4 + (*nb)[x0*8+mu] ] );
111 deltaS -= 2 * real( conj(candPhi) * U[ (*nb)[x0*8+mu+4]*4 + mu ] * phi[ iphi*lsize4 + (*nb)[x0*8+mu+4] ] );
115 deltaS -= kappa[iphi] * norm(phi[ iphi*lsize4 + x0 ]);
116 deltaS += kappa[iphi] * norm(candPhi);
118 deltaS -= lambda[iphi] * pow(norm(phi[ iphi*lsize4 + x0 ]),2);
119 deltaS += lambda[iphi] * pow(norm(candPhi),2);
124 double sim::rhoU(const int& x0, const int& nu0, const complex<double>& candU)
128 for( int nu=0; nu<4; nu++ ) {
129 if( nu == nu0 ) continue;
130 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 ]) );
131 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 ]) );
132 deltaS -= beta * real( candU * U[ (*nb)[x0*8+nu0]*4 + nu ] * conj(U[ (*nb)[x0*8+nu]*4 + nu0 ]) * conj(U[ x0*4 + nu ]) );
133 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 ]) );
136 deltaS += 2 * real( conj(phi[ 0*lsize4 + x0 ]) * U[ x0*4 + nu0 ] * phi[ 0*lsize4 + (*nb)[x0*8+nu0] ] );
137 deltaS -= 2 * real( conj(phi[ 0*lsize4 + x0 ]) * candU * phi[ 0*lsize4 + (*nb)[x0*8+nu0] ] );
139 deltaS += 2 * real( conj(phi[ 1*lsize4 + x0 ]) * conj(U[ x0*4 + nu0 ]) * phi[ 1*lsize4 + (*nb)[x0*8+nu0] ] );
140 deltaS -= 2 * real( conj(phi[ 1*lsize4 + x0 ]) * conj(candU) * phi[ 1*lsize4 + (*nb)[x0*8+nu0] ] );