1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Partitioning/decimation module for the SALOME v3.2 platform
22 * \file MULTIPR_Mesh.hxx
24 * \brief Class Mesh used by the MULTIPR API; used to wrap MED file meshes.
26 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
31 #ifndef MULTIPR_MESH_HXX
32 #define MULTIPR_MESH_HXX
34 //*****************************************************************************
36 //*****************************************************************************
50 #include "MULTIPR_Globals.hxx"
55 //*****************************************************************************
57 //*****************************************************************************
69 extern const med_geometrie_element CELL_TYPES[MED_NBR_GEOMETRIE_MAILLE];
70 extern char CELL_NAMES[MED_NBR_GEOMETRIE_MAILLE][MED_TAILLE_NOM + 1];
71 extern const int CELL_NB_NODE[MED_NBR_GEOMETRIE_MAILLE];
93 //*****************************************************************************
95 //*****************************************************************************
99 * - 3D mesh in a 3D space
100 * - Unstructured mesh (not a grid)
101 * - Nodal connectivity
102 * - Cartesian coordinates system
103 * Always use FULL_INTERLACE arrays
110 * Builds an empty Mesh (default constructor).
115 * Destructor. Removes everything.
120 * Resets this object in its state by default (empty). Cleans memory.
124 //---------------------------------------------------------------------
125 // Basic accessors/mutators
126 //---------------------------------------------------------------------
129 * Returns the name of this Mesh.
130 * \return the name of this Mesh.
132 const char* getName() const { return mMeshName; }
135 * Returns the groups of this Mesh.
136 * \return the groups of this Mesh.
138 std::vector<Group*>* getGroups() { return &mGroups; }
141 * Returns the nodes of this Mesh.
142 * \return the nodes of this Mesh.
144 const Nodes* getNodes() const { return mNodes; }
147 * Returns the elements of this Mesh.
148 * \param pGeomIdx The index of the geometry.
149 * \return the elements of this Mesh.
151 const Elements* getElements(int pGeomIdx) const { return mElements[pGeomIdx]; }
154 * Returns the gauss index of the splited meshes.
155 * Only valid after a call to Mesh::splitGroupsOfElements().
156 * \return the elements of this Mesh.
158 GaussIndexList* editGaussIndex() { return &mGaussIndex; }
161 * Returns the name of all the scalar fields.
162 * \return the name of all the scalar fields.
164 std::vector<std::string> getNameScalarFields() const;
167 * Returns the number of iteration for a given field.
168 * \return the number of iteration for a given field.
170 int getTimeStamps(const char* pFieldName) const;
173 * Returns a Field from its name; NULL if it does not exist.
174 * \param pFieldName name of the field to be retrieved.
175 * \param pGeomType The type of the mesh.
176 * \return the Field pFieldName of it exists, NULL otherwise.
177 * \throw NullArgumentException if pFieldName is NULL.
179 Field* getFieldByName(const char* pFieldName, eMeshType pGeomType = eMaxMedMesh) const;
182 * Get the minimum and maximum value of the field.
183 * \param pFieldName The name of the field.
184 * \param pMin The mininum value to fill.
185 * \param pMax The maxinum value to fill.
187 void getFieldMinMax(const char* pFieldName, float& pMin, float& pMax) const;
190 * Returns a GaussLoc from its name; NULL if it does not exist.
191 * \param pGaussLocName name of the GaussLoc to be retrieved.
192 * \return the GaussLoc pGaussLocName if it exists, NULL otherwise.
193 * \throw NullArgumentException if pGaussLocName is NULL.
195 GaussLoc* getGaussLocByName(const char* pGaussLocName) const;
198 * Returns the number of elements for all geometry type (TETRA4 AND HEXA8 AND etc).
199 * \return the number of elements.
201 int getNumberOfElements() const;
204 * Returns the number of elements for the specified geometry type.
205 * \param pGeomType The type of geometry (eMED_TETRA4 OR eMED_HEXA20 OR etc)
206 * \return the number of elements.
208 int getNumberOfElements(eMeshType pGeomType) const;
211 * Add a profile to the mesh.
212 * \param pProfil The profile to add.
214 void addProfile(Profil* pProfil) { this->mProfils.push_back(pProfil); }
217 * Get the vector of profiles of this mesh.
218 * \return A vector of profiles (of this mesh...).
220 std::vector<Profil*>& getProfils() { return mProfils; }
223 * Get the profile by its name.
224 * \param pProfilName The name of the profil to get.
225 * \return A Profil or NULL.
227 Profil* getProfil(const std::string pProfilName);
229 //---------------------------------------------------------------------
231 //---------------------------------------------------------------------
234 * Creates a Mesh from a subset of its elements (cells).
235 * \param pSetOfElements subset of elements to keep.
236 * \param pNewMeshName name of the new Mesh.
237 * \return a new Mesh which is a restriction of this Mesh to the given set of elements.
238 * \throw NullArgumentException if pNewMeshName is NULL.
240 Mesh* createFromSetOfElements(const std::set<med_int>* pSetOfElements, const char* pNewMeshName);
243 * Creates a Mesh from one of its group.
244 * \param pGroup any group of this Mesh.
245 * \param pNewMeshName name of the new Mesh.
246 * \return a new Mesh which is a restriction of this Mesh to pGroup.
247 * \throw NullArgumentException if pGroup or pNewMeshName is NULL.
249 Mesh* createFromGroup(const Group* pGroup, const char* pNewMeshName);
252 * Creates a Mesh from one of its family.
253 * \param pFamily any family of this Mesh.
254 * \param pNewMeshName name of the new Mesh.
255 * \return a new Mesh which is a restriction of this Mesh to pFamily.
256 * \throw NullArgumentException if pGroup or pNewMeshName is NULL.
258 Mesh* createFromFamily(const Family* pFamily, const char* pNewMeshName);
261 * Creates a Mesh by merging this one with the given one.
262 * Warning: not all the data are merged (e.g. bounding box if not computed and family/groups are partially filled).
263 * This method is intended to be used to build mesh for visualization (VISU integration).
264 * Merge is partial to improve speed.
265 * \param pMesh any Mesh
266 * \return a new Mesh which is a the union of this and pMesh.
267 * \throw NullArgumentException if pGroup or pNewMeshName is NULL.
269 //Mesh* mergePartial(const Mesh* pMesh);
270 Mesh* mergePartial(std::vector<Mesh*> pMeshes, const char* pFieldName, int pFieldIt);
273 * Creates a distributed mesh (MeshDis) by creating a new mesh for each group of elements in this Mesh.
274 * \return a distributed mesh from groups of this Mesh.
276 MeshDis* splitGroupsOfElements();
279 * Creates a new mesh by decimating this one.
280 * \param pFilterName name of the filter to be used for decimation (e.g. Filtre_GradientMoyen); should not be NULL.
281 * \param pArgv all the arguments for filtering as a single string.
282 * \param pNameNewMesh name of the new mesh.
283 * \return the decimated mesh.
284 * \throw NullArgumentException if one of the arguments is NULL.
285 * \throw RuntimeException if any error occurs while decimating data.
288 const char* pFilterName,
290 const char* pNameNewMesh);
293 * Gets all the points in a field. Each point has coordinates and a value.
294 * \param pField any field of this Mesh.
295 * \param pTimeStepIt time step iteration.
296 * \param pPoints (out) list of points.
297 * \param pGeomType Get the points from this type of geometry. If the values are on the node, this parameter is ignored.
298 * \throw NullArgumentException if pField is NULL.
299 * \throw IllegalArgumentException if pTimeStepIt is invalid.
301 void getAllPointsOfField(Field* pField, int pTimeStepIt, std::vector<PointOfField>& pPoints, eMeshType pGeomType);
304 * Returns a default value for neighborhood radius.
305 * Return value is such that, for any point in the field, average number of neighbours is pN.
306 * \param pN average number of neighbours.
307 * \return a default value for neighborhood radius; 1.0 if some error occurs.
309 float evalDefaultRadius(int pN) const;
311 //---------------------------------------------------------------------
313 //---------------------------------------------------------------------
316 * Reads a Mesh from a sequential MED file. Resets the object before.
317 * \param pMEDfilename
319 * \param pReadFields Set this to false to skip field.
320 * \throw IOException if any i/o error occurs.
322 void readSequentialMED(const char* pMEDfilename, const char* pMeshName, bool pReadFields = true);
325 * Reads a Mesh from a sequential MED file. Resets the object before.
326 * \param pMEDfilename
328 * \param pReadFields Set this to false to skip field.
329 * \throw IOException if any i/o error occurs.
331 void readSequentialMED(const char* pMEDfilename, med_int pMeshNumber, bool pReadFields = true);
334 * Writes this Mesh and all related things into a MED file.
335 * \param pMEDfilename
336 * \throw IOException if any i/o error occurs.
338 void writeMED(const char* pMEDfilename);
341 * Writes this Mesh and all related things into a MED file.
342 * \param pMEDfilename
344 * \throw IOException if any i/o error occurs.
346 void writeMED(const char* pMEDfilename, const char* pMeshName);
349 * Sets the flag which control the stream operator <<.
350 * \param pFlag new flag value.
352 void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; }
355 * Dumps any Mesh to the given output stream.
356 * \param pOs any output stream.
357 * \param pM any Mesh.
358 * \return the output stream pOs.
360 friend std::ostream& operator<<(std::ostream& pOs, Mesh& pM);
365 * Opens a MED file for the given file name.
366 * \param pMEDfilename
367 * \param pMEDModeAccess
368 * \throw IOException if any i/o error occurs.
370 void _openMEDFile(const char* pMEDfilename, med_mode_acces pMEDModeAccess = MED_LECTURE);
373 * Reads a Mesh from a sequential MED file. Resets the object before.
375 * \param pReadFields Set this to false to skip field.
376 * \throw IOException if any i/o error occurs.
378 void _readSequentialMED(const char* pMeshName, bool pReadFields);
381 * Reads all Gauss localizations in the current MED file.
382 * \throw IOException if an i/o error occurs.
387 * Reads families in the currentMED file and build groups.
388 * \throw IOException if an i/o error occurs.
393 * Finalizes the constructions of families and groups.
394 * Fill structures with elements.
396 void finalizeFamiliesAndGroups();
399 * Reads fields related to this mesh in the current MED file.
400 * \throw IOException if an i/o error occurs.
407 * Name of the associated MED file.
409 char mMEDfilename[256];
419 char mMeshName[MED_TAILLE_NOM + 1];
422 * Universal name of this mesh.
424 char mMeshUName[MED_TAILLE_DESC + 1];
429 char mMeshDesc[MED_TAILLE_DESC + 1];
437 * Type of mesh (MED_NON_STRUCTURE or MED_STRUCTURE (=grid))
439 med_maillage mMeshType;
442 * Axis aligned bounding box of this mesh.
444 med_float mMeshBBoxMin[3];
445 med_float mMeshBBoxMax[3];
448 * All the nodes used by this mesh.
453 * All the TETRA10 elements used by this mesh.
455 Elements* mElements[eMaxMedMesh];
458 * Table of families used by this mesh.
460 std::vector<Family*> mFamilies;
463 * Map to retrieve a Family from its id.
465 std::map<med_int, Family*> mFamIdToFam;
468 * Table of groups used by this mesh.
470 std::vector<Group*> mGroups;
473 * Map to retrieve a Group from its name.
475 std::map<std::string, Group*> mGroupNameToGroup;
480 std::vector<GaussLoc*> mGaussLoc;
483 * Map to retrieve a Gauss info from its name.
485 std::map<std::string, GaussLoc*> mGaussLocNameToGaussLoc;
488 * Table of fields related to this mesh.
489 * Number of fields = mFields.size().
491 std::vector<Field*> mFields;
496 std::vector<Profil*> mProfils;
499 * Flag to control the behaviour of the stream operator <<.
504 * List of gauss points index for optimized domain split.
506 GaussIndexList mGaussIndex;
510 // do not allow copy constructor
514 Mesh& operator=(const Mesh&);
516 // do not allow operator ==
517 bool operator==(const Mesh&);
522 } // namespace MULTIPR
525 #endif // MULTIPR_MESH_HXX