1 // Copyright (C) 2009-2024 CEA, EDF
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"
52 //=============================================================================
56 //=============================================================================
58 HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK(int hypId, SMESH_Gen* gen)
59 : SMESH_3D_Algo(hypId, gen)
61 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK");
62 _name = "HEXABLOCK_3D";
63 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
64 _compatibleHypothesis.push_back("HEXABLOCK_Parameters");
65 _requireShape = false; // can work without shape
66 _requireDiscreteBoundary = false;
68 _supportSubmeshes = false;
73 //=============================================================================
77 //=============================================================================
79 HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK()
81 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK");
84 //=============================================================================
88 //=============================================================================
90 bool HEXABLOCKPlugin_HEXABLOCK::CheckHypothesis ( SMESH_Mesh& aMesh,
91 const TopoDS_Shape& aShape,
92 Hypothesis_Status& aStatus )
94 aStatus = SMESH_Hypothesis::HYP_OK;
96 // there is only one compatible Hypothesis so far
98 const list <const SMESHDS_Hypothesis * >& hyps = GetUsedHypothesis(aMesh, aShape);
100 _hyp = static_cast<const HEXABLOCKPlugin_Hypothesis*> ( hyps.front() );
105 //=============================================================================
107 *Here we are going to use the HEXABLOCK mesher
109 //=============================================================================
111 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape) {
112 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute with a shape");
114 SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
115 if ( (_iShape == 0) && (_nbShape == 0) ) {
116 TopExp_Explorer expShape ( meshDS->ShapeToMesh(), TopAbs_SOLID );
117 for ( ; expShape.More(); expShape.Next() ) {
122 // to prevent from displaying error message after computing,
123 for ( int i = 0; i < _nbShape; ++i )
124 if ( SMESH_subMesh* sm = theMesh.GetSubMeshContaining( theShape ))
126 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
127 /*complexShapeFirst=*/false);
128 while ( smIt->more() )
131 if ( !sm->IsMeshComputed() )
132 sm->SetIsAlwaysComputed( true );
139 if ( _iShape == _nbShape ) {
143 switch (_hyp->GetDimension()) {
144 case 0 : return( Compute0D(theMesh) );
145 case 1 : return( Compute1D(theMesh) );
146 case 2 : return( Compute2D(theMesh) );
147 default: return( Compute3D(theMesh) );
153 //=============================================================================
155 *Here we are going to use the HEXABLOCK mesher w/o geometry
157 //=============================================================================
159 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh,
160 SMESH_MesherHelper* aHelper)
162 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute without a shape");
164 switch (_hyp->GetDimension()) {
165 case 0 : return( Compute0D(theMesh) );
166 case 1 : return( Compute1D(theMesh) );
167 case 2 : return( Compute2D(theMesh) );
168 default: return( Compute3D(theMesh) );
172 //=============================================================================
176 //=============================================================================
177 bool HEXABLOCKPlugin_HEXABLOCK::Evaluate(SMESH_Mesh& aMesh,
178 const TopoDS_Shape& aShape,
179 MapShapeNbElems& aResMap)
181 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Evaluate: do nothing");
186 //=============================================================================
188 * Generate hexehedral
190 //=============================================================================
192 bool HEXABLOCKPlugin_HEXABLOCK::Compute3D(SMESH_Mesh& theMesh) {
193 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D Begin");
195 SMESH_HexaBlocks hexaBuilder(theMesh);
197 HEXA_NS::Document* doc = _hyp->GetDocument();
198 // doc->reorderFaces (); // 0) Abu 06/03/2012
200 hexaBuilder.computeDoc(doc);
201 hexaBuilder.buildGroups(doc);
203 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D End");
207 //=============================================================================
209 * Generate quadrangles
211 //=============================================================================
213 bool HEXABLOCKPlugin_HEXABLOCK::Compute2D(SMESH_Mesh& theMesh)
215 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 2D");
217 HEXA_NS::Document* doc = _hyp->GetDocument();
218 // doc->reorderFaces (); // 0) Abu 06/03/2012
220 SMESH_HexaBlocks hexaBuilder(theMesh);
222 // A) Vertex computation
223 int nVertex = doc->countUsedVertex();
224 HEXA_NS::Vertex* vertex = NULL;
225 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
226 vertex = doc->getUsedVertex(j);
227 hexaBuilder.computeVertex(*vertex);
230 // B) Edges computation
232 HEXA_NS::Propagation* propa = NULL;
233 HEXA_NS::Law* law = NULL;
234 HEXA_NS::Edges edges;
236 nbPropa = doc->countPropagation();
237 for (int j=0; j < nbPropa; ++j ){ //Computing each edge's propagations of the document
238 propa = doc->getPropagation(j);
239 edges = propa->getEdges();
240 law = propa->getLaw();
242 law = doc->getLaw(0); // default law
244 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
245 hexaBuilder.computeEdge(**iter, *law);
249 // C) Quad computation
250 std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(doc);
251 int nQuad = doc->countUsedQuad();
252 HEXA_NS::Quad* quad = NULL;
253 for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
254 quad = doc->getUsedQuad(j);
255 int id = quad->getId();
256 if ( quadWays.count(quad) > 0 )
257 hexaBuilder.computeQuad(*quad, quadWays[quad]);
259 MESSAGE("NO QUAD WAY ID = "<<id);
263 hexaBuilder.buildGroups(doc);
268 // SMESH::SMESH_Mesh_ptr SMESH_Gen_i::HexaBlocksQuad( HEXABLOCK_ORB::Document_ptr docIn, ::CORBA::Long quadID )
271 // SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
272 // if ( !aNewMesh->_is_nil() ) {
273 // SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
274 // Document_impl* docServant = dynamic_cast<Document_impl*>( GetServant( docIn ).in() );
275 // ASSERT( aNewImpl );
276 // ASSERT( docServant );
278 // HEXA_NS::Document* doc = docServant->GetImpl();
279 // SMESH_HexaBlocks hexaBuilder(aNewImpl);
281 // // A) Vertex computation
282 // int nVertex = doc->countVertex();
283 // HEXA_NS::Vertex* vertex = NULL;
284 // for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
285 // vertex = doc->getUsedVertex(j);
286 // hexaBuilder.computeVertex(*vertex);
289 // // B) Edges computation
291 // HEXA_NS::Propagation* propa = NULL;
292 // HEXA_NS::Law* law = NULL;
293 // HEXA_NS::Edges edges;
295 // nbPropa = doc->countPropagation();
296 // for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
297 // propa = doc->getPropagation(j);
298 // edges = propa->getEdges();
299 // law = propa->getLaw();
302 // law = doc->getLaw(0); // default law
304 // for( HEXA_NS::Edges::const_iterator iter = edges.begin();
305 // iter != edges.end();
307 // hexaBuilder.computeEdge(**iter, *law);
311 // // C) Quad computation
312 // std::map<HEXA_NS::Quad*, bool> quadWays = hexaBuilder.computeQuadWays(*doc);
313 // int nQuad = doc->countQuad();
314 // HEXA_NS::Quad* quad = NULL;
315 // for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
316 // quad = doc->getQuad(j);
317 // int id = quad->getId();
318 // if ( quadID == id and (quadWays.count(quad) > 0) )
319 // hexaBuilder.computeQuad( *quad, quadWays[quad] );
321 // if ( quadWays.count(quad) == 0 )
322 // MESSAGE("NO QUAD WAY ID = "<<id);
326 // // D) build Groups
327 // hexaBuilder.buildGroups(doc);
330 // return aNewMesh._retn();
331 // } catch (SALOME_Exception& S_ex) {
332 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
336 bool HEXABLOCKPlugin_HEXABLOCK::Compute1D(SMESH_Mesh& theMesh)
338 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 1D");
340 HEXA_NS::Document* doc = _hyp->GetDocument();
341 // doc->reorderFaces (); // 0) Abu 06/03/2012
343 SMESH_HexaBlocks hexaBuilder(theMesh);
345 // A) Vertex computation
346 int nVertex = doc->countUsedVertex();
347 HEXA_NS::Vertex* vertex = NULL;
348 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
349 vertex = doc->getUsedVertex(j);
350 hexaBuilder.computeVertex(*vertex);
353 // B) Edges computation
355 HEXA_NS::Propagation* propa = NULL;
356 HEXA_NS::Law* law = NULL;
357 HEXA_NS::Edges edges;
359 nbPropa = doc->countPropagation();
360 for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
361 propa = doc->getPropagation(j);
362 edges = propa->getEdges();
363 law = propa->getLaw();
366 law = doc->getLaw(0); // default law
368 for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
369 hexaBuilder.computeEdge(**iter, *law);
374 hexaBuilder.buildGroups(doc);
379 bool HEXABLOCKPlugin_HEXABLOCK::Compute0D(SMESH_Mesh& theMesh)
381 MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 0D");
383 HEXA_NS::Document* doc = _hyp->GetDocument();
384 // doc->reorderFaces (); // 0) Abu 06/03/2012
386 SMESH_HexaBlocks hexaBuilder(theMesh);
388 // A) Vertex computation
389 int nVertex = doc->countUsedVertex();
390 HEXA_NS::Vertex* vertex = NULL;
391 for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
392 vertex = doc->getUsedVertex(j);
393 hexaBuilder.computeVertex(*vertex);
397 hexaBuilder.buildGroups(doc);