1 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from smesh import Mesh_Algorithm, AssureGeomPublished, ParseParameters, IsEqual
22 # import NETGENPlugin module if possible
31 NETGEN_3D = "NETGEN_3D"
32 NETGEN_1D2D3D = "NETGEN_2D3D"
33 NETGEN_1D2D = "NETGEN_2D"
34 NETGEN_2D = "NETGEN_2D_ONLY"
35 NETGEN_FULL = NETGEN_1D2D3D
37 FULL_NETGEN = NETGEN_FULL
42 # Fineness enumeration
50 ## Base of all NETGEN algorithms.
52 class NETGEN_Algorithm(Mesh_Algorithm):
54 def __init__(self, mesh, geom=0):
55 Mesh_Algorithm.__init__(self)
56 if noNETGENPlugin: print "Warning: NETGENPlugin module unavailable"
57 self.Create(mesh, geom, self.algoType, "libNETGENEngine.so")
62 def SetMaxSize(self, theSize):
64 self.params.SetMaxSize(theSize)
68 def SetMinSize(self, theSize):
70 self.params.SetMinSize(theSize)
75 def SetOptimize(self, theVal):
77 self.params.SetOptimize(theVal)
80 # @param theFineness is:
81 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
83 def SetFineness(self, theFineness):
85 self.params.SetFineness(theFineness)
89 def SetGrowthRate(self, theRate):
91 self.params.SetGrowthRate(theRate)
93 ## Defines hypothesis having several parameters
95 def Parameters(self, which=SOLE):
96 if self.algoType == NETGEN_1D2D:
98 hypType = "NETGEN_SimpleParameters_2D"
100 hypType = "NETGEN_Parameters_2D"
101 elif self.algoType == NETGEN_1D2D3D:
103 hypType = "NETGEN_SimpleParameters_3D"
105 hypType = "NETGEN_Parameters"
106 elif self.algoType == NETGEN_2D:
107 hypType = "NETGEN_Parameters_2D_ONLY"
109 hypType = "NETGEN_Parameters_3D"
111 if self.params and self.params.GetName() != hypType:
112 self.mesh.RemoveHypothesis( self.params, self.geom )
115 self.params = self.Hypothesis(hypType, [],"libNETGENEngine.so",UseExisting=0)
121 ## Defines a tetrahedron 1D-2D-3D algorithm
122 # It is created by calling Mesh.Triangle( NETGEN_1D2D3D, geom=0 )
124 class NETGEN_1D2D3D_Algorithm(NETGEN_Algorithm):
126 meshMethod = "Tetrahedron"
127 algoType = NETGEN_1D2D3D
129 ## Private constructor.
130 def __init__(self, mesh, geom=0):
131 NETGEN_Algorithm.__init__(self, mesh, geom)
133 ## Sets SecondOrder flag
135 def SetSecondOrder(self, theVal):
136 if self.Parameters():
137 self.params.SetSecondOrder(theVal)
141 def SetNbSegPerEdge(self, theVal):
142 if self.Parameters():
143 self.params.SetNbSegPerEdge(theVal)
145 ## Sets NbSegPerRadius
147 def SetNbSegPerRadius(self, theVal):
148 if self.Parameters():
149 self.params.SetNbSegPerRadius(theVal)
151 ## Sets QuadAllowed flag.
152 def SetQuadAllowed(self, toAllow=True):
153 if self.Parameters():
154 self.params.SetQuadAllowed(toAllow)
157 ## Sets number of segments overriding the value set by SetLocalLength()
159 def SetNumberOfSegments(self, theVal):
160 self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
162 ## Sets number of segments overriding the value set by SetNumberOfSegments()
164 def SetLocalLength(self, theVal):
165 self.Parameters(SIMPLE).SetLocalLength(theVal)
167 ## Defines "MaxElementArea" parameter of NETGEN_SimpleParameters_3D hypothesis.
168 # Overrides value set by LengthFromEdges()
169 def MaxElementArea(self, area):
170 self.Parameters(SIMPLE).SetMaxElementArea(area)
172 ## Defines "LengthFromEdges" parameter of NETGEN_SimpleParameters_3D hypothesis
173 # Overrides value set by MaxElementArea()
174 def LengthFromEdges(self):
175 self.Parameters(SIMPLE).LengthFromEdges()
177 ## Defines "LengthFromFaces" parameter of NETGEN_SimpleParameters_3D hypothesis
178 # Overrides value set by MaxElementVolume()
179 def LengthFromFaces(self):
180 self.Parameters(SIMPLE).LengthFromFaces()
182 ## Defines "MaxElementVolume" parameter of NETGEN_SimpleParameters_3D hypothesis
183 # Overrides value set by LengthFromFaces()
184 def MaxElementVolume(self, vol):
185 self.Parameters(SIMPLE).SetMaxElementVolume(vol)
188 ## Triangle NETGEN 1D-2D algorithm.
189 # It is created by calling Mesh.Triangle( NETGEN_1D2D, geom=0 )
191 class NETGEN_1D2D_Algorithm(NETGEN_1D2D3D_Algorithm):
193 meshMethod = "Triangle"
194 algoType = NETGEN_1D2D
196 ## Private constructor.
197 def __init__(self, mesh, geom=0):
198 NETGEN_1D2D3D_Algorithm.__init__(self, mesh, geom)
202 ## Triangle NETGEN 2D algorithm
203 # It is created by calling Mesh.Triangle( NETGEN_2D, geom=0 )
205 class NETGEN_2D_Only_Algorithm(NETGEN_Algorithm):
207 meshMethod = "Triangle"
210 ## Private constructor.
211 def __init__(self, mesh, geom=0):
212 NETGEN_Algorithm.__init__(self, mesh, geom)
214 ## Sets QuadAllowed flag.
215 def SetQuadAllowed(self, toAllow=True):
216 if self.Parameters():
217 self.params.SetQuadAllowed(toAllow)
219 ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
220 # @param area for the maximum area of each triangle
221 # @param UseExisting if ==true - searches for an existing hypothesis created with the
222 # same parameters, else (default) - creates a new one
224 def MaxElementArea(self, area, UseExisting=0):
225 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
226 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
227 CompareMethod=compFun)
228 hyp.SetMaxElementArea(area)
231 ## Defines "LengthFromEdges" hypothesis to build triangles
232 # based on the length of the edges taken from the wire
234 def LengthFromEdges(self):
235 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
238 ## Sets QuadAllowed flag.
239 def SetQuadAllowed(self, toAllow=True):
242 hasSimpleHyps = False
243 simpleHyps = ["QuadranglePreference","LengthFromEdges","MaxElementArea"]
244 for hyp in self.mesh.GetHypothesisList( self.geom ):
245 if hyp.GetName() in simpleHyps:
247 if hyp.GetName() == "QuadranglePreference":
248 if not toAllow: # remove QuadranglePreference
249 self.mesh.RemoveHypothesis( self.geom, hyp )
256 if toAllow: # add QuadranglePreference
257 return self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
260 self.Parameters().SetQuadAllowed( toAllow )
263 ## Defines a tetrahedron 3D algorithm
264 # It is created by calling Mesh.Tetrahedron()
266 class NETGEN_3D_Algorithm(NETGEN_Algorithm):
268 meshMethod = "Tetrahedron"
272 ## Private constructor.
273 def __init__(self, mesh, geom=0):
274 NETGEN_Algorithm.__init__(self, mesh, geom)
276 ## Defines "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedron
277 # @param vol for the maximum volume of each tetrahedron
278 # @param UseExisting if ==true - searches for the existing hypothesis created with
279 # the same parameters, else (default) - creates a new one
280 def MaxElementVolume(self, vol, UseExisting=0):
281 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementVolume(), args[0])
282 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
283 CompareMethod=compFun)
284 hyp.SetMaxElementVolume(vol)
288 # Class just to create NETGEN_1D2D by calling Mesh.Triangle(NETGEN)
289 class NETGEN_1D2D_Algorithm_2(NETGEN_1D2D_Algorithm):
293 ## Private constructor.
294 def __init__(self, mesh, geom=0):
295 self.algoType = NETGEN_1D2D
296 NETGEN_1D2D_Algorithm.__init__(self,mesh, geom)
299 # Class just to create NETGEN_1D2D3D by calling Mesh.Netgen()
300 class NETGEN_1D2D3D_Algorithm_2(NETGEN_1D2D3D_Algorithm):
302 meshMethod = "Netgen"
304 ## Private constructor.
305 def __init__(self, mesh, geom=0):
306 NETGEN_1D2D3D_Algorithm.__init__(self,mesh, geom)