void Mocasinns::Metropolis<ConfigurationType,Step,RandomNumberGenerator,rejection_free>::do_metropolis_simulation(const TemperatureType& beta, Accumulator& measurement_accumulator) { // Check the concept of the observator BOOST_CONCEPT_ASSERT((Concepts::ObservatorConcept<Observator,ConfigurationType>)); // Check the concept of the observable BOOST_CONCEPT_ASSERT((Concepts::ObservableConcept<typename Observator::observable_type>)); // Check the concept of the accumulator BOOST_CONCEPT_ASSERT((Concepts::AccumulatorConcept<Accumulator, typename Observator::observable_type>)); // Log the start of the simulation this->simulation_start_log(); // Perform the relaxation steps do_metropolis_steps(simulation_parameters.relaxation_steps, beta); // For each measurement, perform the steps, invoke the signal handler, take the measurement and check for posix signals for (unsigned int m = 0; m < simulation_parameters.measurement_number; ++m) { // Do the steps do_metropolis_steps(simulation_parameters.steps_between_measurement, beta); // Call the measurement signal handler signal_handler_measurement(this); // Observe and check for posix signals measurement_accumulator(Observator::observe(this->configuration_space)); if (this->check_for_posix_signal()) return; } }
std::vector<typename Observator::observable_type> Metropolis<ConfigurationType, Step, RandomNumberGenerator>::autocorrelation_function(const TemperatureType& beta, unsigned int maximal_time, unsigned int simulation_time_factor) { // Check the concept of the observator BOOST_CONCEPT_ASSERT((Concepts::ObservatorConcept<Observator,ConfigurationType>)); // Check the concept of the observable BOOST_CONCEPT_ASSERT((Concepts::ObservableConcept<typename Observator::observable_type>)); // Do the relaxation steps do_metropolis_steps(simulation_parameters.relaxation_steps, beta); // Define the vector with the results std::vector<typename Observator::observable_type> results; // Define the vector with the measurments of the observable and take the measurements std::vector<typename Observator::observable_type> observable_measurements; for (unsigned int i = 0; i <= maximal_time*simulation_time_factor; ++i) { do_metropolis_steps(this->get_config_space()->system_size(), beta); observable_measurements.push_back(Observator::observe(this->get_config_space())); } // Define an accumulator and calculate the mean value of the observable ba::accumulator_set<typename Observator::observable_type, ba::stats<ba::tag::mean> > acc_measured_mean(observable_measurements[0]); for (unsigned int i = 0; i <= maximal_time*simulation_time_factor; ++i) { acc_measured_mean(observable_measurements[i]); } typename Observator::observable_type measured_mean = ba::mean(acc_measured_mean); // Calculate the autocorrelation function using an accumulator for (unsigned int time = 0; time <= maximal_time; ++time) { // Calculate the mean autocorrelation function for time ba::accumulator_set<typename Observator::observable_type, ba::stats<ba::tag::mean> > acc_autocorrelation_function_time(observable_measurements[0]); for (unsigned int sweep = 0; sweep < simulation_time_factor; ++sweep) { unsigned int start_time = sweep*maximal_time; acc_autocorrelation_function_time(observable_measurements[start_time]*observable_measurements[start_time + time]); } // Add to the result vector results.push_back(ba::mean(acc_autocorrelation_function_time) - measured_mean*measured_mean); } // Return the result vector return results; }