forked from harpaj/acc14
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
72 lines (59 loc) · 2.05 KB
/
tasks.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
from celery import Celery
from csv import DictReader
import psutil
import subprocess
celery = Celery('tasks')
celery.config_from_object('celeryconfig')
celery.conf.task_serializer = 'json'
celery.conf.task_compression = 'gzip'
@celery.task()
def one_angle(
angle, naca1, naca2, naca3, naca4, nodes, refinements,
samples, viscosity, speed, time
):
filename = angle + '_' + nodes + '_' + naca1 + naca2 + naca3 + naca4 + '.geo'
# create geo file
with open("results/geo/" + filename, 'w') as geo_fh:
subprocess.run(
[
"/home/ubuntu/acc14/bin/cloudnaca/naca2gmsh_geo.py",
angle, naca1, naca2, naca3, naca4, nodes
],
stdout=geo_fh
)
# create mesh file
msh_name = filename[:-3] + "msh"
subprocess.run([
"gmsh", "-v", '0', '-nopopup', '-2', '-o', "results/msh/"+msh_name, "results/geo/"+filename
])
# refine mesh file
for _ in range(int(refinements)):
subprocess.run(["gmsh", "-refine", "-v", "0", "results/msh/"+msh_name])
# convert mesh file to xml
xml_name = filename[:-3] + "xml"
subprocess.run([
"dolfin-convert", "-i", "gmsh", "-o", "xml",
"results/msh/" + msh_name, "results/xml/" + xml_name
])
# run airfoil on xml file
subprocess.run(
[
"/home/ubuntu/acc14/bin/airfoil/airfoil",
samples, viscosity, speed, time, "../../results/xml/" + xml_name
],
cwd="/home/ubuntu/acc14/bin/airfoil"
)
result_name = '_'.join([filename[:-4], samples, viscosity, speed, time, 'drag_ligt.m'])
# read in and return result
result = []
with open("/home/ubuntu/acc14/bin/airfoil/results/" + result_name) as f:
reader = DictReader(f, delimiter='\t')
for row in reader:
result.append(row)
return angle, result
'''@app.on_after_configure.connect
def config_periodic_cpu_monitor(sender, **kwargs):
sender.add_periodic_task(60.0, cpu_monitor.s(), expires=10)'''
@app.task
def cpu_monitor():
return psutil.cpu_percent()