forked from jaheyns/CfdOF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CfdInitialiseFlowField.py
179 lines (151 loc) · 8.49 KB
/
CfdInitialiseFlowField.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
# ***************************************************************************
# * *
# * Copyright (c) 2013-2015 - Juergen Riegel <[email protected]> *
# * 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 *
# * *
# ***************************************************************************
import FreeCAD
import CfdTools
from CfdTools import addObjectProperty
import os
import os.path
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore
def makeCfdInitialFlowField(name="InitialiseFields"):
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", name)
_CfdInitialVariables(obj)
if FreeCAD.GuiUp:
_ViewProviderCfdInitialseInternalFlowField(obj.ViewObject)
return obj
class _CommandCfdInitialiseInternalFlowField:
""" Field initialisation command """
def GetResources(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "initialise.png")
return {'Pixmap': icon_path,
'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_InitialiseInternal", "Initialise"),
'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP(
"Cfd_InitialiseInternal",
"Initialise internal flow variables based on the selected physics model")}
def IsActive(self):
return CfdTools.getActiveAnalysis() is not None
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Initialise the internal flow variables")
isPresent = False
members = CfdTools.getActiveAnalysis().Group
for i in members:
if "InitialiseFields" in i.Name:
FreeCADGui.activeDocument().setEdit(i.Name)
isPresent = True
# Allow to re-create if deleted
if not isPresent:
FreeCADGui.doCommand("")
FreeCADGui.addModule("CfdInitialiseFlowField")
FreeCADGui.doCommand(
"CfdTools.getActiveAnalysis().addObject(CfdInitialiseFlowField.makeCfdInitialFlowField())")
FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Cfd_InitialiseInternal', _CommandCfdInitialiseInternalFlowField())
class _CfdInitialVariables:
""" The field initialisation object """
def __init__(self, obj):
obj.Proxy = self
self.Type = "InitialVariables"
self.initProperties(obj)
def initProperties(self, obj):
addObjectProperty(obj, 'PotentialFlow', True, "App::PropertyBool", "Flow", "Initialise velocity with potential flow solution")
addObjectProperty(obj, 'PotentialFlowP', False, "App::PropertyBool", "Flow", "Initialise pressure with potential flow solution")
addObjectProperty(obj, 'UseInletUValues', False, "App::PropertyBool", "Flow",
"Initialise with flow values from inlet")
addObjectProperty(obj, 'UseOutletPValue', True, "App::PropertyBool", "Flow",
"Initialise with flow values from outlet")
addObjectProperty(obj, 'Ux', '0 m/s', "App::PropertySpeed", "Flow", "Velocity (x component)")
addObjectProperty(obj, 'Uy', '0 m/s', "App::PropertySpeed", "Flow", "Velocity (y component)")
addObjectProperty(obj, 'Uz', '0 m/s', "App::PropertySpeed", "Flow", "Velocity (z component)")
addObjectProperty(obj, 'Pressure', '0 Pa', "App::PropertyPressure", "Flow", "Static pressure")
addObjectProperty(obj, 'UseInletTemperatureValue', False, "App::PropertyBool", "Thermal",
"Initialise with temperature value from inlet")
addObjectProperty(obj, 'Temperature', '293 K', "App::PropertyQuantity", "Thermal", "Temperature")
addObjectProperty(obj, 'UseInletTurbulenceValues', False, "App::PropertyBool", "Turbulence",
"Initialise turbulence with values from inlet")
addObjectProperty(obj, 'k', '0.01 m^2/s^2', "App::PropertyQuantity", "Turbulence", "Turbulent kinetic energy")
addObjectProperty(obj, 'omega', '1 rad/s', "App::PropertyQuantity", "Turbulence",
"Specific turbulent dissipation rate")
addObjectProperty(obj, 'VolumeFractions', {}, "App::PropertyMap", "Volume Fraction", "Volume fraction values")
addObjectProperty(obj, 'BoundaryU', None, "App::PropertyLink", "", "U boundary name")
addObjectProperty(obj, 'BoundaryP', None, "App::PropertyLink", "", "P boundary name")
addObjectProperty(obj, 'BoundaryT', None, "App::PropertyLink", "", "T boundary name")
addObjectProperty(obj, 'BoundaryTurb', None, "App::PropertyLink", "", "Turbulence boundary name")
def onDocumentRestored(self, obj):
self.initProperties(obj)
class _ViewProviderCfdInitialseInternalFlowField:
def __init__(self, vobj):
vobj.Proxy = self
def getIcon(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "initialise.png")
return icon_path
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
def updateData(self, obj, prop):
return
def onChanged(self, vobj, prop):
return
def setEdit(self, vobj, mode):
analysis_object = CfdTools.getParentAnalysisObject(self.Object)
if analysis_object is None:
CfdTools.cfdError("No parent analysis object found")
return False
physics_model = CfdTools.getPhysicsModel(analysis_object)
if not physics_model:
CfdTools.cfdError("Analysis object must have a physics object")
return False
boundaries = CfdTools.getCfdBoundaryGroup(analysis_object)
material_objs = CfdTools.getMaterials(analysis_object)
import _TaskPanelCfdInitialiseInternalFlowField
taskd = _TaskPanelCfdInitialiseInternalFlowField._TaskPanelCfdInitialiseInternalFlowField(
self.Object, physics_model, boundaries, material_objs)
taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(taskd)
return True
def unsetEdit(self, vobj, mode):
FreeCADGui.Control.closeDialog()
return
# Override doubleClicked to make sure no other Material taskd (and thus no selection observer) is still active
def doubleClicked(self, vobj):
doc = FreeCADGui.getDocument(vobj.Object.Document)
if not CfdTools.getActiveAnalysis():
analysis_obj = CfdTools.getParentAnalysisObject(self.Object)
if analysis_obj:
CfdTools.setActiveAnalysis(analysis_obj)
else:
CfdTools.cfdError('No parent analysis object detected')
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Active Task Dialog found! Please close this one first!\n')
return True
def __getstate__(self):
return None
def __setstate__(self, state):
return None