1 # Copyright (C) 2007-2016 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 LIBRARY = "libNETGENEngine.so"
37 #----------------------------
38 # Mesh algo type identifiers
39 #----------------------------
41 ## Algorithm type: Netgen tetrahedron 3D algorithm, see NETGEN_3D_Algorithm
42 NETGEN_3D = "NETGEN_3D"
43 ## Algorithm type: Netgen tetrahedron 1D-2D-3D algorithm, see NETGEN_1D2D3D_Algorithm
44 NETGEN_1D2D3D = "NETGEN_2D3D"
45 ## Algorithm type: Netgen triangle 1D-2D algorithm, see NETGEN_1D2D_Algorithm
46 NETGEN_1D2D = "NETGEN_2D"
47 ## Algorithm type: Netgen triangle 2D algorithm, see NETGEN_2D_Only_Algorithm
48 NETGEN_2D = "NETGEN_2D_ONLY"
49 ## Algorithm type: Synonim of NETGEN_1D2D3D, see NETGEN_1D2D3D_Algorithm
50 NETGEN_FULL = NETGEN_1D2D3D
51 ## Algorithm type: Synonim of NETGEN_3D, see NETGEN_3D_Algorithm
53 ## Algorithm type: Synonim of NETGEN_1D2D3D, see NETGEN_1D2D3D_Algorithm
54 FULL_NETGEN = NETGEN_FULL
56 #----------------------------
57 # Hypothesis type enumeration
58 #----------------------------
60 ## Hypothesis type enumeration: complex hypothesis
61 # (full set of parameters can be specified),
62 # see NETGEN_Algorithm.Parameters()
64 ## Hypothesis type enumeration: simple hypothesis
65 # (only major parameters are specified),
66 # see NETGEN_Algorithm.Parameters()
69 #----------------------
70 # Fineness enumeration
71 #----------------------
73 ## Fineness enumeration: very coarse quality of mesh,
74 # see NETGEN_Algorithm.SetFineness()
76 ## Fineness enumeration: coarse quality of mesh,
77 # see NETGEN_Algorithm.SetFineness()
79 ## Fineness enumeration: moderate quality of mesh,
80 # see NETGEN_Algorithm.SetFineness()
82 ## Fineness enumeration: fine quality of mesh,
83 # see NETGEN_Algorithm.SetFineness()
85 ## Fineness enumeration: very fine quality of mesh,
86 # see NETGEN_Algorithm.SetFineness()
88 ## Fineness enumeration: custom quality of mesh specified by other parameters),
89 # see NETGEN_Algorithm.SetFineness()
92 #----------------------
94 #----------------------
96 ## Base of all NETGEN algorithms.
98 # This class provides common methods for all algorithms implemented by NETGEN plugin.
99 # @note This class must not be instantiated directly.
100 class NETGEN_Algorithm(Mesh_Algorithm):
102 ## Private constructor
103 # @param mesh parent mesh object algorithm is assigned to
104 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
105 # if it is @c 0 (default), the algorithm is assigned to the main shape
106 def __init__(self, mesh, geom=0):
107 Mesh_Algorithm.__init__(self)
108 if noNETGENPlugin: print "Warning: NETGENPlugin module unavailable"
109 self.Create(mesh, geom, self.algoType, LIBRARY)
113 ## Sets @c MaxSize parameter
114 # @param theSize new value of the @c MaxSize parameter
115 def SetMaxSize(self, theSize):
116 if self.Parameters(): self.params.SetMaxSize(theSize)
119 ## Sets @c MinSize parameter
120 # @param theSize new value of the @c MinSize parameter
121 def SetMinSize(self, theSize):
122 if self.Parameters(): self.params.SetMinSize(theSize)
125 ## Sets @c Optimize flag
126 # @param theVal new value of the @c Optimize parameter
127 def SetOptimize(self, theVal):
128 if self.Parameters(): self.params.SetOptimize(theVal)
131 ## Sets @c Fineness parameter
132 # @param theFineness new value of the @c Fineness parameter; it can be:
133 # @ref VeryCoarse, @ref Coarse, @ref Moderate, @ref Fine, @ref VeryFine or @ref Custom
134 def SetFineness(self, theFineness):
135 if self.Parameters(): self.params.SetFineness(theFineness)
138 ## Sets @c GrowthRate parameter
139 # @param theRate new value of the @c GrowthRate parameter
140 def SetGrowthRate(self, theRate):
141 if self.Parameters(): self.params.SetGrowthRate(theRate)
144 ## Creates meshing hypothesis according to the chosen algorithm type
145 # and initializes it with default parameters
146 # @param which hypothesis type; can be either @ref SOLE (default) or @ref SIMPLE
147 # @return hypothesis object
148 def Parameters(self, which=SOLE):
149 if self.algoType == NETGEN_1D2D:
151 hypType = "NETGEN_SimpleParameters_2D"
153 hypType = "NETGEN_Parameters_2D"
154 elif self.algoType == NETGEN_1D2D3D:
156 hypType = "NETGEN_SimpleParameters_3D"
158 hypType = "NETGEN_Parameters"
159 elif self.algoType == NETGEN_2D:
160 hypType = "NETGEN_Parameters_2D_ONLY"
162 hypType = "NETGEN_Parameters_3D"
164 if self.params and self.params.GetName() != hypType:
165 self.mesh.RemoveHypothesis( self.params, self.geom )
168 self.params = self.Hypothesis(hypType, [], LIBRARY, UseExisting=0)
172 pass # end of NETGEN_Algorithm class
175 ## Tetrahedron 1D-2D-3D algorithm.
177 # It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN_1D2D3D, geom=0 ).
178 # This algorithm generates all 1D (edges), 2D (faces) and 3D (volumes) elements
179 # for given geometrical shape.
180 class NETGEN_1D2D3D_Algorithm(NETGEN_Algorithm):
182 ## name of the dynamic method in smeshBuilder.Mesh class
184 meshMethod = "Tetrahedron"
185 ## type of algorithm used with helper function in smeshBuilder.Mesh class
187 algoType = NETGEN_1D2D3D
188 ## doc string of the method
190 docHelper = "Creates tetrahedron 3D algorithm for solids"
192 ## Private constructor.
193 # @param mesh parent mesh object algorithm is assigned to
194 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
195 # if it is @c 0 (default), the algorithm is assigned to the main shape
196 def __init__(self, mesh, geom=0):
197 NETGEN_Algorithm.__init__(self, mesh, geom)
200 ## Sets @c SecondOrder flag
201 # @param theVal new value of the @c SecondOrder parameter
202 def SetSecondOrder(self, theVal):
203 if self.Parameters(): self.params.SetSecondOrder(theVal)
206 ## Sets @c NbSegPerEdge parameter
207 # @param theVal new value of the @c NbSegPerEdge parameter
208 def SetNbSegPerEdge(self, theVal):
209 if self.Parameters(): self.params.SetNbSegPerEdge(theVal)
212 ## Sets @c NbSegPerRadius parameter
213 # @param theVal new value of the @c NbSegPerRadius parameter
214 def SetNbSegPerRadius(self, theVal):
215 if self.Parameters(): self.params.SetNbSegPerRadius(theVal)
218 ## Sets @c QuadAllowed flag
219 # @param toAllow new value of the @c QuadAllowed parameter (@c True by default)
220 def SetQuadAllowed(self, toAllow=True):
221 if self.Parameters(): self.params.SetQuadAllowed(toAllow)
223 ## Sets @c UseSurfaceCurvature flag
224 # @param toUse new value of the @c UseSurfaceCurvature parameter (@c True by default)
225 def SetUseSurfaceCurvature(self, toUse=True):
226 if self.Parameters(): self.params.SetUseSurfaceCurvature(toUse)
228 ## Sets @c FuseEdges flag
229 # @param toFuse new value of the @c FuseEdges parameter (@c False by default)
230 def SetFuseEdges(self, toFuse=False):
231 if self.Parameters(): self.params.SetFuseEdges(toFuse)
234 ## Sets number of segments overriding the value set by SetLocalLength()
235 # @param theVal new value of number of segments parameter
236 def SetNumberOfSegments(self, theVal):
237 self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
240 ## Sets number of segments overriding the value set by SetNumberOfSegments()
241 # @param theVal new value of local length parameter
242 def SetLocalLength(self, theVal):
243 self.Parameters(SIMPLE).SetLocalLength(theVal)
246 ## Defines @c MaxElementArea parameter of @c NETGEN_SimpleParameters_3D hypothesis.
247 # Overrides value set by LengthFromEdges()
248 # @param area new value of @c MaxElementArea parameter
249 def MaxElementArea(self, area):
250 self.Parameters(SIMPLE).SetMaxElementArea(area)
253 ## Defines @c LengthFromEdges parameter of @c NETGEN_SimpleParameters_3D hypothesis.
254 # Overrides value set by MaxElementArea()
255 def LengthFromEdges(self):
256 self.Parameters(SIMPLE).LengthFromEdges()
259 ## Defines @c LengthFromFaces parameter of @c NETGEN_SimpleParameters_3D hypothesis.
260 # Overrides value set by MaxElementVolume()
261 def LengthFromFaces(self):
262 self.Parameters(SIMPLE).LengthFromFaces()
265 ## Defines @c MaxElementVolume parameter of @c NETGEN_SimpleParameters_3D hypothesis.
266 # Overrides value set by LengthFromFaces()
267 # @param vol new value of @c MaxElementVolume parameter
268 def MaxElementVolume(self, vol):
269 self.Parameters(SIMPLE).SetMaxElementVolume(vol)
272 pass # end of NETGEN_1D2D3D_Algorithm class
275 ## Triangle NETGEN 1D-2D algorithm.
277 # It can be created by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_1D2D, geom=0 )
279 # This algorithm generates 1D (edges) and 2D (faces) elements
280 # for given geometrical shape.
281 class NETGEN_1D2D_Algorithm(NETGEN_1D2D3D_Algorithm):
283 ## name of the dynamic method in smeshBuilder.Mesh class
285 meshMethod = "Triangle"
286 ## type of algorithm used with helper function in smeshBuilder.Mesh class
288 algoType = NETGEN_1D2D
289 ## doc string of the method
291 docHelper = "Creates triangle 2D algorithm for faces"
293 ## Private constructor.
294 # @param mesh parent mesh object algorithm is assigned to
295 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
296 # if it is @c 0 (default), the algorithm is assigned to the main shape
297 def __init__(self, mesh, geom=0):
298 NETGEN_1D2D3D_Algorithm.__init__(self, mesh, geom)
301 pass # end of NETGEN_1D2D_Algorithm class
304 ## Triangle NETGEN 2D algorithm
306 # It can be created by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_2D, geom=0 )
308 # This algorithm generates only 2D (faces) elements for given geometrical shape
309 # and, in contrast to NETGEN_1D2D_Algorithm class, should be used in conjunction
310 # with other 1D meshing algorithm.
311 class NETGEN_2D_Only_Algorithm(NETGEN_Algorithm):
313 ## name of the dynamic method in smeshBuilder.Mesh class
315 meshMethod = "Triangle"
316 ## type of algorithm used with helper function in smeshBuilder.Mesh class
319 ## doc string of the method
321 docHelper = "Creates triangle 2D algorithm for faces"
323 ## Private constructor.
324 # @param mesh parent mesh object algorithm is assigned to
325 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
326 # if it is @c 0 (default), the algorithm is assigned to the main shape
327 def __init__(self, mesh, geom=0):
328 NETGEN_Algorithm.__init__(self, mesh, geom)
331 ## Defines @c MaxElementArea parameter of hypothesis basing on the definition of the
332 # maximum area of each triangle
333 # @param area maximum area value of each triangle
334 # @param UseExisting if \c True - searches for an existing hypothesis created with the
335 # same parameters, else (default) - creates a new one
336 # @return hypothesis object
337 def MaxElementArea(self, area, UseExisting=0):
338 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
339 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
340 CompareMethod=compFun)
341 hyp.SetMaxElementArea(area)
344 ## Defines @c LengthFromEdges hypothesis to build triangles
345 # based on the length of the edges taken from the wire
346 # @return hypothesis object
347 def LengthFromEdges(self):
348 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
351 ## Sets @c UseSurfaceCurvature flag
352 # @param toUse new value of the @c UseSurfaceCurvature parameter (@c True by default)
353 def SetUseSurfaceCurvature(self, toUse=True):
354 if self.Parameters(): self.params.SetUseSurfaceCurvature(toUse)
357 ## Sets @c QuadAllowed flag.
358 # @param toAllow new value of the @c QuadAllowed parameter (@c True by default)
359 # @return hypothesis object
360 def SetQuadAllowed(self, toAllow=True):
363 hasSimpleHyps = False
364 simpleHyps = ["QuadranglePreference","LengthFromEdges","MaxElementArea"]
365 for hyp in self.mesh.GetHypothesisList( self.geom ):
366 if hyp.GetName() in simpleHyps:
368 if hyp.GetName() == "QuadranglePreference":
369 if not toAllow: # remove QuadranglePreference
370 self.mesh.RemoveHypothesis( self.geom, hyp )
377 if toAllow: # add QuadranglePreference
378 return self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
381 self.Parameters().SetQuadAllowed( toAllow )
384 pass # end of NETGEN_2D_Only_Algorithm class
387 ## Tetrahedron 3D algorithm
389 # It can be created by calling smeshBuilder.Mesh.Tetrahedron() or smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN, geom=0 )
391 # This algorithm generates only 3D (volumes) elements for given geometrical shape
392 # and, in contrast to NETGEN_1D2D3D_Algorithm class, should be used in conjunction
393 # with other 1D and 2D meshing algorithms.
394 class NETGEN_3D_Algorithm(NETGEN_Algorithm):
396 ## name of the dynamic method in smeshBuilder.Mesh class
398 meshMethod = "Tetrahedron"
399 ## type of algorithm used with helper function in smeshBuilder.Mesh class
402 ## flag pointing either this algorithm should be used by default in dynamic method
403 # of smeshBuilder.Mesh class
406 ## doc string of the method
408 docHelper = "Creates tetrahedron 3D algorithm for solids"
410 ## Private constructor.
411 # @param mesh parent mesh object algorithm is assigned to
412 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
413 # if it is @c 0 (default), the algorithm is assigned to the main shape
414 def __init__(self, mesh, geom=0):
415 NETGEN_Algorithm.__init__(self, mesh, geom)
418 ## Defines @c MaxElementVolume hypothesis to specify the maximum volume value of each tetrahedron
419 # @param vol maximum volume value of each tetrahedron
420 # @param UseExisting if \c True - searches for the existing hypothesis created with
421 # the same parameters, else (default) - creates a new one
422 # @return hypothesis object
423 def MaxElementVolume(self, vol, UseExisting=0):
424 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementVolume(), args[0])
425 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
426 CompareMethod=compFun)
427 hyp.SetMaxElementVolume(vol)
430 pass # end of NETGEN_3D_Algorithm class
433 ## Triangle (helper) 1D-2D algorithm
435 # This is the helper class that is used just to allow creating of create NETGEN_1D2D algorithm
436 # by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN, geom=0 ); this is required for backward compatibility
437 # with old Python scripts.
439 # @note This class (and corresponding smeshBuilder.Mesh function) is obsolete;
440 # use smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_1D2D, geom=0 ) instead.
441 class NETGEN_1D2D_Algorithm_2(NETGEN_1D2D_Algorithm):
443 ## name of the dynamic method in smeshBuilder.Mesh class
447 ## Private constructor.
448 # @param mesh parent mesh object algorithm is assigned to
449 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
450 # if it is @c 0 (default), the algorithm is assigned to the main shape
451 def __init__(self, mesh, geom=0):
452 self.algoType = NETGEN_1D2D
453 NETGEN_1D2D_Algorithm.__init__(self,mesh, geom)
456 pass # end of NETGEN_1D2D_Algorithm_2 class
459 ## Tetrahedron (helper) 1D-2D-3D algorithm.
461 # This is the helper class that is used just to allow creating of create NETGEN_1D2D3D
462 # by calling smeshBuilder.Mesh.Netgen(); this is required for backward compatibility with old Python scripts.
464 # @note This class (and corresponding smeshBuilder.Mesh function) is obsolete;
465 # use smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN_1D2D3D, geom=0 ) instead.
466 class NETGEN_1D2D3D_Algorithm_2(NETGEN_1D2D3D_Algorithm):
468 ## name of the dynamic method in smeshBuilder.Mesh class
470 meshMethod = "Netgen"
471 ## doc string of the method
473 docHelper = "Deprecated, used only for compatibility! See Tetrahedron() method."
475 ## Private constructor.
476 # @param mesh parent mesh object algorithm is assigned to
477 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
478 # if it is @c 0 (default), the algorithm is assigned to the main shape
479 def __init__(self, mesh, geom=0):
480 NETGEN_1D2D3D_Algorithm.__init__(self,mesh, geom)
483 pass # end of NETGEN_1D2D3D_Algorithm_2 class