From dca762861c66d8782be31811822812d347ee4577 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 25 Nov 2013 13:59:54 +0100 Subject: [PATCH] Added - algorithms. --- .gitignore | 2 ++ CMakeLists.txt | 8 +++++ heatbath.cpp | 6 ++++ obs_phip2_hist.hpp | 35 ++++++++++---------- sim-1mr-.hpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++ sim-r-.hpp | 76 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 187 insertions(+), 19 deletions(-) create mode 100644 sim-1mr-.hpp create mode 100644 sim-r-.hpp diff --git a/.gitignore b/.gitignore index f6507bd..9b2b6d7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ heatbath-nor heatbath-1mr heatbath-r heatbath-1mr+ +heatbath-1mr- +heatbath-r- diff --git a/CMakeLists.txt b/CMakeLists.txt index 41c8e07..3e554d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,3 +26,11 @@ target_link_libraries(heatbath-1mr o815 gsl gslcblas lat_neigh) add_executable(heatbath-1mr+ heatbath.cpp) set_target_properties(heatbath-1mr+ PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_1MRPLUS") target_link_libraries(heatbath-1mr+ o815 gsl gslcblas lat_neigh) + +add_executable(heatbath-1mr- heatbath.cpp) +set_target_properties(heatbath-1mr- PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_1MRMINUS") +target_link_libraries(heatbath-1mr- o815 gsl gslcblas lat_neigh) + +add_executable(heatbath-r- heatbath.cpp) +set_target_properties(heatbath-r- PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_RMINUS") +target_link_libraries(heatbath-r- o815 gsl gslcblas lat_neigh) diff --git a/heatbath.cpp b/heatbath.cpp index a6f0859..0c1348d 100644 --- a/heatbath.cpp +++ b/heatbath.cpp @@ -14,6 +14,12 @@ #elif ALGORITHM_1MRPLUS #define ALGORITHM "1mr+" #include "sim-1mr+.hpp" +#elif ALGORITHM_1MRMINUS +#define ALGORITHM "1mr-" +#include "sim-1mr-.hpp" +#elif ALGORITHM_RMINUS +#define ALGORITHM "r-" +#include "sim-r-.hpp" #else #error NO UPDATE-ALGORITHM DEFINED! #endif diff --git a/obs_phip2_hist.hpp b/obs_phip2_hist.hpp index a239d0e..60c86b8 100644 --- a/obs_phip2_hist.hpp +++ b/obs_phip2_hist.hpp @@ -15,7 +15,7 @@ class obs_phip2_hist : public o815::obs { public: struct obsmem { - double phip2[2]; + double phip2[4]; }; obs_phip2_hist(o815 *_O815); @@ -28,7 +28,7 @@ private: }; obs_phip2_hist::obs_phip2_hist(o815 *_O815) : o815::obs("phip2", - _O815->paraQ->getParaNames() + "nthstep:iruv:phip2absdiffequi", _O815, + _O815->paraQ->getParaNames() + "nthstep:imode:kt:kx:phip2absdiffequi", _O815, sizeof(obsmem), "_hist") { OM = (obsmem*)obsMem; @@ -36,33 +36,30 @@ obs_phip2_hist::obs_phip2_hist(o815 *_O815) : o815::obs("phip2", } void obs_phip2_hist::_meas(bool loadedobs, const int& nthmeas) { - if (!loadedobs) { - for (int kpiruv=0; kpiruv<2; kpiruv++) { - double ppt = 2.*M_PI/O815->comargs.lsize[0] * ( 0 + kpiruv * O815->comargs.lsize[0]/2 ) ; - double ppx = 2.*M_PI/O815->comargs.lsize[1] * ( 0 + kpiruv * O815->comargs.lsize[1]/2 ); + for (int kpimode=0; kpimode<4; kpimode++) { + const double ppt = 2.*M_PI/O815->comargs.lsize[0] * ( 0 + int( kpimode/4. * O815->comargs.lsize[0] ) ) ; + const double ppx = 2.*M_PI/O815->comargs.lsize[1] * ( 0 + int( kpimode/4. * O815->comargs.lsize[1] ) ); - OM->phip2[ kpiruv ] = 0; + if (!loadedobs) { + OM->phip2[ kpimode ] = 0; for (int ixt = 0; ixt < O815->comargs.lsize[0]; ixt++) for (int ixx = 0; ixx < O815->comargs.lsize[1]; ixx++) for (int ixpt = 0; ixpt < O815->comargs.lsize[0]; ixpt++) for (int ixpx = 0; ixpx < O815->comargs.lsize[1]; ixpx++) - OM->phip2[ kpiruv ] += real( conj( Sim->conf[ ixt*O815->comargs.lsize[1] + ixx ].phi ) - * Sim->conf[ ixpt*O815->comargs.lsize[1] + ixpx ].phi - * exp ( _i_*(double)ppx*(double)(ixx-ixpx) + _i_*(double)ppt*(double)(ixt-ixpt) ) ); + OM->phip2[ kpimode ] += real( conj( Sim->conf[ ixt*O815->comargs.lsize[1] + ixx ].phi ) + * Sim->conf[ ixpt*O815->comargs.lsize[1] + ixpx ].phi + * exp ( _i_*(double)ppx*(double)(ixx-ixpx) + _i_*(double)ppt*(double)(ixt-ixpt) ) ); - OM->phip2[ kpiruv ] /= Sim->LSIZE2; + OM->phip2[ kpimode ] /= Sim->LSIZE2; } - } - - for (int kpiruv=0; kpiruv<2; kpiruv++) { - double ppt = 2.*M_PI/O815->comargs.lsize[0] * ( 0 + kpiruv * O815->comargs.lsize[0]/2 ) ; - double ppx = 2.*M_PI/O815->comargs.lsize[1] * ( 0 + kpiruv * O815->comargs.lsize[1]/2 ); - + *out << O815->paraQ->getParaVals(); *out << "\t" << ( Sim->nequi + (nthmeas+1)*Sim->nskip ); - *out << "\t" << kpiruv; - *out << "\t" << abs( OM->phip2[ kpiruv ] - 1./(ppt*ppt + ppx*ppx + Sim->m*Sim->m) ) << endl; + *out << "\t" << kpimode; + *out << "\t" << 0 + int( kpimode/4. * O815->comargs.lsize[0] ); + *out << "\t" << 0 + int( kpimode/4. * O815->comargs.lsize[1] ); + *out << "\t" << abs( OM->phip2[ kpimode ] - 1./(ppt*ppt + ppx*ppx + Sim->m*Sim->m) ) << endl; } }; diff --git a/sim-1mr-.hpp b/sim-1mr-.hpp new file mode 100644 index 0000000..00e15be --- /dev/null +++ b/sim-1mr-.hpp @@ -0,0 +1,79 @@ +#ifndef SIM_HPP +#define SIM_HPP + +#include +#include +#include + +#include "latlib/neigh.h" + +class sim : public o815::sim { +public: + struct siteconf { + complex phi; + }; + sim(o815 *_O815); + siteconf* conf; + unsigned int LSIZE2; + double M; + double m; + neigh *nb; + +private: + void _makeSweep(); + void _newParas(); + gsl_rng* rangsl; + void updatePhi (const int& x); +}; + + + +sim::sim(o815 *_O815) : o815::sim( _O815, + sizeof(siteconf)* + (_O815->comargs.lsize[0]*_O815->comargs.lsize[1]) ) { + conf = (siteconf*)confMem; + + rangsl = gsl_rng_alloc(gsl_rng_ranlxs0); + gsl_rng_set(rangsl, time(NULL)); + + LSIZE2 = _O815->comargs.lsize[0] * _O815->comargs.lsize[1]; + + nb = new neigh(2, _O815->comargs.lsize[0], _O815->comargs.lsize[1]); +} + +void sim::updatePhi (const int& x) +{ + const double theta = gsl_rng_uniform(rangsl) * 2*M_PI; + complex V=0; + + for (int nu=0; nu<4; nu++) + V += conf[ (*nb)[x*4+nu] ].phi; + + const double r = exp( - M * norm(conf[x].phi) + - 1./M * norm(V) + + 2 * real( conf[x].phi * conj(V) ) ); + + double oldarg = arg(conf[x].phi); + + conf[x].phi = sqrt(std::log( 1./(1-r) )) / sqrt(M) + * polar(1.0, oldarg) + + V / M; +} + +void sim::_makeSweep() { + for (int ichecker=0; ichecker<2; ichecker++) + for (int it=0; itcomargs.lsize[0]; it++) + for (int iy=(it+ichecker)%2; iycomargs.lsize[1]; iy+=2) + updatePhi( it*O815->comargs.lsize[1] + iy ); +} + +void sim::_newParas() { + m = (*O815->paraQ)["mass"]; + M = pow( (*O815->paraQ)["mass"], 2 ) + 4; + *log << "SIM: Resetting fields." << endl << flush; + + for (int ix=0; ix +#include +#include + +#include "latlib/neigh.h" + +class sim : public o815::sim { +public: + struct siteconf { + complex phi; + }; + sim(o815 *_O815); + siteconf* conf; + unsigned int LSIZE2; + double M; + double m; + neigh *nb; + +private: + void _makeSweep(); + void _newParas(); + gsl_rng* rangsl; + void updatePhi (const int& x); +}; + + + +sim::sim(o815 *_O815) : o815::sim( _O815, + sizeof(siteconf)* + (_O815->comargs.lsize[0]*_O815->comargs.lsize[1]) ) { + conf = (siteconf*)confMem; + + rangsl = gsl_rng_alloc(gsl_rng_ranlxs0); + gsl_rng_set(rangsl, time(NULL)); + + LSIZE2 = _O815->comargs.lsize[0] * _O815->comargs.lsize[1]; + + nb = new neigh(2, _O815->comargs.lsize[0], _O815->comargs.lsize[1]); +} + +void sim::updatePhi (const int& x) +{ + const double r = gsl_rng_uniform(rangsl); + const double theta = gsl_rng_uniform(rangsl) * 2*M_PI; + complex V=0; + + for (int nu=0; nu<4; nu++) + V += conf[ (*nb)[x*4+nu] ].phi; + + double oldarg = arg(conf[x].phi); + + conf[x].phi = sqrt(std::log( 1./(1-r) )) / sqrt(M) + * polar(1.0, oldarg) + + V / M; +} + +void sim::_makeSweep() { + for (int ichecker=0; ichecker<2; ichecker++) + for (int it=0; itcomargs.lsize[0]; it++) + for (int iy=(it+ichecker)%2; iycomargs.lsize[1]; iy+=2) + updatePhi( it*O815->comargs.lsize[1] + iy ); +} + +void sim::_newParas() { + m = (*O815->paraQ)["mass"]; + M = pow( (*O815->paraQ)["mass"], 2 ) + 4; + *log << "SIM: Resetting fields." << endl << flush; + + for (int ix=0; ix