From 7c70f0d280537866677146856170efc54ed7c9ca Mon Sep 17 00:00:00 2001 From: Manuel Date: Sat, 26 Jun 2021 23:25:54 +0200 Subject: [PATCH 01/14] almost compiles --- src/CMakeLists.txt | 6 ++ src/config.h | 3 + src/hamiltonian/MassiveScalarField.h | 156 +++++++++++++++++++++++++++ src/kleingordon.cpp | 107 ++++++++++++++++++ 4 files changed, 272 insertions(+) create mode 100644 src/config.h create mode 100644 src/hamiltonian/MassiveScalarField.h create mode 100644 src/kleingordon.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b0fdfb2..7548629 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,12 @@ target_include_directories(mysimpleheisenbergthreaded PUBLIC ${MYHDF5INCLUDES}) target_link_libraries(mysimpleheisenbergthreaded libmarqov) set_target_properties(mysimpleheisenbergthreaded PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED YES) +# configuration for the Klein-Gordon case +add_executable(kleingordon kleingordon.cpp libmarqov/marqov.cpp) +target_include_directories(kleingordon PUBLIC ${MYHDF5INCLUDES}) +target_link_libraries(kleingordon libmarqov) +set_target_properties(kleingordon PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED YES) + # configuration of the main parts. SET(MARQOVTARGETS MARQOV mpiMARQOV) diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..f43a111 --- /dev/null +++ b/src/config.h @@ -0,0 +1,3 @@ +#define HAVE_SCANDIR +#define HAVE_ALPHASORT +#define HAVE_READDIR_R diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h new file mode 100644 index 0000000..a580048 --- /dev/null +++ b/src/hamiltonian/MassiveScalarField.h @@ -0,0 +1,156 @@ +#ifndef PHI4_H +#define PHI4_H +#include +#include +#include +#include "util/randomdir.h" +#include "util/hamparts.h" +#include "util/termcollection.h" + + +auto hyperfilter = [](auto p) +{ + auto& mp = std::get<1>(p); + auto& hp = std::get<2>(p); + + std::string str_repid = std::to_string(mp.repid); + std::string str_mass = "mass"+std::to_string(std::get<2>(hp)); + mp.outname = str_mass + "_" + str_repid; + + return p; +}; + + +// ------------------------------ OBSERVABLES --------------------------- + +#include "util/observables.h" + + + + +// ------------------------------ HAMILTONIAN -------------------------- + + +template +class FiniteDifferencesInteraction +{ + + public: + const double k; + FiniteDifferencesInteraction(double k) : k(k) {} + ~FiniteDifferencesInteraction() {} + + double diff (const int rsite, + const StateVector& svold, + const StateVector& svnew, + std::vector& nbrs, + StateSpace& s) + + { + double energy_old = 0; + double energy_new = 0; + for (std::size_t i=0; i StateVector; + + + + // ---- Hamiltonian terms ---- + + Onsite_Quadratic onsite_standard; + FiniteDifferencesInteraction, StateVector> maininteraction; + + std::array*, 1> interactions = {new Standard_Interaction(0)}; + std::vector*> onsite; // empty here, to be filled in the constructor! + std::vector,StateVector>*> multisite; + + MassiveScalarField(double k, double mass) : + k(k), mass(mass), name("MassiveScalarField"), onsite_standard(mass), maininteraction(k) + { + onsite.push_back(&onsite_standard); + multisite.push_back(&maininteraction); + } + + + + // ---- Observables ---- + + Magnetization obs_m; + decltype(std::make_tuple(obs_m)) observables = {std::make_tuple(obs_m)}; + + + + // ---- Parameter Names ---- + + /** Allows to give the Hamiltonian parameter names + * + * @param i index of the parameter + * + * @return the parameter name (string) + */ + std::string paramname(int i) + { + std::string name; + switch (i) + { + case (0): name = "k"; break; + case (1): name = "mass"; break; + default: break; + } + return name; + } +}; + + +// ------------------------------ INITIALIZER --------------------------- + +template +class Initializer +{ + public: + Initializer() {} + + template + static StateVector newsv(const StateVector& svold, RNGCache& rng) + { + double amp = 0.5; // Amplitude (TODO: make me a class parameter) + double r = rng.real(-1.0, 1.0); + double oldval = osv[0]; + double newval = oldval + amp*r; + auto nsv = osv + nsv[comp] = newval; + return nsv; + } +}; + + + +#endif diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp new file mode 100644 index 0000000..7ab47fc --- /dev/null +++ b/src/kleingordon.cpp @@ -0,0 +1,107 @@ +/* MARQOV - A modern framework for classical spin models on general topologies + * Copyright (C) 2020-2021, The MARQOV Project + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using std::cout; +using std::endl; +using std::flush; +using std::ofstream; + +// MARQOV +#include "libmarqov/libmarqov.h" + +// Lattices +#include "lattice/graph_from_csv.h" + +// Hamiltonians +#include "hamiltonian/MassiveScalarField.h" + +using namespace MARQOV; + + +int main() +{ + + std::cout<<"MARQOV Copyright (C) 2020-2021, The MARQOV Project contributors"< beta = {1.0}; + std::vector K = {-1.0}; + std::vector mass = {2,4,6,8}; + + auto hp = cart_prod(beta, K, mass); + + const int nthreads = 1; + const int nreplicas = 1; + + + + // Typedefs + typedef MassiveScalarField Hamiltonian; + typedef GraphFromCSV Lattice; + + std::string latfile = "/home/schrauth/marqov/marqov-dev/src/geometry/7-3-8.csv"; + GraphFromCSV lat(latfile); + + typedef typename std::tuple > ParameterType; + typedef typename GetSchedulerType::MarqovScheduler SchedulerType; + SchedulerType sched(1,nthreads); + + // prepare output + std::string outpath = outbasedir+"/hyperbolic/"; + makeDir(outpath); + + // Monte Carlo parameters + MARQOV::Config mp(outpath); + mp.setnmetro(1); + mp.setncluster(0); + mp.setwarmupsteps(0); + mp.setgameloopsteps(1000); + + // lattice parameters + // form parameter triple and replicate + auto params = finalize_parameter(lat, mp, hp); + auto rparams = replicator(params, nreplicas); + + // schedule simulations + for (auto p: rparams) sched.createSimfromParameter(p, hyperfilter); + + // run! + sched.start(); + +} -- GitLab From 395156cf81f9b7940ecacb4594d650f9f56e2511 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sat, 26 Jun 2021 23:32:57 +0200 Subject: [PATCH 02/14] fix GraphFromCSV --- src/lattice/graph_from_csv.h | 2 +- src/lattice/util/io.h | 49 ------------------------------------ 2 files changed, 1 insertion(+), 50 deletions(-) diff --git a/src/lattice/graph_from_csv.h b/src/lattice/graph_from_csv.h index facab01..f07d5f4 100644 --- a/src/lattice/graph_from_csv.h +++ b/src/lattice/graph_from_csv.h @@ -58,7 +58,7 @@ class GraphFromCSVwithCoords std::vector> neighbours; std::vector> grid; - GraphFromCSV(std::string filename, ncoords) + GraphFromCSVwithCoords(std::string filename, int ncoords) { npoints = import_geometry(filename, grid, neighbours, ncoords); } diff --git a/src/lattice/util/io.h b/src/lattice/util/io.h index b4d28ae..dd49c0c 100644 --- a/src/lattice/util/io.h +++ b/src/lattice/util/io.h @@ -84,55 +84,6 @@ void save_geometry_deluxe(Grid& grid, const std::string path) } -/** -* Import CSV lattice file containing coordinates and connections between vertices. -* -* @param path the filename -* @param grid the coordinates will be stored here -* @param nbrs the bonds will be stored here -* @param ncoords number of coordinates per point -* -* @return number of points -*/ -int import_geometry(const std::string path, std::vector>& grid, std::vector>& nbrs, int ncoords) -{ - int idxoffs = 1; - // set to 1 if vertex indices in the CSV are counted from 1. Set 0 zero if they are counted from 0 - - std::ifstream in(NULL); - in.open(path.c_str()); - std::string row; - - // loop over lines - while (!in.eof()) - { - std::getline(in, row); - if (in.bad() || in.fail()) - { - break; - } - std::istringstream ss(row); - std::string substr; - - int counter = 0; - std::vector g; - std::vector n; - - // loop over "words" in a line - while(std::getline(ss, substr, '\t')) - { - // if coordinate, transform to double - if (counter < ncoords) g.push_back(std::stod(substr)); - // if vertex, transform to int - else n.push_back(std::stoi(substr)-idxoffs); - counter++; - } - grid.push_back(g); - nbrs.push_back(n); - } - return nbrs.size(); -} - /** * @brief Import coordinates and neighbour relations from CSV file * -- GitLab From 3c409212b9664b61690645fb6aac84b8cdc3fa6f Mon Sep 17 00:00:00 2001 From: Manuel Date: Sat, 26 Jun 2021 23:39:32 +0200 Subject: [PATCH 03/14] fix remaining template problems --- src/hamiltonian/MassiveScalarField.h | 13 ++++++++----- src/kleingordon.cpp | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index a580048..1585326 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -132,21 +132,24 @@ class MassiveScalarField // ------------------------------ INITIALIZER --------------------------- -template +//template +template <> class Initializer { public: Initializer() {} template - static StateVector newsv(const StateVector& svold, RNGCache& rng) +// static StateVector newsv(const StateVector& svold, RNGCache& rng) + static typename MassiveScalarField::StateVector newsv(const typename MassiveScalarField::StateVector& svold, RNGCache& rng) { double amp = 0.5; // Amplitude (TODO: make me a class parameter) double r = rng.real(-1.0, 1.0); - double oldval = osv[0]; + + double oldval = svold[0]; double newval = oldval + amp*r; - auto nsv = osv - nsv[comp] = newval; + auto nsv = svold; + nsv[0] = newval; return nsv; } }; diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index 7ab47fc..bc220c7 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -78,7 +78,7 @@ int main() std::string latfile = "/home/schrauth/marqov/marqov-dev/src/geometry/7-3-8.csv"; GraphFromCSV lat(latfile); - typedef typename std::tuple > ParameterType; + typedef typename std::tuple > ParameterType; typedef typename GetSchedulerType::MarqovScheduler SchedulerType; SchedulerType sched(1,nthreads); -- GitLab From b01cead3965f62b93bb8fcc5eef9f92bdd60ac89 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 27 Jun 2021 08:24:33 +0200 Subject: [PATCH 04/14] adjust initializer, metropolis, set variables to their actual values --- src/hamiltonian/MassiveScalarField.h | 36 +++++++++++++++++++++------- src/kleingordon.cpp | 17 ++++++------- src/lattice/graph_from_csv.h | 4 ++++ src/libmarqov/core.h | 2 +- src/libmarqov/metropolis.h | 4 ++++ 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index 1585326..ab9d1e5 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -14,7 +14,7 @@ auto hyperfilter = [](auto p) auto& hp = std::get<2>(p); std::string str_repid = std::to_string(mp.repid); - std::string str_mass = "mass"+std::to_string(std::get<2>(hp)); + std::string str_mass = "mass"+std::to_string(std::get<3>(hp)); mp.outname = str_mass + "_" + str_repid; return p; @@ -72,7 +72,7 @@ class MassiveScalarField public: // ---- Parameters ---- - double beta, k, mass; + double beta, k, mass, sqrtg; static constexpr int SymD = 1; const std::string name = "MassiveScalarField"; @@ -80,20 +80,25 @@ class MassiveScalarField // ---- Definitions ----- typedef std::array StateVector; + typedef MARQOV::Space StateSpace; // ---- Hamiltonian terms ---- Onsite_Quadratic onsite_standard; - FiniteDifferencesInteraction, StateVector> maininteraction; + FiniteDifferencesInteraction maininteraction; std::array*, 1> interactions = {new Standard_Interaction(0)}; std::vector*> onsite; // empty here, to be filled in the constructor! - std::vector,StateVector>*> multisite; - - MassiveScalarField(double k, double mass) : - k(k), mass(mass), name("MassiveScalarField"), onsite_standard(mass), maininteraction(k) + std::vector*> multisite; + + MassiveScalarField(double k, double sqrtg, double mass) : k(k), + mass(-mass), + sqrtg(sqrtg), + name("MassiveScalarField"), + onsite_standard(-0.5*sqrtg*mass), + maininteraction(0.5*k) { onsite.push_back(&onsite_standard); multisite.push_back(&maininteraction); @@ -122,11 +127,26 @@ class MassiveScalarField switch (i) { case (0): name = "k"; break; - case (1): name = "mass"; break; + case (1): name = "sqrtg"; break; + case (2): name = "mass"; break; default: break; } return name; } + + + // ---- Initializer ---- + + template + void initstatespace(StateSpace& statespace, Lattice& grid, RNG& rng) const + { + for(decltype(grid.size()) i = 0; i < grid.size(); ++i) + { + auto nnbrs = grid.nbrs(0,i).size(); + if (nnbrs < 7) statespace[i][0] = 1; + else statespace[i] = rnddir(rng); + } + } }; diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index bc220c7..54a35c4 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -51,7 +51,7 @@ int main() // remove old output and prepare new one - std::string outbasedir = "../out/hyperbolic"; + std::string outbasedir = "../out"; std::string command; command = "rm -r " + outbasedir; system(command.c_str()); @@ -61,12 +61,13 @@ int main() // Parameters std::vector beta = {1.0}; - std::vector K = {-1.0}; - std::vector mass = {2,4,6,8}; + std::vector K = {0.50315223}; // geometric factor + std::vector sqrtg = {1.0471975511}; // geometric factor + std::vector mass = {0.3, 0.4, 0.5, 0.6, 0.7}; // negative mass squared - auto hp = cart_prod(beta, K, mass); + auto hp = cart_prod(beta, K, sqrtg, mass); - const int nthreads = 1; + const int nthreads = 3; const int nreplicas = 1; @@ -75,10 +76,10 @@ int main() typedef MassiveScalarField Hamiltonian; typedef GraphFromCSV Lattice; - std::string latfile = "/home/schrauth/marqov/marqov-dev/src/geometry/7-3-8.csv"; + std::string latfile = "/home/schrauth/hyperbolic-7-3-9.csv"; GraphFromCSV lat(latfile); - typedef typename std::tuple > ParameterType; + typedef typename std::tuple > ParameterType; typedef typename GetSchedulerType::MarqovScheduler SchedulerType; SchedulerType sched(1,nthreads); @@ -91,7 +92,7 @@ int main() mp.setnmetro(1); mp.setncluster(0); mp.setwarmupsteps(0); - mp.setgameloopsteps(1000); + mp.setgameloopsteps(3000); // lattice parameters // form parameter triple and replicate diff --git a/src/lattice/graph_from_csv.h b/src/lattice/graph_from_csv.h index f07d5f4..f167d05 100644 --- a/src/lattice/graph_from_csv.h +++ b/src/lattice/graph_from_csv.h @@ -43,6 +43,10 @@ class GraphFromCSV return neighbours[i]; } + std::vector flexnbrs(const int a, const int i) const + { + return neighbours[i]; + } std::size_t size() const {return npoints;} }; diff --git a/src/libmarqov/core.h b/src/libmarqov/core.h index c288ebb..98c8bd5 100644 --- a/src/libmarqov/core.h +++ b/src/libmarqov/core.h @@ -613,7 +613,7 @@ class Core : public RefType auto retval = new typename Hamiltonian::StateVector[size]; if (step > 0) { - std::cout<<"[MARQOV::Core] Previous data found! Continuing simulation at step "<::type HasInt; -- GitLab From f5d7b43cf3f8317e3fc51a17cbff6dfdf29a3d5b Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 28 Jun 2021 23:20:48 +0200 Subject: [PATCH 05/14] adjustments --- src/hamiltonian/MassiveScalarField.h | 44 +++++++++++++++++++++++++++- src/kleingordon.cpp | 31 +++++++++++--------- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index ab9d1e5..1c59fae 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -25,7 +25,47 @@ auto hyperfilter = [](auto p) #include "util/observables.h" +class BulkMagnetization +{ + public: + std::string name; ///< The name of the observable + std::string desc; ///< A helpful description that will be used in the HDF5 output files. + + /** Construct a bulk magnetization object + * + */ + BulkMagnetization() : name("mb"), desc("bulk magnetization") {} + + template + double measure(const StateSpace& statespace, const Grid& grid) + { + // q used to distinguish boundary and bulk sites; bulk sites have q neighbours, boundary ones less + const int q = 7; // hard-coded (fixme) + + const/*expr static*/ int SymD = statespace[0].size(); + std::vector mag(SymD, 0); + int counter = 0; + for (decltype(grid.size()) i = 0; i < grid.size(); i++) + { + auto nbrs = grid.nbrs(i,0); + int nnbrs = nbrs.size(); + if (nnbrs == q) + { + counter++; + for (int j=0; j(rng); +// statespace[i] = rnddir(rng); } } }; diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index 54a35c4..ea3f47b 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -49,13 +49,14 @@ int main() std::cout<<"This program comes with ABSOLUTELY NO WARRANTY."< beta = {1.0}; std::vector K = {0.50315223}; // geometric factor std::vector sqrtg = {1.0471975511}; // geometric factor - std::vector mass = {0.3, 0.4, 0.5, 0.6, 0.7}; // negative mass squared + std::vector mass = {.33, .34, .35}; // negative mass squared auto hp = cart_prod(beta, K, sqrtg, mass); - + const int nthreads = 3; const int nreplicas = 1; - - + // Typedefs typedef MassiveScalarField Hamiltonian; typedef GraphFromCSV Lattice; - std::string latfile = "/home/schrauth/hyperbolic-7-3-9.csv"; + // Lattice + int nlayers = 12; + std::string latfile = "/home/schrauth/hyperbolic-7-3-"+std::to_string(nlayers)+".csv"; GraphFromCSV lat(latfile); + // Scheduler typedef typename std::tuple > ParameterType; typedef typename GetSchedulerType::MarqovScheduler SchedulerType; SchedulerType sched(1,nthreads); - // prepare output - std::string outpath = outbasedir+"/hyperbolic/"; + // Output + std::string outpath = outbasedir+"/hyperbolic-"+std::to_string(nlayers)+"/"; makeDir(outpath); - // Monte Carlo parameters + // Monte Carlo MARQOV::Config mp(outpath); - mp.setnmetro(1); + mp.setnmetro(10); mp.setncluster(0); mp.setwarmupsteps(0); - mp.setgameloopsteps(3000); + mp.setgameloopsteps(500); // lattice parameters // form parameter triple and replicate -- GitLab From d335983b16f7da7eb97117f9c7895d2e2c900267 Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 30 Jun 2021 14:15:35 +0200 Subject: [PATCH 06/14] second Hamiltonian for comparison; should be equivalent --- src/hamiltonian/MassiveScalarField.h | 22 +++-- src/hamiltonian/MassiveScalarField2.h | 126 ++++++++++++++++++++++++++ src/kleingordon.cpp | 13 ++- src/libmarqov/metropolis.h | 4 +- 4 files changed, 148 insertions(+), 17 deletions(-) create mode 100644 src/hamiltonian/MassiveScalarField2.h diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index 1c59fae..2b8f7d7 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -1,5 +1,5 @@ -#ifndef PHI4_H -#define PHI4_H +#ifndef MASSIVESCALARFIELD_H +#define MASSIVESCALARFIELD_H #include #include #include @@ -129,15 +129,18 @@ class MassiveScalarField Onsite_Quadratic onsite_standard; FiniteDifferencesInteraction maininteraction; + + // write specialization for Wolff in order to get rid of "interactions" + std::array*, 1> interactions = {new Standard_Interaction(0)}; std::vector*> onsite; // empty here, to be filled in the constructor! std::vector*> multisite; MassiveScalarField(double k, double sqrtg, double mass) : k(k), - mass(-mass), + mass(mass), sqrtg(sqrtg), name("MassiveScalarField"), - onsite_standard(-0.5*sqrtg*mass), + onsite_standard(0.5*sqrtg*mass), maininteraction(0.5*k) { onsite.push_back(&onsite_standard); @@ -183,10 +186,10 @@ class MassiveScalarField { for(decltype(grid.size()) i = 0; i < grid.size(); ++i) { - auto nnbrs = grid.nbrs(0,i).size(); - if (nnbrs < 7) statespace[i][0] = 1; - else statespace[i] = rnddir(rng); -// statespace[i] = rnddir(rng); +// auto nnbrs = grid.nbrs(0,i).size(); +// if (nnbrs < 7) statespace[i][0] = 1; +// else statespace[i] = rnddir(rng); + statespace[i] = rnddir(rng); } } }; @@ -194,7 +197,6 @@ class MassiveScalarField // ------------------------------ INITIALIZER --------------------------- -//template template <> class Initializer { @@ -202,7 +204,7 @@ class Initializer Initializer() {} template -// static StateVector newsv(const StateVector& svold, RNGCache& rng) + // auto? static typename MassiveScalarField::StateVector newsv(const typename MassiveScalarField::StateVector& svold, RNGCache& rng) { double amp = 0.5; // Amplitude (TODO: make me a class parameter) diff --git a/src/hamiltonian/MassiveScalarField2.h b/src/hamiltonian/MassiveScalarField2.h new file mode 100644 index 0000000..aac9233 --- /dev/null +++ b/src/hamiltonian/MassiveScalarField2.h @@ -0,0 +1,126 @@ +#ifndef MASSIVESCALARFIELD2_H +#define MASSIVESCALARFIELD2_H +#include +#include +#include +#include "util/randomdir.h" +#include "util/hamparts.h" +#include "util/termcollection.h" + + +// ------------------------------ OBSERVABLES --------------------------- + +#include "util/observables.h" + + +// ------------------------------ HAMILTONIAN -------------------------- + + +/** Action of a massive scalar field + */ +class MassiveScalarField2 +{ + public: + // ---- Parameters ---- + + int q = 7; // hardcoded!! + double beta, k, mass, sqrtg; + static constexpr int SymD = 1; + const std::string name = "MassiveScalarField2"; + + + // ---- Definitions ----- + + typedef std::array StateVector; + typedef MARQOV::Space StateSpace; + + + + // ---- Hamiltonian terms ---- + + std::array*, 1> interactions + = {new Standard_Interaction(-k)}; + + std::array*, 1> onsite + = {new Onsite_Quadratic(0.5*(q*k+sqrtg*mass))}; + + MassiveScalarField2(double k, double sqrtg, double mass) : k(k), + mass(mass), + sqrtg(sqrtg), + name("MassiveScalarField") + { + } + + + + // ---- Observables ---- + + Magnetization obs_m; + decltype(std::make_tuple(obs_m)) observables = {std::make_tuple(obs_m)}; + + + + // ---- Parameter Names ---- + + /** Allows to give the Hamiltonian parameter names + * + * @param i index of the parameter + * + * @return the parameter name (string) + */ + std::string paramname(int i) + { + std::string name; + switch (i) + { + case (0): name = "k"; break; + case (1): name = "sqrtg"; break; + case (2): name = "mass"; break; + default: break; + } + return name; + } + + + // ---- Initializer ---- + + template + void initstatespace(StateSpace& statespace, Lattice& grid, RNG& rng) const + { + for(decltype(grid.size()) i = 0; i < grid.size(); ++i) + { +// auto nnbrs = grid.nbrs(0,i).size(); +// if (nnbrs < 7) statespace[i][0] = 1; +// else statespace[i] = rnddir(rng); + statespace[i] = rnddir(rng); + } + } +}; + + +// ------------------------------ INITIALIZER --------------------------- + +template <> +class Initializer +{ + public: + Initializer() {} + + template + // auto? + static typename MassiveScalarField2::StateVector newsv(const typename MassiveScalarField2::StateVector& svold, RNGCache& rng) + { + double amp = 0.5; // Amplitude (TODO: make me a class parameter) + double r = rng.real(-1.0, 1.0); + + double oldval = svold[0]; + double newval = oldval + amp*r; + auto nsv = svold; + nsv[0] = newval; + return nsv; + } +}; + + + +#endif diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index ea3f47b..72b98ee 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -38,6 +38,7 @@ using std::ofstream; // Hamiltonians #include "hamiltonian/MassiveScalarField.h" +#include "hamiltonian/MassiveScalarField2.h" using namespace MARQOV; @@ -64,11 +65,11 @@ int main() std::vector beta = {1.0}; std::vector K = {0.50315223}; // geometric factor std::vector sqrtg = {1.0471975511}; // geometric factor - std::vector mass = {.33, .34, .35}; // negative mass squared + std::vector mass = { -10, -1, -0.1, 0, 0.1, 1, 10}; // mass squared auto hp = cart_prod(beta, K, sqrtg, mass); - const int nthreads = 3; + const int nthreads = 2; const int nreplicas = 1; @@ -77,17 +78,19 @@ int main() typedef GraphFromCSV Lattice; // Lattice - int nlayers = 12; + int nlayers = 8; std::string latfile = "/home/schrauth/hyperbolic-7-3-"+std::to_string(nlayers)+".csv"; GraphFromCSV lat(latfile); + + // Scheduler typedef typename std::tuple > ParameterType; typedef typename GetSchedulerType::MarqovScheduler SchedulerType; SchedulerType sched(1,nthreads); // Output - std::string outpath = outbasedir+"/hyperbolic-"+std::to_string(nlayers)+"/"; + std::string outpath = outbasedir+"/test-"+std::to_string(nlayers)+"/"; makeDir(outpath); // Monte Carlo @@ -95,7 +98,7 @@ int main() mp.setnmetro(10); mp.setncluster(0); mp.setwarmupsteps(0); - mp.setgameloopsteps(500); + mp.setgameloopsteps(200); // lattice parameters // form parameter triple and replicate diff --git a/src/libmarqov/metropolis.h b/src/libmarqov/metropolis.h index 8d4f9cf..dd52f5e 100644 --- a/src/libmarqov/metropolis.h +++ b/src/libmarqov/metropolis.h @@ -79,8 +79,8 @@ namespace MARQOV { - auto neighs = grid.nbrs(0,rsite); - if (neighs.size() < 7) return 0; +// auto neighs = grid.nbrs(0,rsite); +// if (neighs.size() < 7) return 0; // definitions typedef typename Hamiltonian::StateVector StateVector; -- GitLab From ad344c0f742baf711b92cd6be07188659e0ddea8 Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 30 Jun 2021 14:37:17 +0200 Subject: [PATCH 07/14] specialize Metropolis for MSF2 --- src/hamiltonian/MassiveScalarField2.h | 73 +++++++++++++++++++++++++++ src/kleingordon.cpp | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/hamiltonian/MassiveScalarField2.h b/src/hamiltonian/MassiveScalarField2.h index aac9233..6438628 100644 --- a/src/hamiltonian/MassiveScalarField2.h +++ b/src/hamiltonian/MassiveScalarField2.h @@ -123,4 +123,77 @@ class Initializer + +namespace MARQOV +{ + +// /* + // unfinished! + template + struct Metropolis + { + template + static int move(const MassiveScalarField2& ham, const Lattice& grid, StateSpace& statespace, RNG& rng, double beta, int rsite) + { + + typedef MassiveScalarField2 Hamiltonian; + typedef typename Hamiltonian::StateVector StateVector; + + cout << "here" << endl; + + + // old state vector at index rsite + StateVector& svold = statespace[rsite]; + // propose new configuration + StateVector svnew(Initializer::newsv(svold, rng) ); + + const int a = 0; // only one interaction term + const auto nbrs = getnbrs(grid, a, rsite); + + StateVector neighbourhood = {0}; + + // sum over neighbours + for (std::size_t i=0; iget(statespace[idx]); + + // sum up contributions from neighbourbood + neighbourhood = neighbourhood + nbr; + } + + double interactionenergydiff = ham.interactions[a]->J * (dot(svnew-svold, neighbourhood)); + + + + // sum up energy differences + double dE = interactionenergydiff; // + onsite + + int retval = 0; + if ( dE <= 0 ) + { + svold = svnew; + retval = 1; + } + else if (rng.real() < exp(-beta*dE)) + { + svold = svnew; + retval = 1; + } + return retval; + } + }; + +//*/ + + + +} + + + + #endif diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index 72b98ee..8653079 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -74,7 +74,7 @@ int main() // Typedefs - typedef MassiveScalarField Hamiltonian; + typedef MassiveScalarField2 Hamiltonian; typedef GraphFromCSV Lattice; // Lattice -- GitLab From 066f95f795891ca7b62b3b13d8315c14aee7e9d7 Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 30 Jun 2021 17:38:33 +0200 Subject: [PATCH 08/14] specialized Metro for both actions --- src/hamiltonian/MassiveScalarField.h | 52 +++++++++++++++++++++++++++ src/hamiltonian/MassiveScalarField2.h | 17 ++++----- src/kleingordon.cpp | 3 +- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index 2b8f7d7..db1e796 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -220,4 +220,56 @@ class Initializer +namespace MARQOV +{ + + template + struct Metropolis + { + template + static int move(const MassiveScalarField& ham, const Lattice& grid, StateSpace& statespace, RNG& rng, double beta, int rsite) + { + typedef MassiveScalarField Hamiltonian; + typedef typename Hamiltonian::StateVector StateVector; + + + // old state vector at index rsite + StateVector& svold = statespace[rsite]; + // propose new configuration + StateVector svnew(Initializer::newsv(svold, rng) ); + + // no interaction term + + + const int b = 0; // only one on-site term + auto diffb = ham.onsite[b]->get(svnew) - ham.onsite[b]->get(svold); + double onsiteenergydiff = dot(ham.onsite[b]->h, diffb); + + const int c = 0; // one flex term + auto nbrs = getflexnbrs(grid, c, rsite); + auto diffc = ham.multisite[c]->diff(rsite, svold, svnew, nbrs, statespace); + double flexenergydiff = dot(ham.multisite[c]->k, diffc); + + + + // sum up energy differences + double dE = onsiteenergydiff + flexenergydiff; + + int retval = 0; + if ( dE <= 0 ) + { + svold = svnew; + retval = 1; + } + else if (rng.real() < exp(-beta*dE)) + { + svold = svnew; + retval = 1; + } + return retval; + } + }; +} + + #endif diff --git a/src/hamiltonian/MassiveScalarField2.h b/src/hamiltonian/MassiveScalarField2.h index 6438628..a5ceac8 100644 --- a/src/hamiltonian/MassiveScalarField2.h +++ b/src/hamiltonian/MassiveScalarField2.h @@ -127,8 +127,6 @@ class Initializer namespace MARQOV { -// /* - // unfinished! template struct Metropolis { @@ -139,8 +137,6 @@ namespace MARQOV typedef MassiveScalarField2 Hamiltonian; typedef typename Hamiltonian::StateVector StateVector; - cout << "here" << endl; - // old state vector at index rsite StateVector& svold = statespace[rsite]; @@ -169,8 +165,14 @@ namespace MARQOV + const int b = 0; // only one on-site term + auto diff = ham.onsite[b]->get(svnew) - ham.onsite[b]->get(svold); + double onsiteenergydiff = dot(ham.onsite[b]->h, diff); + + + // sum up energy differences - double dE = interactionenergydiff; // + onsite + double dE = interactionenergydiff + onsiteenergydiff; int retval = 0; if ( dE <= 0 ) @@ -186,11 +188,6 @@ namespace MARQOV return retval; } }; - -//*/ - - - } diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index 8653079..ceec904 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -66,6 +66,7 @@ int main() std::vector K = {0.50315223}; // geometric factor std::vector sqrtg = {1.0471975511}; // geometric factor std::vector mass = { -10, -1, -0.1, 0, 0.1, 1, 10}; // mass squared + // note that the geometric factors are only valid for the bulk region! auto hp = cart_prod(beta, K, sqrtg, mass); @@ -74,7 +75,7 @@ int main() // Typedefs - typedef MassiveScalarField2 Hamiltonian; + typedef MassiveScalarField Hamiltonian; typedef GraphFromCSV Lattice; // Lattice -- GitLab From 8b37df21483806def02fd560bc00d748286258a1 Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 30 Jun 2021 20:22:33 +0200 Subject: [PATCH 09/14] getting rid of interactions by specializing Wolff; also: Hamiltonian terms are arrays now --- src/hamiltonian/MassiveScalarField.h | 59 +++++++++++++++++----------- src/kleingordon.cpp | 4 +- src/libmarqov/metropolis.h | 4 -- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index db1e796..e3fcde4 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -71,14 +71,15 @@ class BulkMagnetization // ------------------------------ HAMILTONIAN -------------------------- +// Finite Differences Interaction template -class FiniteDifferencesInteraction +class FinDiffInt { public: const double k; - FiniteDifferencesInteraction(double k) : k(k) {} - ~FiniteDifferencesInteraction() {} + FinDiffInt(double k) : k(k) {} + ~FinDiffInt() {} double diff (const int rsite, const StateVector& svold, @@ -126,26 +127,17 @@ class MassiveScalarField // ---- Hamiltonian terms ---- - Onsite_Quadratic onsite_standard; - FiniteDifferencesInteraction maininteraction; - - - // write specialization for Wolff in order to get rid of "interactions" - - std::array*, 1> interactions = {new Standard_Interaction(0)}; - std::vector*> onsite; // empty here, to be filled in the constructor! - std::vector*> multisite; + std::array*,1> onsite + = {new Onsite_Quadratic(0.5*sqrtg*mass)}; + + std::array*,1> multisite + = {new FinDiffInt(0.5*k)}; MassiveScalarField(double k, double sqrtg, double mass) : k(k), mass(mass), sqrtg(sqrtg), - name("MassiveScalarField"), - onsite_standard(0.5*sqrtg*mass), - maininteraction(0.5*k) - { - onsite.push_back(&onsite_standard); - multisite.push_back(&maininteraction); - } + name("MassiveScalarField") + {} @@ -229,10 +221,15 @@ namespace MARQOV template static int move(const MassiveScalarField& ham, const Lattice& grid, StateSpace& statespace, RNG& rng, double beta, int rsite) { + + // boundary cells are not being updated + auto neighs = grid.nbrs(0,rsite); + if (neighs.size() < 7) return 0; + + // typedefs typedef MassiveScalarField Hamiltonian; typedef typename Hamiltonian::StateVector StateVector; - // old state vector at index rsite StateVector& svold = statespace[rsite]; // propose new configuration @@ -240,12 +237,13 @@ namespace MARQOV // no interaction term - - const int b = 0; // only one on-site term + // only one on-site term + const int b = 0; auto diffb = ham.onsite[b]->get(svnew) - ham.onsite[b]->get(svold); double onsiteenergydiff = dot(ham.onsite[b]->h, diffb); - const int c = 0; // one flex term + // one flex term + const int c = 0; auto nbrs = getflexnbrs(grid, c, rsite); auto diffc = ham.multisite[c]->diff(rsite, svold, svnew, nbrs, statespace); double flexenergydiff = dot(ham.multisite[c]->k, diffc); @@ -269,6 +267,21 @@ namespace MARQOV return retval; } }; + + + + // write specialization for Wolff in order to get rid of "interactions" in Hamiltonian + + template + struct Wolff + { + template + static int move(const MassiveScalarField& ham, const Lattice& grid, StateSpace& statespace, RNG& rng, double beta, int rsite) + { + + return 0; + } + }; } diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index ceec904..6b9b32d 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -65,7 +65,7 @@ int main() std::vector beta = {1.0}; std::vector K = {0.50315223}; // geometric factor std::vector sqrtg = {1.0471975511}; // geometric factor - std::vector mass = { -10, -1, -0.1, 0, 0.1, 1, 10}; // mass squared + std::vector mass = { -10, -7, -5, -3, -1, 0, 3, 10}; // mass squared // note that the geometric factors are only valid for the bulk region! auto hp = cart_prod(beta, K, sqrtg, mass); @@ -99,7 +99,7 @@ int main() mp.setnmetro(10); mp.setncluster(0); mp.setwarmupsteps(0); - mp.setgameloopsteps(200); + mp.setgameloopsteps(500); // lattice parameters // form parameter triple and replicate diff --git a/src/libmarqov/metropolis.h b/src/libmarqov/metropolis.h index dd52f5e..7a52a63 100644 --- a/src/libmarqov/metropolis.h +++ b/src/libmarqov/metropolis.h @@ -78,10 +78,6 @@ namespace MARQOV int rsite) { - -// auto neighs = grid.nbrs(0,rsite); -// if (neighs.size() < 7) return 0; - // definitions typedef typename Hamiltonian::StateVector StateVector; typedef typename HasInteractions::type HasInt; -- GitLab From c9be4958c953067e1048ad6fe70688c5de0546e9 Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 30 Jun 2021 21:07:34 +0200 Subject: [PATCH 10/14] tidy up --- src/hamiltonian/MassiveScalarField.h | 18 ++++++++-------- src/hamiltonian/MassiveScalarField2.h | 2 +- src/kleingordon.cpp | 19 +++++++++-------- src/lattice/graph_from_csv.h | 30 +++++++++++++++++++++++---- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index e3fcde4..7169096 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -121,7 +121,7 @@ class MassiveScalarField // ---- Definitions ----- typedef std::array StateVector; - typedef MARQOV::Space StateSpace; + typedef MARQOV::Space StateSpace; @@ -136,8 +136,7 @@ class MassiveScalarField MassiveScalarField(double k, double sqrtg, double mass) : k(k), mass(mass), sqrtg(sqrtg), - name("MassiveScalarField") - {} + name("MassiveScalarField") {} @@ -178,10 +177,12 @@ class MassiveScalarField { for(decltype(grid.size()) i = 0; i < grid.size(); ++i) { -// auto nnbrs = grid.nbrs(0,i).size(); -// if (nnbrs < 7) statespace[i][0] = 1; -// else statespace[i] = rnddir(rng); - statespace[i] = rnddir(rng); + double boundary_value = 1; + auto nnbrs = grid.nbrs(0,i).size(); + if (nnbrs < 7) statespace[i][0] = boundary_value; + else statespace[i] = rnddir(rng); + +// statespace[i] = rnddir(rng); } } }; @@ -196,10 +197,9 @@ class Initializer Initializer() {} template - // auto? static typename MassiveScalarField::StateVector newsv(const typename MassiveScalarField::StateVector& svold, RNGCache& rng) { - double amp = 0.5; // Amplitude (TODO: make me a class parameter) + double amp = 0.5; double r = rng.real(-1.0, 1.0); double oldval = svold[0]; diff --git a/src/hamiltonian/MassiveScalarField2.h b/src/hamiltonian/MassiveScalarField2.h index a5ceac8..ad821dc 100644 --- a/src/hamiltonian/MassiveScalarField2.h +++ b/src/hamiltonian/MassiveScalarField2.h @@ -32,7 +32,7 @@ class MassiveScalarField2 // ---- Definitions ----- typedef std::array StateVector; - typedef MARQOV::Space StateSpace; + typedef MARQOV::Space StateSpace; diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index 6b9b32d..0c08bc7 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -76,13 +76,16 @@ int main() // Typedefs typedef MassiveScalarField Hamiltonian; - typedef GraphFromCSV Lattice; + typedef HyperbolicRegularFromCSV Lattice; + // Lattice + int p = 3; + int q = 7; int nlayers = 8; - std::string latfile = "/home/schrauth/hyperbolic-7-3-"+std::to_string(nlayers)+".csv"; - GraphFromCSV lat(latfile); + std::string filebase = "/home/schrauth/hyperbolic-"; + HyperbolicRegularFromCSV lat(filebase, p, q, nlayers); // Scheduler @@ -90,10 +93,12 @@ int main() typedef typename GetSchedulerType::MarqovScheduler SchedulerType; SchedulerType sched(1,nthreads); + // Output std::string outpath = outbasedir+"/test-"+std::to_string(nlayers)+"/"; makeDir(outpath); + // Monte Carlo MARQOV::Config mp(outpath); mp.setnmetro(10); @@ -101,15 +106,11 @@ int main() mp.setwarmupsteps(0); mp.setgameloopsteps(500); - // lattice parameters - // form parameter triple and replicate + + // Schedule and Run auto params = finalize_parameter(lat, mp, hp); auto rparams = replicator(params, nreplicas); - - // schedule simulations for (auto p: rparams) sched.createSimfromParameter(p, hyperfilter); - - // run! sched.start(); } diff --git a/src/lattice/graph_from_csv.h b/src/lattice/graph_from_csv.h index f167d05..489a0d9 100644 --- a/src/lattice/graph_from_csv.h +++ b/src/lattice/graph_from_csv.h @@ -43,14 +43,36 @@ class GraphFromCSV return neighbours[i]; } - std::vector flexnbrs(const int a, const int i) const - { - return neighbours[i]; - } std::size_t size() const {return npoints;} }; + +class HyperbolicRegularFromCSV : public GraphFromCSV +{ + public: + int p, q, nlayers; + HyperbolicRegularFromCSV(std::string filebasename, int p, int q, int nlayers) : p(p), q(q), nlayers(nlayers), + GraphFromCSV(filebasename+std::to_string(p)+"-"+std::to_string(q)+"-"+std::to_string(nlayers)+".csv") + {} + + // check whether site is boundary site + bool is_boundary_site(const int idx) + { + auto nnbrs = this->neighbours[idx].size(); + if (nnbrs < q) return true; + else return false; + } + + // implement flexnbrs + std::vector flexnbrs(const int a, const int i) const + { + return this->neighbours[i]; + } + +}; + + /* Read graph with coordinates from csv file. * @note for format specifications see general documentation */ -- GitLab From f2ca6b8a22d3914154e3c488981565bd41d4e683 Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 30 Jun 2021 21:24:49 +0200 Subject: [PATCH 11/14] tidy up again --- src/hamiltonian/MassiveScalarField.h | 6 ++---- src/lattice/graph_from_csv.h | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index 7169096..049b827 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -178,8 +178,7 @@ class MassiveScalarField for(decltype(grid.size()) i = 0; i < grid.size(); ++i) { double boundary_value = 1; - auto nnbrs = grid.nbrs(0,i).size(); - if (nnbrs < 7) statespace[i][0] = boundary_value; + if (grid.is_boundary_site(i)) statespace[i][0] = boundary_value; else statespace[i] = rnddir(rng); // statespace[i] = rnddir(rng); @@ -223,8 +222,7 @@ namespace MARQOV { // boundary cells are not being updated - auto neighs = grid.nbrs(0,rsite); - if (neighs.size() < 7) return 0; + if (grid.is_boundary_site(rsite)) return 0; // typedefs typedef MassiveScalarField Hamiltonian; diff --git a/src/lattice/graph_from_csv.h b/src/lattice/graph_from_csv.h index 489a0d9..5ca6bf6 100644 --- a/src/lattice/graph_from_csv.h +++ b/src/lattice/graph_from_csv.h @@ -53,11 +53,10 @@ class HyperbolicRegularFromCSV : public GraphFromCSV public: int p, q, nlayers; HyperbolicRegularFromCSV(std::string filebasename, int p, int q, int nlayers) : p(p), q(q), nlayers(nlayers), - GraphFromCSV(filebasename+std::to_string(p)+"-"+std::to_string(q)+"-"+std::to_string(nlayers)+".csv") - {} + GraphFromCSV(filebasename+std::to_string(p)+"-"+std::to_string(q)+"-"+std::to_string(nlayers)+".csv") {} // check whether site is boundary site - bool is_boundary_site(const int idx) + bool is_boundary_site(int idx) const { auto nnbrs = this->neighbours[idx].size(); if (nnbrs < q) return true; -- GitLab From e2eafefb512505807a02625835d70989019e6648 Mon Sep 17 00:00:00 2001 From: Manuel Date: Thu, 1 Jul 2021 03:16:12 +0200 Subject: [PATCH 12/14] adjust initalization --- src/hamiltonian/MassiveScalarField.h | 14 ++++++++++---- src/kleingordon.cpp | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index 049b827..6cda5cb 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -175,13 +175,19 @@ class MassiveScalarField template void initstatespace(StateSpace& statespace, Lattice& grid, RNG& rng) const { + double boundary_value = 5; + for(decltype(grid.size()) i = 0; i < grid.size(); ++i) { - double boundary_value = 1; - if (grid.is_boundary_site(i)) statespace[i][0] = boundary_value; - else statespace[i] = rnddir(rng); + // random initialization with mean zero is not a good idea! + // it can introduce frustration effects to the system -// statespace[i] = rnddir(rng); + if (grid.is_boundary_site(i)) statespace[i][0] = boundary_value; + else + { + statespace[i] = rnddir(rng); + statespace[i][0] += boundary_value; + } } } }; diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index 0c08bc7..07ec65c 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -65,7 +65,7 @@ int main() std::vector beta = {1.0}; std::vector K = {0.50315223}; // geometric factor std::vector sqrtg = {1.0471975511}; // geometric factor - std::vector mass = { -10, -7, -5, -3, -1, 0, 3, 10}; // mass squared + std::vector mass = { -10, -7, -5, -4, -3, -2, -1, -0.5, -0.25, 0, 1, 3, 10}; // mass squared // note that the geometric factors are only valid for the bulk region! auto hp = cart_prod(beta, K, sqrtg, mass); @@ -101,10 +101,10 @@ int main() // Monte Carlo MARQOV::Config mp(outpath); - mp.setnmetro(10); + mp.setnmetro(5); mp.setncluster(0); mp.setwarmupsteps(0); - mp.setgameloopsteps(500); + mp.setgameloopsteps(300); // Schedule and Run -- GitLab From 23c7afb627a58b969682a02498132dadbc46120c Mon Sep 17 00:00:00 2001 From: Manuel Date: Thu, 1 Jul 2021 12:17:43 +0200 Subject: [PATCH 13/14] simplify bulk magnetization --- src/hamiltonian/MassiveScalarField.h | 24 ++++++------------------ src/kleingordon.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index 6cda5cb..6d64ae0 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -39,31 +39,19 @@ class BulkMagnetization template double measure(const StateSpace& statespace, const Grid& grid) { - // q used to distinguish boundary and bulk sites; bulk sites have q neighbours, boundary ones less - const int q = 7; // hard-coded (fixme) - - const/*expr static*/ int SymD = statespace[0].size(); - std::vector mag(SymD, 0); + double mag = 0; int counter = 0; - for (decltype(grid.size()) i = 0; i < grid.size(); i++) + for (decltype(grid.size()) i=0; i(rng); - statespace[i][0] += boundary_value; + statespace[i][0] += 10000; // boundary_value; } } } diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index 07ec65c..608169e 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -65,12 +65,12 @@ int main() std::vector beta = {1.0}; std::vector K = {0.50315223}; // geometric factor std::vector sqrtg = {1.0471975511}; // geometric factor - std::vector mass = { -10, -7, -5, -4, -3, -2, -1, -0.5, -0.25, 0, 1, 3, 10}; // mass squared + std::vector mass = {-3, -2, -1, -0.7, -0.6, -0.55, -0.50, -0.45, -0.40}; // mass squared // note that the geometric factors are only valid for the bulk region! auto hp = cart_prod(beta, K, sqrtg, mass); - const int nthreads = 2; + const int nthreads = 3; const int nreplicas = 1; @@ -95,7 +95,7 @@ int main() // Output - std::string outpath = outbasedir+"/test-"+std::to_string(nlayers)+"/"; + std::string outpath = outbasedir+"/testlong-"+std::to_string(nlayers)+"/"; makeDir(outpath); @@ -104,7 +104,7 @@ int main() mp.setnmetro(5); mp.setncluster(0); mp.setwarmupsteps(0); - mp.setgameloopsteps(300); + mp.setgameloopsteps(10000); // Schedule and Run -- GitLab From 7050ea9dfe6a9a573e525dd4e72824ae41e4ccef Mon Sep 17 00:00:00 2001 From: Manuel Schrauth Date: Tue, 3 Aug 2021 00:27:46 +0200 Subject: [PATCH 14/14] minor changes --- src/hamiltonian/MassiveScalarField.h | 32 ++++++++++++++++++++++------ src/kleingordon.cpp | 10 ++++----- src/lattice/graph_from_csv.h | 12 ++++++++++- src/libmarqov/emcs.h | 6 ++++-- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/hamiltonian/MassiveScalarField.h b/src/hamiltonian/MassiveScalarField.h index 6d64ae0..a7d957e 100644 --- a/src/hamiltonian/MassiveScalarField.h +++ b/src/hamiltonian/MassiveScalarField.h @@ -163,19 +163,32 @@ class MassiveScalarField template void initstatespace(StateSpace& statespace, Lattice& grid, RNG& rng) const { - double boundary_value = 5; + double boundary_value = 1000; + double central_value = 10; for(decltype(grid.size()) i = 0; i < grid.size(); ++i) { // random initialization with mean zero is not a good idea! - // it can introduce frustration effects to the system + // it can introduce frustration effects! + /* + // boundary values if (grid.is_boundary_site(i)) statespace[i][0] = boundary_value; - else + // remaining sites + else statespace[i][0] = rng.real(0, 2*boundary_value); + */ + + + // central value + auto firstlayer = grid.flexnbrs(0,0); + if (i==0) statespace[i][0] = central_value; + else if (std::find(firstlayer.begin(), firstlayer.end(), i) != firstlayer.end()) { - statespace[i] = rnddir(rng); - statespace[i][0] += 10000; // boundary_value; + statespace[i][0] = central_value; } + // remaining sites + else statespace[i][0] = rng.real(0, 2*central_value); + } } }; @@ -216,7 +229,14 @@ namespace MARQOV { // boundary cells are not being updated - if (grid.is_boundary_site(rsite)) return 0; +// if (grid.is_boundary_site(rsite)) return 0; + // central cell is not being updated + if (rsite == 0) return 0; + auto firstlayer = grid.flexnbrs(0,0); + if (std::find(firstlayer.begin(), firstlayer.end(), rsite) != firstlayer.end()) + { + return 0; + } // typedefs typedef MassiveScalarField Hamiltonian; diff --git a/src/kleingordon.cpp b/src/kleingordon.cpp index 608169e..4ae5bb7 100644 --- a/src/kleingordon.cpp +++ b/src/kleingordon.cpp @@ -65,12 +65,12 @@ int main() std::vector beta = {1.0}; std::vector K = {0.50315223}; // geometric factor std::vector sqrtg = {1.0471975511}; // geometric factor - std::vector mass = {-3, -2, -1, -0.7, -0.6, -0.55, -0.50, -0.45, -0.40}; // mass squared + std::vector mass = {-10, -3, -1, -0.3, -0.1, -0.03, -0.01, 0, 1, 3, 10}; // mass squared // note that the geometric factors are only valid for the bulk region! auto hp = cart_prod(beta, K, sqrtg, mass); - const int nthreads = 3; + const int nthreads = 4; const int nreplicas = 1; @@ -95,16 +95,16 @@ int main() // Output - std::string outpath = outbasedir+"/testlong-"+std::to_string(nlayers)+"/"; + std::string outpath = outbasedir+"/fixedcentral-"+std::to_string(nlayers)+"/"; makeDir(outpath); // Monte Carlo MARQOV::Config mp(outpath); - mp.setnmetro(5); + mp.setnmetro(10); mp.setncluster(0); mp.setwarmupsteps(0); - mp.setgameloopsteps(10000); + mp.setgameloopsteps(1000); // Schedule and Run diff --git a/src/lattice/graph_from_csv.h b/src/lattice/graph_from_csv.h index 5ca6bf6..1f846e2 100644 --- a/src/lattice/graph_from_csv.h +++ b/src/lattice/graph_from_csv.h @@ -53,7 +53,17 @@ class HyperbolicRegularFromCSV : public GraphFromCSV public: int p, q, nlayers; HyperbolicRegularFromCSV(std::string filebasename, int p, int q, int nlayers) : p(p), q(q), nlayers(nlayers), - GraphFromCSV(filebasename+std::to_string(p)+"-"+std::to_string(q)+"-"+std::to_string(nlayers)+".csv") {} + GraphFromCSV(filebasename+std::to_string(p)+"-"+std::to_string(q)+"-"+std::to_string(nlayers)+".csv") + { + // subtract neighbour indices by one + for (int i=0; i::move(ham, + int avgacceptance = Metropolis::move(ham, grid, statespace, rngcache, @@ -79,7 +80,8 @@ namespace MARQOV } } - return avgclustersize/ncluster; + return avgacceptance/grid.size()/double(nmetro); +// return avgclustersize/ncluster; } template class RefType> -- GitLab