/* Ising 2D * Algorithme de Metropolis appliqué au modèle d'Ising 2D carré. * Conditions aux limites fixes */ int[][] spins;//reseau de spins int N;//N est le nombre de spin sur un coté int Nspin;//N est le nombre de spins total int spin;// valeur du spin en (i,j) float T; //température int temps_equilibre;//nombre d'iteration pour atteindre l'équilibre int temps_decorrelation;//nombre d'iteration pour avoir deux échantillons indépendants int M; //aimantation et aimantation quadratique float Mmoy,normMmoy, MMmoy; //aimantation moyenne et aimantation quadratique moyenne int E; //énergie et énergie quadratique du réseau float Emoy, EEmoy; //énergie et énegie quadratique moyenne float chi, cv; //susceptibilité et capacité thermique int p; //nombre de mesures int spacer; boolean playing = false; void setup() { size(600, 400); spacer=4; N=height/spacer; T=3.5; Nspin=N*N;//nombre de spins temps_equilibre=1000000; temps_decorrelation=100000; spins = new int[N][N]; text("", 0, 0); initialisation(); Metropolis(T, temps_equilibre); p=0;Mmoy=0;MMmoy=0;normMmoy=0;MMmoy=0;Emoy=0;EEmoy=0; noLoop(); } void draw() { background(255); Metropolis(T, temps_decorrelation); DessinerReseau(); Mesures(); Mmoy=(p*Mmoy+float(M)/Nspin)/(p+1);//aimanation par site normMmoy=(p*normMmoy+float(abs(M))/Nspin)/(p+1);//aimanation en valeur absolue par site MMmoy=(p*MMmoy+float(M*M)/(Nspin*Nspin))/(p+1);//aimanation quadratique par site Emoy=(p*Emoy+float(E))/(p+1); EEmoy=(p*EEmoy+float(E*E))/(p+1); p+=1; fill(0); text("réseau de "+N+"x"+N+" spins", 420, 20); text("T = "+nf(T, 1, 2)+" K", 420, 40); text("PROPRIETES MAGNETIQUES", 420, 70); text(" = "+nf(Mmoy, 1, 3), 420, 100); text(" = "+nf(MMmoy, 1, 3), 420, 120); text("\u03C7 = "+nf((MMmoy-normMmoy*normMmoy)/T, 1, 4), 420, 140); text("PROPRIETES THERMIQUES", 420, 170); text(" = "+round(Emoy), 420, 200); //text(" = "+round(EEmoy),420,220); text("Cv = "+nf((EEmoy-Emoy*Emoy)/(T*T*Nspin), 1, 2), 420, 220); fill(255, 157, 0); text("CLICK TO PLAY/PAUSE", 420, 370); } void DessinerReseau() { noStroke(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { fill(255, 157, 0, (spins[i][j]+1)*127); rect(i*spacer, j*spacer, spacer, spacer); } } } void Metropolis(float temperature, int iteration) { float rr, delta_E; int x, y; for (int k=0; k=0){return x%p;}else{return(p-(-x%p));} } void play() { playing = true; loop(); } /*** Pause playback */ void pause() { playing = false; fill(0, 0, 0, 100); noStroke(); rect(0, 0, width, height); fill(255); String pausetext = " CLICK TO PLAY/PAUSE"; textSize(24); text(pausetext, 100, 200); textSize(12); noLoop(); } void mouseClicked() { if (!playing) { play(); } else { pause(); } } void setTemperature(float pas){ T=constrain(T+pas,0.1,10); p=0;Mmoy=0;MMmoy=0;normMmoy=0;MMmoy=0;Emoy=0;EEmoy=0; }