]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPR/MULTIPR_Mesh.hxx
Salome HOME
fde319595da1b299cca24ea532267d20c3537ed9
[modules/multipr.git] / src / MULTIPR / MULTIPR_Mesh.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_Mesh.hxx
6  *
7  * \brief   Class Mesh used by the MULTIPR API; used to wrap MED file meshes.
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13
14 #ifndef MULTIPR_MESH_HXX
15 #define MULTIPR_MESH_HXX
16
17 //*****************************************************************************
18 // Includes section
19 //*****************************************************************************
20
21 extern "C"
22 {
23         #include "med.h"
24 }
25
26 #include <iostream>
27 #include <fstream>
28 #include <set>
29 #include <map>
30 #include <vector>
31 #include <string>
32
33
34 namespace multipr
35 {
36
37 //*****************************************************************************
38 // Pre-declaration
39 //*****************************************************************************
40
41 class GaussLoc;
42 class Profil;
43 class Nodes;
44 class Elements;
45 class Family;
46 class Field;
47 class Group;
48 class MeshDis;
49 class PointOfField;
50
51
52 //*****************************************************************************
53 // Class Mesh
54 //*****************************************************************************
55
56 /**
57  * Assumes:
58  * - 3D mesh in a 3D space
59  * - Unstructured mesh (not a grid)
60  * - Nodal connectivity
61  * - Cartesian coordinates system
62  * Always use FULL_INTERLACE arrays
63  */
64 class Mesh
65 {
66 public:
67
68         /**
69          * Builds an empty Mesh (default constructor).
70          */
71         Mesh();
72          
73         /**
74          * Destructor. Removes everything.
75          */
76         ~Mesh();
77          
78         /**
79          * Resets this object in its state by default (empty). Cleans memory.
80          */
81         void reset();
82         
83         //---------------------------------------------------------------------
84         // Basic accessors/mutators
85         //---------------------------------------------------------------------
86         
87         /**
88          * Returns the name of this Mesh.
89          * \return the name of this Mesh.
90          */
91         const char* getName() const { return mMeshName; }
92         
93         /**
94          * Returns the name of all the scalar fields.
95          * \return the name of all the scalar fields.
96          */
97         std::vector<std::string> getNameScalarFields() const; 
98         
99         /**
100          * Returns the number of iteration for a given field.
101          * \return the number of iteration for a given field.
102          */
103         int getTimeStamps(const char* pFieldName) const; 
104         
105         /**
106          * Returns a Field from its name; NULL if it does not exist.
107          * \param  pFieldName name of the field to be retrieved.
108          * \return the Field pFieldName of it exists, NULL otherwise.
109          * \throw  NullArgumentException if pFieldName is NULL.
110          */
111         Field* getFieldByName(const char* pFieldName) const;
112         
113         /**
114          * Returns a GaussLoc from its name; NULL if it does not exist.
115          * \param  pGaussLocName name of the GaussLoc to be retrieved.
116          * \return the GaussLoc pGaussLocName if it exists, NULL otherwise.
117          * \throw  NullArgumentException if pGaussLocName is NULL.
118          */
119         GaussLoc* getGaussLocByName(const char* pGaussLocName) const;   
120          
121         /**
122          * Returns true iff the given 3D-point is in the bounding box of this Mesh.
123          * \param  pX 
124          * \param  pY 
125          * \param  pZ
126          * \return true iff the given 3D-point is in the bounding box of this Mesh.
127          */
128         bool isInBBox(med_float pX, med_float pY, med_float pZ) const
129         {
130                 return ((pX >= mMeshBBoxMin[0]) && (pX <= mMeshBBoxMax[0]) &&
131                         (pY >= mMeshBBoxMin[1]) && (pY <= mMeshBBoxMax[1]) &&
132                         (pZ >= mMeshBBoxMin[2]) && (pZ <= mMeshBBoxMax[2]));
133         }
134          
135         /**
136          * Returns the number of elements.
137          * \return the number of elements.
138          */
139         int getNumberOfElements() const;
140         
141         //---------------------------------------------------------------------
142         // Algorithms
143         //---------------------------------------------------------------------
144         
145         /**
146          * Creates a Mesh from a subset of its elements (cells).
147          * \param  pSetOfElements subset of elements to keep.
148          * \param  pNewMeshName   name of the new Mesh.
149          * \return a new Mesh which is a restriction of this Mesh to the given set of elements.
150          * \throw  NullArgumentException if pNewMeshName is NULL.
151          */
152         Mesh* createFromSetOfElements(const std::set<med_int>& pSetOfElements, const char* pNewMeshName);
153         
154         /**
155          * Creates a Mesh from one of its group.
156          * \param  pGroup       any group of this Mesh.  
157          * \param  pNewMeshName name of the new Mesh.
158          * \return a new Mesh which is a restriction of this Mesh to pGroup.
159          * \throw  NullArgumentException if pGroup or pNewMeshName is NULL.
160          */
161         Mesh* createFromGroup(const Group* pGroup, const char* pNewMeshName);
162         
163         /**
164          * Creates a distributed mesh (MeshDis) by creating a new mesh for each group of elements in this Mesh.
165          * \return a distributed mesh from groups of this Mesh.
166          */
167         MeshDis* splitGroupsOfElements();
168         
169         /**
170          * Creates a new mesh by decimating this one.
171          * \param  pFilterName  name of the filter to be used for decimation (e.g. Filtre_GradientMoyen); should not be NULL.
172          * \param  pArgv        all the arguments for filtering as a single string.
173          * \param  pNameNewMesh name of the new mesh.
174          * \return the decimated mesh.
175          * \throw  NullArgumentException if one of the arguments is NULL.
176          * \throw  RuntimeException if any error occurs while decimating data.
177          */
178         Mesh* decimate(
179                 const char* pFilterName,
180                 const char* pArgv,
181                 const char* pNameNewMesh);
182         
183         /**
184          * Gets all the points in a field. Each point has coordinates and a value.
185          * \param  pField      any field of this Mesh.
186          * \param  pTimeStepIt time step iteration.
187          * \param  pPoints     (out) list of points.
188          * \throw  NullArgumentException if pField is NULL.
189          * \throw  IllegalArgumentException if pTimeStepIt is invalid.
190          */
191         void getAllPointsOfField(Field* pField, int pTimeStepIt, std::vector<PointOfField>& pPoints);
192         
193         /**
194          * Returns a default value for neighborhood radius.
195          * Return value is such that, for any point in the field, average number of neighbours is pN.
196          * \param  pN average number of neighbours.
197          * \return a default value for neighborhood radius; 1.0 if some error occurs.
198          */
199         float evalDefaultRadius(int pN) const;
200         
201         //---------------------------------------------------------------------
202         // I/O
203         //---------------------------------------------------------------------
204         
205         /**
206          * Reads a Mesh from a sequential MED file. Resets the object before.
207          * \param  pMEDfilename
208          * \param  pMeshName
209          * \throw  IOException if any i/o error occurs.
210          */
211         void readSequentialMED(const char* pMEDfilename, const char* pMeshName);
212         
213         /**
214          * Writes this Mesh and all related things into a MED file.
215          * \param  pMEDfilename
216          * \throw  IOException if any i/o error occurs.
217          */
218         void writeMED(const char* pMEDfilename);
219         
220         /**
221          * Sets the flag which control the stream operator <<.
222          * \param pFlag new flag value.
223          */
224         void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } 
225         
226         /**
227          * Dumps any Mesh to the given output stream.
228          * \param  pOs any output stream.
229          * \param  pM  any Mesh.
230          * \return the output stream pOs.
231          */
232         friend std::ostream& operator<<(std::ostream& pOs, Mesh& pM);
233         
234 private:
235          
236         /**
237          * Reads all Gauss localizations in the current MED file.
238          * \throw  IOException if an i/o error occurs.
239          */
240         void readGaussLoc();
241          
242         /**
243          * Reads families in the currentMED file and build groups.
244          * \throw  IOException if an i/o error occurs.
245          */
246         void readFamilies();
247         
248         /**
249          * Finalizes the constructions of families and groups. 
250          * Fill structures with elements.
251          */
252         void finalizeFamiliesAndGroups();
253         
254         /**
255          * Reads fields related to this mesh in the current MED file.
256          * \throw  IOException if an i/o error occurs.
257          */
258         void readFields();
259         
260 private:
261
262         /**
263          * Name of the associated MED file.
264          */
265         char                              mMEDfilename[256];
266         
267         /**
268          * MED file handle.
269          */
270         med_idt                           mMEDfile;
271         
272         /**
273          * Name of this mesh.
274          */
275         char                              mMeshName[MED_TAILLE_NOM + 1];
276         
277         /**
278          * Universal name of this mesh.
279          */ 
280         char                              mMeshUName[MED_TAILLE_DESC + 1];
281         
282         /**
283          * Description.
284          */
285         char                              mMeshDesc[MED_TAILLE_DESC + 1]; 
286         
287         /**
288          * Dimension.
289          */
290         med_int                           mMeshDim;
291         
292         /**
293          * Type of mesh (MED_NON_STRUCTURE or MED_STRUCTURE (=grid)) 
294          */
295         med_maillage                      mMeshType;
296         
297         /** 
298          * Axis aligned bounding box of this mesh.
299          */
300         med_float                         mMeshBBoxMin[3];
301         med_float                         mMeshBBoxMax[3];
302
303         /**
304          * All the nodes used by this mesh. 
305          */
306         Nodes*                            mNodes;
307         
308         /**
309          * All the TETRA10 elements used by this mesh.
310          */
311         Elements*                         mElements;
312         
313         /**
314          * Table of families used by this mesh.
315          */
316         std::vector<Family*>              mFamilies;
317         
318         /**
319          * Map to retrieve a Family from its name.
320          */
321         std::map<med_int, Family*>        mFamIdToFam;
322         
323         /**
324          * Table of groups used by this mesh.
325          */
326         std::vector<Group*>               mGroups;
327         
328         /**
329          * Map to retrieve a Group from its name.
330          */
331         std::map<std::string, Group*>     mGroupNameToGroup;
332         
333         /**
334          * Table of GaussLoc. 
335          */
336         std::vector<GaussLoc*>            mGaussLoc; 
337         
338         /**
339          * Map to retrieve a Gauss info from its name.
340          */
341         std::map<std::string, GaussLoc*>  mGaussLocNameToGaussLoc;
342         
343         /**
344          * Table of fields related to this mesh.
345          * Number of fiels = mFields.size().
346          */
347         std::vector<Field*>               mFields;
348         
349         /**
350          * Table of profils.
351          */
352         std::vector<Profil*>              mProfils;
353         
354         /** 
355          * Flag to control the behaviour of the stream operator <<. 
356          */
357         bool                              mFlagPrintAll;
358         
359 private:
360
361         // do not allow copy constructor
362         Mesh(const Mesh&);
363         
364         // do not allow copy
365         Mesh& operator=(const Mesh&);
366         
367         // do not allow operator ==
368         bool operator==(const Mesh&); 
369         
370 }; // class Mesh
371
372
373 } // namespace MULTIPR
374
375
376 #endif // MULTIPR_MESH_HXX
377
378 // EOF