Hysteresis Applet
Source Code and Documentation

The source code for the Hysteresis applet is divided into five packages. Two of these packages, Hysteresis and HysteresisApplet, are specific to the Hysteresis applet. The other three packages, ConfigurePack, FastApplet, and RngPack, may be useful in many situations. I have used javadoc to generate Documentation for all five packages, with links to the source code. Below, you can find a breif description of each of the five packages, along with links for the source code for each of the packages.





The Packages


Description

The package edu.cornell.lassp.mck10.Hysteresis, written by Matt Kuntz is at the heart of the hysteresis applet. This is where all of the computatoin is done. The main class in this package is the HysteresisLattice class. This class contains all of the actual computational code to simulate a simple model of hysteresis. The rest of the classes in this package provide support for the HysteresisLattice class. The most important of these are the interfaces XYProducer, XYConsumer, AvalancheConsumer, and AvalancheProducer. These are the interfaces which are used to communicate data between the model and the outside world. The model implements the two producer interfaces, and any class which needs to recieve data from the model must implement either the XYConsumer or AvalancheConsumer interface. The first is used to recieve XY data --- in this case, the external magnetic field is X, and the magnetization is Y. The AvalancheConsumer interface is implemented by classes which need to recieve detailed information about the individual spins that flip in each avalanche, including their coordinates, and the order in which they flipped. The Hysteresis package uses the classes of the ConfigurePack package for the purpose of configuration. It also uses the classes of the RngPack package for the generation of random numbers.

Source Code

HysteresisLattice.java
XYProducer.java
XYConsumer.java
AvalancheProducer.java
AvalancheConsumer.java
XYPair.java
SpinFlip.java
Avalanche.java
RandField.java
RandGauss.java
RandLorenzian.java
LatticeView.java

Description

The classes in the HysteresisApplet package, written by Matt Kuntz provide a front end to the model implemented in the Hysteresis package. The applet itself is contained in the class HysteresisPanel. This is a subclass of AppletPanel from the FastApplet package, so that it can be "fast loaded" by FastApplet.

Views

There are two classes which are used to view the results of the simulation: LoopView and LatticeView. (For now, LatticeView is actually in the Hysteresis package, because it needs access to some of the internals of the HysteresisLattice class, but it will eventually be moved into the HysteresisApplet package, where it belongs.)

The LoopView class displays the hysteresis loop which is generated by the HysteresisLattice simulation. It allows the user to change the external field of the simulation by clicking on the view. It also allows the user to zoom in on the hysteresis loop by draging a box around the area they want to view. Zooming can also be initiated through a call to the zoom method.

The LatticeView class displays a view of the spins in the lattice. If the simulation is 2-dimensional, it simply displays the grid of spins, with spins that are pointing up white, and spins that are pointing down black. If the simulation is higher-dimensional, a view through the lattice is displayed. When all the spins along a line through the lattice are up, the point will be white. If they are all down, it will be black. If some are up and some are down, a shade of grey will be displayed, which depends on the percentage of spins along the line that are up. When an avalanche of spins first flips, the spins in the avalanche are displayed in color. The first spins to flip are displayed in blue, followed by cyan, green, yellow, orange, red, and finally purple.

Controls

There are also a number of controls in the HysteresisApplet package. These include a ZoomButton, a AutoFitButton, a LoopButton, and a StopButton. Also, a ConfigureTextField from the ConfigurePack is used to allow the disorder of the simulation to be changed, and a ConfigureButton is used to allow fine control over the parameters of the simulation.

The ZoomButton and the AutoFitButton are used to controll the zooming of the LoopView. The ZoomButton can be used either to zoom in, or to zoom out. In this applet, it acts as a button which has the label "Zoom Out", and will zoom out by a factor of two. The AutoFitButton will cause zoom in on the LoopView so that the hysteresis loop exactly fits inside the view. It appears as a button with the label "Fit".

The LoopButton allows the user to generate an entire hysteresis loop with the press of one button. The label on the button is "Generate Loop".

The StopButton performs the function one would expect: it allows the user to stop the simulation. It appears as a button labeled "STOP!".

The ConfigureTextField and ConfigureButton are linked into the configuration system of the applet, which was created using the functionality of the ConfigurePack package. At the bottom of the applet, there is a ConfigureTextField which allows the user to change the disorder of the simulation. On the button bar, at the top, there is a button labeled "Configure", which is created with the ConfigureButton class. This button is attatched to the applet's configuration menu, and when it is pressed, it displays the main configuration menu on the screen. Through this menu, all of the details of the simulation can be controlled.

