DiagMC
Diagrammatic Monte Carlo simulation of a 2-level spin system in a magnetic field
Loading...
Searching...
No Matches
diagram.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <list>
11#include <random>
12#include <chrono>
13
14#define EPSILON 1e-10 //theshold for floating point comparison
15
24{
25
26 protected:
27
28 double _beta;
29 int _s0;
30 double _H;
31 double _GAMMA;
32 std::list<double> _vertices;
33
34
45 void assert_parameters_validity(double beta, int s0, double H, double GAMMA, std::list<double> vertices) const;
46
47
48 public:
49
60 Diagram_core(double beta, int s0, double H, double GAMMA, std::list<double> vertices=std::list<double>() );
61
71 bool operator==(const Diagram_core & other) const;
72
73
82 bool operator!=(const Diagram_core & other) const;
83
89 double operator/(const Diagram_core & other) const;
90
96 double sum_deltatau() const;
97
98
104 double value() const;
105
111 size_t order() const;
112
118 double get_beta() const;
119
125 int get_s0() const;
126
132 double get_H() const;
133
139 double get_GAMMA() const;
140
146 std::list<double> get_vertices() const;
147
148
158 double acceptance_rate_add(double tau1, double tau2, double tau2max, double new_segment_spin) const;
159
169 double acceptance_rate_remove(double tau1, double tau2, double tau2max, double segment_toberemoved_spin) const;
170
176 double acceptance_rate_flip() const;
177
188 bool attempt_add_segment(double RN1, double RN2, double RNacc);
189
199 bool attempt_remove_segment(double RN1, double RNacc);
200
209 bool attempt_spin_flip(double RNacc);
210
211
212};
213
214
222{
223
224 private:
225 std::uniform_real_distribution<double> _uniform_dist;
226 std::mt19937 _mt_generator;
227
228
229 public:
230
243 Diagram(double beta, int s0, double H, double GAMMA,
244 std::list<double> _vertices=std::list<double>(),
245 unsigned int seed = std::chrono::system_clock::now().time_since_epoch().count());
246
247 using Diagram_core::operator/ ;
248 //using Diagram_core::operator== ;
249
250
258
266
274
285 void reset_diagram(double beta, int s0, double H, double GAMMA,
286 std::list<double> vertices=std::list<double>(),
287 unsigned int seed = std::chrono::system_clock::now().time_since_epoch().count());
288
289};
290
291
303bool lists_are_float_equal(const std::list<double>& list1, const std::list<double>& list2, double epsilon);
This class is the base class of Diagram, and should not be used directly, aside from testing function...
Definition: diagram.h:24
bool operator!=(const Diagram_core &other) const
operator to test wether two Diagram_core objects are different. It is the negation of operator==....
double acceptance_rate_add(double tau1, double tau2, double tau2max, double new_segment_spin) const
Returns the acceptance rate for the ADD_SEGMENT update for the given parameters.
double operator/(const Diagram_core &other) const
Returns the ratio of the weights of the two diagrams, i.e. this->value()/other.value()
bool attempt_remove_segment(double RN1, double RNacc)
Attemps the REMOVE_SEGMENT update for the current status of the diagram, using the two random numbers...
double value() const
Returns the value ("weight") of the current diagram.
int get_s0() const
Get the value of the spin of the 0-th segment of the diagram [0—t1].
Diagram_core(double beta, int s0, double H, double GAMMA, std::list< double > vertices=std::list< double >())
Construct a new diagram, setting its defining parameters. The list of vertices is optional: by defaul...
std::list< double > get_vertices() const
Get a copy of the list of _vertices.
double get_GAMMA() const
Get the value of the transverse field _GAMMA.
std::list< double > _vertices
list containing the times of the diagram vertices
Definition: diagram.h:32
double _H
value of the longitudinal component of magnetic field
Definition: diagram.h:30
double get_H() const
Get the value of the longitudinal field _H.
double acceptance_rate_remove(double tau1, double tau2, double tau2max, double segment_toberemoved_spin) const
Returns the acceptance rate for the REMOVE_SEGMENT update for the given parameters.
double _beta
length of the diagram (here representing the thermondinamical beta = 1/T)). Must be > 0.
Definition: diagram.h:28
size_t order() const
Get the order of the diagram (number of _vertices)
double get_beta() const
Get the value of _beta (length of the diagram)
int _s0
spin of the 0-th segment of the diagram [0—t1]. Must be +1 or -1
Definition: diagram.h:29
bool operator==(const Diagram_core &other) const
operator to test wether two Diagram_core objects are equal. It is intended for TESTING purposes only,...
double sum_deltatau() const
Small helper function, performing the sum (... +t4-t3 + t2-t1)
double _GAMMA
Value of the transversal component of magnetic field. Must be != 0.
Definition: diagram.h:31
double acceptance_rate_flip() const
Returns the acceptance rate for the SPIN_FLIP update for the given parameter.
void assert_parameters_validity(double beta, int s0, double H, double GAMMA, std::list< double > vertices) const
Internal (non-public) member function that checks wether all the parameters are within the allowed va...
bool attempt_spin_flip(double RNacc)
Attemps the SPIN_FLIP update for the current status of the diagram, using the random number given in ...
bool attempt_add_segment(double RN1, double RN2, double RNacc)
Attemps the ADD_SEGMENT update for the current status of the diagram, using the three random numbers ...
This is the main Diagram class, containing the variables defining the diagram - inherited from Diagra...
Definition: diagram.h:222
bool attempt_remove_segment()
Attemps the REMOVE_SEGMENT update for the current status of the diagram.
bool attempt_add_segment()
Attemps the ADD_SEGMENT update for the current status of the diagram.
Diagram(double beta, int s0, double H, double GAMMA, std::list< double > _vertices=std::list< double >(), unsigned int seed=std::chrono::system_clock::now().time_since_epoch().count())
Construct a new Diagram object, setting its defining parameters. The list of vertices is optional: by...
bool attempt_spin_flip()
Attemps the SPIN_FLIP update for the current status of the diagram.
void reset_diagram(double beta, int s0, double H, double GAMMA, std::list< double > vertices=std::list< double >(), unsigned int seed=std::chrono::system_clock::now().time_since_epoch().count())
Reset all diagram parameters with the new values.
bool lists_are_float_equal(const std::list< double > &list1, const std::list< double > &list2, double epsilon)
Small helper function that checks if two lists of floating points numbers are equal,...