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/
29 #include "MEDMEM_Support.hxx"
30 #include "MEDMEM_DriversDef.hxx"
31 #include "MEDMEM_Mesh.hxx"
34 using namespace MED_EN;
35 using namespace MEDMEM;
37 #define MED_NBR_GEOMETRIE_MAILLE 15
39 /* This class is a generic class for family and group */
44 //--------------------------------------------------------------------------
45 SUPPORT::SUPPORT(): _name(""), _description("None"), _mesh((MESH*)NULL),
46 _entity(MED_CELL), _numberOfGeometricType(0),
48 _totalNumberOfElements(0),
49 _number((MEDSKYLINEARRAY*)NULL)
50 //--------------------------------------------------------------------------
52 MESSAGE("SUPPORT::SUPPORT()");
58 //--------------------------------------------------------------------------
59 SUPPORT::SUPPORT(MESH* Mesh, string Name/*=""*/, medEntityMesh Entity/*=MED_CELL*/):
60 _name(Name), _description("None"), _mesh(Mesh), _entity(Entity),
61 _numberOfGeometricType(0), _isOnAllElts(true),
62 _totalNumberOfElements(0), _number((MEDSKYLINEARRAY*)NULL)
63 //--------------------------------------------------------------------------
65 MESSAGE("SUPPORT::SUPPORT(MESH*Mesh,string Name,medEntityMesh Entity)");
72 //--------------------------------------------------------------------------
73 SUPPORT::SUPPORT(const SUPPORT & m)
74 //--------------------------------------------------------------------------
76 const char * LOC = "SUPPORT::SUPPORT(SUPPORT & m) : " ;
80 _description = m._description ;
81 _mesh = m._mesh ; // on recopie uniquement l'adresse
83 _numberOfGeometricType = m._numberOfGeometricType;
86 _geometricType.set(_numberOfGeometricType,m._geometricType);
88 _isOnAllElts = m._isOnAllElts;
90 if (m._numberOfElements)
91 _numberOfElements.set(_numberOfGeometricType,m._numberOfElements);
93 _totalNumberOfElements = m._totalNumberOfElements;
95 if (m._isOnAllElts == false && m._number ) // m may be not filled SUPPORTClient
96 _number = new MEDSKYLINEARRAY(* m._number);
98 _number = (MEDSKYLINEARRAY *) NULL;
103 Affectation operator. operator = perform et deep copy except for attribute _mesh
105 //--------------------------------------------------------------------------
106 SUPPORT & SUPPORT::operator=(const SUPPORT & m)
107 //--------------------------------------------------------------------------
109 const char * LOC = "SUPPORT::operator=(const SUPPORT & m) : " ;
112 if ( this == &m ) return *this;
115 _description = m._description;
116 _mesh = m._mesh ; // on recopie uniquement l'adresse
118 _numberOfGeometricType = m._numberOfGeometricType;
119 if (m._geometricType)
120 _geometricType.set(_numberOfGeometricType,m._geometricType);
121 _isOnAllElts = m._isOnAllElts;
122 if (m._numberOfElements)
123 _numberOfElements.set(_numberOfGeometricType,m._numberOfElements);
124 _totalNumberOfElements = m._totalNumberOfElements;
125 if (m._isOnAllElts == false) {
126 if (_number) delete _number;
127 if ( m._number ) // m may be not filled SUPPORTClient
128 _number = new MEDSKYLINEARRAY(* m._number);
130 _number = (MEDSKYLINEARRAY *) NULL;
132 _number = (MEDSKYLINEARRAY *) NULL;
145 MESSAGE("Destructeur ~SUPPORT()");
146 clearDataOnNumbers();
152 //--------------------------------------------------
153 ostream & MEDMEM::operator<<(ostream &os, const SUPPORT &my)
154 //--------------------------------------------------
156 os << "Name : "<< my.getName() << endl ;
157 os << "Description : "<< my.getDescription() << endl ;
159 if (my.getMesh() == NULL)
160 os << " Mesh not defined." << endl ;
162 os << " Mesh defined." << endl;
164 os << my.getMeshName() << endl ;
165 os << "Entity : "<<MED_EN::entNames[my._entity] << endl;
166 os << "Entity list : "<< endl;
167 if ( my._isOnAllElts )
168 os << "Is on all entities."<< endl;
170 os << "Is not on all entities. "<< endl;
171 if ( my._number ) // m may be not filled SUPPORTClient
172 os << *my.getNumber(MED_ALL_ELEMENTS);
174 int numberoftypes = my._numberOfGeometricType ;
175 os << "NumberOfTypes : "<<numberoftypes<<endl;
176 PointerOf<medGeometryElement> types = my._geometricType;
177 for (int j=0;j<numberoftypes;j++) {
178 int numberOfElements = my._numberOfElements[j];
179 os << " On Type "<<MED_EN::geoNames[types[j]]
180 <<" : there is(are) "<<numberOfElements<<" element(s) and " <<endl;
186 Updade the SUPPORT attributs with rigth MESH information.
188 It has an effect only if SUPPORT is on all elements.
190 No more need in future release.
192 //-------------------
193 void SUPPORT::update()
194 //-------------------
196 const char * LOC = "SUPPORT::update() : " ;
201 if (_entity == MED_NODE)
203 _numberOfGeometricType=1 ;
204 _geometricType.set(1);
205 _geometricType[0]=MED_NONE;
206 _numberOfElements.set(1);
207 _numberOfElements[0]=_mesh->getNumberOfNodes(); // Vérifier le pointeur !
208 _totalNumberOfElements=_numberOfElements[0];
211 { // we duplicate information from _mesh
\ 1
212 _numberOfGeometricType=_mesh->getNumberOfTypesWithPoly(_entity);
213 SCRUTE(_numberOfGeometricType);
214 medGeometryElement * allType = _mesh->getTypesWithPoly(_entity);
215 _geometricType.set(_numberOfGeometricType,allType );
216 _numberOfElements.set(_numberOfGeometricType);
217 _totalNumberOfElements=0;
218 for (int i=0;i<_numberOfGeometricType;i++)
220 _numberOfElements[i]=_mesh->getNumberOfElementsWithPoly(_entity,_geometricType[i]) ;
221 _totalNumberOfElements+=_numberOfElements[i];
227 SCRUTE(_numberOfGeometricType);
232 Get the field value index (in fortran mode) from the support global number.
233 Becareful, it doesn't take care of the field number of components
235 //-------------------
236 int SUPPORT::getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION)
237 //-------------------
239 const char * LOC="getValIndFromGlobalNumber(const int number) : ";
242 if (_isOnAllElts) return number;
244 int nbOfEltsThis = getNumberOfElements(MED_ALL_ELEMENTS);
245 const int *eltsThis = _number->getValue();
250 for(iThis=0;iThis<nbOfEltsThis && !found;)
251 if(eltsThis[iThis]==number)
254 int valInd = iThis+1;
261 cout << "----Contenu du skyline : ---------------------" << *_number << endl;
264 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Can't find the global number |"
265 << number << "| in Support |"
266 << getName() << "|" ));
268 // It should never arrive here !!
275 Blend the given SUPPORT mySupport into the calling object SUPPORT.
277 //-------------------
278 void SUPPORT::blending(SUPPORT * mySupport) throw (MEDEXCEPTION)
279 //-------------------
281 const char * LOC="SUPPORT::blending(SUPPORT *) : ";
283 if (_entity!=mySupport->getEntity())
284 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !"));
285 if(!(*_mesh == *mySupport->getMesh()))
286 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh are different !"));
289 if(mySupport->isOnAllElements())
294 if(mySupport->_totalNumberOfElements==0)
296 const int *ids=getNumber(MED_ALL_ELEMENTS);
297 set<int> idsSet(ids,ids+getNumberOfElements(MED_ALL_ELEMENTS));
298 const int *idsMySupport=mySupport->getNumber(MED_ALL_ELEMENTS);
299 int mySupportSize=mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
300 set<int>::iterator iter;
301 for(int i=0;i<mySupportSize;i++)
302 idsSet.insert(idsMySupport[i]);
303 int size=idsSet.size();
308 for(iter=idsSet.begin();iter!=idsSet.end();iter++)
309 idsList.push_back(*iter);
311 MESSAGE(LOC << " size Set " << idsSet.size() << " size List " << idsList.size());
313 if(_entity==MED_NODE)
314 fillFromNodeList(idsList);
316 fillFromElementList(idsList);
319 clearDataOnNumbers();
324 This function allows the user to set a support not on all entities Entity,
325 it should be used after an initialisation with the constructor
326 SUPPORT(MESH* Mesh, string Name="", medEntityMesh Entity=MED_CELL) and
327 after the call to the function setAll(false).
328 It allocates and initialises all the attributs of the class SUPPORT.
331 //-------------------
332 void SUPPORT::setpartial(string Description, int NumberOfGeometricType,
333 int TotalNumberOfElements,
334 medGeometryElement *GeometricType,
335 int *NumberOfElements, int *NumberValue)
336 //-------------------
338 const char * LOC = "SUPPORT::setpartial(string , int , int , medGeometryElement * , int * , int *) : " ;
341 _isOnAllElts = false ;
343 _description=Description;
345 _numberOfGeometricType=NumberOfGeometricType;
346 _geometricType.set(NumberOfGeometricType);
347 _numberOfElements.set(NumberOfGeometricType);
348 _totalNumberOfElements = TotalNumberOfElements;
350 int * index = new int[_numberOfGeometricType+1];
353 for (int i=0;i<_numberOfGeometricType;i++) {
354 if(GeometricType[i]/100 != elemDim)
356 elemDim=GeometricType[i]/100;
358 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"unhomogeneous geometric types (dimension) !"));
359 _geometricType[i] = GeometricType[i] ;
360 _numberOfElements[i] = NumberOfElements[i] ;
361 index[i+1] = index[i]+NumberOfElements[i] ;
364 if (_number!=NULL) delete _number ;
365 _number = new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,NumberValue);
374 This function allows the user to set a support not on all entities Entity,
375 it should be used after an initialisation of :
376 SUPPORT(MESH* Mesh, string Name="", medEntityMesh Entity=MED_CELL) and
377 after calling at least setGeometricType and perharps setEntity.
378 It allocates and initialises all the attributs of the class SUPPORT but
379 doesn't set a description, a SUPPORT name, a meshName and an associated MESH.
382 //-------------------
383 void SUPPORT::setpartial(MEDSKYLINEARRAY * number, bool shallowCopy) throw (MEDEXCEPTION)
384 //-------------------
386 const char * LOC = "SUPPORT::setpartial(MEDSKYLINEARRAY * number) : " ;
389 if ( ! _geometricType )
390 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT must contains"
391 << " a geometric type list" )) ;
393 _numberOfGeometricType = number->getNumberOf();
395 _numberOfElements.set(_numberOfGeometricType);
397 for (int i=0; i< _numberOfGeometricType; i++)
398 _numberOfElements[i] = number->getNumberOfI(i+1);
400 _totalNumberOfElements = number->getLength();
402 _isOnAllElts = false ;
404 if (_number!=NULL) delete _number ;
409 _number = new MEDSKYLINEARRAY(*number);
411 // cout << *_number << endl;
416 void SUPPORT::setProfilNames(vector<string> profilNames) throw (MEDEXCEPTION){
418 const char * LOC = "SUPPORT::setProfilNames(vector<string> profilNames) : " ;
422 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT shouldn't be on all elements"
423 << " while setting profil name list" )) ;
425 if ( ! _geometricType || _numberOfGeometricType==0 )
426 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT must contains"
427 << " a least one geometric type" )) ;
430 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT must contains"
431 << " a profil number list before setting"
432 << " the associated profil name list" )) ;
434 if ( ( profilNames.size() != _number->getNumberOf() ) &&
435 ( profilNames.size() !=_numberOfGeometricType ) ) {
436 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The profil name list size : "<< profilNames.size()
437 << " must be equal to the number of geometric type : "
438 << _numberOfGeometricType << " (_number->getNumberOf() : "
439 << _number->getNumberOf() << " )"
444 _profilNames = profilNames;
450 vector<string> SUPPORT::getProfilNames() const throw (MEDEXCEPTION)
457 This method gets the boundary elements of the mesh. The support has to be
458 build using the constructor SUPPORT(MESH *,string, medEntityMesh) or
459 SUPPORT() followed by setMesh(MESH*) setName(string) and
460 setEntity(medEntityMesh) before using this method.
462 //-------------------
463 void SUPPORT::getBoundaryElements() throw (MEDEXCEPTION)
464 //-------------------
466 const char * LOC = "SUPPORT::getBoundaryElements() : " ;
469 if (_mesh == (MESH*)NULL) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"You shlould use the appropriate SUPPORT Constructor before calling this method"));
471 int spaceDimension = _mesh->getSpaceDimension();
473 if (spaceDimension == 3)
474 if (_entity != MED_FACE)
475 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 3D mesh for entity "<<_entity<<" !"));
476 if (spaceDimension == 2)
477 if (_entity != MED_EDGE)
478 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 2D mesh for entity "<<_entity<<" !"));
482 const int * myConnectivityValue = _mesh->getReverseConnectivity(MED_DESCENDING) ;
483 const int * myConnectivityIndex = _mesh->getReverseConnectivityIndex(MED_DESCENDING) ;
484 int numberOf = _mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS) ;
485 list<int> myElementsList ;
488 for (int i=0 ; i<numberOf; i++)
489 if (myConnectivityValue[myConnectivityIndex[i]] == 0) {
491 myElementsList.push_back(i+1) ;
495 // Well, we must know how many geometric type we have found
496 int * myListArray = new int[size] ;
498 list<int>::iterator myElementsListIt ;
499 for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
500 myListArray[id]=(*myElementsListIt) ;
502 SCRUTE(myListArray[id]);
506 int numberOfGeometricType ;
507 medGeometryElement* geometricType ;
508 int * geometricTypeNumber ;
509 int * numberOfElements ;
510 //MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY() ;
511 int * mySkyLineArrayIndex ;
513 int numberOfType = _mesh->getNumberOfTypes(_entity) ;
514 if (numberOfType == 1) { // wonderfull : it's easy !
515 numberOfGeometricType = 1 ;
516 geometricType = new medGeometryElement[1] ;
517 const medGeometryElement * allType = _mesh->getTypes(_entity);
518 geometricType[0] = allType[0] ;
519 geometricTypeNumber = new int[1] ; // not use, but initialized to nothing
520 geometricTypeNumber[0] = 0 ;
521 numberOfElements = new int[1] ;
522 numberOfElements[0] = size ;
523 mySkyLineArrayIndex = new int[2] ;
524 mySkyLineArrayIndex[0]=1 ;
525 mySkyLineArrayIndex[1]=1+size ;
528 map<medGeometryElement,int> theType ;
529 for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
530 medGeometryElement myType = _mesh->getElementType(_entity,*myElementsListIt) ;
531 if (theType.find(myType) != theType.end() )
536 numberOfGeometricType = theType.size() ;
537 geometricType = new medGeometryElement[numberOfGeometricType] ;
538 //const medGeometryElement * allType = _mesh->getTypes(_entity); !! UNUSED VARIABLE !!
539 geometricTypeNumber = new int[numberOfGeometricType] ; // not use, but initialized to nothing
540 numberOfElements = new int[numberOfGeometricType] ;
541 mySkyLineArrayIndex = new int[numberOfGeometricType+1] ;
543 mySkyLineArrayIndex[0]=1 ;
544 map<medGeometryElement,int>::iterator theTypeIt ;
545 for (theTypeIt=theType.begin();theTypeIt!=theType.end();theTypeIt++) {
546 geometricType[index] = (*theTypeIt).first ;
547 geometricTypeNumber[index] = 0 ;
548 numberOfElements[index] = (*theTypeIt).second ;
549 mySkyLineArrayIndex[index+1]=mySkyLineArrayIndex[index]+numberOfElements[index] ;
553 //mySkyLineArray->setMEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray) ;
554 MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray) ;
556 setNumberOfGeometricType(numberOfGeometricType) ;
557 // setGeometricType(geometricType) ;
558 for (int i=0;i<numberOfGeometricType;i++)
560 _geometricType[i] = geometricType[i];
563 setNumberOfElements(numberOfElements) ;
564 setTotalNumberOfElements(size) ;
565 // setNumber(mySkyLineArray) ;
567 _number = new MEDSKYLINEARRAY(numberOfGeometricType,size);
569 _number->setIndex(mySkyLineArrayIndex);
571 for (int i=0;i<size;i++)
573 _number->setIndexValue(i+1,myListArray[i]);
576 delete[] numberOfElements;
577 delete[] geometricTypeNumber;
578 delete[] geometricType;
579 delete[] mySkyLineArrayIndex;
580 delete[] myListArray;
581 delete mySkyLineArray;
587 intersect the given SUPPORT mySupport into the calling SUPPORT object.
589 //-------------------
590 void SUPPORT::intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION)
592 const char * LOC="SUPPORT::intersecting(SUPPORT *) : ";
594 if (_entity!=mySupport->getEntity())
595 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !"));
596 if(!(*_mesh == *mySupport->getMesh()))
597 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh are different !"));
598 if(mySupport->isOnAllElements())
605 if(_totalNumberOfElements==0)
607 const int *ids=getNumber(MED_ALL_ELEMENTS);
608 set<int> idsSet(ids,ids+getNumberOfElements(MED_ALL_ELEMENTS));
609 const int *idsMySupport=mySupport->getNumber(MED_ALL_ELEMENTS);
610 int mySupportSize=mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
611 set<int> idsSetMySupport(idsMySupport,idsMySupport+mySupportSize);
612 set<int>::iterator iter;
614 for(iter=idsSet.begin();iter!=idsSet.end();iter++)
615 if(idsSetMySupport.find(*iter)!=idsSetMySupport.end())
616 idsList.push_back(*iter);
617 int size=idsSet.size();
618 int sizeList = idsList.size();
620 MESSAGE(LOC << " size Set " << idsSet.size() << " size List " << idsList.size());
622 if(size!=0 && sizeList != 0)
624 if(_entity==MED_NODE)
625 fillFromNodeList(idsList);
627 fillFromElementList(idsList);
631 clearDataOnNumbers();
637 Method that cleans up all the fields related to _numbers. Defined for code factorization.
639 //--------------------------------------------------
640 void MEDMEM::SUPPORT::clearDataOnNumbers()
641 //--------------------------------------------------
643 _numberOfGeometricType=0;
644 _totalNumberOfElements=0;
649 _number=(MEDSKYLINEARRAY *) NULL;
654 operator == This operator does not compare attributs _name and _description.
656 //--------------------------------------------------
657 bool MEDMEM::SUPPORT::operator == (const SUPPORT &support) const
658 //--------------------------------------------------
660 const char * LOC = "bool SUPPORT::operator ==(const SUPPORT &support) const : ";
664 bool operatorReturn = false;
666 operatorReturn = (*_mesh == *support._mesh) && (_entity == support._entity) &&
667 (_numberOfGeometricType == support._numberOfGeometricType) &&
668 ((_isOnAllElts && support._isOnAllElts) || (!_isOnAllElts && !support._isOnAllElts)) &&
669 (_totalNumberOfElements == support._totalNumberOfElements);
675 for (int i=0; i<_numberOfGeometricType; i++)
677 operatorReturn = operatorReturn &&
678 (_geometricType[i] == support._geometricType[i]) &&
679 (_numberOfElements[i] == support._numberOfElements[i]);
683 for (int j=0; j<_numberOfElements[i]; j++)
685 operatorReturn = operatorReturn &&
686 (getNumber(_geometricType[i])[j] ==
687 support.getNumber(_geometricType[i])[j]);
696 return operatorReturn;
699 void SUPPORT::changeElementsNbs(MED_EN::medEntityMesh entity, const int *renumberingFromOldToNew, int limitNbClassicPoly, const int *renumberingFromOldToNewPoly)
701 if(entity != _entity)
702 throw MEDEXCEPTION("SUPPORT::changeElementsNbs : Renumbering on a mismatch entity");
706 const int *oldNbs=_number->getValue();
707 for(int i=0;i<_totalNumberOfElements;i++)
709 int globNb=oldNbs[i];
710 if(globNb<=limitNbClassicPoly)
711 newNbs.push_back(renumberingFromOldToNew[globNb-1]);
713 newNbs.push_back(renumberingFromOldToNewPoly[globNb-limitNbClassicPoly-1]);
716 fillFromElementList(newNbs);
723 operator == + in case false a test if coordinates and connectivity of _mesh and support->_mesh are the same
725 bool MEDMEM::SUPPORT::deepCompare(const SUPPORT &support) const
727 bool operatorReturn =(_entity == support._entity) &&
728 (_numberOfGeometricType == support._numberOfGeometricType) &&
729 ( (_isOnAllElts && support._isOnAllElts) || (!_isOnAllElts && !support._isOnAllElts) ) &&
730 (_totalNumberOfElements == support._totalNumberOfElements);
735 for (int i=0; i<_numberOfGeometricType && operatorReturn; i++)
737 operatorReturn = (_geometricType[i] == support._geometricType[i]) &&
738 (_numberOfElements[i] == support._numberOfElements[i]);
741 for (int j=0; j<_numberOfElements[i]; j++)
743 operatorReturn = (getNumber(_geometricType[i])[j] ==
744 support.getNumber(_geometricType[i])[j]);
752 if(!(*_mesh == *support._mesh))
754 return _mesh->deepCompare(*support._mesh);
757 return operatorReturn;
761 States if this is included in other.
763 bool MEDMEM::SUPPORT::belongsTo(const SUPPORT& other, bool deepCompare) const
765 if(!(*_mesh == *other._mesh))
769 if(!_mesh->deepCompare(*other._mesh))
772 if(_entity!=other._entity)
774 if(other._isOnAllElts)
776 if(_isOnAllElts && !other._isOnAllElts)
778 if(_numberOfGeometricType>other._numberOfGeometricType)
780 for(int i=0; i<_numberOfGeometricType; i++)
782 MED_EN::medGeometryElement curGeomType=_geometricType[i];
784 for(int j=0; j<other._numberOfGeometricType; j++)
785 if(other._geometricType[j]==curGeomType)
789 if(_numberOfElements[i]>other._numberOfElements[iOther])
791 const int *numbers1=_number->getI(i+1);
792 const int *numbers2=other._number->getI(iOther+1);
793 for (int k=0; k<_numberOfElements[i]; k++)
796 for(int l=0;l<other._numberOfElements[iOther] && !found;l++)
798 if(numbers1[k]==numbers2[l])
808 Method used to sort array of id.
810 int compareId(const void *x, const void *y)
812 const int *x1=(const int *)x;
813 const int *y1=(const int *)y;
823 performs a common operation : Sub builds a sorted int array that is obtained by supression of all ids contained
824 in array defined by (idsToSuppress,lgthIdsToSuppress) from array [start ... end]
825 Example sub(0,7,{1,2,5},3) => {0,3,4,6,7} - WARNING returned list should be deallocated !
827 list<int> *MEDMEM::SUPPORT::sub(int start,int end,const int *idsToSuppress,int lgthIdsToSuppress)
829 int size=end-start+1;
830 int sizeRet=size-lgthIdsToSuppress;
833 throw MEDEXCEPTION("MEDMEM::SUPPORT::sub");
841 for(int l=0;l<size;l++)
842 ret->push_back(start+l);
846 int *temp=new int[lgthIdsToSuppress];
847 memcpy(temp,idsToSuppress,sizeof(int)*lgthIdsToSuppress);
848 qsort(temp,lgthIdsToSuppress,sizeof(int),compareId);
850 for(int i=start;i<=end;i++)
860 performs a common operation : Sub builds a sorted int array that is obtained by supression of all ids contained
861 in array defined by (idsToSuppress,lgthIdsToSuppress) from array [start ... end]
862 Example sub({1,3,4,5,6,7,9},7,{1,2,5},3) => {3,4,6,7,9} - WARNING returned list should be deallocated !
864 list<int> *MEDMEM::SUPPORT::sub(const int *ids,int lgthIds,const int *idsToSuppress,int lgthIdsToSuppress)
869 throw MEDEXCEPTION("MEDMEM::SUPPORT::sub");
873 int *temp1=new int[lgthIds];
874 memcpy(temp1,ids,sizeof(int)*lgthIds);
875 qsort(temp1,lgthIds,sizeof(int),compareId);
876 int *temp2=new int[lgthIdsToSuppress];
877 memcpy(temp2,idsToSuppress,sizeof(int)*lgthIdsToSuppress);
878 qsort(temp2,lgthIdsToSuppress,sizeof(int),compareId);
881 if(j>=lgthIdsToSuppress)
882 ret->push_back(temp1[i++]);
883 else if(temp1[i]>temp2[j])
885 else if(temp1[i]<temp2[j])
886 ret->push_back(temp1[i++]);
896 returns a new SUPPORT (responsability to caller to destroy it)
897 that is the complement to "this", lying on the same entity than "this".
899 SUPPORT *MEDMEM::SUPPORT::getComplement() const
902 const int nbOfElt=_mesh->getNumberOfElements(_entity,MED_EN::MED_ALL_ELEMENTS);
903 int nbOfEltInSupp=getNumberOfElements(MED_EN::MED_ALL_ELEMENTS);
904 if(_isOnAllElts || nbOfElt==nbOfEltInSupp)
908 ret->setEntity(_entity);
909 string name="Complement of ";
914 const int *nbs=_number->getValue();
915 list<int> *ids=sub(1,nbOfElt,nbs,nbOfEltInSupp);
916 if(_entity==MED_EN::MED_NODE)
917 ret=_mesh->buildSupportOnNodeFromElementList(*ids,_entity);
919 ret=_mesh->buildSupportOnElementsFromElementList(*ids,_entity);
925 returns a new support the user should delete.
927 SUPPORT *MEDMEM::SUPPORT::substract(const SUPPORT& other) const throw (MEDEXCEPTION)
929 const char * LOC = "SUPPORT *MEDMEM::subtract(const SUPPORT * other) : ";
932 if (_entity!=other.getEntity())
933 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !"));
934 if(!(*_mesh == *other.getMesh()))
935 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh are different !"));
936 if(other._isOnAllElts)
940 ret->setEntity(_entity);
944 return other.getComplement();
945 int nbOfEltInThis=getNumberOfElements(MED_EN::MED_ALL_ELEMENTS);
946 const int *nbsThis=_number->getValue();
947 int nbOfEltInOther=other.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS);
948 const int *nbsOther=other._number->getValue();
949 list<int> *ids=sub(nbsThis,nbOfEltInThis,nbsOther,nbOfEltInOther);
950 if(_entity==MED_EN::MED_NODE)
951 ret=_mesh->buildSupportOnNodeFromElementList(*ids,_entity);
953 ret=_mesh->buildSupportOnElementsFromElementList(*ids,_entity);
960 returns a new support the user has to delete. Entity is either MED_NODE to obtain node elements lying on boundary of "this"
961 or MED_FACE,MED_EDGE (depends on the this->_mesh dimension).
963 SUPPORT *MEDMEM::SUPPORT::getBoundaryElements(MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION)
965 const char * LOC = "SUPPORT *MEDMEM::SUPPORT::getBoundaryElements(MED_EN::medEntityMesh Entity) : ";
967 int spaceDimension=_mesh->getSpaceDimension();
968 MED_EN::medEntityMesh baseEntity=Entity;
969 if (spaceDimension == 3)
970 if (Entity!=MED_FACE)
974 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 3D mesh for entity "<<Entity<<" !"));
975 if (spaceDimension == 2)
976 if (Entity!=MED_EDGE)
980 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 2D mesh for entity "<<Entity<<" !"));
982 return _mesh->getBoundaryElements(Entity);
984 const int * myConnectivityValue=_mesh->getReverseConnectivity(MED_DESCENDING);
985 const int * myConnectivityIndex=_mesh->getReverseConnectivityIndex(MED_DESCENDING);
986 int numberOf=_mesh->getNumberOfElements(baseEntity,MED_ALL_ELEMENTS);
987 const int *ids=_number->getValue();
988 set<int> idsSet(ids,ids+_totalNumberOfElements);
989 list<int> myElementsList;
990 for (int i=0;i<numberOf;i++)
992 int nbOfDP1EntitySharing=0;
993 if(idsSet.find(myConnectivityValue[myConnectivityIndex[i]-1])!=idsSet.end())
994 nbOfDP1EntitySharing++;
995 if(idsSet.find(myConnectivityValue[myConnectivityIndex[i]])!=idsSet.end())
996 nbOfDP1EntitySharing++;
997 if(nbOfDP1EntitySharing==1)
998 myElementsList.push_back(i+1);
1000 if(Entity==MED_NODE)
1002 return _mesh->buildSupportOnNodeFromElementList(myElementsList,baseEntity);
1006 return _mesh->buildSupportOnElementsFromElementList(myElementsList,baseEntity);
1011 Method that fills this and updates all its attributes in order to lye on the the listOfNode.
1013 void MEDMEM::SUPPORT::fillFromNodeList(const list<int>& listOfNode) throw (MEDEXCEPTION)
1015 setEntity(MED_EN::MED_NODE);
1016 clearDataOnNumbers();
1017 int size=listOfNode.size();
1018 int totalNbInMesh=_mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS);
1019 if(totalNbInMesh==size)
1027 int numberOfGeometricType=1;
1028 medGeometryElement* geometricType=new medGeometryElement[1];
1029 geometricType[0]=MED_NONE;
1030 int *numberOfElements=new int[1];
1031 numberOfElements[0]=size;
1032 int *mySkyLineArrayIndex=new int[2];
1033 mySkyLineArrayIndex[0]=1;
1034 mySkyLineArrayIndex[1]=1+numberOfElements[0];
1035 int *tab=new int[numberOfElements[0]];
1037 for(list<int>::const_iterator iter2=listOfNode.begin();iter2!=listOfNode.end();iter2++)
1039 MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(1,numberOfElements[0],mySkyLineArrayIndex,tab,true);
1040 setNumberOfGeometricType(numberOfGeometricType);
1041 setGeometricType(geometricType);
1042 setNumberOfElements(numberOfElements);
1043 setTotalNumberOfElements(numberOfElements[0]);
1044 setNumber(mySkyLineArray);
1046 delete[] numberOfElements;
1047 delete[] geometricType;
1051 Method created to factorize code. This method fills the current SUPPORT on entity 'entity' containing all the entities contained in
1052 elements 'listOfElt' of entity 'entity'. Warning this method should be called after both the attributes this->_mesh and this->_entity are correctly set.
1054 void MEDMEM::SUPPORT::fillFromElementList(const list<int>& listOfElt) throw (MEDEXCEPTION)
1056 clearDataOnNumbers();
1057 int size=listOfElt.size();
1058 int totalNbInMesh=_mesh->getNumberOfElementsWithPoly(_entity,MED_ALL_ELEMENTS);
1059 if(totalNbInMesh==size){
1066 // Well, we must know how many geometric type we have found
1067 int * myListArray = new int[size] ;
1069 list<int>::const_iterator myElementsListIt ;
1070 for (myElementsListIt=listOfElt.begin();myElementsListIt!=listOfElt.end();myElementsListIt++)
1071 myListArray[id++]=(*myElementsListIt) ;
1072 int numberOfGeometricType ;
1073 medGeometryElement* geometricType ;
1074 int * numberOfElements ;
1075 int * mySkyLineArrayIndex ;
1077 int numberOfType = _mesh->getNumberOfTypesWithPoly(_entity) ;
1078 if (numberOfType == 1) {
1079 numberOfGeometricType = 1 ;
1080 geometricType = new medGeometryElement[1] ;
1081 medGeometryElement * allType = _mesh->getTypesWithPoly(_entity);
1082 geometricType[0] = allType[0] ;
1083 numberOfElements = new int[1] ;
1084 numberOfElements[0] = size ;
1085 mySkyLineArrayIndex = new int[2] ;
1086 mySkyLineArrayIndex[0]=1 ;
1087 mySkyLineArrayIndex[1]=1+size ;
1091 map<medGeometryElement,int> theType ;
1092 for (myElementsListIt=listOfElt.begin();myElementsListIt!=listOfElt.end();myElementsListIt++) {
1093 medGeometryElement myType = _mesh->getElementTypeWithPoly(_entity,*myElementsListIt) ;
1094 if (theType.find(myType) != theType.end() )
1095 theType[myType]+=1 ;
1099 numberOfGeometricType = theType.size() ;
1100 geometricType = new medGeometryElement[numberOfGeometricType] ;
1101 numberOfElements = new int[numberOfGeometricType] ;
1102 mySkyLineArrayIndex = new int[numberOfGeometricType+1] ;
1104 mySkyLineArrayIndex[0]=1 ;
1105 map<medGeometryElement,int>::iterator theTypeIt ;
1106 for (theTypeIt=theType.begin();theTypeIt!=theType.end();theTypeIt++) {
1107 geometricType[index] = (*theTypeIt).first ;
1108 numberOfElements[index] = (*theTypeIt).second ;
1109 mySkyLineArrayIndex[index+1]=mySkyLineArrayIndex[index]+numberOfElements[index] ;
1113 MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray,true) ;
1114 setNumberOfGeometricType(numberOfGeometricType) ;
1115 setGeometricType(geometricType) ;
1116 setNumberOfElements(numberOfElements) ;
1117 setTotalNumberOfElements(size) ;
1118 setNumber(mySkyLineArray) ;
1120 delete[] numberOfElements;
1121 delete[] geometricType;
1124 /*! set the reference _mesh to Mesh */
1125 //--------------------------------------
1126 void SUPPORT::setMesh(MESH *Mesh) const
1127 //--------------------------------------
1130 _mesh->removeReference();
1134 _mesh->addReference();
1137 /*! returns the mesh name */
1138 //------------------------------------
1139 string SUPPORT::getMeshName() const
1140 //------------------------------------
1143 return _mesh->getName();
1149 addReference : reference counter presently disconnected in C++ -> just connected for client.
1151 void MEDMEM::SUPPORT::addReference() const
1156 removeReference : reference counter presently disconnected in C++ -> just connected for client.
1158 void MEDMEM::SUPPORT::removeReference() const