diff --git a/src/NETGENPlugin/Makefile.am b/src/NETGENPlugin/Makefile.am index f3e9f17..c26697a 100644 --- a/src/NETGENPlugin/Makefile.am +++ b/src/NETGENPlugin/Makefile.am @@ -101,3 +101,6 @@ libNETGENEngine_la_LDFLAGS += \ $(MED_LDFLAGS) -lSalomeIDLMED \ $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine -lSMESHUtils -lStdMeshersEngine -lStdMeshers -lSMESHDS -lSMDS -lSMESHControls \ $(KERNEL_LDFLAGS) -lSalomeGenericObj -lSalomeNS -lSALOMELocalTrace -lOpUtil + +# Scripts to be installed. +dist_salomescript_DATA= NETGENPluginDC.py diff --git a/src/NETGENPlugin/NETGENPluginDC.py b/src/NETGENPlugin/NETGENPluginDC.py new file mode 100644 index 0000000..fe5822d --- /dev/null +++ b/src/NETGENPlugin/NETGENPluginDC.py @@ -0,0 +1,326 @@ +# Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# + +from smesh import Mesh_Algorithm, AssureGeomPublished, ParseParameters + +# import NETGENPlugin module if possible +noNETGENPlugin = 0 +try: + import NETGENPlugin +except ImportError: + noNETGENPlugin = 1 + pass + +# Types of algorithms +NETGEN_3D = "NETGEN_3D" +NETGEN_1D2D3D = "NETGEN_2D3D" +NETGEN_1D2D = "NETGEN_2D" +NETGEN_2D = "NETGEN_2D_ONLY" +NETGEN_FULL = NETGEN_1D2D3D +NETGEN = NETGEN_3D +FULL_NETGEN = NETGEN_FULL + +SOLE = 0 +SIMPLE = 1 + +# Fineness enumeration +VeryCoarse = 0 +Coarse = 1 +Moderate = 2 +Fine = 3 +VeryFine = 4 +Custom = 5 + +## Base of all NETGEN algorithms. +# +# @ingroup l3_algos_basic +class NETGEN_Algorithm(Mesh_Algorithm): + + def __init__(self, mesh, geom=0): + Mesh_Algorithm.__init__(self) + if noNETGENPlugin: print "Warning: NETGENPlugin module unavailable" + self.Create(mesh, geom, self.algoType, "libNETGENEngine.so") + self.params = None + + ## Sets MaxSize + # + # @ingroup l3_hypos_netgen + def SetMaxSize(self, theSize): + if self.Parameters(): + self.params.SetMaxSize(theSize) + + ## Sets MinSize + # + # @ingroup l3_hypos_netgen + def SetMinSize(self, theSize): + if self.Parameters(): + self.params.SetMinSize(theSize) + + + ## Sets Optimize flag + # + # @ingroup l3_hypos_netgen + def SetOptimize(self, theVal): + if self.Parameters(): + self.params.SetOptimize(theVal) + + ## Sets Fineness + # @param theFineness is: + # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom + # + # @ingroup l3_hypos_netgen + def SetFineness(self, theFineness): + if self.Parameters(): + self.params.SetFineness(theFineness) + + ## Sets GrowthRate + # + # @ingroup l3_hypos_netgen + def SetGrowthRate(self, theRate): + if self.Parameters(): + self.params.SetGrowthRate(theRate) + + ## Defines hypothesis having several parameters + # + # @ingroup l3_hypos_netgen + def Parameters(self, which=SOLE): + if self.algoType == NETGEN_1D2D: + if which == SIMPLE: + hypType = "NETGEN_SimpleParameters_2D" + else: + hypType = "NETGEN_Parameters_2D" + elif self.algoType == NETGEN_1D2D3D: + if which == SIMPLE: + hypType = "NETGEN_SimpleParameters_3D" + else: + hypType = "NETGEN_Parameters" + elif self.algoType == NETGEN_2D: + hypType = "NETGEN_Parameters_2D_ONLY" + else: + hypType = "NETGEN_Parameters_3D" + + if self.params and self.params.GetName() != hypType: + self.mesh.RemoveHypothesis( self.params, self.geom ) + self.params = None + if not self.params: + self.params = self.Hypothesis(hypType, [],"libNETGENEngine.so",UseExisting=0) + + return self.params + + + +## Defines a tetrahedron 1D-2D-3D algorithm +# It is created by calling Mesh.Triangle( NETGEN_1D2D3D, geom=0 ) +# +# @ingroup l3_algos_basic +class NETGEN_1D2D3D_Algorithm(NETGEN_Algorithm): + + meshMethod = "Tetrahedron" + algoType = NETGEN_1D2D3D + + ## Private constructor. + def __init__(self, mesh, geom=0): + NETGEN_Algorithm.__init__(self, mesh, geom) + + ## Sets SecondOrder flag + # + # @ingroup l3_hypos_netgen + def SetSecondOrder(self, theVal): + if self.Parameters(): + self.params.SetSecondOrder(theVal) + + ## Sets NbSegPerEdge + # + # @ingroup l3_hypos_netgen + def SetNbSegPerEdge(self, theVal): + if self.Parameters(): + self.params.SetNbSegPerEdge(theVal) + + ## Sets NbSegPerRadius + # + # @ingroup l3_hypos_netgen + def SetNbSegPerRadius(self, theVal): + if self.Parameters(): + self.params.SetNbSegPerRadius(theVal) + + + ## Sets number of segments overriding the value set by SetLocalLength() + # + # @ingroup l3_hypos_netgen + def SetNumberOfSegments(self, theVal): + self.Parameters(SIMPLE).SetNumberOfSegments(theVal) + + ## Sets number of segments overriding the value set by SetNumberOfSegments() + # + # @ingroup l3_hypos_netgen + def SetLocalLength(self, theVal): + self.Parameters(SIMPLE).SetLocalLength(theVal) + + ## Defines "MaxElementArea" parameter of NETGEN_SimpleParameters_3D hypothesis. + # Overrides value set by LengthFromEdges() + # @ingroup l3_hypos_netgen + def MaxElementArea(self, area): + self.Parameters(SIMPLE).SetMaxElementArea(area) + + ## Defines "LengthFromEdges" parameter of NETGEN_SimpleParameters_3D hypothesis + # Overrides value set by MaxElementArea() + # @ingroup l3_hypos_netgen + def LengthFromEdges(self): + self.Parameters(SIMPLE).LengthFromEdges() + + ## Defines "LengthFromFaces" parameter of NETGEN_SimpleParameters_3D hypothesis + # Overrides value set by MaxElementVolume() + # @ingroup l3_hypos_netgen + def LengthFromFaces(self): + self.Parameters(SIMPLE).LengthFromFaces() + + ## Defines "MaxElementVolume" parameter of NETGEN_SimpleParameters_3D hypothesis + # Overrides value set by LengthFromFaces() + # @ingroup l3_hypos_netgen + def MaxElementVolume(self, vol): + self.Parameters(SIMPLE).SetMaxElementVolume(vol) + + +## Triangle NETGEN 1D-2D algorithm. +# It is created by calling Mesh.Triangle( NETGEN_1D2D, geom=0 ) +# +# @ingroup l3_algos_basic +class NETGEN_1D2D_Algorithm(NETGEN_1D2D3D_Algorithm): + + meshMethod = "Triangle" + algoType = NETGEN_1D2D + + ## Private constructor. + def __init__(self, mesh, geom=0): + NETGEN_1D2D3D_Algorithm.__init__(self, mesh, geom) + + ## Sets QuadAllowed flag. + # @ingroup l3_hypos_netgen + def SetQuadAllowed(self, toAllow=True): + if self.Parameters(): + self.params.SetQuadAllowed(toAllow) + + + +## Triangle NETGEN 2D algorithm +# It is created by calling Mesh.Triangle( NETGEN_2D, geom=0 ) +# +# @ingroup l3_algos_basic +class NETGEN_2D_Only_Algorithm(NETGEN_Algorithm): + + meshMethod = "Triangle" + algoType = NETGEN_2D + + ## Private constructor. + def __init__(self, mesh, geom=0): + NETGEN_Algorithm.__init__(self, mesh, geom) + + ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle + # @param area for the maximum area of each triangle + # @param UseExisting if ==true - searches for an existing hypothesis created with the + # same parameters, else (default) - creates a new one + # + # @ingroup l3_hypos_2dhyps + def MaxElementArea(self, area, UseExisting=0): + compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0]) + hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting, + CompareMethod=compFun) + hyp.SetMaxElementArea(area) + return hyp + + ## Defines "LengthFromEdges" hypothesis to build triangles + # based on the length of the edges taken from the wire + # + # @ingroup l3_hypos_2dhyps + def LengthFromEdges(self): + hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp) + return hyp + + ## Sets QuadAllowed flag. + # @ingroup l3_hypos_netgen + def SetQuadAllowed(self, toAllow=True): + if not self.params: + # use simple hyps + hasSimpleHyps = False + simpleHyps = ["QuadranglePreference","LengthFromEdges","MaxElementArea"] + for hyp in self.mesh.GetHypothesisList( self.geom ): + if hyp.GetName() in simpleHyps: + hasSimpleHyps = True + if hyp.GetName() == "QuadranglePreference": + if not toAllow: # remove QuadranglePreference + self.mesh.RemoveHypothesis( self.geom, hyp ) + else: + return hyp + return None + pass + pass + if hasSimpleHyps: + if toAllow: # add QuadranglePreference + return self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp) + return None + pass + self.Parameters().SetQuadAllowed( toAllow ) + return self.params + +## Defines a tetrahedron 3D algorithm +# It is created by calling Mesh.Tetrahedron() +# +# @ingroup l3_algos_basic +class NETGEN_3D_Algorithm(NETGEN_Algorithm): + + meshMethod = "Tetrahedron" + algoType = NETGEN + isDefault = True + + ## Private constructor. + def __init__(self, mesh, geom=0): + NETGEN_Algorithm.__init__(self, mesh, geom) + + ## Defines "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedron + # @param vol for the maximum volume of each tetrahedron + # @param UseExisting if ==true - searches for the existing hypothesis created with + # the same parameters, else (default) - creates a new one + # @ingroup l3_hypos_maxvol + def MaxElementVolume(self, vol, UseExisting=0): + compFun = lambda hyp, args: IsEqual(hyp.GetMaxElementVolume(), args[0]) + hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting, + CompareMethod=compFun) + hyp.SetMaxElementVolume(vol) + return hyp + + +# Class just to create NETGEN_1D2D by calling Mesh.Triangle(NETGEN) +class NETGEN_1D2D_Algorithm_2(NETGEN_1D2D_Algorithm): + + algoType = NETGEN + + ## Private constructor. + def __init__(self, mesh, geom=0): + NETGEN_1D2D_Algorithm.__init__(self,mesh, geom) + + +# Class just to create NETGEN_1D2D3D by calling Mesh.Netgen() +class NETGEN_1D2D3D_Algorithm_2(NETGEN_1D2D3D_Algorithm): + + meshMethod = "Netgen" + + ## Private constructor. + def __init__(self, mesh, geom=0): + NETGEN_1D2D3D_Algorithm.__init__(self,mesh, geom)