* Create a dual mesh of a Tetrahedron mesh
* \param mesh - TetraHedron mesh to create dual from
* \param meshName - a name of the new mesh
+ * \param adaptToShape - if True project boundary point on shape
*/
SMESH_Mesh CreateDualMesh(in SMESH_IDSource mesh,
- in string meshName)
+ in string meshName,
+ in boolean adaptToShape)
raises ( SALOME::SALOME_Exception );
/*!
// Qt includes
#include <QLineEdit>
+#include <QCheckBox>
// IDL includes
#include <SALOMEconfig.h>
SMESH::SMESH_Gen_var gen = SMESHGUI::GetSMESHGen();
SMESH::SMESH_Mesh_var newMesh;
QByteArray newMeshName=myDlg->myMeshName->text().toUtf8();
+ bool adapt_to_shape=myDlg->myProjShape->isChecked();
try
{
- // TODO: change name as previous name + "_dual"
- newMesh = gen->CreateDualMesh(mesh, newMeshName.constData());
+ newMesh = gen->CreateDualMesh(mesh, newMeshName.constData(), adapt_to_shape);
if ( !newMesh->_is_nil() )
if ( _PTR(SObject) aSObject = SMESH::ObjectToSObject( newMesh ) )
//================================================================================
SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateDualMesh(SMESH::SMESH_IDSource_ptr mesh,
- const char* meshName)
+ const char* meshName,
+ CORBA::Boolean adapt_to_shape)
{
Unexpect aCatch(SALOME_SalomeException);
CORBA::String_var mesh_var=GetORB()->object_to_string(mesh);
std::string mesh_ior = mesh_var.in();
- fs::path tmp_folder = fs::unique_path(fs::path("dual_mesh-%%%%-%%%%"));
+ //temporary folder for the generation of the med file
+ fs::path tmp_folder = fs::temp_directory_path() / fs::unique_path(fs::path("dual_mesh-%%%%"));
fs::create_directories(tmp_folder);
fs::path dual_mesh_file = tmp_folder / fs::path("tmp_dual_mesh.med");
- std::string mesh_name = "MESH";
+ std::string mesh_name = meshName;
+ MESSAGE("Working in folder" + tmp_folder.string());
// Running Python script
assert(Py_IsInitialized());
std::string cmd="import salome.smesh.smesh_tools as smt";
PyRun_SimpleString(cmd.c_str());
+ std::string ats;
+ if(adapt_to_shape)
+ ats = "True";
+ else
+ ats = "False";
- cmd = "smt.create_dual_mesh(\"" + mesh_ior + "\", \"" + dual_mesh_file.string() + "\", \"" + mesh_name + "\")";
+ cmd = "smt.smesh_create_dual_mesh(\"" + mesh_ior + "\", \"" +
+ dual_mesh_file.string() + "\", mesh_name=\"" + mesh_name + "\", adapt_to_shape=" + ats + ")";
+ MESSAGE(cmd);
PyRun_SimpleString(cmd.c_str());
PyGILState_Release(gstate);
+ MESSAGE("Executed python script");
+ MESSAGE("Mesh created in " + dual_mesh_file.string());
// Import created MED
SMESH::SMESH_Mesh_var newMesh = CreateMesh(GEOM::GEOM_Object::_nil());
SALOMEDS::SObject_wrap meshSO = ObjectToSObject( newMesh );
if ( !meshSO->_is_nil() )
{
- SetName( meshSO, meshName, "Mesh" );
- SetPixMap( meshSO, "ICON_SMESH_TREE_MESH");
+ SetName( meshSO, meshName, meshName );
+ SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
}
SMESH_Mesh& newMesh2 = newMesh_i->GetImpl();
newMesh2.MEDToMesh(dual_mesh_file.c_str(), meshName);
+ MESSAGE("Imported created MED")
+
SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS();
newMeshDS->Modified();
*pyDump << newMesh << " = " << this
<< ".CreateDualMesh("
- << "'" << meshName << "') ";
+ << mesh << ", "
+ << "'" << meshName << "', "
+ << ats << ") ";
return newMesh._retn();
}
// Create dual mesh of a tetrahedron mesh
SMESH::SMESH_Mesh_ptr CreateDualMesh(SMESH::SMESH_IDSource_ptr meshPart,
- const char* meshName);
+ const char* meshName,
+ CORBA::Boolean adapt_to_shape);
// Copy a part of mesh
SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
aMesh = Mesh( self, self.geompyD, aSmeshMesh, name=name )
return aMesh
- def CreateDualMesh( self, mesh, meshName):
+ def CreateDualMesh( self, mesh, meshName, adaptToShape):
"""
Create a dual of a mesh.
:class:`mesh, <SMESH.SMESH_IDSource>`.
meshName: a name of the new mesh
+ adpatToShape: if true project boundary points on shape
Returns:
an instance of class :class:`Mesh`
"""
if isinstance( mesh, Mesh ):
mesh = mesh.GetMesh()
- dualMesh = SMESH._objref_SMESH_Gen.CreateDualMesh(self, mesh, meshName)
+ print("calling createdualmesh from Python")
+ dualMesh = SMESH._objref_SMESH_Gen.CreateDualMesh(self, mesh, meshName, adaptToShape)
return Mesh(self, self.geompyD, dualMesh)
smesh = smeshBuilder.New()
-def create_dual_mesh(mesh_ior, output_file, adapt_to_shape=True, mesh_name="MESH"):
+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
Args:
output_file (string): dual mesh file
"""
# Import mesh from file
- # mesh = salome.orb.string_to_object(salome.salome_study.myStudy.FindObjectID(mesh_id).GetIOR())
mesh = salome.orb.string_to_object(mesh_ior)
if not mesh:
raise Exception("Could not find mesh using id: ", mesh_ior)
# 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]
+ tetras = mc.MEDFileMesh.New(dab)[0]
# End of SMESH -> MEDCoupling part for dualmesh
tetras = mc.MEDCoupling1SGTUMesh(tetras)
polyh = tetras.computeDualMesh()
+ dual_volume_raw = polyh.getMeasureField(True).accumulate()[0]
+
+ # Getting list of new points added on the skin
skin = tetras.buildUnstructured().computeSkin()
skin_polyh = polyh.buildUnstructured().computeSkin()
allNodesOnSkinPolyh = skin_polyh.computeFetchedNodeIds()
ptsAddedCoo = ptsAddedMesh.getCoords()
ptsAddedCooModified = ptsAddedCoo[:]
- # We need the geometry for that
- # TODO : Loop on faces identify points associated to which face
+ # Matching faces with their ids
faces = geompy.ExtractShapes(shape, geompy.ShapeType["FACE"], True)
- #assert( len(faces) == 1 )
- ## projection des points ajoutés par le dual sur la surface
- #for i,tup in enumerate(ptsAddedCooModified):
- # vertex = geompy.MakeVertex(*tuple(tup))
- # prj = geompy.MakeProjection(vertex, faces)
- # newCoor = geompy.PointCoordinates( prj )
- # ptsAddedCooModified[i] = newCoor
- ## assign coordinates with projected ones
- #polyh.getCoords()[ptsAdded] = ptsAddedCooModified
-
- print("Writing dual mesh in ", output_file)
+ 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
+ for i, tup in enumerate(ptsAddedCooModified):
+ vertex = geompy.MakeVertex(*tuple(tup))
+ shapes = geompy.GetShapesNearPoint(shape, vertex,
+ geompy.ShapeType["FACE"])
+ prj = geompy.MakeProjection(vertex,
+ id2face[shapes.GetSubShapeIndices()[0]])
+ new_coor = geompy.PointCoordinates(prj)
+ ptsAddedCooModified[i] = new_coor
+
+ polyh.getCoords()[ptsAdded] = ptsAddedCooModified
+
polyh.setName(mesh_name)
polyh.write(output_file)
-
-
-
-
-
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')
+dual_Mesh_1 = smesh.CreateDualMesh( Mesh_1, 'dual_Mesh_1', True)
assert(dual_Mesh_1.NbPolyhedrons() > 0)
--- /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)
+Cylinder_1 = geompy.MakeCylinderRH(100, 400)
+Sphere_1 = geompy.MakeSpherePntR(O, 100)
+Fuse_1 = geompy.MakeFuseList([Cylinder_1, Sphere_1], True, True)
+
+[geomObj_1,geomObj_2,geomObj_3] = geompy.ExtractShapes(Fuse_1, geompy.ShapeType["FACE"], True)
+
+top = geompy.CreateGroup(Fuse_1, geompy.ShapeType["FACE"])
+geompy.UnionIDs(top, geomObj_1.GetSubShapeIndices())
+
+middle = geompy.CreateGroup(Fuse_1, geompy.ShapeType["FACE"])
+geompy.UnionIDs(middle, geomObj_2.GetSubShapeIndices())
+
+bottom = geompy.CreateGroup(Fuse_1, geompy.ShapeType["FACE"])
+geompy.UnionIDs(bottom, geomObj_3.GetSubShapeIndices())
+
+#[top, middle, bottom] = geompy.GetExistingSubObjects(Fuse_1, False)
+
+geompy.addToStudy( O, 'O' )
+geompy.addToStudy( OX, 'OX' )
+geompy.addToStudy( OY, 'OY' )
+geompy.addToStudy( OZ, 'OZ' )
+geompy.addToStudy( Cylinder_1, 'Cylinder_1' )
+geompy.addToStudy( Sphere_1, 'Sphere_1' )
+geompy.addToStudy( Fuse_1, 'Fuse_1' )
+geompy.addToStudyInFather( Fuse_1, top, 'top' )
+geompy.addToStudyInFather( Fuse_1, middle, 'middle' )
+geompy.addToStudyInFather( Fuse_1, bottom, 'bottom' )
+
+###
+### SMESH component
+###
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+
+smesh = smeshBuilder.New()
+
+NETGEN_3D_Parameters_1 = smesh.CreateHypothesisByAverageLength( 'NETGEN_Parameters', 'NETGENEngine', 50, 0 )
+Mesh_1 = smesh.Mesh(Fuse_1,'Mesh_1')
+status = Mesh_1.AddHypothesis( Fuse_1, NETGEN_3D_Parameters_1 )
+NETGEN_1D_2D_3D = Mesh_1.Tetrahedron(algo=smeshBuilder.NETGEN_1D2D3D)
+top_1 = Mesh_1.GroupOnGeom(top,'top',SMESH.FACE)
+middle_1 = Mesh_1.GroupOnGeom(middle,'middle',SMESH.FACE)
+bottom_1 = Mesh_1.GroupOnGeom(bottom,'bottom',SMESH.FACE)
+isDone = Mesh_1.Compute()
+
+[ top_1, middle_1, bottom_1 ] = Mesh_1.GetGroups()
+
+
+dual_Mesh_1 = smesh.CreateDualMesh(Mesh_1, 'dual_Mesh_1', True)
+dual_Mesh_raw_1 = smesh.CreateDualMesh(Mesh_1, 'dual_Mesh_1', False)
+
+#Comparing volumes
+dual_volume = dual_Mesh_1.GetVolume()
+dual_raw_volume = dual_Mesh_raw_1.GetVolume()
+print("dual_volume: ", dual_volume)
+print("dual_raw_volume: ", dual_raw_volume)
+
+assert (dual_volume >= dual_raw_volume)
+
+if salome.sg.hasDesktop():
+ salome.sg.updateObjBrowser()
SMESH_test2.py
SMESH_test4.py
SMESH_create_dual_mesh.py
+ SMESH_create_dual_mesh_adapt.py
)
IF(NOT WIN32)
LIST(APPEND BAD_TESTS