Salome HOME
178aa4c9839515dcd301da854f91c819d4063265
[modules/multipr.git] / src / MULTIPR / MULTIPR_Elements.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_Elements.hxx
6  *
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.
11  *
12  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
13  * 
14  * \date    01/2007
15  */
16
17 #ifndef MULTIPR_ELEMENTS_HXX
18 #define MULTIPR_ELEMENTS_HXX
19
20 //*****************************************************************************
21 // Includes section
22 //*****************************************************************************
23
24 extern "C"
25 {
26         #include "med.h"
27 }
28
29 #include <set>
30
31
32 namespace multipr
33 {
34
35 //*****************************************************************************
36 // Predeclaration
37 //*****************************************************************************
38
39 class Nodes;
40
41
42 //*****************************************************************************
43 // Class Elements
44 //*****************************************************************************
45
46 class Elements
47 {
48 public:
49
50         /** 
51          * Builds an empty set of elements (default constructor).
52          */
53         Elements();
54         
55         /**
56          * Destructor. Removes everything.
57          */
58         ~Elements();
59         
60         /**
61          * Resets this object in its state by default (empty). Cleans memory.
62          */
63         void reset();
64         
65         //---------------------------------------------------------------------
66         // Basic accessors/mutators
67         //---------------------------------------------------------------------
68         
69         /**
70          * Returns true iff this object contains no elements (table of elements is empty).
71          * \return true iff this object contains no elements.
72          */
73         bool isEmpty() const { return (mNum == 0); }
74         
75         /**
76          * Returns true iff elements have a name.
77          * \return true iff elements have a name.
78          */
79         bool isNames() const { return (mNames != NULL); }
80         
81         /**
82          * Returns true iff elements have an identifier (= a number).
83          * \return true iff elements have an identifier (= a number).
84          */
85         bool isIdentifiers() const { return (mId != NULL); }    
86         
87         /**
88          * Returns the number of elements.
89          * \return the number of elements.
90          */
91         int getNumberOfElements() const { return mNum; }
92         
93         /**
94          * Returns the type of primitives (e.g. MED_TETRA10).
95          * \return the type of primitives
96          */
97         med_geometrie_element getTypeOfPrimitives() const { return mGeom; }
98         
99         /**
100          * Returns the number of nodes that composed an element.
101          * \return the number of nodes that composed an element.
102          */
103          int getNumberOfNodesByElement() const { return mNumNodesByElt; }
104          
105         /**
106          * Returns the family associated with an element.
107          * \param  pIndex index of any element in [0..NUMBER_OF_ELEMENTS-1].
108          * \return the family associated with an element.
109          * \throw  IndexOutOfBoundsException if pIndex is invalid.
110          */
111         med_int getFamilyIdentifier(med_int pIndex) const;
112         
113         /**
114          * Returns the connectivity of one element.
115          * \param  pIndex must be in [0..NUMBER_OF_ELEMENTS-1].
116          * \return a pointer towards the table of connectivity of the element.
117          * \throw  IndexOutOfBoundsException if pIndex is invalid.
118          */
119         const med_int* getConnectivity(int pIndex) const;
120         
121         /**
122          * Returns the coordinates of all the nodes of one element.
123          * \param  pIndexElt must be in [0..NUMBER_OF_ELEMENTS-1].
124          * \param  pNodes    table of nodes, used to retrieve coordinates.
125          * \param  pCoo      (out) table of coordinates of nodes (e.g. 30 = 3 * 10 med_float for a TETRA10).
126          * \param  pFirst    only get the pFirst coordinates.
127          * \throw  IndexOutOfBoundsException if pIndex is invalid.
128          */
129         void getCoordinates(med_int pIndexElt, const Nodes* pNodes, med_float* pCoo, int pFirst = 100) const;
130         
131         //---------------------------------------------------------------------
132         // Algorithms
133         //---------------------------------------------------------------------
134         
135         /**
136          * Constructor. Creates a subset of this set of elements from a set of indices.
137          * \param  pSetIndices set of indices (start at 1).
138          * \return a restriction of this set of elements.
139          */
140         Elements* extractSubSet(const std::set<med_int>& pSetIndices) const;
141         
142         /**
143          * Returns the set of indices (starting at 1) of all nodes used by this set of elements.
144          * \return the set of indices of all nodes used by this set of elements.
145          */
146         const std::set<med_int>& getSetOfNodes();
147         
148         /**
149          * Returns the set of families referenced by this set of elements.
150          * Each family is described by its identifier.
151          * \return Returns the set of families referenced by this set of elements.
152          */
153         std::set<med_int> getSetOfFamilies() const;
154         
155         /**
156          * Remaps this set of elements such that indices of nodes are continous 1 2 3 4 5 ... *
157          * This method is intended to be used after extractSubSet().
158          */
159         void remap();
160         
161         //---------------------------------------------------------------------
162         // I/O
163         //---------------------------------------------------------------------
164         
165         /**
166          * Reads a set of elements from a MED file.
167          * You must give: name of mesh, dimension of the mesh, type of entity and type of elements.
168          * \param  pMEDfile   any valid MED file opened for reading.
169          * \param  pMeshName  name of the mesh.
170          * \param  pMeshDim   dimension of the mesh.
171          * \param  pEntity    entity to be read (e.g. MED_MAILLE).
172          * \param  pGeom      type of primitves to be read (e.g. MED_TETRA10).
173          * \throw  IOException if any i/o error occurs.
174          */
175         void readMED(
176                 med_idt               pMEDfile, 
177                 char*                 pMeshName, 
178                 med_int               pMeshDim,
179                 med_entite_maillage   pEntity, 
180                 med_geometrie_element pGeom);
181         
182         /**
183          * Writes this set of elements to a MED file.
184          * WARNING: mesh must have been created and added to the MED file before.
185          * \param  pMEDfile  any valid MED file opened for writing.
186          * \param  pMeshName name of the mesh.
187          * \param  pMeshDim  dimension of the mesh.
188          * \throw  IOException if any i/o error occurs.
189          */
190         void writeMED(med_idt pMEDfile, char* pMeshName, med_int pMeshDim);
191         
192         /**
193          * Sets the flag which control the stream operator <<.
194          * \param  pFlag new flag value.
195          */
196         void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } 
197         
198         /**
199          * Dumps any Elements to the given output stream.
200          * \param  pOs any output stream.
201          * \param  pE  any Elements.
202          * \return the output stream pOs.
203          */
204         friend std::ostream& operator<<(std::ostream& pOs, Elements& pE);
205
206 private:
207         
208         /**
209          * Builds the set of nodes used by this set of elements.
210          * If the set already exist, then it is cleared and a new set is computed.
211          */
212         void buildSetOfNodes();
213         
214 private:
215         
216         med_int               mNum;           /**< Number of elements. */
217         med_entite_maillage   mEntity;        /**< Type of entity, e.g. MED_MAILLE. */
218         med_geometrie_element mGeom;          /**< Type of primitive, e.g. MED_TETRA10. */
219         int                   mDim;           /**< Dimension of elements = mGeom / 100. */
220         int                   mNumNodesByElt; /**< Number of nodes by element = mGeom % 100. */
221         med_int*              mId;            /**< Optional; for each element, its identifier; NULL if undefined. */
222         med_int*              mFamIdent;      /**< For each element, its family (identifier). */
223         char*                 mNames;         /**< Optional; for each element, its name; NULL if undefined. */
224         med_int*              mCon;           /**< For each element, list of nodes (index in 1..*) = table of connectivity. */
225         std::set<med_int>     mSetOfNodes;    /**< Set of all nodes used by this set of elements. */
226         
227         bool                  mFlagPrintAll;  /** Flag to control the behaviour of the stream operator <<. */
228         
229 private:
230
231         // do not allow copy constructor
232         Elements(const Elements&);
233         
234         // do not allow copy
235         Elements& operator=(const Elements&);
236         
237         // do not allow operator ==
238         bool operator==(const Elements&); 
239         
240 }; // class Elements
241
242
243 } // namespace MULTIPR
244
245
246 #endif // MULTIPR_NODES_HXX
247
248 // EOF