-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOFoam_plot_forces.py
More file actions
56 lines (48 loc) · 1.6 KB
/
OFoam_plot_forces.py
File metadata and controls
56 lines (48 loc) · 1.6 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
#!/usr/bin/python
import os
import sys
import math
ALYA_SCRPTS_DIR='~/1.post_process/0.alya_pv_scripts/'
file_path = os.getcwd()+'/'
forces_file = file_path+str(sys.argv[1])
if not os.path.isfile(forces_file):
print ("Forces file not found at "+forces_file)
print ("Be sure that the case has been run and you have the right directory!")
print ("Exiting.")
sys.exit()
def line2dict(line):
tokens_unprocessed = line.split()
tokens = [x.replace(")","").replace("(","") for x in tokens_unprocessed]
floats = [float(x) for x in tokens]
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
return data_dict
time = []
drag = []
lift = []
moment = []
with open(forces_file,"r") as datafile:
for line in datafile:
if line[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()
outputfile = open('forces.txt','w')
for i in range(0,len(time)):
outputfile.write(str(time[i])+' '+str(lift[i])+' '+str(drag[i])+' '+str(moment[i])+'\n')
outputfile.close()
os.system(ALYA_SCRPTS_DIR+"/plot_forces_script.sh")