The Ising Simple example

This is probably the simplest self-defined model. It shows how to define a Model, use a predefined lattice, and a predefined observable. It sets up marqov as a single threaded simulation of a single parameter set without any scheduling.

 1#include <iostream>
 2#include <array>
 3
 4// include the RegularLattice
 5#include "../src/lattice/regular_hypercubic.h"
 6
 7// include the MARQOV library
 8#include "libmarqov.h"
 9
10// include certain hamiltonian building blocks from the utilities
11#include "../src/hamiltonian/util/termcollection.h"
12// include some predefined observables, e.g. the magnetization and the energy
13#include "../src/hamiltonian/util/observables.h"
14
15class MySimpleIsing
16{
17	public:
18		// The spin dimension of the Ising model
19		constexpr static int SymD = 1;
20
21		// Define the state vector that this model will use. 
22		// The Ising Model has integers spins +1/-1, hence we go with plain ints
23		typedef std::array<int, SymD> StateVector;
24
25		// Parameters
26		double J; // The coupling constant
27		const std::string name; // every Hamiltonian MUST have a name, this is required for the HDF5 output
28
29		// Hamiltonian terms
30		// here this is only a canonical two-body interaction
31		std::array<Standard_Interaction<StateVector>*, 1> interactions = {new Standard_Interaction<StateVector>(J)};
32        
33		// Constructor
34		MySimpleIsing(double J) : J(J), name("MySimpleIsing"), obs_e(*this){}
35		~MySimpleIsing() {delete interactions[0];}
36
37		// Observables
38		Magnetization  obs_m;
39		Energy<MySimpleIsing>  obs_e{*this};
40		std::pair<Magnetization, Energy<MySimpleIsing> >  observables {obs_m, obs_e};
41};
42
43using namespace std;
44using namespace MARQOV;
45
46int main()
47{
48    std::cout<<"Welcome to the simplest test case of MARQOV:"<<std::endl;
49    std::cout<<"A plain Ising Model in 2D without threading support."<<std::endl;
50    // Initialize the lattice
51    int L = 8;
52    int dim = 2;
53    RegularHypercubic mylatt(L, dim);
54
55    // Set Monte Carlo parameters using MARQOV::Config
56    MARQOV::Config mp("./"); //initialize bas path to current folder
57    mp.outname = "IsingSimple_out"; // output filename: will be IsingSimple_out.h5
58    mp.setnmetro(5); // number of Metropolis sweeps per EMCS(Elementary Monte Carlo Sweep)
59    mp.setncluster(10); // number of Wolff updates per EMCS
60    mp.setwarmupsteps(500); // number of EMCS for warmup
61    mp.setgameloopsteps(3000); // number of EMCS for production
62    mp.logverbosity = DEBUG; // set the verbositiy of our log to quite verbose
63
64    // Set the Hamiltonian parameters, J, and the inverse temperature beta
65    double beta = 0.440;
66    double J = -1;
67    auto hp = make_tuple(beta, J);
68
69    // Prepare argument list, contains
70    // 1) reference to the lattice
71    // 2) Monte Carlo parameter object
72    // 3) Hamiltonian parameters packed as tuple
73    auto args = make_tuple(std::ref(mylatt), mp, hp);
74
75    // Eexecute the Core routines of MARQOV.
76    auto mysim = makeCore<RegularHypercubic, MySimpleIsing>(args);
77    mysim.init(); // initialize the state space; by default randomized
78    mysim.wrmploop(); // do some warmup, to get rid of memory of the initial state
79    mysim.gameloop(); // Get the game going! Involves: Some EMCS, and then some measurements
80}