#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import sys, os, pickle import numpy as np from libs.cython import set_globals, compute_distances from libs.simlib import Plotter from matplotlib import cm p = Plotter(show=True, pdf=False, pgf=False, name='ljsim') """==== DEFINITIONS ====""" # SYSTEM CONSTANTS # density density = 0.316 # number of particles per side for cubic setup n = 10 # COMPUTED CONSTANTS # total number of particles N = n * n * n # volume of the system volume = N / density # side length of the system L = volume**(1. / 3.) # get filename on command line if len(sys.argv) == 2: print "Usage: python %s FILE" % sys.argv[0] datafilename = sys.argv[1] else:
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import numpy as np import sys from libs.simlib import Plotter p = Plotter(show = True, pdf = False, pgf = False, name='4_ljfluid') # ==== DEFINITIONS ==== # CONSTANTS EPS = 1 SIG = 1 # density density = 0.7 # number of particles per side if len(sys.argv) == 2 and sys.argv[1].isdigit(): n = int(sys.argv[1]) else: n = 3 # timestep dt = 0.01 # length of run tmax = 1.0 # cutoff rcut = 2.5*SIG # potential shift shift = -0.016316891136 # total number of particles N = n*n*n # particle positions on a cubic lattice
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import numpy as np from libs.simlib import Plotter p = Plotter(show = True, pdf = False, pgf = False, name='2_ljbillards') # ==== DEFINITIONS ==== EPS = 1 SIG = 1 # constants dt = 0.01 tmax = 20.0 # running variables t = 0.0 # particle positions x = np.zeros((3,5)) x[:,0] = [0.0, 0.0, 0.0] x[:,1] = [5.0, 0.3, 0.0] x[:,2] = [8.0, 1.8, 0.0] x[:,3] = [11.0, 0.0, -1.0] #x[:,4] = [12.0, 9.0, 0.0] x[:,4] = [15.4324, 9.51146, 0.0] # particle velocities v = np.zeros((3,5))
params.T_StepSize = 0.005 # only 0.02 would be needed Ising_L = [4,16,64] Binning_K = [50,200,800] # parameters used to estimate beta_m elif OverParam == 2: params.T_Start = 2.27 # << estimated critical Temperature params.T_Stop = params.T_Start params.T_StepSize = 0.01 # only 0.02 would be needed Ising_L = [4,16,32,64,128] Binning_K = [50,200,800,800,800] useCache = True p = Plotter(show = False, pdf = False, pgf = False, latex=False, name='ising') # FUNCTIONS ############################################################################################### #==Exact=== itmp = np.arange(-1,4-1) def generateAllStates(n=4): nsqrt = n*n possibilities = np.mgrid[[slice(-1,3,2) for _ in range(nsqrt)]] # Vectorization makes the calculation fast as hell. configurations = possibilities.reshape(n,n,-1).T return configurations def calcEFromAll(configurations, J=params.Ising_J, H=params.Ising_H, n=4, i=itmp): E = -J*np.sum(np.sum(configurations*configurations[:,:,i]+configurations*configurations[:,i,:],axis=1),axis=1) E -= H*np.sum(np.sum(configurations,axis=1),axis=1) # Attention: Numpy doesn't like "E /= n**2". It applies integer division! return E
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import numpy as np from libs.simlib import Plotter p = Plotter(show=True, pdf=False, pgf=False, name="1_potential") # ==== DEFINITIONS ==== EPS = 1 SIG = 1 NParticles = 1000 # ==== FUNCTIONS ==== def compute_lj_potential(rij, eps=EPS, sig=SIG): q = sig / np.linalg.norm(rij) return 4 * eps * (q ** 12 - q ** 6) def compute_lj_force(rij, eps=EPS, sig=SIG): norm = np.linalg.norm(rij) q = sig / norm return 4 * eps * (12 * q ** 11 - 6 * q ** 5) * q / norm ** 2 * rij # ==== CALCULATION ==== d = np.zeros((NParticles, 3)) d[:, 0] = np.linspace(0.85, 2.5, NParticles) potential = np.array(map(compute_lj_potential, d)) force = np.array(map(compute_lj_force, d))
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import numpy as np from libs.simlib import Plotter p = Plotter(show=True, pdf=False, pgf=False, name='3_periodic') # ==== DEFINITIONS ==== EPS = 1 SIG = 1 RCOFF = 2.5 * SIG L = 10 # constants dt = 0.01 tmax = 20.0 # running variables t = 0.0 # particle positions x = np.zeros((3, 2)) x[:, 0] = [3.9, 3, 4] x[:, 1] = [6.1, 5, 6] # particle velocities v = np.zeros((3, 2)) v[:, 0] = [-2, -2, -2] v[:, 1] = [2, 2, 2]
#!/usr/bin/python # -*- coding: utf-8 -*- from __future__ import division import os, sys, pickle import numpy as np #import scipy as sp #import scipy.signal from libs.simlib import Plotter """==== PARAMETERS ====""" # path to simulation File datafilename = "./data/series.dat" p = Plotter(show = True, pdf = True, pgf = False, name='series') """=== LOADING DATA ===""" # check whether datafilename is given/data file exists if len(datafilename) == 0: print "ERROR: No path to data file given." sys.exit(1) if not os.path.exists(datafilename): print "ERROR: '%s' doesn't exist." % datafilename sys.exit(1) # read from datafile print "Reading data from '%s.'" % datafilename datafile = open(datafilename, 'r') s0, s1, s2, s3, s4 = pickle.load(datafile) datafile.close() """==== DEFINITIONS ==="""
=== SETUP === ''' n = 4 J = 1 H = 0 TStart = 1 TStop = 5 TStep = 0.1 MCSteps = 10000 k = 200 np.random.seed(13) useExact = True useMC = True p = Plotter(show=True, pdf=False, pgf=False, latex=False, name='ising') ''' === FUNCTIONS === ''' def unique(arr): order = np.lexsort(arr.T) arr = arr[order] diff = np.diff(arr, axis=0) ui = np.ones(len(arr), 'bool') ui[1:] = (diff != 0).any(axis=1) return arr[ui] itmp = np.arange(-1, n - 1)
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import os, pickle import numpy as np from libs.cython import set_globals, compute_forces, compute_distances, compute_energy, compute_pressure, rebuild_neighbor_lists from libs.simlib import Plotter from matplotlib import cm p = Plotter(show=True, pdf=False, pgf=False, name='ljsim') """==== DEFINITIONS ====""" # SYSTEM CONSTANTS # density density = 0.316 # timestep dt = 0.01 # max length of each run 800 tadd = 1000.0 # max length of all runs tges = 1000.0 # number of particles per side for cubic setup n = 10 # Desired temperature {0.3, 1.0, 2.0} Tdes = 0.3 NEWRUN = False RANDOMPOSITION = False FORCECAPPING = False VELOCITYRESCALING = False LD = True
params.Ising_J = 1 params.Ising_H = 0 params.MC_Seed = 42 params.MC_Sweeps = 100000 params.T_Start = 1 params.T_Stop = 3 params.T_StepSize = 0.1 Ising_L = [4, 8, 16, 32, 64] Binning_K = [50, 100, 200, 400, 800] useCache = True p = Plotter(show=True, pdf=False, pgf=False, latex=False, name='3beta') Tc = 2.27 v = -1 # FUNCTIONS ############################################################################################### #===Error analysis=== def binning(allValues, k): nBlocks = len(allValues) // k allBlocks = allValues[:nBlocks * k].reshape((-1, k)) meanBlocks = np.mean(allBlocks, axis=1) meanValue = np.mean(meanBlocks) variance = np.mean((meanBlocks - meanValue)**2) / (nBlocks - 1)
params.Ising_J = 1 params.Ising_H = 0 params.MC_Seed = 42 params.MC_Sweeps = 10000 params.T_Start = 2 params.T_Stop = 2.4 params.T_StepSize = 0.005 # only 0.02 would be needed Ising_L = [4,16,64] Binning_K = [50,200,800] useCache = True p = Plotter(show = True, pdf = False, pgf = False, latex=False, name='2binder') # FUNCTIONS ############################################################################################### #===Error analysis=== def binning(allValues,k): nBlocks=len(allValues)//k allBlocks = allValues[:nBlocks*k].reshape((-1,k)) meanBlocks = np.mean(allBlocks,axis=1) meanValue = np.mean(meanBlocks) variance = np.mean((meanBlocks-meanValue)**2)/(nBlocks-1) return np.sqrt(variance) def errorAll(func,arr,k):
MC_M = arrayM.flat MC_P = arrayP MC_errmE = calcError(MC_meanE) MC_errmM = calcError(MC_meanM) MC_errmMabs = calcError(MC_meanMabs) print "error of MC mean E:", MC_errmE print "error of MC mean M:", MC_errmM print "error of MC mean |M|:", MC_errmMabs print 'Finished metropolis calculation.' ''' === PLOTS === ''' p = Plotter(show = True, pdf = False, pgf = False, name='ising') p.new(name='Mean energy',xlabel='Temperature',ylabel='Energy') if useExact: p.plot(T,meanE,label='exact') if useMC: p.errorbar(T, MC_meanE, yerr=MC_errmE, label='metropolis') p.new(name='Mean magnetization',xlabel='Temperature',ylabel='Magnetization') if useExact: p.plot(T,meanM,label='exact') if useMC: p.errorbar(T, MC_meanM, yerr=MC_errmM, label='metropolis') p.new(name='Mean absolute magnetization',xlabel='Temperature',ylabel=r'\vertMagnetization\vert') if useExact:
params.Ising_J = 1 params.Ising_H = 0 params.MC_Seed = 42 params.MC_Sweeps = 100000 params.T_Start = 1 params.T_Stop = 3 params.T_StepSize = 0.1 Ising_L = [4,8,16,32,64] Binning_K = [50,100,200,400,800] useCache = True p = Plotter(show = True, pdf = False, pgf = False, latex=False, name='3beta') Tc = 2.27 v = -1 # FUNCTIONS ############################################################################################### #===Error analysis=== def binning(allValues,k): nBlocks=len(allValues)//k allBlocks = allValues[:nBlocks*k].reshape((-1,k)) meanBlocks = np.mean(allBlocks,axis=1) meanValue = np.mean(meanBlocks) variance = np.mean((meanBlocks-meanValue)**2)/(nBlocks-1)
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division from numpy import * from libs.cython2.lj import * from libs.simlib import Plotter import sys p = Plotter(show = True, pdf = False, pgf = False, name='7_ljfluid_lists') # CONSTANTS # density density = 0.7 # number of particles per side if len(sys.argv) == 2 and sys.argv[1].isdigit(): n = int(sys.argv[1]) else: n = 5 # timestep dt = 0.01 # length of run tmax = 50.0 # cutoff length rcut = 2.5 # potential shift shift = -0.016316891136 # skin size skin = 0.3 # COMPUTED CONSTANTS # total number of particles
params.T_StepSize = 0.005 # only 0.02 would be needed Ising_L = [4, 16, 64] Binning_K = [50, 200, 800] # parameters used to estimate beta_m elif OverParam == 2: params.T_Start = 2.27 # << estimated critical Temperature params.T_Stop = params.T_Start params.T_StepSize = 0.01 # only 0.02 would be needed Ising_L = [4, 16, 32, 64, 128] Binning_K = [50, 200, 800, 800, 800] useCache = True p = Plotter(show=False, pdf=False, pgf=False, latex=False, name="ising") # FUNCTIONS ############################################################################################### # ==Exact=== itmp = np.arange(-1, 4 - 1) def generateAllStates(n=4): nsqrt = n * n possibilities = np.mgrid[ [slice(-1, 3, 2) for _ in range(nsqrt)] ] # Vectorization makes the calculation fast as hell. configurations = possibilities.reshape(n, n, -1).T return configurations
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import os, pickle import numpy as np from libs.cython import set_globals, compute_forces, compute_distances, compute_energy, compute_pressure, rebuild_neighbor_lists from libs.simlib import Plotter from matplotlib import cm p = Plotter(show = True, pdf = False, pgf = False, name='ljsim') """==== DEFINITIONS ====""" # SYSTEM CONSTANTS # density density = 0.316 # timestep dt = 0.01 # max length of each run 800 tadd = 20.0 # max length of all runs tges = 1000.0 # number of particles per side for cubic setup n = 10 # Desired temperature {0.3, 1.0, 2.0} Tdes= 10.0 NEWRUN = True RANDOMPOSITION = True FORCECAPPING = True VELOCITYRESCALING = True
=== SETUP === ''' n = 4 J = 1 H = 0 TStart = 1 TStop = 5 TStep = 0.1 MCSteps = 10000 k = 200 np.random.seed(13) useExact = True useMC = True p = Plotter(show = True, pdf = False, pgf = False, latex=False, name='ising') ''' === FUNCTIONS === ''' def unique(arr): order = np.lexsort(arr.T) arr = arr[order] diff = np.diff(arr, axis=0) ui = np.ones(len(arr), 'bool') ui[1:] = (diff != 0).any(axis=1) return arr[ui] itmp = np.arange(-1,n-1) #==Exact===
params.Ising_J = 1 params.Ising_H = 0 params.MC_Seed = 42 params.MC_Sweeps = 10000 params.T_Start = 2.27 # << estimated critical Temperature params.T_Stop = params.T_Start params.T_StepSize = 0.01 # only 0.02 would be needed Ising_L = [4,16,32,64,128] Binning_K = [50,200,800,800,800] useCache = True p = Plotter(show = True, pdf = False, pgf = False, latex=False, name='3beta') v=-1 # FUNCTIONS ############################################################################################### #===Error analysis=== def binning(allValues,k): nBlocks=len(allValues)//k allBlocks = allValues[:nBlocks*k].reshape((-1,k)) meanBlocks = np.mean(allBlocks,axis=1) meanValue = np.mean(meanBlocks) variance = np.mean((meanBlocks-meanValue)**2)/(nBlocks-1) return np.sqrt(variance)
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division from numpy import * from libs.cython1.lj import * from libs.simlib import Plotter import sys p = Plotter(show=True, pdf=False, pgf=False, name='6_ljfluid_cython') # CONSTANTS # density density = 0.7 # number of particles per side if len(sys.argv) == 2 and sys.argv[1].isdigit(): n = int(sys.argv[1]) else: n = 3 # timestep dt = 0.01 # length of run tmax = 1.0 # cutoff rcut = 2.5 # potential shift shift = -0.016316891136 # COMPUTED CONSTANTS # total number of particles N = n * n * n # volume of the system volume = N / density
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import sys, os, pickle import numpy as np from libs.cython import set_globals, compute_distances from libs.simlib import Plotter from matplotlib import cm p = Plotter(show=True, pdf=False, pgf=False, name="ljsim") """==== DEFINITIONS ====""" # SYSTEM CONSTANTS # density density = 0.316 # number of particles per side for cubic setup n = 10 # COMPUTED CONSTANTS # total number of particles N = n * n * n # volume of the system volume = N / density # side length of the system L = volume ** (1.0 / 3.0) # get filename on command line if len(sys.argv) == 2: print "Usage: python %s FILE" % sys.argv[0] datafilename = sys.argv[1]
MC_acceptance = np.mean(arrayA) MC_E = arrayE.flat MC_M = arrayM.flat MC_P = arrayP print 'Finished metropolis calculation.' MC_errmE = binningAll(arrayE) MC_errmM = binningAll(arrayM) MC_errmMabs = binningAll(abs(arrayM)) print 'Finished error calculation.' ''' === PLOTS === ''' p = Plotter(show=True, pdf=False, pgf=False, name='ising') p.new(name='Mean energy', xlabel='Temperature', ylabel='Energy') if useExact: p.plot(T, meanE, label='exact') if useMC: p.errorbar(T, MC_meanE, yerr=MC_errmE, label='metropolis') p.new(name='Mean magnetization', xlabel='Temperature', ylabel='Magnetization') if useExact: p.plot(T, meanM, label='exact') if useMC: p.errorbar(T, MC_meanM, yerr=MC_errmM, label='metropolis') p.new(name='Mean absolute magnetization', xlabel='Temperature',
from __future__ import division import os, pickle import numpy as np from libs.cython import ( set_globals, compute_forces, compute_distances, compute_energy, compute_pressure, rebuild_neighbor_lists, ) from libs.simlib import Plotter from matplotlib import cm p = Plotter(show=True, pdf=False, pgf=False, name="ljsim") """==== DEFINITIONS ====""" # SYSTEM CONSTANTS # density density = 0.316 # timestep dt = 0.01 # max length of each run 800 tadd = 1000.0 # max length of all runs tges = 1000.0 # number of particles per side for cubic setup n = 10 # Desired temperature {0.3, 1.0, 2.0} Tdes = 0.3
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import numpy as np from libs.simlib import Plotter p = Plotter(show = True, pdf = False, pgf = False, name='3_periodic') # ==== DEFINITIONS ==== EPS = 1 SIG = 1 RCOFF = 2.5*SIG L = 10 # constants dt = 0.01 tmax = 20.0 # running variables t = 0.0 # particle positions x = np.zeros((3,2)) x[:,0] = [3.9, 3, 4] x[:,1] = [6.1, 5, 6] # particle velocities v = np.zeros((3,2)) v[:,0] = [-2, -2, -2] v[:,1] = [2, 2, 2]
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import sys, os, pickle import numpy as np from libs.cython import set_globals, compute_distances from libs.simlib import Plotter from matplotlib import cm p = Plotter(show = True, pdf = False, pgf = False, name='ljsim') """==== DEFINITIONS ====""" # SYSTEM CONSTANTS # density density = 0.316 # number of particles per side for cubic setup n = 10 # COMPUTED CONSTANTS # total number of particles N = n*n*n # volume of the system volume = N/density # side length of the system L = volume**(1./3.) # get filename on command line if len(sys.argv) == 2: print "Usage: python %s FILE" % sys.argv[0] datafilename = sys.argv[1]
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import numpy as np import sys from libs.simlib import Plotter p = Plotter(show=True, pdf=False, pgf=False, name='4_ljfluid') # ==== DEFINITIONS ==== # CONSTANTS EPS = 1 SIG = 1 # density density = 0.7 # number of particles per side if len(sys.argv) == 2 and sys.argv[1].isdigit(): n = int(sys.argv[1]) else: n = 3 # timestep dt = 0.01 # length of run tmax = 1.0 # cutoff rcut = 2.5 * SIG # potential shift shift = -0.016316891136 # total number of particles N = n * n * n # particle positions on a cubic lattice
MC_E = arrayE.flat MC_M = arrayM.flat MC_P = arrayP print "Finished metropolis calculation." MC_errmE = binningAll(arrayE) MC_errmM = binningAll(arrayM) MC_errmMabs = binningAll(abs(arrayM)) print "Finished error calculation." """ === PLOTS === """ p = Plotter(show=True, pdf=False, pgf=False, name="ising") p.new(name="Mean energy", xlabel="Temperature", ylabel="Energy") if useExact: p.plot(T, meanE, label="exact") if useMC: p.errorbar(T, MC_meanE, yerr=MC_errmE, label="metropolis") p.new(name="Mean magnetization", xlabel="Temperature", ylabel="Magnetization") if useExact: p.plot(T, meanM, label="exact") if useMC: p.errorbar(T, MC_meanM, yerr=MC_errmM, label="metropolis") p.new(name="Mean absolute magnetization", xlabel="Temperature", ylabel=r"\vertMagnetization\vert") if useExact:
params.Ising_J = 1 params.Ising_H = 0 params.MC_Seed = 42 params.MC_Sweeps = 10000 params.T_Start = 1 params.T_Stop = 5 params.T_StepSize = 0.1 Ising_L = [4,16,64] Binning_K = [50,200,800] useCache = True p = Plotter(show = True, pdf = False, pgf = False, latex=False, name='1simulation') # FUNCTIONS ############################################################################################### #==Exact=== itmp = np.arange(-1,4-1) def generateAllStates(n=4): nsqrt = n*n possibilities = np.mgrid[[slice(-1,3,2) for _ in range(nsqrt)]] # Vectorization makes the calculation fast as hell. configurations = possibilities.reshape(n,n,-1).T return configurations def calcEFromAll(configurations, J=params.Ising_J, H=params.Ising_H, n=4, i=itmp): E = -J*np.sum(np.sum(configurations*configurations[:,:,i]+configurations*configurations[:,i,:],axis=1),axis=1) E -= H*np.sum(np.sum(configurations,axis=1),axis=1) # Attention: Numpy doesn't like "E /= n**2". It applies integer division! return E
params.Ising_J = 1 params.Ising_H = 0 params.MC_Seed = 42 params.MC_Sweeps = 10000 params.T_Start = 1 params.T_Stop = 5 params.T_StepSize = 0.1 Ising_L = [4, 16, 64] Binning_K = [50, 200, 800] useCache = True p = Plotter(show=True, pdf=False, pgf=False, latex=False, name='1simulation') # FUNCTIONS ############################################################################################### #==Exact=== itmp = np.arange(-1, 4 - 1) def generateAllStates(n=4): nsqrt = n * n possibilities = np.mgrid[[ slice(-1, 3, 2) for _ in range(nsqrt) ]] # Vectorization makes the calculation fast as hell. configurations = possibilities.reshape(n, n, -1).T return configurations
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import os, pickle import numpy as np from libs.cython import set_globals, compute_forces, compute_distances, compute_energy, compute_pressure, rebuild_neighbor_lists from libs.simlib import Plotter from matplotlib import cm p = Plotter(show=True, pdf=False, pgf=False, name='ljsim') """==== DEFINITIONS ====""" # SYSTEM CONSTANTS # density density = 0.316 # timestep dt = 0.01 # max length of each run 800 tadd = 20.0 # max length of all runs tges = 1000.0 # number of particles per side for cubic setup n = 10 # Desired temperature {0.3, 1.0, 2.0} Tdes = 10.0 NEWRUN = True RANDOMPOSITION = True FORCECAPPING = True VELOCITYRESCALING = True
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division import numpy as np from libs.simlib import Plotter p = Plotter(show=True, pdf=False, pgf=False, name='1_potential') # ==== DEFINITIONS ==== EPS = 1 SIG = 1 NParticles = 1000 # ==== FUNCTIONS ==== def compute_lj_potential(rij, eps=EPS, sig=SIG): q = sig / np.linalg.norm(rij) return 4 * eps * (q**12 - q**6) def compute_lj_force(rij, eps=EPS, sig=SIG): norm = np.linalg.norm(rij) q = sig / norm return 4 * eps * (12 * q**11 - 6 * q**5) * q / norm**2 * rij # ==== CALCULATION ==== d = np.zeros((NParticles, 3)) d[:, 0] = np.linspace(0.85, 2.5, NParticles) potential = np.array(map(compute_lj_potential, d))
#!/usr/bin/python2 # -*- coding:utf-8 -*- from __future__ import division from numpy import * from libs.cython2.lj import * from libs.simlib import Plotter import sys p = Plotter(show=True, pdf=False, pgf=False, name="7_ljfluid_lists") # CONSTANTS # density density = 0.7 # number of particles per side if len(sys.argv) == 2 and sys.argv[1].isdigit(): n = int(sys.argv[1]) else: n = 5 # timestep dt = 0.01 # length of run tmax = 50.0 # cutoff length rcut = 2.5 # potential shift shift = -0.016316891136 # skin size skin = 0.3