Hysteresis and Avalanches 3: Sorted Lists

Physics 681, Materials Simulations

Jim Sethna, Spring 1999

  1. Read the Sorted Lists section of Matt’s paper.
  2. Start a new class SortedListSimulation derived from HysteresisSimulation. Add member variables s, spinFlipQueue, randomField, neighborsUp as in BruteForceSimulation, and initialize them in the constructor. Add member functions FlipNextAvalanche, AvalancheEnd, and FlipSpin as in BruteForce. I recommend copying the BruteForceSimulation code entirely, change the View class to use a SortedListSimulation, and check if it runs: much of the code in SortedListSimulation is similar.
  3. Create a new class Spin, with member variables i, j, and randomField. C++ supports operator overloading: you can define things like multiplication and addition for classes. For our sorted list of spins to sort itself, we need a sense of inequality. Overload the operators <, >, ==, and = for Spin:
  4. bool operator < (const Spin &A) const

    { return (randomField < A.randomField); }

    [same for >, ==]

    spin & operator = (const spin &A)

    { i = A.i;...return *this; }

  5. Add a member variable std::vector<Spin> sortedSpins to SortedListSimulation. Also, add an integer stopNUp, which will be used to avoid looking for spins with four neighbors up after no such spins exist.
  6. In the constructor for SortedListSimulation, set up the sorted list. You’ll want to start by allocating the right size vector (use resize(N)), and then run through the lattice and set sortedSpins[ij] to the right i, j, and randomField. (Or, instead of starting with resize, create lots of spins and push_back onto the empty vector.) Try out the operators you overloaded.Then sort the random fields using the built-in function
  7. std::sort(sortedSpins.begin(), sortedSpins.end());

    Check what direction the list is sorted in. (I had troubles using the debugger with the spin class: I needed to set up temporary variables for the random field at sortedSpins[0] and sortedSpins[N-1] to look at them.)

  8. Add a member variable array nextPossible[Z+1] and initialize it as described in step 1 of the sorted-list algorithm in Matt’s paper. Initialize stopNUp to Z.
  9. In FlipNextAvalanche, replace the slow loop over i and j with the sorted list algorithm described in Matt’s paper. I used a
  10. do {...}

    while (s[iMax][jMax] != -1

    || neighborsUp[iMax][jMax] != nUpMax);

    You’ll want to loop from nUp to stopNUp. Just after decrementing nextPossible[nUp] (step 3), you should check to see if you’ve spilled over the end of the loop: decrement stopNUp if nextPossible[nUpMax]==-1.

  11. Try it out! You’ll notice that large simulations will pause noticeably before starting. Why? What’s the part of the sorted list algorithm that scales worst with N?

Statistical Mechanics: Entropy, Order Parameters, and Complexity, now available at Oxford University Press (USA, Europe).