]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPR/MULTIPR_Obj.hxx
Salome HOME
*** empty log message ***
[modules/multipr.git] / src / MULTIPR / MULTIPR_Obj.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_GaussLoc.hxx
6  *
7  * \brief   Class MULTIPR_Obj. 
8  *          This class is used as an interface to implement MULTIPR services in the salome MODULE 
9  *          as described in the spec/design doc.
10  *
11  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
12  * 
13  * \date    01/2007
14  */
15
16 #ifndef MULTIPR_OBJ_HXX
17 #define MULTIPR_OBJ_HXX
18
19 //*****************************************************************************
20 // Includes section
21 //*****************************************************************************
22
23 #include <iostream>
24 #include <string>
25 #include <vector>
26
27
28 namespace multipr
29 {
30
31 class MeshDis;
32
33
34 //*****************************************************************************
35 // Class Obj
36 //*****************************************************************************
37
38 enum ObjState
39 {
40         MULTIPR_OBJ_STATE_ERROR,
41         MULTIPR_OBJ_STATE_RESET,
42         MULTIPR_OBJ_STATE_SEQ_INIT,
43         MULTIPR_OBJ_STATE_SEQ,
44         MULTIPR_OBJ_STATE_DIS,
45         MULTIPR_OBJ_STATE_DIS_MEM
46 }; // enum ObjState
47
48
49 class Obj
50 {
51 public:
52
53         /** 
54          * Builds an empty Gauss reference (default constructor).
55          */
56         Obj();
57         
58         /**
59          * Destructor. Removes everything.
60          */
61         ~Obj();
62         
63         /**
64          * Resets this object in its state by default (empty). Cleans memory.
65          */
66         void reset();
67         
68         /**
69          * Associate a MED file (sequential or distributed) with this object.
70          * This method also:
71          * - reset everything before starting
72          * - determine if the given file is a sequential (SEQ) or a distributed (DIS) MED file
73          * - read the ASCII master file if it is a distributed MED file
74          * - set state
75          */
76         void create(const char* pMEDfilename);
77          
78         //---------------------------------------------------------------------
79         // Basic accessors/mutators
80         //--------------------------------------------------------------------
81         
82         /**
83          * Returns true iff this obj represents a valid sequential MED file.
84          * \return true iff this obj represents a valid sequential MED file.
85          */
86         bool isValidSequentialMEDFile() const { return (mState == MULTIPR_OBJ_STATE_SEQ) || (mState == MULTIPR_OBJ_STATE_SEQ_INIT); }
87         
88         /**
89          * Returns true iff this obj represents a valid distributed MED file.
90          * \return true iff this obj represents a valid distributed  MED file.
91          */
92         bool isValidDistributedMEDFile() const { return (mState == MULTIPR_OBJ_STATE_DIS) || (mState == MULTIPR_OBJ_STATE_DIS_MEM); }
93          
94         /**
95          * Defines the mesh to be processed.
96          * \param  pMeshName name of the mesh to be partitionned.
97          */
98         void setMesh(const char* pMeshName);
99          
100         /**
101          * Returns the list of meshes contained in the sequential MED file.
102          * Assumes this object encapsulates a sequential MED file.
103          * \return the list of meshes contained in the sequential MED file.
104          */
105         std::vector<std::string> getMeshes() const;
106         
107         /**
108          * Returns the list of fields contained in the sequential MED file.
109          * Assumes this object encapsulates a sequential MED file.
110          * \return the list of fields contained in the sequential MED file.
111          */
112         std::vector<std::string> getFields() const;
113         
114         /**
115          * Returns the number of timestamps for a given field.
116          * Assumes this object encapsulates a sequential MED file.
117          * \param  pFieldName name of any field.
118          * \return the number of timestamps for a given field; 0 if field not found.
119          */
120         int getTimeStamps(const char* pFieldName) const;
121         
122         /**
123          * Returns the name of all partitions.
124          * Assumes this object encapsulates a distributed MED file.
125          * \return the name of all partitions.
126          */
127         std::vector<std::string> getParts() const;
128         
129         /**
130          * Returns all information about a part.
131          * \param  pPartName name of the part.
132          * \return all information about a part.
133          */
134         std::string getPartInfo(const char* pPartName) const;
135         
136         /**
137          * Removes all the part beginning by pPrefixPartName from the distributed MED file.
138          * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41".
139          * Assume this object encapsulates a distributed MED file.
140          * \param  pPrefixPartName name of the part.
141          */
142         void removeParts(const char* pPrefixPartName);
143         
144           
145         //---------------------------------------------------------------------
146         // Algorithms
147         //--------------------------------------------------------------------
148         
149         /**
150          * Creates a distributed MED file (v2.3) by extracting all the groups from the current mesh of the current MED sequential MED file.
151          *         Assumes:
152          *         - the file is in MED format and can be read using MED file v2.3.
153          *         - the file is sequential (not a distributed MED).
154          *         - the file only contains TETRA10 elements (dimension of space and mesh is 3).
155          *         - the file have no profil.
156          * \return the name of each part.
157          * \throw  RuntimeException if any error occurs.
158          */
159         std::vector<std::string> partitionneDomaine();
160         
161         /** 
162          * Creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine.
163          *         Assumes:
164          *         - the file is a distributed MED file, previously created by partitionneDomaine()
165          *           (=> each part only contain 1 mesh, TETRA10 elements only)
166          *         - nbPart > 1
167          * \param  pPartName     name of the part to be splitted.
168          * \param  pNbParts      number of parts; must be > 1.
169          * \param  pPartitionner use value 0=MULTIPR_METIS for Metis or 1=MULTIPR_SCOTCH for Scotch.
170          * \return the name of each part.
171          * \throw  RuntimeException if any error occurs.
172          */
173         std::vector<std::string> partitionneGrain(
174                 const char* pPartName, 
175                 int         pNbParts, 
176                 int         pPartitionner=0);
177         
178         /**
179          * Creates 3 resolutions of the given part of a distributed MED file (V2.3).
180          *         Assumes:
181          *         - the file is a distributed MED file, previously created by partitionneDomaine() or partitionneGrain()
182          *           (=> each part only contain 1 mesh, TETRA10 elements only)
183          * \param  pPartName    name of the part to be decimated.
184          * \param  pFieldName   name of the field used for decimation.
185          * \param  pFieldIt     iteration (time step) of the field.
186          * \param  pFilterName  name of the filter to be used.
187          * \param  pTmed        threshold used for medium resolution.
188          * \param  pTlow        threshold used for low resolution; tmed must be less than tlow
189          * \param  pTadius      radius used to determine the neighbourhood.
190          * \param  pBoxing      number of cells along each axis; must be >= 1; e.g. if 100 then acceleration grid will have 100*100*100 = 10**6 cells.
191          * \return the name of each part.
192          * \throw  RuntimeException if any error occurs.
193          */
194         std::vector<std::string> decimePartition(
195                 const char* pPartName,
196                 const char* pFieldName,
197                 int         pFieldIt,
198                 const char* pFilterName,
199                 double      pTmed,
200                 double      pTlow,
201                 double      pRadius,
202                 int         pBoxing);
203         
204         /**
205          * Returns useful information to configure decimation parameters.
206          * Depends on part, field and filter: generic operation.
207          * \param  pPartName     name of the part.
208          * \param  pFieldName    name of the field used for decimation.
209          * \param  pFieldIt      iteration (time step) of the field.
210          * \param  pFilterName   name of the filter to be used.
211          * \param  pFilterParams params to be used with the filter (depends on filter; this string will be parsed).
212          */
213         std::string evalDecimationParams(
214                 const char* pPartName, 
215                 const char* pFieldName, 
216                 int         pFieldIt, 
217                 const char* pFilterName,
218                 const char* pFilterParams);
219         
220                 
221         //---------------------------------------------------------------------
222         // I/O
223         //---------------------------------------------------------------------
224         
225         /**
226          * Saves the associated MED file if necessary.
227          * \throw  IOException if any i/o error occurs.
228          */
229         void save();
230
231         /**
232          * Dumps any Obj to the given output stream.
233          * \param  pOs any output stream.
234          * \param  pO  any Obj.
235          * \return the output stream pOs.
236          */
237         friend std::ostream& operator<<(std::ostream& pOs, Obj& pO);
238         
239 private:
240
241         /**
242          * Returns the list of parts contained in the current distributed mesh.
243          * \return the list of parts contained in the current distributed mesh.
244          * \throw  IllegalStateException if the distributed mesh does not still exist.
245          */
246         std::vector<std::string> getListParts() const;
247
248 private:
249         
250         std::string  mMEDfilename;     /**< Name of the MED file: sequential or distributed. */
251         std::string  mMeshName;        /**< Mesh to be partitionned. */
252         ObjState     mState;           /**< State of this object. */
253         MeshDis*     mMeshDis;         /**< Distributed mesh. */
254         
255         
256 private:
257         
258         // do not allow copy constructor
259         Obj(const Obj&);
260         
261         // do not allow copy
262         Obj& operator=(const Obj&);
263         
264         // do not allow operator ==
265         bool operator==(const Obj&); 
266         
267 }; // class Obj
268
269
270 } // namespace MULTIPR
271
272
273 #endif // MULTIPR_OBJ_HXX
274
275 // EOF