Hysteresis and Avalanches
Physics 681, Materials Simulations
Jim Sethna, Spring 1999
(1) Read Matt’s paper through the section “The Brute Force Method”. We’ll be implementing the brute force method today, in a console application, for two dimensions, pretty much from scratch. (Nobody writes their own random number generator.)
(2) Start up Visual C++, and start a new Win32 console application:
File-Projects-Win32 Console Application
(3) Give a project name (HysteresisConsole), and accept the defaults.
(4) Make a new class, HysteresisSimulation. This will be an abstract strategy, which we’ll implement with two or three different algorithms. Include protected variables describing the system L=length of side, R=width of the random field. Include protected variables giving the state of the system , H=external field (double), M=magnetization, N=number of spins in the system, Z=number of neighbors for each spin, and rand (our random-number generator, which you can copy from LMC or MD). Write Get routines for the variables. Write an abstract member function FlipNextAvalanche, and two protected abstract member functions FlipSpin and AvalancheEnd. Abstract member functions don’t have a body, and are set = 0 to force you to define one in the derived classes:
virtual void FlipNextAvalanche() = 0;
(5) Derive a BruteForceSimulation class from HysteresisSimulation: the constructor should be passed R, L, and a seed for the random number generator. The constructor should set all the internal variables and initialize rand. It should also allocate space and initialize three protected member variable arrays: a spin array s, a randomField array of doubles (using rand.gaussian(R)), and a neighborsUp array to keep track of the number of up neighbors. Remember to delete the arrays in the destructor. Add a protected member variable spinFlipQueue; you’ll need to include <queue>, and the line should read
std::queue<int> spinFlipQueue
(the std:: tells the system that queue is in the standard template library). If you want, you can pack the (ij) pairs into a structure, and queue the structure instead of the two integers separately.
(6) Write the member function FlipSpin, which should flip the spin and increment the magnetization. We’ll add the graphics and other observers here.
(7) Write the member function AvalancheEnd, which should do nothing for now. It will call various observers, for example to change the color of the spins between avalanches.
(8) Write the member function FlipNextAvalanche, implementing steps 1-5 of Matt’s write-up of the avalanche algorithm in the Brute Force section. This is the bulk of the work for today. In using spinFlipQueue, you’ll want to use the member functions push, empty, front and pop. You’ll always want to pop after front (looking at the top variable in the queue doesn’t remove it).
(9) Write the main loop. I did it by adding a new file to the project and then opening it. It should include the relevant .h files from parts (4) and (5), and define void main(int argc, char **argv). The main loop should set up a BruteForceSimulation of modest size (for debugging, say R=3.0 and L=3), and repeatedly call brute.FlipNextAvalanche() until brute.GetM() equals brute.GetN().
(10) A console application can write to the console, making it a lot easier to debug. Add print statements to FlipSpin and AvalancheEnd to show each spin as it flips. You can do this by #include <iostream.h> and lines like
cout < “i = “ < i < ...
Next lab period we’ll implement the graphics in a Windows application.