Salome HOME
Adding user documentation
authorYoann Audouin <yoann.audouin@edf.fr>
Mon, 10 Oct 2022 07:34:15 +0000 (09:34 +0200)
committerYoann Audouin <yoann.audouin@edf.fr>
Thu, 13 Oct 2022 12:33:36 +0000 (14:33 +0200)
13 files changed:
doc/examples/create_dual_mesh.py [new file with mode: 0644]
doc/examples/tests.set
doc/gui/CMakeLists.txt
doc/gui/images/create_dual_mesh_dlg.png [new file with mode: 0644]
doc/gui/input/about_meshes.rst
doc/gui/input/create_dual_mesh.rst [new file with mode: 0644]
doc/gui/input/tui_creating_meshes.rst
src/SMESHGUI/SMESHGUI_CreateDualMeshOp.cxx
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_SWIG/smesh_tools.py
test/SMESH_create_dual_mesh.py [deleted file]
test/SMESH_create_dual_mesh_adapt.py
test/tests.set

diff --git a/doc/examples/create_dual_mesh.py b/doc/examples/create_dual_mesh.py
new file mode 100644 (file)
index 0000000..08dfea8
--- /dev/null
@@ -0,0 +1,59 @@
+# Creating dual Mesh
+
+
+import sys
+import salome
+
+salome.salome_init()
+import salome_notebook
+notebook = salome_notebook.NoteBook()
+sys.path.insert(0, r'/home/B61570/work_in_progress/dual_mesh')
+
+###
+### GEOM component
+###
+
+import GEOM
+from salome.geom import geomBuilder
+import math
+import SALOMEDS
+
+
+# Creating a sphere
+geompy = geomBuilder.New()
+
+O = geompy.MakeVertex(0, 0, 0)
+OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
+OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
+OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
+Sphere_1 = geompy.MakeSphereR(100)
+[geomObj_1] = geompy.ExtractShapes(Sphere_1, geompy.ShapeType["FACE"], True)
+geompy.addToStudy( O, 'O' )
+geompy.addToStudy( OX, 'OX' )
+geompy.addToStudy( OY, 'OY' )
+geompy.addToStudy( OZ, 'OZ' )
+geompy.addToStudy( Sphere_1, 'Sphere_1' )
+
+import  SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+
+smesh = smeshBuilder.New()
+
+# Meshing sphere in Tetrahedron
+NETGEN_3D_Parameters_1 = smesh.CreateHypothesisByAverageLength( 'NETGEN_Parameters', 'NETGENEngine', 34.641, 0 )
+Mesh_1 = smesh.Mesh(Sphere_1,'Mesh_1')
+status = Mesh_1.AddHypothesis( Sphere_1, NETGEN_3D_Parameters_1 )
+NETGEN_1D_2D_3D = Mesh_1.Tetrahedron(algo=smeshBuilder.NETGEN_1D2D3D)
+isDone = Mesh_1.Compute()
+
+
+# Creating Dual mesh
+dual_Mesh_1 = smesh.CreateDualMesh( Mesh_1, 'dual_Mesh_1', True)
+
+
+assert(dual_Mesh_1.NbPolyhedrons() > 0)
+assert(dual_Mesh_1.NbTetras() == 0)
+
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser()
index cb22edab5de632c0bd8816511d94e2000f9f03a1..df39d9dd9c7f9954548fb893a5685a4e0e5aae6e 100644 (file)
@@ -128,6 +128,7 @@ SET(BAD_TESTS
   transforming_meshes_ex06.py
   viewing_meshes_ex01.py
   radial_prism_3d_algo.py
+  create_dual_mesh.py
   )
 IF(NOT WIN32)
   LIST(APPEND BAD_TESTS
index c85b76e947e9f76227895bf3d02b592a0829a3f6..26660b650ad783e64a8877b9a452489195e84440 100644 (file)
@@ -57,7 +57,7 @@ SET(_cmd_smeshBuilder_gen_options ${smesh_merge_file} -o tmp2/smeshBuilder.py sm
 SALOME_GENERATE_ENVIRONMENT_SCRIPT(_cmd_smeshBuilder_gen env_script "${PYTHON_EXECUTABLE}" "${_cmd_smeshBuilder_gen_options}" CONTEXT "SMESH_DOC" ADDITIONAL_VARIABLES ${ADD_VAR})
 
 ADD_CUSTOM_TARGET(pre_usr_docs
-  # 1. Make temporary directories for python modules 
+  # 1. Make temporary directories for python modules
   COMMAND ${CMAKE_COMMAND} -E make_directory tmp1
   COMMAND ${CMAKE_COMMAND} -E make_directory tmp2
 
diff --git a/doc/gui/images/create_dual_mesh_dlg.png b/doc/gui/images/create_dual_mesh_dlg.png
new file mode 100644 (file)
index 0000000..b28beaa
Binary files /dev/null and b/doc/gui/images/create_dual_mesh_dlg.png differ
index 270fbe5e1b3d82606ff14830afd0b7959b054373..73af1714eca11b583ac21e94e33b9d84243e8c4f 100644 (file)
@@ -1,8 +1,8 @@
-.. _about_meshes_page: 
+.. _about_meshes_page:
 
 ************
 About meshes
-************ 
+************
 
 **MESH** represents a discrete approximation of a subset of the three-dimensional space by `elementary geometrical elements`_.
 
@@ -10,7 +10,7 @@ A SALOME study can contain multiple meshes, but they do not implicitly compose o
 
 Mesh module provides several ways to create the mesh:
 
-* The main way is to :ref:`construct the mesh <constructing_meshes_page>` on the basis of the geometrical shape produced in the Geometry module. This way implies selection of 
+* The main way is to :ref:`construct the mesh <constructing_meshes_page>` on the basis of the geometrical shape produced in the Geometry module. This way implies selection of
 
   * a geometrical object (*main shape*) and
   * *meshing parameters* (:ref:`meshing algorithms <basic_meshing_algos_page>` and characteristics (e.g. element size) of a required mesh encapsulated in :ref:`hypothesis <about_hypo_page>` objects).
@@ -20,19 +20,21 @@ Mesh module provides several ways to create the mesh:
 
   .. note::
        Algorithms and hypotheses used at mesh level are referred to as *global* ones and those used at sub-mesh level are referred to as *local* ones.
-  
+
 * Bottom-up way, using :ref:`mesh modification <modifying_meshes_page>` operations, especially :ref:`extrusion <extrusion_page>` and :ref:`revolution <revolution_page>`. To create an empty mesh not based on geometry, use the same dialog as to :ref:`construct the mesh on geometry <constructing_meshes_page>` but specify neither the geometry nor meshing algorithms.
-  
+
 * The mesh can be :ref:`imported <importing_exporting_meshes_page>` from (and exported to) the file in MED, UNV, STL, CGNS, DAT and GMF formats.
-  
+
 * The 3D mesh can be generated from the 2D mesh not based on geometry, which was either :ref:`imported <importing_exporting_meshes_page>` or created in other way. To setup the meshing parameters of a mesh not based on geometry, just invoke :ref:`Edit mesh / sub-mesh <editing_meshes_page>` command on your 2D mesh.
-  
+
 * Several meshes can be :ref:`combined <building_compounds_page>` into a new mesh.
-  
+
 * The whole mesh or its part (sub-mesh or group) can be :ref:`copied <copy_mesh_page>` into a new mesh.
-  
+
 * A new mesh can be created from a transformed, e.g. :ref:`translated <translation_page>`, part of the mesh.
 
+* A new mesh can be created from the gernation of the :ref:`dual <create_dual_mesh_page>` of a Tetrahedron Mesh.
+
 
 Meshes can be edited using the MESH functions destined for :ref:`modification <modifying_meshes_page>` of meshes.
 
@@ -82,4 +84,5 @@ Quadratic mesh can be obtained in three ways:
    importing_exporting_meshes.rst
    building_compounds.rst
    copy_mesh.rst
+   create_dual_mesh.rst
    connectivity.rst
diff --git a/doc/gui/input/create_dual_mesh.rst b/doc/gui/input/create_dual_mesh.rst
new file mode 100644 (file)
index 0000000..2a540a1
--- /dev/null
@@ -0,0 +1,42 @@
+.. _create_dual_mesh_page:
+
+****************
+Create Dual Mesh
+****************
+
+We can create the dual of a Tetrahedron Mesh which will be a polyhedron mesh.
+The Mesh is created using MEDCoupling computeDualMesh function.
+
+*To create a dual mesh:*
+
+.. |img| image:: ../images/create_dual_mesh_icon.png
+
+From the contextual menu in the Object Browser of from the **Mesh** menu select
+**Create Dual Mesh** or click *"Create Dual Mesh"* button |img| in the toolbar.
+
+The following dialog box will appear:
+
+.. image:: ../images/create_dual_mesh_dlg.png
+       :align: center
+
+In the dialog:
+
+* specify the mesh for which to create the dual mesh:
+  * **Select whole mesh** from the study tree. If a mesh was selected before calling function it will be preselected.
+  * If the mesh is not made of only Tetrahedrons a error message will be displayed and you won't be allowed to go through.
+* specify the **New Mesh Name**;
+* activate **Project boundary elements on shape** for the boundary points of the
+  dual mesh to be projected on their associated shape.
+
+* Click **Apply** or **Apply and Close** button to confirm the operation.
+
+----------------------------
+Limitations of the dual mesh
+----------------------------
+
+Only 2d groups will be transferred to the dual mesh.
+
+If you have convex shape the projection might not improve the mesh.
+
+
+**See Also** a sample script of :ref:`tui_create_dual_mesh`.
index 9d3cb50773b1ce61ecb61fff1da109e4c8976069..253fbf260da44b54e688065df9882113fe7a3545 100644 (file)
@@ -70,7 +70,7 @@ Export of a Mesh
 
 :download:`Download this script <../../examples/creating_meshes_ex05.py>`
 
-.. _how_to_mesh_a_cylinder_with_hexahedrons: 
+.. _how_to_mesh_a_cylinder_with_hexahedrons:
 
 How to mesh a cylinder with hexahedrons?
 ========================================
@@ -84,10 +84,10 @@ demonstrates the resulting mesh.
 :download:`Download this script <../../examples/creating_meshes_ex06.py>`
 
 .. image:: ../images/mesh_cylinder_hexa.png
-       :align: center                                                 
+       :align: center
 
 
-.. _tui_building_compound: 
+.. _tui_building_compound:
 
 Building a compound of meshes
 =============================
@@ -107,3 +107,13 @@ Mesh Copying
 
 :download:`Download this script <../../examples/creating_meshes_ex08.py>`
 
+.. _tui_create_dual_mesh:
+
+Creating Dual Mesh
+==================
+
+.. literalinclude:: ../../examples/create_dual_mesh.py
+    :language: python
+
+:download:`Download this script <../../examples/create_dual_mesh.py>`
+
index 4ee81382a7bf2afdc4cf92eb267af4ccf9d916cc..c0fed0340de1e63fd79e8614e45f15864c9269f7 100644 (file)
@@ -150,9 +150,10 @@ void SMESHGUI_CreateDualMeshOp::selectionDone()
     {
       SMESH::SMESH_subMesh_var subMesh =
         SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pObj );
-      // TODO: Check that mesh is only tetra
+      // Check that mesh is only tetra
       if (!checkMesh(idSource)){
         myDlg->ShowWarning( true );
+        myDlg->setButtonEnabled(false, QtxDialog::OK|QtxDialog::Apply);
       }
     }
     std::string mesh_name = "dual_" + pObj->GetName();
index 0fd53cbc7ae57124da6517ee62723282f4d064b9..f6abcbdceb5767cac2dcc9937152b2f81a7deaf3 100644 (file)
@@ -2885,6 +2885,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateDualMesh(SMESH::SMESH_IDSource_ptr mesh
 
   SMESH_Mesh& newMesh2 = newMesh_i->GetImpl();
 
+  MESSAGE("Loading file: " << dual_mesh_file.string() << " with mesh " << mesh_name);
   newMesh2.MEDToMesh(dual_mesh_file.c_str(), meshName);
 
   MESSAGE("Imported created MED")
index 1a6995eedcfe55d695791988efa21ab142590ac6..3d95f730c07f78144de4acbbdcffb1b8aa95aa15 100644 (file)
@@ -4,6 +4,7 @@ import sys
 import salome
 import medcoupling as mc
 from math import pi
+import numpy as np
 
 #salome.salome_init()
 
@@ -17,6 +18,10 @@ from salome.smesh import smeshBuilder
 
 smesh = smeshBuilder.New()
 
+from salome.kernel.logger import Logger
+logger = Logger("salome.smesh.smesh_tools")
+logger.setLevel("DEBUG")
+
 def smesh_create_dual_mesh(mesh_ior, output_file, adapt_to_shape=True, mesh_name="MESH"):
     """ Create a dual of the mesh in input_file into output_file
 
@@ -31,15 +36,51 @@ def smesh_create_dual_mesh(mesh_ior, output_file, adapt_to_shape=True, mesh_name
 
     shape = mesh.GetShapeToMesh()
 
+    # Creating output file
+    myfile = mc.MEDFileUMesh()
+    myfile.setName(mesh_name)
+
+
     # We got a meshProxy so we need to convert pointer to MEDCoupling
     int_ptr = mesh.ExportMEDCoupling(True, True)
     dab = mc.FromPyIntPtrToDataArrayByte(int_ptr)
-    tetras = mc.MEDFileMesh.New(dab)[0]
+    mc_mesh_file = mc.MEDFileMesh.New(dab)
+    tetras = mc_mesh_file[0]
     # End of SMESH -> MEDCoupling part for dualmesh
 
     tetras = mc.MEDCoupling1SGTUMesh(tetras)
     polyh = tetras.computeDualMesh()
-    dual_volume_raw = polyh.getMeasureField(True).accumulate()[0]
+
+    ## Adding skin + transfering groups on faces from tetras mesh
+    mesh2d = polyh.buildUnstructured().computeSkin()
+    mesh2d.setName(mesh_name)
+    myfile.setMeshAtLevel(-1, mesh2d)
+
+
+    for grp_name in mc_mesh_file.getGroupsOnSpecifiedLev(-1):
+        logger.debug("Transferring group: "+ grp_name)
+        grp_tria = mc_mesh_file.getGroup(-1, grp_name)
+        # Retrieve the nodes in group
+        grp_nodes = grp_tria.computeFetchedNodeIds()
+        # Find all the cells lying on one of the nodes
+        id_grp_poly = mesh2d.getCellIdsLyingOnNodes(grp_nodes, False)
+
+        grp_poly = mesh2d[id_grp_poly]
+
+        # We use the interpolation to remove the element that are not really in
+        # the group (the ones that are next to a nodes nut not in the group
+        # will have the sum of their column in the enterpolation matrix equal
+        # to zero)
+        rem = mc.MEDCouplingRemapper()
+
+        rem.prepare(grp_poly, grp_tria, "P0P0")
+        m = rem.getCrudeCSRMatrix()
+        _, id_to_keep = np.where(m.sum(dtype=np.int64, axis=0) >= 1e-07)
+
+        id_grp_poly = id_grp_poly[id_to_keep.tolist()]
+        id_grp_poly.setName(grp_name)
+
+        myfile.addGroup(-1, id_grp_poly)
 
     # Getting list of new points added on the skin
     skin = tetras.buildUnstructured().computeSkin()
@@ -50,6 +91,7 @@ def smesh_create_dual_mesh(mesh_ior, output_file, adapt_to_shape=True, mesh_name
     ptsAddedMesh = mc.MEDCouplingUMesh.Build0DMeshFromCoords( skin_polyh.getCoords()[ptsAdded] )
 
     if adapt_to_shape:
+        logger.debug("Adapting to shape")
         ptsAddedCoo = ptsAddedMesh.getCoords()
         ptsAddedCooModified = ptsAddedCoo[:]
 
@@ -58,7 +100,6 @@ def smesh_create_dual_mesh(mesh_ior, output_file, adapt_to_shape=True, mesh_name
         id2face = {}
         for face in faces:
             id2face[face.GetSubShapeIndices()[0]] = face
-        print(id2face)
 
         ## Projecting each points added by the dual mesh on the surface it is
         # associated with
@@ -74,4 +115,7 @@ def smesh_create_dual_mesh(mesh_ior, output_file, adapt_to_shape=True, mesh_name
         polyh.getCoords()[ptsAdded] = ptsAddedCooModified
 
     polyh.setName(mesh_name)
-    polyh.write(output_file)
+    myfile.setMeshAtLevel(0, polyh)
+
+    logger.debug("Writting dual mesh in :"+output_file)
+    myfile.write(output_file, 2)
diff --git a/test/SMESH_create_dual_mesh.py b/test/SMESH_create_dual_mesh.py
deleted file mode 100644 (file)
index 08621f3..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/env python
-
-###
-### This file is generated automatically by SALOME v9.9.0 with dump python functionality
-###
-
-import sys
-import salome
-
-salome.salome_init()
-import salome_notebook
-notebook = salome_notebook.NoteBook()
-sys.path.insert(0, r'/home/B61570/work_in_progress/dual_mesh')
-
-###
-### GEOM component
-###
-
-import GEOM
-from salome.geom import geomBuilder
-import math
-import SALOMEDS
-
-
-geompy = geomBuilder.New()
-
-O = geompy.MakeVertex(0, 0, 0)
-OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
-OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
-OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
-Sphere_1 = geompy.MakeSphereR(100)
-[geomObj_1] = geompy.ExtractShapes(Sphere_1, geompy.ShapeType["FACE"], True)
-geompy.addToStudy( O, 'O' )
-geompy.addToStudy( OX, 'OX' )
-geompy.addToStudy( OY, 'OY' )
-geompy.addToStudy( OZ, 'OZ' )
-geompy.addToStudy( Sphere_1, 'Sphere_1' )
-
-###
-### SMESH component
-###
-
-import  SMESH, SALOMEDS
-from salome.smesh import smeshBuilder
-
-smesh = smeshBuilder.New()
-
-NETGEN_3D_Parameters_1 = smesh.CreateHypothesisByAverageLength( 'NETGEN_Parameters', 'NETGENEngine', 34.641, 0 )
-Mesh_1 = smesh.Mesh(Sphere_1,'Mesh_1')
-status = Mesh_1.AddHypothesis( Sphere_1, NETGEN_3D_Parameters_1 )
-NETGEN_1D_2D_3D = Mesh_1.Tetrahedron(algo=smeshBuilder.NETGEN_1D2D3D)
-isDone = Mesh_1.Compute()
-dual_Mesh_1 = smesh.CreateDualMesh( Mesh_1, 'dual_Mesh_1', True)
-
-
-assert(dual_Mesh_1.NbPolyhedrons() > 0)
-assert(dual_Mesh_1.NbTetras() == 0)
-
-
-if salome.sg.hasDesktop():
-  salome.sg.updateObjBrowser()
index c95e6a62e139631637b7113607c74691aeb54874..9f79618da72dc582c84f0c02fa9d6c5d3a23cc3d 100644 (file)
@@ -80,6 +80,8 @@ isDone = Mesh_1.Compute()
 dual_Mesh_1 = smesh.CreateDualMesh(Mesh_1, 'dual_Mesh_1', True)
 dual_Mesh_raw_1 = smesh.CreateDualMesh(Mesh_1, 'dual_Mesh_1', False)
 
+[ top_2, middle_2, bottom_2 ] = dual_Mesh_1.GetGroups()
+
 #Comparing volumes
 dual_volume = dual_Mesh_1.GetVolume()
 dual_raw_volume = dual_Mesh_raw_1.GetVolume()
index 977f4a667fda7bc7e95d4ee8499b263bb8139e9b..fddb002499e87fcb70e1707f32e02bec4cbafe7f 100644 (file)
@@ -62,7 +62,6 @@ SET(BAD_TESTS
   SMESH_test1.py
   SMESH_test2.py
   SMESH_test4.py
-  SMESH_create_dual_mesh.py
   SMESH_create_dual_mesh_adapt.py
   )
 IF(NOT WIN32)