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