1 # Copyright (C) 2007-2014 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, or (at your option) any later version.
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
21 # @package NETGENPluginBuilder
22 # Python API for the NETGEN meshing plug-in module.
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
25 from salome.smesh.smeshBuilder import AssureGeomPublished, ParseParameters, IsEqual
27 # import NETGENPlugin module if possible
35 #----------------------------
36 # Mesh algo type identifiers
37 #----------------------------
39 ## Algorithm type: Netgen tetrahedron 3D algorithm, see NETGEN_3D_Algorithm
40 NETGEN_3D = "NETGEN_3D"
41 ## Algorithm type: Netgen tetrahedron 1D-2D-3D algorithm, see NETGEN_1D2D3D_Algorithm
42 NETGEN_1D2D3D = "NETGEN_2D3D"
43 ## Algorithm type: Netgen triangle 1D-2D algorithm, see NETGEN_1D2D_Algorithm
44 NETGEN_1D2D = "NETGEN_2D"
45 ## Algorithm type: Netgen triangle 2D algorithm, see NETGEN_2D_Only_Algorithm
46 NETGEN_2D = "NETGEN_2D_ONLY"
47 ## Algorithm type: Synonim of NETGEN_1D2D3D, see NETGEN_1D2D3D_Algorithm
48 NETGEN_FULL = NETGEN_1D2D3D
49 ## Algorithm type: Synonim of NETGEN_3D, see NETGEN_3D_Algorithm
51 ## Algorithm type: Synonim of NETGEN_1D2D3D, see NETGEN_1D2D3D_Algorithm
52 FULL_NETGEN = NETGEN_FULL
54 #----------------------------
55 # Hypothesis type enumeration
56 #----------------------------
58 ## Hypothesis type enumeration: complex hypothesis
59 # (full set of parameters can be specified),
60 # see NETGEN_Algorithm.Parameters()
62 ## Hypothesis type enumeration: simple hypothesis
63 # (only major parameters are specified),
64 # see NETGEN_Algorithm.Parameters()
67 #----------------------
68 # Fineness enumeration
69 #----------------------
71 ## Fineness enumeration: very coarse quality of mesh,
72 # see NETGEN_Algorithm.SetFineness()
74 ## Fineness enumeration: coarse quality of mesh,
75 # see NETGEN_Algorithm.SetFineness()
77 ## Fineness enumeration: moderate quality of mesh,
78 # see NETGEN_Algorithm.SetFineness()
80 ## Fineness enumeration: fine quality of mesh,
81 # see NETGEN_Algorithm.SetFineness()
83 ## Fineness enumeration: very fine quality of mesh,
84 # see NETGEN_Algorithm.SetFineness()
86 ## Fineness enumeration: custom quality of mesh specified by other parameters),
87 # see NETGEN_Algorithm.SetFineness()
90 #----------------------
92 #----------------------
94 ## Base of all NETGEN algorithms.
96 # This class provides common methods for all algorithms implemented by NETGEN plugin.
97 # @note This class must not be instantiated directly.
98 class NETGEN_Algorithm(Mesh_Algorithm):
100 ## Private constructor
101 # @param mesh parent mesh object algorithm is assigned to
102 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
103 # if it is @c 0 (default), the algorithm is assigned to the main shape
104 def __init__(self, mesh, geom=0):
105 Mesh_Algorithm.__init__(self)
106 if noNETGENPlugin: print "Warning: NETGENPlugin module unavailable"
107 self.Create(mesh, geom, self.algoType, "libNETGENEngine.so")
111 ## Sets @c MaxSize parameter
112 # @param theSize new value of the @c MaxSize parameter
113 def SetMaxSize(self, theSize):
114 if self.Parameters(): self.params.SetMaxSize(theSize)
117 ## Sets @c MinSize parameter
118 # @param theSize new value of the @c MinSize parameter
119 def SetMinSize(self, theSize):
120 if self.Parameters(): self.params.SetMinSize(theSize)
123 ## Sets @c Optimize flag
124 # @param theVal new value of the @c Optimize parameter
125 def SetOptimize(self, theVal):
126 if self.Parameters(): self.params.SetOptimize(theVal)
129 ## Sets @c Fineness parameter
130 # @param theFineness new value of the @c Fineness parameter; it can be:
131 # @ref VeryCoarse, @ref Coarse, @ref Moderate, @ref Fine, @ref VeryFine or @ref Custom
132 def SetFineness(self, theFineness):
133 if self.Parameters(): self.params.SetFineness(theFineness)
136 ## Sets @c GrowthRate parameter
137 # @param theRate new value of the @c GrowthRate parameter
138 def SetGrowthRate(self, theRate):
139 if self.Parameters(): self.params.SetGrowthRate(theRate)
142 ## Creates meshing hypothesis according to the chosen algorithm type
143 # and initializes it with default parameters
144 # @param which hypothesis type; can be either @ref SOLE (default) or @ref SIMPLE
145 # @return hypothesis object
146 def Parameters(self, which=SOLE):
147 if self.algoType == NETGEN_1D2D:
149 hypType = "NETGEN_SimpleParameters_2D"
151 hypType = "NETGEN_Parameters_2D"
152 elif self.algoType == NETGEN_1D2D3D:
154 hypType = "NETGEN_SimpleParameters_3D"
156 hypType = "NETGEN_Parameters"
157 elif self.algoType == NETGEN_2D:
158 hypType = "NETGEN_Parameters_2D_ONLY"
160 hypType = "NETGEN_Parameters_3D"
162 if self.params and self.params.GetName() != hypType:
163 self.mesh.RemoveHypothesis( self.params, self.geom )
166 self.params = self.Hypothesis(hypType, [],"libNETGENEngine.so",UseExisting=0)
170 pass # end of NETGEN_Algorithm class
173 ## Tetrahedron 1D-2D-3D algorithm.
175 # It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN_1D2D3D, geom=0 ).
176 # This algorithm generates all 1D (edges), 2D (faces) and 3D (volumes) elements
177 # for given geometrical shape.
178 class NETGEN_1D2D3D_Algorithm(NETGEN_Algorithm):
180 ## name of the dynamic method in smeshBuilder.Mesh class
182 meshMethod = "Tetrahedron"
183 ## type of algorithm used with helper function in smeshBuilder.Mesh class
185 algoType = NETGEN_1D2D3D
186 ## doc string of the method
188 docHelper = "Creates tetrahedron 3D algorithm for solids"
190 ## Private constructor.
191 # @param mesh parent mesh object algorithm is assigned to
192 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
193 # if it is @c 0 (default), the algorithm is assigned to the main shape
194 def __init__(self, mesh, geom=0):
195 NETGEN_Algorithm.__init__(self, mesh, geom)
198 ## Sets @c SecondOrder flag
199 # @param theVal new value of the @c SecondOrder parameter
200 def SetSecondOrder(self, theVal):
201 if self.Parameters(): self.params.SetSecondOrder(theVal)
204 ## Sets @c NbSegPerEdge parameter
205 # @param theVal new value of the @c NbSegPerEdge parameter
206 def SetNbSegPerEdge(self, theVal):
207 if self.Parameters(): self.params.SetNbSegPerEdge(theVal)
210 ## Sets @c NbSegPerRadius parameter
211 # @param theVal new value of the @c NbSegPerRadius parameter
212 def SetNbSegPerRadius(self, theVal):
213 if self.Parameters(): self.params.SetNbSegPerRadius(theVal)
216 ## Sets @c QuadAllowed flag
217 # @param toAllow new value of the @c QuadAllowed parameter (@c True by default)
218 def SetQuadAllowed(self, toAllow=True):
219 if self.Parameters(): self.params.SetQuadAllowed(toAllow)
221 ## Sets @c UseSurfaceCurvature flag
222 # @param toUse new value of the @c UseSurfaceCurvature parameter (@c True by default)
223 def SetUseSurfaceCurvature(self, toUse=True):
224 if self.Parameters(): self.params.SetUseSurfaceCurvature(toUse)
226 ## Sets @c FuseEdges flag
227 # @param toFuse new value of the @c FuseEdges parameter (@c False by default)
228 def SetFuseEdges(self, toFuse=False):
229 if self.Parameters(): self.params.SetFuseEdges(toFuse)
232 ## Sets number of segments overriding the value set by SetLocalLength()
233 # @param theVal new value of number of segments parameter
234 def SetNumberOfSegments(self, theVal):
235 self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
238 ## Sets number of segments overriding the value set by SetNumberOfSegments()
239 # @param theVal new value of local length parameter
240 def SetLocalLength(self, theVal):
241 self.Parameters(SIMPLE).SetLocalLength(theVal)
244 ## Defines @c MaxElementArea parameter of @c NETGEN_SimpleParameters_3D hypothesis.
245 # Overrides value set by LengthFromEdges()
246 # @param area new value of @c MaxElementArea parameter
247 def MaxElementArea(self, area):
248 self.Parameters(SIMPLE).SetMaxElementArea(area)
251 ## Defines @c LengthFromEdges parameter of @c NETGEN_SimpleParameters_3D hypothesis.
252 # Overrides value set by MaxElementArea()
253 def LengthFromEdges(self):
254 self.Parameters(SIMPLE).LengthFromEdges()
257 ## Defines @c LengthFromFaces parameter of @c NETGEN_SimpleParameters_3D hypothesis.
258 # Overrides value set by MaxElementVolume()
259 def LengthFromFaces(self):
260 self.Parameters(SIMPLE).LengthFromFaces()
263 ## Defines @c MaxElementVolume parameter of @c NETGEN_SimpleParameters_3D hypothesis.
264 # Overrides value set by LengthFromFaces()
265 # @param vol new value of @c MaxElementVolume parameter
266 def MaxElementVolume(self, vol):
267 self.Parameters(SIMPLE).SetMaxElementVolume(vol)
270 pass # end of NETGEN_1D2D3D_Algorithm class
273 ## Triangle NETGEN 1D-2D algorithm.
275 # It can be created by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_1D2D, geom=0 )
277 # This algorithm generates 1D (edges) and 2D (faces) elements
278 # for given geometrical shape.
279 class NETGEN_1D2D_Algorithm(NETGEN_1D2D3D_Algorithm):
281 ## name of the dynamic method in smeshBuilder.Mesh class
283 meshMethod = "Triangle"
284 ## type of algorithm used with helper function in smeshBuilder.Mesh class
286 algoType = NETGEN_1D2D
287 ## doc string of the method
289 docHelper = "Creates triangle 2D algorithm for faces"
291 ## Private constructor.
292 # @param mesh parent mesh object algorithm is assigned to
293 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
294 # if it is @c 0 (default), the algorithm is assigned to the main shape
295 def __init__(self, mesh, geom=0):
296 NETGEN_1D2D3D_Algorithm.__init__(self, mesh, geom)
299 pass # end of NETGEN_1D2D_Algorithm class
302 ## Triangle NETGEN 2D algorithm
304 # It can be created by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_2D, geom=0 )
306 # This algorithm generates only 2D (faces) elements for given geometrical shape
307 # and, in contrast to NETGEN_1D2D_Algorithm class, should be used in conjunction
308 # with other 1D meshing algorithm.
309 class NETGEN_2D_Only_Algorithm(NETGEN_Algorithm):
311 ## name of the dynamic method in smeshBuilder.Mesh class
313 meshMethod = "Triangle"
314 ## type of algorithm used with helper function in smeshBuilder.Mesh class
317 ## doc string of the method
319 docHelper = "Creates triangle 2D algorithm for faces"
321 ## Private constructor.
322 # @param mesh parent mesh object algorithm is assigned to
323 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
324 # if it is @c 0 (default), the algorithm is assigned to the main shape
325 def __init__(self, mesh, geom=0):
326 NETGEN_Algorithm.__init__(self, mesh, geom)
329 ## Defines @c MaxElementArea parameter of hypothesis basing on the definition of the
330 # maximum area of each triangle
331 # @param area maximum area value of each triangle
332 # @param UseExisting if \c True - searches for an existing hypothesis created with the
333 # same parameters, else (default) - creates a new one
334 # @return hypothesis object
335 def MaxElementArea(self, area, UseExisting=0):
336 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
337 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
338 CompareMethod=compFun)
339 hyp.SetMaxElementArea(area)
342 ## Defines @c LengthFromEdges hypothesis to build triangles
343 # based on the length of the edges taken from the wire
344 # @return hypothesis object
345 def LengthFromEdges(self):
346 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
349 ## Sets @c UseSurfaceCurvature flag
350 # @param toUse new value of the @c UseSurfaceCurvature parameter (@c True by default)
351 def SetUseSurfaceCurvature(self, toUse=True):
352 if self.Parameters(): self.params.SetUseSurfaceCurvature(toUse)
355 ## Sets @c QuadAllowed flag.
356 # @param toAllow new value of the @c QuadAllowed parameter (@c True by default)
357 # @return hypothesis object
358 def SetQuadAllowed(self, toAllow=True):
361 hasSimpleHyps = False
362 simpleHyps = ["QuadranglePreference","LengthFromEdges","MaxElementArea"]
363 for hyp in self.mesh.GetHypothesisList( self.geom ):
364 if hyp.GetName() in simpleHyps:
366 if hyp.GetName() == "QuadranglePreference":
367 if not toAllow: # remove QuadranglePreference
368 self.mesh.RemoveHypothesis( self.geom, hyp )
375 if toAllow: # add QuadranglePreference
376 return self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
379 self.Parameters().SetQuadAllowed( toAllow )
382 pass # end of NETGEN_2D_Only_Algorithm class
385 ## Tetrahedron 3D algorithm
387 # It can be created by calling smeshBuilder.Mesh.Tetrahedron() or smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN, geom=0 )
389 # This algorithm generates only 3D (volumes) elements for given geometrical shape
390 # and, in contrast to NETGEN_1D2D3D_Algorithm class, should be used in conjunction
391 # with other 1D and 2D meshing algorithms.
392 class NETGEN_3D_Algorithm(NETGEN_Algorithm):
394 ## name of the dynamic method in smeshBuilder.Mesh class
396 meshMethod = "Tetrahedron"
397 ## type of algorithm used with helper function in smeshBuilder.Mesh class
400 ## flag pointing either this algorithm should be used by default in dynamic method
401 # of smeshBuilder.Mesh class
404 ## doc string of the method
406 docHelper = "Creates tetrahedron 3D algorithm for solids"
408 ## Private constructor.
409 # @param mesh parent mesh object algorithm is assigned to
410 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
411 # if it is @c 0 (default), the algorithm is assigned to the main shape
412 def __init__(self, mesh, geom=0):
413 NETGEN_Algorithm.__init__(self, mesh, geom)
416 ## Defines @c MaxElementVolume hypothesis to specify the maximum volume value of each tetrahedron
417 # @param vol maximum volume value of each tetrahedron
418 # @param UseExisting if \c True - searches for the existing hypothesis created with
419 # the same parameters, else (default) - creates a new one
420 # @return hypothesis object
421 def MaxElementVolume(self, vol, UseExisting=0):
422 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementVolume(), args[0])
423 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
424 CompareMethod=compFun)
425 hyp.SetMaxElementVolume(vol)
428 pass # end of NETGEN_3D_Algorithm class
431 ## Triangle (helper) 1D-2D algorithm
433 # This is the helper class that is used just to allow creating of create NETGEN_1D2D algorithm
434 # by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN, geom=0 ); this is required for backward compatibility
435 # with old Python scripts.
437 # @note This class (and corresponding smeshBuilder.Mesh function) is obsolete;
438 # use smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_1D2D, geom=0 ) instead.
439 class NETGEN_1D2D_Algorithm_2(NETGEN_1D2D_Algorithm):
441 ## name of the dynamic method in smeshBuilder.Mesh class
445 ## Private constructor.
446 # @param mesh parent mesh object algorithm is assigned to
447 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
448 # if it is @c 0 (default), the algorithm is assigned to the main shape
449 def __init__(self, mesh, geom=0):
450 self.algoType = NETGEN_1D2D
451 NETGEN_1D2D_Algorithm.__init__(self,mesh, geom)
454 pass # end of NETGEN_1D2D_Algorithm_2 class
457 ## Tetrahedron (helper) 1D-2D-3D algorithm.
459 # This is the helper class that is used just to allow creating of create NETGEN_1D2D3D
460 # by calling smeshBuilder.Mesh.Netgen(); this is required for backward compatibility with old Python scripts.
462 # @note This class (and corresponding smeshBuilder.Mesh function) is obsolete;
463 # use smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN_1D2D3D, geom=0 ) instead.
464 class NETGEN_1D2D3D_Algorithm_2(NETGEN_1D2D3D_Algorithm):
466 ## name of the dynamic method in smeshBuilder.Mesh class
468 meshMethod = "Netgen"
469 ## doc string of the method
471 docHelper = "Deprecated, used only for compatibility! See Tetrahedron() method."
473 ## Private constructor.
474 # @param mesh parent mesh object algorithm is assigned to
475 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
476 # if it is @c 0 (default), the algorithm is assigned to the main shape
477 def __init__(self, mesh, geom=0):
478 NETGEN_1D2D3D_Algorithm.__init__(self,mesh, geom)
481 pass # end of NETGEN_1D2D3D_Algorithm_2 class