1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
5 * \file MULTIPR_Elements.hxx
7 * \brief Class Elements = table of elements in a mesh.
8 * All elements share the same type (e.g. MED_MAILLE) and the same geometric description (e.g. TETRA10).
9 * Each element has a family and a table of connectivity.
10 * Optional: each element has a name and an id.
12 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
17 #ifndef MULTIPR_ELEMENTS_HXX
18 #define MULTIPR_ELEMENTS_HXX
20 //*****************************************************************************
22 //*****************************************************************************
36 //*****************************************************************************
38 //*****************************************************************************
43 //*****************************************************************************
45 //*****************************************************************************
52 * Builds an empty set of elements (default constructor).
57 * Builds an empty set of elements with of the defined geometry type.
58 * \param pGeomType The geometry type.
60 Elements(med_geometrie_element pGeomType);
64 * Destructor. Removes everything.
69 * Resets this object in its state by default (empty). Cleans memory.
73 //---------------------------------------------------------------------
74 // Basic accessors/mutators
75 //---------------------------------------------------------------------
78 * Returns true iff this object contains no elements (table of elements is empty).
79 * \return true iff this object contains no elements.
81 bool isEmpty() const { return (mNum == 0); }
84 * Returns true iff elements have a name.
85 * \return true iff elements have a name.
87 bool isNames() const { return (mNames != NULL); }
90 * Returns true iff elements have an identifier (= a number).
91 * \return true iff elements have an identifier (= a number).
93 bool isIdentifiers() const { return (mId != NULL); }
96 * Returns the number of elements.
97 * \return the number of elements.
99 int getNumberOfElements() const { return mNum; }
102 * Returns the type of primitives (e.g. MED_TETRA10).
103 * \return the type of primitives
105 med_geometrie_element getTypeOfPrimitives() const { return mGeom; }
108 * Returns the number of nodes that composed an element.
109 * \return the number of nodes that composed an element.
111 int getNumberOfNodesByElement() const { return mNumNodesByElt; }
114 * Returns the family associated with an element.
115 * \param pIndex index of any element in [0..NUMBER_OF_ELEMENTS-1].
116 * \return the family associated with an element.
117 * \throw IndexOutOfBoundsException if pIndex is invalid.
119 med_int getFamilyIdentifier(med_int pIndex) const;
122 * Returns the connectivity of one element.
123 * \param pIndex must be in [0..NUMBER_OF_ELEMENTS-1].
124 * \return a pointer towards the table of connectivity of the element.
125 * \throw IndexOutOfBoundsException if pIndex is invalid.
127 const med_int* getConnectivity(int pIndex) const;
130 * Returns the coordinates of all the nodes of one element.
131 * \param pIndexElt must be in [0..NUMBER_OF_ELEMENTS-1].
132 * \param pNodes table of nodes, used to retrieve coordinates.
133 * \param pCoo (out) table of coordinates of nodes (e.g. 30 = 3 * 10 med_float for a TETRA10).
134 * \param pFirst only get the pFirst coordinates.
135 * \throw IndexOutOfBoundsException if pIndex is invalid.
137 void getCoordinates(med_int pIndexElt, const Nodes* pNodes, med_float* pCoo, int pFirst = 100) const;
139 //---------------------------------------------------------------------
141 //---------------------------------------------------------------------
144 * Constructor. Creates a subset of this set of elements from a set of indices.
145 * \param pSetIndices set of indices (start at 1).
146 * \return a restriction of this set of elements.
148 Elements* extractSubSet(const std::set<med_int>& pSetIndices) const;
151 * Create a subset of elements containing the given nodes.
152 * \param pSetOfNodes The set of nodes.
153 * \param pSubSetOfElements The subset of elements to fill.
154 * \throw IllegalStateException if pSetOfNodes and pSubSetOfElements are not different.
156 void extractSubSetFromNodes(const std::set<med_int>& pSetOfNodes, std::set<med_int>& pSubSetOfElements) const;
159 * Returns the set of indices (starting at 1) of all nodes used by this set of elements.
160 * \return the set of indices of all nodes used by this set of elements.
162 const std::set<med_int>& getSetOfNodes();
165 * Returns the set of families referenced by this set of elements.
166 * Each family is described by its identifier.
167 * \return Returns the set of families referenced by this set of elements.
169 std::set<med_int> getSetOfFamilies() const;
172 * Remaps this set of elements such that indices of nodes are continous 1 2 3 4 5 ... *
173 * This method is intended to be used after extractSubSet().
179 * Remaps this set of elements such that indices of nodes are continous 1 2 3 4 5 ... *
180 * This method is intended to be used after extractSubSet().
181 * This remap method allows to use the same set of nodes with several mesh type.
182 * \param pSetOfNodes The set of nodes index extracted from the original med file.
184 void remap(std::set<med_int>& pSetOfNodes);
188 * Builds a new set of elements by merging two set of elements (this and pElements) if possible.
189 * Merge is partial because Id and Names are not take into account.
190 * \param pElements any set of nodes to be merged with this.
192 * \return a new set of nodes.
193 * \throw IllegalStateException if the two sets of elements are incompatible.
195 Elements* mergePartial(Elements* pElements, int pOffset);
196 Elements* mergePartial(std::vector<Elements*> pElements, std::vector<int>& pOffsets);
198 //---------------------------------------------------------------------
200 //---------------------------------------------------------------------
203 * Reads a set of elements from a MED file.
204 * You must give: name of mesh, dimension of the mesh, type of entity and type of elements.
205 * \param pMEDfile any valid MED file opened for reading.
206 * \param pMeshName name of the mesh.
207 * \param pMeshDim dimension of the mesh.
208 * \param pEntity entity to be read (e.g. MED_MAILLE).
209 * \param pGeom type of primitves to be read (e.g. MED_TETRA10).
210 * \throw IOException if any i/o error occurs.
216 med_entite_maillage pEntity,
217 med_geometrie_element pGeom);
220 * Writes this set of elements to a MED file.
221 * WARNING: mesh must have been created and added to the MED file before.
222 * \param pMEDfile any valid MED file opened for writing.
223 * \param pMeshName name of the mesh.
224 * \param pMeshDim dimension of the mesh.
225 * \throw IOException if any i/o error occurs.
227 void writeMED(med_idt pMEDfile, char* pMeshName, med_int pMeshDim);
230 * Sets the flag which control the stream operator <<.
231 * \param pFlag new flag value.
233 void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; }
236 * Dumps any Elements to the given output stream.
237 * \param pOs any output stream.
238 * \param pE any Elements.
239 * \return the output stream pOs.
241 friend std::ostream& operator<<(std::ostream& pOs, Elements& pE);
246 * Builds the set of nodes used by this set of elements.
247 * If the set already exist, then it is cleared and a new set is computed.
249 void buildSetOfNodes();
253 med_int mNum; /**< Number of elements. */
254 med_entite_maillage mEntity; /**< Type of entity, e.g. MED_MAILLE. */
255 med_geometrie_element mGeom; /**< Type of primitive, e.g. MED_TETRA10. */
256 int mDim; /**< Dimension of elements = mGeom / 100. */
257 int mNumNodesByElt; /**< Number of nodes by element = mGeom % 100. */
258 med_int* mId; /**< Optional; for each element, its identifier; NULL if undefined. */
259 med_int* mFamIdent; /**< For each element, its family (identifier). */
260 char* mNames; /**< Optional; for each element, its name; NULL if undefined. */
261 med_int* mCon; /**< For each element, list of nodes (index in 1..*) = table of connectivity. */
262 std::set<med_int> mSetOfNodes; /**< Set of all nodes used by this set of elements. */
264 bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */
268 // do not allow copy constructor
269 Elements(const Elements&);
272 Elements& operator=(const Elements&);
274 // do not allow operator ==
275 bool operator==(const Elements&);
280 } // namespace MULTIPR
283 #endif // MULTIPR_NODES_HXX