]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPR/MULTIPR_Field.hxx
Salome HOME
*** empty log message ***
[modules/multipr.git] / src / MULTIPR / MULTIPR_Field.hxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_Field.hxx
6  *
7  * \brief   Class Field used to wrap MED file fields.
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13
14 #ifndef MULTIPR_FIELD_HXX
15 #define MULTIPR_FIELD_HXX
16
17 //*****************************************************************************
18 // Includes section
19 //*****************************************************************************
20
21 extern "C"
22 {
23     #include "med.h"
24 }
25
26 #include <string>
27 #include <vector>
28 #include <set>
29
30
31 namespace multipr
32 {
33
34
35 //*****************************************************************************
36 // Class Field
37 //*****************************************************************************
38
39 class Field
40 {
41 public:
42
43     /** 
44      * Builds an empty field (default constructor).
45      */
46     Field();
47     
48     /**
49      * Destructor. Removes everything.
50      */
51     ~Field();
52     
53     /**
54      * Resets this object in its state by default (empty). Cleans memory.
55      */
56     void reset();
57     
58     //---------------------------------------------------------------------
59     // Basic accessors/mutators
60     //---------------------------------------------------------------------
61     
62     /**
63      * Returns true iff this field is empty (no data).
64      * \return true if this field is empty, false otherwise.
65      */
66     bool isEmpty() const;
67     
68     /**
69      * Returns true iff this field apply on nodes (otherwise, information are related to elements).
70      * \return true iff this field apply on nodes.
71      */
72     bool isFieldOnNodes() const { return (mEntity == MED_NOEUD); }
73     
74     /**
75      * Returns the name of this Field.
76      * \return the name of this Field.
77      */
78     const char* getName() const { return mName; }
79     
80     /**
81      * Returns the number of time steps in this Field.
82      * \return the number of time steps in this Field.
83      */
84     int getNumberOfTimeSteps() const { return mNGauss.size(); }
85     
86     /**
87      * Returns the numeric type of information contained in this Field (e.g. MED_FLOAT64).
88      * \return the numeric type of this Field.
89      */
90     med_type_champ getType() const { return mType; }
91     
92     /**
93      * Returns the number of components of this Field.
94      * \return the number of components of this Field.
95      */
96     int getNumberOfComponents() const { return mNumComponents; }
97     
98     /**
99      * Returns the number of Gauss points for each element at the given time step.
100      * \param  pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION].
101      * \return number of Gauss points in the elements of this Field at the given iteration.
102      * \throw  IndexOutOfBoundsException if pTimeStepIt not in [1..MAX_ITERATION].
103      */
104     int getNumberOfGaussPointsByElement(int pTimeStepIt) const;
105     
106     /**
107      * Returns the name of the Gauss localization related to the given iteration.
108      * \param  pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION].
109      * \return the name of the Gauss localization related to the given iteration.
110      * \throw  IndexOutOfBoundsException if pTimeStepIt not in [1..MAX_ITERATION].
111      */
112     const std::string& getNameGaussLoc(int pTimeStepIt) const;
113     
114     /**
115      * Returns a pointer towards the first value of this Field for the given element at the given time step.
116      * \param  pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION].
117      * \param  pIndex      index of the element; must be >= 1.
118      * \return the value of this Field for the given element at the given time step.
119      * \throw  IndexOutOfBoundsException if pTimeStepIt or pIndex are invalid.
120      */
121     const unsigned char* getValue(int pTimeStepIt, int pIndex) const;
122     
123     //---------------------------------------------------------------------
124     // Algorithms
125     //---------------------------------------------------------------------
126     
127     /**
128      * Creates a subset of this Field restricted to a set of elements (NODES or CELLS).
129      * This method performs a projection of this Field on the given set of elements.     
130      * \param  pSetIndices WARNING: indices start at 1.
131      * \return a new Field restricted to the given set of elements.
132      */
133     Field* extractSubSet(const std::set<med_int>& pSetIndices) const;
134     
135     /**
136      * Adds the set of GaussLoc used by this Field into the given set.
137      * \param  pSetOfGauss any set of Gauss localisation.
138      */
139     void getSetOfGaussLoc(std::set<std::string>& pSetOfGaussLoc) const;
140
141     //---------------------------------------------------------------------
142     // I/O
143     //---------------------------------------------------------------------
144     
145     /**
146      * Reads a field from a MED file.
147      * If the field is not related to the given mesh, the result is an empty field.
148      * \param  pMEDfile  any valid MED file opened for reading.
149      * \param  pIndex    index of the field to be read; must be >= 1.
150      * \param  pMeshName name of the mesh (a field is always related to a mesh).
151      * \throw  IOException if any i/o error occurs.
152      */
153     void readMED(med_idt pMEDfile, med_int pIndex, char* pMeshName);
154     
155     /**
156      * Writes this field to a MED file. The field is linked to the given mesh.
157      * WARNING: all related Gauss info must have been added to the MED file before.
158      * \param  pMEDfile  any valid MED file opened for writing.
159      * \param  pMeshName name of the mesh.
160      * \throw  IOException if any i/o error occurs.
161      */
162     void writeMED(med_idt pMEDfile, char* pMeshName);
163     
164     /**
165      * Sets the flag which control the stream operator <<.
166      * \param  pFlag new flag value.
167      */
168     void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } 
169     
170     /**
171      * Dumps any Field to the given output stream.
172      * \param  pOs any output stream.
173      * \param  pF  any Field.
174      * \return the output stream pOs.
175      */
176     friend std::ostream& operator<<(std::ostream& pOs, Field& pF);
177     
178 private:
179
180     /**
181      * Reads all the information related to its field and a given time step (by its index).
182      * \param  pMEDfile           MED file handle.
183      * \param  pNumberOfTimeSteps number of timesteps (iteration) to be read.
184      * \param  pMeshName          name of the mesh.
185      * \throw  IOException if any i/o error occurs.
186      */
187     void readMEDtimeSteps(med_idt pMEDfile, med_int pNumberOfTimeSteps, char* pMeshName);
188     
189 private:
190     
191     char                         mName[MED_TAILLE_NOM + 1];
192     med_entite_maillage          mEntity;      // type of entity, e.g. MED_MAILLE
193     med_geometrie_element        mGeom;        // type of primitives, e.g. MED_TETRA10 (MED_NONE for a field on nodes)
194     med_type_champ               mType;        // type of field, e.g. MED_FLOAT64, MED_INT32
195     int                          mSizeOfType;  // 8 for MED_FLOAT64, 4 for MED_INT32, etc.
196     med_int                      mNumComponents;
197     std::string                  mStrComponent;
198     std::string                  mStrUnit;
199     
200     // Information related to time steps.
201     // Each vector should contain the same number of elements.
202     // Number of time step = mNGauss.size() = mDT.size() = ...
203     
204     std::vector<med_int>         mNGauss;        /**< For each time step, number of Gauss points in the field. */
205     std::vector<med_float>       mDT;            /**< For each time step, value of time step. */
206     std::vector<med_int>         mNumDT;         /**< For each time step, iteration number. */
207     std::vector<std::string>     mDTUnit;        /**< For each time step, units. */
208     std::vector<med_int>         mNumO;          /**< For each time step, order number. */
209     std::vector<std::string>     mGaussLoc;      /**< For each time step, name of Gauss localization to be used (empty if none). */
210     std::vector<std::string>     mProfil;        /**< For each time step, name of the profil to be used (empty if none). */
211     std::vector<int>             mSizeOfData;    /**< For each time step, sizeof data (mVal) in bytes. */
212     std::vector<med_int>         mNVal;          /**< For each time step, number of values. */
213     std::vector<unsigned char*>  mVal;           /**< For each time step, raw data; can be MED_FLOAT64, MED_INT32, etc. see mType. */
214
215     bool                         mFlagPrintAll;  /**< Flag to control the behaviour of the stream operator <<. */
216     
217 private:
218
219     // do not allow copy constructor
220     Field(const Field&);
221     
222     // do not allow copy
223     Field& operator=(const Field&);
224     
225     // do not allow operator ==
226     bool operator==(const Field&); 
227     
228 }; // class Field
229
230
231 } // namespace MULTIPR
232
233
234 #endif // MULTIPR_FIELD_HXX
235
236 // EOF