1 # Copyright (C) 2007-2013 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
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)
222 ## Sets number of segments overriding the value set by SetLocalLength()
223 # @param theVal new value of number of segments parameter
224 def SetNumberOfSegments(self, theVal):
225 self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
228 ## Sets number of segments overriding the value set by SetNumberOfSegments()
229 # @param theVal new value of local length parameter
230 def SetLocalLength(self, theVal):
231 self.Parameters(SIMPLE).SetLocalLength(theVal)
234 ## Defines @c MaxElementArea parameter of @c NETGEN_SimpleParameters_3D hypothesis.
235 # Overrides value set by LengthFromEdges()
236 # @param area new value of @c MaxElementArea parameter
237 def MaxElementArea(self, area):
238 self.Parameters(SIMPLE).SetMaxElementArea(area)
241 ## Defines @c LengthFromEdges parameter of @c NETGEN_SimpleParameters_3D hypothesis.
242 # Overrides value set by MaxElementArea()
243 def LengthFromEdges(self):
244 self.Parameters(SIMPLE).LengthFromEdges()
247 ## Defines @c LengthFromFaces parameter of @c NETGEN_SimpleParameters_3D hypothesis.
248 # Overrides value set by MaxElementVolume()
249 def LengthFromFaces(self):
250 self.Parameters(SIMPLE).LengthFromFaces()
253 ## Defines @c MaxElementVolume parameter of @c NETGEN_SimpleParameters_3D hypothesis.
254 # Overrides value set by LengthFromFaces()
255 # @param vol new value of @c MaxElementVolume parameter
256 def MaxElementVolume(self, vol):
257 self.Parameters(SIMPLE).SetMaxElementVolume(vol)
260 pass # end of NETGEN_1D2D3D_Algorithm class
263 ## Triangle NETGEN 1D-2D algorithm.
265 # It can be created by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_1D2D, geom=0 )
267 # This algorithm generates 1D (edges) and 2D (faces) elements
268 # for given geometrical shape.
269 class NETGEN_1D2D_Algorithm(NETGEN_1D2D3D_Algorithm):
271 ## name of the dynamic method in smeshBuilder.Mesh class
273 meshMethod = "Triangle"
274 ## type of algorithm used with helper function in smeshBuilder.Mesh class
276 algoType = NETGEN_1D2D
277 ## doc string of the method
279 docHelper = "Creates triangle 2D algorithm for faces"
281 ## Private constructor.
282 # @param mesh parent mesh object algorithm is assigned to
283 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
284 # if it is @c 0 (default), the algorithm is assigned to the main shape
285 def __init__(self, mesh, geom=0):
286 NETGEN_1D2D3D_Algorithm.__init__(self, mesh, geom)
289 pass # end of NETGEN_1D2D_Algorithm class
292 ## Triangle NETGEN 2D algorithm
294 # It can be created by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_2D, geom=0 )
296 # This algorithm generates only 2D (faces) elements for given geometrical shape
297 # and, in contrast to NETGEN_1D2D_Algorithm class, should be used in conjunction
298 # with other 1D meshing algorithm.
299 class NETGEN_2D_Only_Algorithm(NETGEN_Algorithm):
301 ## name of the dynamic method in smeshBuilder.Mesh class
303 meshMethod = "Triangle"
304 ## type of algorithm used with helper function in smeshBuilder.Mesh class
307 ## doc string of the method
309 docHelper = "Creates triangle 2D algorithm for faces"
311 ## Private constructor.
312 # @param mesh parent mesh object algorithm is assigned to
313 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
314 # if it is @c 0 (default), the algorithm is assigned to the main shape
315 def __init__(self, mesh, geom=0):
316 NETGEN_Algorithm.__init__(self, mesh, geom)
319 ## Defines @c MaxElementArea parameter of hypothesis basing on the definition of the
320 # maximum area of each triangle
321 # @param area maximum area value of each triangle
322 # @param UseExisting if \c True - searches for an existing hypothesis created with the
323 # same parameters, else (default) - creates a new one
324 # @return hypothesis object
325 def MaxElementArea(self, area, UseExisting=0):
326 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
327 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
328 CompareMethod=compFun)
329 hyp.SetMaxElementArea(area)
332 ## Defines @c LengthFromEdges hypothesis to build triangles
333 # based on the length of the edges taken from the wire
334 # @return hypothesis object
335 def LengthFromEdges(self):
336 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
339 ## Sets @c QuadAllowed flag.
340 # @param toAllow new value of the @c QuadAllowed parameter (@c True by default)
341 # @return hypothesis object
342 def SetQuadAllowed(self, toAllow=True):
345 hasSimpleHyps = False
346 simpleHyps = ["QuadranglePreference","LengthFromEdges","MaxElementArea"]
347 for hyp in self.mesh.GetHypothesisList( self.geom ):
348 if hyp.GetName() in simpleHyps:
350 if hyp.GetName() == "QuadranglePreference":
351 if not toAllow: # remove QuadranglePreference
352 self.mesh.RemoveHypothesis( self.geom, hyp )
359 if toAllow: # add QuadranglePreference
360 return self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
363 self.Parameters().SetQuadAllowed( toAllow )
366 pass # end of NETGEN_2D_Only_Algorithm class
369 ## Tetrahedron 3D algorithm
371 # It can be created by calling smeshBuilder.Mesh.Tetrahedron() or smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN, geom=0 )
373 # This algorithm generates only 3D (volumes) elements for given geometrical shape
374 # and, in contrast to NETGEN_1D2D3D_Algorithm class, should be used in conjunction
375 # with other 1D and 2D meshing algorithms.
376 class NETGEN_3D_Algorithm(NETGEN_Algorithm):
378 ## name of the dynamic method in smeshBuilder.Mesh class
380 meshMethod = "Tetrahedron"
381 ## type of algorithm used with helper function in smeshBuilder.Mesh class
384 ## flag pointing either this algorithm should be used by default in dynamic method
385 # of smeshBuilder.Mesh class
388 ## doc string of the method
390 docHelper = "Creates tetrahedron 3D algorithm for solids"
392 ## Private constructor.
393 # @param mesh parent mesh object algorithm is assigned to
394 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
395 # if it is @c 0 (default), the algorithm is assigned to the main shape
396 def __init__(self, mesh, geom=0):
397 NETGEN_Algorithm.__init__(self, mesh, geom)
400 ## Defines @c MaxElementVolume hypothesis to specify the maximum volume value of each tetrahedron
401 # @param vol maximum volume value of each tetrahedron
402 # @param UseExisting if \c True - searches for the existing hypothesis created with
403 # the same parameters, else (default) - creates a new one
404 # @return hypothesis object
405 def MaxElementVolume(self, vol, UseExisting=0):
406 compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementVolume(), args[0])
407 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
408 CompareMethod=compFun)
409 hyp.SetMaxElementVolume(vol)
412 pass # end of NETGEN_3D_Algorithm class
415 ## Triangle (helper) 1D-2D algorithm
417 # This is the helper class that is used just to allow creating of create NETGEN_1D2D algorithm
418 # by calling smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN, geom=0 ); this is required for backward compatibility
419 # with old Python scripts.
421 # @note This class (and corresponding smeshBuilder.Mesh function) is obsolete;
422 # use smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_1D2D, geom=0 ) instead.
423 class NETGEN_1D2D_Algorithm_2(NETGEN_1D2D_Algorithm):
425 ## name of the dynamic method in smeshBuilder.Mesh class
429 ## Private constructor.
430 # @param mesh parent mesh object algorithm is assigned to
431 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
432 # if it is @c 0 (default), the algorithm is assigned to the main shape
433 def __init__(self, mesh, geom=0):
434 self.algoType = NETGEN_1D2D
435 NETGEN_1D2D_Algorithm.__init__(self,mesh, geom)
438 pass # end of NETGEN_1D2D_Algorithm_2 class
441 ## Tetrahedron (helper) 1D-2D-3D algorithm.
443 # This is the helper class that is used just to allow creating of create NETGEN_1D2D3D
444 # by calling smeshBuilder.Mesh.Netgen(); this is required for backward compatibility with old Python scripts.
446 # @note This class (and corresponding smeshBuilder.Mesh function) is obsolete;
447 # use smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN_1D2D3D, geom=0 ) instead.
448 class NETGEN_1D2D3D_Algorithm_2(NETGEN_1D2D3D_Algorithm):
450 ## name of the dynamic method in smeshBuilder.Mesh class
452 meshMethod = "Netgen"
453 ## doc string of the method
455 docHelper = "Deprecated, used only for compatibility! See Tetrahedron() method."
457 ## Private constructor.
458 # @param mesh parent mesh object algorithm is assigned to
459 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
460 # if it is @c 0 (default), the algorithm is assigned to the main shape
461 def __init__(self, mesh, geom=0):
462 NETGEN_1D2D3D_Algorithm.__init__(self,mesh, geom)
465 pass # end of NETGEN_1D2D3D_Algorithm_2 class