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 * Returns the current number of parts in this distributed mesh.
291 * \return the current number of parts in this distributed mesh.
293 int getNumParts() const { return mParts.size(); }
296 * Returns the nth part of this distributed mesh.
297 * \param pIndex index of the part (in 0..getNumParts()-1).
298 * \return the nth part of this distributed mesh.
300 MeshDisPart* getPart(int pIndex) const { return mParts[pIndex]; }
303 * Returns the list of meshes contained in this distributed MED file.
304 * \return the list of meshes contained in this distributed MED file.
306 std::vector<std::string> getMeshes() const;
309 * Returns the list of fields contained in this distributed MED file.
310 * \return the list of fields contained in this distributed MED file.
312 std::vector<std::string> getFields() const;
315 * Returns the number of iteration for a given field.
316 * \param pFieldName field name.
317 * \return the number of iteration for a given field.
319 int getTimeStamps(const char* pFieldName) const;
322 * Returns all information about a part.
323 * \param pPartName name of the part.
324 * \return all information about a part.
326 std::string getPartInfo(const char* pPartName);
328 //---------------------------------------------------------------------
330 //---------------------------------------------------------------------
333 * Finds a part of this distributed mesh by its name.
334 * Returns NULL if the part does not exist.
335 * \param pPartName part to be found; must not be NULL.
336 * \return a pointer towards the part if it exists, NULL otherwise.
337 * \throw NullArgumentException if pPartName is NULL.
339 MeshDisPart* findPart(const char* pPartName);
342 * Updates this distributed mesh by splitting one of its part.
343 * This splitting method leans on medsplitter, by V. Bergeaud (CEA).
344 * \param pPartName name of the part to be splitted.
345 * \param pNbParts number of sub-parts.
346 * \param pPartitionner MULTIPR_METIS or MULTIPR_SCOTCH.
347 * \throw RuntimeException if any error occurs.
349 void splitPart(const char* pPartName, int pNbParts, int pPartitionner);
352 * Creates 3 resolution (CURRENT = FULL, MEDIUM and LOW) of a part of this distributed mesh.
353 * Names of new meshes are <original_name>_MED and <original_name>_LOW.
358 * \param pTMed threshold used to generate MEDIUM resolution.
359 * \param pTLow threshold used to generate LOW resolution (must be >= pTMed).
361 * \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.
362 * \throw RuntimeException if any error occurs.
365 const char* pPartName,
366 const char* pFieldName,
368 const char* pFilterName,
374 //---------------------------------------------------------------------
376 //---------------------------------------------------------------------
379 * Reads the master file of a distributed MED file.
380 * \param pMEDfilename
381 * \throw NullArgumentException if pMEDfilename is NULL.
382 * \throw IOException if any i/o error occurs.
384 void readDistributedMED(const char* pMEDfilename);
387 * Writes this distributed MED file (including master file and sub MED files if necessary).
388 * \param pMEDfilenamePrefix
389 * \throw NullArgumentException if pMEDfilename is NULL.
390 * \throw IOException if any i/o error occurs.
392 void writeDistributedMED(const char* pMEDfilenamePrefix);
395 * Dumps any MeshDis to the given output stream.
396 * \param pOs any output stream.
397 * \param pM any MeshDis.
398 * \return the output stream pOs.
400 friend std::ostream& operator<<(std::ostream& pOs, MeshDis& pM);
405 * Recomputes the number of parts in this distributed mesh.
406 * This method is used by writeDistributedMED().
407 * \return the number of parts in this distributed mesh.
409 int computeNumParts();
413 char mMEDfilename[256]; /** Name of this distributed MED file (= name of the master file). */
414 std::vector<MeshDisPart*> mParts; /**< Table of sub-parts; a distributed mesh is composed of N sub-part, where N = mParts.size(). */
415 //MULTIPR_ProgressCallback* mProgressCallback;
419 // do not allow copy constructor
420 MeshDis(const MeshDis&);
423 MeshDis& operator=(const MeshDis&);
425 // do not allow operator ==
426 bool operator==(const MeshDis&);
431 } // namespace MULTIPR
434 #endif // MULTIPR_MESHDIS_HXX