forked from jaheyns/CfdOF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCfdAnalysis.py
153 lines (125 loc) · 6.77 KB
/
CfdAnalysis.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
# ***************************************************************************
# * *
# * Copyright (c) 2013-2015 - Juergen Riegel <[email protected]> *
# * Copyright (c) 2017 Johan Heyns (CSIR) <[email protected]> *
# * Copyright (c) 2017 Oliver Oxtoby (CSIR) <[email protected]> *
# * Copyright (c) 2017 Alfred Bogaers (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
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore
def makeCfdAnalysis(name):
""" Create a Cfd Analysis group object """
obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython", name)
_CfdAnalysis(obj)
if FreeCAD.GuiUp:
_ViewProviderCfdAnalysis(obj.ViewObject)
return obj
class _CfdAnalysis:
""" The CFD analysis group """
def __init__(self, obj):
obj.Proxy = self
self.Type = "CfdAnalysis"
self.initProperties(obj)
def initProperties(self, obj):
addObjectProperty(obj, "OutputPath", "", "App::PropertyPath", "",
"Path to which cases are written (blank to use system default)")
addObjectProperty(obj, "IsActiveAnalysis", False, "App::PropertyBool", "", "Active analysis object in document")
obj.setEditorMode("IsActiveAnalysis", 1) # Make read-only (2 = hidden)
def onDocumentRestored(self, obj):
self.initProperties(obj)
class _CommandCfdAnalysis:
""" The Cfd_Analysis command definition """
def __init__(self):
pass
def GetResources(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "cfd_analysis.png")
return {'Pixmap': icon_path,
'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_Analysis", "Analysis container"),
'Accel': "N, C",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_Analysis", "Creates an analysis container with a CFD solver")}
def IsActive(self):
return FreeCAD.ActiveDocument is not None
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Create CFD Analysis")
FreeCADGui.doCommand("")
FreeCADGui.addModule("CfdAnalysis")
FreeCADGui.addModule("CfdTools")
FreeCADGui.doCommand("analysis = CfdAnalysis.makeCfdAnalysis('CfdAnalysis')")
FreeCADGui.doCommand("CfdTools.setActiveAnalysis(analysis)")
''' Objects ordered according to expected workflow '''
# Add physics object when CfdAnalysis container is created
FreeCADGui.addModule("CfdPhysicsSelection")
FreeCADGui.doCommand("analysis.addObject(CfdPhysicsSelection.makeCfdPhysicsSelection())")
# Add fluid properties object when CfdAnalysis container is created
FreeCADGui.addModule("CfdFluidMaterial")
FreeCADGui.doCommand("analysis.addObject(CfdFluidMaterial.makeCfdFluidMaterial('FluidProperties'))")
# Add initialisation object when CfdAnalysis container is created
FreeCADGui.addModule("CfdInitialiseFlowField")
FreeCADGui.doCommand("analysis.addObject(CfdInitialiseFlowField.makeCfdInitialFlowField())")
# Add solver object when CfdAnalysis container is created
FreeCADGui.addModule("CfdSolverFoam")
FreeCADGui.doCommand("analysis.addObject(CfdSolverFoam.makeCfdSolverFoam())")
class _ViewProviderCfdAnalysis:
""" A View Provider for the CfdAnalysis container object. """
def __init__(self, vobj):
vobj.Proxy = self
def getIcon(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "cfd_analysis.png")
return icon_path
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
self.bubbles = None
def updateData(self, obj, prop):
return
def onChanged(self, vobj, prop):
self.makePartTransparent(vobj)
CfdTools.setCompSolid(vobj)
return
def doubleClicked(self, vobj):
if not CfdTools.getActiveAnalysis() == self.Object:
if FreeCADGui.activeWorkbench().name() != 'CfdOFWorkbench':
FreeCADGui.activateWorkbench("CfdOFWorkbench")
CfdTools.setActiveAnalysis(self.Object)
return True
return True
def makePartTransparent(self, vobj):
""" Make parts transparent so that the boundary conditions and cell zones are clearly visible. """
docName = str(vobj.Object.Document.Name)
doc = FreeCAD.getDocument(docName)
for obj in doc.Objects:
if obj.isDerivedFrom("Part::Feature") and not("CfdFluidBoundary" in obj.Name):
FreeCAD.getDocument(docName).getObject(obj.Name).ViewObject.Transparency = 70
if obj.isDerivedFrom("PartDesign::Feature"):
doc.getObject(obj.Name).ViewObject.LineWidth = 1
doc.getObject(obj.Name).ViewObject.LineColor = (0.5, 0.5, 0.5)
doc.getObject(obj.Name).ViewObject.PointColor = (0.5, 0.5, 0.5)
if obj.isDerivedFrom("Part::Feature") and obj.Name.startswith("Compound"):
FreeCAD.getDocument(docName).getObject(obj.Name).ViewObject.Visibility = False
def __getstate__(self):
return None
def __setstate__(self, state):
return None