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
98 * \param pMEDFileName file name excluding the path.
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 * Sets the name of the associated sequential MED file (=original MED file).
243 * \param pFilename name of the associated sequential MED file.
245 void setSequentialMEDFilename(const char* pFilename);
248 * Returns the name of this sequential MED file (=original MED file).
249 * \return the name of this sequential MED file (=original MED file).
251 const char* getSequentialMEDFilename() const { return mSequentialMEDFilename; }
254 * Returns the name of this distributed MED file (=name of the master file).
255 * \return the name of this distributed MED file (=name of the master file).
257 const char* getDistributedMEDFilename() const { return mDistributedMEDFilename; }
260 * Adds a new part to this distributed mesh.
261 * Used by the split process (extract groups).
262 * \param pToDoOnNextWrite
267 * \param pMEDFileName
268 * \param pMesh can be NULL.
271 MeshDisPart::OnNextWrite pToDoOnNextWrite,
272 const char* pMeshName,
274 const char* pPartName,
276 const char* pMEDFileName,
280 * Inserts a new part to this distributed mesh.
281 * Used by the decimation process.
282 * \param pToDoOnNextWrite
287 * \param pMEDFileName
288 * \param pMesh can be NULL.
289 * \param pPosition insert after this position. Start at 1.
292 MeshDisPart::OnNextWrite pToDoOnNextWrite,
293 const char* pMeshName,
295 const char* pPartName,
297 const char* pMEDFileName,
302 * Removes all the part beginning by pPrefixPartName from this distributed mesh.
303 * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41".
304 * \param pPrefixPartName name of the part.
306 void removeParts(const char* pPrefixPartName);
309 * Returns the current number of parts in this distributed mesh.
310 * \return the current number of parts in this distributed mesh.
312 int getNumParts() const { return mParts.size(); }
315 * Returns the nth part of this distributed mesh.
316 * \param pIndex index of the part (in 0..getNumParts()-1).
317 * \return the nth part of this distributed mesh.
319 MeshDisPart* getPart(int pIndex) const { return mParts[pIndex]; }
322 * Returns the list of meshes contained in this distributed MED file.
323 * \return the list of meshes contained in this distributed MED file.
325 std::vector<std::string> getMeshes() const;
328 * Returns the list of fields contained in this distributed MED file.
329 * \return the list of fields contained in this distributed MED file.
331 std::vector<std::string> getFields() const;
334 * Returns the number of iteration for a given field.
335 * \param pFieldName field name.
336 * \return the number of iteration for a given field.
338 int getTimeStamps(const char* pFieldName) const;
341 * Returns all information about a part.
342 * \param pPartName name of the part.
343 * \return all information about a part.
345 std::string getPartInfo(const char* pPartName);
347 //---------------------------------------------------------------------
349 //---------------------------------------------------------------------
352 * Finds a part of this distributed mesh by its name.
353 * Returns NULL if the part does not exist.
354 * \param pPartName part to be found; must not be NULL.
355 * \return a pointer towards the part if it exists, NULL otherwise.
356 * \throw NullArgumentException if pPartName is NULL.
358 MeshDisPart* findPart(const char* pPartName);
361 * Updates this distributed mesh by splitting one of its part.
362 * This splitting method leans on medsplitter, by V. Bergeaud (CEA).
363 * \param pPartName name of the part to be splitted.
364 * \param pNbParts number of sub-parts.
365 * \param pPartitionner MULTIPR_METIS or MULTIPR_SCOTCH.
366 * \throw RuntimeException if any error occurs.
368 void splitPart(const char* pPartName, int pNbParts, int pPartitionner);
371 * Creates 3 resolution (CURRENT = FULL, MEDIUM and LOW) of a part of this distributed mesh.
372 * Names of new meshes are <original_name>_MED and <original_name>_LOW.
377 * \param pTMed threshold used to generate MEDIUM resolution.
378 * \param pTLow threshold used to generate LOW resolution (must be >= pTMed).
380 * \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.
381 * \throw RuntimeException if any error occurs.
384 const char* pPartName,
385 const char* pFieldName,
387 const char* pFilterName,
394 * Returns useful information to configure decimation parameters.
395 * Depends on part, field and filter: generic operation.
396 * \param pPartName name of the part.
397 * \param pFieldName name of the field used for decimation.
398 * \param pFieldIt iteration (time step) of the field.
399 * \param pFilterName name of the filter to be used.
400 * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed).
403 std::string evalDecimationParams(
404 const char* pPartName,
405 const char* pFieldName,
407 const char* pFilterName,
408 const char* pFilterParams);
410 //---------------------------------------------------------------------
412 //---------------------------------------------------------------------
415 * Reads the master file of a distributed MED file.
416 * \param pMEDfilename
417 * \throw NullArgumentException if pMEDfilename is NULL.
418 * \throw IOException if any i/o error occurs.
420 void readDistributedMED(const char* pMEDfilename);
423 * Writes this distributed MED file (including master file and sub MED files if necessary).
424 * \param pMEDfilenamePrefix
425 * \throw NullArgumentException if pMEDfilename is NULL.
426 * \throw IOException if any i/o error occurs.
428 void writeDistributedMED(const char* pMEDfilenamePrefix);
431 * Dumps any MeshDis to the given output stream.
432 * \param pOs any output stream.
433 * \param pM any MeshDis.
434 * \return the output stream pOs.
436 friend std::ostream& operator<<(std::ostream& pOs, MeshDis& pM);
441 * Recomputes the number of parts in this distributed mesh.
442 * This method is used by writeDistributedMED().
443 * \return the number of parts in this distributed mesh.
445 int computeNumParts();
449 char mSequentialMEDFilename[256]; /**< Name of the original MED file used to build distribyuted MED. */
450 char mDistributedMEDFilename[256]; /**< Name of this distributed MED file (= name of the master file). */
451 std::vector<MeshDisPart*> mParts; /**< Table of sub-parts; a distributed mesh is composed of N sub-part, where N = mParts.size(). */
452 //MULTIPR_ProgressCallback* mProgressCallback;
456 // do not allow copy constructor
457 MeshDis(const MeshDis&);
460 MeshDis& operator=(const MeshDis&);
462 // do not allow operator ==
463 bool operator==(const MeshDis&);
468 } // namespace MULTIPR
471 #endif // MULTIPR_MESHDIS_HXX