forked from jaheyns/CfdOF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCfdRunnableFoam.py
146 lines (124 loc) · 6.33 KB
/
CfdRunnableFoam.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# ***************************************************************************
# * *
# * Copyright (c) 2015 - Qingfeng Xia <qingfeng.xia()eng.ox.ac.uk> *
# * Copyright (c) 2017 Alfred Bogaers (CSIR) <[email protected]> *
# * Copyright (c) 2017 Oliver Oxtoby (CSIR) <[email protected]> *
# * Copyright (c) 2017 Johan Heyns (CSIR) <[email protected]> *
# * Copyright (c) 2019 Oliver Oxtoby <[email protected]> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
from __future__ import print_function
import FreeCAD
import CfdTools
import CfdAnalysis
from PySide.QtCore import QObject, Signal
from CfdResidualPlot import ResidualPlot
from collections import OrderedDict
class CfdRunnable(QObject, object):
def __init__(self, analysis=None, solver=None):
super(CfdRunnable, self).__init__()
if analysis and isinstance(analysis.Proxy, CfdAnalysis._CfdAnalysis):
self.analysis = analysis
else:
if FreeCAD.GuiUp:
self.analysis = CfdTools.getActiveAnalysis()
self.solver = None
if solver:
self.solver = solver
else:
if analysis:
self.solver = CfdTools.getSolver(self.analysis)
if not self.solver:
FreeCAD.Console.printMessage("Solver object is missing from Analysis Object")
if self.analysis:
self.results_present = False
self.result_object = None
else:
raise Exception('No active analysis found')
def check_prerequisites(self):
return ""
class CfdRunnableFoam(CfdRunnable):
update_residual_signal = Signal(list, list, list, list)
def __init__(self, analysis=None, solver=None):
super(CfdRunnableFoam, self).__init__(analysis, solver)
self.initResiduals()
self.residualPlot = None
def check_prerequisites(self):
return ""
def initResiduals(self):
self.UxResiduals = []
self.UyResiduals = []
self.UzResiduals = []
self.pResiduals = []
self.rhoResiduals = []
self.EResiduals = []
self.kResiduals = []
self.omegaResiduals = []
self.niter = 0
def get_solver_cmd(self, case_dir):
self.initResiduals()
self.residualPlot = ResidualPlot()
# Environment is sourced in run script, so no need to include in run command
cmd = CfdTools.makeRunCommand('./Allrun', case_dir, source_env=False)
FreeCAD.Console.PrintMessage("Solver run command: " + ' '.join(cmd) + "\n")
return cmd
def getRunEnvironment(self):
return CfdTools.getRunEnvironment()
def process_output(self, text):
loglines = text.split('\n')
for line in loglines:
# print line,
split = line.split()
# Only store the first residual per timestep
if line.startswith(u"Time = "):
self.niter += 1
# print split
if "Ux," in split and self.niter-1 > len(self.UxResiduals):
self.UxResiduals.append(float(split[7].split(',')[0]))
if "Uy," in split and self.niter-1 > len(self.UyResiduals):
self.UyResiduals.append(float(split[7].split(',')[0]))
if "Uz," in split and self.niter-1 > len(self.UzResiduals):
self.UzResiduals.append(float(split[7].split(',')[0]))
if "p," in split and self.niter-1 > len(self.pResiduals):
self.pResiduals.append(float(split[7].split(',')[0]))
if "p_rgh," in split and self.niter-1 > len(self.pResiduals):
self.pResiduals.append(float(split[7].split(',')[0]))
if "h," in split and self.niter-1 > len(self.EResiduals):
self.EResiduals.append(float(split[7].split(',')[0]))
# HiSA coupled residuals
if "Residual:" in split and self.niter-1 > len(self.rhoResiduals):
self.rhoResiduals.append(float(split[4]))
self.UxResiduals.append(float(split[5].lstrip('(')))
self.UyResiduals.append(float(split[6]))
self.UzResiduals.append(float(split[7].rstrip(')')))
self.EResiduals.append(float(split[8]))
if "k," in split and self.niter-1 > len(self.kResiduals):
self.kResiduals.append(float(split[7].split(',')[0]))
if "omega," in split and self.niter-1 > len(self.omegaResiduals):
self.omegaResiduals.append(float(split[7].split(',')[0]))
if self.niter > 1:
self.residualPlot.updateResiduals(OrderedDict([
('$\\rho$', self.rhoResiduals),
('$U_x$', self.UxResiduals),
('$U_y$', self.UyResiduals),
('$U_z$', self.UzResiduals),
('$p$', self.pResiduals),
('$E$', self.EResiduals),
('$k$', self.kResiduals),
('$\\omega$', self.omegaResiduals)]))