From: Yoann Audouin Date: Mon, 10 Oct 2022 07:34:15 +0000 (+0200) Subject: Adding user documentation X-Git-Tag: V9_10_0a1~1^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b131becc0872f2050b117ce5bfc0fda84e34faa6;p=modules%2Fsmesh.git Adding user documentation --- diff --git a/doc/examples/create_dual_mesh.py b/doc/examples/create_dual_mesh.py new file mode 100644 index 000000000..08dfea822 --- /dev/null +++ b/doc/examples/create_dual_mesh.py @@ -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() diff --git a/doc/examples/tests.set b/doc/examples/tests.set index cb22edab5..df39d9dd9 100644 --- a/doc/examples/tests.set +++ b/doc/examples/tests.set @@ -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 diff --git a/doc/gui/CMakeLists.txt b/doc/gui/CMakeLists.txt index c85b76e94..26660b650 100644 --- a/doc/gui/CMakeLists.txt +++ b/doc/gui/CMakeLists.txt @@ -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 index 000000000..b28beaaf8 Binary files /dev/null and b/doc/gui/images/create_dual_mesh_dlg.png differ diff --git a/doc/gui/input/about_meshes.rst b/doc/gui/input/about_meshes.rst index 270fbe5e1..73af1714e 100644 --- a/doc/gui/input/about_meshes.rst +++ b/doc/gui/input/about_meshes.rst @@ -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 ` 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 ` 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 ` and characteristics (e.g. element size) of a required mesh encapsulated in :ref:`hypothesis ` 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 ` operations, especially :ref:`extrusion ` and :ref:`revolution `. To create an empty mesh not based on geometry, use the same dialog as to :ref:`construct the mesh on geometry ` but specify neither the geometry nor meshing algorithms. - + * The mesh can be :ref:`imported ` 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 ` or created in other way. To setup the meshing parameters of a mesh not based on geometry, just invoke :ref:`Edit mesh / sub-mesh ` command on your 2D mesh. - + * Several meshes can be :ref:`combined ` into a new mesh. - + * The whole mesh or its part (sub-mesh or group) can be :ref:`copied ` into a new mesh. - + * A new mesh can be created from a transformed, e.g. :ref:`translated `, part of the mesh. +* A new mesh can be created from the gernation of the :ref:`dual ` of a Tetrahedron Mesh. + Meshes can be edited using the MESH functions destined for :ref:`modification ` 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 index 000000000..2a540a1c6 --- /dev/null +++ b/doc/gui/input/create_dual_mesh.rst @@ -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`. diff --git a/doc/gui/input/tui_creating_meshes.rst b/doc/gui/input/tui_creating_meshes.rst index 9d3cb5077..253fbf260 100644 --- a/doc/gui/input/tui_creating_meshes.rst +++ b/doc/gui/input/tui_creating_meshes.rst @@ -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>` + diff --git a/src/SMESHGUI/SMESHGUI_CreateDualMeshOp.cxx b/src/SMESHGUI/SMESHGUI_CreateDualMeshOp.cxx index 4ee81382a..c0fed0340 100644 --- a/src/SMESHGUI/SMESHGUI_CreateDualMeshOp.cxx +++ b/src/SMESHGUI/SMESHGUI_CreateDualMeshOp.cxx @@ -150,9 +150,10 @@ void SMESHGUI_CreateDualMeshOp::selectionDone() { SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface( 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(); diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 0fd53cbc7..f6abcbdce 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -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") diff --git a/src/SMESH_SWIG/smesh_tools.py b/src/SMESH_SWIG/smesh_tools.py index 1a6995eed..3d95f730c 100644 --- a/src/SMESH_SWIG/smesh_tools.py +++ b/src/SMESH_SWIG/smesh_tools.py @@ -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 index 08621f30e..000000000 --- a/test/SMESH_create_dual_mesh.py +++ /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() diff --git a/test/SMESH_create_dual_mesh_adapt.py b/test/SMESH_create_dual_mesh_adapt.py index c95e6a62e..9f79618da 100644 --- a/test/SMESH_create_dual_mesh_adapt.py +++ b/test/SMESH_create_dual_mesh_adapt.py @@ -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() diff --git a/test/tests.set b/test/tests.set index 977f4a667..fddb00249 100644 --- a/test/tests.set +++ b/test/tests.set @@ -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)