IGLib  1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel Class Reference
+ Inheritance diagram for IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel:
+ Collaboration diagram for IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel:

Classes

class  SpinStateCollection
 A nested class providing the indexed property functionality for the _spinState list. More...
 

Public Member Functions

 IsingModel ()
 The constructors starts the state list in an extremely ordered state. We also need to instantiate the fake indexed SpinState property. More...
 
void TryTurnRandomSpin ()
 Tries to turn a random spin in the lattice. If the energy change is positive and the dice roll falls above the exponential curve defined by the beta parameter, the change is discarded. More...
 
void SimulatedAnnealingWithPlot ()
 Anneals the Ising model while plotting the results. More...
 
void SimulatedAnnealing ()
 Anneals the Ising model, no plotting. More...
 
double ConfigurationEnergy ()
 Calculates the configuration energy by accounting for every bond in the lattice. Takes into account the B-vK boundary conditions. More...
 
double AverageConfigEnergy ()
 Calculates the average configuration energy at a certain temperature. More...
 
void AvgConfigEnergyVsTemp (double initTemp, double finalTemp, double nSamples)
 Calculates the average configuration energy on a temperature range and writes the results to a file. More...
 
double MagMoment ()
 Calculates the magnetization by accounting for each spin in the lattice. More...
 
double AverageMagMoment ()
 Calculates the average magnetization at a certain temperature. More...
 
void AvgMagMomentVsTemp (double initTemp, double finalTemp, double nSamples)
 Calculates the average magnetization on a temperature range and writes the results to a file. More...
 
double AverageSusceptibilityN ()
 Calculates the average susceptibility times N at a certain temperature. More...
 
void AvgSusceptibilityNVsTemp (double initTemp, double finalTemp, double nSamples)
 Calculates the average susceptibility times N on a temperature range and writes the results to a file. More...
 
double EnergyVariance ()
 Calculates the expected value of energy squared minus square of the expected value of energy. More...
 
double AvgEnergyVariance ()
 Calculates the average energy variance, used when calculating the specific heat. More...
 
void AvgSpecificHeatNVsTemp (double initTemp, double finalTemp, double nSamples)
 Calculates the average specific heat times N at a certain temperature range and writes the results to a file. More...
 
double OnlineEnergyVariance ()
 Calculates the online energy variance. More...
 
double AvgOnlineEnergyVariance ()
 Calculates the average online energy variance, used when calculating the specific heat. More...
 
void AvgSpecificHeatNVsTemp2 (double initTemp, double finalTemp, double nSamples)
 Calculates the average specific heat times N at a certain temperature range and writes the results to a file. More...
 
- Public Member Functions inherited from IG.MPetekLib.Algorithms.PlottableModels.PlottableModelBase
PlotZedgraphCurve NewCurveFromPlottableData (PlotterZedGraph plotter, int x, int y)
 Creates a new PlotZedgraphCurve object from the available plottable data. More...
 
void LoadPlottableDataToCurve (PlotZedgraphCurve curve, int x, int y)
 Copies the calculated data to the existing PlotZedgraphCurve object. Enough space must be available on the curve object's list. More...
 

Protected Attributes

double _initialBeta = 0.005
 
double _finalBeta = 30
 
int _stepsAtTemperature = 5000
 
int _coolingLevels = 7
 
double _gamma
 The factor for which the inverse temperature beta rises after each cooling level. The inverse alpha, where alpha is the analogous factor asocciated with the gradual fall of the temperature. More...
 
int _plotEveryNShifts = 50
 
- Protected Attributes inherited from IG.MPetekLib.Algorithms.PlottableModels.PlottableModelBase
string _title
 

Properties

int LatticeXDim [get, set]
 Rectangular lattice's x-dimension. More...
 
int LatticeYDim [get, set]
 Rectangular lattice's y-dimension. More...
 
double Beta [get, set]
 The parameter beta of the falling exponential (Boltzmann) distribution. The "inverse" temperature. More...
 
