1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
37 #include "MEDMEM_Utilities.hxx"
38 #include "MEDMEM_STRING.hxx"
39 #include "MEDMEM_Exception.hxx"
40 #include "MEDMEM_define.hxx"
41 #include "MEDMEM_SkyLineArray.hxx"
42 #include "MEDMEM_RCBase.hxx"
51 This class describe a support of elements on an entity of the mesh.
53 It contains the list of meshes elements for an entity (MED_NODE,
54 MED_CELL, MED_FACE or MED_EDGE).
57 class MEDMEM_EXPORT SUPPORT : public RCBASE
69 Name of the associated mesh if the _mesh pointer
73 mutable string _meshName;
77 Description of the support (optional).
84 Reference to the mesh on which the support is defined.
91 Type of entity on which the support is defined
92 (only one for each support).
95 MED_EN::medEntityMesh _entity ;
99 Number of geometric type defined in the support.
102 int _numberOfGeometricType;
106 Array of all geometric type defined in the support.
109 PointerOf<MED_EN::medGeometryElement> _geometricType;
113 If true, we consider all entities of type _entity
114 defined in the associated mesh
121 Index array of size _numberOfGeometricType wich contains
122 for each geometric type, the number of elements of this type.
125 PointerOf<int> _numberOfElements;
129 Sum of each _numberOfElements component.
132 int _totalNumberOfElements;
134 // the two following arrays are defined only if _isOnAllElts is false :
138 Array of size _index[_numberOfType]-1 wich contain number of
139 entities of each geometric type. We use global numbering.\n
140 Defined only if _isOnAllElts is false.
143 mutable MEDSKYLINEARRAY * _number;
147 Array of size _index[_numberOfType]-1 wich contain number of
148 entities of each geometric type. We use file numbering.\n
149 Defined only if _isOnAllElts is false.
152 mutable MEDSKYLINEARRAY * _number_fromfile;
156 Array of size <_numberOfGeometricType> wich contain the profil name of
157 entities of each geometric type.\n
158 Defined only if _isOnAllElts is false.
159 If it exist an entities list on a geometric type in _number but there is no profil name associated
160 ( MED_NOPFL ) the MED driver will consider and verify this entities list as being all the
161 entities available on the associated mesh for this geometric type.
165 vector< string > _profilNames;
170 SUPPORT(MESH* Mesh, string Name="", MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
171 SUPPORT(const SUPPORT & m);
173 friend MEDMEM_EXPORT ostream & operator<<(ostream &os,const SUPPORT &my);
175 SUPPORT& operator=(const SUPPORT &support);
176 bool operator == (const SUPPORT &support) const;
177 bool deepCompare(const SUPPORT &support) const;
180 inline void setName(string Name);
181 inline void setDescription(string Description);
182 void setMesh(MESH *Mesh) const;
183 void setMeshDirectly(MESH *Mesh) const { _mesh=Mesh; }
184 inline void setMeshName(const string & meshName);
185 inline void setAll(bool All);
186 inline void setEntity(MED_EN::medEntityMesh Entity);
187 inline void setNumberOfGeometricType(int NumberOfGeometricType);
188 inline void setGeometricType(const MED_EN::medGeometryElement *GeometricType);
189 inline void setNumberOfElements(const int *NumberOfElements);
190 //inline void setTotalNumberOfElements(int TotalNumberOfElements);
191 inline void setNumber(MEDSKYLINEARRAY * Number);
192 inline void setNumber(const int * index, const int* value, bool shallowCopy=false);
194 inline string getName() const;
195 inline string getDescription() const;
196 virtual inline MESH * getMesh() const;
197 string getMeshName() const;
198 inline MED_EN::medEntityMesh getEntity() const;
200 inline bool isOnAllElements() const;
201 inline int getNumberOfTypes() const;
202 inline const MED_EN::medGeometryElement* getTypes() const ;
203 inline int getNumberOfElements(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
204 inline const int * getNumberOfElements() const throw (MEDEXCEPTION);
205 virtual inline MEDSKYLINEARRAY * getnumber() const throw (MEDEXCEPTION);
206 virtual inline MEDSKYLINEARRAY * getnumberFromFile() const throw (MEDEXCEPTION);
207 virtual inline const int * getNumber(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
208 virtual inline const int * getNumberFromFile(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
209 virtual inline const int * getNumberIndex() const throw (MEDEXCEPTION);
210 virtual int getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION);
212 void blending(SUPPORT * mySupport) throw (MEDEXCEPTION) ;
214 // Les numéros d'entités dans les profils doivent être croissant
215 // pour respecter la norme MED
216 void setpartial(string Description, int NumberOfGeometricType,
217 int TotalNumberOfEntity, MED_EN::medGeometryElement *GeometricType,
218 int *NumberOfEntity, int *NumberValue);
220 void setpartial(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
223 void setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
225 // Si les noms de profils ne sont pas positionnés, les profils ne seront
226 // pas écrits par MEDFICHIER.
227 void setProfilNames(vector<string> profilNames) throw (MEDEXCEPTION);
228 //string getProfilName(const MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
229 vector<string> getProfilNames() const throw (MEDEXCEPTION);
231 void getBoundaryElements() throw (MEDEXCEPTION);
232 void changeElementsNbs(MED_EN::medEntityMesh entity, const int *renumberingFromOldToNew, int limitNbClassicPoly, const int *renumberingFromOldToNewPoly=0);
233 void intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION) ;
234 bool belongsTo(const SUPPORT& other, bool deepCompare=false) const;
235 SUPPORT *getComplement() const;
236 SUPPORT *substract(const SUPPORT& other) const throw (MEDEXCEPTION) ;
237 SUPPORT *getBoundaryElements(MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION);
238 void fillFromNodeList(const list<int>& listOfNode) throw (MEDEXCEPTION);
239 void fillFromElementList(const list<int>& listOfElt) throw (MEDEXCEPTION);
240 void clearDataOnNumbers();
241 //A.G. Addings for RC
242 virtual void addReference() const;
243 virtual void removeReference() const;
245 static list<int> *sub(int start,int end,const int *idsToSuppress,int lgthIdsToSuppress);
246 static list<int> *sub(const int *ids,int lgthIds,const int *idsToSuppress,int lgthIdsToSuppress);
249 // _____________________
251 // _____________________
254 \addtogroup SUPPORT_query
260 This method returns the number of all elements of the type GeometricType.
262 If isOnAllElements is false, it returns the number of elements in the
263 support otherwise it returns number of elements in the mesh.
265 Example : number of MED_TRIA3 or MED_ALL_ELEMENTS elements
268 Note : If SUPPORT is defined on MED_NODE, use MED_ALL_ELEMENTS as
269 medGeometryElement GeometricType and it will return the number
270 of nodes in the support (or in the mesh).
272 //-----------------------------------------------------------------------------
273 inline int SUPPORT::getNumberOfElements(MED_EN::medGeometryElement GeometricType) const
275 //-----------------------------------------------------------------------------
277 if (GeometricType==MED_EN::MED_ALL_ELEMENTS)
278 return _totalNumberOfElements;
279 for (int i=0;i<_numberOfGeometricType;i++)
280 if (_geometricType[i]==GeometricType)
281 return _numberOfElements[i];
282 throw MEDEXCEPTION("Support::getNumberOfElements : Geometric type not found !") ;
285 /*! Returns the total number of elements in the support. */
286 //-----------------------------------------------------------------------------
287 inline const int * SUPPORT::getNumberOfElements() const throw (MEDEXCEPTION) {
288 //-----------------------------------------------------------------------------
289 return _numberOfElements;
292 //---------------------------------------------------------------------
293 inline MEDSKYLINEARRAY * SUPPORT::getnumber() const
295 //---------------------------------------------------------------------
298 throw MEDEXCEPTION("Support::getnumber : Not defined !") ;
302 //---------------------------------------------------------------------
303 inline MEDSKYLINEARRAY * SUPPORT::getnumberFromFile() const
305 //---------------------------------------------------------------------
307 if (_number_fromfile==NULL)
308 throw MEDEXCEPTION("Support::getnumberFromFile : Not defined !") ;
309 return _number_fromfile ;
313 If isOnAllElements is false, returns an array which contains
314 all number of given medGeometryElement.
316 Numbering is global, ie numbers are bounded by 1 and
317 MESH::getNumberOfElement(entity,MED_ALL_ELEMENTS) and not by 1 and
318 MESH::getNumberOfElement(entity,geomElement).
320 Note : If SUPPORT is defined on MED_NODE, use MED_NONE
321 medGeometryElement type.
323 //---------------------------------------------------------------------
324 inline const int * SUPPORT::getNumber(MED_EN::medGeometryElement GeometricType) const
326 //---------------------------------------------------------------------
328 const char * LOC = "Support::getNumber : " ;
330 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined, support is on all entity !")) ;
331 if (GeometricType==MED_EN::MED_ALL_ELEMENTS)
332 return _number->getValue() ;
333 for (int i=0;i<_numberOfGeometricType;i++)
334 if (_geometricType[i]==GeometricType)
335 return _number->getI(i+1) ;
336 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"GeometricType not found !")) ;
339 //---------------------------------------------------------------------
340 inline const int * SUPPORT::getNumberFromFile(MED_EN::medGeometryElement GeometricType) const
342 //---------------------------------------------------------------------
344 const char * LOC = "Support::getNumberFromFile : " ;
346 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined, support is on all entity !")) ;
347 if (GeometricType==MED_EN::MED_ALL_ELEMENTS)
348 return _number_fromfile->getValue() ;
349 for (int i=0;i<_numberOfGeometricType;i++)
350 if (_geometricType[i]==GeometricType)
351 return _number_fromfile->getI(i+1) ;
352 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"GeometricType not found !")) ;
356 If isOnAllElements is false, returns index of element number.
357 Use it with getNumber(MED_ALL_ELEMENTS).
359 Note : See getConnectivityIndex for details.
361 //-------------------------------------------
362 inline const int * SUPPORT::getNumberIndex() const
363 //-------------------------------------------
367 throw MEDEXCEPTION("Support::getNumberIndex : Not defined, support is on all entity !") ;
368 return _number->getIndex() ;
374 /*! set the attribute _name to Name */
375 //--------------------------------------
376 inline void SUPPORT::setName(string Name)
377 //--------------------------------------
382 /*! set the attribute _description to Description */
383 //--------------------------------------------------
384 inline void SUPPORT::setDescription(string Description)
385 //--------------------------------------------------
387 _description=Description;
391 /*! set the meshName if there is ni reference _mesh to Mesh */
392 //--------------------------------------
393 inline void SUPPORT::setMeshName(const string & meshName)
394 //--------------------------------------
396 const char * LOC = "SUPPORT::setMeshName(const string & meshName) : ";
399 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Setting meshName is not possible when an associated mesh is set !")) ;
405 \addtogroup SUPPORT_creation
410 /*! Creates a support on all elements of the type specified in the constructor.
412 Even if _isonAllElts is true, geometric types defining the FIELD's SUPPORT
413 must be read from the SUPPORT not from the associated MESH (the geometric
414 types defining the FIELD's SUPPORT may be a subset of the geometric types
415 defined in the MESH even if for each SUPPORT geometric type all MESH entities
418 //------------------------------------------
419 inline void SUPPORT::setAll(bool All)
420 //------------------------------------------
424 /*! \if MEDMEM_ug @} \endif */
426 /*! set the attribute _entity to Entity */
427 //------------------------------------------
428 inline void SUPPORT::setEntity(MED_EN::medEntityMesh Entity)
433 /*! set the attribute _numberOfGeometricType to NumberOfGeometricType */
434 //---------------------------------------------------------------------
435 inline void SUPPORT::setNumberOfGeometricType(int NumberOfGeometricType)
436 //---------------------------------------------------------------------
438 _numberOfGeometricType=NumberOfGeometricType;
440 _geometricType.set(0);
441 _numberOfElements.set(0);
444 /*! set the attribute _geometricType to geometricType */
445 //---------------------------------------------------------------------
446 inline void SUPPORT::setGeometricType(const MED_EN::medGeometryElement *GeometricType)
447 //---------------------------------------------------------------------
450 _geometricType.set(_numberOfGeometricType);
451 for (int i=0;i<_numberOfGeometricType;i++)
452 _geometricType[i] = GeometricType[i];
454 if (_profilNames.empty())
456 // giving a default value to profile names
457 vector<string> prof_names( _numberOfGeometricType);
458 for (int itype=0; itype < _numberOfGeometricType; itype++)
460 ostringstream typestr;
461 typestr<<_name<<"_type"<<_geometricType[itype];
462 prof_names[itype]=typestr.str();
464 _profilNames=prof_names;
470 Set the attribute _numberOfElements to NumberOfElements and
471 calculate the total number of elements.
473 //----------------------------------------------------------
474 inline void SUPPORT::setNumberOfElements(const int *NumberOfElements)
475 //----------------------------------------------------------
477 if (_numberOfElements == NULL)
478 if (_numberOfGeometricType)
479 _numberOfElements.set(_numberOfGeometricType,NumberOfElements);
481 _numberOfElements.set(0);
482 _totalNumberOfElements = 0 ;
483 for (int i=0;i<_numberOfGeometricType;i++)
484 _totalNumberOfElements+=_numberOfElements[i];
487 /*! set the attribute _totalNumberOfElements to TotalNumberOfElements */
488 //--------------------------------------------------------------------
489 //inline void SUPPORT::setTotalNumberOfElements(int TotalNumberOfElements)
490 //--------------------------------------------------------------------
492 // _totalNumberOfElements=TotalNumberOfElements;
495 /*! set the attribute _number to Number */
496 //---------------------------------------------------
497 inline void SUPPORT::setNumber(MEDSKYLINEARRAY * Number)
498 //---------------------------------------------------
500 const char * LOC = "SUPPORT::setNumber(MEDSKYLINEARRAY * Number)";
502 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support is on all elements")) ;
504 if (_number != NULL) delete _number ;
508 /*! set the attribute _number with index and value arrays */
509 //---------------------------------------------------
510 inline void SUPPORT::setNumber(const int * index, const int* value, bool shallowCopy)
511 //---------------------------------------------------
513 if (_number != NULL) delete _number ;
514 _number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value,shallowCopy);
517 /*! returns the name of the support. */
518 //------------------------------------
519 inline string SUPPORT::getName() const
520 //------------------------------------
526 /*! returns the description of the support. */
527 //--------------------------------------------
528 inline string SUPPORT::getDescription() const
529 //--------------------------------------------
534 /*! returns a reference to the mesh */
535 //------------------------------------
536 inline MESH * SUPPORT::getMesh() const
537 //------------------------------------
543 Returns true if all elements of this entity are
544 concerned, false otherwise.
545 If true, you must use mesh reference (getMesh) to get more information.
547 //------------------------------------------
548 inline bool SUPPORT::isOnAllElements() const
549 //------------------------------------------
555 Returns number of geometric Types
556 defines in the support
558 //------------------------------------------
559 inline int SUPPORT::getNumberOfTypes() const
560 //------------------------------------------
562 // if ((_isOnAllElts)&(_entity != MED_NODE))
563 // return _mesh->getNumberOfTypes(_entity) ;
565 return _numberOfGeometricType ;
569 Returns the %medEntityMesh's type used by the support.
570 Note : A support deals only with one entity's type
571 (for example : MED_FACE or MED_NODE)
573 //---------------------------------------------
574 inline MED_EN::medEntityMesh SUPPORT::getEntity() const
575 //---------------------------------------------
581 If isOnAllElements is false, returns an array of %medGeometryElement
582 types used by the support.
584 //---------------------------------------------------
585 inline const MED_EN::medGeometryElement * SUPPORT::getTypes() const
586 //---------------------------------------------------
588 return _geometricType;
591 }//End namespace MEDMEM
594 #endif /* SUPPORT_HXX */