mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2024-12-25 08:50:35 +05:00
Adding user documentation
This commit is contained in:
parent
7d1a127bbb
commit
b131becc08
@ -1,8 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# Creating dual Mesh
|
||||
|
||||
###
|
||||
### This file is generated automatically by SALOME v9.9.0 with dump python functionality
|
||||
###
|
||||
|
||||
import sys
|
||||
import salome
|
||||
@ -22,6 +19,7 @@ import math
|
||||
import SALOMEDS
|
||||
|
||||
|
||||
# Creating a sphere
|
||||
geompy = geomBuilder.New()
|
||||
|
||||
O = geompy.MakeVertex(0, 0, 0)
|
||||
@ -36,20 +34,20 @@ 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()
|
||||
|
||||
# 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)
|
||||
|
||||
|
@ -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
|
||||
|
BIN
doc/gui/images/create_dual_mesh_dlg.png
Normal file
BIN
doc/gui/images/create_dual_mesh_dlg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
@ -33,6 +33,8 @@ Mesh module provides several ways to create the 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
|
||||
|
42
doc/gui/input/create_dual_mesh.rst
Normal file
42
doc/gui/input/create_dual_mesh.rst
Normal file
@ -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`.
|
@ -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>`
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user