/*

Random diluted dimer model

Definitions of the model, Hamiltonian, parameters, etc.

This applet simulates a ....

Comments (on programming issues)

Each site has 4 neighbors nn. Each occupied site (with a dimer) has a partner pp. A single thread controls both the computation and the visualization. (This is to avoid having syncing problems) setDefaultLookAndFeelDecorated (true); // doens't work properly

Credits and references

(...)

*/ import java.awt.*; import java.awt.event.*; import java.awt.geom.*; // for AffineTransform import javax.swing.*; import javax.swing.event.*; // for ChangeListener import javax.swing.JSpinner.NumberEditor; import java.text.DecimalFormat; import java.util.Random; //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // JApplet class //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ public class dimer extends JApplet implements Runnable,ComponentListener,ChangeListener,ActionListener { final String namesOfLattices[] = {"Square","Cubic"}; final String namesOfAlgorithms[] = {"Worm"}; final String namesOfVisualizations[] = {"Colored cells", "Cells w/borders", "Stripes"}; final int VACANT = -1; boolean bInitLattice,bInitConfig,bDrawLattice,bUpdatePars,bDrawConfig; Container appletPane; JFrame frCtrls; MyFrame mfConfig,mfDirtConfig,mfNoise,mfHysteresis,mfMvsT; JSpinner spnrsmax,spnrxmax,spnrymax,spnrzmax, spnrrefresh, spnrz; JButton buttonPolarize,buttonRandomize; JComboBox comboAlgorithm,comboLattice,comboVisual; JCheckBox chkboxRunning; GridBagConstraints gbcL,gbcR; Thread thread1; int refresh; //==================================================================== // CORE OF THE PROGRAM IS HERE //==================================================================== int smax,xmax,ymax,zmax,imax,bmax; int nn[][]; // Neighbour list int xx[],yy[],zz[]; double kk[][]; // Random bonds int pp[]; // Partner array int seed; double tempT,beta,pstop,fieldH; Random rng; private int IXYZ (int x, int y, int z) {return x+xmax*(y+ymax*z);} private int irand (int i) {return rng.nextInt(i); } private double drand_gauss () {return rng.nextGaussian(); } //========== INITIAL PARAMETERS void initBigBang() { smax=2; xmax=ymax=16; zmax=8; seed = 123456789; tempT=1d; fieldH=0.0d; refresh=500; } //========== SET UP LATTICE AND ALLOCATE ARRAYS void initLattice() { int x,y,z,i; smax = Integer.parseInt(spnrsmax.getValue().toString()); xmax = Integer.parseInt(spnrxmax.getValue().toString()); ymax = Integer.parseInt(spnrymax.getValue().toString()); zmax = Integer.parseInt(spnrzmax.getValue().toString()); switch (comboLattice.getSelectedIndex()) { case 0: // LATTICE_SQUARE: spnrzmax.setValue(new Integer(zmax=1)); bmax = 4; imax = xmax*ymax*zmax; nn = new int[imax][bmax]; // setup neighborlist xx = new int[imax]; yy = new int[imax]; zz = new int[imax]; for (z=0; z0; n--) metropolis(); worm(); //chkboxRunning.setSelected(false); //hack Thread.sleep (0); break; } bDrawConfig=true; } else { Thread.sleep (250); } } } catch (Exception e) { System.out.println("run() exception, exiting"); } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // IMPLEMENT ChangeListener //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public void stateChanged(ChangeEvent e) { Object esrc = e.getSource(); if (esrc==spnrsmax || esrc==spnrxmax || esrc==spnrymax || esrc==spnrzmax) bInitLattice=true; // demand full restart else { bUpdatePars=true; // request to update parameters } } //&&&&&&&&&&&&&&&& Implement ActionListener public void actionPerformed(ActionEvent e) { Object esrc = e.getSource(); if (esrc==comboLattice) bInitLattice=true; else if (esrc==comboVisual) bDrawLattice=true; } //&&&&&&&&&&&&&&&& Implement ComponentListener // These events are only triggered by MyFrame objects public void componentHidden(ComponentEvent e){} public void componentMoved(ComponentEvent e){} public void componentShown(ComponentEvent e) {} public void componentResized(ComponentEvent e) { Object esrc = e.getSource(); bDrawLattice=true; //?????? } //&&&&&&&&&&&&&&&& Implement MouseListener (NOT!) public void mouseEntered (MouseEvent e) {} public void mouseExited (MouseEvent e) {} public void mousePressed (MouseEvent e) {} public void mouseReleased (MouseEvent e) {} public void mouseClicked (MouseEvent e) {} } //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // MyFrame // This frame displays a dynamic image. // This simple functionality requires a hierarchy of 5 objects! // This is why I am making this a separate class. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ class MyFrame extends JFrame { Container pane; JLabel label; ImageIcon icon; Image image; //=========================================================================== // Constructor public MyFrame () { super(); // Call JFrame constructor pane = this.getContentPane(); icon = new ImageIcon(); label = new JLabel(icon); label.setDoubleBuffered(true); // This helps to eliminate flicker label.setOpaque(true); // No need for MyFrame to redraw itself pane.add(label); //this.setIgnoreRepaint(false);//Controls need to draw themselves. } //=========================================================================== // Ensure that the Image fits in the MyFrame void ensureImageFitsFrame () { int widthLabel,heightLabel,widthImage,heightImage; widthLabel = label.getSize().width; heightLabel = label.getSize().height; if (image!=null) { widthImage = image.getWidth(null); heightImage = image.getHeight(null); if (widthImage==widthLabel && heightImage==heightLabel) return; } image = createImage(widthLabel, heightLabel); icon.setImage(image); } }