Modules are fortran subunits which can be compiled separately. Download the example where you can see that if a module is included in a program file it comes before the main program. From this file, create a two separate files: one called vectorfun.f90 containing the module and the other Example.f90 containing the main program. Compile the module using
f90-vast -c vectorfun.f90
which creates an object code and stores it in the file vectorfun.o To create an executable enter
f90-vast Example.f90 vectorfun.o
which creates an executable and writes it into the default file a.out. You can then run it in the usual way. To write the executable to a specified file, Example.exe, enter
f90-vast -o Example.exe Example.f90 vectorfun.o
Modules may contain functions and/or subroutines and can be any subunit of a larger program.
PROBLEM 1
Write a computer program to carry out a Monte Carlo simulation
of the magnetic behavior of an array of spins on a two dimensional
square lattice. Each site of the lattice has a spin which can
be either up or down, which we take to be 1(up) or -1(down).
Let the lattice dimension be a variable, L,
and hence the number of spins is N = LxL. Each spin S(i,j), for i=1...L and
J=1...L, has an energy
of interaction with each of its four neighbors which is given by
J S(i,j)S(neighbor). Consider that J is negative, so that the
lowest energy state of the magnet is when all the spins are
aligned in the same direction, that is all of the spins are
in the state "one" or all of them are in the state "minus one".
This is the ferromagnetic or magnetized state.
When the spin lattice is heated up, the spins fluctuate and
eventually the magnetized state is destroyed by the
fluctuations. Our goal is to write a computer program to
calculate the magnetization of the spin lattice as a function
of the temperature. We will do this by using a Monte Carlo
procedure to include the effect of temperature. This
is achieved by the following algorithm.
(1) Choose a random spin in the lattice
(2) Calculate the energy contribution of that spin E(S)
(3) Flip that spin and find the new energy contribution E(S')
(4) Calulate the quantity X=Exp((E(S)-E(S'))/k T)
(5) If X>R, then keep the spin flip, otherwize return the spin
to its original state. Here R is a random number. Return to (1)
The first
thing to do is to get the algorithm going, then we can
talk about how to calculate various properties, including the
magnetization.
For this project your code is expected to be well structured, by following the
these principles.
-Design your code before you starting writing it
-Break your code into sensible subunits
-State precisely, using comments, what each subunit does
-Don't use clever tricks. Make each step as transparent as possible
-Use variable names that have meaning, though overly long variable names are also bad
Choosing a good naming convention is part of your program design