1 // Copyright (C) 2009-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //=============================================================================
21 // File : HEXABLOCKPlugin_HEXABLOCK.cxx
23 // Author : Lioka RAZAFINDRAZAKA (CEA)
26 //=============================================================================
28 #include "HEXABLOCKPlugin_HEXABLOCK.hxx"
29 #include "HEXABLOCKPlugin_Hypothesis.hxx"
31 #include "TopExp_Explorer.hxx"
33 #include <Basics_Utils.hxx>
35 #include "SMESH_Gen.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_subMesh.hxx"
38 #include "SMESH_MesherHelper.hxx"
40 #include "HEXABLOCKPlugin_mesh.hxx"
42 #include "HexQuad.hxx"
43 #include "HexEdge.hxx"
44 #include "HexVertex.hxx"
45 #include "HexPropagation.hxx"
47 #include "utilities.h"
52 static int MYDEBUG = HEXA_NS::on_debug ();
54 static int MYDEBUG = 0;
57 //=============================================================================
61 //=============================================================================
63 HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK(int hypId, int studyId, SMESH_Gen* gen)
64 : SMESH_3D_Algo(hypId, studyId, gen)
66 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK");
67 _name = "HEXABLOCK_3D";
68 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
69 _compatibleHypothesis.push_back("HEXABLOCK_Parameters");
70 _requireShape = false; // can work without shape
71 _requireDiscreteBoundary = false;
73 _supportSubmeshes = false;
78 //=============================================================================
82 //=============================================================================
84 HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK()
86 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK");
89 //=============================================================================
93 //=============================================================================
95 bool HEXABLOCKPlugin_HEXABLOCK::CheckHypothesis ( SMESH_Mesh& aMesh,
96 const TopoDS_Shape& aShape,
97 Hypothesis_Status& aStatus )
99 aStatus = SMESH_Hypothesis::HYP_OK;
101 // there is only one compatible Hypothesis so far
103 const list <const SMESHDS_Hypothesis * >& hyps = GetUsedHypothesis(aMesh, aShape);
105 _hyp = static_cast<const HEXABLOCKPlugin_Hypothesis*> ( hyps.front() );
110 //=============================================================================
112 *Here we are going to use the HEXABLOCK mesher
114 //=============================================================================
116 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape) {
117 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute with a shape");
119 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
120 if ( (_iShape == 0) && (_nbShape == 0) ) {
121 TopExp_Explorer expShape ( meshDS->ShapeToMesh(), TopAbs_SOLID );
122 for ( ; expShape.More(); expShape.Next() ) {
127 // to prevent from displaying error message after computing,
128 for ( int i = 0; i < _nbShape; ++i )
129 if ( SMESH_subMesh* sm = theMesh.GetSubMeshContaining( theShape ))
131 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
132 /*complexShapeFirst=*/false);
133 while ( smIt->more() )
136 if ( !sm->IsMeshComputed() )
137 sm->SetIsAlwaysComputed( true );
144 if ( _iShape == _nbShape ) {
148 switch (_hyp->GetDimension()) {
149 case 0 : return( Compute0D(theMesh) );
150 case 1 : return( Compute1D(theMesh) );
151 case 2 : return( Compute2D(theMesh) );
152 default: return( Compute3D(theMesh) );
158 //=============================================================================
160 *Here we are going to use the HEXABLOCK mesher w/o geometry
162 //=============================================================================
164 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh,
165 SMESH_MesherHelper* aHelper)
167 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute without a shape");
169 switch (_hyp->GetDimension()) {
170 case 0 : return( Compute0D(theMesh) );
171 case 1 : return( Compute1D(theMesh) );
172 case 2 : return( Compute2D(theMesh) );
173 default: return( Compute3D(theMesh) );
177 //=============================================================================
181 //=============================================================================
182 bool HEXABLOCKPlugin_HEXABLOCK::Evaluate(SMESH_Mesh& aMesh,
183 const TopoDS_Shape& aShape,
184 MapShapeNbElems& aResMap)
186 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Evaluate: do nothing");
191 //=============================================================================
193 * Generate hexehedral
195 //=============================================================================
197 bool HEXABLOCKPlugin_HEXABLOCK::Compute3D(SMESH_Mesh& theMesh) {
198 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D Begin");
200 SMESH_HexaBlocks hexaBuilder(theMesh);
202 HEXA_NS::Document* doc = _hyp->GetDocument();
203 // doc->reorderFaces (); // 0) Abu 06/03/2012
205 hexaBuilder.computeDoc(doc);
206 hexaBuilder.buildGroups(doc);
208 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D End");
212 //=============================================================================
214 * Generate quadrangles
216 //=============================================================================
218 bool HEXABLOCKPlugin_HEXABLOCK::Compute2D(SMESH_Mesh& theMesh)
220 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 2D");
222 HEXA_NS::Document* doc = _hyp->GetDocument();
223 // doc->reorderFaces (); // 0) Abu 06/03/2012
225 SMESH_HexaBlocks hexaBuilder(theMesh);
227 // A) Vertex computation
228 int nVertex = doc->countUsedVertex();
229 HEXA_NS::Vertex* vertex = NULL;
230 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
231 vertex = doc->getUsedVertex(j);
232 hexaBuilder.computeVertex(*vertex);
235 // B) Edges computation
237 HEXA_NS::Propagation* propa = NULL;
238 HEXA_NS::Law* law = NULL;
239 HEXA_NS::Edges edges;
241 nbPropa = doc->countPropagation();
242 for (int j=0; j < nbPropa; ++j ){ //Computing each edge's propagations of the document
243 propa = doc->getPropagation(j);
244 edges = propa->getEdges();
245 law = propa->getLaw();
247 law = doc->getLaw(0); // default law
249 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
250 hexaBuilder.computeEdge(**iter, *law);
254 // C) Quad computation
255 std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(doc);
256 int nQuad = doc->countUsedQuad();
257 HEXA_NS::Quad* quad = NULL;
258 for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
259 quad = doc->getUsedQuad(j);
260 int id = quad->getId();
261 if ( quadWays.count(quad) > 0 )
262 hexaBuilder.computeQuad(*quad, quadWays[quad]);
264 if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
268 hexaBuilder.buildGroups(doc);
273 // SMESH::SMESH_Mesh_ptr SMESH_Gen_i::HexaBlocksQuad( HEXABLOCK_ORB::Document_ptr docIn, ::CORBA::Long quadID )
276 // SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
277 // if ( !aNewMesh->_is_nil() ) {
278 // SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
279 // Document_impl* docServant = dynamic_cast<Document_impl*>( GetServant( docIn ).in() );
280 // ASSERT( aNewImpl );
281 // ASSERT( docServant );
283 // HEXA_NS::Document* doc = docServant->GetImpl();
284 // SMESH_HexaBlocks hexaBuilder(aNewImpl);
286 // // A) Vertex computation
287 // int nVertex = doc->countVertex();
288 // HEXA_NS::Vertex* vertex = NULL;
289 // for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
290 // vertex = doc->getUsedVertex(j);
291 // hexaBuilder.computeVertex(*vertex);
294 // // B) Edges computation
296 // HEXA_NS::Propagation* propa = NULL;
297 // HEXA_NS::Law* law = NULL;
298 // HEXA_NS::Edges edges;
300 // nbPropa = doc->countPropagation();
301 // for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
302 // propa = doc->getPropagation(j);
303 // edges = propa->getEdges();
304 // law = propa->getLaw();
307 // law = doc->getLaw(0); // default law
309 // for( HEXA_NS::Edges::const_iterator iter = edges.begin();
310 // iter != edges.end();
312 // hexaBuilder.computeEdge(**iter, *law);
316 // // C) Quad computation
317 // std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(*doc);
318 // int nQuad = doc->countQuad();
319 // HEXA_NS::Quad* quad = NULL;
320 // for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
321 // quad = doc->getQuad(j);
322 // int id = quad->getId();
323 // if ( quadID == id and (quadWays.count(quad) > 0) )
324 // hexaBuilder.computeQuad( *quad, quadWays[quad] );
326 // if ( quadWays.count(quad) == 0 )
327 // if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
331 // // D) build Groups
332 // hexaBuilder.buildGroups(doc);
335 // return aNewMesh._retn();
336 // } catch (SALOME_Exception& S_ex) {
337 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
341 bool HEXABLOCKPlugin_HEXABLOCK::Compute1D(SMESH_Mesh& theMesh)
343 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 1D");
345 HEXA_NS::Document* doc = _hyp->GetDocument();
346 // doc->reorderFaces (); // 0) Abu 06/03/2012
348 SMESH_HexaBlocks hexaBuilder(theMesh);
350 // A) Vertex computation
351 int nVertex = doc->countUsedVertex();
352 HEXA_NS::Vertex* vertex = NULL;
353 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
354 vertex = doc->getUsedVertex(j);
355 hexaBuilder.computeVertex(*vertex);
358 // B) Edges computation
360 HEXA_NS::Propagation* propa = NULL;
361 HEXA_NS::Law* law = NULL;
362 HEXA_NS::Edges edges;
364 nbPropa = doc->countPropagation();
365 for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
366 propa = doc->getPropagation(j);
367 edges = propa->getEdges();
368 law = propa->getLaw();
371 law = doc->getLaw(0); // default law
373 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
374 hexaBuilder.computeEdge(**iter, *law);
379 hexaBuilder.buildGroups(doc);
384 bool HEXABLOCKPlugin_HEXABLOCK::Compute0D(SMESH_Mesh& theMesh)
386 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 0D");
388 HEXA_NS::Document* doc = _hyp->GetDocument();
389 // doc->reorderFaces (); // 0) Abu 06/03/2012
391 SMESH_HexaBlocks hexaBuilder(theMesh);
393 // A) Vertex computation
394 int nVertex = doc->countUsedVertex();
395 HEXA_NS::Vertex* vertex = NULL;
396 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
397 vertex = doc->getUsedVertex(j);
398 hexaBuilder.computeVertex(*vertex);
402 hexaBuilder.buildGroups(doc);