1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
5 * \file MULTIPR_Field.hxx
7 * \brief Class Field used to wrap MED file fields.
9 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
14 #ifndef MULTIPR_FIELD_HXX
15 #define MULTIPR_FIELD_HXX
17 //*****************************************************************************
19 //*****************************************************************************
35 //*****************************************************************************
37 //*****************************************************************************
44 * Builds an empty field (default constructor).
49 * Destructor. Removes everything.
54 * Resets this object in its state by default (empty). Cleans memory.
58 //---------------------------------------------------------------------
59 // Basic accessors/mutators
60 //---------------------------------------------------------------------
63 * Returns true iff this field is empty (no data).
64 * \return true if this field is empty, false otherwise.
69 * Returns true iff this field apply on nodes (otherwise, information are related to elements).
70 * \return true iff this field apply on nodes.
72 bool isFieldOnNodes() const { return (mEntity == MED_NOEUD); }
75 * Returns the name of this Field.
76 * \return the name of this Field.
78 const char* getName() const { return mName; }
81 * Returns the number of time steps in this Field.
82 * \return the number of time steps in this Field.
84 int getNumberOfTimeSteps() const { return mNGauss.size(); }
87 * Returns the numeric type of information contained in this Field (e.g. MED_FLOAT64).
88 * \return the numeric type of this Field.
90 med_type_champ getType() const { return mType; }
93 * Returns the number of components of this Field.
94 * \return the number of components of this Field.
96 int getNumberOfComponents() const { return mNumComponents; }
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].
104 int getNumberOfGaussPointsByElement(int pTimeStepIt) const;
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].
112 const std::string& getNameGaussLoc(int pTimeStepIt) const;
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.
121 const unsigned char* getValue(int pTimeStepIt, int pIndex) const;
123 //---------------------------------------------------------------------
125 //---------------------------------------------------------------------
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.
133 Field* extractSubSet(const std::set<med_int>& pSetIndices) const;
136 * Adds the set of GaussLoc used by this Field into the given set.
137 * \param pSetOfGauss any set of Gauss localisation.
139 void getSetOfGaussLoc(std::set<std::string>& pSetOfGaussLoc) const;
141 //---------------------------------------------------------------------
143 //---------------------------------------------------------------------
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.
153 void readMED(med_idt pMEDfile, med_int pIndex, char* pMeshName);
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.
162 void writeMED(med_idt pMEDfile, char* pMeshName);
165 * Sets the flag which control the stream operator <<.
166 * \param pFlag new flag value.
168 void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; }
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.
176 friend std::ostream& operator<<(std::ostream& pOs, Field& pF);
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.
187 void readMEDtimeSteps(med_idt pMEDfile, med_int pNumberOfTimeSteps, char* pMeshName);
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;
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() = ...
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. */
215 bool mFlagPrintAll; /**< Flag to control the behaviour of the stream operator <<. */
219 // do not allow copy constructor
223 Field& operator=(const Field&);
225 // do not allow operator ==
226 bool operator==(const Field&);
231 } // namespace MULTIPR
234 #endif // MULTIPR_FIELD_HXX