1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDMEM_convert.hxx"
21 #include "Utils_CorbaException.hxx"
22 #include "UtilClient.hxx"
23 #include "CONNECTIVITYClient.hxx"
25 #include "ReceiverFactory.hxx"
26 using namespace MEDMEM;
27 //=============================================================================
31 //=============================================================================
33 CONNECTIVITYClient::CONNECTIVITYClient(const SALOME_MED::MESH_ptr m,
34 medEntityMesh Entity) :
35 CONNECTIVITY(m->getNumberOfTypes(Entity), Entity),
36 IOR_Mesh(SALOME_MED::MESH::_duplicate(m)),
37 _numberOfElements_client(0),
40 BEGIN_OF("CONNECTIVITYClient::CONNECTIVITYClient()");
46 END_OF("CONNECTIVITYClient::CONNECTIVITYClient()");
49 //=============================================================================
53 //=============================================================================
54 CONNECTIVITYClient::~CONNECTIVITYClient()
56 BEGIN_OF("CONNECTIVITYClient::~CONNECTIVITYClient()");
58 if (_numberOfElements_client)
59 delete [] _numberOfElements_client;
61 END_OF("CONNECTIVITYClient::~CONNECTIVITYClient()");
64 //=============================================================================
66 * Remplit les informations nécessaires
69 //=============================================================================
70 void CONNECTIVITYClient::blankCopy()
72 BEGIN_OF("CONNECTIVITYClient::blankCopy()");
73 SALOME_MED::MESH::connectivityInfos_var all;
74 medEntityMesh Entity = getEntity();
77 all= IOR_Mesh->getConnectGlobal(Entity);
79 catch (const exception & ex)
81 MESSAGE("Unable to acces Global information");
82 THROW_SALOME_CORBA_EXCEPTION(ex.what() ,SALOME::INTERNAL_ERROR);
85 _numberOfNodes = all->numberOfNodes;
86 _entityDimension = all->entityDimension;
87 medGeometryElement * Types;
89 long iT, nTwithPoly, nT=getNumberOfTypes(Entity);
90 convertCorbaArray<MED_EN::medGeometryElement,SALOME_MED::medGeometryElement_array *, long>
91 (Types, nTwithPoly, &all->meshTypes);
93 //ASSERT(nT == (int) getNumberOfTypes(Entity)); FALSE with POLY
96 setGeometricTypes(Types, Entity);
98 _totalNumberOfElements_client = 0L;
99 if (_numberOfElements_client)
100 delete [] _numberOfElements_client;
101 _numberOfElements_client = new long[nTwithPoly];
102 for (iT=0; iT<nT; iT++)
104 _numberOfElements_client[iT] = all->numberOfElements[iT];
105 _totalNumberOfElements_client += _numberOfElements_client[iT];
107 SCRUTE(_numberOfElements_client[iT]);
110 if ( nT != nTwithPoly )
112 _numberOfElements_client[iT] = all->numberOfElements[iT];
113 _polyType_client = Types[iT];
117 _polyType_client = MED_EN::MED_NONE;
123 // create a constituent (PAL10556)
124 // The consequence is that, if the remote server
125 // has not calculated nodal connectivity of dimension d-1, heavy method
126 // (CPU and memory) calculateDecsendingConnectivity is called on this
127 // server for a potentially useless information for client side . (by Anthony GEAY)
128 if ( Entity == MED_CELL ) {
129 Entity = ( IOR_Mesh->getMeshDimension() == 3 ? MED_FACE : MED_EDGE );
132 _constituent = new CONNECTIVITYClient( IOR_Mesh, Entity );
137 END_OF("CONNECTIVITYClient::blankCopy()");
140 //=============================================================================
143 //=============================================================================
144 // template< class T>
145 // void dumpArray(const T* array, int size, const char* msg)
148 // std::cout << msg << " " << std::endl;
149 // std::cout << "Size: " << size << std::endl;
150 // for ( int i = 0; i < size; i++ )
151 // std::cout << " " << array[ i ];
152 // std::cout << endl;
155 void CONNECTIVITYClient::fillCopy()
157 BEGIN_OF("void CONNECTIVITYClient::fillCopy()");
165 medEntityMesh Entity = getEntity();
166 int iT, nT = getNumberOfTypes(Entity);
168 const medGeometryElement * T = getGeometricTypes(Entity);
170 int * Count = new int[nT+1] ;
173 for (iT=0; iT<nT; iT++) {
174 Count[iT+1]=Count[iT] + _numberOfElements_client[iT];
177 setCount(Count, Entity) ;
179 for (iT=0; iT<nT; iT++) {
182 int kT = Count[iT+1]-Count[iT];
185 SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForConnectivity(MED_FULL_INTERLACE, MED_NODAL, Entity, T[iT]);
186 pC=ReceiverFactory::getValue(senderForConnectivity,nC);
188 ASSERT(nC == (T[iT]%100) * kT);
190 setNodal(pC, Entity, T[iT]);
194 if ( _polyType_client == MED_POLYGON )
196 const medConnectivity ConType = MED_NODAL;
197 SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForPolygonsConnectivity (ConType, Entity);
198 SALOME::SenderInt_var senderForConnectivityIndex=IOR_Mesh->getSenderForPolygonsConnectivityIndex (ConType, Entity);
200 pC=ReceiverFactory::getValue(senderForConnectivity,nC);
202 int * pCI=ReceiverFactory::getValue(senderForConnectivityIndex,nP);
203 // dumpArray( pC, nC, "POLYGON Connectivity: ");
204 // dumpArray( pCI, nP, "POLYGON ConnectivityIndex: ");
206 setPolygonsConnectivity(ConType, Entity, pC, pCI, nC, nP-1);
211 if ( _polyType_client == MED_POLYHEDRA )
213 const medConnectivity ConType = MED_NODAL;
214 SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForPolyhedronConnectivity (ConType);
215 SALOME::SenderInt_var senderForPolyhedronIndex=IOR_Mesh->getSenderForPolyhedronIndex (ConType);
216 SALOME::SenderInt_var senderForPolyhedronFacesIndex=IOR_Mesh->getSenderForPolyhedronFacesIndex ();
218 pC=ReceiverFactory::getValue(senderForConnectivity,nC);
220 int * pPI=ReceiverFactory::getValue(senderForPolyhedronIndex,nP);
221 int * pFI=ReceiverFactory::getValue(senderForPolyhedronFacesIndex,nF);
223 // dumpArray( pC, nC, "POLYHedron Connectivity: ");
224 // dumpArray( pFI, nF, "POLYHedron Face Index: ");
225 // dumpArray( pPI, nP, "POLYHedron Index: ");
227 setPolyhedronConnectivity(ConType, pC, pPI, nC, nP-1, pFI, nF-1);
235 ((CONNECTIVITYClient *)_constituent)->fillCopy();
239 END_OF("void CONNECTIVITYClient::fillCopy()");
242 //=============================================================================
245 //=============================================================================
246 int CONNECTIVITYClient::getNumberOf(medEntityMesh Entity,
247 medGeometryElement Type) const
249 BEGIN_OF("void CONNECTIVITYClient::getNumberOf()");
258 if (Entity == _entity) {
260 if (Type==MED_ALL_ELEMENTS)
261 n = _totalNumberOfElements_client;
263 for (int i=0; i<_numberOfTypes; i++) {
264 SCRUTE(_geometricTypes[i]);
265 if (_geometricTypes[i] == Type) {
266 n = _numberOfElements_client[i];
271 else if (_constituent != NULL)
272 n = _constituent->getNumberOf(Entity,Type);
276 n = CONNECTIVITY::getNumberOf(Entity, Type);
279 END_OF("void CONNECTIVITYClient::getNumberOf()");
283 //=============================================================================
286 //=============================================================================
287 const int * CONNECTIVITYClient::getConnectivity
288 (medConnectivity ConnectivityType,
289 medEntityMesh Entity,
290 medGeometryElement Type)
292 BEGIN_OF("void CONNECTIVITYClient::getConnectivity()");
297 const int * c = CONNECTIVITY::getConnectivity
298 (ConnectivityType, Entity, Type);
300 END_OF("void CONNECTIVITYClient::getConnectivity()");
304 //=============================================================================
307 //=============================================================================
308 const int * CONNECTIVITYClient::getConnectivityIndex
309 (medConnectivity ConnectivityType,
310 medEntityMesh Entity)
312 BEGIN_OF("void CONNECTIVITYClient::getConnectivityIndex()");
317 const int *c = CONNECTIVITY::getConnectivityIndex
318 (ConnectivityType, Entity);
320 END_OF("void CONNECTIVITYClient::getConnectivityIndex()");
324 //=============================================================================
327 //=============================================================================
328 void CONNECTIVITYClient::calculateConnectivity
329 (medConnectivity connectivityType,
330 medEntityMesh Entity)
332 BEGIN_OF("void CONNECTIVITYClient::calculateConnectivity()");
337 CONNECTIVITY::calculateConnectivity(connectivityType, Entity);
339 END_OF("void CONNECTIVITYClient::calculateConnectivity()");
342 //=============================================================================
345 //=============================================================================
346 void CONNECTIVITYClient::updateFamily (vector<FAMILY*> myFamilies)
348 BEGIN_OF("void CONNECTIVITYClient::updateFamily()");
353 CONNECTIVITY::updateFamily(myFamilies);
355 END_OF("void CONNECTIVITYClient::updateFamily()");
358 //=============================================================================
361 //=============================================================================
362 const int * CONNECTIVITYClient::getGlobalNumberingIndex
363 (medEntityMesh Entity) const throw (MEDEXCEPTION)
365 BEGIN_OF("void CONNECTIVITYClient::getGlobalNumberingIndex()");
368 (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
370 const int * index = CONNECTIVITY::getGlobalNumberingIndex(Entity);
372 END_OF("void CONNECTIVITYClient::getGlobalNumberingIndex()");
377 //=============================================================================
380 //=============================================================================
381 bool CONNECTIVITYClient::existConnectivity(medConnectivity ConnectivityType,
382 medEntityMesh Entity) const
384 BEGIN_OF("void CONNECTIVITYClient::existConnectivity()");
387 (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
389 bool b = CONNECTIVITY::existConnectivity(ConnectivityType, Entity);
391 END_OF("void CONNECTIVITYClient::existConnectivity()");
396 //=============================================================================
399 //=============================================================================
400 const int * CONNECTIVITYClient::getReverseConnectivity
401 (medConnectivity ConnectivityType,
402 medEntityMesh Entity) throw (MEDEXCEPTION)
404 BEGIN_OF("void CONNECTIVITYClient::getReverseConnectivity()");
409 const int *c = CONNECTIVITY::getReverseConnectivity
410 (ConnectivityType, Entity);
412 END_OF("void CONNECTIVITYClient::getReverseConnectivity()");
417 //=============================================================================
420 //=============================================================================
421 const int * CONNECTIVITYClient::getReverseConnectivityIndex
422 (medConnectivity ConnectivityType,
423 medEntityMesh Entity) throw (MEDEXCEPTION)
425 BEGIN_OF("void CONNECTIVITYClient::getReverseConnectivityIndex()");
430 const int *c = CONNECTIVITY::getReverseConnectivityIndex
431 (ConnectivityType, Entity);
433 END_OF("void CONNECTIVITYClient::getReverseConnectivityIndex()");
438 //=============================================================================
441 //=============================================================================
442 const int* CONNECTIVITYClient::getValue(medConnectivity TypeConnectivity,
443 medGeometryElement Type)
445 BEGIN_OF("void CONNECTIVITYClient::getValue()");
450 const int * c = CONNECTIVITY::getValue(TypeConnectivity, Type);
452 END_OF("void CONNECTIVITYClient::()");
457 //=============================================================================
460 //=============================================================================
461 const int* CONNECTIVITYClient::getValueIndex(medConnectivity TypeConnectivity)
463 BEGIN_OF("void CONNECTIVITYClient::getValueIndex()");
468 const int * c = CONNECTIVITY::getValueIndex(TypeConnectivity);
470 END_OF("void CONNECTIVITYClient::getValueIndex()");
475 //=============================================================================
478 //=============================================================================
479 const int* CONNECTIVITYClient::getNeighbourhood() const
481 BEGIN_OF("void CONNECTIVITYClient::getNeighbourhood()");
484 (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
486 const int * c = CONNECTIVITY::getNeighbourhood();
488 END_OF("void CONNECTIVITYClient::getNeighbourhood()");
493 //=======================================================================
494 //function : existPolygonsConnectivity
496 //=======================================================================
498 bool CONNECTIVITYClient::existPolygonsConnectivity(medConnectivity connectivityType,
499 medEntityMesh Entity) const
501 BEGIN_OF("void CONNECTIVITYClient::existPolygonsConnectivity()");
504 (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
506 bool b = CONNECTIVITY::existPolygonsConnectivity( connectivityType, Entity );
508 END_OF("void CONNECTIVITYClient::existPolygonsConnectivity(connectivityType, Entity)");
513 //=======================================================================
514 //function : existPolyhedronConnectivity
516 //=======================================================================
518 bool CONNECTIVITYClient::existPolyhedronConnectivity(medConnectivity connectivityType,
519 medEntityMesh Entity) const
521 BEGIN_OF("void CONNECTIVITYClient::existPolyhedronConnectivity()");
524 (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
526 bool b = CONNECTIVITY::existPolyhedronConnectivity( connectivityType, Entity );
528 END_OF("void CONNECTIVITYClient::existPolyhedronConnectivity(connectivityType, Entity)");
533 //=======================================================================
534 //function : getPolygonsConnectivity
536 //=======================================================================
538 const int* CONNECTIVITYClient::getPolygonsConnectivity(medConnectivity ConnectivityType,
539 medEntityMesh Entity)
541 BEGIN_OF("void CONNECTIVITYClient::getPolygonsConnectivity()");
546 const int * c = CONNECTIVITY::getPolygonsConnectivity (ConnectivityType, Entity);
548 END_OF("void CONNECTIVITYClient::getPolygonsConnectivity()");
552 //=======================================================================
553 //function : getPolygonsConnectivityIndex
555 //=======================================================================
557 const int* CONNECTIVITYClient::getPolygonsConnectivityIndex(medConnectivity ConnectivityType,
558 medEntityMesh Entity)
560 BEGIN_OF("void CONNECTIVITYClient::getPolygonsConnectivityIndex()");
565 const int * c = CONNECTIVITY::getPolygonsConnectivityIndex (ConnectivityType, Entity);
567 END_OF("void CONNECTIVITYClient::getPolygonsConnectivityIndex()");
571 //=======================================================================
572 //function : getPolyhedronConnectivity
574 //=======================================================================
576 const int* CONNECTIVITYClient::getPolyhedronConnectivity(medConnectivity ConnectivityType) const
578 BEGIN_OF("void CONNECTIVITYClient::getPolyhedronConnectivity()");
581 (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
583 const int * c = CONNECTIVITY::getPolyhedronConnectivity (ConnectivityType);
585 END_OF("void CONNECTIVITYClient::getPolyhedronConnectivity()");
589 //=======================================================================
590 //function : getPolyhedronFacesIndex
592 //=======================================================================
594 const int* CONNECTIVITYClient::getPolyhedronFacesIndex() const
596 BEGIN_OF("void CONNECTIVITYClient::getPolyhedronFacesIndex()");
599 (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
601 const int * c = CONNECTIVITY::getPolyhedronFacesIndex();
603 END_OF("void CONNECTIVITYClient::getPolyhedronFacesIndex()");
607 //=======================================================================
608 //function : getPolyhedronIndex
610 //=======================================================================
612 const int* CONNECTIVITYClient::getPolyhedronIndex(medConnectivity ConnectivityType) const
614 BEGIN_OF("void CONNECTIVITYClient::getPolyhedronIndex()");
617 (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
619 const int * c = CONNECTIVITY::getPolyhedronIndex (ConnectivityType);
621 END_OF("void CONNECTIVITYClient::getPolyhedronIndex()");
625 //=======================================================================
626 //function : getNumberOfPolygons
628 //=======================================================================
630 int CONNECTIVITYClient::getNumberOfPolygons() const
632 BEGIN_OF("void CONNECTIVITYClient::getNumberOfPolygons()");
637 if ( _polyType_client == MED_POLYGON )
638 n = _numberOfElements_client[ getNumberOfTypes( _entity )];
641 n = CONNECTIVITY::getNumberOfPolygons();
645 END_OF("void CONNECTIVITYClient::getNumberOfPolygons()");
649 //=======================================================================
650 //function : getNumberOfPolyhedronFaces
652 //=======================================================================
654 int CONNECTIVITYClient::getNumberOfPolyhedronFaces() const
656 BEGIN_OF("void CONNECTIVITYClient::getNumberOfPolyhedronFaces()");
659 (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
661 int n = CONNECTIVITY::getNumberOfPolyhedronFaces ();
665 END_OF("void CONNECTIVITYClient::getNumberOfPolyhedronFaces()");
669 //=======================================================================
670 //function : getNumberOfPolyhedron
672 //=======================================================================
674 int CONNECTIVITYClient::getNumberOfPolyhedron() const
676 BEGIN_OF("void CONNECTIVITYClient::getNumberOfPolyhedron()");
681 if ( _polyType_client == MED_POLYHEDRA )
682 n = _numberOfElements_client[ getNumberOfTypes( _entity )];
685 n = CONNECTIVITY::getNumberOfPolyhedron();
689 END_OF("void CONNECTIVITYClient::getNumberOfPolyhedron()");