From 69aa7507f2647f99203fa4b526f99c77d8c43471 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 12 Apr 2017 16:55:16 +0300 Subject: [PATCH] 23427: [CEA 2073] No hypothesis "Viscous Layers" with Netgen 1D-2D-3D Add GetElementsByNodes() that return elements including all given nodes. --- .../gui/SMESH/input/constructing_meshes.doc | 2 +- idl/SMESH_Mesh.idl | 5 +++ src/SMDS/SMDS_Mesh.cxx | 43 +++++++++++++++++++ src/SMDS/SMDS_Mesh.hxx | 3 ++ src/SMESH_I/SMESH_Mesh_i.cxx | 29 +++++++++++++ src/SMESH_I/SMESH_Mesh_i.hxx | 10 ++++- 6 files changed, 89 insertions(+), 3 deletions(-) diff --git a/doc/salome/gui/SMESH/input/constructing_meshes.doc b/doc/salome/gui/SMESH/input/constructing_meshes.doc index 6794b398b..2481807fd 100644 --- a/doc/salome/gui/SMESH/input/constructing_meshes.doc +++ b/doc/salome/gui/SMESH/input/constructing_meshes.doc @@ -19,7 +19,7 @@ and hypotheses. Mesh generation on the geometry is performed in the bottom-up flow: nodes on vertices are created first, then edges are divided into -segments using nodes on vertices; the node of segments are then +segments using nodes on vertices; the nodes of segments are then used to mesh faces; then the nodes of faces are used to mesh solids. This automatically assures the conformity of the mesh. diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index 805b21df6..cef3831ee 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -975,6 +975,11 @@ module SMESH */ long FindElementByNodes(in long_array nodes); + /*! + * Return elements including all given nodes. + */ + long_array GetElementsByNodes(in long_array nodes, in ElementType elem_type); + /*! * Returns true if given element is polygon */ diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index 5d8294700..7c8e66327 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -2458,6 +2458,49 @@ const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector& nodes, + std::vector& foundElems, + const SMDSAbs_ElementType type) +{ + // chose a node with minimal number of inverse elements + const SMDS_MeshNode* n0 = nodes[0]; + int minNbInverse = n0 ? n0->NbInverseElements( type ) : 1000; + for ( size_t i = 1; i < nodes.size(); ++i ) + if ( nodes[i] && nodes[i]->NbInverseElements( type ) < minNbInverse ) + { + n0 = nodes[i]; + minNbInverse = n0->NbInverseElements( type ); + } + + foundElems.clear(); + if ( n0 ) + { + foundElems.reserve( minNbInverse ); + SMDS_ElemIteratorPtr eIt = n0->GetInverseElementIterator( type ); + while ( eIt->more() ) + { + const SMDS_MeshElement* e = eIt->next(); + bool includeAll = true; + for ( size_t i = 0; i < nodes.size() && includeAll; ++i ) + if ( nodes[i] != n0 && e->GetNodeIndex( nodes[i] ) < 0 ) + includeAll = false; + if ( includeAll ) + foundElems.push_back( e ); + } + } + return foundElems.size(); +} + //======================================================================= //function : DumpNodes //purpose : diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index b1af99a1d..d1d0b1120 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -689,6 +689,9 @@ public: static const SMDS_MeshElement* FindElement(const std::vector& nodes, const SMDSAbs_ElementType type=SMDSAbs_All, const bool noMedium=true); + static int GetElementsByNodes(const std::vector& nodes, + std::vector& foundElems, + const SMDSAbs_ElementType type=SMDSAbs_All); /*! * \brief Raise an exception if free memory (ram+swap) too low diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index a075dadce..268dfd829 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -4771,6 +4771,35 @@ CORBA::Long SMESH_Mesh_i::FindElementByNodes(const SMESH::long_array& nodes) return elemID; } +//================================================================================ +/*! + * \brief Return elements including all given nodes. + */ +//================================================================================ + +SMESH::long_array* SMESH_Mesh_i::GetElementsByNodes(const SMESH::long_array& nodes, + SMESH::ElementType elemType) +{ + if ( _preMeshInfo ) + _preMeshInfo->FullLoadFromFile(); + + SMESH::long_array_var result = new SMESH::long_array(); + + if ( SMESHDS_Mesh* mesh = _impl->GetMeshDS() ) + { + vector< const SMDS_MeshNode * > nn( nodes.length() ); + for ( CORBA::ULong i = 0; i < nodes.length(); ++i ) + nn[i] = mesh->FindNode( nodes[i] ); + + std::vector elems; + mesh->GetElementsByNodes( nn, elems, (SMDSAbs_ElementType) elemType ); + result->length( elems.size() ); + for ( size_t i = 0; i < elems.size(); ++i ) + result[i] = elems[i]->GetID(); + } + return result._retn(); +} + //============================================================================= /*! * Returns true if given element is polygon diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 8aaa79bae..62d08763d 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -536,8 +536,8 @@ public: * Returns true if given node is medium node * in one of quadratic elements */ - CORBA::Boolean IsMediumNodeOfAnyElem(CORBA::Long idn, - SMESH::ElementType theElemType); + CORBA::Boolean IsMediumNodeOfAnyElem(CORBA::Long idn, + SMESH::ElementType elemType); /*! * Returns number of edges for given element @@ -563,6 +563,12 @@ public: */ CORBA::Long FindElementByNodes(const SMESH::long_array& nodes); + /*! + * Return elements including all given nodes. + */ + SMESH::long_array* GetElementsByNodes(const SMESH::long_array& nodes, + SMESH::ElementType elemType); + /*! * Returns true if given element is polygon */ -- 2.30.2