Hey guys, I could do with some help to get my program working. In the int main section of my program I could do with some help to evolve my program with monte carlo steps so the magnetisation and energy per spin changes with step. I think I need to add something in the last for loop.
I use microsoft visual studio 2010.
double J = +1; // ferromagnetic coupling
int Lx, Ly; // number of spins in and y
int N; // number of spins
int **s; // the spins
double T; // temperature
double H; // External Field
//take at least N Metropolis Steps to generate next config, gives opportunity to change state
double acceptanceRatio;
void oneMonteCarloStepPerSpin () {
int accepts = 0;
for (int i = 0; i < N; i++)
if (MetropolisStep())
++accepts;
acceptanceRatio = accepts / double (N);
++steps;
}
//compute average magnetisation per spin of lattice
double magnetisationPerSpin() {
int sSum = 0;
for (int i = 0; i < Lx; i++)
for (int j = 0; j < Ly; j++){
sSum += s[i][j];
}
return sSum / double (N);
}
//energy per spin, accounting for boundary conditons
double energyPerSpin () {
int sSum = 0, ssSum = 0;
for (int i = 0; i < Lx; i++)
for (int j = 0; j < Ly; j++){
sSum += s[i][j];
int iNext = i == Lx - 1 ? 0 : i + 1;
int jNext = j == Ly - 1 ? 0 : j + 1;
ssSum += s[i][j]*(s[iNext][j] + s[i][jNext]);
}
return - (J*ssSum + H*sSum)/N;
}
//main function, user input
int main(int argc, char *argv[]){
cout << " Two Dimensional Ising Model\n"
<< "----------------------------\n"
<< " Enter Number of spins L in each direction: ";
cin >> Lx;
Ly = Lx;
N = Lx*Ly;
cout << " Enter Temperature T: ";
cin >> T;
cout << " Enter Magnetic Field H: ";
cin >> H;
cout << " Enter number of Monte Carlo Steps: ";
int MCSteps;
cin >> MCSteps;
initialise ();
for (int i = 0; i < Lx; i++)
for (int j = 0; j < Ly; j++)
cout << s[i][j] << endl;
//perform thermalization steps first, allows system to reach thermal equilibrium at specified temperature