forked from jaheyns/CfdOF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCfdZone.py
269 lines (229 loc) · 12.6 KB
/
CfdZone.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# ***************************************************************************
# * *
# * Copyright (c) 2017 Oliver Oxtoby (CSIR) <[email protected]> *
# * Copyright (c) 2017 Alfred Bogaers (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 *
# * *
# ***************************************************************************
import FreeCAD
import Part
import CfdTools
from CfdTools import addObjectProperty
import os
import os.path
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore
# Constants
POROUS_CORRELATIONS = ['DarcyForchheimer', 'Jakob']
POROUS_CORRELATION_NAMES = ["Darcy-Forchheimer coefficients", "Staggered tube bundle (Jakob)"]
POROUS_CORRELATION_TIPS = ["Specify viscous and inertial drag tensors by giving their principal components and directions (these will be made orthogonal)",
"Specify geometry of parallel tube bundle with staggered layers."]
ASPECT_RATIOS = ["1.0", "1.73", "1.0"]
ASPECT_RATIO_NAMES = ["User defined", "Equilateral", "Rotated square"]
ASPECT_RATIO_TIPS = ["", "Equilateral triangles pointing perpendicular to spacing direction", "45 degree angles; isotropic"]
def makeCfdPorousZone(name='PorousZone'):
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", name)
_CfdZone(obj)
if FreeCAD.GuiUp:
_ViewProviderCfdZone(obj.ViewObject)
return obj
def makeCfdInitialisationZone(name='InitialisationZone'):
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", name)
_CfdZone(obj)
if FreeCAD.GuiUp:
_ViewProviderCfdZone(obj.ViewObject)
return obj
class _CommandCfdPorousZone:
def GetResources(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "porous.png")
return {'Pixmap': icon_path,
'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_PorousZone", "Porous zone"),
'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_PorousZone", "Select and create a porous zone")}
def IsActive(self):
return CfdTools.getActiveAnalysis() is not None
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Select and create a porous zone")
FreeCADGui.doCommand("")
FreeCADGui.addModule("CfdZone")
FreeCADGui.addModule("CfdTools")
FreeCADGui.doCommand("CfdTools.getActiveAnalysis().addObject(CfdZone.makeCfdPorousZone())")
FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Cfd_PorousZone', _CommandCfdPorousZone())
class _CommandCfdInitialisationZone:
def GetResources(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "alpha.svg")
return {'Pixmap': icon_path,
'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_InitialisationZone", "Initialisation zone"),
'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_InitialisationZone",
"Select and create an initialisation zone")}
def IsActive(self):
return CfdTools.getActiveAnalysis() is not None
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Select and create an initialisation zone")
FreeCADGui.doCommand("")
FreeCADGui.addModule("CfdZone")
FreeCADGui.addModule("CfdTools")
FreeCADGui.doCommand(
"CfdTools.getActiveAnalysis().addObject(CfdZone.makeCfdInitialisationZone())")
FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Cfd_InitialisationZone', _CommandCfdInitialisationZone())
class _CfdZone:
def __init__(self, obj):
obj.Proxy = self
self.Type = 'Zone'
self.initProperties(obj)
def initProperties(self, obj):
addObjectProperty(obj, 'References', [], "App::PropertyPythonObject")
addObjectProperty(obj, 'LinkedObjects', [], 'App::PropertyLinkList', "", "Linked objects")
if obj.Name.startswith('PorousZone'):
if addObjectProperty(obj, 'PorousCorrelation', POROUS_CORRELATIONS, "App::PropertyEnumeration",
"Porous zone", "Porous drag model"):
obj.PorousCorrelation = 'DarcyForchheimer'
addObjectProperty(obj, 'D1', '0 1/m^2', "App::PropertyQuantity",
"Darcy-Forchheimer", "Darcy coefficient (direction 1)")
addObjectProperty(obj, 'D2', '0 1/m^2', "App::PropertyQuantity",
"Darcy-Forchheimer", "Darcy coefficient (direction 2)")
addObjectProperty(obj, 'D3', '0 1/m^2', "App::PropertyQuantity",
"Darcy-Forchheimer", "Darcy coefficient (direction 3)")
addObjectProperty(obj, 'F1', '0 1/m', "App::PropertyQuantity",
"Darcy-Forchheimer", "Forchheimer coefficient (direction 1)")
addObjectProperty(obj, 'F2', '0 1/m', "App::PropertyQuantity",
"Darcy-Forchheimer", "Forchheimer coefficient (direction 2)")
addObjectProperty(obj, 'F3', '0 1/m', "App::PropertyQuantity",
"Darcy-Forchheimer", "Forchheimer coefficient (direction 3)")
addObjectProperty(obj, 'e1', FreeCAD.Vector(1, 0, 0), "App::PropertyVector",
"Darcy-Forchheimer", "Principal direction 1")
addObjectProperty(obj, 'e2', FreeCAD.Vector(0, 1, 0), "App::PropertyVector",
"Darcy-Forchheimer", "Principal direction 2")
addObjectProperty(obj, 'e3', FreeCAD.Vector(0, 0, 1), "App::PropertyVector",
"Darcy-Forchheimer", "Principal direction 3")
addObjectProperty(obj, 'OuterDiameter', '0 m', "App::PropertyLength",
"Jakob", "Tube diameter")
addObjectProperty(obj, 'TubeAxis', FreeCAD.Vector(0, 0, 1), "App::PropertyVector",
"Jakob", "Direction parallel to tubes")
addObjectProperty(obj, 'TubeSpacing', '0 m', "App::PropertyLength",
"Jakob", "Spacing between tube layers")
addObjectProperty(obj, 'SpacingDirection', FreeCAD.Vector(1, 0, 0), "App::PropertyVector",
"Jakob", "Direction normal to tube layers")
addObjectProperty(obj, 'AspectRatio', '1.73', "App::PropertyQuantity",
"Jakob", "Tube spacing aspect ratio (layer-to-layer : tubes in layer)")
addObjectProperty(obj, 'VelocityEstimate', '0 m/s', "App::PropertySpeed",
"Jakob", "Approximate flow velocity")
elif obj.Name.startswith('InitialisationZone'):
addObjectProperty(obj, "VelocitySpecified", False, "App::PropertyBool",
"Initialisation zone", "Whether the zone initialises velocity")
addObjectProperty(obj, 'Ux', '0 m/s', "App::PropertySpeed",
"Initialisation zone", "Velocity (x component)")
addObjectProperty(obj, 'Uy', '0 m/s', "App::PropertySpeed",
"Initialisation zone", "Velocity (y component)")
addObjectProperty(obj, 'Uz', '0 m/s', "App::PropertySpeed",
"Initialisation zone", "Velocity (z component)")
addObjectProperty(obj, "PressureSpecified", False, "App::PropertyBool",
"Initialisation zone", "Whether the zone initialises pressure")
addObjectProperty(obj, 'Pressure', '0 kg/m/s^2', "App::PropertyPressure",
"Initialisation zone", "Static pressure")
addObjectProperty(obj, "VolumeFractionSpecified", True, "App::PropertyBool",
"Initialisation zone", "Whether the zone initialises volume fraction")
addObjectProperty(obj, "VolumeFractions", {}, "App::PropertyMap",
"Initialisation zone", "Volume fraction values")
def onDocumentRestored(self, obj):
self.initProperties(obj)
def execute(self, fp):
listOfShapes = []
fp.LinkedObjects = []
for r in fp.References:
object = FreeCAD.ActiveDocument.getObject(r[0])
if object is not None: # Could have been deleted
try:
listOfShapes.append(object.Shape)
except Part.OCCError: # In case solid deleted
pass
if object not in fp.LinkedObjects:
fp.LinkedObjects += [object]
if listOfShapes:
fp.Shape = Part.makeCompound(listOfShapes)
else:
fp.Shape = Part.Shape()
def __getstate__(self):
return None
def __setstate__(self, state):
return None
class _ViewProviderCfdZone:
""" A View Provider for Zone objects. """
def __init__(self, vobj):
""" Set this object to the proxy object of the actual view provider """
vobj.Proxy = self
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
self.ViewObject.ShapeColor = (0.5,0.0,1.0)
self.ViewObject.Transparency = 70
# Setup the scene sub-graph of the view provider, this method is mandatory
return
def updateData(self, fp, prop):
""" If a property of the handled feature has changed we have the chance to handle this here """
return
def getDisplayModes(self, obj):
""" Return a list of display modes. """
modes=[]
return modes
def getDefaultDisplayMode(self):
""" Return the name of the default display mode. It must be defined in getDisplayModes. """
return "Shaded"
def setDisplayMode(self,mode):
""" Map the display mode defined in attach with those defined in getDisplayModes. Since they have the same
names nothing needs to be done. This method is optional.
"""
return mode
def onChanged(self, vp, prop):
return
def getIcon(self):
if self.Object.Name.startswith('PorousZone'):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "porous.png")
else:
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "alpha.svg")
return icon_path
def setEdit(self, vobj, mode):
import _TaskPanelCfdZone
taskd = _TaskPanelCfdZone._TaskPanelCfdZone(self.Object)
taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(taskd)
return True
def unsetEdit(self, vobj, mode):
FreeCADGui.Control.closeDialog()
return
def doubleClicked(self, vobj):
doc = FreeCADGui.getDocument(vobj.Object.Document)
# Overwrite the doubleClicked to make sure no other Material taskd (and thus no selection observer) is still
# active
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Task dialog already open\n')
return True
def __getstate__(self):
return None
def __setstate__(self, state):
return None