- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforce_read.py
More file actions
Latest commit
91 lines (82 loc) · 2.63 KB
/
Copy pathforce_read.py
File metadata and controls
91 lines (82 loc) · 2.63 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/python
importos
importsys
importmath
importnumpy
defline2dict(line):
tokens_unprocessed=line.split()
tokens= [x.replace(")","").replace("(","") \
forxintokens_unprocessed]
floats= [float(x) forxintokens]
data_dict= {}
data_dict['time'] =floats[0]
force_dict= {}
force_dict['pressure'] =floats[1:4]
force_dict['viscous'] =floats[4:7]
force_dict['porous'] =floats[7:10]
moment_dict= {}
moment_dict['pressure'] =floats[10:13]
moment_dict['viscous'] =floats[13:16]
moment_dict['porous'] =floats[16:19]
data_dict['force'] =force_dict
data_dict['moment'] =moment_dict
returndata_dict
defget_forces_dict(forces_file):
# Returns a list of lists: [time, drag, lift, moment]
time= []
drag= []
lift= []
moment= []
withopen(forces_file,"r") asdatafile:
forlineindatafile:
ifline[0] =="#":
continue
data_dict=line2dict(line)
time+= [data_dict['time']]
drag+= [data_dict['force']['pressure'][0] + \
data_dict['force']['viscous'][0]]
lift+= [data_dict['force']['pressure'][1] + \
data_dict['force']['viscous'][1]]
moment+= [data_dict['moment']['pressure'][2] + \
data_dict['moment']['viscous'][2]]
datafile.close()
return [time, drag, lift, moment]
defget_line_from_file(file_path, line_number):
withopen(file_path, "r") astemp_file:
lines=temp_file.readlines()
temp_file.close()
returnlines[line_number]
defget_overall_chord():
# Searches file for the chord.
returnfloat(get_line_from_file("geometry.dat", 0))
defget_cell_depth():
# Searches file for the cell_depth.
returnfloat(get_line_from_file("geometry.dat", 1))
defget_V():
# Searches file for the velocity.
# We assume we are in the case directory.
velocity=0
withopen("0/include/initialConditions","r") asufile:
forlineinufile:
if"flowVelocity"inline:
vector=line[line.find("(")+1:line.find(")")]
velocity=float(vector.split()[0])
ufile.close()
returnvelocity
deftrailing_average(time, data, trailing_time):
end_time=time[-1]
start_time=end_time-trailing_time
diff=numpy.abs( [x-start_timeforxintime] )
start_index=diff.argmin()
subdata=data[start_index:len(data)]
returnsum(subdata) /len(subdata)
defget_latest_force_time(patch):
# Assumes in main case directory
# Assumes all folders are floating-point named
# Gets folder with highest floating-point value
folders= [ float(x) forxinos.listdir("postProcessing/"+patch) ]
folders.sort()
folder=folders[-1]
iffolder.is_integer():
folder=int(folder)
returnfolder