-
Notifications
You must be signed in to change notification settings - Fork 0
/
SU2Writer.py
70 lines (60 loc) · 2.4 KB
/
SU2Writer.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
import numpy as np
import os
import re
class writeBFMinput:
n_sec = None
n_points = None
n_rows = 0
def __init__(self, Meangen):
self.M = Meangen
self.dir = os.getcwd()
self.BFMfile = open(self.dir + "/BFM_stage_input", "w+")
self.getBFMinputs()
self.BFMfile.write("%i\t%i\t%i\n" % (self.n_rows, self.n_sec, self.n_points))
self.writeInputFile()
self.BFMfile.close()
def getBFMinputs(self):
for i in range(self.M.n_stage):
for j in [1, 2]:
with open(self.dir + "/Stage_"+str(i+1)+"/Bladerow_"+str(j)+"/output/mesh_files/BFM_input", "r") as file:
first_line = file.readline().split('\t', 2)
first_line[-1] = first_line[-1].strip()
self.n_sec = int(first_line[0])
self.n_points = int(first_line[1])
self.n_rows += 1
file.close()
def writeInputFile(self):
for i in range(self.M.n_stage):
for j in [1, 2]:
with open(self.dir + "/Stage_"+str(i+1)+"/Bladerow_"+str(j)+"/output/mesh_files/BFM_input", "r") as file:
lines = file.readlines()[1:]
if self.M.machineType == 'C':
rotFac = [1, 0]
blades = [self.M.N_b_R[i], self.M.N_b_S[i]]
else:
rotFac = [0, 1]
blades = [self.M.N_b_S[i], self.M.N_b_R[i]]
for line in lines:
self.BFMfile.write(line.strip()+"\t"+str(rotFac[j-1])+"\t"+str(int(blades[j-1]))+"\n")
#self.BFMfile.writelines(lines)
file.close()
def ReadUserInput(name):
IN = {}
infile = open(name, 'r')
for line in infile:
words = re.split('=| |\n|,|[|]', line)
if not any(words[0] in s for s in ['\n', '%', ' ', '#']):
words = list(filter(None, words))
for i in range(0, len(words)):
try:
words[i] = float(words[i])
except:
words[i] = words[i]
if len(words[1::1]) == 1 and isinstance(words[1], float):
IN[words[0]] = [words[1]]
elif len(words[1::1]) == 1 and isinstance(words[1], str):
IN[words[0]] = words[1]
else:
IN[words[0]] = words[1::1]
IN['Config_Path'] = name
return IN