0

I need to calculate the hamiltonian of a grid of particles given their spin. I am given the grid of particles with their spin as well as the values of J and B. The way to find that value is depicted below...

We consider the 2D Ising model, a grid of particles with periodic boundary conditions, such that each particle is spin up +1, or spin down -1. The Hamiltonian (total energy) of this system is $$H = -J\sum_{\langle a,b \rangle} s_a s_b - B \sum_a s_a$$ where $\langle a, b\rangle$ are the pairs of all neighboring particles, $B$ is the external magnetic field, and $J$ the exchange coupling (strength of interaction between neighbors) is positive. Note that both $a$ and $b$ each represent a pair of indices (row,column) for a single particle in the 2D grid of particles.

so you can imagine a grid that looks something like

 1  1  1 
-1 -1  1 
 1  1 -1

where the above grid is just numbers I randomly added. My way of calculating it was

sumLeft = 0   // sum of SaSb
sumRight = 0  // sum of Sa
for each particle in the grid:
        sumLeft = sumLeft + (spin of A * the sum of the spin of A's neighbors)
        sumRight = sumRight + spin of A

Hamiltonian = -J*sumLeft - B*sumRight

but the answer I am getting is wrong. Can anyone point me in the right direction? I think I am just misunderstanding the formula provided to me.

Eric Towers
  • 67,037
  • How are you defining "neighbors"? The domain is assumed periodic -- are you implementing periodic boundary conditions? – Eric Towers Feb 21 '20 at 23:33
  • neighbors is defined as the particles directly above, below, to the right, and to the left, so EVERY particle has exactly 4 neighbors. In the grid included in my problem statement the top left value would wrap around and touch the top right as well as the bottom left. You can think of the grid as a sphere, similiar to how a 2D map is representative of the globe – Sam Hinkie Feb 21 '20 at 23:36
  • What answer do you get and why do you think it is wrong? – Eric Towers Feb 21 '20 at 23:37
  • 1
    I think that's a torus rather than a sphere. Regarding your original question, it's possible that you are double counting in sumLeft – Ali Feb 21 '20 at 23:39
  • @EricTowers my test case that I was given is a grid that is 10x15 with each having a spin of -1. My answer is 0.304 E-20 but it expects 0.11 E-20 so I'm pretty significantly off. I can run my code with that grid though and see how I make out, one moment – Sam Hinkie Feb 21 '20 at 23:44
  • @Ali why do you think I may be double counting? I can provide a snapshot of my code if that would be useful – Sam Hinkie Feb 21 '20 at 23:45
  • It depends somewhat on the interpretation of your notation. Taking your example of a $10\times 15$ grid of particles all with spin $-1$, I count $150$ particles and $300$ adjacent pairs. So perhaps the answer is $H=-300 J + 150 B$? But it looks as if your code would count each pair twice and therefore give an answer of $H=-600 J + 150 B$. – Ali Feb 21 '20 at 23:54
  • @Ali Yeah that's a really good catch, that is (hopefully) it. I'll modify my code right now and see how it works! – Sam Hinkie Feb 22 '20 at 00:03
  • @Ali You're a lifesaver, I don't think I'm allowed to give you the right answer check mark in the comments but if you reply as an answer I'd be happy to give it there.

    *edit: you were right, I was double counting

    – Sam Hinkie Feb 22 '20 at 00:14

0 Answers0