Source Code

HysteresisPanel.java
HysteresisPanel.java
LoopView.java
LatticeView.java
ZoomButton.java
AutoFitButton.java
LoopButton.java
StopButton.java
RunMeter.java
ProcessAvalanche.java
CheckLatticeSize.java
SizeDialog.java

Description

The ConfigurePack package, by Matt Kuntz provides mechanisms for configuring variables in a number of ways. The entire package is built around the class Configurable, an abstract class which all configurable variables must extend. The two primary methods in the Configurable class are set(String value) and toString(). The set method allows the variable to be set using a human readable string to describe it's value. The toString() outputs the value of the variable as a string. The output of toString() should be fomatted so that it can be used as input to the set method.

One special type of Configurable is the ConfigurableCollection. Configurable collections allow configurable variables to be easily grouped together into a menu system. When a Configurable is constructed, it can be given a name, and attached to a ConfigurableCollection. It can then be set indirectly through the collection's set method, or through the menu system which the ConfigurableCollection is capable of displaying. To work with this menu system, the configurable variable must define a method which returns an AWT Component which allows for the editing of the variable, as well as an AWT Frame which allows for the editing of the variable outside of the menu system.

By default the ConfigureTextField and ConfigureFrame classes are used. They simply use a text field and the set(String) method to change the variable's value. Since the ConfigurableCollection is itself a configurable, it can also be placed in other collections to build a heierarchical menu system.

The ConfigurePack package also allows variables to be easily and automatically set through < PARAM > tags. When variables are put into a menu tree, they receive a unique name, which can be used in param tags to set them. For this to work, the top level menu must be passed a pointer to the applet in it's constructor.

Another important feature of the Configurable variables is that they are all subclasses of Observable, so that other classes can implement the Observer interface, and request notification when the variable changes. With all of the different ways in which a configurable variable may unexpectedly change, it is important to have such a mechanism in place.

There are several basic types of Configurable variables already defined in the ConfigurePack package, and many more can be created. These types are the ConfigurableInteger, the ConfigurableDouble, and the ConfigurableBoolean. In addition to the set and toString() methods, these types all define a set method that takes their native type (int, double, etc.), and a value method (intValue(), doubleValue(), etc.) which returns their native type.

Configurable variables can also be attatched to any number of instances of the CheckConfigurable class, which will check their value when any attempt is made to change them, and keep them from being changed to inappropriate values.

Source Code

Configurable.java
ConfigurableCollection.java
ConfigureTextField.java
ConfigureFrame.java
CollectionFrame.java
ConfigureButton.java
ListConfigurable.java
ListConfigurableNode.java
CheckConfigurable.java
ConfigurableInteger.java
ConfigurableDouble.java
ConfigurableBoolean.java

Description

The FastApplet package, by Matt Kuntz, allows large applets to display a "splash" screen long before all of their classes have been loaded. The hysteresis applet is over 100K, overall, but because it is loaded by FastApplet, a screen with a title, a picture and a status message is displayed within a couple of seconds. In order to use this package, the actual program must be implemented as an AppletPanel, instead of an Applet. The AppletPanel is a subclass of Panel with an added setup method. This setup method is necessary because the FastApplet class loads the class by name, and can not call any constructor other than the default constructor. In order to give the AppletPanel access to the applet's < PARAM > tags, the setup method is called, with the FastApplet as a prameter. After the setup is complete, the AppletPanel is displayed in place of the splash screen.

The FastApplet is actually a complete applet, all by itself. In order to get interesting functionality out of it, several < PARAM > tags must be set. The "Title" tag set's the title which is displayed in the splash screen. The "PictureUrl" tag gives the URL of the picture to be displayed on the splash screen. Most importantly, the "AppletClass" tag gives the URL of the class (a subclass of AppletPanel) which contains the actual program. For the hysteresis applet, the tag is < PARAM name="AppletClass" value="edu.cornell.lassp.mck10.HysteresisPanel" >.

Source Code

FastApplet.java
AppletPanel.java

Description

Paul Houle has written a package for generating random numbers, called RngPack. He has implemented several research grade random number generators, including ranlux, ranmar, and ranecu. I used his ranmar generator to generate the random fields for the simulation. Paul has created a page all about the classes in RngPack.

Source Code





This page last updated on Sunday January 5, 1997

e-mail: mck10@cornell.edu