double Temperature [get, set]
 Temperature is an inverse with beta. Boltzmann constant = 1. More...
 
double J [get, set]
 Coupling constant between spins: 1 -> paramagnetism (same direction: lower energy), -1 -> diamagnetism. More...
 
double H [get, set]
 Coupling constant between a spin and the external magnetic field: 1 -> (same direction: lower energy). More...
 
int StateChosenSpin [get, set]
 The state of the spin that's been chosen by the RNG. This property should make the code more readable. More...
 
int StateAboveSpin [get, set]
 The state of the spin above the chosen spin. This property should make the code more readable. More...
 
int StateBelowSpin [get, set]
 The state of the spin below the chosen spin. This property should make the code more readable. More...
 
int StateLeftSpin [get, set]
 The state of the spin left of the chosen spin. This property should make the code more readable. More...
 
int StateRightSpin [get, set]
 The state of the spin right of the chosen spin. This property should make the code more readable. More...
 
double InitialBeta [get, set]
 The initial inverse temperature for the simulated annealing process. More...
 
double InitialTemperature [get, set]
 The initial temperature for the simulated annealing process. More...
 
double FinalBeta [get, set]
 The final inverse temperature for the simulated annealing process. More...
 
double FinalTemperature [get, set]
 The final temperature for the simulated annealing process. More...
 
int StepsAtTemperature [get, set]
 How many spin turns the method will make at a certain temperature. More...
 
int CoolingLevels [get, set]
 How granular the cooling will be. Example: T0 = 1000, TN=100, CoolingLevels = 10: 1000, 900, 800, ..., 200, 100. More levels means higher reliability, but also more time wasted. More...
 
int PlotEveryNShifts [get, set]
 How often the plotting window should refresh. A smaller number means more often and makes it more interesting. However, a bigger number makes the whole calculation much faster. More...
 
int NumOfAnnealingsToAvgOver [get, set]
 How many terms should be added together before averaging takes place. Used by all the averaging methods. More...
 
- Properties inherited from IG.MPetekLib.Algorithms.PlottableModels.PlottableModelBase
string Title [get, set]
 The plottable model's name. Also used as a plot title. More...
 
List< double[]> PlottableData [get, set]
 The main solution array, which is used by the plotter. More...
 

Private Member Functions

void UpdateLatticeRowCurves ()
 Used by the main thread. Updates the points shown by the plotting thread to the most recent state. More...
 
void ShowPlot ()
 This method runs on the plotting thread. Its only job is to display the plotting window. More...
 

Private Attributes

List< List< int > > _spinState
 
SpinStateCollection SpinState
 Holds the states (1 or -1) of all the spins in the lattice. Each spin's position in the lattice can be inferred from the indices, since the lattice is rectangular. The indices are cyclic (periodic boundary condition). An indexed property. More...
 
List< PlotZedgraphCurve_latticeRowCurve
 A list of all the rows of spins in the spin lattice. Each row is represented by a PlotZedGraphCurve object. More...
 
PlotHQ _plothq1
 A PlotHQ object used by the plotting thread. More...
 
int _latticeXDim = 100
 
int _latticeYDim = 100
 
double _beta = 0.3
 
double _j = 1
 
double _h = 0
 
Random _rng = new Random()
 An all-purpose RNG. More...
 
double _diceRoll
 A random real number between 0 and 1. Used for the simulated annealing (Boltzmann) criterion. More...
 
int _randomSpinX
 The RNG chooses a random spin. This is its x-index. More...
 
int _randomSpinY
 The RNG chooses a random spin. This is its y-index. More...
 
double _energyChange
 The difference between the new and the old energy. More...
 
readonly object _locker = new object()
 A locker for wait/pulse methods. More...
 
bool _go = false
 A blocking condition for the wait/pulse methods. More...
 
int _numOfAnnealingsToAvgOver = 10
 

Constructor & Destructor Documentation

IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.IsingModel ( )
inline

The constructors starts the state list in an extremely ordered state. We also need to instantiate the fake indexed SpinState property.

