forked from DarkOfTheMoon/CfdOF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_TaskPanelCfdInitialiseInternalFlowField.py
More file actions
178 lines (151 loc) · 8.64 KB
/
_TaskPanelCfdInitialiseInternalFlowField.py
File metadata and controls
178 lines (151 loc) · 8.64 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# ***************************************************************************
# * *
# * Copyright (c) 2013-2015 - Juergen Riegel <FreeCAD@juergen-riegel.net> *
# * Copyright (c) 2017 Alfred Bogaers (CSIR) <abogaers@csir.co.za> *
# * Copyright (c) 2017 Oliver Oxtoby (CSIR) <ooxtoby@csir.co.za> *
# * Copyright (c) 2017 Johan Heyns (CSIR) <jheyns@csir.co.za> *
# * Copyright (c) 2019 Oliver Oxtoby <oliveroxtoby@gmail.com> *
# * *
# * 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 *
# * *
# ***************************************************************************
import FreeCAD
import os
import os.path
from CfdTools import getQuantity, setQuantity
if FreeCAD.GuiUp:
import FreeCADGui
class _TaskPanelCfdInitialiseInternalFlowField:
def __init__(self, obj, physics_model, boundaries, material_objs):
FreeCADGui.Selection.clearSelection()
self.obj = obj
self.physicsModel = physics_model
self.boundaries = boundaries
self.material_objs = material_objs
self.form = FreeCADGui.PySideUic.loadUi(os.path.join(os.path.dirname(__file__),
"TaskPanelCfdInitialiseInternalField.ui"))
self.form.basicPropertiesFrame.setVisible(False)
self.form.radioButtonPotentialFlow.toggled.connect(self.radioUPChanged)
self.form.radioButtonUseInletValuesUP.toggled.connect(self.radioUPChanged)
self.form.turbulencePropertiesFrame.setVisible(False)
self.form.checkUseInletValuesThermal.toggled.connect(self.updateUi)
self.form.checkUseInletValues.toggled.connect(self.updateUi)
self.form.comboFluid.currentIndexChanged.connect(self.comboFluidChanged)
self.form.inputVolumeFraction.valueChanged.connect(self.inputVolumeFractionChanged)
self.form.radioButtonPotentialFlow.setToolTip(
"Initialise the velocity field using an incompressible, potential "
"(irrotational) flow assumption.")
self.alphas = {}
self.load()
def load(self):
potential_foam = self.obj.PotentialFoam
use_inlet_UP = self.obj.UseInletUPValues
if potential_foam:
self.form.radioButtonPotentialFlow.toggle()
elif use_inlet_UP:
self.form.radioButtonUseInletValuesUP.toggle()
else:
self.form.radioButtonSpecifyValues.toggle()
setQuantity(self.form.Ux, self.obj.Ux)
setQuantity(self.form.Uy, self.obj.Uy)
setQuantity(self.form.Uz, self.obj.Uz)
setQuantity(self.form.pressure, self.obj.Pressure)
# Add volume fraction fields
self.alphas = self.obj.VolumeFractions
if self.physicsModel.Phase != 'Single':
mat_names = []
for m in self.material_objs:
mat_names.append(m.Label)
self.form.comboFluid.clear()
self.form.comboFluid.addItems(mat_names[:-1])
self.comboFluidChanged(self.form.comboFluid.currentIndex())
else:
self.form.comboFluid.clear()
use_inlet_turb = self.obj.UseInletTurbulenceValues
self.form.checkUseInletValues.setChecked(use_inlet_turb)
setQuantity(self.form.inputk, self.obj.k)
setQuantity(self.form.inputOmega, self.obj.omega)
use_inlet_temp = self.obj.UseInletTemperatureValues
self.form.checkUseInletValuesThermal.setChecked(use_inlet_temp)
setQuantity(self.form.inputTemperature, self.obj.Temperature)
# Add any inlets to the list
for b in self.boundaries:
if b.BoundaryType in ['inlet', 'open']:
self.form.comboInlets.addItem(b.Label, b.Name)
if self.obj.Inlet is not None:
self.form.comboInlets.setCurrentIndex(self.form.comboInlets.findData(self.obj.Inlet.Name))
self.updateUi()
def updateUi(self):
potential_foam = self.form.radioButtonPotentialFlow.isChecked()
use_inlet_UP = self.form.radioButtonUseInletValuesUP.isChecked()
use_inlet_turb = self.form.checkUseInletValues.isChecked()
use_inlet_temp = self.form.checkUseInletValuesThermal.isChecked()
self.form.basicPropertiesFrame.setVisible(not (potential_foam or use_inlet_UP))
if self.physicsModel.Phase != 'Single':
self.form.volumeFractionsFrame.setVisible(True)
else:
self.form.volumeFractionsFrame.setVisible(False)
if self.physicsModel.Turbulence in ['RANS', 'LES']:
self.form.turbulencePropertiesFrame.setVisible(True)
else:
self.form.turbulencePropertiesFrame.setVisible(False)
if self.physicsModel.Thermal == 'Energy':
self.form.energyFrame.setVisible(not use_inlet_temp)
else:
self.form.thermalPropertiesFrame.setVisible(False)
self.form.frameInlets.setVisible(
(use_inlet_UP or use_inlet_turb or use_inlet_temp) and self.form.comboInlets.count() > 1)
self.form.kEpsilonFrame.setVisible(False)
self.form.kOmegaSSTFrame.setVisible(False)
self.form.SpalartAlmerasFrame.setVisible(False)
if self.physicsModel.TurbulenceModel == 'kOmegaSST':
self.form.kOmegaSSTFrame.setVisible(not use_inlet_turb)
def radioUPChanged(self):
self.updateUi()
def getMaterialName(self, index):
return self.material_objs[index].Label
def comboFluidChanged(self, index):
setQuantity(self.form.inputVolumeFraction, self.alphas.get(self.getMaterialName(index), '0.0'))
def inputVolumeFractionChanged(self):
self.alphas[self.form.comboFluid.currentText()] = getQuantity(self.form.inputVolumeFraction)
def accept(self):
doc = FreeCADGui.getDocument(self.obj.Document)
doc.resetEdit()
FreeCADGui.doCommand("\ninit = FreeCAD.ActiveDocument.{}".format(self.obj.Name))
FreeCADGui.doCommand("init.PotentialFoam = {}".format(self.form.radioButtonPotentialFlow.isChecked()))
FreeCADGui.doCommand("init.UseInletUPValues = {}".format(self.form.radioButtonUseInletValuesUP.isChecked()))
FreeCADGui.doCommand("init.Ux = '{}'".format(getQuantity(self.form.Ux)))
FreeCADGui.doCommand("init.Uy = '{}'".format(getQuantity(self.form.Uy)))
FreeCADGui.doCommand("init.Uz = '{}'".format(getQuantity(self.form.Uz)))
FreeCADGui.doCommand("init.Pressure = '{}'".format(getQuantity(self.form.pressure)))
FreeCADGui.doCommand("init.VolumeFractions = {}".format(self.alphas))
FreeCADGui.doCommand("init.UseInletTemperatureValues "
"= {}".format(self.form.checkUseInletValuesThermal.isChecked()))
FreeCADGui.doCommand("init.Temperature "
"= '{}'".format(getQuantity(self.form.inputTemperature)))
FreeCADGui.doCommand("init.UseInletTurbulenceValues "
"= {}".format(self.form.checkUseInletValues.isChecked()))
FreeCADGui.doCommand("init.omega = '{}'".format(getQuantity(self.form.inputOmega)))
FreeCADGui.doCommand("init.k = '{}'".format(getQuantity(self.form.inputk)))
inlet = self.form.comboInlets.currentData()
if inlet:
FreeCADGui.doCommand("init.Inlet = FreeCAD.ActiveDocument.{}".format(inlet))
else:
FreeCADGui.doCommand("init.Inlet = None")
def reject(self):
doc = FreeCADGui.getDocument(self.obj.Document)
doc.resetEdit()