1 // Copyright (C) 2009-2012 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.
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_MesherHelper.hxx"
39 #include "HEXABLOCKPlugin_mesh.hxx"
41 #include "HexQuad.hxx"
42 #include "HexEdge.hxx"
43 #include "HexVertex.hxx"
44 #include "HexPropagation.hxx"
46 #include "utilities.h"
51 static int MYDEBUG = 1;
53 static int MYDEBUG = 0;
56 //=============================================================================
60 //=============================================================================
62 HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK(int hypId, int studyId, SMESH_Gen* gen)
63 : SMESH_3D_Algo(hypId, studyId, gen)
65 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK");
66 _name = "HEXABLOCK_3D";
67 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
68 _compatibleHypothesis.push_back("HEXABLOCK_Parameters");
69 _requireShape = false; // can work without shape
70 _requireDiscreteBoundary = false;
72 _supportSubmeshes = false;
77 //=============================================================================
81 //=============================================================================
83 HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK()
85 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK");
88 //=============================================================================
92 //=============================================================================
94 bool HEXABLOCKPlugin_HEXABLOCK::CheckHypothesis ( SMESH_Mesh& aMesh,
95 const TopoDS_Shape& aShape,
96 Hypothesis_Status& aStatus )
98 aStatus = SMESH_Hypothesis::HYP_OK;
100 // there is only one compatible Hypothesis so far
102 const list <const SMESHDS_Hypothesis * >& hyps = GetUsedHypothesis(aMesh, aShape);
104 _hyp = static_cast<const HEXABLOCKPlugin_Hypothesis*> ( hyps.front() );
109 //=============================================================================
111 *Here we are going to use the HEXABLOCK mesher
113 //=============================================================================
115 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape) {
116 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute with a shape");
118 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
119 if ( (_iShape == 0) && (_nbShape == 0) ) {
120 TopExp_Explorer expShape ( meshDS->ShapeToMesh(), TopAbs_SOLID );
121 for ( ; expShape.More(); expShape.Next() ) {
126 // to prevent from displaying error message after computing,
127 for ( int i = 0; i < _nbShape; ++i )
128 if ( SMESH_subMesh* sm = theMesh.GetSubMeshContaining( theShape ))
130 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
131 /*complexShapeFirst=*/false);
132 while ( smIt->more() )
135 if ( !sm->IsMeshComputed() )
136 sm->SetIsAlwaysComputed( true );
143 if ( _iShape == _nbShape ) {
147 switch (_hyp->GetDimension()) {
148 case 0 : return( Compute0D(theMesh) );
149 case 1 : return( Compute1D(theMesh) );
150 case 2 : return( Compute2D(theMesh) );
151 default: return( Compute3D(theMesh) );
156 //=============================================================================
158 *Here we are going to use the HEXABLOCK mesher w/o geometry
160 //=============================================================================
162 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh,
163 SMESH_MesherHelper* aHelper)
165 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute without a shape");
167 switch (_hyp->GetDimension()) {
168 case 0 : return( Compute0D(theMesh) );
169 case 1 : return( Compute1D(theMesh) );
170 case 2 : return( Compute2D(theMesh) );
171 default: return( Compute3D(theMesh) );
175 //=============================================================================
179 //=============================================================================
180 bool HEXABLOCKPlugin_HEXABLOCK::Evaluate(SMESH_Mesh& aMesh,
181 const TopoDS_Shape& aShape,
182 MapShapeNbElems& aResMap)
184 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Evaluate: do nothing");
189 //=============================================================================
191 * Generate hexehedral
193 //=============================================================================
195 bool HEXABLOCKPlugin_HEXABLOCK::Compute3D(SMESH_Mesh& theMesh) {
196 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D Begin");
198 SMESH_HexaBlocks hexaBuilder(theMesh);
200 HEXA_NS::Document* doc = _hyp->GetDocument();
201 // doc->reorderFaces (); // 0) Abu 06/03/2012
203 hexaBuilder.computeDoc(doc);
204 hexaBuilder.buildGroups(doc);
206 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D End");
210 //=============================================================================
212 * Generate quadrangles
214 //=============================================================================
216 bool HEXABLOCKPlugin_HEXABLOCK::Compute2D(SMESH_Mesh& theMesh)
218 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 2D");
220 HEXA_NS::Document* doc = _hyp->GetDocument();
221 // doc->reorderFaces (); // 0) Abu 06/03/2012
223 SMESH_HexaBlocks hexaBuilder(theMesh);
225 // A) Vertex computation
226 int nVertex = doc->countUsedVertex();
227 HEXA_NS::Vertex* vertex = NULL;
228 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
229 vertex = doc->getUsedVertex(j);
230 hexaBuilder.computeVertex(*vertex);
233 // B) Edges computation
235 HEXA_NS::Propagation* propa = NULL;
236 HEXA_NS::Law* law = NULL;
237 HEXA_NS::Edges edges;
239 nbPropa = doc->countPropagation();
240 for (int j=0; j < nbPropa; ++j ){ //Computing each edge's propagations of the document
241 propa = doc->getPropagation(j);
242 edges = propa->getEdges();
243 law = propa->getLaw();
245 law = doc->getLaw(0); // default law
247 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
248 hexaBuilder.computeEdge(**iter, *law);
252 // C) Quad computation
253 std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(doc);
254 int nQuad = doc->countUsedQuad();
255 HEXA_NS::Quad* quad = NULL;
256 for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
257 quad = doc->getUsedQuad(j);
258 int id = quad->getId();
259 if ( quadWays.count(quad) > 0 )
260 hexaBuilder.computeQuad(*quad, quadWays[quad]);
262 if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
266 hexaBuilder.buildGroups(doc);
271 // SMESH::SMESH_Mesh_ptr SMESH_Gen_i::HexaBlocksQuad( HEXABLOCK_ORB::Document_ptr docIn, ::CORBA::Long quadID )
274 // SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
275 // if ( !aNewMesh->_is_nil() ) {
276 // SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
277 // Document_impl* docServant = dynamic_cast<Document_impl*>( GetServant( docIn ).in() );
278 // ASSERT( aNewImpl );
279 // ASSERT( docServant );
281 // HEXA_NS::Document* doc = docServant->GetImpl();
282 // SMESH_HexaBlocks hexaBuilder(aNewImpl);
284 // // A) Vertex computation
285 // int nVertex = doc->countVertex();
286 // HEXA_NS::Vertex* vertex = NULL;
287 // for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
288 // vertex = doc->getUsedVertex(j);
289 // hexaBuilder.computeVertex(*vertex);
292 // // B) Edges computation
294 // HEXA_NS::Propagation* propa = NULL;
295 // HEXA_NS::Law* law = NULL;
296 // HEXA_NS::Edges edges;
298 // nbPropa = doc->countPropagation();
299 // for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
300 // propa = doc->getPropagation(j);
301 // edges = propa->getEdges();
302 // law = propa->getLaw();
305 // law = doc->getLaw(0); // default law
307 // for( HEXA_NS::Edges::const_iterator iter = edges.begin();
308 // iter != edges.end();
310 // hexaBuilder.computeEdge(**iter, *law);
314 // // C) Quad computation
315 // std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(*doc);
316 // int nQuad = doc->countQuad();
317 // HEXA_NS::Quad* quad = NULL;
318 // for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
319 // quad = doc->getQuad(j);
320 // int id = quad->getId();
321 // if ( quadID == id and (quadWays.count(quad) > 0) )
322 // hexaBuilder.computeQuad( *quad, quadWays[quad] );
324 // if ( quadWays.count(quad) == 0 )
325 // if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
329 // // D) build Groups
330 // hexaBuilder.buildGroups(doc);
333 // return aNewMesh._retn();
334 // } catch (SALOME_Exception& S_ex) {
335 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
339 bool HEXABLOCKPlugin_HEXABLOCK::Compute1D(SMESH_Mesh& theMesh)
341 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 1D");
343 HEXA_NS::Document* doc = _hyp->GetDocument();
344 // doc->reorderFaces (); // 0) Abu 06/03/2012
346 SMESH_HexaBlocks hexaBuilder(theMesh);
348 // A) Vertex computation
349 int nVertex = doc->countUsedVertex();
350 HEXA_NS::Vertex* vertex = NULL;
351 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
352 vertex = doc->getUsedVertex(j);
353 hexaBuilder.computeVertex(*vertex);
356 // B) Edges computation
358 HEXA_NS::Propagation* propa = NULL;
359 HEXA_NS::Law* law = NULL;
360 HEXA_NS::Edges edges;
362 nbPropa = doc->countPropagation();
363 for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
364 propa = doc->getPropagation(j);
365 edges = propa->getEdges();
366 law = propa->getLaw();
369 law = doc->getLaw(0); // default law
371 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
372 hexaBuilder.computeEdge(**iter, *law);
377 hexaBuilder.buildGroups(doc);
382 bool HEXABLOCKPlugin_HEXABLOCK::Compute0D(SMESH_Mesh& theMesh)
384 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 0D");
386 HEXA_NS::Document* doc = _hyp->GetDocument();
387 // doc->reorderFaces (); // 0) Abu 06/03/2012
389 SMESH_HexaBlocks hexaBuilder(theMesh);
391 // A) Vertex computation
392 int nVertex = doc->countUsedVertex();
393 HEXA_NS::Vertex* vertex = NULL;
394 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
395 vertex = doc->getUsedVertex(j);
396 hexaBuilder.computeVertex(*vertex);
400 hexaBuilder.buildGroups(doc);