Salome HOME
Patch modules/smesh.git for Doxygen typos/grammar + misc. typos
[modules/smesh.git] / src / MEDWrapper / Base / MED_Structures.hxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 #ifndef MED_Structures_HeaderFile
24 #define MED_Structures_HeaderFile
25
26 #include "MED_Common.hxx"
27 #include "MED_Utilities.hxx"
28
29 #ifdef WIN32
30 #pragma warning(disable:4251)
31 #endif
32
33 namespace MED
34 {
35
36   //---------------------------------------------------------------
37   //! Defines a type for managing sequence of strings
38   typedef TVector<char> TString; 
39   typedef SharedPtr<TString> PString;
40
41   //! Extract a substring from the sequence of the strings
42   MEDWRAPPER_EXPORT
43   std::string 
44   GetString(TInt theId, TInt theStep, 
45             const TString& theString);
46   
47   //! Set a substring in the sequence of the strings
48   MEDWRAPPER_EXPORT 
49   void
50   SetString(TInt theId, TInt theStep, 
51                  TString& theString, 
52                  const std::string& theValue);
53
54   //! Set a substring in the sequence of the strings
55   MEDWRAPPER_EXPORT
56   void
57   SetString(TInt theId, TInt theStep, 
58                  TString& theString, 
59                  const TString& theValue);
60
61   //---------------------------------------------------------------
62   //! Define a parent class for all MEDWrapper classes
63   struct MEDWRAPPER_EXPORT TBase
64   {
65     virtual ~TBase() {} 
66   };
67
68
69   //---------------------------------------------------------------
70   //! Define a parent class for all named MED entities
71   struct MEDWRAPPER_EXPORT TNameInfo: virtual TBase
72   {
73     TString myName; //!< Keeps its name
74     virtual std::string GetName() const = 0; //!< Gets its name
75     virtual void SetName(const std::string& theValue) = 0; //!< Set a new name
76     virtual void SetName(const TString& theValue) = 0; //!< Set a new name
77   };
78
79
80   //---------------------------------------------------------------
81   //! Define a parent class for all MED entities that contains a sequence of numbers
82   /*!
83     It defines through corresponding enumeration (EModeSwitch) how the sequence 
84     should be interpreted in C or Fortran mode (eFULL_INTERLACE or eNON_INTERLACE).
85   */
86   struct MEDWRAPPER_EXPORT TModeSwitchInfo: virtual TBase
87   {
88     //! To construct instance of the class by default
89     TModeSwitchInfo():
90       myModeSwitch(eFULL_INTERLACE)
91     {}
92
93     //! To construct instance of the class
94     TModeSwitchInfo(EModeSwitch theModeSwitch):
95       myModeSwitch(theModeSwitch)
96     {}
97
98     EModeSwitch myModeSwitch; //!< Keeps the 
99     EModeSwitch GetModeSwitch() const { return myModeSwitch;}
100   };
101
102
103   //---------------------------------------------------------------
104   //! Define a base class which represents MED Mesh entity
105   struct MEDWRAPPER_EXPORT TMeshInfo: virtual TNameInfo
106   {
107     TInt myDim; //!< Dimension of the mesh (0, 1, 2 or 3)
108     TInt GetDim() const { return myDim;} //!< Gets dimension of the mesh
109
110     TInt mySpaceDim;
111     TInt GetSpaceDim() const { return mySpaceDim; }
112
113     EMaillage myType; //!< Type of the mesh
114     EMaillage GetType() const { return myType;} //!< Gets type of the mesh
115
116     TString myDesc; //!< Description of the mesh
117     virtual std::string GetDesc() const = 0; //!< Get description for the mesh
118     virtual void SetDesc(const std::string& theValue) = 0; //!< Sets description for the mesh
119
120     
121   };
122   
123
124   //---------------------------------------------------------------
125   typedef TVector<TInt> TIntVector;
126   typedef TSlice<TInt> TIntVecSlice;
127   typedef TCSlice<TInt> TCIntVecSlice;
128
129   typedef TIntVector TFamAttr;
130
131   //! Define a base class which represents MED Family entity
132   struct MEDWRAPPER_EXPORT TFamilyInfo: virtual TNameInfo
133   {
134     PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh
135     //! Get a reference to corresponding MED Mesh
136     const PMeshInfo& GetMeshInfo() const { return myMeshInfo;} 
137
138     TInt myId; //!< An unique index of the MED FAMILY
139     TInt GetId() const { return myId;} //!< Gets number of the MED FAMILY
140     void SetId(TInt theId) { myId = theId;} //! Define number of the MED FAMILY
141
142     TInt myNbGroup; //!< Defines number MED Groups connected to
143     //! Gets number of MED GROUPS the MED FAMILY is bound to
144     TInt GetNbGroup() const { return myNbGroup;} 
145
146     //! Contains sequence of the names for the MED Groups connected to
147     TString myGroupNames; 
148     //! Gets name of a bound MED GROUP by its number
149     virtual std::string GetGroupName(TInt theId) const = 0;
150     //! Sets name of the defined MED GROUP by its number
151     virtual void SetGroupName(TInt theId, const std::string& theValue) = 0;
152
153     TInt myNbAttr; //!< Defines number of the MED Family attributes 
154     //! Gets number of attached attributes for the MED FAMILY
155     TInt GetNbAttr() const { return myNbAttr;} 
156
157     //! Defines sequence of the indexes of the MED Family attributes
158     TFamAttr myAttrId; 
159     //! Get MED FAMILY attribute by its number
160     TInt GetAttrId(TInt theId) const;
161     //! Set MED FAMILY attribute by its number
162     void SetAttrId(TInt theId, TInt theVal);
163
164     //! Defines sequence of the values of the MED Family attributes
165     TFamAttr myAttrVal;
166     //! Get MED FAMILY attribute by its number
167     TInt GetAttrVal(TInt theId) const;
168     //! Set MED FAMILY attribute by its number
169     void SetAttrVal(TInt theId, TInt theVal);
170
171     //! Defines sequence of the names of the MED Family attributes
172     TString myAttrDesc;
173     //! Get value of the MED FAMILY attribute by its number
174     virtual std::string GetAttrDesc(TInt theId) const = 0;
175     //! Set value of the MED FAMILY attribute by its number
176     virtual void SetAttrDesc(TInt theId, const std::string& theValue) = 0;
177   };
178
179
180   //---------------------------------------------------------------
181   typedef TIntVector TElemNum;
182   typedef SharedPtr<TElemNum> PElemNum;
183   
184   //! Define a parent class for all MED entities that describes mesh entites such as nodes and cells.
185   struct MEDWRAPPER_EXPORT TElemInfo: virtual TBase
186   {
187     PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh
188     //! Get a reference to corresponding MED Mesh
189     const PMeshInfo& GetMeshInfo() const { return myMeshInfo;}
190
191     TInt myNbElem; //<! Number of corresponding mesh entities
192     TInt GetNbElem() const { return myNbElem;} //! Get number of mesh elements
193     
194     //! Defines sequence MED Family indexes for corresponding mesh entites
195     PElemNum myFamNum; 
196     //! Get number of a MED FAMILY by order number of the mesh element
197     TInt GetFamNum(TInt theId) const;
198     //! Set number of a MED FAMILY for the mesh element with the  order number
199     void SetFamNum(TInt theId, TInt theVal);
200
201     //! Defines if the mesh elements are indexed
202     EBooleen myIsElemNum;
203     //! Let know if the mesh elements are indexed
204     EBooleen IsElemNum() const { return myIsElemNum;}
205     
206     //! Defines if the mesh elements family are indexed
207     EBooleen myIsFamNum;
208     //! Let know if the mesh elements family are indexed
209     EBooleen IsFamNum() const { return myIsFamNum;}
210     
211
212     //! Contains sequence of the indexes for the mesh elements
213     PElemNum myElemNum;
214     //! Get a reference number of the mesh element by its order number
215     TInt GetElemNum(TInt theId) const;
216     //! Set a reference number for the mesh element by its order number
217     void SetElemNum(TInt theId, TInt theVal);
218
219     //! Defines if the mesh elements are named
220     EBooleen myIsElemNames;
221     //! Let know if the mesh elements havew names
222     EBooleen IsElemNames() const { return myIsElemNames;}
223
224     //! Contains sequence of the names for the mesh elements
225     PString myElemNames;
226     //! Get name of the mesh element by its order number
227     virtual std::string GetElemName(TInt theId) const = 0;
228     //! Set name of the mesh element by its order number
229     virtual void SetElemName(TInt theId, const std::string& theValue) = 0;
230   };
231
232
233   //---------------------------------------------------------------
234   typedef TVector<TFloat> TFloatVector;
235   typedef TSlice<TFloat> TFloatVecSlice;
236   typedef TCSlice<TFloat> TCFloatVecSlice;
237
238   typedef TFloatVector TNodeCoord;
239   typedef SharedPtr<TNodeCoord> PNodeCoord;
240
241   typedef TFloatVecSlice TCoordSlice;
242   typedef TCFloatVecSlice TCCoordSlice;
243
244   //! Define a base class which represents MED Nodes entity
245   struct MEDWRAPPER_EXPORT TNodeInfo: 
246     virtual TElemInfo,
247     virtual TModeSwitchInfo 
248   {
249     PNodeCoord myCoord; //!< Contains all nodal coordinates
250
251     //! Gives coordinates for mesh node by its number (const version)
252     TCCoordSlice GetCoordSlice(TInt theId) const;
253     //! Gives coordinates for mesh node by its number
254     TCoordSlice GetCoordSlice(TInt theId);
255
256     ERepere mySystem; //!< Defines, which coordinate system is used
257     //! Get which coordinate system is used for the node describing
258     ERepere GetSystem() const { return mySystem;}
259     //! Set coordinate system to be used for the node describing
260     void SetSystem(ERepere theSystem) { mySystem = theSystem;}
261
262     TString myCoordNames; //!< Contains names for the coordinate dimensions
263     //! Get name of the coordinate dimension by its order number
264     virtual std::string GetCoordName(TInt theId) const = 0;
265     //! Set name of the coordinate dimension by its order number
266     virtual void SetCoordName(TInt theId, const std::string& theValue) = 0;
267
268     TString myCoordUnits; //!< Contains units for the coordinate dimensions
269     //! Get name of unit for the coordinate dimension by its order number
270     virtual std::string GetCoordUnit(TInt theId) const = 0;
271     //! Set name of unit for the coordinate dimension by its order number
272     virtual void SetCoordUnit(TInt theId, const std::string& theValue) = 0;
273   };
274
275
276   //---------------------------------------------------------------
277   typedef TIntVecSlice TConnSlice;
278   typedef TCIntVecSlice TCConnSlice;
279
280   //! Define a base class which represents MED Cells entity
281   struct MEDWRAPPER_EXPORT TCellInfo: 
282     virtual TElemInfo,
283     virtual TModeSwitchInfo 
284   {
285     EEntiteMaillage myEntity; //!< Defines the MED Entity where the mesh cells belongs to
286     //! Find out what MED ENTITY the cells belong to
287     EEntiteMaillage GetEntity() const { return myEntity;}
288
289     EGeometrieElement myGeom; //!< Defines the MED Geometric type of the instance
290     //! Find out what MED geometrical type the cells belong to
291     EGeometrieElement GetGeom() const { return myGeom;}
292
293     EConnectivite myConnMode; //!< Defines connectivity mode
294     //! Find out in what connectivity the cells are written
295     EConnectivite GetConnMode() const { return myConnMode;}
296
297     virtual TInt GetConnDim() const = 0; //!< Gives step in the connectivity sequence
298
299     PElemNum myConn; //!< Defines sequence which describe connectivity for each of mesh cell
300
301     //! Gives connectivities for mesh cell by its number (const version)
302     TCConnSlice GetConnSlice(TInt theElemId) const;
303     //! Gives connectivities for mesh cell by its number
304     TConnSlice GetConnSlice(TInt theElemId);
305   };
306
307   //---------------------------------------------------------------
308   //! Define a base class which represents MED Polygon entity
309   struct MEDWRAPPER_EXPORT TPolygoneInfo: 
310     virtual TElemInfo
311   {
312     //! Defines the MED Entity where the polygons belongs to
313     EEntiteMaillage myEntity; // MED_FACE|MED_MAILLE
314     //! Find out what MED ENTITY the MED Polygons belong to
315     EEntiteMaillage GetEntity() const { return myEntity;}
316
317     //! Defines the MED Geometric type of the instance
318     EGeometrieElement myGeom; // ePOLYGONE
319     //! Find out what MED geometrical type the MED Polygons belong to
320     EGeometrieElement GetGeom() const { return ePOLYGONE;}
321
322     //! Defines connectivity mode
323     EConnectivite myConnMode; // eNOD|eDESC(eDESC not used)
324     //! Find out in what connectivity the cells are written
325     EConnectivite GetConnMode() const { return myConnMode;}
326
327     PElemNum myConn; //!< Table de connectivities
328     PElemNum myIndex; //!< Table de indexes
329
330     //! Gives number of the connectivities for the defined polygon
331     TInt GetNbConn(TInt theElemId) const;
332
333     //! Gives connectivities for polygon by its number (const version)
334     TCConnSlice GetConnSlice(TInt theElemId) const;
335     //! Gives connectivities for polygon by its number
336     TConnSlice GetConnSlice(TInt theElemId);
337   };
338
339   //---------------------------------------------------------------
340   //! Define a class representing MED_BALL structure element.
341   //
342   //  This could be a generic class for any structure element
343   //  holding any number of contant and variable attributes
344   //  but it's too hard to implement
345   //
346   struct MEDWRAPPER_EXPORT TBallInfo: 
347     virtual TCellInfo
348   {
349     TFloatVector myDiameters;
350   };
351
352   //---------------------------------------------------------------
353   typedef TVector<TCConnSlice> TCConnSliceArr;
354   typedef TVector<TConnSlice> TConnSliceArr;
355
356   //! Define a base class which represents MED Polyedre entity
357   struct MEDWRAPPER_EXPORT TPolyedreInfo: 
358     virtual TElemInfo
359   {
360     //! Defines the MED Entity where the polyedres belongs to
361     EEntiteMaillage myEntity; // MED_FACE|MED_MAILLE
362     //! Find out what MED ENTITY the MED Polyedres belong to
363     EEntiteMaillage GetEntity() const { return myEntity;}
364
365     //! Defines the MED Geometric type of the instance
366     EGeometrieElement myGeom; // ePOLYEDRE
367     //! Find out what MED geometrical type the MED Polyedres belong to
368     EGeometrieElement GetGeom() const { return ePOLYEDRE;}
369
370     //! Defines connectivity mode
371     EConnectivite myConnMode; // eNOD|eDESC(eDESC not used)
372     //! Find out in what connectivity the cells are written
373     EConnectivite GetConnMode() const { return myConnMode;}
374
375     PElemNum myConn; //!< Table de connectivities
376     PElemNum myFaces; //!< Table de faces indexes
377     PElemNum myIndex; //!< Table de indexes
378
379     //! Gives number of the faces for the defined polyedre (const version)
380     TInt GetNbFaces(TInt theElemId) const;
381     //! Gives number of the nodes for the defined polyedre
382     TInt GetNbNodes(TInt theElemId) const;
383
384     //! Gives sequence of the face connectivities for polyedre by its number (const version)
385     TCConnSliceArr GetConnSliceArr(TInt theElemId) const;
386     //! Gives sequence of the face connectivities for polyedre by its number
387     TConnSliceArr GetConnSliceArr(TInt theElemId);
388   };
389
390   //---------------------------------------------------------------
391   //! Define a base class which represents MED Field entity
392   struct MEDWRAPPER_EXPORT TFieldInfo: 
393     virtual TNameInfo
394   {
395     PMeshInfo myMeshInfo; //!< A reference to corresponding MED Mesh
396     //! Get a reference to corresponding MED Mesh
397     const PMeshInfo& GetMeshInfo() const { return myMeshInfo;}
398
399     ETypeChamp myType; //!< Defines type of MED Field
400     //! Find out what type of MED FIELD is used
401     ETypeChamp GetType() const { return myType;}
402
403     TInt myNbComp; //!< Defines number of components stored in the field
404     //! Get number of components for MED FIELD
405     TInt GetNbComp() const { return myNbComp;}
406
407     EBooleen myIsLocal; //!< Defines if the MED Field is local
408     //! Find out if MED FIELD is local or not
409     EBooleen GetIsLocal() const { return myIsLocal;}
410
411     TInt myNbRef; //!< Defines number of references of the field
412     //! Find out number of references for the MED FIELD
413     TInt GetNbRef() const { return myNbRef;}
414
415     TString myCompNames; //!< Contains names for each of MED Field components
416     //! Get name of the component by its order number
417     virtual std::string GetCompName(TInt theId) const = 0;
418     //! Set name for the component by its order number
419     virtual void SetCompName(TInt theId, const std::string& theValue) = 0;
420
421     TString myUnitNames; //!< Contains units for each of MED Field components
422     //! Get unit of the component by its order number
423     virtual std::string GetUnitName(TInt theId) const = 0;
424     //! Set unit for the component by its order number
425     virtual void SetUnitName(TInt theId, const std::string& theValue) = 0;
426
427   };
428
429
430   //---------------------------------------------------------------
431   //! Get dimension of the Gauss coordinates for the defined type of mesh cell
432   MEDWRAPPER_EXPORT
433   TInt
434   GetDimGaussCoord(EGeometrieElement theGeom);
435
436   //! Get number of referenced nodes for the defined type of mesh cell
437   MEDWRAPPER_EXPORT
438   TInt
439   GetNbRefCoord(EGeometrieElement theGeom);
440
441   typedef TFloatVector TWeight;
442
443   //! The class represents MED Gauss entity
444   struct MEDWRAPPER_EXPORT TGaussInfo: 
445     virtual TNameInfo,
446     virtual TModeSwitchInfo 
447   {
448     typedef boost::tuple<EGeometrieElement,std::string> TKey;
449     typedef boost::tuple<TKey,TInt> TInfo;
450     struct MEDWRAPPER_EXPORT TLess
451     {
452       bool
453       operator()(const TKey& theLeft, const TKey& theRight) const;
454
455       bool
456       operator()(const TGaussInfo& theLeft, const TGaussInfo& theRight) const;
457     };
458
459     //! Defines, which geometrical type the MED Gauss entity belongs to
460     EGeometrieElement myGeom; 
461     //! Find out what MED geometrical type the MED GAUSS entity belong to
462     EGeometrieElement GetGeom() const { return myGeom;}
463
464     //! Contains coordinates for the refereced nodes
465     TNodeCoord myRefCoord; 
466
467     //! Gives coordinates for the referenced node by its number
468     TCCoordSlice GetRefCoordSlice(TInt theId) const;
469     //! Gives coordinates for the referenced node by its number
470     TCoordSlice GetRefCoordSlice(TInt theId);
471
472     //! Contains coordinates for the Gauss points
473     TNodeCoord myGaussCoord;
474
475     //! Gives coordinates for the Gauss points by its number
476     TCCoordSlice GetGaussCoordSlice(TInt theId) const;
477     //! Gives coordinates for the Gauss points by its number
478     TCoordSlice GetGaussCoordSlice(TInt theId);
479
480     //! Contains wheights for the Gauss points
481     TWeight myWeight;
482
483     //! Gives number of the referenced nodes
484     TInt GetNbRef() const { return GetNbRefCoord(GetGeom());}
485
486     //! Gives dimension of the referenced nodes
487     TInt GetDim() const { return GetDimGaussCoord(GetGeom());}
488
489     //! Gives number of the Gauss Points
490     TInt GetNbGauss() const { return (TInt)(myGaussCoord.size()/GetDim());}
491   };
492
493
494   //---------------------------------------------------------------
495   typedef std::map<EGeometrieElement,PGaussInfo> TGeom2Gauss;
496   typedef std::map<EGeometrieElement,TInt> TGeom2NbGauss;
497
498   //! Define a base class which represents MED TimeStamp
499   struct MEDWRAPPER_EXPORT TTimeStampInfo: 
500     virtual TBase
501   {
502     PFieldInfo myFieldInfo; //!< A reference to correspondig MED Field
503     //! Get a reference to corresponding MED Field
504     const PFieldInfo& GetFieldInfo() const { return myFieldInfo;}
505
506     //! Defines the MED Entity where the MED TimeStamp belongs to
507     EEntiteMaillage myEntity;
508     //! Find out to what MED Entity the MED TimeStamp belong to
509     EEntiteMaillage GetEntity() const { return myEntity;}
510
511     //! Keeps map of number of cells per geometric type where the MED TimeStamp belongs to
512     TGeom2Size myGeom2Size;
513     //! Get map of number of cells per geometric type where the MED TimeStamp belongs to
514     const TGeom2Size& GetGeom2Size() const { return myGeom2Size;}
515
516     TGeom2NbGauss myGeom2NbGauss; //!< Keeps number of the Gauss Points for the MED TimeStamp
517     TInt GetNbGauss(EGeometrieElement theGeom) const; //!< Gives number of the Gauss Points for the MED TimeStamp
518
519     TInt myNumDt; //!< Keeps number in time for the MED TimeStamp
520     TInt GetNumDt() const { return myNumDt;} //!< Defines number in time for the MED TimeStamp
521
522     TInt myNumOrd; //!< Keeps number for the MED TimeStamp
523     TInt GetNumOrd() const { return myNumOrd;} //!< Defines number for the MED TimeStamp
524
525     TFloat myDt; //!< Keeps time for the MED TimeStamp
526     TFloat GetDt() const { return myDt;} //!< Defines time for the MED TimeStamp
527
528     //! Keeps map of MED Gauss entityes per geometric type
529     TGeom2Gauss myGeom2Gauss;
530     //! Gets a map of MED Gauss entityes per geometric type
531     const TGeom2Gauss& GetGeom2Gauss() const { return myGeom2Gauss;}
532
533     TString myUnitDt; //!< Defines unit for the time for the MED TimeStamp
534     //! Get unit of time for the MED TimeStamp
535     virtual std::string GetUnitDt() const = 0;
536     //! Set unit of time for the MED TimeStamp
537     virtual void SetUnitDt(const std::string& theValue) = 0;
538   };
539   
540
541   //---------------------------------------------------------------
542   //! The class represents MED Profile entity
543   struct MEDWRAPPER_EXPORT TProfileInfo: 
544     virtual TNameInfo
545   {
546     typedef std::string TKey;
547     typedef boost::tuple<TKey,TInt> TInfo;
548
549     EModeProfil myMode; //!< Keeps mode for the MED Profile
550     //! Find out what mode of MED Profile is used
551     EModeProfil GetMode() const { return myMode;}
552     //! Set mode for the MED Profile
553     void SetMode(EModeProfil theMode) { myMode = theMode;}
554
555     PElemNum myElemNum; //!< Keeps sequence of cell by its number which belong to the profile
556     //! Get number of mesh elelemts by its order number
557     TInt GetElemNum(TInt theId) const;
558     //! Set number of mesh elelemts by its order number
559     void SetElemNum(TInt theId, TInt theVal);
560
561     //! Find out if the MED Profile defined
562     bool IsPresent() const { return GetName() != "";}
563
564     //! Find out size of the MED Profile
565     TInt GetSize() const { return (TInt)myElemNum->size();}
566   };
567
568
569   //---------------------------------------------------------------
570   //! The class is a helper one. It provide safe and flexible way to get access to values for a MED TimeStamp
571   struct MEDWRAPPER_EXPORT TMeshValueBase:
572     virtual TModeSwitchInfo 
573   {
574     TInt myNbElem;
575     TInt myNbComp;
576     TInt myNbGauss;
577     TInt myStep;
578
579     TMeshValueBase();
580
581     //! Initialize the class
582     void
583     Allocate(TInt theNbElem,
584              TInt theNbGauss,
585              TInt theNbComp,
586              EModeSwitch theMode = eFULL_INTERLACE);
587
588     //! Returns size of the value container
589     size_t
590     GetSize() const;
591     
592     //! Returns MED interpetation of the value size
593     size_t
594     GetNbVal() const;
595     
596     //! Returns number of Gauss Points bounded with the value
597     size_t
598     GetNbGauss() const;
599     
600     //! Returns step inside of the data array
601     size_t
602     GetStep() const;
603     
604     //! Returns bare pointer on the internal value representation
605     virtual
606     unsigned char*
607     GetValuePtr() = 0;
608   };
609
610   //---------------------------------------------------------------
611   //! The class is a helper one. It provide safe and flexible way to get access to values for a MED TimeStamp
612   template<class TValueType>
613   struct TTMeshValue:
614     virtual TMeshValueBase 
615   {
616     typedef TValueType TValue;
617     typedef typename TValueType::value_type TElement;
618
619     typedef TSlice<TElement> TValueSlice;
620     typedef TCSlice<TElement> TCValueSlice;
621     
622     typedef TVector<TCValueSlice> TCValueSliceArr;
623     typedef TVector<TValueSlice> TValueSliceArr;
624     
625     TValue myValue;
626
627     //! Initialize the class
628     void
629     Allocate(TInt theNbElem,
630              TInt theNbGauss,
631              TInt theNbComp,
632              EModeSwitch theMode = eFULL_INTERLACE)
633     {
634       TMeshValueBase::Allocate(theNbElem, theNbGauss, theNbComp, theMode);
635       myValue.resize(theNbElem * this->GetStep());
636     }
637
638     //! Returns bare pointer on the internal value representation
639     virtual
640     unsigned char*
641     GetValuePtr()
642     {
643       return (unsigned char*)&myValue[0];
644     }
645
646     //! Returns bare pointer on the internal value representation
647     virtual
648     TElement*
649     GetPointer()
650     {
651       return &myValue[0];
652     }
653
654     //! Returns bare pointer on the internal value representation
655     virtual
656     const TElement*
657     GetPointer() const
658     {
659       return &myValue[0];
660     }
661
662     //! Iteration through Gauss Points by their components
663     TCValueSliceArr
664     GetGaussValueSliceArr(TInt theElemId) const
665     {
666       TCValueSliceArr aValueSliceArr(myNbGauss);
667       if(GetModeSwitch() == eFULL_INTERLACE){
668         TInt anId = theElemId * myStep;
669         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
670           aValueSliceArr[aGaussId] =
671             TCValueSlice(myValue, std::slice(anId, myNbComp, 1));
672           anId += myNbComp;
673         }
674       }
675       else{
676         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
677           aValueSliceArr[aGaussId] =
678             TCValueSlice(myValue, std::slice(theElemId, myNbComp, myStep));
679         }
680       }
681       return aValueSliceArr;
682     }
683
684     //! Iteration through Gauss Points by their components
685     TValueSliceArr 
686     GetGaussValueSliceArr(TInt theElemId)
687     {
688       TValueSliceArr aValueSliceArr(myNbGauss);
689       if(GetModeSwitch() == eFULL_INTERLACE){
690         TInt anId = theElemId*myStep;
691         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
692           aValueSliceArr[aGaussId] =
693             TValueSlice(myValue, std::slice(anId, myNbComp, 1));
694           anId += myNbComp;
695         }
696       }
697       else{
698         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
699           aValueSliceArr[aGaussId] =
700             TValueSlice(myValue, std::slice(theElemId, myNbComp, myStep));
701         }
702       }
703       return aValueSliceArr;
704     }
705
706     //! Iteration through components by corresponding Gauss Points
707     TCValueSliceArr
708     GetCompValueSliceArr(TInt theElemId) const
709     {
710       TCValueSliceArr aValueSliceArr(myNbComp);
711       if(GetModeSwitch() == eFULL_INTERLACE){
712         TInt anId = theElemId*myStep;
713         for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){
714           aValueSliceArr[aCompId] =
715             TCValueSlice(myValue, std::slice(anId, myNbGauss, myNbComp));
716           anId += 1;
717         }
718       }
719       else{
720         for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){
721           aValueSliceArr[aCompId] =
722             TCValueSlice(myValue, std::slice(theElemId, myNbGauss, myStep));
723         }
724       }
725       return aValueSliceArr;
726     }
727
728     //! Iteration through components by corresponding Gauss Points
729     TValueSliceArr 
730     GetCompValueSliceArr(TInt theElemId)
731     {
732       if(GetModeSwitch() == eFULL_INTERLACE){
733         TValueSliceArr aValueSliceArr(myNbComp);
734         TInt anId = theElemId*myStep;
735         for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){
736           aValueSliceArr[aCompId] =
737             TValueSlice(myValue, std::slice(anId, myNbGauss, myNbComp));
738           anId += 1;
739         }
740         return aValueSliceArr;
741       }
742       else{
743         TValueSliceArr aValueSliceArr(myNbGauss);
744         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
745           aValueSliceArr[aGaussId] =
746             TValueSlice(myValue,std::slice(theElemId, myNbComp, myStep));
747         }
748         return aValueSliceArr;
749       }
750     }
751   };
752
753   typedef TTMeshValue<TFloatVector> TFloatMeshValue;
754   typedef TTMeshValue<TIntVector> TIntMeshValue;
755
756   //---------------------------------------------------------------
757   // Backward compatibility  declarations
758   typedef TFloatVector TValue;
759   typedef TSlice<TFloat> TValueSlice;
760   typedef TCSlice<TFloat> TCValueSlice;
761   
762   typedef TVector<TCValueSlice> TCValueSliceArr;
763   typedef TVector<TValueSlice> TValueSliceArr;
764     
765   typedef TFloatMeshValue TMeshValue;
766   typedef std::map<EGeometrieElement,TMeshValue> TGeom2Value;
767
768   //---------------------------------------------------------------
769   typedef std::map<EGeometrieElement,PProfileInfo> TGeom2Profile;
770   typedef std::set<EGeometrieElement> TGeom;
771
772   //! The class is a base class for MED TimeStamp values holder
773   struct MEDWRAPPER_EXPORT TTimeStampValueBase: 
774     virtual TModeSwitchInfo 
775   {
776     //! A reference to correspondig MED TimeStamp
777     PTimeStampInfo myTimeStampInfo;
778     //!< Get a reference to correspondig MED TimeStamp
779     const PTimeStampInfo& GetTimeStampInfo() const { return myTimeStampInfo;}
780
781     //! Keeps set of MED EGeometrieElement which contains values for the timestamp
782     TGeomSet myGeomSet;
783     const TGeomSet& GetGeomSet() const { return myGeomSet;}
784
785     //! Keeps map of MED Profiles per geometric type
786     TGeom2Profile myGeom2Profile;
787     //! Gets a map of MED Profiles per geometric type
788     const TGeom2Profile& GetGeom2Profile() const { return myGeom2Profile;}
789
790     //! Gets type of the champ
791     virtual 
792     ETypeChamp
793     GetTypeChamp() const = 0;
794
795     //! Allocates values for the given geometry
796     virtual 
797     void
798     AllocateValue(EGeometrieElement theGeom,
799                   TInt theNbElem,
800                   TInt theNbGauss,
801                   TInt theNbComp,
802                   EModeSwitch theMode = eFULL_INTERLACE) = 0;
803     
804     virtual 
805     size_t
806     GetValueSize(EGeometrieElement theGeom) const = 0;
807     
808     virtual 
809     size_t
810     GetNbVal(EGeometrieElement theGeom) const = 0;
811     
812     virtual 
813     size_t
814     GetNbGauss(EGeometrieElement theGeom) const = 0;
815
816     virtual 
817     unsigned char*
818     GetValuePtr(EGeometrieElement theGeom) = 0;
819   };
820
821
822   //---------------------------------------------------------------
823   //! The class implements a container for MED TimeStamp values
824   template<class TMeshValueType>
825   struct TTimeStampValue: 
826     virtual TTimeStampValueBase 
827   {
828     typedef TMeshValueType TTMeshValue;
829     typedef SharedPtr<TMeshValueType> PTMeshValue;
830     typedef typename TMeshValueType::TElement TElement;
831     typedef std::map<EGeometrieElement, PTMeshValue> TTGeom2Value;
832
833     ETypeChamp myTypeChamp; //<! Keeps type of the champ
834
835     //! Gets type of the champ
836     virtual 
837     ETypeChamp
838     GetTypeChamp() const
839     {
840       return myTypeChamp;
841     }
842
843     //! Keeps map of MED TimeStamp values per geometric type (const version)
844     TTGeom2Value myGeom2Value;
845
846     const TTGeom2Value& 
847     GetGeom2Value() const
848     {
849       return myGeom2Value;
850     }
851
852     //! Gets MED TimeStamp values for the given geometric type (const version)
853     const PTMeshValue& 
854     GetMeshValuePtr(EGeometrieElement theGeom) const
855     {
856       typename TTGeom2Value::const_iterator anIter = myGeom2Value.find(theGeom);
857       if(anIter == myGeom2Value.end())
858         EXCEPTION(std::runtime_error,"TTimeStampValue::GetMeshValuePtr - myGeom2Value.find(theGeom) fails");
859       return anIter->second;
860     }
861
862     //! Gets MED TimeStamp values for the given geometric type
863     PTMeshValue& 
864     GetMeshValuePtr(EGeometrieElement theGeom)
865     {
866       myGeomSet.insert(theGeom);
867       if(myGeom2Value.find(theGeom) == myGeom2Value.end()){
868         myGeom2Value[theGeom] = PTMeshValue(new TTMeshValue());
869         return myGeom2Value[theGeom];
870       }
871       return myGeom2Value[theGeom];
872     }
873
874     //! Gets MED TimeStamp values for the given geometric type (const version)
875     const TTMeshValue& 
876     GetMeshValue(EGeometrieElement theGeom) const
877     {
878       return *(this->GetMeshValuePtr(theGeom));
879     }
880
881     //! Gets MED TimeStamp values for the given geometric type
882     TTMeshValue& 
883     GetMeshValue(EGeometrieElement theGeom)
884     {
885       return *(this->GetMeshValuePtr(theGeom));
886     }
887   };
888
889
890   //---------------------------------------------------------------
891   typedef TTimeStampValue<TFloatMeshValue> TFloatTimeStampValue;
892   typedef SharedPtr<TFloatTimeStampValue> PFloatTimeStampValue;
893
894   PFloatTimeStampValue MEDWRAPPER_EXPORT
895   CastToFloatTimeStampValue(const PTimeStampValueBase& theTimeStampValue);
896
897   typedef TTimeStampValue<TIntMeshValue> TIntTimeStampValue;
898   typedef SharedPtr<TIntTimeStampValue> PIntTimeStampValue;
899   
900   PIntTimeStampValue MEDWRAPPER_EXPORT
901   CastToIntTimeStampValue(const PTimeStampValueBase& theTimeStampValue);
902
903
904   //---------------------------------------------------------------
905   template<class TMeshValueTypeFrom, class TMeshValueTypeTo>
906   void
907   CopyTimeStampValue(SharedPtr<TTimeStampValue<TMeshValueTypeFrom> > theTimeStampValueFrom,
908                      SharedPtr<TTimeStampValue<TMeshValueTypeTo> > theTimeStampValueTo)
909   {
910     typedef TTimeStampValue<TMeshValueTypeFrom> TimeStampValueTypeFrom;
911     typedef TTimeStampValue<TMeshValueTypeTo> TimeStampValueTypeTo;
912     typedef typename TMeshValueTypeTo::TElement TElementTo;
913
914     typename TimeStampValueTypeFrom::TTGeom2Value& aGeom2Value = theTimeStampValueFrom->myGeom2Value;
915     typename TimeStampValueTypeFrom::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
916     for(; anIter != aGeom2Value.end(); anIter++){
917       const EGeometrieElement& aGeom = anIter->first;
918       const typename TimeStampValueTypeFrom::TTMeshValue& aMeshValue = *anIter->second;
919       typename TimeStampValueTypeTo::TTMeshValue& aMeshValue2 = theTimeStampValueTo->GetMeshValue(aGeom);
920       aMeshValue2.Allocate(aMeshValue.myNbElem, 
921                            aMeshValue.myNbGauss, 
922                            aMeshValue.myNbComp,
923                            aMeshValue.myModeSwitch);
924       const typename TimeStampValueTypeFrom::TTMeshValue::TValue& aValue = aMeshValue.myValue;
925       typename TimeStampValueTypeTo::TTMeshValue::TValue& aValue2 = aMeshValue2.myValue;
926       TInt aSize = aValue.size();
927       for(TInt anId = 0; anId < aSize; anId++)
928         aValue2[anId] = TElementTo(aValue[anId]);
929     }
930   }
931
932   template<class TMeshValueType>
933   void
934   CopyTimeStampValue(SharedPtr<TTimeStampValue<TMeshValueType> > theTimeStampValueFrom,
935                      SharedPtr<TTimeStampValue<TMeshValueType> > theTimeStampValueTo)
936   {
937     typedef TTimeStampValue<TMeshValueType> TimeStampValueType;
938     typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValueFrom->myGeom2Value;
939     typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
940     for(; anIter != aGeom2Value.end(); anIter++){
941       const EGeometrieElement& aGeom = anIter->first;
942       const typename TimeStampValueType::TTMeshValue& aMeshValue = *anIter->second;
943       typename TimeStampValueType::TTMeshValue& aMeshValue2 = theTimeStampValueTo->GetMeshValue(aGeom);
944       aMeshValue2 = aMeshValue;
945     }
946   }
947
948   //---------------------------------------------------------------
949   inline
950   void
951   CopyTimeStampValueBase(const PTimeStampValueBase& theValueFrom, 
952                          const PTimeStampValueBase& theValueTo)
953   {
954     if(theValueFrom->GetTypeChamp() == theValueTo->GetTypeChamp()){
955       if(theValueFrom->GetTypeChamp() == eFLOAT64)
956         CopyTimeStampValue<TFloatMeshValue>(theValueFrom, theValueTo);
957       else if(theValueFrom->GetTypeChamp() == eINT)
958         CopyTimeStampValue<TIntMeshValue>(theValueFrom, theValueTo);
959     }else{
960       if(theValueFrom->GetTypeChamp() == eFLOAT64 && theValueTo->GetTypeChamp() == eINT)
961         CopyTimeStampValue<TFloatMeshValue, TIntMeshValue>(theValueFrom, theValueTo);
962       else if(theValueFrom->GetTypeChamp() == eINT && theValueTo->GetTypeChamp() == eFLOAT64)
963         CopyTimeStampValue<TIntMeshValue, TFloatMeshValue>(theValueFrom, theValueTo);
964     }
965   }
966
967
968   //---------------------------------------------------------------
969   // Backward compatibility  declarations
970   typedef TFloatTimeStampValue TTimeStampVal;
971   typedef PFloatTimeStampValue PTimeStampVal;
972
973   //---------------------------------------------------------------
974   typedef std::map<TInt,TFloatVector> TIndexes;
975   typedef std::map<TInt,TString> TNames;
976   
977   //! Define a base class which represents MED Grille (structured mesh)
978   struct MEDWRAPPER_EXPORT TGrilleInfo:
979     virtual TModeSwitchInfo
980   {
981
982     PMeshInfo myMeshInfo;
983     const PMeshInfo& GetMeshInfo() const { return myMeshInfo;} 
984
985     TNodeCoord myCoord; //!< Contains all nodal coordinates, now used only for eGRILLE_STANDARD
986     //! Gives coordinates for mesh nodes (const version)
987     const TNodeCoord& GetNodeCoord() const;
988     TNodeCoord& GetNodeCoord();
989     //! Gives coordinates for mesh node by its number, array index from 0
990     TNodeCoord GetCoord(TInt theId);
991     //! Gives ids of nodes for mesh cell or sub-cell by its number, array index from 0
992     TIntVector GetConn(TInt theId, const bool isSub=false);
993
994     EGrilleType myGrilleType; //!< Defines grille type (eGRILLE_CARTESIENNE,eGRILLE_POLAIRE,eGRILLE_STANDARD)
995     //!Gets grille type (const version)
996     const EGrilleType& GetGrilleType() const;
997     //!Gets grille type
998     EGrilleType GetGrilleType();
999     //!Sets grille type
1000     void SetGrilleType(EGrilleType theGrilleType);
1001
1002
1003     
1004     TString myCoordNames; //!< Contains names for the coordinate dimensions
1005     //! Get name of the coordinate dimension by its order number
1006     virtual std::string GetCoordName(TInt theId) const = 0 ;
1007     //! Set name of the coordinate dimension by its order number
1008     virtual void SetCoordName(TInt theId, const std::string& theValue) = 0;
1009
1010     TString myCoordUnits; //!< Contains units for the coordinate dimensions
1011     //! Get name of unit for the coordinate dimension by its order number
1012     virtual std::string GetCoordUnit(TInt theId) const = 0;
1013     //! Set name of unit for the coordinate dimension by its order number
1014     virtual void SetCoordUnit(TInt theId, const std::string& theValue) = 0;
1015
1016
1017     //! Map of index of axes and Table of indexes for certain axe, now used for eGRILLE_CARTESIENNE and eGRILLE_POLAIRE
1018     TIndexes myIndixes;
1019     //!Gets a map of Tables (const version)
1020     const TIndexes& GetMapOfIndexes() const ;
1021     //!Gets a map of Tables
1022     TIndexes& GetMapOfIndexes();
1023     //!Gets a Table of indexes for certain axe(const version)
1024     const TFloatVector& GetIndexes(TInt theAxisNumber) const;
1025     //!Gets a Table of indexes for certain axe
1026     TFloatVector& GetIndexes(TInt theAxisNumber);
1027     //!Gets a number of indices per axe
1028     TInt GetNbIndexes(TInt theAxisNumber);
1029     
1030     TInt GetNbNodes();//! Return count of all points
1031     TInt GetNbCells();//! Return count of all cells
1032     TInt GetNbSubCells();//! Return count of all entities of <mesh dimension-1>
1033     EGeometrieElement GetGeom();//! Return geometry of cells (calculated from mesh dimension)
1034     EGeometrieElement GetSubGeom();//! Return geometry of subcells (calculated from mesh dimension)
1035     EEntiteMaillage GetEntity();//! Return entity (eMAILLE)
1036     EEntiteMaillage GetSubEntity();//! Return sub entity
1037
1038     /*!
1039      *Vector of grille structure (Example: {3,4,5}, 3 nodes in X axe, 4 nodes in Y axe, ...)
1040      */
1041     TIntVector myGrilleStructure;
1042     //!Gets grille structure(const version)
1043     const TIntVector& GetGrilleStructure() const;
1044     //!Gets grille structure
1045     TIntVector GetGrilleStructure();
1046     //!Sets the grille structure of theAxis axe to theNb.
1047     void SetGrilleStructure(TInt theAxis,TInt theNb);
1048     
1049     /*!
1050      *Defines sequence MED Family indexes for corresponding mesh entites
1051      */
1052     TElemNum myFamNum; 
1053     //! Get number of a MED FAMILY by order number of the mesh element
1054     TInt GetFamNum(TInt theId) const;
1055     //! Set number of a MED FAMILY for the mesh element with the  order number
1056     void SetFamNum(TInt theId, TInt theVal);
1057     
1058     /*!
1059      *Defines sequence MED Family indexes for sub entites
1060      */
1061     TElemNum myFamSubNum; 
1062     //! Get number of a MED FAMILY by order number of sub element
1063     TInt GetFamSubNum(TInt theId) const;
1064     //! Set number of a MED FAMILY for theId-th sub element
1065     void SetFamSubNum(TInt theId, TInt theVal);
1066     
1067     /*!
1068      *Defines sequence MED Family indexes for corresponding mesh nodes
1069      */
1070     TElemNum myFamNumNode;
1071     //! Get number of a MED FAMILY by order number of the mesh node
1072     TInt GetFamNumNode(TInt theId) const;
1073     //! Set number of a MED FAMILY for the mesh node with the  order number
1074     void SetFamNumNode(TInt theId, TInt theVal);
1075
1076   };
1077
1078
1079 }
1080
1081 #endif