Member Function Documentation

void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.UpdateLatticeRowCurves ( )
inlineprivate

Used by the main thread. Updates the points shown by the plotting thread to the most recent state.

void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.ShowPlot ( )
inlineprivate
void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.TryTurnRandomSpin ( )
inline

Tries to turn a random spin in the lattice. If the energy change is positive and the dice roll falls above the exponential curve defined by the beta parameter, the change is discarded.

void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.SimulatedAnnealingWithPlot ( )
inline
void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.SimulatedAnnealing ( )
inline

Anneals the Ising model, no plotting.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.ConfigurationEnergy ( )
inline

Calculates the configuration energy by accounting for every bond in the lattice. Takes into account the B-vK boundary conditions.

Returns
Current configuration energy.
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AverageConfigEnergy ( )
inline

Calculates the average configuration energy at a certain temperature.

Returns
Average configuration energy.
void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AvgConfigEnergyVsTemp ( double  initTemp,
double  finalTemp,
double  nSamples 
)
inline

Calculates the average configuration energy on a temperature range and writes the results to a file.

Parameters
initTempInitial temperature.
finalTempFinal temperature.
nSamplesThe number of samples on the temperature range.

Referenced by IG.MPetekLib.Application.Scripts.CompPhys._04IsingAvgEnergy.Run().

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.MagMoment ( )
inline

Calculates the magnetization by accounting for each spin in the lattice.

Returns
Current magnetization.
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AverageMagMoment ( )
inline

Calculates the average magnetization at a certain temperature.

Returns
void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AvgMagMomentVsTemp ( double  initTemp,
double  finalTemp,
double  nSamples 
)
inline

Calculates the average magnetization on a temperature range and writes the results to a file.

Parameters
initTempInitial temperature.
finalTempFinal temperature.
nSamplesThe number of samples on the temperature range.
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AverageSusceptibilityN ( )
inline

Calculates the average susceptibility times N at a certain temperature.

Returns
Average susceptibility.
void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AvgSusceptibilityNVsTemp ( double  initTemp,
double  finalTemp,
double  nSamples 
)
inline

Calculates the average susceptibility times N on a temperature range and writes the results to a file.

Parameters
initTempInitial temperature.
finalTempFinal temperature.
nSamplesThe number of samples on the temperature range.
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.EnergyVariance ( )
inline

Calculates the expected value of energy squared minus square of the expected value of energy.

Returns
The variance of energy.
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AvgEnergyVariance ( )
inline

Calculates the average energy variance, used when calculating the specific heat.

Returns
Average energy variance.
void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AvgSpecificHeatNVsTemp ( double  initTemp,
double  finalTemp,
double  nSamples 
)
inline

Calculates the average specific heat times N at a certain temperature range and writes the results to a file.

Parameters
initTempInitial temperature.
finalTempFinal temperature.
nSamplesThe number of samples on the temperature range.
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.OnlineEnergyVariance ( )
inline

Calculates the online energy variance.

Returns
Energy variance.
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AvgOnlineEnergyVariance ( )
inline

Calculates the average online energy variance, used when calculating the specific heat.

Returns
Average energy variance.
void IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.AvgSpecificHeatNVsTemp2 ( double  initTemp,
double  finalTemp,
double  nSamples 
)
inline

Calculates the average specific heat times N at a certain temperature range and writes the results to a file.

Parameters
initTempInitial temperature.
finalTempFinal temperature.
nSamplesThe number of samples on the temperature range.

Referenced by IG.MPetekLib.Application.Scripts.CompPhys._05IsingAvgMagnetization.Run().

Member Data Documentation

List<List<int> > IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._spinState
private
SpinStateCollection IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.SpinState
private

Holds the states (1 or -1) of all the spins in the lattice. Each spin's position in the lattice can be inferred from the indices, since the lattice is rectangular. The indices are cyclic (periodic boundary condition). An indexed property.

List<PlotZedgraphCurve> IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._latticeRowCurve
private

