8 #include "MEDMEM_STRING.hxx"
9 #include "MEDMEM_Exception.hxx"
10 #include "MEDMEM_define.hxx"
12 //#include "MEDMEM_Support.hxx"
13 #include "MEDMEM_Coordinate.hxx"
14 #include "MEDMEM_Connectivity.hxx"
16 #include "MEDMEM_MedMeshDriver.hxx"
23 template <class T> class FIELD;
26 //class MED_MESH_RDONLY_DRIVER ;
27 //class MED_MESH_WRONLY_DRIVER ;
29 using namespace MED_EN;
31 /*! This class contains all the informations related with a MESH :
39 NOTE: A Family is only on one type of entity (MED_CELL, MED_FACE, MED_EDGE, MED_NODE).
40 You can't have a family on MED_CELL and MED_FACE
50 // ------- Drivers Management Part
53 //-----------------------//
55 //-----------------------//
58 virtual GENDRIVER * run(const string & fileName, MESH * ptrMesh) const = 0 ;
61 //-------------------------------------------------------//
62 template <class T> class INSTANCE_DE : public INSTANCE
63 //-------------------------------------------------------//
66 GENDRIVER * run(const string & fileName, MESH * ptrMesh) const
67 { return new T(fileName,ptrMesh) ; }
70 static INSTANCE_DE<MED_MESH_RDWR_DRIVER> inst_med ;
71 //static INSTANCE_DE<VTK_DRIVER> inst_vtk ;
72 static const INSTANCE * const instances[] ;
74 // ------ End of Drivers Management Part
77 //-----------------------//
79 //-----------------------//
83 string _name; // A POSITIONNER EN FCT DES IOS ?
85 int _numberOfMEDNodeFamily ; // INUTILE
86 int * _MEDArrayNodeFamily ; // SOLUTION TEMPORAIRE
87 int * _numberOfMEDCellFamily ; // INUTILE
88 int * _numberOfMEDFaceFamily ; // INUTILE
89 int * _numberOfMEDEdgeFamily ; // INUTILE
90 int ** _MEDArrayCellFamily ; // SOLUTION TEMPORAIRE
91 int ** _MEDArrayFaceFamily ; // SOLUTION TEMPORAIRE
92 int ** _MEDArrayEdgeFamily ; // SOLUTION TEMPORAIRE
94 COORDINATE * _coordinate;
95 CONNECTIVITY * _connectivity;
101 int _numberOfNodesFamilies; //INUTILE ? -> _familyNode.size()
102 vector<FAMILY*> _familyNode ; // array of size _numberOfNodesFamilies;
103 int _numberOfCellsFamilies;
104 vector<FAMILY*> _familyCell ; // array of size _numberOfCellsFamilies;
105 int _numberOfFacesFamilies;
106 vector<FAMILY*> _familyFace ; // array of size _numberOfFacesFamilies;
107 int _numberOfEdgesFamilies;
108 vector<FAMILY*> _familyEdge ; // array of size _numberOfEdgesFamilies;
110 int _numberOfNodesGroups; //INUTILE ?
111 vector<GROUP*> _groupNode; // array of size _numberOfNodesGroups;
112 int _numberOfCellsGroups; //INUTILE ?
113 vector<GROUP*> _groupCell; // array of size _numberOfCellsGroups;
114 int _numberOfFacesGroups; //INUTILE ?
115 vector<GROUP*> _groupFace; // array of size _numberOfFacesGroups;
116 int _numberOfEdgesGroups; //INUTILE ?
117 vector<GROUP*> _groupEdge; // array of size _numberOfEdgesGroups;
120 vector<GENDRIVER *> _drivers; // Storage of the drivers currently in use
122 //-----------------------//
124 //-----------------------//
128 friend class MED_MESH_RDONLY_DRIVER;
129 friend class MED_MESH_WRONLY_DRIVER;
134 MESH & operator=(const MESH &m);
135 MESH( driverTypes driverType, const string & fileName="",
136 const string & meshName="");
138 friend ostream & operator<<(ostream &os, MESH &my) ;
140 int addDriver(driverTypes driverType,
141 const string & fileName ="Default File Name.med",
142 const string & driverName="Default Mesh Name");
143 int addDriver(GENDRIVER & driver);
144 void rmDriver(int index=0);
146 inline void read(int index=0);
147 inline void write(int index=0, const string & driverName = "");
148 inline void write(const GENDRIVER &);
150 inline int * getMEDArrayNodeFamily() ;
151 inline int ** getMEDArrayCellFamily() ;
152 inline int ** getMEDArrayFaceFamily() ;
153 inline int ** getMEDArrayEdgeFamily() ;
155 // void calculateReverseConnectivity();
156 // void createFaces(); //Faces creation => full constituent informations
157 // void buildConstituent() ; // calculate descendent connectivity + face-cell connectivity
160 inline void setName(string name);
162 inline string getName() const;
163 inline int getSpaceDimension();
164 inline int getMeshDimension();
166 inline int getNumberOfNodes();
167 inline COORDINATE * getCoordinateptr();
168 inline string getCoordinatesSystem();
169 inline const double * getCoordinates(medModeSwitch Mode);
170 inline const double getCoordinate(int Number,int Axis);
171 inline string * getCoordinatesNames();
172 inline string * getCoordinatesUnits();
173 // inline int * getNodesNumbers();
175 inline int getNumberOfTypes(medEntityMesh Entity);
176 inline medGeometryElement * getTypes(medEntityMesh Entity);
177 inline CELLMODEL * getCellsTypes(medEntityMesh Entity);
178 inline int * getGlobalNumberingIndex(medEntityMesh Entity);
179 inline int getNumberOfElements(medEntityMesh Entity,medGeometryElement Type);
180 inline bool existConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity);
181 inline medGeometryElement getElementType(medEntityMesh Entity,int Number) ;
182 inline void calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity);
183 inline int * getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity, medGeometryElement Type);
184 inline int * getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh Entity);
185 int getElementNumber(medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type, int * connectivity) ;
186 inline int * getReverseConnectivity(medConnectivity ConnectivityType);
187 inline int * getReverseConnectivityIndex(medConnectivity ConnectivityType);
189 inline int getNumberOfFamilies(medEntityMesh Entity);
190 inline vector<FAMILY*> getFamilies(medEntityMesh Entity);
191 inline FAMILY* getFamily(medEntityMesh Entity,int i);
192 inline int getNumberOfGroups(medEntityMesh Entity);
193 inline vector<GROUP*> getGroups(medEntityMesh Entity);
194 inline GROUP* getGroup(medEntityMesh Entity,int i);
197 SUPPORT * getBoundaryElements(medEntityMesh Entity) throw (MEDEXCEPTION) ;
199 // Node DonneBarycentre(const Cell &m) const;
200 FIELD<double>* getVolume(const SUPPORT * Support) throw (MEDEXCEPTION) ; // Support must be on 3D elements
201 FIELD<double>* getArea(const SUPPORT * Support) throw (MEDEXCEPTION) ; // Support must be on 2D elements
202 FIELD<double>* getLength(const SUPPORT * Support) throw (MEDEXCEPTION) ; // Support must be on 1D elements
203 FIELD<double>* getNormal(const SUPPORT * Support) throw (MEDEXCEPTION) ; // Support must be on 2D elements
204 FIELD<double>* getBarycenter(const SUPPORT * Support) throw (MEDEXCEPTION) ;
205 // FIELD<int>* getNeighbourhood(SUPPORT * Support) throw (MEDEXCEPTION) ; // Il faut preciser !
208 // ---------------------------------------
210 // ---------------------------------------
212 inline void MESH::read(int index=0)
214 const char * LOC = "MESH::read(int index=0) : ";
217 if (_drivers[index]) {
218 _drivers[index]->open();
219 _drivers[index]->read();
220 _drivers[index]->close();
223 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
224 << "The index given is invalid, index must be between 0 and |"
231 /*! Write all the content of the MESH using driver referenced by the handler <index>*/
232 inline void MESH::write(int index=0, const string & driverName = "")
234 const char * LOC = "MESH::write(int index=0, const string & driverName = \"\") : ";
237 if ( _drivers[index] ) {
238 _drivers[index]->open();
239 if (driverName != "") _drivers[index]->setMeshName(driverName);
240 _drivers[index]->write();
241 _drivers[index]->close();
244 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
245 << "The index given is invalid, index must be between 0 and |"
252 // This method is MED specific : don't use it
254 inline void MESH::write(const GENDRIVER & genDriver)
256 const char * LOC = "MESH::write(const GENDRIVER & genDriver): ";
259 for (int index=0; index < _drivers.size(); index++ )
260 if ( *_drivers[index] == genDriver ) {
261 _drivers[index]->open();
262 _drivers[index]->write();
263 _drivers[index]->close();
264 // ? FINALEMENT PAS BESOIN DE L'EXCEPTION ?
271 /*! Set the MESH name */
272 inline void MESH::setName(string name)
274 _name=name ; //NOM interne à la classe
277 /*! Get the MESH name */
278 inline string MESH::getName() const
283 /*! Get the dimension of the space */
284 inline int MESH::getSpaceDimension()
286 return _spaceDimension;
289 /*! Get the dimension of the MESH */
290 inline int MESH::getMeshDimension()
292 return _meshDimension;
295 /*! Get the number of nodes used in the MESH */
296 inline int MESH::getNumberOfNodes()
298 return _numberOfNodes;
301 /*! Get the COORDINATES object. Use it only if you need COORDINATES informations not provided by the MESH class.*/
302 inline COORDINATE * MESH::getCoordinateptr()
307 /*! Get the system in which coordinates are given (CARTESIAN,CYLINDRICAL,SPHERICAL) __??MED_CART??__. */
308 inline string MESH::getCoordinatesSystem()
310 return _coordinate->getCoordinatesSystem();
313 /*! Get the whole coordinates array in a given interlacing mode. The interlacing mode are :
314 - MED_NO_INTERLACE : X1 X2 Y1 Y2 Z1 Z2
315 - MED_FULL_INTERLACE : X1 Y1 Z1 X2 Y2 Z2
317 inline const double * MESH::getCoordinates(medModeSwitch Mode)
319 return _coordinate->getCoordinates(Mode);
322 /*! Get the coordinate n° number on axis n°axis*/
323 inline const double MESH::getCoordinate(int number, int axis)
325 return _coordinate->getCoordinate(number,axis);
328 /*! Get the coordinate names array ("x ","y ","z ")
329 of size n*MED_TAILLE_PNOM
331 inline string * MESH::getCoordinatesNames()
333 return _coordinate->getCoordinatesNames();
336 /*! Get the coordinate unit names array ("cm ","cm ","cm ")
337 of size n*MED_TAILLE_PNOM
339 inline string * MESH::getCoordinatesUnits()
341 return _coordinate->getCoordinatesUnits();
343 // int * MESH::getNodesNumbers() {
344 // return nodesNumbers;
347 /*! Get the number of different geometric types for a given entity type.
348 For exemple getNumberOfTypes(MED_CELL) would return 2 is the MESH have some MED_TETRA4 and MED_HEXA6 in it.
349 medEntityMesh entity : MED_CELL, MED_FACE, MED_EDGE, MED_NODE, MED_ALL_ENTITIES
351 inline int MESH::getNumberOfTypes(medEntityMesh entity)
353 MESSAGE("MESH::getNumberOfTypes(medEntityMesh entity) : "<<entity);
354 if (entity == MED_NODE)
356 if (_connectivity != NULL)
357 return _connectivity->getNumberOfTypes(entity) ;
358 throw MEDEXCEPTION(LOCALIZED("MESH::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !"));
362 Get the list of geometric types used by a given entity.
363 medEntityMesh entity : MED_CELL, MED_FACE, MED_EDGE, MED_ALL_ENTITIES
364 REM : Don't use MED_NODE
366 inline medGeometryElement * MESH::getTypes(medEntityMesh entity)
368 if (entity == MED_NODE)
369 throw MEDEXCEPTION(LOCALIZED("MESH::getTypes( medEntityMesh ) : No medGeometryElement with MED_NODE entity !"));
371 if (_connectivity != NULL)
372 return _connectivity->getGeometricTypes(entity) ;
373 throw MEDEXCEPTION(LOCALIZED("MESH::getTypes( medEntityMesh ) : Connectivity not defined !"));
377 Get the whole list of CELLMODEL used by cells of given type (medEntityMesh).
378 REMARK : Don't use MED_NODE as medEntityMesh
380 inline CELLMODEL * MESH::getCellsTypes(medEntityMesh Entity)
382 if (_connectivity != NULL)
383 return _connectivity->getCellsTypes(Entity) ;
384 throw MEDEXCEPTION(LOCALIZED("MESH::getCellsTypes( medEntityMesh ) : Connectivity not defined !"));
387 /*! Since informations related with an entity type are stored in independent arrays, the only way to
388 get a uniq index is to call this method.
389 For exemple if you want the global numbers of your ... ????? size ?????
391 inline int * MESH::getGlobalNumberingIndex(medEntityMesh entity)
393 if (_connectivity != NULL)
394 return _connectivity->getGlobalNumberingIndex(entity);
395 throw MEDEXCEPTION(LOCALIZED("MESH::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !"));
397 inline int MESH::getNumberOfElements(medEntityMesh entity, medGeometryElement Type)
399 const char * LOC = "MESH::getNumberOfElements(medEntityMesh,medGeometryElement) : " ;
400 if (entity==MED_NODE)
401 if ((Type==MED_NONE)|(Type==MED_ALL_ELEMENTS))
402 return _numberOfNodes ;
405 //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"wrong medGeometryElement with MED_NODE"));
407 if (_connectivity != (CONNECTIVITY*)NULL)
408 return _connectivity->getNumberOf(entity,Type) ;
411 //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"connectivity not defined !"));
413 inline bool MESH::existConnectivity(medConnectivity connectivityType, medEntityMesh entity)
415 if (_connectivity==(CONNECTIVITY*)NULL)
416 throw MEDEXCEPTION("MESH::existConnectivity(medConnectivity,medEntityMesh) : no connectivity defined !");
417 return _connectivity->existConnectivity(connectivityType,entity) ;
420 Return the geometric type of element Number of entity Entity.
422 Throw an exception if Entity is not defined or Number are wrong (too big).
424 inline medGeometryElement MESH::getElementType(medEntityMesh Entity,int Number)
426 if (_connectivity==(CONNECTIVITY*)NULL)
427 throw MEDEXCEPTION("MESH::getElementType(medEntityMesh,int) : no connectivity defined !");
428 return _connectivity->getElementType(Entity,Number) ;
430 inline void MESH::calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity)
432 if (Mode==MED_FULL_INTERLACE)
433 _connectivity->calculateConnectivity(ConnectivityType,entity) ;
435 throw MEDEXCEPTION(LOCALIZED("MESH::calculateConnectivity : only for MED_FULL_INTERLACE mode"));
437 inline int * MESH::getConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh entity, medGeometryElement Type)
439 if (Mode==MED_FULL_INTERLACE)
440 return _connectivity->getConnectivity(ConnectivityType,entity,Type) ;
441 throw MEDEXCEPTION(LOCALIZED("MESH::getConnectivity : only for MED_FULL_INTERLACE mode"));
443 inline int * MESH::getConnectivityIndex(medConnectivity ConnectivityType,medEntityMesh entity)
445 return _connectivity->getConnectivityIndex(ConnectivityType, entity) ;
447 inline int * MESH::getReverseConnectivity(medConnectivity ConnectivityType)
449 if (ConnectivityType==MED_NODAL)
450 return _connectivity->getReverseNodalConnectivity() ;
451 else if (ConnectivityType==MED_DESCENDING)
452 return _connectivity->getReverseDescendingConnectivity() ;
453 throw MEDEXCEPTION("MESH::getReverseConnectivity : connectivity mode not supported !");
455 inline int * MESH::getReverseConnectivityIndex(medConnectivity ConnectivityType)
457 if (ConnectivityType==MED_NODAL)
458 return _connectivity->getReverseNodalConnectivityIndex() ;
459 else if (ConnectivityType==MED_DESCENDING)
460 return _connectivity->getReverseDescendingConnectivityIndex() ;
461 throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : connectivity mode not supported !");
465 inline int MESH::getNumberOfFamilies (medEntityMesh entity)
469 return _numberOfNodesFamilies ;
471 return _numberOfCellsFamilies ;
473 return _numberOfFacesFamilies ;
475 return _numberOfEdgesFamilies ;
477 throw MEDEXCEPTION("MESH::getNumberOfFamilies : Unknown entity");
480 inline int MESH::getNumberOfGroups (medEntityMesh entity)
484 return _numberOfNodesGroups ;
486 return _numberOfCellsGroups ;
488 return _numberOfFacesGroups ;
490 return _numberOfEdgesGroups ;
492 throw MEDEXCEPTION("MESH::getNumberOfGroups : Unknown entity");
495 vector<FAMILY*> MESH::getFamilies(medEntityMesh entity) {
506 throw MEDEXCEPTION("MESH::getFamilies : Unknown entity");
510 vector<GROUP*> MESH::getGroups(medEntityMesh entity) {
521 throw MEDEXCEPTION("MESH::getGroups : Unknown entity");
525 FAMILY* MESH::getFamily(medEntityMesh entity, int i) {
527 throw MEDEXCEPTION("MESH::getFamily(i) : argument i must be > 0");
528 int NumberOfFamilies = 0 ;
529 vector<FAMILY*> Family ;
532 NumberOfFamilies = _numberOfNodesFamilies ;
533 Family = _familyNode ;
537 NumberOfFamilies = _numberOfCellsFamilies ;
538 Family = _familyCell ;
542 NumberOfFamilies = _numberOfFacesFamilies ;
543 Family = _familyFace ;
547 NumberOfFamilies = _numberOfEdgesFamilies ;
548 Family = _familyEdge ;
552 throw MEDEXCEPTION("MESH::getFamilies : Unknown entity");
554 if (i>NumberOfFamilies)
555 throw MEDEXCEPTION("MESH::getFamily(entity,i) : argument i must be <= _numberOfFamilies");
559 GROUP* MESH::getGroup(medEntityMesh entity, int i) {
560 const char * LOC = "MESH::getGroup(medEntityMesh entity, int i) : " ;
562 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"argument i must be > 0"));
563 int NumberOfGroups = 0 ;
564 vector<GROUP*> Group ;
567 NumberOfGroups = _numberOfNodesGroups ;
572 NumberOfGroups = _numberOfCellsGroups ;
577 NumberOfGroups = _numberOfFacesGroups ;
582 NumberOfGroups = _numberOfEdgesGroups ;
587 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Unknown entity"));
589 if (i>NumberOfGroups)
590 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"argument i="<<i<<" must be <= _numberOfGroups="<<NumberOfGroups));
599 //inline void MESH::write(const string & driverName) {
600 // write(0,driverName);
604 // this method are temporary, perhaps we remove it if we put information in an other place
605 inline int * MESH::getMEDArrayNodeFamily() {
606 return _MEDArrayNodeFamily ;
608 inline int ** MESH::getMEDArrayCellFamily() {
609 return _MEDArrayCellFamily ;
611 inline int ** MESH::getMEDArrayFaceFamily() {
612 return _MEDArrayFaceFamily ;
614 inline int ** MESH::getMEDArrayEdgeFamily() {
615 return _MEDArrayEdgeFamily ;
618 #endif /* MESH_HXX */