1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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;
100 _profilNames=m._profilNames;
105 Affectation operator. operator = perform et deep copy except for attribute _mesh
107 //--------------------------------------------------------------------------
108 SUPPORT & SUPPORT::operator=(const SUPPORT & m)
109 //--------------------------------------------------------------------------
111 const char * LOC = "SUPPORT::operator=(const SUPPORT & m) : " ;
114 if ( this == &m ) return *this;
117 _description = m._description;
118 _mesh = m._mesh ; // on recopie uniquement l'adresse
120 _numberOfGeometricType = m._numberOfGeometricType;
121 if (m._geometricType)
122 _geometricType.set(_numberOfGeometricType,m._geometricType);
123 _isOnAllElts = m._isOnAllElts;
124 if (m._numberOfElements)
125 _numberOfElements.set(_numberOfGeometricType,m._numberOfElements);
126 _totalNumberOfElements = m._totalNumberOfElements;
127 if (m._isOnAllElts == false) {
128 if (_number) delete _number;
129 if ( m._number ) // m may be not filled SUPPORTClient
130 _number = new MEDSKYLINEARRAY(* m._number);
132 _number = (MEDSKYLINEARRAY *) NULL;
134 _number = (MEDSKYLINEARRAY *) NULL;
135 _profilNames=m._profilNames;
148 MESSAGE("Destructeur ~SUPPORT()");
149 clearDataOnNumbers();
155 //--------------------------------------------------
156 ostream & MEDMEM::operator<<(ostream &os, const SUPPORT &my)
157 //--------------------------------------------------
159 os << "Name : "<< my.getName() << endl ;
160 os << "Description : "<< my.getDescription() << endl ;
162 if (my.getMesh() == NULL)
163 os << " Mesh not defined." << endl ;
165 os << " Mesh defined." << endl;
167 os << my.getMeshName() << endl ;
168 os << "Entity : "<<MED_EN::entNames[my._entity] << endl;
169 os << "Entity list : "<< endl;
170 if ( my._isOnAllElts )
171 os << "Is on all entities."<< endl;
173 os << "Is not on all entities. "<< endl;
174 if ( my._number ) // m may be not filled SUPPORTClient
175 os << *my.getNumber(MED_ALL_ELEMENTS);
177 int numberoftypes = my._numberOfGeometricType ;
178 os << "NumberOfTypes : "<<numberoftypes<<endl;
179 PointerOf<medGeometryElement> types = my._geometricType;
180 for (int j=0;j<numberoftypes;j++) {
181 int numberOfElements = my._numberOfElements[j];
182 os << " On Type "<<MED_EN::geoNames[types[j]]
183 <<" : there is(are) "<<numberOfElements<<" element(s) and " <<endl;
189 Updade the SUPPORT attributs with rigth MESH information.
191 It has an effect only if SUPPORT is on all elements.
193 No more need in future release.
195 //-------------------
196 void SUPPORT::update()
197 //-------------------
199 const char * LOC = "SUPPORT::update() : " ;
204 if (_entity == MED_NODE)
206 _numberOfGeometricType=1 ;
207 _geometricType.set(1);
208 _geometricType[0]=MED_POINT1;
209 _numberOfElements.set(1);
210 _numberOfElements[0]=_mesh->getNumberOfNodes(); // Vérifier le pointeur !
211 _totalNumberOfElements=_numberOfElements[0];
214 { // we duplicate information from _mesh
\ 1
215 _numberOfGeometricType=_mesh->getNumberOfTypesWithPoly(_entity);
216 SCRUTE(_numberOfGeometricType);
217 medGeometryElement * allType = _mesh->getTypesWithPoly(_entity);
218 _geometricType.set(_numberOfGeometricType,allType );
219 _numberOfElements.set(_numberOfGeometricType);
220 _totalNumberOfElements=0;
221 for (int i=0;i<_numberOfGeometricType;i++)
223 _numberOfElements[i]=_mesh->getNumberOfElementsWithPoly(_entity,_geometricType[i]) ;
224 _totalNumberOfElements+=_numberOfElements[i];
230 SCRUTE(_numberOfGeometricType);
235 Get the field value index (in fortran mode) from the support global number.
236 Becareful, it doesn't take care of the field number of components
238 //-------------------
239 int SUPPORT::getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION)
240 //-------------------
242 const char * LOC="getValIndFromGlobalNumber(const int number) : ";
245 if (_isOnAllElts) return number;
247 int nbOfEltsThis = getNumberOfElements(MED_ALL_ELEMENTS);
249 const int *eltsThis = _number->getValue();
254 for(iThis=0;iThis<nbOfEltsThis && !found;)
255 if(eltsThis[iThis]==number)
258 int valInd = iThis+1;
265 cout << "----Contenu du skyline : ---------------------" << *_number << endl;
268 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Can't find the global number |"
269 << number << "| in Support |"
270 << getName() << "|" ));
272 // It should never arrive here !!
279 Blend the given SUPPORT mySupport into the calling object SUPPORT.
281 //-------------------
282 void SUPPORT::blending(SUPPORT * mySupport) throw (MEDEXCEPTION)
283 //-------------------
285 const char * LOC="SUPPORT::blending(SUPPORT *) : ";
287 if (_entity!=mySupport->getEntity())
288 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !"));
289 if(!(*_mesh == *mySupport->getMesh()))
290 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh are different !"));
293 if(mySupport->isOnAllElements())
298 if(mySupport->_totalNumberOfElements==0)
300 const int *ids=getNumber(MED_ALL_ELEMENTS);
301 set<int> idsSet(ids,ids+getNumberOfElements(MED_ALL_ELEMENTS));
302 const int *idsMySupport=mySupport->getNumber(MED_ALL_ELEMENTS);
303 int mySupportSize=mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
304 set<int>::iterator iter;
305 for(int i=0;i<mySupportSize;i++)
306 idsSet.insert(idsMySupport[i]);
307 int size=idsSet.size();
312 for(iter=idsSet.begin();iter!=idsSet.end();iter++)
313 idsList.push_back(*iter);
315 MESSAGE(LOC << " size Set " << idsSet.size() << " size List " << idsList.size());
317 if(_entity==MED_NODE)
318 fillFromNodeList(idsList);
320 fillFromElementList(idsList);
323 clearDataOnNumbers();
328 This function allows the user to set a support not on all entities Entity,
329 it should be used after an initialisation with the constructor
330 SUPPORT(MESH* Mesh, string Name="", medEntityMesh Entity=MED_CELL) and
331 after the call to the function setAll(false).
332 It allocates and initialises all the attributs of the class SUPPORT.
335 //-------------------
336 void SUPPORT::setpartial(string Description, int NumberOfGeometricType,
337 int TotalNumberOfElements,
338 medGeometryElement *GeometricType,
339 int *NumberOfElements, int *NumberValue)
340 //-------------------
342 const char * LOC = "SUPPORT::setpartial(string , int , int , medGeometryElement * , int * , int *) : " ;
345 _isOnAllElts = false ;
347 _description=Description;
349 _numberOfGeometricType=NumberOfGeometricType;
350 _geometricType.set(NumberOfGeometricType);
351 _numberOfElements.set(NumberOfGeometricType);
352 _totalNumberOfElements = TotalNumberOfElements;
354 int * index = new int[_numberOfGeometricType+1];
357 for (int i=0;i<_numberOfGeometricType;i++) {
358 if(GeometricType[i]/100 != elemDim)
360 elemDim=GeometricType[i]/100;
362 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"unhomogeneous geometric types (dimension) !"));
363 _geometricType[i] = GeometricType[i] ;
364 _numberOfElements[i] = NumberOfElements[i] ;
365 index[i+1] = index[i]+NumberOfElements[i] ;
368 if (_number!=NULL) delete _number ;
369 _number = new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,NumberValue);
373 // PAL16854(Partial support on nodes):
374 // giving a default value to profile names
375 vector<string> prof_names( NumberOfGeometricType);
376 for (int itype=0; itype < NumberOfGeometricType; itype++)
378 ostringstream typestr;
379 typestr<<_name<<"_type"<<itype;
380 prof_names[itype]=typestr.str();
382 setProfilNames(prof_names);
389 This function allows the user to set a support not on all entities Entity,
390 it should be used after an initialisation of :
391 SUPPORT(MESH* Mesh, string Name="", medEntityMesh Entity=MED_CELL) and
392 after calling at least setGeometricType and perharps setEntity.
393 It allocates and initialises all the attributs of the class SUPPORT but
394 doesn't set a description, a SUPPORT name, a meshName and an associated MESH.
397 //-------------------
398 void SUPPORT::setpartial(MEDSKYLINEARRAY * number, bool shallowCopy) throw (MEDEXCEPTION)
399 //-------------------
401 const char * LOC = "SUPPORT::setpartial(MEDSKYLINEARRAY * number) : " ;
404 if ( ! _geometricType )
405 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT must contains"
406 << " a geometric type list" )) ;
408 _numberOfGeometricType = number->getNumberOf();
410 _numberOfElements.set(_numberOfGeometricType);
412 for (int i=0; i< _numberOfGeometricType; i++)
413 _numberOfElements[i] = number->getNumberOfI(i+1);
415 _totalNumberOfElements = number->getLength();
417 _isOnAllElts = false ;
419 if (_number!=NULL) delete _number ;
424 _number = new MEDSKYLINEARRAY(*number);
426 // cout << *_number << endl;
431 void SUPPORT::setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy) throw (MEDEXCEPTION)
432 //-------------------
434 const char * LOC = "SUPPORT::setpartial_fromfile(MEDSKYLINEARRAY * number) : " ;
438 _number_fromfile = number;
440 _number_fromfile = new MEDSKYLINEARRAY(*number);
445 void SUPPORT::setProfilNames(vector<string> profilNames) throw (MEDEXCEPTION){
447 const char * LOC = "SUPPORT::setProfilNames(vector<string> profilNames) : " ;
451 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT shouldn't be on all elements"
452 << " while setting profil name list" )) ;
454 if ( ! _geometricType || _numberOfGeometricType==0 )
455 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT must contains"
456 << " a least one geometric type" )) ;
459 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"SUPPORT must contains"
460 << " a profil number list before setting"
461 << " the associated profil name list" )) ;
463 if ( ( profilNames.size() != _number->getNumberOf() ) &&
464 ( profilNames.size() !=_numberOfGeometricType ) ) {
465 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The profil name list size : "<< profilNames.size()
466 << " must be equal to the number of geometric type : "
467 << _numberOfGeometricType << " (_number->getNumberOf() : "
468 << _number->getNumberOf() << " )"
473 _profilNames = profilNames;
479 vector<string> SUPPORT::getProfilNames() const throw (MEDEXCEPTION)
486 This method gets the boundary elements of the mesh. The support has to be
487 build using the constructor SUPPORT(MESH *,string, medEntityMesh) or
488 SUPPORT() followed by setMesh(MESH*) setName(string) and
489 setEntity(medEntityMesh) before using this method.
491 //-------------------
492 void SUPPORT::getBoundaryElements() throw (MEDEXCEPTION)
493 //-------------------
495 const char * LOC = "SUPPORT::getBoundaryElements() : " ;
498 if (_mesh == (MESH*)NULL) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"You shlould use the appropriate SUPPORT Constructor before calling this method"));
500 int spaceDimension = _mesh->getSpaceDimension();
502 if (spaceDimension == 3)
503 if (_entity != MED_FACE)
504 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 3D mesh for entity "<<_entity<<" !"));
505 if (spaceDimension == 2)
506 if (_entity != MED_EDGE)
507 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 2D mesh for entity "<<_entity<<" !"));
511 const int * myConnectivityValue = _mesh->getReverseConnectivity(MED_DESCENDING) ;
512 const int * myConnectivityIndex = _mesh->getReverseConnectivityIndex(MED_DESCENDING) ;
513 int numberOf = _mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS) ;
514 list<int> myElementsList ;
517 for (int i=0 ; i<numberOf; i++)
518 if (myConnectivityValue[myConnectivityIndex[i]] == 0) {
520 myElementsList.push_back(i+1) ;
524 // Well, we must know how many geometric type we have found
525 int * myListArray = new int[size] ;
527 list<int>::iterator myElementsListIt ;
528 for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
529 myListArray[id]=(*myElementsListIt) ;
531 SCRUTE(myListArray[id]);
535 int numberOfGeometricType ;
536 medGeometryElement* geometricType ;
537 int * geometricTypeNumber ;
538 int * numberOfElements ;
539 //MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY() ;
540 int * mySkyLineArrayIndex ;
542 int numberOfType = _mesh->getNumberOfTypes(_entity) ;
543 if (numberOfType == 1) { // wonderfull : it's easy !
544 numberOfGeometricType = 1 ;
545 geometricType = new medGeometryElement[1] ;
546 const medGeometryElement * allType = _mesh->getTypes(_entity);
547 geometricType[0] = allType[0] ;
548 geometricTypeNumber = new int[1] ; // not use, but initialized to nothing
549 geometricTypeNumber[0] = 0 ;
550 numberOfElements = new int[1] ;
551 numberOfElements[0] = size ;
552 mySkyLineArrayIndex = new int[2] ;
553 mySkyLineArrayIndex[0]=1 ;
554 mySkyLineArrayIndex[1]=1+size ;
557 map<medGeometryElement,int> theType ;
558 for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
559 medGeometryElement myType = _mesh->getElementType(_entity,*myElementsListIt) ;
560 if (theType.find(myType) != theType.end() )
565 numberOfGeometricType = theType.size() ;
566 geometricType = new medGeometryElement[numberOfGeometricType] ;
567 //const medGeometryElement * allType = _mesh->getTypes(_entity); !! UNUSED VARIABLE !!
568 geometricTypeNumber = new int[numberOfGeometricType] ; // not use, but initialized to nothing
569 numberOfElements = new int[numberOfGeometricType] ;
570 mySkyLineArrayIndex = new int[numberOfGeometricType+1] ;
572 mySkyLineArrayIndex[0]=1 ;
573 map<medGeometryElement,int>::iterator theTypeIt ;
574 for (theTypeIt=theType.begin();theTypeIt!=theType.end();theTypeIt++) {
575 geometricType[index] = (*theTypeIt).first ;
576 geometricTypeNumber[index] = 0 ;
577 numberOfElements[index] = (*theTypeIt).second ;
578 mySkyLineArrayIndex[index+1]=mySkyLineArrayIndex[index]+numberOfElements[index] ;
582 //mySkyLineArray->setMEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray) ;
583 MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray) ;
585 setNumberOfGeometricType(numberOfGeometricType) ;
586 // setGeometricType(geometricType) ;
587 for (int i=0;i<numberOfGeometricType;i++)
589 _geometricType[i] = geometricType[i];
592 setNumberOfElements(numberOfElements) ;
593 setTotalNumberOfElements(size) ;
594 // setNumber(mySkyLineArray) ;
596 _number = new MEDSKYLINEARRAY(numberOfGeometricType,size);
598 _number->setIndex(mySkyLineArrayIndex);
600 for (int i=0;i<size;i++)
602 _number->setIndexValue(i+1,myListArray[i]);
605 delete[] numberOfElements;
606 delete[] geometricTypeNumber;
607 delete[] geometricType;
608 delete[] mySkyLineArrayIndex;
609 delete[] myListArray;
610 delete mySkyLineArray;
616 intersect the given SUPPORT mySupport into the calling SUPPORT object.
618 //-------------------
619 void SUPPORT::intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION)
621 const char * LOC="SUPPORT::intersecting(SUPPORT *) : ";
623 if (_entity!=mySupport->getEntity())
624 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !"));
625 if(!(*_mesh == *mySupport->getMesh()))
626 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh are different !"));
627 if(mySupport->isOnAllElements())
634 if(_totalNumberOfElements==0)
636 const int *ids=getNumber(MED_ALL_ELEMENTS);
637 set<int> idsSet(ids,ids+getNumberOfElements(MED_ALL_ELEMENTS));
638 const int *idsMySupport=mySupport->getNumber(MED_ALL_ELEMENTS);
639 int mySupportSize=mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
640 set<int> idsSetMySupport(idsMySupport,idsMySupport+mySupportSize);
641 set<int>::iterator iter;
643 for(iter=idsSet.begin();iter!=idsSet.end();iter++)
644 if(idsSetMySupport.find(*iter)!=idsSetMySupport.end())
645 idsList.push_back(*iter);
646 int size=idsSet.size();
647 int sizeList = idsList.size();
649 MESSAGE(LOC << " size Set " << idsSet.size() << " size List " << idsList.size());
651 if(size!=0 && sizeList != 0)
653 if(_entity==MED_NODE)
654 fillFromNodeList(idsList);
656 fillFromElementList(idsList);
660 clearDataOnNumbers();
666 Method that cleans up all the fields related to _numbers. Defined for code factorization.
668 //--------------------------------------------------
669 void MEDMEM::SUPPORT::clearDataOnNumbers()
670 //--------------------------------------------------
672 _numberOfGeometricType=0;
673 _totalNumberOfElements=0;
678 _number=(MEDSKYLINEARRAY *) NULL;
683 operator == This operator does not compare attributs _name and _description.
685 //--------------------------------------------------
686 bool MEDMEM::SUPPORT::operator == (const SUPPORT &support) const
687 //--------------------------------------------------
689 const char * LOC = "bool SUPPORT::operator ==(const SUPPORT &support) const : ";
693 bool operatorReturn = false;
695 operatorReturn = (*_mesh == *support._mesh) && (_entity == support._entity) &&
696 (_numberOfGeometricType == support._numberOfGeometricType) &&
697 ((_isOnAllElts && support._isOnAllElts) || (!_isOnAllElts && !support._isOnAllElts)) &&
698 (_totalNumberOfElements == support._totalNumberOfElements);
704 for (int i=0; i<_numberOfGeometricType; i++)
706 operatorReturn = operatorReturn &&
707 (_geometricType[i] == support._geometricType[i]) &&
708 (_numberOfElements[i] == support._numberOfElements[i]);
712 for (int j=0; j<_numberOfElements[i]; j++)
714 operatorReturn = operatorReturn &&
715 (getNumber(_geometricType[i])[j] ==
716 support.getNumber(_geometricType[i])[j]);
725 return operatorReturn;
728 void SUPPORT::changeElementsNbs(MED_EN::medEntityMesh entity, const int *renumberingFromOldToNew, int limitNbClassicPoly, const int *renumberingFromOldToNewPoly)
730 if(entity != _entity)
731 throw MEDEXCEPTION("SUPPORT::changeElementsNbs : Renumbering on a mismatch entity");
735 const int *oldNbs=_number->getValue();
736 for(int i=0;i<_totalNumberOfElements;i++)
738 int globNb=oldNbs[i];
739 if(globNb<=limitNbClassicPoly)
740 newNbs.push_back(renumberingFromOldToNew[globNb-1]);
742 newNbs.push_back(renumberingFromOldToNewPoly[globNb-limitNbClassicPoly-1]);
745 fillFromElementList(newNbs);
752 operator == + in case false a test if coordinates and connectivity of _mesh and support->_mesh are the same
754 bool MEDMEM::SUPPORT::deepCompare(const SUPPORT &support) const
756 bool operatorReturn =(_entity == support._entity) &&
757 (_numberOfGeometricType == support._numberOfGeometricType) &&
758 ( (_isOnAllElts && support._isOnAllElts) || (!_isOnAllElts && !support._isOnAllElts) ) &&
759 (_totalNumberOfElements == support._totalNumberOfElements);
764 for (int i=0; i<_numberOfGeometricType && operatorReturn; i++)
766 operatorReturn = (_geometricType[i] == support._geometricType[i]) &&
767 (_numberOfElements[i] == support._numberOfElements[i]);
770 for (int j=0; j<_numberOfElements[i]; j++)
772 operatorReturn = (getNumber(_geometricType[i])[j] ==
773 support.getNumber(_geometricType[i])[j]);
781 if(!(*_mesh == *support._mesh))
783 return _mesh->deepCompare(*support._mesh);
786 return operatorReturn;
790 States if this is included in other.
792 bool MEDMEM::SUPPORT::belongsTo(const SUPPORT& other, bool deepCompare) const
794 if(!(*_mesh == *other._mesh))
798 if(!_mesh->deepCompare(*other._mesh))
801 if(_entity!=other._entity)
803 if(other._isOnAllElts)
805 if(_isOnAllElts && !other._isOnAllElts)
807 if(_numberOfGeometricType>other._numberOfGeometricType)
809 for(int i=0; i<_numberOfGeometricType; i++)
811 MED_EN::medGeometryElement curGeomType=_geometricType[i];
813 for(int j=0; j<other._numberOfGeometricType; j++)
814 if(other._geometricType[j]==curGeomType)
818 if(_numberOfElements[i]>other._numberOfElements[iOther])
820 const int *numbers1=_number->getI(i+1);
821 const int *numbers2=other._number->getI(iOther+1);
822 for (int k=0; k<_numberOfElements[i]; k++)
825 for(int l=0;l<other._numberOfElements[iOther] && !found;l++)
827 if(numbers1[k]==numbers2[l])
837 Method used to sort array of id.
839 int compareId(const void *x, const void *y)
841 const int *x1=(const int *)x;
842 const int *y1=(const int *)y;
852 performs a common operation : Sub builds a sorted int array that is obtained by supression of all ids contained
853 in array defined by (idsToSuppress,lgthIdsToSuppress) from array [start ... end]
854 Example sub(0,7,{1,2,5},3) => {0,3,4,6,7} - WARNING returned list should be deallocated !
856 list<int> *MEDMEM::SUPPORT::sub(int start,int end,const int *idsToSuppress,int lgthIdsToSuppress)
858 int size=end-start+1;
859 int sizeRet=size-lgthIdsToSuppress;
862 throw MEDEXCEPTION("MEDMEM::SUPPORT::sub");
870 for(int l=0;l<size;l++)
871 ret->push_back(start+l);
875 int *temp=new int[lgthIdsToSuppress];
876 memcpy(temp,idsToSuppress,sizeof(int)*lgthIdsToSuppress);
877 qsort(temp,lgthIdsToSuppress,sizeof(int),compareId);
879 for(int i=start;i<=end;i++)
889 performs a common operation : Sub builds a sorted int array that is obtained by supression of all ids contained
890 in array defined by (idsToSuppress,lgthIdsToSuppress) from array [start ... end]
891 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 !
893 list<int> *MEDMEM::SUPPORT::sub(const int *ids,int lgthIds,const int *idsToSuppress,int lgthIdsToSuppress)
898 throw MEDEXCEPTION("MEDMEM::SUPPORT::sub");
902 int *temp1=new int[lgthIds];
903 memcpy(temp1,ids,sizeof(int)*lgthIds);
904 qsort(temp1,lgthIds,sizeof(int),compareId);
905 int *temp2=new int[lgthIdsToSuppress];
906 memcpy(temp2,idsToSuppress,sizeof(int)*lgthIdsToSuppress);
907 qsort(temp2,lgthIdsToSuppress,sizeof(int),compareId);
910 if(j>=lgthIdsToSuppress)
911 ret->push_back(temp1[i++]);
912 else if(temp1[i]>temp2[j])
914 else if(temp1[i]<temp2[j])
915 ret->push_back(temp1[i++]);
925 returns a new SUPPORT (responsability to caller to destroy it)
926 that is the complement to "this", lying on the same entity than "this".
928 SUPPORT *MEDMEM::SUPPORT::getComplement() const
931 const int nbOfElt=_mesh->getNumberOfElements(_entity,MED_EN::MED_ALL_ELEMENTS);
932 int nbOfEltInSupp=getNumberOfElements(MED_EN::MED_ALL_ELEMENTS);
933 if(_isOnAllElts || nbOfElt==nbOfEltInSupp)
937 ret->setEntity(_entity);
938 string name="Complement of ";
943 const int *nbs=_number->getValue();
944 list<int> *ids=sub(1,nbOfElt,nbs,nbOfEltInSupp);
945 if(_entity==MED_EN::MED_NODE)
946 ret=_mesh->buildSupportOnNodeFromElementList(*ids,_entity);
948 ret=_mesh->buildSupportOnElementsFromElementList(*ids,_entity);
954 returns a new support the user should delete.
956 SUPPORT *MEDMEM::SUPPORT::substract(const SUPPORT& other) const throw (MEDEXCEPTION)
958 const char * LOC = "SUPPORT *MEDMEM::subtract(const SUPPORT * other) : ";
961 if (_entity!=other.getEntity())
962 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Entities are different !"));
963 if(!(*_mesh == *other.getMesh()))
964 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Mesh are different !"));
965 if(other._isOnAllElts)
969 ret->setEntity(_entity);
973 return other.getComplement();
974 int nbOfEltInThis=getNumberOfElements(MED_EN::MED_ALL_ELEMENTS);
975 const int *nbsThis=_number->getValue();
976 int nbOfEltInOther=other.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS);
977 const int *nbsOther=other._number->getValue();
978 list<int> *ids=sub(nbsThis,nbOfEltInThis,nbsOther,nbOfEltInOther);
979 if(_entity==MED_EN::MED_NODE)
980 ret=_mesh->buildSupportOnNodeFromElementList(*ids,_entity);
982 ret=_mesh->buildSupportOnElementsFromElementList(*ids,_entity);
989 returns a new support the user has to delete. Entity is either MED_NODE to obtain node elements lying on boundary of "this"
990 or MED_FACE,MED_EDGE (depends on the this->_mesh dimension).
992 SUPPORT *MEDMEM::SUPPORT::getBoundaryElements(MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION)
994 const char * LOC = "SUPPORT *MEDMEM::SUPPORT::getBoundaryElements(MED_EN::medEntityMesh Entity) : ";
996 int spaceDimension=_mesh->getSpaceDimension();
997 MED_EN::medEntityMesh baseEntity=Entity;
998 if (spaceDimension == 3)
999 if (Entity!=MED_FACE)
1000 if(Entity==MED_NODE)
1001 baseEntity=MED_FACE;
1003 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 3D mesh for entity "<<Entity<<" !"));
1004 if (spaceDimension == 2)
1005 if (Entity!=MED_EDGE)
1006 if(Entity==MED_NODE)
1007 baseEntity=MED_EDGE;
1009 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 2D mesh for entity "<<Entity<<" !"));
1011 return _mesh->getBoundaryElements(Entity);
1013 const int * myConnectivityValue=_mesh->getReverseConnectivity(MED_DESCENDING);
1014 const int * myConnectivityIndex=_mesh->getReverseConnectivityIndex(MED_DESCENDING);
1015 int numberOf=_mesh->getNumberOfElements(baseEntity,MED_ALL_ELEMENTS);
1016 const int *ids=_number->getValue();
1017 set<int> idsSet(ids,ids+_totalNumberOfElements);
1018 list<int> myElementsList;
1019 for (int i=0;i<numberOf;i++)
1021 int nbOfDP1EntitySharing=0;
1022 if(idsSet.find(myConnectivityValue[myConnectivityIndex[i]-1])!=idsSet.end())
1023 nbOfDP1EntitySharing++;
1024 if(idsSet.find(myConnectivityValue[myConnectivityIndex[i]])!=idsSet.end())
1025 nbOfDP1EntitySharing++;
1026 if(nbOfDP1EntitySharing==1)
1027 myElementsList.push_back(i+1);
1029 if(Entity==MED_NODE)
1031 return _mesh->buildSupportOnNodeFromElementList(myElementsList,baseEntity);
1035 return _mesh->buildSupportOnElementsFromElementList(myElementsList,baseEntity);
1040 Method that fills this and updates all its attributes in order to lye on the the listOfNode.
1042 void MEDMEM::SUPPORT::fillFromNodeList(const list<int>& listOfNode) throw (MEDEXCEPTION)
1044 setEntity(MED_EN::MED_NODE);
1045 clearDataOnNumbers();
1046 int size=listOfNode.size();
1047 int totalNbInMesh=_mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS);
1048 if(totalNbInMesh==size)
1056 int numberOfGeometricType=1;
1057 medGeometryElement* geometricType=new medGeometryElement[1];
1058 geometricType[0]=MED_NONE;
1059 int *numberOfElements=new int[1];
1060 numberOfElements[0]=size;
1061 int *mySkyLineArrayIndex=new int[2];
1062 mySkyLineArrayIndex[0]=1;
1063 mySkyLineArrayIndex[1]=1+numberOfElements[0];
1064 int *tab=new int[numberOfElements[0]];
1066 for(list<int>::const_iterator iter2=listOfNode.begin();iter2!=listOfNode.end();iter2++)
1068 MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(1,numberOfElements[0],mySkyLineArrayIndex,tab,true);
1069 setNumberOfGeometricType(numberOfGeometricType);
1070 setGeometricType(geometricType);
1071 setNumberOfElements(numberOfElements);
1072 setTotalNumberOfElements(numberOfElements[0]);
1073 setNumber(mySkyLineArray);
1075 delete[] numberOfElements;
1076 delete[] geometricType;
1080 Method created to factorize code. This method fills the current SUPPORT on entity 'entity' containing all the entities contained in
1081 elements 'listOfElt' of entity 'entity'. Warning this method should be called after both the attributes this->_mesh and this->_entity are correctly set.
1083 void MEDMEM::SUPPORT::fillFromElementList(const list<int>& listOfElt) throw (MEDEXCEPTION)
1085 clearDataOnNumbers();
1086 int size=listOfElt.size();
1087 int totalNbInMesh=_mesh->getNumberOfElementsWithPoly(_entity,MED_ALL_ELEMENTS);
1088 if(totalNbInMesh==size){
1095 // Well, we must know how many geometric type we have found
1096 int * myListArray = new int[size] ;
1098 list<int>::const_iterator myElementsListIt ;
1099 for (myElementsListIt=listOfElt.begin();myElementsListIt!=listOfElt.end();myElementsListIt++)
1100 myListArray[id++]=(*myElementsListIt) ;
1101 int numberOfGeometricType ;
1102 medGeometryElement* geometricType ;
1103 int * numberOfElements ;
1104 int * mySkyLineArrayIndex ;
1106 int numberOfType = _mesh->getNumberOfTypesWithPoly(_entity) ;
1107 if (numberOfType == 1) {
1108 numberOfGeometricType = 1 ;
1109 geometricType = new medGeometryElement[1] ;
1110 medGeometryElement * allType = _mesh->getTypesWithPoly(_entity);
1111 geometricType[0] = allType[0] ;
1112 numberOfElements = new int[1] ;
1113 numberOfElements[0] = size ;
1114 mySkyLineArrayIndex = new int[2] ;
1115 mySkyLineArrayIndex[0]=1 ;
1116 mySkyLineArrayIndex[1]=1+size ;
1120 map<medGeometryElement,int> theType ;
1121 for (myElementsListIt=listOfElt.begin();myElementsListIt!=listOfElt.end();myElementsListIt++) {
1122 medGeometryElement myType = _mesh->getElementTypeWithPoly(_entity,*myElementsListIt) ;
1123 if (theType.find(myType) != theType.end() )
1124 theType[myType]+=1 ;
1128 numberOfGeometricType = theType.size() ;
1129 geometricType = new medGeometryElement[numberOfGeometricType] ;
1130 numberOfElements = new int[numberOfGeometricType] ;
1131 mySkyLineArrayIndex = new int[numberOfGeometricType+1] ;
1133 mySkyLineArrayIndex[0]=1 ;
1134 map<medGeometryElement,int>::iterator theTypeIt ;
1135 for (theTypeIt=theType.begin();theTypeIt!=theType.end();theTypeIt++) {
1136 geometricType[index] = (*theTypeIt).first ;
1137 numberOfElements[index] = (*theTypeIt).second ;
1138 mySkyLineArrayIndex[index+1]=mySkyLineArrayIndex[index]+numberOfElements[index] ;
1142 MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray,true) ;
1143 setNumberOfGeometricType(numberOfGeometricType) ;
1144 setGeometricType(geometricType) ;
1145 setNumberOfElements(numberOfElements) ;
1146 setTotalNumberOfElements(size) ;
1147 setNumber(mySkyLineArray) ;
1149 delete[] numberOfElements;
1150 delete[] geometricType;
1153 /*! set the reference _mesh to Mesh */
1154 //--------------------------------------
1155 void SUPPORT::setMesh(MESH *Mesh) const
1156 //--------------------------------------
1159 _mesh->removeReference();
1163 _mesh->addReference();
1166 /*! returns the mesh name */
1167 //------------------------------------
1168 string SUPPORT::getMeshName() const
1169 //------------------------------------
1172 return _mesh->getName();
1178 addReference : reference counter presently disconnected in C++ -> just connected for client.
1180 void MEDMEM::SUPPORT::addReference() const
1185 removeReference : reference counter presently disconnected in C++ -> just connected for client.
1187 void MEDMEM::SUPPORT::removeReference() const