Back to index

salome-med  6.5.0
MEDMEM_Support.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 /*
00024  File Support.cxx
00025 */
00026 
00027 #include "MEDMEM_Support.hxx"
00028 #include "MEDMEM_DriversDef.hxx"
00029 #include "MEDMEM_GMesh.hxx"
00030 #include "MEDMEM_Meshing.hxx"
00031 
00032 #include <set>
00033 #include <algorithm>
00034 #include <list>
00035 
00036 using namespace std;
00037 using namespace MED_EN;
00038 using namespace MEDMEM;
00039 
00040 #define MED_NBR_GEOMETRIE_MAILLE 15
00041 
00061 /* This class is a generic class for family and group */
00062 
00066 //--------------------------------------------------------------------------
00067 SUPPORT::SUPPORT(): _name(""),  _description("None"), _mesh((GMESH*)NULL),
00068                     _entity(MED_CELL), _numberOfGeometricType(0),
00069                     _isOnAllElts(false),
00070                     _totalNumberOfElements(0),
00071                     _number((MEDSKYLINEARRAY*)NULL),
00072                     _number_fromfile(0)
00073   //--------------------------------------------------------------------------
00074 {
00075   MESSAGE_MED("SUPPORT::SUPPORT()");
00076 }
00077 
00092 //--------------------------------------------------------------------------
00093 // SUPPORT::SUPPORT(MESH* Mesh, string Name/*=""*/, medEntityMesh Entity/*=MED_CELL*/):
00094 //   _name(Name), _description("None"), _mesh(Mesh), _entity(Entity),
00095 //   _numberOfGeometricType(0), _isOnAllElts(true),
00096 //   _totalNumberOfElements(0), _number((MEDSKYLINEARRAY*)NULL),_number_fromfile(0)
00097 //   //--------------------------------------------------------------------------
00098 // {
00099 //   MESSAGE_MED("SUPPORT::SUPPORT(MESH*Mesh,string Name,medEntityMesh Entity)");
00100 //   if(_mesh)
00101 //     _mesh->addReference();
00102 //   update() ;
00103 // }
00104 
00108 //--------------------------------------------------------------------------
00109 SUPPORT::SUPPORT(const SUPPORT & m):_number_fromfile(0)
00110   //--------------------------------------------------------------------------
00111 {
00112   const char* LOC = "SUPPORT::SUPPORT(SUPPORT & m) : ";
00113   BEGIN_OF_MED(LOC);
00114 
00115   _name = m._name ;
00116   _description = m._description ;
00117   _mesh = m._mesh ; // on recopie uniquement l'adresse
00118   if(_mesh)
00119     _mesh->addReference();
00120   _meshName = m._meshName;
00121   _entity = m._entity;
00122   _numberOfGeometricType = m._numberOfGeometricType;
00123 
00124   if (m._geometricType)
00125     _geometricType.set(_numberOfGeometricType,m._geometricType);
00126 
00127   _isOnAllElts = m._isOnAllElts;
00128 
00129   if (m._numberOfElements)
00130     _numberOfElements.set(_numberOfGeometricType,m._numberOfElements);
00131 
00132   _totalNumberOfElements = m._totalNumberOfElements;
00133 
00134   if ( m._number ) // m may be not filled SUPPORTClient
00135     _number = new MEDSKYLINEARRAY(* m._number);
00136   else
00137     _number = (MEDSKYLINEARRAY *) NULL;
00138 
00139   _profilNames=m._profilNames;
00140 
00141   END_OF_MED(LOC);
00142 }
00143 
00152 //--------------------------------------------------------------------------
00153 SUPPORT & SUPPORT::operator=(const SUPPORT & m)
00154   //--------------------------------------------------------------------------
00155 {
00156   const char* LOC = "SUPPORT::operator=(const SUPPORT & m) : ";
00157   BEGIN_OF_MED(LOC);
00158 
00159   if ( this == &m ) return *this;
00160 
00161   _name = m._name;
00162   _description = m._description;
00163   if(m._mesh!=_mesh)//setMesh not used here due to _meshName update is this...
00164     {
00165       if(_mesh)
00166         _mesh->removeReference();
00167       _mesh=m._mesh;
00168       if(_mesh)
00169         _mesh->addReference();
00170     }
00171   _entity = m._entity;
00172   _numberOfGeometricType = m._numberOfGeometricType;
00173   if (m._geometricType)
00174     _geometricType.set(_numberOfGeometricType,m._geometricType);
00175   _isOnAllElts = m._isOnAllElts;
00176   if (m._numberOfElements)
00177     _numberOfElements.set(_numberOfGeometricType,m._numberOfElements);
00178   _totalNumberOfElements = m._totalNumberOfElements;
00179 
00180   if (_number) delete _number;
00181   if  ( m._number ) // m may be not filled SUPPORTClient
00182     _number = new MEDSKYLINEARRAY(* m._number);
00183   else
00184     _number = (MEDSKYLINEARRAY *) NULL;
00185 
00186   _profilNames=m._profilNames;
00187 
00188   END_OF_MED(LOC);
00189   return *this;
00190 }
00191 
00195 //-----------------
00196 SUPPORT::~SUPPORT()
00197   //-----------------
00198 {
00199   MESSAGE_MED("Destructeur ~SUPPORT()");
00200   clearDataOnNumbers();
00201   if(_mesh)
00202     _mesh->removeReference();
00203 }
00204 
00208 //--------------------------------------------------
00209 ostream & MEDMEM::operator<<(ostream &os, const SUPPORT &my)
00210   //--------------------------------------------------
00211 {
00212   os << "Name : "<< my.getName() << endl ;
00213   os << "Description : "<< my.getDescription() << endl ;
00214   os << "Mesh ptr : ";
00215   if (my.getMesh() == NULL)
00216     os << " Mesh not defined." << endl ;
00217   else
00218     os << " Mesh defined." << endl;
00219   os << "MeshName : ";
00220   os << my.getMeshName() << endl ;
00221   os << "Entity : "<<entNames[my._entity] << endl;
00222   os << "Entity list : "<< endl;
00223   if ( my._isOnAllElts )
00224     os << "Is on all entities."<< endl;
00225   else {
00226     os << "Is not on all entities. "<< endl;
00227     if ( my._number )  // m may be not filled SUPPORTClient
00228       os << *my.getNumber(MED_ALL_ELEMENTS);
00229   }
00230   int numberoftypes = my._numberOfGeometricType ;
00231   os << "NumberOfTypes : "<<numberoftypes<<endl;
00232   PointerOf<medGeometryElement> types = my._geometricType;
00233   for (int j=0;j<numberoftypes;j++) {
00234     int numberOfElements = my._numberOfElements ? my._numberOfElements[j] : -1;
00235     os << "    On Type "<<geoNames[types[j]]
00236        <<" : there is(are) "<<numberOfElements<<" element(s) and " <<endl;
00237   }
00238   int nbProfilNames = my._profilNames.size();
00239   os<<"Number of profil names = "<<nbProfilNames<<endl;
00240   for(int j=0; j<nbProfilNames; j++) {
00241     os<<"    Profil Name N"<<j+1<<" = "<<my._profilNames[j]<<endl;
00242   }
00243   return os ;
00244 }
00245 
00253 //-------------------
00254 void SUPPORT::update()
00255 //-------------------
00256 {
00257   const char* LOC = "SUPPORT::update() : ";
00258   BEGIN_OF_MED(LOC);
00259 
00260   if (_isOnAllElts && _mesh)
00261     {
00262       if (_entity == MED_NODE)
00263         {
00264           // BEGIN Issue 0020804: [CEA 399] Memory corruption ... in MEDMEMCppTest
00265           //_numberOfGeometricType = 1;
00266           setNumberOfGeometricType(1);
00267           // END Issue 0020804
00268 
00269           // BEGIN Issue 0020633: [CEA] Pb with 3D field creation fron another
00270           // Use setGeometricType() in order to get _profilNames updated
00271           //_geometricType.set(1);
00272           //_geometricType[0]=MED_POINT1;
00273           const MED_EN::medGeometryElement type = MED_NONE;
00274           setGeometricType( & type );
00275           // END Issue 0020633: [CEA] Pb with 3D field creation fron another
00276           _numberOfElements.set(1);
00277           _numberOfElements[0]=_mesh->getNumberOfNodes();
00278           _totalNumberOfElements=_numberOfElements[0];
00279         }
00280       else
00281         { // we duplicate information from _mesh
00282           // BEGIN Issue 0020804: [CEA 399] Memory corruption ... in MEDMEMCppTest
00283           setNumberOfGeometricType(_mesh->getNumberOfTypes(_entity));
00284           // END Issue 0020804
00285           // BEGIN Issue 0020633: [CEA] Pb with 3D field creation fron another
00286           if ( const medGeometryElement *  allType = _mesh->getTypes(_entity))
00287             setGeometricType( allType );
00288           // END Issue 0020633: [CEA] Pb with 3D field creation fron another
00289           _numberOfElements.set(_numberOfGeometricType);
00290           _totalNumberOfElements=0;
00291           for (int i=0;i<_numberOfGeometricType;i++)
00292             {
00293               _numberOfElements[i]=_mesh->getNumberOfElements(_entity,_geometricType[i]) ;
00294               _totalNumberOfElements+=_numberOfElements[i];
00295             }
00296         }
00297 
00298       if (_totalNumberOfElements <= 0)
00299         throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"We have found no element for this support !"));
00300       // set _number (issue 0021167)
00301       {
00302         vector<int> nums( _totalNumberOfElements );
00303         for ( unsigned i = 0; i < nums.size(); ++i )
00304           nums[i] = i+1;
00305 
00306         vector<int> index( _numberOfGeometricType + 1 );
00307         index[0] = 1;
00308         for ( int i = 0; i < _numberOfGeometricType; ++i )
00309           index[i+1] = index[i] + _numberOfElements[i];
00310 
00311         setNumber( & index[0], & nums[0] );
00312       }
00313     }
00314   END_OF_MED(LOC);
00315 }
00316 
00321 //-------------------
00322 int SUPPORT::getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION)
00323 //-------------------
00324 {
00325   const char * LOC="getValIndFromGlobalNumber(const int number) : ";
00326 
00327   if (_isOnAllElts) return number;
00328 
00329   int nbOfEltsThis    = getNumberOfElements(MED_ALL_ELEMENTS);
00330 
00331   const int *eltsThis = _number->getValue();
00332 
00333   int iThis;
00334   bool found=false;
00335 
00336   for(iThis=0;iThis<nbOfEltsThis && !found;)
00337     if(eltsThis[iThis]==number)
00338     {
00339       found = true;
00340       int valInd = iThis+1;
00341       return valInd;
00342     }
00343     else
00344       iThis++;
00345 
00346   if(!found)
00347     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Can't find the global number |"
00348                                  << number << "| in Support |"
00349                                  << getName() << "|" ));
00350 
00351   // It should never arrive here !!
00352   return 0;
00353 }
00354 
00373 //-------------------
00374 void SUPPORT::blending(const SUPPORT * mySupport) throw (MEDEXCEPTION)
00375   //-------------------
00376 {
00377   const char * LOC="SUPPORT::blending(SUPPORT *) : ";
00378   BEGIN_OF_MED(LOC);
00379   if (_entity!=mySupport->getEntity())
00380     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !"));
00381   if(!(*_mesh == *mySupport->getMesh()))
00382     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh are different !"));
00383   if(_isOnAllElts)
00384     return;
00385   if(mySupport->isOnAllElements())
00386   {
00387     *this=*mySupport;
00388     return;
00389   }
00390   if(mySupport->_totalNumberOfElements==0)
00391     return;
00392   const int *ids=getNumber(MED_ALL_ELEMENTS);
00393   set<int> idsSet(ids,ids+getNumberOfElements(MED_ALL_ELEMENTS));
00394   const int *idsMySupport=mySupport->getNumber(MED_ALL_ELEMENTS);
00395   int mySupportSize=mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
00396   set<int>::iterator iter;
00397   for(int i=0;i<mySupportSize;i++)
00398     idsSet.insert(idsMySupport[i]);
00399   int size=idsSet.size();
00400 
00401   if(size!=0)
00402   {
00403     list<int> idsList;
00404     for(iter=idsSet.begin();iter!=idsSet.end();iter++)
00405       idsList.push_back(*iter);
00406 
00407     MESSAGE_MED(LOC << " size Set " << idsSet.size() << " size List " << idsList.size());
00408 
00409     if(_entity==MED_NODE)
00410       fillFromNodeList(idsList);
00411     else
00412       fillFromElementList(idsList);
00413   }
00414   else
00415     clearDataOnNumbers();
00416   END_OF_MED(LOC);
00417 }
00464 //-------------------
00465 void SUPPORT::setpartial(const std::string&         Description,
00466                          int                        NumberOfGeometricType,
00467                          int                        TotalNumberOfElements,
00468                          const medGeometryElement * GeometricType,
00469                          const int *                NumberOfElements,
00470                          const int *                NumberValue)
00471 //-------------------
00472 {
00473   const char * LOC = "SUPPORT::setpartial(string , int , int , medGeometryElement * , int * , int *) : " ;
00474   BEGIN_OF_MED(LOC) ;
00475 
00476   _isOnAllElts = false ;
00477 
00478   _description=Description;
00479 
00480   _numberOfGeometricType=NumberOfGeometricType;
00481   _geometricType.set(NumberOfGeometricType);
00482   _numberOfElements.set(NumberOfGeometricType);
00483   _totalNumberOfElements = TotalNumberOfElements;
00484 
00485   int * index = new int[_numberOfGeometricType+1];
00486   index[0]=1;
00487   int elemDim = -1;
00488   for (int i=0;i<_numberOfGeometricType;i++) {
00489     if(GeometricType[i]/100 != elemDim)
00490       {
00491         if(i==0)
00492           elemDim=GeometricType[i]/100;
00493         else if ( CELLMODEL_Map::retrieveCellModel( GeometricType[i] ).getDimension() !=
00494                   CELLMODEL_Map::retrieveCellModel( GeometricType[0] ).getDimension() )
00495           throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"unhomogeneous geometric types (dimension) !"));
00496       }
00497     _geometricType[i] = GeometricType[i] ;
00498     _numberOfElements[i] = NumberOfElements[i] ;
00499     index[i+1] = index[i]+NumberOfElements[i] ;
00500   }
00501 
00502   if (_number!=NULL) delete _number ;
00503   _number = new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,NumberValue);
00504 
00505   delete[] index ;
00506 
00507   // PAL16854(Partial support on nodes):
00508   // giving a default value to profile names
00509   vector<string> prof_names( NumberOfGeometricType);
00510   for (int itype=0; itype < NumberOfGeometricType; itype++)
00511   {
00512     ostringstream typestr;
00513     typestr<<_name<<"_type"<<_geometricType[itype];
00514     prof_names[itype]=typestr.str();
00515   }
00516   setProfilNames(prof_names);
00517 
00518   END_OF_MED(LOC);
00519 }
00520 
00534 //-------------------
00535 void SUPPORT::setpartial(MEDSKYLINEARRAY * number, bool shallowCopy) throw (MEDEXCEPTION)
00536   //-------------------
00537 {
00538   const char * LOC = "SUPPORT::setpartial(MEDSKYLINEARRAY * number) : " ;
00539   BEGIN_OF_MED(LOC) ;
00540 
00541   if ( ! _geometricType )
00542     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT must contains"
00543                                  << " a geometric type list" )) ;
00544 
00545   _numberOfGeometricType = number->getNumberOf();
00546 
00547   _numberOfElements.set(_numberOfGeometricType);
00548 
00549   for (int i=0; i< _numberOfGeometricType; i++)
00550     _numberOfElements[i] =  number->getNumberOfI(i+1);
00551 
00552   _totalNumberOfElements = number->getLength();
00553 
00554   _isOnAllElts = false ;
00555 
00556   if (_number!=NULL) delete _number ;
00557 
00558   if ( shallowCopy )
00559     _number = number;
00560   else
00561     _number = new MEDSKYLINEARRAY(*number);
00562 
00563   END_OF_MED(LOC);
00564 }
00565 
00566 void SUPPORT::setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy) throw (MEDEXCEPTION)
00567   //-------------------
00568 {
00569   const char* LOC = "SUPPORT::setpartial_fromfile(MEDSKYLINEARRAY * number) : ";
00570   BEGIN_OF_MED(LOC);
00571 
00572   if ( shallowCopy )
00573     _number_fromfile = number;
00574   else
00575     _number_fromfile = new MEDSKYLINEARRAY(*number);
00576 
00577   END_OF_MED(LOC);
00578 }
00579 
00580 void SUPPORT::setProfilNames(const std::vector<std::string>& profilNames) throw (MEDEXCEPTION){
00581 
00582   const char * LOC = "SUPPORT::setProfilNames(vector<string> profilNames) : " ;
00583   BEGIN_OF_MED(LOC) ;
00584 
00585   if ( _isOnAllElts )
00586     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT shouldn't be on all elements"
00587                                  << " while setting profil name list" )) ;
00588 
00589   if ( ! _geometricType || _numberOfGeometricType==0 )
00590     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT must contains"
00591                                  << " a least one geometric type" )) ;
00592 
00593   if ( ! _number )
00594     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT must contains"
00595                                  << " a profil number list before setting"
00596                                  << " the associated profil name list" )) ;
00597 
00598   if ( ( (int)profilNames.size() != _number->getNumberOf() ) &&
00599        ( (int)profilNames.size() !=_numberOfGeometricType ) ) {
00600     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The profil name list size : "<< profilNames.size()
00601                                  << " must be equal to the number of geometric type : " 
00602                                  <<  _numberOfGeometricType << " (_number->getNumberOf() : "
00603                                  << _number->getNumberOf() << " )"
00604                                  )) ;
00605 
00606   }
00607 
00608   _profilNames = profilNames;
00609 
00610   END_OF_MED(LOC);
00611 
00612 }
00613 
00614 vector<string> SUPPORT::getProfilNames() const throw (MEDEXCEPTION)
00615 {
00616   return _profilNames;
00617 }
00618 
00629 //-------------------
00630 void SUPPORT::getBoundaryElements() throw (MEDEXCEPTION)
00631   //-------------------
00632 {
00633   const char * LOC = "SUPPORT::getBoundaryElements() : " ;
00634   BEGIN_OF_MED(LOC) ;
00635 
00636   if (_mesh == (GMESH*)NULL) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"You shlould use the appropriate SUPPORT Constructor before calling this method"));
00637 
00638   int spaceDimension = _mesh->getSpaceDimension();
00639 
00640   if (spaceDimension == 3)
00641     if (_entity != MED_FACE)
00642       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 3D mesh for entity "<<_entity<<" !"));
00643   if (spaceDimension == 2)
00644     if (_entity != MED_EDGE)
00645       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 2D mesh for entity "<<_entity<<" !"));
00646 
00647   setAll(false);
00648 
00649   const MESH* mesh = _mesh->convertInMESH();
00650   const_cast<CONNECTIVITY*>
00651     (mesh->getConnectivityptr())->calculateFullDescendingConnectivity(MED_CELL);
00652   const int * myConnectivityValue = mesh->getReverseConnectivity(MED_DESCENDING) ;
00653   const int * myConnectivityIndex = mesh->getReverseConnectivityIndex(MED_DESCENDING) ;
00654   int numberOf = mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS) ;
00655   list<int> myElementsList ;
00656   int size = 0 ;
00657   SCRUTE_MED(numberOf) ;
00658   for (int i=0 ; i<numberOf; i++)
00659     if (myConnectivityValue[myConnectivityIndex[i]] == 0) {
00660       SCRUTE_MED(i+1) ;
00661       myElementsList.push_back(i+1) ;
00662       size++ ;
00663     }
00664   SCRUTE_MED(size) ;
00665   // Well, we must know how many geometric type we have found
00666   int * myListArray = new int[size] ;
00667   int id = 0 ;
00668   list<int>::iterator myElementsListIt ;
00669   for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
00670     myListArray[id]=(*myElementsListIt) ;
00671     SCRUTE_MED(id);
00672     SCRUTE_MED(myListArray[id]);
00673     id ++ ;
00674   }
00675 
00676   int numberOfGeometricType ;
00677   medGeometryElement* geometricType ;
00678   int * geometricTypeNumber ;
00679   int * numberOfElements ;
00680   int * mySkyLineArrayIndex ;
00681 
00682   int numberOfType = mesh->getNumberOfTypes(_entity) ;
00683   if (numberOfType == 1) { // wonderfull : it's easy !
00684     numberOfGeometricType = 1 ;
00685     geometricType = new medGeometryElement[1] ;
00686     const medGeometryElement *  allType = mesh->getTypes(_entity);
00687     geometricType[0] = allType[0] ;
00688     geometricTypeNumber = new int[1] ; // not use, but initialized to nothing
00689     geometricTypeNumber[0] = 0 ;
00690     numberOfElements = new int[1] ;
00691     numberOfElements[0] = size ;
00692     mySkyLineArrayIndex = new int[2] ;
00693     mySkyLineArrayIndex[0]=1 ;
00694     mySkyLineArrayIndex[1]=1+size ;
00695   }
00696   else {// hemmm
00697     map<medGeometryElement,int> theType ;
00698     for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
00699       medGeometryElement myType = mesh->getElementType(_entity,*myElementsListIt) ;
00700       if (theType.find(myType) != theType.end() )
00701         theType[myType]+=1 ;
00702       else
00703         theType[myType]=1 ;
00704     }
00705     numberOfGeometricType = theType.size() ;
00706     geometricType = new medGeometryElement[numberOfGeometricType] ;
00707     geometricTypeNumber = new int[numberOfGeometricType] ; // not use, but initialized to nothing
00708     numberOfElements = new int[numberOfGeometricType] ;
00709     mySkyLineArrayIndex = new int[numberOfGeometricType+1] ;
00710     int index = 0 ;
00711     mySkyLineArrayIndex[0]=1 ;
00712     map<medGeometryElement,int>::iterator theTypeIt ;
00713     for (theTypeIt=theType.begin();theTypeIt!=theType.end();theTypeIt++) {
00714       geometricType[index] = (*theTypeIt).first ;
00715       geometricTypeNumber[index] = 0 ;
00716       numberOfElements[index] = (*theTypeIt).second ;
00717       mySkyLineArrayIndex[index+1]=mySkyLineArrayIndex[index]+numberOfElements[index] ;
00718       index++ ;
00719     }
00720   }
00721   MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray) ;
00722 
00723   setNumberOfGeometricType(numberOfGeometricType) ;
00724   setGeometricType(geometricType) ;
00725   setNumberOfElements(numberOfElements) ;
00726 
00727   _number = new MEDSKYLINEARRAY(numberOfGeometricType,size);
00728 
00729   _number->setIndex(mySkyLineArrayIndex);
00730 
00731   for (int i=0;i<size;i++)
00732   {
00733     _number->setIndexValue(i+1,myListArray[i]);
00734   }
00735 
00736   delete[] numberOfElements;
00737   delete[] geometricTypeNumber;
00738   delete[] geometricType;
00739   delete[] mySkyLineArrayIndex;
00740   delete[] myListArray;
00741   delete mySkyLineArray;
00742 
00743   mesh->removeReference();
00744 
00745   END_OF_MED(LOC);
00746 }
00747 
00752 //-------------------
00753 void SUPPORT::intersecting(const SUPPORT * mySupport) throw (MEDEXCEPTION)
00754 {
00755   const char * LOC="SUPPORT::intersecting(SUPPORT *) : ";
00756   BEGIN_OF_MED(LOC);
00757   if (_entity!=mySupport->getEntity())
00758     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !"));
00759   if(!(*_mesh == *mySupport->getMesh()))
00760     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh are different !"));
00761   if(mySupport->isOnAllElements())
00762     return;
00763   if(_isOnAllElts)
00764   {
00765     *this=*mySupport;
00766     return;
00767   }
00768   if(_totalNumberOfElements==0)
00769     return;
00770   const int *ids=getNumber(MED_ALL_ELEMENTS);
00771   set<int> idsSet(ids,ids+getNumberOfElements(MED_ALL_ELEMENTS));
00772   const int *idsMySupport=mySupport->getNumber(MED_ALL_ELEMENTS);
00773   int mySupportSize=mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
00774   set<int> idsSetMySupport(idsMySupport,idsMySupport+mySupportSize);
00775   set<int>::iterator iter;
00776   list<int> idsList;
00777   for(iter=idsSet.begin();iter!=idsSet.end();iter++)
00778     if(idsSetMySupport.find(*iter)!=idsSetMySupport.end())
00779       idsList.push_back(*iter);
00780   int size=idsSet.size();
00781   int sizeList = idsList.size();
00782 
00783   MESSAGE_MED(LOC << " size Set " << idsSet.size() << " size List " << idsList.size());
00784 
00785   if(size!=0 && sizeList != 0)
00786   {
00787     if(_entity==MED_NODE)
00788       fillFromNodeList(idsList);
00789     else
00790       fillFromElementList(idsList);
00791   }
00792   else
00793   {
00794     clearDataOnNumbers();
00795   }
00796   END_OF_MED(LOC);
00797 }
00803 //--------------------------------------------------
00804 void MEDMEM::SUPPORT::clearDataOnNumbers()
00805   //--------------------------------------------------
00806 {
00807   _numberOfGeometricType=0;
00808   _totalNumberOfElements=0;
00809 
00810   if(_number)
00811   {
00812     delete _number;
00813     _number=(MEDSKYLINEARRAY *) NULL;
00814   }
00815   if(_number_fromfile)
00816     {
00817       delete _number_fromfile;
00818       _number_fromfile=0;
00819     }
00820 }
00821 
00825 //--------------------------------------------------
00826 bool MEDMEM::SUPPORT::operator == (const SUPPORT &support) const
00827   //--------------------------------------------------
00828 {
00829 
00830   const char* LOC = "bool SUPPORT::operator ==(const SUPPORT &support) const : ";
00831   BEGIN_OF_MED(LOC);
00832 
00833   bool operatorReturn = false;
00834 
00835   operatorReturn = (*_mesh == *support._mesh) && (_entity == support._entity) &&
00836     (_numberOfGeometricType == support._numberOfGeometricType) &&
00837     ((_isOnAllElts && support._isOnAllElts) || (!_isOnAllElts && !support._isOnAllElts)) &&
00838     (_totalNumberOfElements == support._totalNumberOfElements) &&
00839     (_profilNames.size() == support._profilNames.size());
00840 
00841   if (operatorReturn)
00842   {
00843     if (!_isOnAllElts)
00844     {
00845       for (int i=0; i<_numberOfGeometricType; i++)
00846       {
00847         operatorReturn = operatorReturn &&
00848           (_geometricType[i] == support._geometricType[i]) &&
00849           (_numberOfElements[i] == support._numberOfElements[i]);
00850 
00851         if (operatorReturn)
00852         {
00853           for (int j=0; j<_numberOfElements[i]; j++)
00854           {
00855             operatorReturn = operatorReturn &&
00856               (getNumber(_geometricType[i])[j] ==
00857                support.getNumber(_geometricType[i])[j]);
00858           }
00859         }
00860       }
00861     }
00862   }
00863 
00864   END_OF_MED(LOC);
00865 
00866   return operatorReturn;
00867 }
00868 
00869 void SUPPORT::changeElementsNbs(medEntityMesh entity, const int *renumberingFromOldToNew)
00870 {
00871   if(entity != _entity)
00872     throw MEDEXCEPTION("SUPPORT::changeElementsNbs : Renumbering on a mismatch entity");
00873   list<int> newNbs;
00874   if(!_isOnAllElts)
00875   {
00876     const int *oldNbs=_number->getValue();
00877     for(int i=0;i<_totalNumberOfElements;i++)
00878       newNbs.push_back(renumberingFromOldToNew[oldNbs[i]-1]);
00879     newNbs.sort();
00880     fillFromElementList(newNbs);
00881   }
00882   else
00883     update();
00884 }
00885 
00889 bool MEDMEM::SUPPORT::deepCompare(const SUPPORT &support) const
00890 {
00891   bool operatorReturn =(_entity == support._entity) &&
00892     (_numberOfGeometricType == support._numberOfGeometricType) &&
00893     ( (_isOnAllElts && support._isOnAllElts) || (!_isOnAllElts  && !support._isOnAllElts) ) &&
00894     (_totalNumberOfElements == support._totalNumberOfElements);
00895   if (operatorReturn)
00896   {
00897     if (!_isOnAllElts)
00898     {
00899       for (int i=0; i<_numberOfGeometricType && operatorReturn; i++)
00900       {
00901         operatorReturn = (_geometricType[i] == support._geometricType[i]) &&
00902           (_numberOfElements[i] == support._numberOfElements[i]);
00903         if (operatorReturn)
00904         {
00905           for (int j=0; j<_numberOfElements[i]; j++)
00906           {
00907             operatorReturn = (getNumber(_geometricType[i])[j] ==
00908                               support.getNumber(_geometricType[i])[j]);
00909           }
00910         }
00911       }
00912     }
00913   }
00914   if(operatorReturn)
00915     operatorReturn = ( bool(_mesh) == bool(support._mesh));
00916 
00917   if(operatorReturn)
00918   {
00919     if(!(*_mesh == *support._mesh))
00920     {
00921       return _mesh->deepCompare(*support._mesh);
00922     }
00923   }
00924   return operatorReturn;
00925 }
00926 
00930 bool MEDMEM::SUPPORT::belongsTo(const SUPPORT& other, bool deepCompare) const
00931 {
00932   if(!(*_mesh == *other._mesh))
00933   {
00934     if(!deepCompare)
00935       return false;
00936     if(!_mesh->deepCompare(*other._mesh))
00937       return false;
00938   }
00939   if(_entity!=other._entity)
00940     return false;
00941   if(other._isOnAllElts)
00942     return true;
00943   if(_isOnAllElts && !other._isOnAllElts)
00944     return false;
00945   if(_numberOfGeometricType>other._numberOfGeometricType)
00946     return false;
00947   for(int i=0; i<_numberOfGeometricType; i++)
00948   {
00949     medGeometryElement curGeomType=_geometricType[i];
00950     int iOther=-1;
00951     for(int j=0; j<other._numberOfGeometricType; j++)
00952       if(other._geometricType[j]==curGeomType)
00953         iOther=j;
00954     if(iOther==-1)
00955       return false;
00956     if(_numberOfElements[i]>other._numberOfElements[iOther])
00957       return false;
00958     const int *numbers1=_number->getI(i+1);
00959     const int *numbers2=other._number->getI(iOther+1);
00960     for (int k=0; k<_numberOfElements[i]; k++)
00961     {
00962       bool found=false;
00963       for(int l=0;l<other._numberOfElements[iOther] && !found;l++)
00964       {
00965         if(numbers1[k]==numbers2[l])
00966           found=true;
00967       }
00968       if(!found)
00969         return false;
00970     }
00971   }
00972   return true;
00973 }
00977 int compareId(const void *x, const void *y);
00978 int compareId(const void *x, const void *y)
00979 {
00980   const int *x1=(const int *)x;
00981   const int *y1=(const int *)y;
00982   if(*x1<*y1)
00983     return -1;
00984   else if(*x1>*y1)
00985     return 1;
00986   else
00987     return 0;
00988 }
00989 
00995 list<int> *MEDMEM::SUPPORT::sub(int start,int end,const int *idsToSuppress,int lgthIdsToSuppress)
00996 {
00997   int size=end-start+1;
00998   int sizeRet=size-lgthIdsToSuppress;
00999   list<int> *ret;
01000   if(sizeRet<0)
01001     throw MEDEXCEPTION("MEDMEM::SUPPORT::sub");
01002   else if(sizeRet==0)
01003   {
01004     return 0;
01005   }
01006   if(idsToSuppress==0)
01007   {
01008     ret=new list<int>;
01009     for(int l=0;l<size;l++)
01010       ret->push_back(start+l);
01011     return ret;
01012   }
01013   ret=new list<int>;
01014   int *temp=new int[lgthIdsToSuppress+1];
01015   memcpy(temp,idsToSuppress,sizeof(int)*lgthIdsToSuppress);
01016   temp[lgthIdsToSuppress] = -1;
01017   qsort(temp,lgthIdsToSuppress,sizeof(int),compareId);
01018   int k=0;
01019   for(int i=start;i<=end;i++)
01020     if(temp[k]!=i)
01021       ret->push_back(i);
01022     else
01023       k++;
01024   delete [] temp;
01025   return ret;
01026 }
01027 
01033 list<int> *MEDMEM::SUPPORT::sub(const int *ids,int lgthIds,const int *idsToSuppress,int lgthIdsToSuppress)
01034 {
01035   list<int> *ret;
01036   int i,j=0;
01037   if(lgthIds<0)
01038     throw MEDEXCEPTION("MEDMEM::SUPPORT::sub");
01039   else if(lgthIds==0)
01040     return 0;
01041   ret=new list<int>;
01042   int *temp1=new int[lgthIds];
01043   memcpy(temp1,ids,sizeof(int)*lgthIds);
01044   qsort(temp1,lgthIds,sizeof(int),compareId);
01045   int *temp2=new int[lgthIdsToSuppress];
01046   memcpy(temp2,idsToSuppress,sizeof(int)*lgthIdsToSuppress);
01047   qsort(temp2,lgthIdsToSuppress,sizeof(int),compareId);
01048   for(i=0;i<lgthIds;)
01049   {
01050     if(j>=lgthIdsToSuppress)
01051       ret->push_back(temp1[i++]);
01052     else if(temp1[i]>temp2[j])
01053       j++;
01054     else if(temp1[i]<temp2[j])
01055       ret->push_back(temp1[i++]);
01056     else
01057       i++;
01058   }
01059   delete [] temp1;
01060   delete [] temp2;
01061   return ret;
01062 }
01063 
01068 SUPPORT *MEDMEM::SUPPORT::getComplement() const
01069 {
01070   SUPPORT *ret;
01071   const int nbOfElt=_mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS);
01072   int nbOfEltInSupp=getNumberOfElements(MED_ALL_ELEMENTS);
01073   if(_isOnAllElts || nbOfElt==nbOfEltInSupp)
01074   {
01075     ret=new SUPPORT;
01076     ret->setMesh(_mesh);
01077     ret->setEntity(_entity);
01078     string name="Complement of ";
01079     name+=_name;
01080     ret->setName(name);
01081     return ret;
01082   }
01083   const int *nbs=_number->getValue();
01084   list<int> *ids=sub(1,nbOfElt,nbs,nbOfEltInSupp);
01085   if(_entity==MED_NODE)
01086     ret=_mesh->buildSupportOnNodeFromElementList(*ids,_entity);
01087   else
01088     ret=_mesh->buildSupportOnElementsFromElementList(*ids,_entity);
01089   delete ids;
01090   return ret;
01091 }
01092 
01096 SUPPORT *MEDMEM::SUPPORT::substract(const SUPPORT& other) const throw (MEDEXCEPTION)
01097 {
01098   const char * LOC = "SUPPORT *MEDMEM::subtract(const SUPPORT * other) : ";
01099   BEGIN_OF_MED(LOC);
01100   SUPPORT *ret;
01101   if (_entity!=other.getEntity())
01102     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !"));
01103   if(!(*_mesh == *other.getMesh()))
01104     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh are different !"));
01105   if(other._isOnAllElts)
01106   {
01107     ret=new SUPPORT;
01108     ret->setMesh(_mesh);
01109     ret->setEntity(_entity);
01110     return ret;
01111   }
01112   if(_isOnAllElts)
01113     return other.getComplement();
01114   int nbOfEltInThis=getNumberOfElements(MED_ALL_ELEMENTS);
01115   const int *nbsThis=_number->getValue();
01116   int nbOfEltInOther=other.getNumberOfElements(MED_ALL_ELEMENTS);
01117   const int *nbsOther=other._number->getValue();
01118   list<int> *ids=sub(nbsThis,nbOfEltInThis,nbsOther,nbOfEltInOther);
01119   if(_entity==MED_NODE)
01120     ret=_mesh->buildSupportOnNodeFromElementList(*ids,_entity);
01121   else
01122     ret=_mesh->buildSupportOnElementsFromElementList(*ids,_entity);
01123   delete ids;
01124   return ret;
01125   END_OF_MED(LOC);
01126 }
01127 
01132 SUPPORT *MEDMEM::SUPPORT::getBoundaryElements(medEntityMesh Entity) const throw (MEDEXCEPTION)
01133 {
01134   const char * LOC = "SUPPORT *MEDMEM::SUPPORT::getBoundaryElements(medEntityMesh Entity) : ";
01135   BEGIN_OF_MED(LOC);
01136   int spaceDimension=_mesh->getSpaceDimension();
01137   medEntityMesh baseEntity=Entity;
01138   if (spaceDimension == 3)
01139     {
01140       if (Entity!=MED_FACE)
01141         {
01142           if(Entity==MED_NODE)
01143             baseEntity=MED_FACE;
01144           else
01145             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 3D mesh for entity "<<Entity<<" !"));
01146         }
01147     }
01148   if (spaceDimension == 2)
01149     {
01150       if (Entity!=MED_EDGE)
01151         {
01152           if(Entity==MED_NODE)
01153             baseEntity=MED_EDGE;
01154           else
01155             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 2D mesh for entity "<<Entity<<" !"));
01156         }
01157     }
01158   if(_isOnAllElts)
01159     return _mesh->getBoundaryElements(Entity);
01160 
01161   const MESH* mesh = _mesh->convertInMESH();
01162   const int * myConnectivityValue=mesh->getReverseConnectivity(MED_DESCENDING);
01163   const int * myConnectivityIndex=mesh->getReverseConnectivityIndex(MED_DESCENDING);
01164   int numberOf=mesh->getNumberOfElements(baseEntity,MED_ALL_ELEMENTS);
01165   const int *ids=_number->getValue();
01166   set<int> idsSet(ids,ids+_totalNumberOfElements);
01167   list<int> myElementsList;
01168   for (int i=0;i<numberOf;i++)
01169   {
01170     int nbOfDP1EntitySharing=0;
01171     if(idsSet.find(myConnectivityValue[myConnectivityIndex[i]-1])!=idsSet.end())
01172       nbOfDP1EntitySharing++;
01173     if(idsSet.find(myConnectivityValue[myConnectivityIndex[i]])!=idsSet.end())
01174       nbOfDP1EntitySharing++;
01175     if(nbOfDP1EntitySharing==1)
01176       myElementsList.push_back(i+1);
01177   }
01178   mesh->removeReference();
01179 
01180   if(Entity==MED_NODE)
01181   {
01182     return mesh->buildSupportOnNodeFromElementList(myElementsList,baseEntity);
01183   }
01184   else
01185   {
01186     return mesh->buildSupportOnElementsFromElementList(myElementsList,baseEntity);
01187   }
01188 }
01189 
01194 SUPPORT* SUPPORT::buildSupportOnNode() const throw (MEDEXCEPTION)
01195 {
01196   const char * LOC = "SUPPORT *MEDMEM::SUPPORT::buildSupportOnNode() : ";
01197   if ( !getMesh() )
01198     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"This SUPPORT has no mesh"));
01199 
01200   SUPPORT* nodalSupport = 0;
01201   if ( isOnAllElements() )
01202     {
01203       nodalSupport = const_cast<SUPPORT*>( getMesh()->getSupportOnAll( MED_NODE ));
01204       nodalSupport->addReference();
01205     }
01206   else
01207     {
01208       if ( !_numberOfElements )
01209         throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No element numbers in a partial support"));
01210       string name("Support On Node built from ");
01211       name += getName();
01212 
01213       nodalSupport = new SUPPORT;
01214       nodalSupport->setMesh( getMesh());
01215       nodalSupport->setName( name );
01216       nodalSupport->setEntity( MED_NODE );
01217       nodalSupport->setEntity( getEntity() );
01218 
01219       const int * nums = _number->getValue();
01220       list<int> elems( nums, nums + _totalNumberOfElements );
01221       getMesh()->fillSupportOnNodeFromElementList( elems, nodalSupport );
01222     }
01223   return nodalSupport;
01224 }
01225 
01229 void MEDMEM::SUPPORT::fillFromNodeList(const list<int>& listOfNode) throw (MEDEXCEPTION)
01230 {
01231   setEntity(MED_NODE);
01232   clearDataOnNumbers();
01233   int size=listOfNode.size();
01234   int totalNbInMesh=_mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS);
01235   if(totalNbInMesh==size)
01236   {
01237     _isOnAllElts=true;
01238     update();
01239     return;
01240   }
01241   else
01242     _isOnAllElts=false;
01243   int numberOfGeometricType=1;
01244   medGeometryElement* geometricType=new medGeometryElement[1];
01245   geometricType[0]=MED_NONE;
01246   int *numberOfElements=new int[1];
01247   numberOfElements[0]=size;
01248   int *mySkyLineArrayIndex=new int[2];
01249   mySkyLineArrayIndex[0]=1;
01250   mySkyLineArrayIndex[1]=1+numberOfElements[0];
01251   int *tab=new int[numberOfElements[0]];
01252   int i=0;
01253   for(list<int>::const_iterator iter2=listOfNode.begin();iter2!=listOfNode.end();iter2++)
01254     tab[i++]=*iter2;
01255   MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(1,numberOfElements[0],mySkyLineArrayIndex,tab,true);
01256   setNumberOfGeometricType(numberOfGeometricType);
01257   setGeometricType(geometricType);
01258   setNumberOfElements(numberOfElements);
01259   setNumber(mySkyLineArray);
01260 
01261   delete[] numberOfElements;
01262   delete[] geometricType;
01263 }
01264 
01265 /*
01266   Method created to factorize code. This method fills the current SUPPORT on entity 'entity' containing all the entities contained in
01267   elements 'listOfElt' of entity 'entity'. Warning this method should be called after both the attributes this->_mesh and this->_entity are correctly set.
01268 */
01269 void MEDMEM::SUPPORT::fillFromElementList(const list<int>& listOfElt) throw (MEDEXCEPTION)
01270 {
01271   clearDataOnNumbers();
01272   int size=listOfElt.size();
01273   int totalNbInMesh=_mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS);
01274   if(totalNbInMesh==size)
01275   {
01276     _isOnAllElts=true;
01277     update();
01278     return;
01279   }
01280   else
01281     _isOnAllElts=false;
01282   // Well, we must know how many geometric type we have found
01283   int * myListArray = new int[size] ;
01284   int id = 0 ;
01285   list<int>::const_iterator myElementsListIt ;
01286   for (myElementsListIt=listOfElt.begin();myElementsListIt!=listOfElt.end();myElementsListIt++)
01287     myListArray[id++]=(*myElementsListIt) ;
01288   int numberOfGeometricType ;
01289   medGeometryElement* geometricType ;
01290   int * numberOfElements ;
01291   int * mySkyLineArrayIndex ;
01292 
01293   int numberOfType = _mesh->getNumberOfTypes(_entity) ;
01294   if (numberOfType == 1)
01295   {
01296     numberOfGeometricType = 1 ;
01297     geometricType = new medGeometryElement[1] ;
01298     geometricType[0] = _mesh->getTypes(_entity)[0];
01299     numberOfElements = new int[1] ;
01300     numberOfElements[0] = size ;
01301     mySkyLineArrayIndex = new int[2] ;
01302     mySkyLineArrayIndex[0]=1 ;
01303     mySkyLineArrayIndex[1]=1+size ;
01304   }
01305   else // hemmm
01306   {
01307     map<medGeometryElement,int> theType ;
01308     for (myElementsListIt=listOfElt.begin();myElementsListIt!=listOfElt.end();myElementsListIt++)
01309     {
01310       medGeometryElement myType = _mesh->getElementType(_entity,*myElementsListIt) ;
01311       if (theType.find(myType) != theType.end() )
01312         theType[myType]+=1 ;
01313       else
01314         theType[myType]=1 ;
01315     }
01316     numberOfGeometricType = theType.size() ;
01317     geometricType = new medGeometryElement[numberOfGeometricType] ;
01318     numberOfElements = new int[numberOfGeometricType] ;
01319     mySkyLineArrayIndex = new int[numberOfGeometricType+1] ;
01320     int index = 0 ;
01321     mySkyLineArrayIndex[0]=1 ;
01322     map<medGeometryElement,int>::iterator theTypeIt ;
01323     for (theTypeIt=theType.begin();theTypeIt!=theType.end();theTypeIt++)
01324     {
01325       geometricType[index] = (*theTypeIt).first ;
01326       numberOfElements[index] = (*theTypeIt).second ;
01327       mySkyLineArrayIndex[index+1]=mySkyLineArrayIndex[index]+numberOfElements[index] ;
01328       index++ ;
01329     }
01330   }
01331   MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray,/*shallowCopy=*/true) ;
01332   setNumberOfGeometricType(numberOfGeometricType) ;
01333   setGeometricType(geometricType) ;
01334   setNumberOfElements(numberOfElements) ;
01335   setNumber(mySkyLineArray) ;
01336 
01337   delete[] numberOfElements;
01338   delete[] geometricType;
01339 }
01340 
01347 MESH* SUPPORT::makeMesh() const
01348 {
01349   const char* LOC = "SUPPORT::makeMesh(): ";
01350   if ( !_mesh )
01351     throw MED_EXCEPTION(STRING(LOC)<<" NULL mesh in support");
01352   if ( _entity == MED_NODE )
01353     throw MED_EXCEPTION(STRING(LOC)<<" unavailable for support on nodes");
01354 
01355   //Creating the new mesh
01356 
01357   MESHING* newmesh = new MESHING();
01358   newmesh->setName( STRING("MeshFromSupport_") << getName() );
01359 
01360   // set types info
01361   const medGeometryElement* types = getTypes();
01362   int nb_types = _numberOfGeometricType;
01363   newmesh->setNumberOfTypes   ( nb_types, MED_CELL );
01364   newmesh->setTypes           ( types, MED_CELL );
01365   newmesh->setNumberOfElements( _numberOfElements, MED_CELL);
01366 
01367   // browsing through elements to create a mapping between
01368   // the new nodes and the old nodes and to create nodal connectivity
01369 
01370   const MESH* mesh = _mesh->convertInMESH();
01371   const medGeometryElement* all_mesh_types = mesh->getTypes( _entity );
01372   const int *                    num_index = mesh->getGlobalNumberingIndex( _entity );
01373 
01374   map<int,int> oldnodes; // map old to new nodes
01375   if ( types[nb_types-1] == MED_POLYHEDRA )
01376     oldnodes.insert( make_pair( -1, -1 )); // for face separators
01377   int newid=1;
01378   for (int itype=0; itype < _numberOfGeometricType;itype++)
01379   {
01380     medGeometryElement type = types[itype];
01381     int nbelems = getNumberOfElements(type);
01382 
01383     // get connectivity info
01384     int shift = 1; // to pass from elem number to array index
01385     const int* conn = mesh->getConnectivity(MED_NODAL,_entity,MED_ALL_ELEMENTS);
01386     const int* index = mesh->getConnectivityIndex(MED_NODAL,_entity);
01387     int t = 0;
01388     while ( type != all_mesh_types[t] ) ++t;
01389     shift+= num_index[ t ] - num_index[0];
01390     index+= num_index[ t ] - num_index[0];
01391 
01392     // make and set new connectivity
01393     if ( _isOnAllElts  && _entity == MED_CELL )
01394     {
01395       newmesh->setConnectivity( MED_CELL, type, conn, index );
01396     }
01397     else // partial support or support of sub-entities
01398     {
01399       vector<int> new_conn, new_index;
01400       new_conn.reserve ( nbelems * (type % 100) );
01401       new_index.reserve( nbelems + 1 );
01402       new_index.push_back(1);
01403 
01404       const int * nums = _isOnAllElts ? 0 : getNumber( type );
01405 
01406       for (int i=0; i<nbelems; i++)
01407       {
01408         int ielem = nums ? nums[i]-shift : i;
01409         const int* elem_node = conn + index[ ielem   ] - 1;
01410         const int* nodes_end = conn + index[ ielem+1 ] - 1;
01411         for ( ; elem_node < nodes_end; ++elem_node )
01412         {
01413           // make new connectivity
01414           map<int,int>::iterator old_new = oldnodes.insert(make_pair( *elem_node, newid )).first;
01415           new_conn.push_back( old_new->second );
01416           if ( old_new->second == newid )
01417             newid++;
01418         }
01419         new_index.push_back( new_index.back() + index[ ielem+1 ] - index[ ielem ] );
01420       }
01421       // set new connectivity
01422       newmesh->setConnectivity( MED_CELL, type, & new_conn[0], & new_index[0] );
01423     }
01424   }
01425 
01426   //definition of coordinates
01427 
01428   int nb_nodes, spacedim = mesh->getSpaceDimension();  
01429   const double*oldcoords = mesh->getCoordinates(MED_FULL_INTERLACE);
01430   PointerOf<double> newcoords;
01431 
01432   if ( _isOnAllElts && _entity == MED_CELL )
01433   {
01434     nb_nodes = mesh->getNumberOfNodes();
01435     newcoords.set( oldcoords );
01436   }
01437   else
01438   {
01439     nb_nodes = oldnodes.size();
01440     newcoords.set( nb_nodes * spacedim);
01441     for (std::map<int,int>::const_iterator iter=oldnodes.begin(); iter!=oldnodes.end();iter++)
01442       std::copy( oldcoords+(iter->first-1 )*spacedim,
01443                  oldcoords+(iter->first   )*spacedim,
01444                  newcoords+(iter->second-1)*spacedim);
01445   }
01446   newmesh->setCoordinates(spacedim, nb_nodes, newcoords,
01447                           mesh->getCoordinatesSystem(), MED_FULL_INTERLACE);
01448   newmesh->setCoordinatesNames ( mesh->getCoordinatesNames() );
01449   newmesh->setCoordinatesUnits ( mesh->getCoordinatesUnits() );
01450 
01451   mesh->removeReference();
01452 
01453   return newmesh;
01454 }
01460 //--------------------------------------
01461 void SUPPORT::setMesh(const GMESH *Mesh) const
01462   //--------------------------------------
01463 {
01464   if(_mesh!=Mesh)
01465     {
01466       if(_mesh)
01467         _mesh->removeReference();
01468       _mesh=Mesh;
01469       _meshName = "";
01470       if(_mesh)
01471         _mesh->addReference();
01472     }
01473 }
01474 
01476 //------------------------------------
01477 string SUPPORT::getMeshName() const
01478   //------------------------------------
01479 {
01480   if (_mesh)
01481     return _mesh->getName();
01482   else
01483     return _meshName;
01484 }
01485 
01505 //-----------------------------------------------------------------------------
01506 int SUPPORT::getNumberOfElements(MED_EN::medGeometryElement GeometricType) const
01507   throw (MEDEXCEPTION)
01508 //-----------------------------------------------------------------------------
01509 {
01510   if (GeometricType==MED_EN::MED_ALL_ELEMENTS)
01511     return _totalNumberOfElements;
01512   for (int i=0;i<_numberOfGeometricType;i++)
01513     if (_geometricType[i]==GeometricType)
01514       return ( _totalNumberOfElements < 1 ) ? 0 : _numberOfElements[i];
01515   throw MEDEXCEPTION("Support::getNumberOfElements : Geometric type not found !") ;
01516 }
01517 
01519 //-----------------------------------------------------------------------------
01520 const int * SUPPORT::getNumberOfElements() const throw (MEDEXCEPTION) {
01521 //-----------------------------------------------------------------------------
01522   return _numberOfElements;
01523 }
01524 
01530 //-------------------------------------------
01531 const int * SUPPORT::getNumberIndex() const
01532 //-------------------------------------------
01533   throw (MEDEXCEPTION)
01534 {
01535   /*  issue 0021167: [CEA 448] Supports management on all elements
01536   if (_isOnAllElts)
01537     throw MEDEXCEPTION("Support::getNumberIndex : Not defined, support is on all entity !") ;
01538   */
01539   if ( !_number )
01540     throw MEDEXCEPTION("Support::getNumberIndex : numbers not set !") ;
01541   return _number->getIndex() ;
01542 }
01547 //---------------------------------------------------------------------
01548 MEDSKYLINEARRAY * SUPPORT::getnumber() const
01549   throw (MEDEXCEPTION)
01550 //---------------------------------------------------------------------
01551 {
01552   if (_number==NULL)
01553     throw MEDEXCEPTION("Support::getnumber : Not defined !") ;
01554   return _number ;
01555 }
01556 
01557 //---------------------------------------------------------------------
01558 MEDSKYLINEARRAY * SUPPORT::getnumberFromFile() const
01559   throw (MEDEXCEPTION)
01560 //---------------------------------------------------------------------
01561 {
01562   if (_number_fromfile==NULL)
01563     throw MEDEXCEPTION("Support::getnumberFromFile : Not defined !") ;
01564   return _number_fromfile ;
01565 }
01566 
01577 //---------------------------------------------------------------------
01578 const int * SUPPORT::getNumber(MED_EN::medGeometryElement GeometricType) const
01579   throw (MEDEXCEPTION)
01580 //---------------------------------------------------------------------
01581 {
01582   /*  issue 0021167: [CEA 448] Supports management on all elements
01583   if (_isOnAllElts)
01584     throw MEDEXCEPTION("Support::getNumber : Not defined, support is on all entity !") ;
01585   */
01586   if (!_number)
01587   {
01588     if ( _isOnAllElts )
01589       //update();
01590       throw MEDEXCEPTION("Support::getNumber : not updated (update()) SUPPORT on all elements !") ;
01591     else if ( _totalNumberOfElements > 0 )
01592       throw MEDEXCEPTION("Support::getNumber : wrong support, _number not defined !") ;
01593     else
01594       return NULL;
01595   }
01596   if (GeometricType==MED_EN::MED_ALL_ELEMENTS)
01597     return _number->getValue() ;
01598   for (int i=0;i<_numberOfGeometricType;i++)
01599     if (_geometricType[i]==GeometricType)
01600       return _number->getI(i+1) ;
01601   throw MEDEXCEPTION("Support::getNumber : GeometricType not found !") ;
01602 }
01603 
01604 //---------------------------------------------------------------------
01605 const int * SUPPORT::getNumberFromFile(MED_EN::medGeometryElement GeometricType) const
01606   throw (MEDEXCEPTION)
01607 //---------------------------------------------------------------------
01608 {
01609 //   if (_isOnAllElts)
01610 //     throw MEDEXCEPTION("Support::getNumberFromFile : Not defined, support is on all entity !") ;
01611   if (GeometricType==MED_EN::MED_ALL_ELEMENTS)
01612     return _number_fromfile->getValue() ;
01613   for (int i=0;i<_numberOfGeometricType;i++)
01614     if (_geometricType[i]==GeometricType)
01615       return _number_fromfile->getI(i+1) ;
01616   throw MEDEXCEPTION("Support::getNumberFromFile : GeometricType not found !") ;
01617 }
01618 
01620 //--------------------------------------
01621 void SUPPORT::setMeshName(const std::string & meshName)
01622 //--------------------------------------
01623 {
01624   if (_mesh)
01625     throw MEDEXCEPTION("SUPPORT::setMeshName(const string & meshName) : Setting meshName is not possible when an associated mesh is set !") ;
01626 
01627   _meshName=meshName;
01628 }
01629 
01631 //------------------------------------------
01632 void SUPPORT::setEntity(MED_EN::medEntityMesh Entity)
01633 {
01634   _entity=Entity;
01635   // 0021199: [CEA 458] MEDMEM::SUPPORT : geometric type when support is on node
01636   // set geometric type -> MED_NONE
01637   if ( _entity == MED_NODE )
01638     {
01639       _numberOfGeometricType = 1;
01640       const MED_EN::medGeometryElement nodeType = MED_EN::MED_NONE;
01641       _geometricType.set(0);
01642       setGeometricType( &nodeType );
01643     }
01644 }
01645 
01647 //---------------------------------------------------------------------
01648 void SUPPORT::setNumberOfGeometricType(int NumberOfGeometricType)
01649 //---------------------------------------------------------------------
01650 {
01651   _numberOfGeometricType=NumberOfGeometricType;
01652 
01653   _geometricType.set(0);
01654   _numberOfElements.set(0);
01655   _profilNames.resize( NumberOfGeometricType, "" );
01656 }
01657 
01659 //---------------------------------------------------------------------
01660 void SUPPORT::setGeometricType(const MED_EN::medGeometryElement *GeometricType)
01661 //---------------------------------------------------------------------
01662 {
01663   if (!_geometricType)
01664     {
01665       _geometricType.set(_numberOfGeometricType, GeometricType);
01666       // 0021199: [CEA 458] MEDMEM::SUPPORT : geometric type when support is on node
01667       // geometric type must be MED_NONE
01668       if ( _entity == MED_NODE && _numberOfGeometricType == 1 && _geometricType[0] != MED_NONE )
01669         throw MEDEXCEPTION("SUPPORT::setGeometricType(), valid type for MED_NODE is MED_NONE ");
01670     }
01671   if (_profilNames.empty() || _profilNames[0].empty())
01672     {
01673       // giving a default value to profile names
01674       vector<string> prof_names( _numberOfGeometricType);
01675       string name = healName( _name );
01676       for (int itype=0; itype < _numberOfGeometricType; itype++)
01677         {
01678           ostringstream typestr;
01679           typestr<<name<<"_type"<<_geometricType[itype];
01680           prof_names[itype]=typestr.str();
01681         }
01682       _profilNames=prof_names;
01683     }
01684 }
01685 
01690 //----------------------------------------------------------
01691 void SUPPORT::setNumberOfElements(const int *NumberOfElements)
01692 //----------------------------------------------------------
01693 {
01694   if (_numberOfElements == NULL)
01695     {
01696       if (_numberOfGeometricType)
01697         _numberOfElements.set(_numberOfGeometricType,NumberOfElements);
01698       else
01699         _numberOfElements.set(0);
01700     }
01701   _totalNumberOfElements = 0 ;
01702   for (int i=0;i<_numberOfGeometricType;i++)
01703     _totalNumberOfElements+=_numberOfElements[i];
01704 }
01705 
01707 //---------------------------------------------------
01708 void SUPPORT::setNumber(MEDSKYLINEARRAY * Number)
01709 //---------------------------------------------------
01710 {
01711   /*  issue 0021167: [CEA 448] Supports management on all elements
01712   if ( _isOnAllElts )
01713     throw MEDEXCEPTION("SUPPORT::setNumber(MEDSKYLINEARRAY * Number) Support is on all elements") ;
01714   */
01715   if (_number != NULL) delete _number ;
01716   _number=Number;
01717 }
01718 
01720 //---------------------------------------------------
01721 void SUPPORT::setNumber(const int * index, const int* value, bool shallowCopy)
01722 //---------------------------------------------------
01723 {
01724   if (_number != NULL) delete _number ;
01725   _number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value,shallowCopy);
01726 }