at the moment i am writing my Bachelor theses about Montecarlo simulation for the 2D Ising Model with the Metropolis algorithm.
But my code does´t work. and i can´t finde my mistakes.
my measurement values are very far away from the analytical results.
Please help me to find my mistakes.
I am thankful for any advice and help.
const int Nx = 20; //Spins in direction x
const int Ny = 20;
const int N2 = 400; // all Spins
int MCSteps = 10000; // number of Metropolis Steps
const int k_B = 1; // Boltzmann constant
const int B = 0; //magnetic field
const int J = +1; // ferromagnetic coupling
const int mu = 1; //permeability
double beta; // invers temperatur
double T; // temperatur
int s[Nx][Ny]; //spin
int li[N2] , lj[N2] , ri[N2] , rj[N2]; //spin neightbours
int i; //spin position in direction x
int j; // spin position in direction y
double dE; // energy difference (E_new - E_old)
double E; // energy
double Cv; //specific heat
double a_Cv; // analytical results specific heat
double sus; // susceptibility
double a_sus; // analytical results susceptibility
double tprob; // transmission probability
double rprob; // random probability betwenn 0 and 1
double mag; // magnetisation
double med_mag; // mean magnetisation
double med_mag2; // mean squared magnetisation
double med_E; // mean energy
double med_E2; //mean squared energy
int count1; //counter
int count2; //counter
//generates an inital spin
//configuration randomly spin up (+1) spin down (-1)
void Initialisierung () //inizialisation
// N2 Metropolis Steps
// magnetisation per spin
// energy per spin
void oneMetropolisStepPerSpin()
{
for (int i =0; i<N2; i++)
{
OneMetropolisStep();
}
mag = mag / N2;
E = E / N2;
}
int main(int argc, const char * argv[])
{
for(count1=0; count1<MCSteps; count1++)
{Initialisierung();}
//T=0.1;
for (T=0.1; T<=5; T+=0.1)
{cout << " Temperatur: " << T << '\n';
beta = 1/(k_B*T);
med_mag =0;
med_E =0;
med_mag2 =0;
med_E2 =0;
int MM = int(0.4* MCSteps); //perform thermalization steps to let the system come to equilibrium
for(int count1=0; count1< MM; count1++)
{ oneMetropolisStepPerSpin();
the analytical results are behind the measurements in the program.
the analytical result for the specific heat is in my program called "analytical Cv".
and the analytical result for the susceptibility is called "analytical sus".
Sorry that i posted this in both forums. But I did´t know where to post it.