]> SALOME platform Git repositories - plugins/hexablockplugin.git/blob - src/HEXABLOCKPlugin/HEXABLOCKPlugin_HEXABLOCK.cxx
Salome HOME
First publish of HEXABLOCKPLUGIN
[plugins/hexablockplugin.git] / src / HEXABLOCKPlugin / HEXABLOCKPlugin_HEXABLOCK.cxx
1 //  Copyright (C) 2004-2010  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //=============================================================================
21 // File      : HEXABLOCKPlugin_HEXABLOCK.cxx
22 // Created   : 
23 // Author    : Lioka RAZAFINDRAZAKA (CEA)
24 // Project   : SALOME
25 // $Header$
26 //=============================================================================
27 //
28 #include "HEXABLOCKPlugin_HEXABLOCK.hxx"
29 #include "HEXABLOCKPlugin_Hypothesis.hxx"
30
31 #include <Basics_Utils.hxx>
32
33 #include "SMESH_Gen.hxx"
34 #include "SMESH_Mesh.hxx"
35 #include "SMESH_MesherHelper.hxx"
36
37 #include "HEXABLOCKPlugin_mesh.hxx"
38  
39 #include "HexQuad.hxx"
40 #include "HexEdge.hxx"
41 #include "HexVertex.hxx"
42 #include "HexPropagation.hxx"
43
44 #include "utilities.h"
45
46 using namespace std;
47
48 static int MYDEBUG = 0;
49
50 //=============================================================================
51 /*!
52  *  
53  */
54 //=============================================================================
55
56 HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK(int hypId, int studyId, SMESH_Gen* gen)
57   : SMESH_3D_Algo(hypId, studyId, gen)
58 {
59   MESSAGE("HEXABLOCKPlugin_HEXABLOCK::HEXABLOCKPlugin_HEXABLOCK");
60   _name = "HEXABLOCK_3D";
61   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
62   _compatibleHypothesis.push_back("HEXABLOCK_Parameters");
63   _requireShape = false; // can work without shape
64   _requireDescretBoundary = false;
65   _onlyUnaryInput = false; // Compute() will be called on a compound of solids
66   _hyp = NULL;
67   _supportSubmeshes = false;
68 }
69
70 //=============================================================================
71 /*!
72  *  
73  */
74 //=============================================================================
75
76 HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK()
77 {
78   MESSAGE("HEXABLOCKPlugin_HEXABLOCK::~HEXABLOCKPlugin_HEXABLOCK");
79 }
80
81 //=============================================================================
82 /*!
83  *  
84  */
85 //=============================================================================
86
87 bool HEXABLOCKPlugin_HEXABLOCK::CheckHypothesis ( SMESH_Mesh& aMesh,
88                                           const TopoDS_Shape& aShape,
89                                           Hypothesis_Status&  aStatus )
90 {
91   aStatus = SMESH_Hypothesis::HYP_OK;
92
93   // there is only one compatible Hypothesis so far
94   _hyp = 0;
95   const list <const SMESHDS_Hypothesis * >& hyps = GetUsedHypothesis(aMesh, aShape);
96   if ( !hyps.empty() )
97     _hyp = static_cast<const HEXABLOCKPlugin_Hypothesis*> ( hyps.front() );
98
99   return true;
100 }
101
102 //=============================================================================
103 /*!
104  *Here we are going to use the HEXABLOCK mesher
105  */
106 //=============================================================================
107
108 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh,
109                                 const TopoDS_Shape& theShape)
110 {
111   MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute with a shape");
112
113   switch (_hyp->GetDimension()) {
114     case 0 : return( Compute0D(theMesh) );
115     case 1 : return( Compute1D(theMesh) );
116     case 2 : return( Compute2D(theMesh) );
117     default: return( Compute3D(theMesh) );
118   }
119 }
120
121 //=============================================================================
122 /*!
123  *Here we are going to use the HEXABLOCK mesher w/o geometry
124  */
125 //=============================================================================
126
127 bool HEXABLOCKPlugin_HEXABLOCK::Compute(SMESH_Mesh& theMesh,
128                                 SMESH_MesherHelper* aHelper)
129 {
130   MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute without a shape");
131
132   switch (_hyp->GetDimension()) {
133     case 0 : return( Compute0D(theMesh) );
134     case 1 : return( Compute1D(theMesh) );
135     case 2 : return( Compute2D(theMesh) );
136     default: return( Compute3D(theMesh) );
137   }
138 }
139
140 //=============================================================================
141 /*!
142  *  
143  */
144 //=============================================================================
145 bool HEXABLOCKPlugin_HEXABLOCK::Evaluate(SMESH_Mesh& aMesh,
146                                  const TopoDS_Shape& aShape,
147                                  MapShapeNbElems& aResMap)
148 {
149   MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Evaluate: do nothing");
150
151   return true;
152 }
153
154 //=============================================================================
155 /*!
156  *  Generate hexehedral
157  */
158 //=============================================================================
159
160 bool HEXABLOCKPlugin_HEXABLOCK::Compute3D(SMESH_Mesh& theMesh) {
161   MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 3D");
162
163   SMESH_HexaBlocks hexaBuilder(theMesh);
164
165   HEXA_NS::Document* doc = _hyp->GetDocument();
166   hexaBuilder.computeDoc(doc);
167   hexaBuilder.buildGroups(doc);
168
169   return true;
170 }
171
172 //=============================================================================
173 /*!
174  *  Generate quadrangles
175  */
176 //=============================================================================
177
178 bool HEXABLOCKPlugin_HEXABLOCK::Compute2D(SMESH_Mesh& theMesh)
179 {
180   MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 2D");
181
182   HEXA_NS::Document* doc = _hyp->GetDocument();
183   SMESH_HexaBlocks hexaBuilder(theMesh);
184
185   // A) Vertex computation
186   int nVertex = doc->countVertex();
187   HEXA_NS::Vertex* vertex = NULL;
188   for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
189     vertex = doc->getVertex(j);
190     hexaBuilder.computeVertex(*vertex);
191   };
192
193   // B) Edges computation
194   int nbPropa = 0;
195   HEXA_NS::Propagation* propa = NULL;
196   HEXA_NS::Law*         law   = NULL;
197   HEXA_NS::Edges        edges;
198
199   nbPropa = doc->countPropagation();
200   for (int j=0; j < nbPropa; ++j ){ //Computing each edge's propagations of the document
201     propa = doc->getPropagation(j);
202     edges = propa->getEdges();
203     law   = propa->getLaw();
204     if (law == NULL){
205       law = doc->getLaw(0); // default law
206     };
207     for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
208       hexaBuilder.computeEdge(**iter, *law);
209     };
210   };
211
212   // C) Quad computation
213   std::map<HEXA_NS::Quad*, bool>  quadWays = hexaBuilder.computeQuadWays(doc);
214   int nQuad = doc->countQuad();
215   HEXA_NS::Quad* quad = NULL;
216   for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
217     quad = doc->getQuad(j);
218     int id = quad->getId();
219     if ( quadWays.count(quad) > 0 )
220       hexaBuilder.computeQuad(*quad, quadWays[quad]);
221     else
222       if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
223   };
224
225   // D) build Groups
226   hexaBuilder.buildGroups(doc);
227
228     return true;
229 }
230
231 // SMESH::SMESH_Mesh_ptr SMESH_Gen_i::HexaBlocksQuad( HEXABLOCK_ORB::Document_ptr docIn, ::CORBA::Long quadID )
232 // {
233 //   try {
234 //     SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
235 //     if ( !aNewMesh->_is_nil() ) {
236 //       SMESH_Mesh_i* aNewImpl    = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
237 //       Document_impl* docServant = dynamic_cast<Document_impl*>( GetServant( docIn ).in() );
238 //       ASSERT( aNewImpl );
239 //       ASSERT( docServant );
240
241 //       HEXA_NS::Document* doc = docServant->GetImpl();
242 //       SMESH_HexaBlocks hexaBuilder(aNewImpl);
243
244 //       // A) Vertex computation
245 //       int nVertex = doc->countVertex();
246 //       HEXA_NS::Vertex* vertex = NULL;
247 //       for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
248 //         vertex = doc->getVertex(j);
249 //         hexaBuilder.computeVertex(*vertex);
250 //       }
251
252 //       // B) Edges computation
253 //       int nbPropa = 0;
254 //       HEXA_NS::Propagation* propa = NULL;
255 //       HEXA_NS::Law*         law   = NULL;
256 //       HEXA_NS::Edges        edges;
257
258 //       nbPropa = doc->countPropagation();
259 //       for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
260 //         propa = doc->getPropagation(j);
261 //         edges = propa->getEdges();
262 //         law   = propa->getLaw();
263 // //         ASSERT( law );
264 //         if (law == NULL){
265 //           law = doc->getLaw(0); // default law
266 //         }
267 //         for( HEXA_NS::Edges::const_iterator iter = edges.begin();
268 //             iter != edges.end();
269 //             ++iter ){
270 //             hexaBuilder.computeEdge(**iter, *law);
271 //         }
272 //       }
273
274 //       // C) Quad computation
275 //       std::map<HEXA_NS::Quad*, bool>  quadWays = hexaBuilder.computeQuadWays(*doc);
276 //       int nQuad = doc->countQuad();
277 //       HEXA_NS::Quad* quad = NULL;
278 //       for (int j=0; j <nQuad; ++j ){ //Computing each quad of the document
279 //         quad = doc->getQuad(j);
280 //         int id = quad->getId();
281 //         if ( quadID == id and (quadWays.count(quad) > 0) )
282 //           hexaBuilder.computeQuad( *quad, quadWays[quad] );
283
284 //         if ( quadWays.count(quad) ==  0 )
285 //             if(MYDEBUG) MESSAGE("NO QUAD WAY ID = "<<id);
286
287 //       }
288
289 //       // D) build Groups
290 //       hexaBuilder.buildGroups(doc);
291
292 //     }
293 //     return aNewMesh._retn();
294 //   } catch (SALOME_Exception& S_ex) {
295 //     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
296 //   }
297 // }
298
299 bool HEXABLOCKPlugin_HEXABLOCK::Compute1D(SMESH_Mesh& theMesh)
300 {
301   MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 1D");
302
303   HEXA_NS::Document* doc = _hyp->GetDocument();
304   SMESH_HexaBlocks hexaBuilder(theMesh);
305
306   // A) Vertex computation
307   int nVertex = doc->countVertex();
308   HEXA_NS::Vertex* vertex = NULL;
309   for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
310     vertex = doc->getVertex(j);
311     hexaBuilder.computeVertex(*vertex);
312   };
313
314   // B) Edges computation
315   int nbPropa = 0;
316   HEXA_NS::Propagation* propa = NULL;
317   HEXA_NS::Law*         law   = NULL;
318   HEXA_NS::Edges        edges;
319
320   nbPropa = doc->countPropagation();
321   for (int j=0; j < nbPropa; ++j ){//Computing each edge's propagations of the document
322     propa = doc->getPropagation(j);
323     edges = propa->getEdges();
324     law   = propa->getLaw();
325     //         ASSERT( law );
326     if (law == NULL){
327       law = doc->getLaw(0); // default law
328     };
329     for( HEXA_NS::Edges::const_iterator iter = edges.begin(); iter != edges.end(); ++iter ) {
330       hexaBuilder.computeEdge(**iter, *law);
331     };
332   };
333
334   // C) build Groups
335   hexaBuilder.buildGroups(doc);
336
337     return true;
338 }
339
340 bool HEXABLOCKPlugin_HEXABLOCK::Compute0D(SMESH_Mesh& theMesh)
341 {
342   MESSAGE("HEXABLOCKPlugin_HEXABLOCK::Compute 0D");
343
344   HEXA_NS::Document* doc = _hyp->GetDocument();
345   SMESH_HexaBlocks hexaBuilder(theMesh);
346
347   // A) Vertex computation
348   int nVertex = doc->countVertex();
349   HEXA_NS::Vertex* vertex = NULL;
350   for ( int j=0; j <nVertex; ++j ){ //Computing each vertex of the document
351     vertex = doc->getVertex(j);
352     hexaBuilder.computeVertex(*vertex);
353   };
354
355   // B) build Groups
356   hexaBuilder.buildGroups(doc);
357
358   return true;
359 }