1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
5 * \file MULTIPR_MeshDis.hxx
7 * \brief Class MeshDis: distributed mesh.
8 * = MASTER file (ASCII) -> list of sequential MED file.
10 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
15 #ifndef MULTIPR_MESHDIS_HXX
16 #define MULTIPR_MESHDIS_HXX
18 //*****************************************************************************
20 //*****************************************************************************
30 // include MEDSPLITTER used to split mesh using METIS or SCOTCH
31 #include "MEDMEM_define.hxx"
32 #include "MEDMEM_Mesh.hxx"
33 #include "MEDMEM_Family.hxx"
34 #include "MEDSPLITTER_Graph.hxx"
35 #include "MEDSPLITTER_MESHCollection.hxx"
36 #include "MEDSPLITTER_Topology.hxx"
42 //*****************************************************************************
44 //*****************************************************************************
49 //*****************************************************************************
50 // Class MeshDisPart = a sub-part of a distributed mesh.
53 // - a sequential MED file representing a Group (scenario 1)
54 // - a sequential MED file representing a part of a Group (scenario 2 -> MEDSPLITTER)
55 // - a lower resolution of a part (decimation)
56 //*****************************************************************************
64 * Action to be done for this part on next writing on disk.
77 * Builds an empty part of a distributed mesh (default constructor).
82 * Destructor. Removes everything.
87 * Resets this object in its state by default (empty). Cleans memory.
92 * Creates a MeshDisPart.
93 * \param pToDoOnNextWrite
99 * \param pMesh can be NULL.
102 OnNextWrite pToDoOnNextWrite,
103 const char* pMeshName,
105 const char* pPartName,
107 const char* pMEDFileName,
110 //---------------------------------------------------------------------
111 // Basic accessors/mutators
112 //---------------------------------------------------------------------
115 * Returns the name of this part.
116 * \return the name of this part.
118 const char* getPartName() const { return mPartName; }
121 * Returns the name of the mesh of this part.
122 * \return the name of the mesh of this part.
124 const char* getMeshName() const { return mMeshName; }
127 * Returns the MED filename which contain this part.
128 * \return the MED filename which contain this part.
130 const char* getMEDFileName() const { return mMEDFileName; }
133 * Returns the suffix of the related MED filename (without .med extension).
135 * 1. "agregat100grains_12pas_grain97.med" -> "grain97"
136 * 2. "agregat100grains_12pas_grain100_part2.med" -> "grain100_part2"
137 * 3. "aagregat100grains_12pas_grain98_gradmoy-low-25.0-0.3.med" -> "grain98_gradmoy-low-25-0.3"
139 const char* getMEDFileNameSuffix() const;
142 * Returns the action to be performed on this part on next write.
143 * \return the action to be performed on this part on next write.
145 OnNextWrite getOnNextWrite() const { return mToDoOnNextWrite; }
147 //---------------------------------------------------------------------
149 //---------------------------------------------------------------------
152 * Reads the sequentiel MED file corresponding to this part.
153 * \throw IOException if an i/o error occurs.
158 * Dumps any MeshDisPart to the given output stream.
159 * \param pOs any output stream.
160 * \param pM any MeshDisPart.
161 * \return the output stream pOs.
163 friend std::ostream& operator<<(std::ostream& pOs, MeshDisPart& pM);
167 // MeshDisPart can be used:
168 // 1 (KEEP_AS_IT) : To store data read from one line of an ASCII master file (distributed MED file)
169 // 2 (WRITE_MESH) : As a temporary structure to store all infos about a mesh corresponding to a group (before writing on disk).
170 // 3 (WRITE_PARTS) : As a temporary structure to store all infos about splitting using MEDSPLITTER.
172 OnNextWrite mToDoOnNextWrite; /**< See enum OnNextWrite. */
174 //---------------------------------------------------------------------
176 //---------------------------------------------------------------------
177 char mMeshName[MED_TAILLE_NOM + 1]; /**< Name of the mesh. */
178 int mId; /**< Id of this part in [1..n]. */
179 char mPartName[MED_TAILLE_NOM + 1]; /**< Name of this part. */
180 char mPath[256]; /**< Path of the MED file. */
181 char mMEDFileName[256]; /**< Name of the MED file which contain this part. */
183 //---------------------------------------------------------------------
184 // Case 2: mesh of the related sequential MED file (can be NULL if not loaded)
185 //---------------------------------------------------------------------
186 Mesh* mMesh; /**< Mesh associated with this part; can be NULL. */
188 //---------------------------------------------------------------------
189 // Case 3 only: temporary result of MEDSPLITTER
190 //---------------------------------------------------------------------
191 int mSplit; /**< For MEDSPLITTER: number of parts. Temporary. */
192 MEDSPLITTER::MESHCollection* mCollection; /**< New data after splitting. */
193 MEDSPLITTER::MESHCollection* mOldCollection; /**< Data before splitting (we need them when we want to write new data on disk. */
197 // do not allow copy constructor
198 MeshDisPart(const MeshDisPart&);
201 MeshDisPart& operator=(const MeshDisPart&);
203 // do not allow operator ==
204 bool operator==(const MeshDisPart&);
206 //---------------------------------------------------------------------
208 //---------------------------------------------------------------------
209 friend class MeshDis;
211 }; // class MeshDisPart
214 //*****************************************************************************
216 //*****************************************************************************
223 * Builds an empty mesh (default constructor).
228 * Destructor. Removes everything.
233 * Resets this object in its state by default (empty). Clean memory.
237 //---------------------------------------------------------------------
238 // Basic accessors/mutators
239 //---------------------------------------------------------------------
242 * Returns the name of this distributed MED file (=name of the master file).
243 * \return the name of this distributed MED file (=name of the master file).
245 const char* getFilename() const { return mMEDfilename; }
248 * Adds a new part to this distributed mesh.
249 * Used by the split process (extract groups).
250 * \param pToDoOnNextWrite
255 * \param pMEDFileName
256 * \param pMesh can be NULL.
259 MeshDisPart::OnNextWrite pToDoOnNextWrite,
260 const char* pMeshName,
262 const char* pPartName,
264 const char* pMEDFileName,
268 * Inserts a new part to this distributed mesh.
269 * Used by the decimation process.
270 * \param pToDoOnNextWrite
275 * \param pMEDFileName
276 * \param pMesh can be NULL.
277 * \param pPosition insert after this position. Start at 1.
280 MeshDisPart::OnNextWrite pToDoOnNextWrite,
281 const char* pMeshName,
283 const char* pPartName,
285 const char* pMEDFileName,
290 * Removes all the part beginning by pPrefixPartName from this distributed mesh.
291 * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41".
292 * \param pPrefixPartName name of the part.
294 void removeParts(const char* pPrefixPartName);
297 * Returns the current number of parts in this distributed mesh.
298 * \return the current number of parts in this distributed mesh.
300 int getNumParts() const { return mParts.size(); }
303 * Returns the nth part of this distributed mesh.
304 * \param pIndex index of the part (in 0..getNumParts()-1).
305 * \return the nth part of this distributed mesh.
307 MeshDisPart* getPart(int pIndex) const { return mParts[pIndex]; }
310 * Returns the list of meshes contained in this distributed MED file.
311 * \return the list of meshes contained in this distributed MED file.
313 std::vector<std::string> getMeshes() const;
316 * Returns the list of fields contained in this distributed MED file.
317 * \return the list of fields contained in this distributed MED file.
319 std::vector<std::string> getFields() const;
322 * Returns the number of iteration for a given field.
323 * \param pFieldName field name.
324 * \return the number of iteration for a given field.
326 int getTimeStamps(const char* pFieldName) const;
329 * Returns all information about a part.
330 * \param pPartName name of the part.
331 * \return all information about a part.
333 std::string getPartInfo(const char* pPartName);
335 //---------------------------------------------------------------------
337 //---------------------------------------------------------------------
340 * Finds a part of this distributed mesh by its name.
341 * Returns NULL if the part does not exist.
342 * \param pPartName part to be found; must not be NULL.
343 * \return a pointer towards the part if it exists, NULL otherwise.
344 * \throw NullArgumentException if pPartName is NULL.
346 MeshDisPart* findPart(const char* pPartName);
349 * Updates this distributed mesh by splitting one of its part.
350 * This splitting method leans on medsplitter, by V. Bergeaud (CEA).
351 * \param pPartName name of the part to be splitted.
352 * \param pNbParts number of sub-parts.
353 * \param pPartitionner MULTIPR_METIS or MULTIPR_SCOTCH.
354 * \throw RuntimeException if any error occurs.
356 void splitPart(const char* pPartName, int pNbParts, int pPartitionner);
359 * Creates 3 resolution (CURRENT = FULL, MEDIUM and LOW) of a part of this distributed mesh.
360 * Names of new meshes are <original_name>_MED and <original_name>_LOW.
365 * \param pTMed threshold used to generate MEDIUM resolution.
366 * \param pTLow threshold used to generate LOW resolution (must be >= pTMed).
368 * \param pBoxing number of cells along each axis; e.g. if 100 then grid will have 100*100*100 = 10**6 cells; 100 by default.
369 * \throw RuntimeException if any error occurs.
372 const char* pPartName,
373 const char* pFieldName,
375 const char* pFilterName,
382 * Returns useful information to configure decimation parameters.
383 * Depends on part, field and filter: generic operation.
384 * \param pPartName name of the part.
385 * \param pFieldName name of the field used for decimation.
386 * \param pFieldIt iteration (time step) of the field.
387 * \param pFilterName name of the filter to be used.
388 * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed).
391 std::string evalDecimationParams(
392 const char* pPartName,
393 const char* pFieldName,
395 const char* pFilterName,
396 const char* pFilterParams);
398 //---------------------------------------------------------------------
400 //---------------------------------------------------------------------
403 * Reads the master file of a distributed MED file.
404 * \param pMEDfilename
405 * \throw NullArgumentException if pMEDfilename is NULL.
406 * \throw IOException if any i/o error occurs.
408 void readDistributedMED(const char* pMEDfilename);
411 * Writes this distributed MED file (including master file and sub MED files if necessary).
412 * \param pMEDfilenamePrefix
413 * \throw NullArgumentException if pMEDfilename is NULL.
414 * \throw IOException if any i/o error occurs.
416 void writeDistributedMED(const char* pMEDfilenamePrefix);
419 * Dumps any MeshDis to the given output stream.
420 * \param pOs any output stream.
421 * \param pM any MeshDis.
422 * \return the output stream pOs.
424 friend std::ostream& operator<<(std::ostream& pOs, MeshDis& pM);
429 * Recomputes the number of parts in this distributed mesh.
430 * This method is used by writeDistributedMED().
431 * \return the number of parts in this distributed mesh.
433 int computeNumParts();
437 char mMEDfilename[256]; /** Name of this distributed MED file (= name of the master file). */
438 std::vector<MeshDisPart*> mParts; /**< Table of sub-parts; a distributed mesh is composed of N sub-part, where N = mParts.size(). */
439 //MULTIPR_ProgressCallback* mProgressCallback;
443 // do not allow copy constructor
444 MeshDis(const MeshDis&);
447 MeshDis& operator=(const MeshDis&);
449 // do not allow operator ==
450 bool operator==(const MeshDis&);
455 } // namespace MULTIPR
458 #endif // MULTIPR_MESHDIS_HXX