Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDMEM / MEDMEM_Support.hxx
1 // Copyright (C) 2007-2013  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 /*
24   File Support.hxx
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 GMESH;
48   class MESH;
49
50 /*!
51
52   This class describe a support of elements on an entity of the mesh.
53
54   It contains the list of meshes elements for an entity (MED_NODE,
55   MED_CELL, MED_FACE or MED_EDGE).
56
57 */
58 class MEDMEM_EXPORT SUPPORT : public RCBASE
59 {
60 protected:
61   /*!
62     \if developper
63     Support name.
64     \endif
65   */
66   std::string                   _name;
67
68  /*!
69     \if developper
70     Name of the associated mesh if the _mesh pointer
71     is NULL.
72     \endif
73   */
74   mutable std::string                   _meshName;
75
76   /*!
77     \if developper
78     Description of the support (optional).
79     \endif
80   */
81   std::string                   _description;
82
83   /*!
84     \if developper
85     Reference to the mesh on which the support is defined.
86     \endif
87   */
88   mutable const GMESH *            _mesh;
89
90   /*!
91     \if developper
92     Type of entity on which the support is defined
93     (only one for each support).
94     \endif
95   */
96   MED_EN::medEntityMesh            _entity ;
97
98   /*!
99     \if developper
100     Number of geometric type defined in the support.
101     \endif
102   */
103   int                      _numberOfGeometricType;
104
105   /*!
106     \if developper
107     Array of all geometric type defined in the support.
108     \endif
109   */
110   PointerOf<MED_EN::medGeometryElement>     _geometricType;
111
112   /*!
113     \if developper
114     If true, we consider all entities of type _entity
115     defined in the associated mesh
116     \endif
117   */
118   bool                     _isOnAllElts;
119
120   /*!
121     \if developper
122     Index array of size _numberOfGeometricType wich contains
123     for each geometric type, the number of elements of this type.
124     \endif
125   */
126   PointerOf<int>                    _numberOfElements;
127
128   /*!
129     \if developper
130     Sum of each _numberOfElements component.
131     \endif
132   */
133   int                      _totalNumberOfElements;
134
135   // the two following arrays are defined only if _isOnAllElts is false :
136
137   /*!
138     \if developper
139     Array of size _index[_numberOfType]-1 wich contain number of
140     entities of each geometric type. We use global numbering.\n
141     Defined only if _isOnAllElts is false.
142     \endif
143   */
144   mutable MEDSKYLINEARRAY * _number;
145
146   /*!
147     \if developper
148     Array of size _index[_numberOfType]-1 wich contain number of
149     entities of each geometric type. We use file numbering.\n
150     Defined only if _isOnAllElts is false.
151     \endif
152   */
153   mutable MEDSKYLINEARRAY * _number_fromfile;
154
155   /*!
156     \if developper
157     Array of size <_numberOfGeometricType> wich contain the profil name of 
158     entities of each geometric type.\n
159     Defined only if _isOnAllElts is false.
160     If it exist an entities list on a geometric type in _number but there is no profil name associated
161     ( MED_NOPFL ) the MED driver will consider and verify this entities list as being all the
162     entities available on the associated mesh for this geometric type.
163     \endif
164   */
165
166   std::vector< std::string > _profilNames;
167 public:
168   SUPPORT();
169   //SUPPORT(GMESH* Mesh, std::string Name="", MED_EN::medEntityMesh Entity=MED_EN::MED_CELL);
170   SUPPORT(const SUPPORT & m);
171 public:
172   friend MEDMEM_EXPORT ostream & operator<<(ostream &os,const SUPPORT &my);
173
174   SUPPORT& operator=(const SUPPORT &support);
175   bool operator == (const SUPPORT &support) const;
176   bool deepCompare(const SUPPORT &support) const;
177   void update();
178
179   inline void setName(const std::string& Name);
180   inline void setDescription(const std::string& Description);
181   void        setMesh(const GMESH *Mesh) const;
182   void        setMeshName(const string & meshName);
183   inline void setAll(bool All);
184   void        setEntity(MED_EN::medEntityMesh Entity);
185   void        setNumberOfGeometricType(int NumberOfGeometricType);
186   void        setGeometricType(const MED_EN::medGeometryElement *GeometricType);
187   void        setNumberOfElements(const int *NumberOfElements);
188   void        setNumber(MEDSKYLINEARRAY * Number);
189   void        setNumber(const int * index, const int* value, bool shallowCopy=false);
190
191   inline const std::string&    getName() const;
192   inline const std::string&    getDescription() const;
193   virtual inline const GMESH * getMesh() const;
194   std::string                  getMeshName() const;
195   inline MED_EN::medEntityMesh getEntity() const;
196
197   inline bool   isOnAllElements() const;
198   inline int    getNumberOfTypes() const;
199   inline const MED_EN::medGeometryElement* getTypes() const ;
200   int           getNumberOfElements(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
201   const int *   getNumberOfElements() const throw (MEDEXCEPTION);
202   virtual MEDSKYLINEARRAY *   getnumber() const throw (MEDEXCEPTION);
203   virtual MEDSKYLINEARRAY *   getnumberFromFile() const throw (MEDEXCEPTION);
204   virtual const int *         getNumber(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
205   virtual const int *         getNumberFromFile(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
206   virtual        const int *  getNumberIndex() const throw (MEDEXCEPTION);
207   virtual int getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION);
208
209   void blending(const SUPPORT * mySupport) throw (MEDEXCEPTION) ;
210
211   // Les numéros d'entités dans les profils doivent être croissant
212   // pour respecter la norme MED
213   void setpartial(const std::string& Description, int NumberOfGeometricType,
214                   int TotalNumberOfEntity, const MED_EN::medGeometryElement *GeometricType,
215                   const int *NumberOfEntity, const int *NumberValue);
216
217   void setpartial(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
218
219
220   void setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION);
221   
222   // Si les noms de profils ne sont pas positionnés, les profils ne seront
223   // pas écrits par MEDFICHIER.
224   void   setProfilNames(const std::vector<std::string>& profilNames) throw (MEDEXCEPTION);
225   //string getProfilName(const MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION);
226   std::vector<std::string> getProfilNames() const throw (MEDEXCEPTION);
227
228   void getBoundaryElements() throw (MEDEXCEPTION);
229   void changeElementsNbs(MED_EN::medEntityMesh entity, const int *renumberingFromOldToNew);
230   void intersecting(const SUPPORT * mySupport) throw (MEDEXCEPTION) ;
231   bool belongsTo(const SUPPORT& other, bool deepCompare=false) const;
232   SUPPORT *getComplement() const;
233   SUPPORT *substract(const SUPPORT& other) const throw (MEDEXCEPTION) ;
234   SUPPORT *getBoundaryElements(MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION);
235   SUPPORT* buildSupportOnNode() const throw (MEDEXCEPTION);
236   void fillFromNodeList(const std::list<int>& listOfNode) throw (MEDEXCEPTION);
237   void fillFromElementList(const std::list<int>& listOfElt) throw (MEDEXCEPTION);
238   void clearDataOnNumbers();
239   MESH* makeMesh() const;
240  protected:
241   virtual ~SUPPORT();
242  protected:
243   static std::list<int> *sub(int start,int end,const int *idsToSuppress,int lgthIdsToSuppress);
244   static std::list<int> *sub(const int *ids,int lgthIds,const int *idsToSuppress,int lgthIdsToSuppress);
245 };
246
247 // _____________________
248 // Methodes Inline
249 // _____________________
250
251 /*! set the attribute _name to Name */
252 //--------------------------------------
253 inline void SUPPORT::setName(const std::string& Name)
254 //--------------------------------------
255 {
256   _name=Name;
257 }
258
259 /*! set the attribute _description to Description */
260 //--------------------------------------------------
261 inline void SUPPORT::setDescription(const std::string& Description)
262 //--------------------------------------------------
263 {
264   _description=Description;
265 }
266
267   /*! \if MEDMEM_ug
268 \addtogroup SUPPORT_creation
269 @{
270 \endif
271   */
272
273 /*! Creates a support on all elements of the type specified in the constructor.
274
275   Even if _isonAllElts is true, geometric types defining the FIELD's SUPPORT
276   must be read from the SUPPORT not from the associated GMESH (the geometric
277   types defining the FIELD's SUPPORT may be a subset of the geometric types
278   defined in the GMESH even if for each SUPPORT geometric type all MESH entities
279   are used).
280 */
281 //------------------------------------------
282 inline void SUPPORT::setAll(bool All)
283 //------------------------------------------
284 {
285   _isOnAllElts=All;
286 }
287   /*! \if MEDMEM_ug  @} \endif */
288
289 /*! returns the name of the support. */
290 //------------------------------------
291 inline const std::string& SUPPORT::getName() const
292 //------------------------------------
293 {
294   return _name;
295 }
296
297 /*! returns the description of the support. */
298 //--------------------------------------------
299 inline const std::string& SUPPORT::getDescription() const
300 //--------------------------------------------
301 {
302   return _description;
303 }
304
305 /*! returns a reference to the mesh */
306 //------------------------------------
307 inline const GMESH * SUPPORT::getMesh() const
308 //------------------------------------
309 {
310   return _mesh;
311 }
312
313 /*!
314   Returns true if all elements of this entity are
315   concerned, false otherwise.
316   If true, you must use mesh reference (getMesh) to get more information.
317 */
318 //------------------------------------------
319 inline bool SUPPORT::isOnAllElements() const
320 //------------------------------------------
321 {
322   return _isOnAllElts;
323 }
324
325 /*!
326   Returns number of geometric Types
327   defines in the support
328 */
329 //------------------------------------------
330 inline int SUPPORT::getNumberOfTypes() const
331 //------------------------------------------
332 {
333   //    if ((_isOnAllElts)&(_entity != MED_NODE))
334   //      return _mesh->getNumberOfTypes(_entity) ;
335   //    else
336   return _numberOfGeometricType ;
337 }
338
339 /*!
340   Returns the %medEntityMesh's type used by the support.
341   Note : A support deals only with one entity's type
342   (for example : MED_FACE or MED_NODE)
343 */
344 //---------------------------------------------
345 inline MED_EN::medEntityMesh SUPPORT::getEntity() const
346 //---------------------------------------------
347 {
348   return _entity;
349 }
350
351 /*!
352   If isOnAllElements is false, returns an array of %medGeometryElement
353   types used by the support.
354 */
355 //---------------------------------------------------
356 inline const MED_EN::medGeometryElement * SUPPORT::getTypes() const
357 //---------------------------------------------------
358 {
359   return _geometricType;
360 }
361
362 }//End namespace MEDMEM
363
364
365 #endif /* SUPPORT_HXX */