Salome HOME
71ba606a9fe475ec0cd093dd350e2a5a0490c63a
[modules/med.git] / src / MedClient / src / CONNECTIVITYClient.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "MEDMEM_convert.hxx"
24 #include "Utils_CorbaException.hxx"
25 #include "UtilClient.hxx"
26 #include "CONNECTIVITYClient.hxx"
27
28 #include "ReceiverFactory.hxx"
29 using namespace MEDMEM;
30 //=============================================================================
31 /*!
32  * Constructeur
33  */
34 //=============================================================================
35
36 CONNECTIVITYClient::CONNECTIVITYClient(const SALOME_MED::MESH_ptr m,
37                                        medEntityMesh Entity) :
38   CONNECTIVITY(m->getNumberOfTypes(Entity), Entity),
39   _numberOfElements_client(0),
40   _complete(false),
41   IOR_Mesh(SALOME_MED::MESH::_duplicate(m))
42 {
43   ASSERT(m);
44
45   blankCopy();
46 }
47
48 //=============================================================================
49 /*!
50  * Destructeur
51  */
52 //=============================================================================
53 CONNECTIVITYClient::~CONNECTIVITYClient()
54 {
55   if (_numberOfElements_client)
56     delete [] _numberOfElements_client;
57 }
58
59 //=============================================================================
60 /*!
61  * Remplit les informations nĂ©cessaires
62  * 1 seul appel Corba
63  */
64 //=============================================================================
65 void CONNECTIVITYClient::blankCopy()
66 {
67    SALOME_MED::MESH::connectivityInfos_var all;
68    medEntityMesh Entity = getEntity();
69    try
70    {
71         all= IOR_Mesh->getConnectGlobal(Entity);
72    }
73    catch (const exception & ex)
74    {
75         MESSAGE("Unable to acces Global information");
76         THROW_SALOME_CORBA_EXCEPTION(ex.what() ,SALOME::INTERNAL_ERROR);
77    }
78
79   _numberOfNodes = all->numberOfNodes;
80   _entityDimension = all->entityDimension;
81   medGeometryElement * Types;
82
83   long iT, nT;
84   convertCorbaArray<MED_EN::medGeometryElement,SALOME_MED::medGeometryElement_array *, long>
85     (Types, nT, &all->meshTypes);
86
87   ASSERT(nT == (int) getNumberOfTypes(Entity));
88   SCRUTE(nT);
89   
90   setGeometricTypes(Types, Entity);
91
92   _totalNumberOfElements_client = 0L;
93   if (_numberOfElements_client)
94     delete [] _numberOfElements_client;
95   _numberOfElements_client = new long[nT];
96   for (iT=0; iT<nT; iT++) 
97    {
98     _numberOfElements_client[iT] =  all->numberOfElements[iT];
99     _totalNumberOfElements_client += _numberOfElements_client[iT];
100     SCRUTE(iT);
101     SCRUTE(_numberOfElements_client[iT]);
102   }
103
104   if(Types)
105     delete [] Types;
106
107   // create a constituent (PAL10556)
108 // The consequence is that, if the remote server
109 // has not calculated nodal connectivity of dimension d-1, heavy method
110 // (CPU and memory) calculateDecsendingConnectivity is called on this
111 // server for a potentially useless information for client side . (by Anthony GEAY)
112    if ( Entity == MED_CELL ) {
113      Entity = ( IOR_Mesh->getMeshDimension() == 3 ? MED_FACE : MED_EDGE );
114      if(_constituent)
115        delete _constituent;
116      _constituent = new CONNECTIVITYClient( IOR_Mesh, Entity );
117    }
118
119   _complete = false;
120 }
121
122 //=============================================================================
123 /*!
124  */
125 //=============================================================================
126 // template< class T>
127 // void dumpArray(const T* array, int size, const char* msg)
128 // {
129 //   if ( msg )
130 //     std::cout << msg << " " << std::endl;
131 //   std::cout << "Size: " << size << std::endl;
132 //   for ( int i = 0; i < size; i++ )
133 //     std::cout << " " << array[ i ];
134 //   std::cout << endl;
135 // }
136
137 void CONNECTIVITYClient::fillCopy()
138 {
139   if (!_complete) {
140
141     int *pC;
142     long nC;
143     
144     medEntityMesh Entity = getEntity();
145     int iT, nT = getNumberOfTypes(Entity);
146     SCRUTE(nT);
147     const medGeometryElement * T = getGeometricTypes(Entity);
148     
149     int * Count = new int[nT+1] ;
150     Count[0]=1 ;
151     SCRUTE(Count[0]);
152     for (iT=0; iT<nT; iT++) {
153       Count[iT+1]=Count[iT] + _numberOfElements_client[iT];
154       SCRUTE(Count[iT+1]);
155     }
156     setCount(Count, Entity) ;
157     
158     for (iT=0; iT<nT; iT++) {
159       
160       SCRUTE(iT);
161       SCRUTE(Count[iT+1]-Count[iT]);
162       
163       SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForConnectivity(MED_NODAL, Entity, T[iT]);
164       pC=ReceiverFactory::getValue(senderForConnectivity,nC);
165       SCRUTE(nC);
166       ASSERT(nC == (T[iT]%100) * (Count[iT+1]-Count[iT]));
167
168       int *index = 0;
169       if ( T[iT] == MED_EN::MED_POLYGON || T[iT] == MED_EN::MED_POLYHEDRA )
170       {
171         SALOME::SenderInt_var senderForIndex=IOR_Mesh->getSenderForConnectivityIndex(MED_NODAL, Entity, T[iT]);
172         index=ReceiverFactory::getValue(senderForIndex,nC);
173         ASSERT(nC == (Count[iT+1]-Count[iT]+1));
174       }
175
176       setNodal(pC, Entity, T[iT], index);
177       delete [] pC;
178       delete [] index;
179     }
180
181     delete[] Count;
182     if (_constituent)
183       ((CONNECTIVITYClient *)_constituent)->fillCopy();
184     _complete = true;
185   }
186 }
187
188 //=============================================================================
189 /*!
190  */
191 //=============================================================================
192 int CONNECTIVITYClient::getNumberOf(medEntityMesh Entity, 
193                                     medGeometryElement Type) const
194 {
195   int n = 0;
196
197   SCRUTE(Type);
198   SCRUTE(Entity);
199   
200   if (!_complete) {
201     
202     if (Entity == _entity) {
203       
204       if (Type==MED_ALL_ELEMENTS)
205         n = _totalNumberOfElements_client;
206       
207       for (int i=0; i<_numberOfTypes; i++) {
208         SCRUTE(_geometricTypes[i]);
209         if (_geometricTypes[i] == Type) {
210           n = _numberOfElements_client[i];
211           break;
212         }
213       }
214     } 
215     else if (_constituent != NULL)
216       n = _constituent->getNumberOf(Entity,Type);
217     
218   }
219   else
220     n = CONNECTIVITY::getNumberOf(Entity, Type);
221
222   SCRUTE(n);
223   return n;
224 }
225
226 //=============================================================================
227 /*!
228  */
229 //=============================================================================
230 const int * CONNECTIVITYClient::getConnectivity (medConnectivity ConnectivityType, 
231                                                  medEntityMesh Entity,
232                                                  medGeometryElement Type) const
233 {
234   if (!_complete)
235     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
236
237   const int * c = CONNECTIVITY::getConnectivity (ConnectivityType, Entity, Type);
238
239   return c;
240 }
241
242 int CONNECTIVITYClient::getConnectivityLength(medConnectivity    ConnectivityType,
243                                               medEntityMesh      Entity,
244                                               medGeometryElement Type) const
245 {
246   if (!_complete)
247     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
248
249   const int l = CONNECTIVITY::getConnectivityLength (ConnectivityType, Entity, Type);
250
251   return l;
252 }
253
254 //=============================================================================
255 /*!
256  */
257 //=============================================================================
258 const int * CONNECTIVITYClient::getConnectivityIndex (medConnectivity ConnectivityType,
259                                                       medEntityMesh Entity) const
260 {
261   if (!_complete)
262     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
263
264   const int *c = CONNECTIVITY::getConnectivityIndex
265     (ConnectivityType, Entity);
266
267   return c;
268 }
269
270 //=============================================================================
271 /*!
272  */
273 //=============================================================================
274 void CONNECTIVITYClient::calculateConnectivity (medConnectivity connectivityType, 
275                                                 medEntityMesh Entity)
276 {
277   if (!_complete)
278     fillCopy();
279
280   CONNECTIVITY::calculateConnectivity(connectivityType, Entity);
281 }
282
283 //=============================================================================
284 /*!
285  */
286 //=============================================================================
287 void  CONNECTIVITYClient::updateFamily (vector<FAMILY*> myFamilies)
288 {
289   if (!_complete)
290     fillCopy();
291
292   CONNECTIVITY::updateFamily(myFamilies);
293 }
294
295 //=============================================================================
296 /*!
297  */
298 //=============================================================================
299 const int * CONNECTIVITYClient::getGlobalNumberingIndex (medEntityMesh Entity) const
300   throw (MEDEXCEPTION)
301 {
302   if (!_complete)
303     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
304
305   const int * index = CONNECTIVITY::getGlobalNumberingIndex(Entity);
306
307   return index;
308 }
309
310 //=============================================================================
311 /*!
312  */
313 //=============================================================================
314 bool CONNECTIVITYClient::existConnectivity(medConnectivity ConnectivityType, 
315                                            medEntityMesh Entity) const
316
317   if (!_complete)
318     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
319
320   bool b = CONNECTIVITY::existConnectivity(ConnectivityType, Entity);
321
322   return b;
323 }
324
325 //=============================================================================
326 /*!
327  */
328 //=============================================================================
329 const int * CONNECTIVITYClient::getReverseConnectivity (medConnectivity ConnectivityType, 
330                                                         medEntityMesh Entity) const
331   throw (MEDEXCEPTION)
332 {
333   if (!_complete)
334     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
335
336   const int *c = CONNECTIVITY::getReverseConnectivity
337     (ConnectivityType, Entity);
338
339   return c;
340 }
341
342 //=============================================================================
343 /*!
344  */
345 //=============================================================================
346 const int * CONNECTIVITYClient::getReverseConnectivityIndex (medConnectivity ConnectivityType,
347                                                              medEntityMesh Entity) const
348   throw (MEDEXCEPTION)
349 {
350   if (!_complete)
351     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
352
353   const int *c =  CONNECTIVITY::getReverseConnectivityIndex
354     (ConnectivityType, Entity);
355
356   return c;
357 }
358
359 //=============================================================================
360 /*!
361  */
362 //=============================================================================
363 const int* CONNECTIVITYClient::getValue(medConnectivity TypeConnectivity, 
364                                         medGeometryElement Type) const
365 {
366   if (!_complete)
367     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
368
369   const int * c =  CONNECTIVITY::getValue(TypeConnectivity, Type);
370
371   return c;
372 }
373
374 //=============================================================================
375 /*!
376  */
377 //=============================================================================
378 const int* CONNECTIVITYClient::getValueIndex(medConnectivity TypeConnectivity) const
379 {
380   if (!_complete)
381     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
382
383   const int * c =  CONNECTIVITY::getValueIndex(TypeConnectivity);
384
385   return c;
386 }
387
388 //=============================================================================
389 /*!
390  */
391 //=============================================================================
392 const int* CONNECTIVITYClient::getNeighbourhood() const
393 {
394   if (!_complete)
395     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
396
397   const int * c =  CONNECTIVITY::getNeighbourhood();
398
399   return c;
400 }