-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRateConstantsFits.py
173 lines (134 loc) · 7.89 KB
/
RateConstantsFits.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import warnings
warnings.filterwarnings(action='ignore')
import os
import shutil
import numpy as np
import yaml
import time
import colorama
from CodeFunctions import MessDataExtraction, WriteChemkinFile
colorama.init(autoreset = True)
print(colorama.Fore.BLUE + colorama.Style.BRIGHT+ """
====================================
|| Title: Arrheinus Fit Generator ||
|| Author: Pray Shah ||
|| EMAIL: [email protected] ||
====================================
""")
base_dir = os.getcwd()
if os.path.exists("Plots"):
shutil.rmtree("Plots")
os.mkdir("Plots")
else:
os.mkdir("Plots")
FileName = input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Enter File Name with extension: ")
filePath = os.path.join(base_dir, FileName)
while True:
if input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "\nDo you want to input from 'UserInput.yaml' file? (y/n): ")[0].lower() == 'y':
UserInput = yaml.load(open('UserInput.yaml', 'r'), Loader=yaml.Loader)
TempsArg = np.array(UserInput['Temperature'])
Temps = np.arange(TempsArg[0], TempsArg[1] + TempsArg[2], TempsArg[2])
Pressures = np.array(UserInput['Pressure'])
ChemkinNameDict = UserInput['Species']
MappedKeyword = list(UserInput['Species'].keys())
else:
print("Need to specify temperautre start, stop and step size:")
Temps = np.arange(int(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Please enter start temperature: ")),
int(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Please enter end temperature: ")) + 1,
int(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Please enter step size: ")))
print("\nEnter the pressures for which the arrhenius fits will be generated")
print(colorama.Fore.YELLOW + colorama.Style.BRIGHT + "Specify all pressures in one line and use ',' in between pressures. Do not use any other delimiter!\n")
Pressures = np.array(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Enter Pressures: ").replace(" ","").split(','))
print(colorama.Fore.YELLOW + colorama.Style.BRIGHT + "Enter one at a time!")
check = 'y'
MappedKeyword = []
SpeciesName = []
while check == 'y':
MappedKeyword.append(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Enter the keyword: "))
SpeciesName.append(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Enter the species name: "))
check = input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Have more to map? (y/n): " )[0].lower()
ChemkinNameDict = dict(zip(MappedKeyword, SpeciesName))
print(colorama.Fore.YELLOW + colorama.Style.NORMAL + f"\nTemperatures: {Temps}")
if len(Pressures) == 0:
print(colorama.Fore.YELLOW + colorama.Style.NORMAL + f"\nPressures: {Pressures}")
print(colorama.Fore.RED + colorama.Style.NORMAL + f"\nNo Pressures Found! Code will only print High Pressure Rates!")
else:
print(colorama.Fore.YELLOW + colorama.Style.NORMAL + f"\nPressures: {Pressures}")
print(colorama.Fore.YELLOW + colorama.Style.NORMAL + '\nSpecies Mapped:')
for key, value in ChemkinNameDict.items():
print(colorama.Fore.YELLOW + f'{key} : {value}')
check = input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "\nIs the order correct? (y/n): ")[0].lower()
if check == 'y':
break
else:
print(colorama.Fore.RED + "Re-Enter the species map!")
MappedKeyword = np.array(MappedKeyword)
Parent_HighP, Parent_rates = MessDataExtraction.messExtract(filePath, Temps, Pressures, MappedKeyword)
Parent_HighP = np.array(Parent_HighP)
Parent_rates = np.array(Parent_rates)
print(colorama.Fore.YELLOW + colorama.Style.BRIGHT + "\nData Extracted for requested pressures and temperatures successfully!\n")
# Weighted Rates
WeightedRatesUserInp = input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Do you want to weight the rates for a specific temperature range? (y/n): ").lower()
if WeightedRatesUserInp == 'y':
WeightStartEndTemps = np.array([int(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Enter the inital temperature: ")), int(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Enter the final temperature: "))])
Repitition = int(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Enter the repitions you want of the rates for give range of temperature: ")) - 1
StartIndex = np.where(WeightStartEndTemps[0] == Parent_HighP[0][0])[0][0]
EndIndex = np.where(WeightStartEndTemps[1] == Parent_HighP[0][0])[0][0] + 1
SubArray = Parent_HighP[:,:,StartIndex:EndIndex]
SubArray = np.repeat(SubArray, Repitition, axis=2)
Parent_HighP = np.concatenate((Parent_HighP, SubArray), axis = 2)
Parent_HighP = Parent_HighP[:,:,Parent_HighP[0][0].argsort()]
if Parent_rates != []:
SubArray = Parent_rates[:,:,StartIndex:EndIndex]
SubArray = np.repeat(SubArray, Repitition, axis=2)
Parent_rates = np.concatenate((Parent_rates, SubArray), axis = 2)
Parent_rates = Parent_rates[:,:,Parent_rates[0][0].argsort()]
else:
WeightStartEndTemps = []
# Tolerance
Tolerance = int(input("\nPlease enter the error tolerance in percentage: " ))
# Arrhenius Fit
file = [open("Arrhenius_Fit_Chemkin_Format_ModArr.inp","w"), open("Arrhenius_Fit_Chemkin_Format_DoubleArr.inp","w"), open("Arrhenius_Fit_Chemkin_Format.inp", "w")]
while True:
Index = 0
ReactantKeyword = ''
ReactantKeyword = input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "\nEnter the reactant keyword for which you want rates (e.g: W1, P1 or P6): ")
if ReactantKeyword not in MappedKeyword:
print(colorama.Fore.RED + colorama.Style.BRIGHT + "\nError while entering Reactant keyword!")
print(colorama.Fore.RED + colorama.Style.BRIGHT + "Keyword not found!")
print(colorama.Fore.RED + colorama.Style.BRIGHT + "Re-Enter the keyword")
else:
Bimolec = False
if '+' in ChemkinNameDict[ReactantKeyword]:
print(colorama.Fore.RED + colorama.Style.BRIGHT + "\nReaction is Bimolecular")
Bimolec = True
else:
print(colorama.Fore.RED + colorama.Style.BRIGHT + "\nReaction is Unimolecular")
Bimolec = False
RatePlotDict = {}
Index = np.where(MappedKeyword == ReactantKeyword)[0][0]
MappedForPlot = np.delete(MappedKeyword, [Index])
for i in range(0, len(MappedForPlot)):
RatePlotDict[i + 1] = f'{ChemkinNameDict[ReactantKeyword]} = {ChemkinNameDict[MappedForPlot[i]]}'
print(colorama.Fore.YELLOW + "\nMapped dictionary generated:")
for key, value in RatePlotDict.items():
print(colorama.Fore.BLUE + colorama.Style.BRIGHT + f"{key} : " + colorama.Fore.YELLOW + f"{value}")
print(colorama.Fore.YELLOW + colorama.Style.BRIGHT + "\nSpecify all keys in one line and use ',' in between keys. Do not use any other delimiter!\n")
SpeciesIndex = np.array(input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "Enter the key number from the above dictionary for which you want Arrhenius expression: " ).replace(" ","").split(',')).astype(int)
print(colorama.Fore.BLUE + colorama.Style.BRIGHT + """\n
===========
||Writing||
===========
""")
StartTime = time.time()
WriteChemkinFile.WriteFile(file, RatePlotDict, Index, Pressures, SpeciesIndex, Parent_HighP, Parent_rates, Tolerance, Bimolec, WeightStartEndTemps)
EndTime = time.time()
print(colorama.Back.GREEN + f"\nWrite Time: {EndTime - StartTime} seconds")
if input(colorama.Fore.GREEN + colorama.Style.BRIGHT + "\nDo you want to print any more rates? (y/n): ")[0].lower() == 'y':
continue
else:
break
file[0].close()
file[1].close()
file[2].close()
print(colorama.Fore.BLUE + colorama.Style.BRIGHT + "\nArrhenius Expressions Printed!!\n")