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 if not mesh.GetMesh().HasShapeToMesh() and \
110 self.meshMethod == "Triangle": # create a 2D remesher
111 self.Create(mesh, geom, "NETGEN_Remesher_2D", LIBRARY)
113 self.Create(mesh, geom, self.algoType, LIBRARY)
117 ## Sets @c MaxSize parameter
118 # @param theSize new value of the @c MaxSize parameter
119 def SetMaxSize(self, theSize):
120 if self.Parameters(): self.params.SetMaxSize(theSize)
123 ## Sets @c MinSize parameter
124 # @param theSize new value of the @c MinSize parameter
125 def SetMinSize(self, theSize):
126 if self.Parameters(): self.params.SetMinSize(theSize)
129 ## Sets @c Optimize flag
130 # @param theVal new value of the @c Optimize parameter
131 def SetOptimize(self, theVal):
132 if self.Parameters(): self.params.SetOptimize(theVal)
135 ## Sets @c Fineness parameter
136 # @param theFineness new value of the @c Fineness parameter; it can be:
137 # @ref VeryCoarse, @ref Coarse, @ref Moderate, @ref Fine, @ref VeryFine or @ref Custom
138 def SetFineness(self, theFineness):
139 if self.Parameters(): self.params.SetFineness(theFineness)
142 ## Sets @c GrowthRate parameter
143 # @param theRate new value of the @c GrowthRate parameter
144 def SetGrowthRate(self, theRate):
145 if self.Parameters(): self.params.SetGrowthRate(theRate)
148 ## Creates meshing hypothesis according to the chosen algorithm type
149 # and initializes it with default parameters
150 # @param which hypothesis type; can be either @ref SOLE (default) or @ref SIMPLE
151 # @return hypothesis object
152 def Parameters(self, which=SOLE):
153 if self.algoType == NETGEN_1D2D:
155 hypType = "NETGEN_SimpleParameters_2D"
157 hypType = "NETGEN_Parameters_2D"
158 elif self.algoType == NETGEN_1D2D3D:
160 hypType = "NETGEN_SimpleParameters_3D"
162 hypType = "NETGEN_Parameters"
163 elif self.algoType == NETGEN_2D:
164 hypType = "NETGEN_Parameters_2D_ONLY"
166 hypType = "NETGEN_Parameters_3D"
168 if self.algo.GetName() == "NETGEN_Remesher_2D":
169 hypType = "NETGEN_RemesherParameters_2D"
171 if self.params and self.params.GetName() != hypType:
172 self.mesh.RemoveHypothesis( self.params, self.geom )
175 self.params = self.Hypothesis(hypType, [], LIBRARY, UseExisting=0)
179 ## Defines a file specifying size of elements at points and lines
180 # @param file name of the file
181 def SetMeshSizeFile(self, file):
182 self.Parameters().SetMeshSizeFile(file)
185 pass # end of NETGEN_Algorithm class
188 ## Tetrahedron 1D-2D-3D algorithm.
190 # It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN_1D2D3D, geom=0 ).
191 # This algorithm generates all 1D (edges), 2D (faces) and 3D (volumes) elements
192 # for given geometrical shape.
193 class NETGEN_1D2D3D_Algorithm(NETGEN_Algorithm):
195 ## name of the dynamic method in smeshBuilder.Mesh class
197 meshMethod = "Tetrahedron"
198 ## type of algorithm used with helper function in smeshBuilder.Mesh class
200 algoType = NETGEN_1D2D3D
201 ## doc string of the method
203 docHelper = "Creates tetrahedron 3D algorithm for solids"
205 ## Private constructor.
206 # @param mesh parent mesh object algorithm is assigned to
207 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
208 # if it is @c 0 (default), the algorithm is assigned to the main shape
209 def __init__(self, mesh, geom=0):
210 NETGEN_Algorithm.__init__(self, mesh, geom)
213 ## Sets @c SecondOrder flag
214 # @param theVal new value of the @c SecondOrder parameter
215 def SetSecondOrder(self, theVal):
216 if self.Parameters(): self.params.SetSecondOrder(theVal)
219 ## Sets @c NbSegPerEdge parameter
220 # @param theVal new value of the @c NbSegPerEdge parameter
221 def SetNbSegPerEdge(self, theVal):
222 if self.Parameters(): self.params.SetNbSegPerEdge(theVal)
225 ## Sets @c NbSegPerRadius parameter
226 # @param theVal new value of the @c NbSegPerRadius parameter
227 def SetNbSegPerRadius(self, theVal):
228 if self.Parameters(): self.params.SetNbSegPerRadius(theVal)
231 ## Sets @c ChordalError parameter
232 # @param theVal new value of the @c ChordalError parameter
233 def SetChordalError(self, theVal):
234 if self.Parameters():
235 self.params.SetChordalError(theVal)
236 self.params.SetChordalErrorEnabled( theVal > 0 )
239 ## Sets @c RidgeAngle parameter
240 # @param theVal new value of the @c RidgeAngle parameter
241 def SetRidgeAngle(self, theVal):
242 if self.Parameters():
243 self.params.SetRidgeAngle(theVal)
246 ## Sets @c QuadAllowed flag
247 # @param toAllow new value of the @c QuadAllowed parameter (@c True by default)
248 def SetQuadAllowed(self, toAllow=True):
249 if self.Parameters(): self.params.SetQuadAllowed(toAllow)
251 ## Sets @c UseSurfaceCurvature flag
252 # @param toUse new value of the @c UseSurfaceCurvature parameter (@c True by default)
253 def SetUseSurfaceCurvature(self, toUse=True):
254 if self.Parameters(): self.params.SetUseSurfaceCurvature(toUse)
256 ## Sets @c FuseEdges flag
257 # @param toFuse new value of the @c FuseEdges parameter (@c False by default)
258 def SetFuseEdges(self, toFuse=False):
259 if self.Parameters(): self.params.SetFuseEdges(toFuse)
262 ## Sets number of segments overriding the value set by SetLocalLength()
263 # @param theVal new value of number of segments parameter
264 def SetNumberOfSegments(self, theVal):
265 self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
268 ## Sets number of segments overriding the value set by SetNumberOfSegments()
269 # @param theVal new value of local length parameter
270 def SetLocalLength(self, theVal):
271 self.Parameters(SIMPLE).SetLocalLength(theVal)
274 ## Defines @c MaxElementArea parameter of @c NETGEN_SimpleParameters_3D hypothesis.
275 # Overrides value set by LengthFromEdges()
276 # @param area new value of @c MaxElementArea parameter
277 def MaxElementArea(self, area):
278 self.Parameters(SIMPLE).SetMaxElementArea(area)
281 ## Defines @c LengthFromEdges parameter of @c NETGEN_SimpleParameters_3D hypothesis.
282 # Overrides value set by MaxElementArea()
283 def LengthFromEdges(self):
284 self.Parameters(SIMPLE).LengthFromEdges()
287 ## Defines @c LengthFromFaces parameter of @c NETGEN_SimpleParameters_3D hypothesis.
288 # Overrides value set by MaxElementVolume()
289 def LengthFromFaces(self):
290 self.Parameters(SIMPLE).LengthFromFaces()
293 ## Defines @c MaxElementVolume parameter of @c NETGEN_SimpleParameters_3D hypothesis.
294 # Overrides value set by LengthFromFaces()
295 # @param vol new value of @c MaxElementVolume parameter
296 def MaxElementVolume(self, vol):
297 self.Parameters(SIMPLE).SetMaxElementVolume(vol)
300 pass # end of NETGEN_1D2D3D_Algorithm class
303 ## Triangle NETGEN 1D-2D algorithm.
305 # It can be created by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_1D2D, geom=0 )
307 # This algorithm generates 1D (edges) and 2D (faces) elements
308 # for given geometrical shape.
309 class NETGEN_1D2D_Algorithm(NETGEN_1D2D3D_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
316 algoType = NETGEN_1D2D
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_1D2D3D_Algorithm.__init__(self, mesh, geom)
329 pass # end of NETGEN_1D2D_Algorithm class
332 ## Triangle NETGEN 2D algorithm
334 # It can be created by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_2D, geom=0 )
336 # This algorithm generates only 2D (faces) elements for given geometrical shape
337 # and, in contrast to NETGEN_1D2D_Algorithm class, should be used in conjunction
338 # with other 1D meshing algorithm.
339 class NETGEN_2D_Only_Algorithm(NETGEN_Algorithm):
341 ## name of the dynamic method in smeshBuilder.Mesh class
343 meshMethod = "Triangle"
344 ## type of algorithm used with helper function in smeshBuilder.Mesh class
347 ## doc string of the method
349 docHelper = "Creates triangle 2D algorithm for faces"
351 ## Private constructor.
352 # @param mesh parent mesh object algorithm is assigned to
353 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
354 # if it is @c 0 (default), the algorithm is assigned to the main shape
355 def __init__(self, mesh, geom=0):
356 NETGEN_Algorithm.__init__(self, mesh, geom)
359 ## Defines @c MaxElementArea parameter of hypothesis basing on the definition of the
360 # maximum area of each triangle
361 # @param area maximum area value of each triangle
362 # @param UseExisting if \c True - searches for an existing hypothesis created with the
363 # same parameters, else (default) - creates a new one
364 # @return hypothesis object
365 def MaxElementArea(self, area, UseExisting=0):
366 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
367 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
368 CompareMethod=compFun)
369 hyp.SetMaxElementArea(area)
372 ## Defines @c LengthFromEdges hypothesis to build triangles
373 # based on the length of the edges taken from the wire
374 # @return hypothesis object
375 def LengthFromEdges(self):
376 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
379 ## Sets @c UseSurfaceCurvature flag
380 # @param toUse new value of the @c UseSurfaceCurvature parameter (@c True by default)
381 def SetUseSurfaceCurvature(self, toUse=True):
382 if self.Parameters(): self.params.SetUseSurfaceCurvature(toUse)
385 ## Sets @c QuadAllowed flag.
386 # @param toAllow new value of the @c QuadAllowed parameter (@c True by default)
387 # @return hypothesis object
388 def SetQuadAllowed(self, toAllow=True):
391 hasSimpleHyps = False
392 simpleHyps = ["QuadranglePreference","LengthFromEdges","MaxElementArea"]
393 for hyp in self.mesh.GetHypothesisList( self.geom ):
394 if hyp.GetName() in simpleHyps:
396 if hyp.GetName() == "QuadranglePreference":
397 if not toAllow: # remove QuadranglePreference
398 self.mesh.RemoveHypothesis( self.geom, hyp )
405 if toAllow: # add QuadranglePreference
406 return self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
409 self.Parameters().SetQuadAllowed( toAllow )
412 pass # end of NETGEN_2D_Only_Algorithm class
415 ## Tetrahedron 3D algorithm
417 # It can be created by calling smeshBuilder.Mesh.Tetrahedron() or smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN, geom=0 )
419 # This algorithm generates only 3D (volumes) elements for given geometrical shape
420 # and, in contrast to NETGEN_1D2D3D_Algorithm class, should be used in conjunction
421 # with other 1D and 2D meshing algorithms.
422 class NETGEN_3D_Algorithm(NETGEN_Algorithm):
424 ## name of the dynamic method in smeshBuilder.Mesh class
426 meshMethod = "Tetrahedron"
427 ## type of algorithm used with helper function in smeshBuilder.Mesh class
430 ## flag pointing either this algorithm should be used by default in dynamic method
431 # of smeshBuilder.Mesh class
434 ## doc string of the method
436 docHelper = "Creates tetrahedron 3D algorithm for solids"
438 ## Private constructor.
439 # @param mesh parent mesh object algorithm is assigned to
440 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
441 # if it is @c 0 (default), the algorithm is assigned to the main shape
442 def __init__(self, mesh, geom=0):
443 NETGEN_Algorithm.__init__(self, mesh, geom)
446 ## Defines @c MaxElementVolume hypothesis to specify the maximum volume value of each tetrahedron
447 # @param vol maximum volume value of each tetrahedron
448 # @param UseExisting if \c True - searches for the existing hypothesis created with
449 # the same parameters, else (default) - creates a new one
450 # @return hypothesis object
451 def MaxElementVolume(self, vol, UseExisting=0):
452 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementVolume(), args[0])
453 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
454 CompareMethod=compFun)
455 hyp.SetMaxElementVolume(vol)
458 pass # end of NETGEN_3D_Algorithm class
461 ## Triangle (helper) 1D-2D algorithm
463 # This is the helper class that is used just to allow creating of create NETGEN_1D2D algorithm
464 # by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN, geom=0 ); this is required for backward compatibility
465 # with old Python scripts.
467 # @note This class (and corresponding smeshBuilder.Mesh function) is obsolete;
468 # use smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_1D2D, geom=0 ) instead.
469 class NETGEN_1D2D_Algorithm_2(NETGEN_1D2D_Algorithm):
471 ## name of the dynamic method in smeshBuilder.Mesh class
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 self.algoType = NETGEN_1D2D
481 NETGEN_1D2D_Algorithm.__init__(self,mesh, geom)
484 pass # end of NETGEN_1D2D_Algorithm_2 class
487 ## Tetrahedron (helper) 1D-2D-3D algorithm.
489 # This is the helper class that is used just to allow creating of create NETGEN_1D2D3D
490 # by calling smeshBuilder.Mesh.Netgen(); this is required for backward compatibility with old Python scripts.
492 # @note This class (and corresponding smeshBuilder.Mesh function) is obsolete;
493 # use smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN_1D2D3D, geom=0 ) instead.
494 class NETGEN_1D2D3D_Algorithm_2(NETGEN_1D2D3D_Algorithm):
496 ## name of the dynamic method in smeshBuilder.Mesh class
498 meshMethod = "Netgen"
499 ## doc string of the method
501 docHelper = "Deprecated, used only for compatibility! See Tetrahedron() method."
503 ## Private constructor.
504 # @param mesh parent mesh object algorithm is assigned to
505 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
506 # if it is @c 0 (default), the algorithm is assigned to the main shape
507 def __init__(self, mesh, geom=0):
508 NETGEN_1D2D3D_Algorithm.__init__(self,mesh, geom)
511 pass # end of NETGEN_1D2D3D_Algorithm_2 class