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 "SMESHDS_Mesh.hxx"
36 #include "SMESH_Gen.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MesherHelper.hxx"
39 #include "SMESH_subMesh.hxx"
41 #include "HEXABLOCKPlugin_mesh.hxx"
43 #include "HexQuad.hxx"
44 #include "HexEdge.hxx"
45 #include "HexVertex.hxx"
46 #include "HexPropagation.hxx"
48 #include "utilities.h"
53 static int MYDEBUG = HEXA_NS::on_debug ();
55 static int MYDEBUG = 0;
58 //=============================================================================
62 //=============================================================================
64 HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK(int hypId, SMESH_Gen* gen)
65 : SMESH_3D_Algo(hypId, gen)
67 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK");
68 _name = "HEXABLOCK_3D";
69 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
70 _compatibleHypothesis.push_back("HEXABLOCK_Parameters");
71 _requireShape = false; // can work without shape
72 _requireDiscreteBoundary = false;
74 _supportSubmeshes = false;
79 //=============================================================================
83 //=============================================================================
85 HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK()
87 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK");
90 //=============================================================================
94 //=============================================================================
96 bool HEXABLOCKPlugin_HEXABLOCK::CheckHypothesis ( SMESH_Mesh& aMesh,
97 const TopoDS_Shape& aShape,
98 Hypothesis_Status& aStatus )
100 aStatus = SMESH_Hypothesis::HYP_OK;
102 // there is only one compatible Hypothesis so far
104 const list <const SMESHDS_Hypothesis * >& hyps = GetUsedHypothesis(aMesh, aShape);
106 _hyp = static_cast<const HEXABLOCKPlugin_Hypothesis*> ( hyps.front() );
111 //=============================================================================
113 *Here we are going to use the HEXABLOCK mesher
115 //=============================================================================
117 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape) {
118 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute with a shape");
120 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
121 if ( (_iShape == 0) && (_nbShape == 0) ) {
122 TopExp_Explorer expShape ( meshDS->ShapeToMesh(), TopAbs_SOLID );
123 for ( ; expShape.More(); expShape.Next() ) {
128 // to prevent from displaying error message after computing,
129 for ( int i = 0; i < _nbShape; ++i )
130 if ( SMESH_subMesh* sm = theMesh.GetSubMeshContaining( theShape ))
132 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
133 /*complexShapeFirst=*/false);
134 while ( smIt->more() )
137 if ( !sm->IsMeshComputed() )
138 sm->SetIsAlwaysComputed( true );
145 if ( _iShape == _nbShape ) {
149 switch (_hyp->GetDimension()) {
150 case 0 : return( Compute0D(theMesh) );
151 case 1 : return( Compute1D(theMesh) );
152 case 2 : return( Compute2D(theMesh) );
153 default: return( Compute3D(theMesh) );
159 //=============================================================================
161 *Here we are going to use the HEXABLOCK mesher w/o geometry
163 //=============================================================================
165 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh,
166 SMESH_MesherHelper* aHelper)
168 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute without a shape");
170 switch (_hyp->GetDimension()) {
171 case 0 : return( Compute0D(theMesh) );
172 case 1 : return( Compute1D(theMesh) );
173 case 2 : return( Compute2D(theMesh) );
174 default: return( Compute3D(theMesh) );
178 //=============================================================================
182 //=============================================================================
183 bool HEXABLOCKPlugin_HEXABLOCK::Evaluate(SMESH_Mesh& aMesh,
184 const TopoDS_Shape& aShape,
185 MapShapeNbElems& aResMap)
187 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Evaluate: do nothing");
192 //=============================================================================
194 * Generate hexehedral
196 //=============================================================================
198 bool HEXABLOCKPlugin_HEXABLOCK::Compute3D(SMESH_Mesh& theMesh) {
199 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D Begin");
201 SMESH_HexaBlocks hexaBuilder(theMesh);
203 HEXA_NS::Document* doc = _hyp->GetDocument();
204 // doc->reorderFaces (); // 0) Abu 06/03/2012
206 hexaBuilder.computeDoc(doc);
207 hexaBuilder.buildGroups(doc);
209 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D End");
213 //=============================================================================
215 * Generate quadrangles
217 //=============================================================================
219 bool HEXABLOCKPlugin_HEXABLOCK::Compute2D(SMESH_Mesh& theMesh)
221 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 2D");
223 HEXA_NS::Document* doc = _hyp->GetDocument();
224 // doc->reorderFaces (); // 0) Abu 06/03/2012
226 SMESH_HexaBlocks hexaBuilder(theMesh);
228 // A) Vertex computation
229 int nVertex = doc->countUsedVertex();
230 HEXA_NS::Vertex* vertex = NULL;
231 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
232 vertex = doc->getUsedVertex(j);
233 hexaBuilder.computeVertex(*vertex);
236 // B) Edges computation
238 HEXA_NS::Propagation* propa = NULL;
239 HEXA_NS::Law* law = NULL;
240 HEXA_NS::Edges edges;
242 nbPropa = doc->countPropagation();
243 for (int j=0; j < nbPropa; ++j ){ //Computing each edge's propagations of the document
244 propa = doc->getPropagation(j);
245 edges = propa->getEdges();
246 law = propa->getLaw();
248 law = doc->getLaw(0); // default law
250 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
251 hexaBuilder.computeEdge(**iter, *law);
255 // C) Quad computation
256 std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(doc);
257 int nQuad = doc->countUsedQuad();
258 HEXA_NS::Quad* quad = NULL;
259 for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
260 quad = doc->getUsedQuad(j);
261 int id = quad->getId();
262 if ( quadWays.count(quad) > 0 )
263 hexaBuilder.computeQuad(*quad, quadWays[quad]);
265 if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
269 hexaBuilder.buildGroups(doc);
274 // SMESH::SMESH_Mesh_ptr SMESH_Gen_i::HexaBlocksQuad( HEXABLOCK_ORB::Document_ptr docIn, ::CORBA::Long quadID )
277 // SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
278 // if ( !aNewMesh->_is_nil() ) {
279 // SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
280 // Document_impl* docServant = dynamic_cast<Document_impl*>( GetServant( docIn ).in() );
281 // ASSERT( aNewImpl );
282 // ASSERT( docServant );
284 // HEXA_NS::Document* doc = docServant->GetImpl();
285 // SMESH_HexaBlocks hexaBuilder(aNewImpl);
287 // // A) Vertex computation
288 // int nVertex = doc->countVertex();
289 // HEXA_NS::Vertex* vertex = NULL;
290 // for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
291 // vertex = doc->getUsedVertex(j);
292 // hexaBuilder.computeVertex(*vertex);
295 // // B) Edges computation
297 // HEXA_NS::Propagation* propa = NULL;
298 // HEXA_NS::Law* law = NULL;
299 // HEXA_NS::Edges edges;
301 // nbPropa = doc->countPropagation();
302 // for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
303 // propa = doc->getPropagation(j);
304 // edges = propa->getEdges();
305 // law = propa->getLaw();
308 // law = doc->getLaw(0); // default law
310 // for( HEXA_NS::Edges::const_iterator iter = edges.begin();
311 // iter != edges.end();
313 // hexaBuilder.computeEdge(**iter, *law);
317 // // C) Quad computation
318 // std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(*doc);
319 // int nQuad = doc->countQuad();
320 // HEXA_NS::Quad* quad = NULL;
321 // for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
322 // quad = doc->getQuad(j);
323 // int id = quad->getId();
324 // if ( quadID == id and (quadWays.count(quad) > 0) )
325 // hexaBuilder.computeQuad( *quad, quadWays[quad] );
327 // if ( quadWays.count(quad) == 0 )
328 // if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
332 // // D) build Groups
333 // hexaBuilder.buildGroups(doc);
336 // return aNewMesh._retn();
337 // } catch (SALOME_Exception& S_ex) {
338 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
342 bool HEXABLOCKPlugin_HEXABLOCK::Compute1D(SMESH_Mesh& theMesh)
344 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 1D");
346 HEXA_NS::Document* doc = _hyp->GetDocument();
347 // doc->reorderFaces (); // 0) Abu 06/03/2012
349 SMESH_HexaBlocks hexaBuilder(theMesh);
351 // A) Vertex computation
352 int nVertex = doc->countUsedVertex();
353 HEXA_NS::Vertex* vertex = NULL;
354 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
355 vertex = doc->getUsedVertex(j);
356 hexaBuilder.computeVertex(*vertex);
359 // B) Edges computation
361 HEXA_NS::Propagation* propa = NULL;
362 HEXA_NS::Law* law = NULL;
363 HEXA_NS::Edges edges;
365 nbPropa = doc->countPropagation();
366 for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
367 propa = doc->getPropagation(j);
368 edges = propa->getEdges();
369 law = propa->getLaw();
372 law = doc->getLaw(0); // default law
374 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
375 hexaBuilder.computeEdge(**iter, *law);
380 hexaBuilder.buildGroups(doc);
385 bool HEXABLOCKPlugin_HEXABLOCK::Compute0D(SMESH_Mesh& theMesh)
387 if(MYDEBUG) MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 0D");
389 HEXA_NS::Document* doc = _hyp->GetDocument();
390 // doc->reorderFaces (); // 0) Abu 06/03/2012
392 SMESH_HexaBlocks hexaBuilder(theMesh);
394 // A) Vertex computation
395 int nVertex = doc->countUsedVertex();
396 HEXA_NS::Vertex* vertex = NULL;
397 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
398 vertex = doc->getUsedVertex(j);
399 hexaBuilder.computeVertex(*vertex);
403 hexaBuilder.buildGroups(doc);