Salome HOME
Copyright update 2022
[plugins/ghs3dplugin.git] / src / GHS3DPlugin / GHS3DPluginBuilder.py
index d0b96248dfbe0a22a4cd7a127c6ef2ba30dafc1b..06f1a875a8afd1121dcddf1a1c3ce7a8945bd777 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+# Copyright (C) 2007-2022  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -21,6 +21,7 @@
 # @package GHS3DPluginBuilder
 # Python API for the MG-Tetra meshing plug-in module.
 
+import omniORB
 from salome.smesh.smesh_algorithm import Mesh_Algorithm
 from salome.smesh.smeshBuilder import AssureGeomPublished
 
@@ -38,6 +39,12 @@ None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization
 # V4.1 (partialy redefines V3.1). Issue 0020574
 None_Optimization, Light_Optimization, Standard_Optimization, StandardPlus_Optimization, Strong_Optimization = 0,1,2,3,4
 
+# import items of enums
+for e in GHS3DPlugin.Mode._items: exec('%s = GHS3DPlugin.%s'%(e,e))
+for e in GHS3DPlugin.PThreadsMode._items: exec('%s = GHS3DPlugin.%s'%(e,e))
+Mode_NO, Mode_YES, Mode_ONLY = GHS3DPlugin.Mode._items
+Mode_SAFE, Mode_AGGRESSIVE, Mode_NONE = GHS3DPlugin.PThreadsMode._items
+
 #----------------------------
 # Mesh algo type identifiers
 #----------------------------
@@ -45,6 +52,7 @@ None_Optimization, Light_Optimization, Standard_Optimization, StandardPlus_Optim
 ## Algorithm type: MG-Tetra tetrahedron 3D algorithm, see GHS3D_Algorithm
 MG_Tetra = "MG-Tetra"
 GHS3D = MG_Tetra
+MG_Tetra_Optimization = "MG-Tetra Optimization"
 
 ## Tetrahedron MG-Tetra 3D algorithm
 #  
@@ -59,7 +67,7 @@ class GHS3D_Algorithm(Mesh_Algorithm):
     algoType   = MG_Tetra
     ## doc string of the method in smeshBuilder.Mesh class
     #  @internal
-    docHelper  = "Creates tetrahedron 3D algorithm for volumes"
+    docHelper  = "Creates tetrahedron 3D algorithm"
 
     ## Private constructor.
     #  @param mesh parent mesh object algorithm is assigned to
@@ -67,7 +75,7 @@ class GHS3D_Algorithm(Mesh_Algorithm):
     #              if it is @c 0 (default), the algorithm is assigned to the main shape
     def __init__(self, mesh, geom=0):
         Mesh_Algorithm.__init__(self)
-        if noGHS3DPlugin: print "Warning: GHS3DPlugin module unavailable"
+        if noGHS3DPlugin: print("Warning: GHS3DPlugin module unavailable")
         self.Create(mesh, geom, self.algoType, "libGHS3DEngine.so")
         self.params = None
         pass
@@ -81,6 +89,30 @@ class GHS3D_Algorithm(Mesh_Algorithm):
             pass
         return self.params
 
+    ## Set lower boundary of mesh element size
+    #  Set it to zero to deactivate this option
+    def SetMinSize(self, theMinSize):
+        self.Parameters().SetMinSize(theMinSize)
+        return
+
+    ## Set upper boundary of mesh element size
+    #  Set it to zero to deactivate this option
+    def SetMaxSize(self, theMaxSize):
+        self.Parameters().SetMaxSize(theMaxSize)
+        return
+
+    ## Activate/deactivate volume proximity computation
+    #
+    def SetVolumeProximity(self, toUse ):
+        self.Parameters().SetVolumeProximity(toUse)
+        return
+
+    ## Set number of surface element layers to be generated due to volume proximity
+    #
+    def SetNbVolumeProximityLayers(self, nbLayers ):
+        self.Parameters().SetNbVolumeProximityLayers(nbLayers)
+        return
+
     ## To mesh "holes" in a solid or not. Default is to mesh.
     #  @param toMesh "mesh holes" flag value
     def SetToMeshHoles(self, toMesh):
