-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_TGA.py
109 lines (82 loc) · 3.72 KB
/
run_TGA.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
import os
import time
import numpy as np
import TGA
start = time.time()
path_input = './input'
path_output = './output_TGA'
#---------------- Automatic mechanism reader-----------------------------------------------------------
#--------------- (to be removed once kinetics and evaporation are optimized)---------------------------
#------------------------------------------------------------------------------------------------------
with open(os.path.join(path_input,'nitramine-liquid-phase-mechanism-input.txt'),'r') as File:
lines = File.readlines()
flag1 = 0
species_list = []
reactions_list = []
for line in lines:
if line.startswith('REACTIONS'):
flag1 = 1
if (flag1 == 1 and (line.strip() not in ['!','REACTIONS','END'])) and not line.startswith('!'):
reactions_list.append(line)
reactants,products = line.split(' ')[0].split('=')
species = reactants.split('+') + products.split('+')
species_list.extend(species)
seen = set()
seen_add = seen.add
species_list = [x for x in species_list if not(x in seen or seen_add(x))]
with open(os.path.join(path_input,'nitramine-liquid-phase-mechanism.txt'),'w') as File2:
File2.writelines('ELEMENTS\nC\nH\nN\nO\nAr\nEND\n')
File2.writelines('SPECIES\n')
for species in species_list:
File2.writelines(species + '\n')
File2.writelines('N2\n')
File2.writelines('END\n')
File2.writelines('THERMO\n')
with open(os.path.join(path_input,'thermo-data.txt'),'r') as File:
lines = File.readlines()
for species in species_list:
for i in range(len(lines)):
if lines[i].split()[0] == species and lines[i].split()[0] != 'N2':
with open(os.path.join(path_input,'nitramine-liquid-phase-mechanism.txt'),'a') as File2:
File2.writelines(lines[i:i+4])
if lines[i].split()[0] == 'N2':
N2_lines = lines[i:i+4]
with open(os.path.join(path_input,'nitramine-liquid-phase-mechanism.txt'),'a') as File2:
File2.writelines(N2_lines)
with open(os.path.join(path_input,'nitramine-liquid-phase-mechanism.txt'),'a') as File2:
File2.writelines('END\n')
File2.writelines('REACTIONS\n')
File2.writelines(reactions_list)
File2.writelines('END')
#------------------------------------------------------------------------------
#---------------- Input parameters---------------------------------------------
parameters = {
"Reactant":'HMX',
"liquid-phase-mechanism":'nitramine-liquid-phase-mechanism.txt',
"species_radius":'log-file-data-minima.txt',
"evaporation_parameters":'evaporation-parameters.txt',
"evaporation_global":1,
"global_AnE":[6.38e18,0,51.3e3],
"Tinit":275.00,
"Tend":310.00,
"Heating_rate":15.0,
"dt":0.001,
"Mc0":1.492,
"Gas-cell-Pressure(Pa)":101325.0,
"Gas-cell-Volume(m3)":8.7e-6,
"Gas-cell-Temperature(K)":473.15,
"Purge-gas-flow-rate(g/s)":70.0*(1.13*0.001/60.0),
"T_onset": 283.0,
"T1sin":275.0,
"T2sin":290.0,
"dTmax":0.0,
"path_input":path_input,
"path_output":path_output,
"loglevel":1
}
#------------------------------------------------------------------------------
TGA.main(parameters)
end = time.time()
import plots_TGA
import plots_TGA_liquid
print('Wall time = %f'%(end-start))