lunedì 16 novembre 2015

2D, 3D Ising model; XY model C code. Want to simulate a ferromagnet?

The Ising model attempts to describe the low-temperature behaviour of ferromagnetic materials, which show a phase transition (means: from simple metal to magnet) at a certain temperature near 0°K. These ferromagnetic materials essentially become magnets just bringing their temperature below a critical value.
The reaching of this critical temperature manifests itself with sharp peaks or drops (jumps) among the values of various "observables", or macroscopic thermodynamical quantities, which are directly measurable given a computer simulation of the Ising model; this computer simulation is based on the Monte Carlo technique, and thus relies on random number generation in order to simulate the dynamics of spin flipping in a sample ferromagnet.
Such code decides where and when to flip spins in an initially random spin matrix (can be a 2D or 3D array) following two rules in logical OR:
  • Energy of the whole system is lower if this spin is flipped
  • A random probability associated with this spin flip is < or = than the negative exponential function of the change in energy and the inverse of the temperature
In my code, I used the Metropolis algorithm for the acceptance of the spin flip; basically it assumes that a spin gets always flipped if the resulting energy is lower than the starting one.

Ising 2D and 3D models are not that different: 3D model is just an extension of the 2D model code. The XY model is  based on the 2D Ising code too, but it relies on a different Hamiltonian for the system.

My code does the following: it is divided into 2 parts, Simulation and Data Analysis.
  • Loops for N_beta values of the temperature. At every loop it first initializes the spin system to a fixed configuration, then it runs a MonteCarlo simulation of the system at that temperature. It writes the values of the total Magnetization per site and of the total energy per site into a measurement file.
  • A data analysis program takes the measurement file and computes thermodynamic observable values, writing them to a final data file.

Repeat for each Simulation (run first) and DataAnalysis:
  • Set the SIDE of the spin array (I use around 14)
  • Set the number of sweeps (MonteCarlo iterations, about 40000)
  • Set beta_minimum, beta_maximum, N_beta (I use .25, .9,40)
  • Compile and Run 

giovedì 19 giugno 2014

Space-time diagram: The "explosion problem": relativistic Doppler effect

Suppose a situation as the one depicted here. Red dashed line is the path of light, the blue axes is the high speed frame, and the black axes is an Inertial frame of reference; green dots represent the signal:


☛ Two reference systems: S (β=cost; inertial) , and S' (β=cost; β≅c)

 ☛ S' emits a light pulse every τ meters of time

☛ S' is moving wrt S with speed β≅c

 ☛ S listens to the signal emitted by S' (which, as said, has a fixed period τ), and measures different periods, depending on β (the speed of S').

☛ We need only τ, whose value as a coordinate refers to the S' system of reference, and β :

First, we set S time and space coordinates to {0,0} and consider that a first flash of light is sent by S' at that space-time position; so this "first flash" will happen at coordinates {0,0} of both S and S'. Now, let :

 be the 4-position vector, in the S' system, of the event "Light pulse sent out", which we will call "A";

 and also let :

be the 4-position of event A in the S system.

To get the coordinates of A {τ,0} in the S system, we just need to apply a "reverse" Lorentz transformation from S' to S:

BUT the first component of X is still NOT the time that A measures!

To get the total time, one has to add the time the light takes to cover the (increasing due to
β) distance from S.

So one can write:

This is because, as light speed is always =1, it takes exactly x time to get to position x (refer to the picture!); so light traces a 45° inclined worldline.

Now, rearranging the previous equation, we may write


that just resembles the acoustic Doppler effect:

this is the relativistic Doppler effect

We can get two very important relations from this picture:

-the shift of the period, from
τ to t, seen by S; it is also a shift in frequency. It is not fixed!
-the velocity β of S' as a function only of t and τ:

 Final, synthetic way of writing the whole thing: