--- /dev/null
+# 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()
transforming_meshes_ex06.py
viewing_meshes_ex01.py
radial_prism_3d_algo.py
+ create_dual_mesh.py
)
IF(NOT WIN32)
LIST(APPEND BAD_TESTS
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
-.. _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`_.
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).
.. 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.
importing_exporting_meshes.rst
building_compounds.rst
copy_mesh.rst
+ create_dual_mesh.rst
connectivity.rst
--- /dev/null
+.. _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`.
: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?
========================================
: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
=============================
: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>`
+
{
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();
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")
import salome
import medcoupling as mc
from math import pi
+import numpy as np
#salome.salome_init()
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
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()
ptsAddedMesh = mc.MEDCouplingUMesh.Build0DMeshFromCoords( skin_polyh.getCoords()[ptsAdded] )
if adapt_to_shape:
+ logger.debug("Adapting to shape")
ptsAddedCoo = ptsAddedMesh.getCoords()
ptsAddedCooModified = ptsAddedCoo[:]
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
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)
+++ /dev/null
-#!/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()
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()
SMESH_test1.py
SMESH_test2.py
SMESH_test4.py
- SMESH_create_dual_mesh.py
SMESH_create_dual_mesh_adapt.py
)
IF(NOT WIN32)