16static_assert(NDIM == 3,
"NDIM must be 3 here");
28 action[X] = -
pow(phi[X], 2) +
pow(phi[X], 4);
31 action[X] +=
pow(phi[X] - phi[X - d], 2);
32 action[X] +=
pow(phi[X + d] - phi[X], 2);
49 new_phi += 0.5 * delta;
52 auto old_action = compute_local_action(phi);
53 auto new_action = compute_local_action(new_phi);
56 double log_P = -(new_action[X] - old_action[X]);
59 if (log_rand > log_P) {
64 double OP_old = order_parameter(phi);
65 double OP_new = order_parameter(new_phi);
68 if (hila::muca::accept_reject(OP_old, OP_new)) {
76 double OP = phi.
sum();
77 return OP / lattice.volume();
86 bool iterate_status =
true;
87 while (iterate_status) {
89 for (
int i = 0; i < 25; i++) {
90 multican_update(phi,
ODD);
91 multican_update(phi,
EVEN);
95 double OP = order_parameter(phi);
96 iterate_status = hila::muca::iterate_weights(OP);
105int main(
int argc,
char *argv[]) {
106 hila::cmdline.add_flag(
"-muca",
"If used, multicanonical methods are applied.");
108 hila::cmdline.print_help();
111 lattice.
setup({12, 12, 12});
120 bool muca = hila::cmdline.flag_present(
"-muca");
123 hila::out0 <<
"Running a multicanonical simulation.\n";
124 MFile.open(
"muca_measurements", std::ios_base::app);
126 hila::out0 <<
"Running a standard simulation.\n";
127 MFile.open(
"ca_measurements", std::ios_base::app);
131 iterate_weights(phi);
135 for (
int i = 1; i <= N; i++) {
136 double OP = order_parameter(phi);
140 sprintf(buffer,
"%d\t%e\t%e\n", i, OP, hila::muca::weight(OP));
142 MFile << std::string(buffer);
144 if (i % (N / 100) == 0)
147 for (
int i = 0; i < 50; i++) {
148 multican_update(phi,
ODD);
149 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...