import java.awt.*; import java.util.*; public class XY { private final int J = 1; private double spinAngle[][]; private int L; private double T, H, dtheta; // implicitly assuming the field is in the y direction public int time_counter; public double E, Mx, My, ave_Mx, ave_My, ave_E; public XY() { } public XY(int L, double T, double H, double dtheta) { reinitialize(L, T, H, dtheta); } public boolean reinitialize(int L, double T, double H, double dtheta) { this.L = L; if(T<0) { System.out.println("\nTemperature is negative, automatically negated!"); T *= -1; } this.T = T; this.H = H; this.dtheta = dtheta; time_counter = 1; ave_Mx = ave_My = ave_E = 0; spinAngle = new double[L][L]; for(int i=0; i= L) return (x-L); else if(x<0) return (x+L); else return x; } private void getME() { E = Mx = My= 0; for(int i=0; i 2*Math.PI) // limit the angle to between 0 and 2*Pi spinAngle[x][y] -= 2*Math.PI; else if(spinAngle[x][y] < -2*Math.PI) spinAngle[x][y] += 2*Math.PI; Mx += deltaMx; My += deltaMy; E += deltaE; return true; } else return false; } public void rotateSpinBloc(int xStart, int yStart, int xEnd, int yEnd, double alpha) { for(int i=xStart; i<=xEnd; i++) for(int j=yStart; j<=yEnd; j++) { spinAngle[i][j] += alpha; if(spinAngle[i][j] > 2*Math.PI) spinAngle[i][j] -= 2*Math.PI; else if(spinAngle[i][j] < 0) spinAngle[i][j] += 2*Math.PI; } getME(); } public void onestep() { int N = L*L; for(int i=0; i -Math.PI) delta += temp; else if(temp > Math.PI) delta += (temp - 2*Math.PI); else delta += (temp + 2*Math.PI); } if(delta > Math.PI) return 1; else if(delta < -Math.PI) return -1; else return 0; } private void drawOneSpin(Graphics g, int x0, int y0, double length, double theta) { int dx = (int)(length/2*Math.cos(theta)); int dy = (int)(length/2*Math.sin(theta)); g.drawLine(x0-dx, y0+dy, x0+dx, y0-dy); // in display, y axis points downward int dx2 = (int)(length/4*Math.cos(theta + Math.PI/6)); int dy2 = (int)(length/4*Math.sin(theta + Math.PI/6)); g.drawLine(x0+dx, y0-dy, x0+dx-dx2, y0-dy+dy2); dx2 = (int)(length/4*Math.cos(theta - Math.PI/6)); dy2 = (int)(length/4*Math.sin(theta - Math.PI/6)); g.drawLine(x0+dx, y0-dy, x0+dx-dx2, y0-dy+dy2); } private void drawPlus(Graphics g, int x0, int y0, double length) { int ds = (int)(length/2); g.drawLine(x0-ds, y0, x0+ds, y0); g.drawLine(x0, y0-ds, x0, y0+ds); } private void drawMinus(Graphics g, int x0, int y0, double length) { int ds = (int)(length/2); g.drawLine(x0-ds, y0, x0+ds, y0); } public void drawSpins(Graphics g, int x0, int y0, int width, int height) { double dx = ((double) width) / L; double dy = ((double) height) / L; double spinLength = dx; if(dy < dx) spinLength = dy; g.setColor(Color.blue); for(int i=0; i