-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoftrans.py
94 lines (77 loc) · 3.21 KB
/
oftrans.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
from pathlib import Path
import cantera as ct
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
class OFTrans:
def __init__(self, mech_file, low=300, high=3000, n_points=200):
# own gas
self.gas = ct.Solution(mech_file)
self.TList = np.linspace(low, high, n_points)
self.species = self.gas.species_names
self.sutherland_params = {}
def getMu4Species(self, species_name, T):
self.gas.TPY = T, ct.one_atm, species_name + ":1.0"
return self.gas.viscosity
def getMuList4Species(self, species_name):
muList = np.zeros_like(self.TList, dtype=np.float64)
for i, T in enumerate(self.TList):
muList[i] = self.getMu4Species(species_name, T)
return muList
def getSutherlandParams(self):
for sp in self.species:
self.sutherland_params[sp] = self.fit(sp)
def fit(self, species_name):
muList = np.zeros_like(self.TList, dtype=np.float64)
muList = self.getMuList4Species(species_name)
params, cov = curve_fit(self.sutherland, self.TList, muList, p0 = [1.512e-6, 120.] )
return params[0], params[1]
def sutherland(self, T, As, Ts):
return As * T ** 1.5 / (T + Ts)
def ofheader(self, version):
header = (
"/*--------------------------------*- C++ -*----------------------------------*\\\n"
"| ========= |\n"
"| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox\n"
"| \\ / O peration | Website: https://openfoam.org\n"
"| \\ / A nd | Version: " + str(version)+"\n"
"| \\/ M anipulation |\n"
"\*---------------------------------------------------------------------------*/\n"
"FoamFile\n"
"{\n"
"\tversion 2.0;\n"
"\tformat ascii;\n"
"\tclass dictionary;\n"
"\tlocation \"chemkin\";\n"
"\tobject transportProperties;\n"
"}\n"
"// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n"
)
return header
def writeEntry(self, name, As,Ts):
entry = (
"\"" + name + "\"\n"
"{\n"
" transport\n"
" {\n"
" As " + str(As) + ";\n"
" Ts " + str(Ts) + ";\n"
" }\n"
"}\n"
)
return entry
def writeDefaultEntry(self):
return self.writeEntry(".*", 1.512e-6, 120.)
def __call__(self, version=7):
# print(self.ofheader(7))
# print(self.writeDefaultEntry())
# for sp in self.species:
# As, Ts = self.sutherland_params[sp]
# print(self.writeEntry(sp, As, Ts))
# write to a file
with open("./transportProperties", "w") as f:
f.write(self.ofheader(version))
f.write(self.writeDefaultEntry())
for sp in self.species:
As, Ts = self.sutherland_params[sp]
f.write(self.writeEntry(sp, As, Ts))