-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPressureVariation.py
More file actions
71 lines (63 loc) · 2.82 KB
/
MainPressureVariation.py
File metadata and controls
71 lines (63 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#Class to get the Volume as a function of the Pressure of the system
from InputData import *
from LatticeHandler import *
from Lattice import *
import numpy as np
import os
#Number of steps to get record system state
meanSteps=100
#Number of measurements to do the mean
valuesForMean=100
#Simulation pressures
iniP=int(1e5) #Initial pressure
finP=int(5.01e8) #Final pressure
pressureIncrement=int(5e7) #Increment of pressure in each simulation
#simulation steps
mcSteps=10000000 #MonteCarlo steps during measurement phase
initialEq=30000000 #Steps to reach the equilibrium before the simulation
Eq=10000000 #Steps to reach equilibrium after changing the temperature of the system
#Temperature (S.i.)
T=250
#Free volumes (Random units)
fbv=0.2 #Free volume of + state
fsv=1.0 #Free volume of - state
#Volumes (S.I)
Vb=4.151444703e-29 #V+
Vs=3.321078553e-29 #V-
#Energies (S.I.)
Eb=-1.660577881e-21 #E+
Es=0 #E-
#Lattice length (Unit cells)
l=50
inputdata=InputData(50, T, mcSteps, Eq,
Vb, Vs, fbv, fsv, Eb, Es, iniP) #Creating Inputdata object containing the initial simulation parameters
lattice=Lattice(inputdata) #Creating Lattice object using the simulation parameters contained in the Inputdata object
#Initial equilibrium steps
print("Initial thermalization")
for i in range(0, initialEq):
if math.fmod(i/initialEq*100,1.0)==0: #Checking progress of the equilibrium steps
print(str(i/(initialEq)*100)+"%")
LatticeHandler().changeVol(lattice, lattice.getInputData()) #Attempting to change state of one cell
#Removing histogram data file to create a new one
if os.path.isfile("Neighbor_Histogram"):
os.remove("Neighbor_Histogram")
#Repeating simulation for the specified temperatures
for P in range(iniP, finP+pressureIncrement, pressureIncrement):
#Creation of the inputData with the desired parameters(L, T, MCs, Therm, Vb, Vs, FVb, FVs, Eb, Es, P)
print(P)
#Changing pressure of the simulation
lattice.changeInputData(T, P) #Changing simulation parameters
print("Thermalization")
#Setting new thermalization for new parameters
for i in range(0, inputdata.getEq()):
if math.fmod(i/Eq*100,1.0)==0: #Checking progress of the equilibrium steps
print(str(i/(Eq)*100)+"%")
LatticeHandler().changeVol(lattice, lattice.getInputData()) #Attempting to change state of one cell
lattice.resetHistogram()
#Getting measurements of the evolution of volume, intermolecular energy and enthalpy
measurements=LatticeHandler().getSystemEvolution(lattice, lattice.getInputData(), meanSteps)
#Renaming data files
newFileName="Measurements_P"+str(P)
oldFileName="Measurements_T"+str(T)
os.rename(oldFileName, newFileName)
lattice.saveHistogram() #Saving neighbor histogram