@@ -257,10 +289,203 @@ class GHS3D_Algorithm(Mesh_Algorithm):
             pass
         pass
 
+    ## Set advanced option value
+    #  @param optionName option name
+    #  @param optionValue option value
+    def SetOptionValue(self, optionName, optionValue):
+        self.Parameters().SetOptionValue( optionName, optionValue )
+        pass
+    
     ## Sets command line option as text.
+    #  @param optionAndValue command line option in a form "option value"
+    def SetAdvancedOption(self, optionAndValue):
+        self.Parameters().SetAdvancedOption(optionAndValue)
+        pass
+    
+    ## OBSOLETE Sets command line option as text.
     #  @param option command line option
     def SetTextOption(self, option):
-        self.Parameters().SetTextOption(option)
+        self.Parameters().SetAdvancedOption(option)
         pass
     
     pass # end of GHS3D_Algorithm class
+
+
+## MG-Tetra Optimization algorithm - optimizer of tetrahedral meshes
+#
+#  It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.MG_Tetra_Optimization )
+class GHS3D_Optimizer(GHS3D_Algorithm):
+
+    ## name of the dynamic method in smeshBuilder.Mesh class
+    #  @internal
+    meshMethod = "Tetrahedron"
+    ## type of algorithm used with helper function in smeshBuilder.Mesh class
+    #  @internal
+    algoType   = MG_Tetra_Optimization
+    ## doc string of the method in smeshBuilder.Mesh class
+    #  @internal
+    docHelper  = "Creates MG-Tetra optimizer of tetrahedral meshes"
+
+    ## Private constructor.
+    #  @param mesh parent mesh object algorithm is assigned to
+    #  @param geom - not used
+    def __init__(self, mesh, geom=0):
+        GHS3D_Algorithm.__init__(self, mesh)
+
+        # remove some inherited methods
+        # del self.SetToMeshHoles
+        # del self.SetToMakeGroupsOfDomains
+        # del self.SetToUseBoundaryRecoveryVersion
+        # del self.SetFEMCorrection
+        # del self.SetToRemoveCentralPoint
+        # del self.SetEnforcedVertex
+        # del self.SetEnforcedVertexGeom
+        # del self.RemoveEnforcedVertex
+        # del self.RemoveEnforcedVertexGeom
+        # del self.SetEnforcedMesh
+        # del self.SetTextOption
+        pass
+
+    ## Defines hypothesis having several parameters
+    #  @return hypothesis object
+    def Parameters(self):
+        if not self.params:
+            self.params = self.Hypothesis("MG-Tetra Optimization Parameters", [],
+                                          "libGHS3DEngine.so", UseExisting=0)
+            pass
+        return self.params
+
+    ## Set Optimization mode
+    #  @param optMode optimization mode, one of the following values:
+    #  smeshBuilder.Mode_NO,
+    #  smeshBuilder.Mode_YES (default),
+    #  smeshBuilder.MODE_ONLY
+    def SetOptimizationOnly(self, optMode ):
+        self.Parameters().SetOptimizationOnly(optMode)
+        pass
+
+    ## Set mode of splitting over-constrained elements
+    #  @param ovcMode, one of the following values
+    #  smeshBuilder.Mode_NO (default),
+    #  smeshBuilder.Mode_YES,
+    #  smeshBuilder.Mode_ONLY
+    def SetSplitOverConstrained(self, ovcMode ):
+        self.Parameters().SetSplitOverConstrained(ovcMode)
+        pass
+
+    ## Activate smoothing sliver elements:
+    #  @param toSmooth - Boolean flag
+    def SetSmoothOffSlivers(self, toSmooth ):
+        self.Parameters().SetSmoothOffSlivers(toSmooth)
+        pass
+
+    ## Set multithread mode
+    #  @param mode - the mode, one of the following values:
+    #  smeshBuilder.Mode_SAFE,
+    #  smeshBuilder.Mode_AGGRESSIVE,
+    #  smeshBuilder.Mode_NONE (default)
+    def SetPThreadsMode(self, mode ):
+        self.Parameters().SetPThreadsMode(mode)
+        pass
+
+    ## Set maximal number of threads
+    #  @param nb - number of threads
+    def SetMaximalNumberOfThreads(self, nb ):
+        self.Parameters().SetMaximalNumberOfThreads(nb)
+        pass
+
+
+    ## Set Optimization level:
+    #  @param level optimization level, one of the following values
+    #  - None_Optimization
+    #  - Light_Optimization
+    #  - Standard_Optimization
+    #  - StandardPlus_Optimization
+    #  - Strong_Optimization.
+    #  .
+    #  Default is Standard_Optimization
+    def SetOptimizationLevel(self, level):
+        self.Parameters().SetOptimizationLevel(level)
+        pass
+
+    ## Set maximal size of memory to be used by the algorithm (in Megabytes).
+    #  @param MB maximal size of memory
+    def SetMaximumMemory(self, MB):
+        self.Parameters().SetMaximumMemory(MB)
+        pass
+
+    ## Set initial size of memory to be used by the algorithm (in Megabytes) in
+    #  automatic memory adjustment mode.
+    #  @param MB initial size of memory
+    def SetInitialMemory(self, MB):
+        self.Parameters().SetInitialMemory(MB)
+        pass
+
+    ## Set path to working directory.
+    #  @param path working directory
+    def SetWorkingDirectory(self, path):
+        self.Parameters().SetWorkingDirectory(path)
+        pass
+
+    ## To keep working files or remove them.
+    #  @param toKeep "keep working files" flag value
+    def SetKeepFiles(self, toKeep):
+        self.Parameters().SetKeepFiles(toKeep)
+        pass
+
+    ## Remove or not the log file (if any) in case of successful computation.
+    #  The log file remains in case of errors anyway. If
+    #  the "keep working files" flag is set to true, this option
+    #  has no effect.
+    #  @param toRemove "remove log on success" flag value
+    def SetRemoveLogOnSuccess(self, toRemove):
+        self.Parameters().SetRemoveLogOnSuccess(toRemove)
+        pass
+
+    ## Print the the log in a file. If set to false, the
+    # log is printed on the standard output
+    #  @param toPrintLogInFile "print log in a file" flag value
+    def SetPrintLogInFile(self, toPrintLogInFile):
+        self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
+        pass
+
+    ## Set verbosity level [0-10].
+    #  @param level verbosity level
+    #  - 0 - no standard output,
+    #  - 2 - prints the data, quality statistics of the skin and final meshes and
+    #    indicates when the final mesh is being saved. In addition the software
+    #    gives indication regarding the CPU time.
+    #  - 10 - same as 2 plus the main steps in the computation, quality statistics
+    #    histogram of the skin mesh, quality statistics histogram together with
+    #    the characteristics of the final mesh.
+    def SetVerboseLevel(self, level):
+        self.Parameters().SetVerboseLevel(level)
+        pass
+
+    ## To create new nodes.
+    #  @param toCreate "create new nodes" flag value
+    def SetToCreateNewNodes(self, toCreate):
+        self.Parameters().SetToCreateNewNodes(toCreate)
+        pass
+
+    ## Sets command line option as text.
+    #  @param option command line option
+    def SetAdvancedOption(self, option):
+        self.Parameters().SetAdvancedOption(option)
+        pass
+
+    pass # end of GHS3D_Optimizer class
+
+class hypoProxy(GHS3DPlugin._objref_GHS3DPlugin_Hypothesis):
+    """
+    Private class wrapping to provide backward compatibility with deprecated API.
+    """
+    def __init__(self, *args):
+        GHS3DPlugin._objref_GHS3DPlugin_Hypothesis.__init__(self, *args)
+    def __deepcopy__(self, memo=None):
+        new = self.__class__(self)
+        return new
+    def SetPrintLogInFile(self, value):
+        self.SetStandardOutputLog(not value)
+omniORB.registerObjref(GHS3DPlugin._objref_GHS3DPlugin_Hypothesis._NP_RepositoryId, hypoProxy)
+del hypoProxy