12static_assert(NDIM == 3,
"NDIM must be 3 here");
24 action[X] = -
pow(phi[X], 2) +
pow(phi[X], 4);
27 action[X] +=
pow(phi[X] - phi[X - d], 2);
28 action[X] +=
pow(phi[X + d] - phi[X], 2);
45 new_phi += 0.5 * delta;
48 auto old_action = compute_local_action(phi);
49 auto new_action = compute_local_action(new_phi);
52 double log_P = -(new_action[X] - old_action[X]);
55 if (log_rand > log_P) {
60 double OP_old = order_parameter(phi);
61 double OP_new = order_parameter(new_phi);
64 if (hila::muca::accept_reject(OP_old, OP_new)) {
72 double OP = phi.
sum();
73 return OP / lattice.volume();
82 bool iterate_status =
true;
83 while (iterate_status) {
85 for (
int i = 0; i < 25; i++) {
86 multican_update(phi,
ODD);
87 multican_update(phi,
EVEN);
91 double OP = order_parameter(phi);
92 iterate_status = hila::muca::iterate_weights(OP);
97void multi_iterate_weights(std::vector<
Field<double>> &N_phi) {
98 bool iterate_status =
true;
99 std::vector<double> OPs(N_phi.size());
100 while (iterate_status) {
102 for (
int j = 0; j < N_phi.size(); j++) {
103 for (
int i = 0; i < 50; i++) {
104 multican_update(N_phi[j],
ODD);
105 multican_update(N_phi[j],
EVEN);
107 OPs[j] = order_parameter(N_phi[j]);
112 iterate_status = hila::muca::iterate_weights(OPs[0]);
121int main(
int argc,
char *argv[]) {
122 hila::cmdline.add_flag(
"-muca",
"If used, multicanonical methods are applied.");
124 hila::cmdline.print_help();
127 lattice.
setup({12, 12, 12});
136 bool muca = hila::cmdline.flag_present(
"-muca");
139 hila::out0 <<
"Running a multicanonical simulation.\n";
140 MFile.open(
"muca_measurements", std::ios_base::app);
142 hila::out0 <<
"Running a standard simulation.\n";
143 MFile.open(
"ca_measurements", std::ios_base::app);
147 iterate_weights(phi);
151 for (
int i = 1; i <= N; i++) {
152 double OP = order_parameter(phi);
156 sprintf(buffer,
"%d\t%e\t%e\n", i, OP, hila::muca::weight(OP));
158 MFile << std::string(buffer);
160 if (i % (N / 100) == 0)
163 for (
int i = 0; i < 50; i++) {
164 multican_update(phi,
ODD);
165 multican_update(phi,
EVEN);
Array< n, m, T > pow(Array< n, m, T > a, int b)
Power.
Array< n, m, T > log(Array< n, m, T > a)
Logarithm.
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
T sum(Parity par=Parity::all, bool allreduce=true) const
Sum reduction of Field.
void setup(const CoordinateVector &siz)
General lattice setup.
Parity
Parity enum with values EVEN, ODD, ALL; refers to parity of the site. Parity of site (x,...
constexpr Parity EVEN
bit pattern: 001
#define foralldir(d)
Macro to loop over (all) Direction(s)
constexpr Parity ODD
bit pattern: 010
constexpr Parity ALL
bit pattern: 011
void write_weight_function(string W_function_filename)
Reads the precomputed weight function from run_parameters struct and saves it into a file.
void initialise(const string wfile_name)
Loads parameters and weights for the multicanonical computation.
Header for model agnostic implementation of various multicanonical (muca) methods.
T gaussian_random()
Template function T hila::gaussian_random<T>(),generates gaussian random value of type T,...
double random()
Real valued uniform random number generator.
int myrank()
rank of this node
std::ostream out0
This writes output only from main process (node 0)
void initialize(int argc, char **argv)
Read in command line arguments. Initialise default stream and MPI communication.
void seed_random(uint64_t seed, bool device_rng=true)
Seed random generators with 64-bit unsigned value. On MPI shuffles the seed so that different MPI ran...
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...