forked from jaheyns/CfdOF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_CfdMeshRegion.py
156 lines (134 loc) · 7.7 KB
/
_CfdMeshRegion.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
# ***************************************************************************
# * *
# * Copyright (c) 2016 - Bernd Hahnebach <bernd@bimstatik.org> *
# * Copyright (c) 2017 - Johan Heyns (CSIR) <jheyns@csir.co.za> *
# * Copyright (c) 2017 - Oliver Oxtoby (CSIR) <ooxtoby@csir.co.za> *
# * Copyright (c) 2017 - Alfred Bogaers (CSIR) <abogaers@csir.co.za> *
# * *
# * 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 *
# * *
# ***************************************************************************
__title__ = "_CfdMeshRegion"
__author__ = "JH, OO, AB"
__url__ = "http://www.freecadweb.org"
# @package CfdMeshRegion
# \ingroup CFD
from FreeCAD import Base
class PartFeature:
def __init__(self, obj):
obj.Proxy = self
class _CfdMeshRegion(PartFeature):
"""The CfdMeshRegion object"""
def __init__(self, obj):
PartFeature.__init__(self, obj)
# GMSH related properties
obj.addProperty("App::PropertyFloat", "RelativeLength", "GMSH",
"Set relative length of the elements for this region")
obj.RelativeLength = 0.75
# cfMesh related properties
obj.addProperty("App::PropertyFloat", "RelativeLength", "cfMesh",
"Set relative length of the elements for this region")
obj.RelativeLength = 0.75
obj.addProperty("App::PropertyLength", "RefinementThickness", "cfMesh",
"Set refinement region thickness")
obj.RefinementThickness = 0.0
obj.addProperty("App::PropertyInteger", "NumberLayers", "cfMesh",
"Set number of boundary layers")
obj.NumberLayers = 0
obj.addProperty("App::PropertyFloat", "ExpansionRatio", "cfMesh",
"Set expansion ratio within boundary layers")
obj.ExpansionRatio = 0.0
obj.addProperty("App::PropertyLength", "FirstLayerHeight", "cfMesh",
"Set the maximum first layer height")
obj.FirstLayerHeight = 0.0
# sHMesh related properties
obj.addProperty("App::PropertyInteger", "RefinementLevel", "snappyHexMesh",
"Minimum and maximum refinement levels")
obj.RefinementLevel = 1
obj.addProperty("App::PropertyInteger", "RegionEdgeRefinement", "snappyHexMesh",
"Region edge or feature refinement level")
obj.RegionEdgeRefinement = 1
obj.addProperty("App::PropertyBool", "Baffle", "snappyHexMesh",
"Create a zero thickness baffle")
obj.Baffle = False
obj.addProperty("App::PropertyPythonObject", "References", "MeshRegionProperties",
"List of mesh region surfaces")
obj.References = []
#Cartesian mesh internal volume refinement properties
obj.addProperty("App::PropertyBool","Internal","MeshRegionProperties")
obj.Internal = False
obj.addProperty("App::PropertyPythonObject","InternalRegion")
obj.InternalRegion = {"Type": "Box",
"Center": {"x":0,"y":0,"z":0},
"BoxLengths": {"x":1e-3,"y":1e-3,"z":1e-3},
"SphereRadius": 1e-3,
"Point1": {"x": 0, "y": 0, "z": 0},
"Point2": {"x": 0, "y": 0, "z": 0},
"Radius1": 1e-3,
"Radius2": 1e-3}
obj.Proxy = self
self.Type = "CfdMeshRegion"
def execute(self, obj):
import Part
#try for problem backward compatibility
try:
if obj.Internal:
shape = None
if obj.InternalRegion["Type"] == "Box":
x = obj.InternalRegion["Center"]["x"]*1000 - obj.InternalRegion["BoxLengths"]["x"]*1000/2.0
y = obj.InternalRegion["Center"]["y"]*1000 - obj.InternalRegion["BoxLengths"]["y"]*1000/2.0
z = obj.InternalRegion["Center"]["z"]*1000 - obj.InternalRegion["BoxLengths"]["z"]*1000/2.0
shape = Part.makeBox(obj.InternalRegion["BoxLengths"]["x"]*1000,
obj.InternalRegion["BoxLengths"]["y"]*1000,
obj.InternalRegion["BoxLengths"]["z"]*1000,
Base.Vector(x,y,z))
elif obj.InternalRegion["Type"] == "Sphere":
shape = Part.makeSphere(obj.InternalRegion["SphereRadius"]*1000,
Base.Vector(obj.InternalRegion["Center"]["x"]*1000,
obj.InternalRegion["Center"]["y"]*1000,
obj.InternalRegion["Center"]["z"]*1000))
elif obj.InternalRegion["Type"] == "Cone":
p1 = Base.Vector(obj.InternalRegion["Point1"]["x"]*1000,
obj.InternalRegion["Point1"]["y"]*1000,
obj.InternalRegion["Point1"]["z"]*1000)
p2 = Base.Vector(obj.InternalRegion["Point2"]["x"]*1000,
obj.InternalRegion["Point2"]["y"]*1000,
obj.InternalRegion["Point2"]["z"]*1000)
h = (p2-p1).Length
if h > 0:
if obj.InternalRegion["Radius1"] == obj.InternalRegion["Radius2"]:
# makeCone fails in this special case
shape = Part.makeCylinder(obj.InternalRegion["Radius1"]*1000,
h, p1, (p2-p1)/(h+1e-8))
else:
shape = Part.makeCone(obj.InternalRegion["Radius1"]*1000,
obj.InternalRegion["Radius2"]*1000,
h, p1, (p2-p1)/(h+1e-8))
if shape:
obj.Shape = shape
else:
obj.Shape = Part.Vertex()
else:
obj.Shape = Part.Vertex()
except AttributeError:
#print("""In order to view a shape corresponding to the internal region please
#re-create the refinement object""")
pass
def __getstate__(self):
return None
def __setstate__(self, state):
return None