]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Support.hxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_Support.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23   File Support.hxx
24   $Header$
25 */
26
27 #ifndef SUPPORT_HXX
28 #define SUPPORT_HXX
29
30 #include <MEDMEM.hxx>
31
32 #include <list>
33 #include <vector>
34 #include <string>
35 #include <list>
36
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"
43
44
45 namespace MEDMEM {
46
47   class MESH;
48
49 /*!
50
51   This class describe a support of elements on an entity of the mesh.
52
53   It contains the list of meshes elements for an entity (MED_NODE,
54   MED_CELL, MED_FACE or MED_EDGE).
55
56 */
57 class MEDMEM_EXPORT SUPPORT : public RCBASE
58 {
59 protected:
60   /*!
61     \if developper
62     Support name.
63     \endif
64   */
65   string                   _name;
66
67  /*!
68     \if developper
69     Name of the associated mesh if the _mesh pointer
70     is NULL.
71     \endif
72   */
73   mutable string                   _meshName;
74
75   /*!
76     \if developper
77     Description of the support (optional).
78     \endif
79   */
80   string                   _description;
81
82   /*!
83     \if developper
84     Reference to the mesh on which the support is defined.
85     \endif
86   */
87   mutable MESH *                   _mesh;
88
89   /*!
90     \if developper
91     Type of entity on which the support is defined
92     (only one for each support).
93     \endif
94   */
95   MED_EN::medEntityMesh            _entity ;
96
97   /*!
98     \if developper
99     Number of geometric type defined in the support.
100     \endif
101   */
102   int                      _numberOfGeometricType;
103
104   /*!
105     \if developper
106     Array of all geometric type defined in the support.
107     \endif
108   */
109   PointerOf<MED_EN::medGeometryElement>     _geometricType;
110
111   /*!
112     \if developper
113     If true, we consider all entities of type _entity
114     defined in the associated mesh
115     \endif
116   */
117   bool                     _isOnAllElts;
118
119   /*!
120     \if developper
121     Index array of size _numberOfGeometricType wich contains
122     for each geometric type, the number of elements of this type.
123     \endif
124   */
125   PointerOf<int>                    _numberOfElements;
126
127   /*!
128     \if developper
129     Sum of each _numberOfElements component.
130     \endif
131   */
132   int                      _totalNumberOfElements;
133
134   // the two following arrays are defined only if _isOnAllElts is false :
135
136   /*!
137     \if developper
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.
141     \endif
142   */
143   mutable MEDSKYLINEARRAY * _number;
144
145   /*!
146     \if developper
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.
150     \endif
151   */
152   mutable MEDSKYLINEARRAY * _number_fromfile;
153
154   /*!
155     \if developper
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.
162     \endif
163   */
164
165   vector< string > _profilNames;
166
167 public:
168
169   SUPPORT();
170   SUPPORT(MESH* Mesh, string Name="", MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
171   SUPPORT(const SUPPORT & m);
172   virtual ~SUPPORT();
173   friend MEDMEM_EXPORT ostream & operator<<(ostream &os,const SUPPORT &my);
174
175   SUPPORT& operator=(const SUPPORT &support);
176   bool operator == (const SUPPORT &support) const;
177   bool deepCompare(const SUPPORT &support) const;
178   void update();
179
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);
193
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;
199
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);
211
212   void blending(SUPPORT * mySupport) throw (MEDEXCEPTION) ;
213
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);
219
220   void setpartial(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
221
222
223   void setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
224   
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);
230
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;
244 protected:
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);
247 };
248
249 // _____________________
250 // Methodes Inline
251 // _____________________
252
253 /*!\if MEDMEM_ug 
254 \addtogroup SUPPORT_query
255 @{
256 \endif
257 */
258
259 /*!
260   This method returns the number of all elements of the type GeometricType.
261
262   If isOnAllElements is false, it returns the number of elements in the
263   support otherwise it returns number of elements in the mesh.
264
265   Example : number of MED_TRIA3 or MED_ALL_ELEMENTS elements
266   in support.
267
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).
271 */
272 //-----------------------------------------------------------------------------
273 inline int SUPPORT::getNumberOfElements(MED_EN::medGeometryElement GeometricType) const
274   throw (MEDEXCEPTION)
275 //-----------------------------------------------------------------------------
276 {
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 !") ;
283 }
284
285   /*! Returns the total number of elements in the support. */
286 //-----------------------------------------------------------------------------
287 inline  const int * SUPPORT::getNumberOfElements() const throw (MEDEXCEPTION) {
288 //-----------------------------------------------------------------------------
289   return _numberOfElements;
290 }
291
292 //---------------------------------------------------------------------
293 inline MEDSKYLINEARRAY * SUPPORT::getnumber() const
294   throw (MEDEXCEPTION)
295 //---------------------------------------------------------------------
296 {
297   if (_number==NULL)
298     throw MEDEXCEPTION("Support::getnumber : Not defined !") ;
299   return _number ;
300 }
301
302 //---------------------------------------------------------------------
303 inline MEDSKYLINEARRAY * SUPPORT::getnumberFromFile() const
304   throw (MEDEXCEPTION)
305 //---------------------------------------------------------------------
306 {
307   if (_number_fromfile==NULL)
308     throw MEDEXCEPTION("Support::getnumberFromFile : Not defined !") ;
309   return _number_fromfile ;
310 }
311
312 /*!
313   If isOnAllElements is false, returns an array which contains
314   all number of given medGeometryElement.
315
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).
319
320   Note : If SUPPORT is defined on MED_NODE, use MED_NONE
321   medGeometryElement type.
322 */
323 //---------------------------------------------------------------------
324 inline const int * SUPPORT::getNumber(MED_EN::medGeometryElement GeometricType) const
325   throw (MEDEXCEPTION)
326 //---------------------------------------------------------------------
327 {
328   const char * LOC = "Support::getNumber : " ;
329   if (_isOnAllElts)
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 !")) ;
337 }
338
339 //---------------------------------------------------------------------
340 inline const int * SUPPORT::getNumberFromFile(MED_EN::medGeometryElement GeometricType) const
341   throw (MEDEXCEPTION)
342 //---------------------------------------------------------------------
343 {
344   const char * LOC = "Support::getNumberFromFile : " ;
345 //   if (_isOnAllElts)
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 !")) ;
353 }
354
355 /*!
356   If isOnAllElements is false, returns index of element number.
357   Use it with getNumber(MED_ALL_ELEMENTS).
358
359   Note : See getConnectivityIndex for details.
360 */
361 //-------------------------------------------
362 inline const int * SUPPORT::getNumberIndex() const
363 //-------------------------------------------
364   throw (MEDEXCEPTION)
365 {
366   if (_isOnAllElts)
367     throw MEDEXCEPTION("Support::getNumberIndex : Not defined, support is on all entity !") ;
368   return _number->getIndex() ;
369 }
370 /*! \if MEDMEM_ug
371 @}
372 \endif */
373
374 /*! set the attribute _name to Name */
375 //--------------------------------------
376 inline void SUPPORT::setName(string Name)
377 //--------------------------------------
378 {
379   _name=Name;
380 }
381
382 /*! set the attribute _description to Description */
383 //--------------------------------------------------
384 inline void SUPPORT::setDescription(string Description)
385 //--------------------------------------------------
386 {
387   _description=Description;
388 }
389
390
391 /*! set the meshName if there is ni reference _mesh to Mesh */
392 //--------------------------------------
393 inline void SUPPORT::setMeshName(const string & meshName)
394 //--------------------------------------
395 {
396   const char * LOC = "SUPPORT::setMeshName(const string & meshName) : ";
397
398   if (_mesh)
399     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Setting meshName is not possible when an associated mesh is set !")) ;
400
401   _meshName=meshName;
402 }
403
404   /*! \if MEDMEM_ug
405 \addtogroup SUPPORT_creation
406 @{
407 \endif
408   */
409
410 /*! Creates a support on all elements of the type specified in the constructor.
411
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
416   are used).
417 */
418 //------------------------------------------
419 inline void SUPPORT::setAll(bool All)
420 //------------------------------------------
421 {
422   _isOnAllElts=All;
423 }
424   /*! \if MEDMEM_ug  @} \endif */
425
426 /*! set the attribute _entity to Entity */
427 //------------------------------------------
428 inline void SUPPORT::setEntity(MED_EN::medEntityMesh Entity)
429 {
430   _entity=Entity;
431 }
432
433 /*! set the attribute _numberOfGeometricType to NumberOfGeometricType */
434 //---------------------------------------------------------------------
435 inline void SUPPORT::setNumberOfGeometricType(int NumberOfGeometricType)
436 //---------------------------------------------------------------------
437 {
438   _numberOfGeometricType=NumberOfGeometricType;
439
440   _geometricType.set(0);
441   _numberOfElements.set(0);
442 }
443
444 /*! set the attribute _geometricType to geometricType */
445 //---------------------------------------------------------------------
446 inline void SUPPORT::setGeometricType(const MED_EN::medGeometryElement *GeometricType)
447 //---------------------------------------------------------------------
448 {
449   if (!_geometricType)
450     _geometricType.set(_numberOfGeometricType);
451   for (int i=0;i<_numberOfGeometricType;i++)
452     _geometricType[i] = GeometricType[i];
453
454   if (_profilNames.empty())
455     {
456       // giving a default value to profile names
457       vector<string> prof_names( _numberOfGeometricType);
458       for (int itype=0; itype < _numberOfGeometricType; itype++)
459         {
460           ostringstream typestr;
461           typestr<<_name<<"_type"<<_geometricType[itype];
462           prof_names[itype]=typestr.str();
463         }
464       _profilNames=prof_names;
465     }
466 }
467
468
469 /*!
470   Set the attribute _numberOfElements to NumberOfElements and
471   calculate the total number of elements.
472 */
473 //----------------------------------------------------------
474 inline void SUPPORT::setNumberOfElements(const int *NumberOfElements)
475 //----------------------------------------------------------
476 {
477   if (_numberOfElements == NULL)
478     if (_numberOfGeometricType)
479       _numberOfElements.set(_numberOfGeometricType,NumberOfElements);
480     else
481       _numberOfElements.set(0);
482   _totalNumberOfElements = 0 ;
483   for (int i=0;i<_numberOfGeometricType;i++)
484     _totalNumberOfElements+=_numberOfElements[i];
485 }
486
487 /*! set the attribute _totalNumberOfElements to TotalNumberOfElements */
488 //--------------------------------------------------------------------
489 //inline void SUPPORT::setTotalNumberOfElements(int TotalNumberOfElements)
490 //--------------------------------------------------------------------
491 //{
492 //  _totalNumberOfElements=TotalNumberOfElements;
493 //}
494
495 /*! set the attribute _number to Number */
496 //---------------------------------------------------
497 inline void SUPPORT::setNumber(MEDSKYLINEARRAY * Number)
498 //---------------------------------------------------
499 {
500   const char * LOC = "SUPPORT::setNumber(MEDSKYLINEARRAY * Number)";
501   if ( _isOnAllElts )
502     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support is on all elements")) ;
503
504   if (_number != NULL) delete _number ;
505   _number=Number;
506 }
507
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 //---------------------------------------------------
512 {
513   if (_number != NULL) delete _number ;
514   _number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value,shallowCopy);
515 }
516
517 /*! returns the name of the support. */
518 //------------------------------------
519 inline string SUPPORT::getName() const
520 //------------------------------------
521 {
522   return _name;
523 }
524
525
526 /*! returns the description of the support. */
527 //--------------------------------------------
528 inline string SUPPORT::getDescription() const
529 //--------------------------------------------
530 {
531   return _description;
532 }
533
534 /*! returns a reference to the mesh */
535 //------------------------------------
536 inline MESH * SUPPORT::getMesh() const
537 //------------------------------------
538 {
539   return _mesh;
540 }
541
542 /*!
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.
546 */
547 //------------------------------------------
548 inline bool SUPPORT::isOnAllElements() const
549 //------------------------------------------
550 {
551   return _isOnAllElts;
552 }
553
554 /*!
555   Returns number of geometric Types
556   defines in the support
557 */
558 //------------------------------------------
559 inline int SUPPORT::getNumberOfTypes() const
560 //------------------------------------------
561 {
562   //    if ((_isOnAllElts)&(_entity != MED_NODE))
563   //      return _mesh->getNumberOfTypes(_entity) ;
564   //    else
565   return _numberOfGeometricType ;
566 }
567
568 /*!
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)
572 */
573 //---------------------------------------------
574 inline MED_EN::medEntityMesh SUPPORT::getEntity() const
575 //---------------------------------------------
576 {
577   return _entity;
578 }
579
580 /*!
581   If isOnAllElements is false, returns an array of %medGeometryElement
582   types used by the support.
583 */
584 //---------------------------------------------------
585 inline const MED_EN::medGeometryElement * SUPPORT::getTypes() const
586 //---------------------------------------------------
587 {
588   return _geometricType;
589 }
590
591 }//End namespace MEDMEM
592
593
594 #endif /* SUPPORT_HXX */