Back to index

salome-med  6.5.0
CONNECTIVITYClient.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "MEDMEM_convert.hxx"
00024 #include "Utils_CorbaException.hxx"
00025 #include "UtilClient.hxx"
00026 #include "CONNECTIVITYClient.hxx"
00027 
00028 #include "ReceiverFactory.hxx"
00029 using namespace MEDMEM;
00030 //=============================================================================
00034 //=============================================================================
00035 
00036 CONNECTIVITYClient::CONNECTIVITYClient(const SALOME_MED::MESH_ptr m,
00037                                        medEntityMesh Entity) :
00038   CONNECTIVITY(m->getNumberOfTypes(Entity), Entity),
00039   _numberOfElements_client(0),
00040   _complete(false),
00041   IOR_Mesh(SALOME_MED::MESH::_duplicate(m))
00042 {
00043   ASSERT(m);
00044 
00045   blankCopy();
00046 }
00047 
00048 //=============================================================================
00052 //=============================================================================
00053 CONNECTIVITYClient::~CONNECTIVITYClient()
00054 {
00055   if (_numberOfElements_client)
00056     delete [] _numberOfElements_client;
00057 }
00058 
00059 //=============================================================================
00064 //=============================================================================
00065 void CONNECTIVITYClient::blankCopy()
00066 {
00067    SALOME_MED::MESH::connectivityInfos_var all;
00068    medEntityMesh Entity = getEntity();
00069    try
00070    {
00071         all= IOR_Mesh->getConnectGlobal(Entity);
00072    }
00073    catch (const exception & ex)
00074    {
00075         MESSAGE("Unable to acces Global information");
00076         THROW_SALOME_CORBA_EXCEPTION(ex.what() ,SALOME::INTERNAL_ERROR);
00077    }
00078 
00079   _numberOfNodes = all->numberOfNodes;
00080   _entityDimension = all->entityDimension;
00081   medGeometryElement * Types;
00082 
00083   long iT, nT;
00084   convertCorbaArray<MED_EN::medGeometryElement,SALOME_MED::medGeometryElement_array *, long>
00085     (Types, nT, &all->meshTypes);
00086 
00087   ASSERT(nT == (int) getNumberOfTypes(Entity));
00088   SCRUTE(nT);
00089   
00090   setGeometricTypes(Types, Entity);
00091 
00092   _totalNumberOfElements_client = 0L;
00093   if (_numberOfElements_client)
00094     delete [] _numberOfElements_client;
00095   _numberOfElements_client = new long[nT];
00096   for (iT=0; iT<nT; iT++) 
00097    {
00098     _numberOfElements_client[iT] =  all->numberOfElements[iT];
00099     _totalNumberOfElements_client += _numberOfElements_client[iT];
00100     SCRUTE(iT);
00101     SCRUTE(_numberOfElements_client[iT]);
00102   }
00103 
00104   if(Types)
00105     delete [] Types;
00106 
00107   // create a constituent (PAL10556)
00108 // The consequence is that, if the remote server
00109 // has not calculated nodal connectivity of dimension d-1, heavy method
00110 // (CPU and memory) calculateDecsendingConnectivity is called on this
00111 // server for a potentially useless information for client side . (by Anthony GEAY)
00112    if ( Entity == MED_CELL ) {
00113      Entity = ( IOR_Mesh->getMeshDimension() == 3 ? MED_FACE : MED_EDGE );
00114      if(_constituent)
00115        delete _constituent;
00116      _constituent = new CONNECTIVITYClient( IOR_Mesh, Entity );
00117    }
00118 
00119   _complete = false;
00120 }
00121 
00122 //=============================================================================
00125 //=============================================================================
00126 // template< class T>
00127 // void dumpArray(const T* array, int size, const char* msg)
00128 // {
00129 //   if ( msg )
00130 //     std::cout << msg << " " << std::endl;
00131 //   std::cout << "Size: " << size << std::endl;
00132 //   for ( int i = 0; i < size; i++ )
00133 //     std::cout << " " << array[ i ];
00134 //   std::cout << endl;
00135 // }
00136 
00137 void CONNECTIVITYClient::fillCopy()
00138 {
00139   if (!_complete) {
00140 
00141     int *pC;
00142     long nC;
00143     
00144     medEntityMesh Entity = getEntity();
00145     int iT, nT = getNumberOfTypes(Entity);
00146     SCRUTE(nT);
00147     const medGeometryElement * T = getGeometricTypes(Entity);
00148     
00149     int * Count = new int[nT+1] ;
00150     Count[0]=1 ;
00151     SCRUTE(Count[0]);
00152     for (iT=0; iT<nT; iT++) {
00153       Count[iT+1]=Count[iT] + _numberOfElements_client[iT];
00154       SCRUTE(Count[iT+1]);
00155     }
00156     setCount(Count, Entity) ;
00157     
00158     for (iT=0; iT<nT; iT++) {
00159       
00160       SCRUTE(iT);
00161       SCRUTE(Count[iT+1]-Count[iT]);
00162       
00163       SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForConnectivity(MED_NODAL, Entity, T[iT]);
00164       pC=ReceiverFactory::getValue(senderForConnectivity,nC);
00165       SCRUTE(nC);
00166       ASSERT(nC == (T[iT]%100) * (Count[iT+1]-Count[iT]));
00167 
00168       int *index = 0;
00169       if ( T[iT] == MED_EN::MED_POLYGON || T[iT] == MED_EN::MED_POLYHEDRA )
00170       {
00171         SALOME::SenderInt_var senderForIndex=IOR_Mesh->getSenderForConnectivityIndex(MED_NODAL, Entity, T[iT]);
00172         index=ReceiverFactory::getValue(senderForIndex,nC);
00173         ASSERT(nC == (Count[iT+1]-Count[iT]+1));
00174       }
00175 
00176       setNodal(pC, Entity, T[iT], index);
00177       delete [] pC;
00178       delete [] index;
00179     }
00180 
00181     delete[] Count;
00182     if (_constituent)
00183       ((CONNECTIVITYClient *)_constituent)->fillCopy();
00184     _complete = true;
00185   }
00186 }
00187 
00188 //=============================================================================
00191 //=============================================================================
00192 int CONNECTIVITYClient::getNumberOf(medEntityMesh Entity, 
00193                                     medGeometryElement Type) const
00194 {
00195   int n = 0;
00196 
00197   SCRUTE(Type);
00198   SCRUTE(Entity);
00199   
00200   if (!_complete) {
00201     
00202     if (Entity == _entity) {
00203       
00204       if (Type==MED_ALL_ELEMENTS)
00205         n = _totalNumberOfElements_client;
00206       
00207       for (int i=0; i<_numberOfTypes; i++) {
00208         SCRUTE(_geometricTypes[i]);
00209         if (_geometricTypes[i] == Type) {
00210           n = _numberOfElements_client[i];
00211           break;
00212         }
00213       }
00214     } 
00215     else if (_constituent != NULL)
00216       n = _constituent->getNumberOf(Entity,Type);
00217     
00218   }
00219   else
00220     n = CONNECTIVITY::getNumberOf(Entity, Type);
00221 
00222   SCRUTE(n);
00223   return n;
00224 }
00225 
00226 //=============================================================================
00229 //=============================================================================
00230 const int * CONNECTIVITYClient::getConnectivity (medConnectivity ConnectivityType, 
00231                                                  medEntityMesh Entity,
00232                                                  medGeometryElement Type) const
00233 {
00234   if (!_complete)
00235     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00236 
00237   const int * c = CONNECTIVITY::getConnectivity (ConnectivityType, Entity, Type);
00238 
00239   return c;
00240 }
00241 
00242 int CONNECTIVITYClient::getConnectivityLength(medConnectivity    ConnectivityType,
00243                                               medEntityMesh      Entity,
00244                                               medGeometryElement Type) const
00245 {
00246   if (!_complete)
00247     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00248 
00249   const int l = CONNECTIVITY::getConnectivityLength (ConnectivityType, Entity, Type);
00250 
00251   return l;
00252 }
00253 
00254 //=============================================================================
00257 //=============================================================================
00258 const int * CONNECTIVITYClient::getConnectivityIndex (medConnectivity ConnectivityType,
00259                                                       medEntityMesh Entity) const
00260 {
00261   if (!_complete)
00262     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00263 
00264   const int *c = CONNECTIVITY::getConnectivityIndex
00265     (ConnectivityType, Entity);
00266 
00267   return c;
00268 }
00269 
00270 //=============================================================================
00273 //=============================================================================
00274 void CONNECTIVITYClient::calculateConnectivity (medConnectivity connectivityType, 
00275                                                 medEntityMesh Entity)
00276 {
00277   if (!_complete)
00278     fillCopy();
00279 
00280   CONNECTIVITY::calculateConnectivity(connectivityType, Entity);
00281 }
00282 
00283 //=============================================================================
00286 //=============================================================================
00287 void  CONNECTIVITYClient::updateFamily (vector<FAMILY*> myFamilies)
00288 {
00289   if (!_complete)
00290     fillCopy();
00291 
00292   CONNECTIVITY::updateFamily(myFamilies);
00293 }
00294 
00295 //=============================================================================
00298 //=============================================================================
00299 const int * CONNECTIVITYClient::getGlobalNumberingIndex (medEntityMesh Entity) const
00300   throw (MEDEXCEPTION)
00301 {
00302   if (!_complete)
00303     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00304 
00305   const int * index = CONNECTIVITY::getGlobalNumberingIndex(Entity);
00306 
00307   return index;
00308 }
00309 
00310 //=============================================================================
00313 //=============================================================================
00314 bool CONNECTIVITYClient::existConnectivity(medConnectivity ConnectivityType, 
00315                                            medEntityMesh Entity) const
00316 { 
00317   if (!_complete)
00318     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00319 
00320   bool b = CONNECTIVITY::existConnectivity(ConnectivityType, Entity);
00321 
00322   return b;
00323 }
00324 
00325 //=============================================================================
00328 //=============================================================================
00329 const int * CONNECTIVITYClient::getReverseConnectivity (medConnectivity ConnectivityType, 
00330                                                         medEntityMesh Entity) const
00331   throw (MEDEXCEPTION)
00332 {
00333   if (!_complete)
00334     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00335 
00336   const int *c = CONNECTIVITY::getReverseConnectivity
00337     (ConnectivityType, Entity);
00338 
00339   return c;
00340 }
00341 
00342 //=============================================================================
00345 //=============================================================================
00346 const int * CONNECTIVITYClient::getReverseConnectivityIndex (medConnectivity ConnectivityType,
00347                                                              medEntityMesh Entity) const
00348   throw (MEDEXCEPTION)
00349 {
00350   if (!_complete)
00351     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00352 
00353   const int *c =  CONNECTIVITY::getReverseConnectivityIndex
00354     (ConnectivityType, Entity);
00355 
00356   return c;
00357 }
00358 
00359 //=============================================================================
00362 //=============================================================================
00363 const int* CONNECTIVITYClient::getValue(medConnectivity TypeConnectivity, 
00364                                         medGeometryElement Type) const
00365 {
00366   if (!_complete)
00367     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00368 
00369   const int * c =  CONNECTIVITY::getValue(TypeConnectivity, Type);
00370 
00371   return c;
00372 }
00373 
00374 //=============================================================================
00377 //=============================================================================
00378 const int* CONNECTIVITYClient::getValueIndex(medConnectivity TypeConnectivity) const
00379 {
00380   if (!_complete)
00381     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00382 
00383   const int * c =  CONNECTIVITY::getValueIndex(TypeConnectivity);
00384 
00385   return c;
00386 }
00387 
00388 //=============================================================================
00391 //=============================================================================
00392 const int* CONNECTIVITYClient::getNeighbourhood() const
00393 {
00394   if (!_complete)
00395     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
00396 
00397   const int * c =  CONNECTIVITY::getNeighbourhood();
00398 
00399   return c;
00400 }