A list of all the rows of spins in the spin lattice. Each row is represented by a PlotZedGraphCurve object.

PlotHQ IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._plothq1
private

A PlotHQ object used by the plotting thread.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._latticeXDim = 100
private
int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._latticeYDim = 100
private
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._beta = 0.3
private
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._j = 1
private
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._h = 0
private
Random IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._rng = new Random()
private

An all-purpose RNG.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._diceRoll
private

A random real number between 0 and 1. Used for the simulated annealing (Boltzmann) criterion.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._randomSpinX
private

The RNG chooses a random spin. This is its x-index.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._randomSpinY
private

The RNG chooses a random spin. This is its y-index.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._energyChange
private

The difference between the new and the old energy.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._initialBeta = 0.005
protected
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._finalBeta = 30
protected
int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._stepsAtTemperature = 5000
protected
int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._coolingLevels = 7
protected
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._gamma
protected

The factor for which the inverse temperature beta rises after each cooling level. The inverse alpha, where alpha is the analogous factor asocciated with the gradual fall of the temperature.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._plotEveryNShifts = 50
protected
readonly object IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._locker = new object()
private

A locker for wait/pulse methods.

bool IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._go = false
private

A blocking condition for the wait/pulse methods.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel._numOfAnnealingsToAvgOver = 10
private

Property Documentation

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.LatticeXDim
getset

Rectangular lattice's x-dimension.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.LatticeYDim
getset

Rectangular lattice's y-dimension.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.Beta
getset

The parameter beta of the falling exponential (Boltzmann) distribution. The "inverse" temperature.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.Temperature
getset

Temperature is an inverse with beta. Boltzmann constant = 1.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.J
getset

Coupling constant between spins: 1 -> paramagnetism (same direction: lower energy), -1 -> diamagnetism.

Referenced by IG.MPetekLib.Application.Scripts.CompPhys._04IsingAvgEnergy.Run(), and IG.MPetekLib.Application.Scripts.CompPhys._05IsingAvgMagnetization.Run().

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.H
getset
int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.StateChosenSpin
getsetprivate

The state of the spin that's been chosen by the RNG. This property should make the code more readable.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.StateAboveSpin
getsetprivate

The state of the spin above the chosen spin. This property should make the code more readable.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.StateBelowSpin
getsetprivate

The state of the spin below the chosen spin. This property should make the code more readable.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.StateLeftSpin
getsetprivate

The state of the spin left of the chosen spin. This property should make the code more readable.

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.StateRightSpin
getsetprivate

The state of the spin right of the chosen spin. This property should make the code more readable.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.InitialBeta
getset

The initial inverse temperature for the simulated annealing process.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.InitialTemperature
getset
double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.FinalBeta
getset

The final inverse temperature for the simulated annealing process.

double IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.FinalTemperature
getset
int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.StepsAtTemperature
getset
int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.CoolingLevels
getset

How granular the cooling will be. Example: T0 = 1000, TN=100, CoolingLevels = 10: 1000, 900, 800, ..., 200, 100. More levels means higher reliability, but also more time wasted.

Referenced by IG.MPetekLib.Application.Scripts.CompPhys._03AnnealingIsingModel.Run(), IG.MPetekLib.Application.Scripts.CompPhys._05IsingAvgMagnetization.Run(), and IG.MPetekLib.Application.Scripts.CompPhys._04IsingAvgEnergy.Run().

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.PlotEveryNShifts
getset

How often the plotting window should refresh. A smaller number means more often and makes it more interesting. However, a bigger number makes the whole calculation much faster.

Referenced by IG.MPetekLib.Application.Scripts.CompPhys._03AnnealingIsingModel.Run().

int IG.MPetekLib.Algorithms.PlottableModels.CompPhys.IsingModel.NumOfAnnealingsToAvgOver
getset

How many terms should be added together before averaging takes place. Used by all the averaging methods.

Referenced by IG.MPetekLib.Application.Scripts.CompPhys._05IsingAvgMagnetization.Run().


The documentation for this class was generated from the following file: