2 #include "MEDMEM_MedMeshDriver.hxx"
4 #include "MEDMEM_DriversDef.hxx"
6 #include "MEDMEM_Family.hxx"
7 #include "MEDMEM_Group.hxx"
8 #include "MEDMEM_Coordinate.hxx"
9 #include "MEDMEM_Connectivity.hxx"
10 #include "MEDMEM_Mesh.hxx"
11 #include "MEDMEM_CellModel.hxx"
14 extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom);
15 extern med_err _MEDdatagroupFermer(med_idt id);
17 using namespace MED_FR;
19 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor
21 void MED_MESH_DRIVER::setMeshName(const string & meshName) { _meshName = meshName; };
22 string MED_MESH_DRIVER::getMeshName() const { return _meshName; };
24 //---------------------------------- RDONLY PART -------------------------------------------------------------
26 //A FAIRE UTILISER LES MAPS...
27 const MED_FR::med_geometrie_element MED_MESH_DRIVER::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]=
28 { MED_FR::MED_POINT1,MED_FR::MED_SEG2,MED_FR::MED_SEG3,MED_FR::MED_TRIA3,MED_FR::MED_QUAD4,MED_FR::MED_TRIA6,MED_FR::MED_QUAD8,
29 MED_FR::MED_TETRA4,MED_FR::MED_PYRA5,MED_FR::MED_PENTA6,MED_FR::MED_HEXA8,MED_FR::MED_TETRA10,MED_FR::MED_PYRA13,
30 MED_FR::MED_PENTA15, MED_FR::MED_HEXA20};
32 const char * const MED_MESH_DRIVER::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]=
33 { "MED_POINT1","MED_SEG2","MED_SEG3","MED_TRIA3","MED_QUAD4","MED_TRIA6","MED_QUAD8",
34 "MED_TETRA4","MED_PYRA5","MED_PENTA6","MED_HEXA8","MED_TETRA10","MED_PYRA13",
35 "MED_PENTA15","MED_HEXA20"};
40 void MED_MESH_RDONLY_DRIVER::read(void)
42 const char * LOC = "MED_MESH_RDONLY_DRIVER::read() : " ;
44 if (_status!=MED_OPENED)
45 throw MEDEXCEPTION(" ");
46 //throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName << " is : " << _medIdt << " (the file is not opened)." )) ;
48 _ptrMesh->_name = _meshName;
50 if (getCOORDINATE()!=MED_VALID)
51 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE" )) ;
53 if (getCONNECTIVITY()!=MED_VALID)
54 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOONECTIVITY")) ;
56 if (getFAMILY()!=MED_VALID)
57 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY" )) ;
61 // we build all groups
63 buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
64 _ptrMesh->_numberOfNodesGroups = _ptrMesh->_groupNode.size() ;
66 buildAllGroups(_ptrMesh->_groupCell,_ptrMesh->_familyCell) ;
67 _ptrMesh->_numberOfCellsGroups = _ptrMesh->_groupCell.size() ;
69 buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace) ;
70 _ptrMesh->_numberOfFacesGroups = _ptrMesh->_groupFace.size() ;
72 buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ;
73 _ptrMesh->_numberOfEdgesGroups = _ptrMesh->_groupEdge.size() ;
75 MESSAGE(LOC<<"Checking of CellModel !!!!!!!");
77 int nbOfTypes = _ptrMesh->_connectivity->_numberOfTypes;
78 for(int i=0;i<nbOfTypes;i++)
80 MESSAGE(LOC << _ptrMesh->_connectivity->_type[i]) ;
87 // A FAIRE : RENVOYER DU VOID
88 int MED_MESH_RDONLY_DRIVER::getCOORDINATE()
90 const char * LOC = "MED_MESH_RDONLY_DRIVER::getCOORDINATE() : " ;
93 if (_status==MED_OPENED)
97 // Read the dimension of the space for the mesh <_meshName>
98 // to be able to create a COORDINATE object
99 int SpaceDimension = MEDdimLire(_medIdt,const_cast <char *> (_meshName.c_str())) ;
100 if ( SpaceDimension <= MED_VALID )
101 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The space dimension |" << SpaceDimension << "| seems to be incorrect "
102 << "for the mesh : |" << _meshName << "|")) ;
103 _ptrMesh->_spaceDimension = SpaceDimension ;
107 // Read the number of nodes used in the mesh <_meshName>
108 // to be able to create a COORDINATE object
109 int NumberOfNodes=MEDnEntMaa(_medIdt,
110 const_cast <char *> (_meshName.c_str()),
113 (MED_FR::med_geometrie_element) MED_NONE,
114 (MED_FR::med_connectivite) MED_NONE);
115 if ( NumberOfNodes <= MED_VALID )
116 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes << "| seems to be incorrect "
117 << "for the mesh : |" << _meshName << "|" )) ;
118 _ptrMesh->_numberOfNodes = NumberOfNodes ;
122 // create a COORDINATE object
123 _ptrMesh->_coordinate = new COORDINATE(MED_EN::MED_FULL_INTERLACE, SpaceDimension, NumberOfNodes);
125 MED_FR::med_repere rep ; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON?
126 string tmp_nom_coord (MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,'\0');
127 string tmp_unit_coord(MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,'\0');
128 char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str()) ) ;
129 char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
131 err=MEDcoordLire(_medIdt,
132 const_cast <char *> (_ptrMesh->_name.c_str()),
133 _ptrMesh->_spaceDimension,
134 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
135 MED_FR::MED_FULL_INTERLACE,
136 MED_ALL, // we read all the coordinates
137 NULL, // we don't use a profile
138 0, // so the profile's size is 0
139 &rep,tmp_nom,tmp_unit);
140 if (err != MED_VALID)
141 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" << NumberOfNodes << "| nodes "
142 << "for the mesh : |" << _meshName
143 << "| of space dimension |" << SpaceDimension
144 << "| with units names |" << tmp_nom
145 << "| and units |" << tmp_unit
148 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
149 // PG : What about blank !!!!!
150 _ptrMesh->_coordinate->_coordinateName[i]=string(tmp_nom,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ;
151 _ptrMesh->_coordinate->_coordinateUnit[i]=string(tmp_unit,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
154 // Pourquoi le stocker sous forme de chaîne ?
157 case MED_FR::MED_CART :
159 _ptrMesh->_coordinate->_coordinateSystem = "CARTESIAN";
162 case MED_FR::MED_CYL :
164 _ptrMesh->_coordinate->_coordinateSystem = "CYLINDRICAL";
167 case MED_FR::MED_SPHER :
169 _ptrMesh->_coordinate->_coordinateSystem = "SPHERICAL";
174 _ptrMesh->_coordinate->_coordinateSystem = "UNDEFINED"; // ?Erreur ?
179 // Read the unused optionnal node Names
180 char * tmp_node_name = new char[NumberOfNodes*MED_TAILLE_PNOM+1];
181 tmp_node_name[NumberOfNodes]='\0' ;
182 err=MEDnomLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
183 tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM,MED_FR::MED_NOEUD,
184 (MED_FR::med_geometrie_element) MED_NONE);
185 if (err == MED_VALID)
186 INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !");
187 delete[] tmp_node_name ;
190 // ??? Read the unused optionnal node Numbers ???
191 int * tmp_node_number = new int[NumberOfNodes] ;
192 err=MEDnumLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
193 tmp_node_number,NumberOfNodes,MED_NOEUD,(MED_FR::med_geometrie_element)0);
194 if (err == MED_VALID) {
195 INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
196 INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !");
197 INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
198 _ptrMesh->_coordinate->_nodeNumber = tmp_node_number ;
200 delete[] tmp_node_number ;
209 int MED_MESH_RDONLY_DRIVER::getCONNECTIVITY()
211 const char * LOC = "MED_MESH_RDONLY_DRIVER::getCONNECTIVITY : " ;
214 if (_status==MED_OPENED)
218 // read MED_CELL connectivity
219 CONNECTIVITY * Connectivity = new CONNECTIVITY(MED_CELL) ;
220 Connectivity->_numberOfNodes = _ptrMesh->_numberOfNodes ; // EF : Pourquoi cet attribut est-il dans MESH et non dans COORDINATE ?
222 // Try to read nodal connectivity of the cells <Connectivity->_nodal>
223 // then try to read descending connectivity <Connectivity->_descending>
224 // if neither nodal nor descending connectivity exists
225 // throw an exception.
226 err = getNodalConnectivity(Connectivity) ;
227 if (err!=MED_VALID) {
228 Connectivity->_typeConnectivity = MED_DESCENDING ;
229 err = getDescendingConnectivity(Connectivity) ;
231 getDescendingConnectivity(Connectivity) ; // we read it if there is one
233 if (err!=MED_VALID) {
234 delete Connectivity ;
235 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "We could not read any Connectivity")) ;
238 _ptrMesh->_meshDimension = Connectivity->_entityDimension ;
240 // At this point Connectivity->_typeConnectivity is either NODAL or DESCENDING
241 // If both connectivities are found Connectivity->_typeConnectivity is NODAL
242 // If space dimension is 3
243 // try to read the nodal connectivity of the faces <ConnectivityFace->_nodal> then
244 // try to read the descending connectivity <ConnectivityFace->_descending>
245 // if there is no descending connectivity and the CELLS are
246 // defined in descending mode then throw an exception
248 // PROVISOIRE : if we have some face or edge in MED_MAILLE, we don't read more. There could not be have face or edge !!!!
250 if(Connectivity->_constituent==NULL) {
252 SCRUTE(_ptrMesh->_meshDimension);
253 if (_ptrMesh->_meshDimension == 3) {
254 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES FACES..." );
255 CONNECTIVITY * ConnectivityFace = new CONNECTIVITY(MED_EN::MED_FACE) ;
256 ConnectivityFace->_typeConnectivity = Connectivity->_typeConnectivity ; // NODAL or DESCENDING
257 SCRUTE(ConnectivityFace->_typeConnectivity);
258 if (Connectivity->_typeConnectivity == MED_DESCENDING) {
259 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES FACES" );
260 err = getDescendingConnectivity(ConnectivityFace) ;
262 throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No FACE in descending connectivity")) ;
263 getNodalConnectivity(ConnectivityFace) ; // if any !
265 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES FACES" );
266 err = getNodalConnectivity(ConnectivityFace) ;
267 if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
268 err = getDescendingConnectivity(ConnectivityFace) ;
270 getDescendingConnectivity(ConnectivityFace); // if any !
272 if (err!=MED_VALID) {
273 delete ConnectivityFace ;
274 MESSAGE(LOC<<"No FACE defined.") ;
276 MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES FACES DANS L'OBJET CONNECTIVITY" );
277 Connectivity->_constituent=ConnectivityFace ;
281 // read MED_EDGE connectivity
282 if (_ptrMesh->_meshDimension > 1) { // we are in 3 or 2D
283 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES ARRETES...." );
284 CONNECTIVITY * ConnectivityEdge = new CONNECTIVITY(MED_EDGE) ;
285 ConnectivityEdge->_typeConnectivity = Connectivity->_typeConnectivity ;
286 if (Connectivity->_typeConnectivity == MED_DESCENDING) {
287 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES ARRETES" );
288 err = getDescendingConnectivity(ConnectivityEdge) ;
290 throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No EDGE in descending connectivity")) ;
291 getNodalConnectivity(ConnectivityEdge) ; // if any !
293 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES ARRETES" );
294 err = getNodalConnectivity(ConnectivityEdge) ;
295 if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
296 err = getDescendingConnectivity(ConnectivityEdge) ;
298 getDescendingConnectivity(ConnectivityEdge) ; // if any !
300 if (err!=MED_VALID) {
301 delete ConnectivityEdge ;
302 MESSAGE(LOC<<"No EDGE defined.") ;
304 if (_ptrMesh->_meshDimension == 3)
305 if (Connectivity->_constituent != NULL)
306 Connectivity->_constituent->_constituent=ConnectivityEdge ;
308 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "EDGE defined but there are no FACE !")) ;
310 MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES ARETES DANS L'OBJET CONNECTIVITY" );
311 Connectivity->_constituent=ConnectivityEdge ;
316 _ptrMesh->_connectivity = Connectivity ;
320 // we have read all connectivity in file, now we must build descending connectivity if necessary !
322 // If connectivity descending is defined, we have nothing to do, all constituent are defined !
323 // If connectivity is only nodal, we must rebuild descending if we have some contituent !
326 // if (Connectivity->_descending == NULL)
327 // if (Connectivity->_constituent != NULL){
328 // // update Connectivity->_constituent
329 // CONNECTIVITY * myConstituentOld = Connectivity->_constituent ;
330 // Connectivity->_constituent = (CONNECTIVITY *)NULL ;
331 // Connectivity->calculateDescendingConnectivity() ;
341 int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity)
343 const char * LOC = "MED_MESH_RDONLY_DRIVER::getNodalConnectivity : " ;
345 if (_status==MED_OPENED)
347 // Get the type of entity to work on (previously set in the Connectivity Object)
348 MED_FR::med_entite_maillage Entity = (MED_FR::med_entite_maillage) Connectivity->getEntity();
350 // Get the number of cells of each type & store it in <tmp_cells_count>.
351 int * tmp_cells_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
352 for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) { // EF :ON SCANNE DES GEOMETRIES INUTILES, UTILISER LES MAPS
353 tmp_cells_count[i]=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
354 MED_FR::MED_CONN,(MED_FR::med_entite_maillage) Entity,
355 all_cell_type[i],MED_FR::MED_NOD);
357 // We suppose there is no cells used as faces, this is forbidden !!!
359 // Only in version 2.2.x of MED, but before, it's right :-(
361 if (tmp_cells_count[i]>0) {
362 Connectivity->_entityDimension=all_cell_type[i]/100;
363 Connectivity->_numberOfTypes++;
368 // well if there is nothing, we quit !
369 if ( Connectivity->_numberOfTypes == 0 ) {
370 delete[] tmp_cells_count ;
374 // if MED version < 2.2.x, we read only entity with dimention = Connectivity->_entityDimension. Lesser dimension are face or edge !
376 char version_med[10] ;
377 if ( MEDfichEntete(_medIdt,MED_FR::MED_VERSION,version_med) != 0 ){
378 // error : we suppose we have not a good med file !
379 delete[] tmp_cells_count ;
383 // we get version number
384 // string medVersion(version_med);
386 int * tmp_edges_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
387 int numberOfEdgesTypes = 0;
388 int * tmp_faces_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
389 int numberOfFacesTypes = 0;
390 if ((version_med != "2.2")&(Entity==MED_MAILLE)) {
391 Connectivity->_numberOfTypes=0;
392 for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) {
393 tmp_faces_count[i]=0;
394 tmp_edges_count[i]=0;
395 if (tmp_cells_count[i]!=0) {
396 int dimension = all_cell_type[i]/100 ;
397 if (Connectivity->_entityDimension==dimension)
398 Connectivity->_numberOfTypes++ ;
401 if (Connectivity->_entityDimension==3) {
402 tmp_faces_count[i]=tmp_cells_count[i] ;
403 tmp_cells_count[i]=0 ;
404 numberOfFacesTypes++;
407 if (Connectivity->_entityDimension>dimension) {
408 tmp_edges_count[i]=tmp_cells_count[i] ;
409 tmp_cells_count[i]=0;
410 numberOfEdgesTypes++ ;
416 // bloc to read CELL :
418 // Prepare an array of indexes on the different cell types to create a MEDSKYLINEARRAY
419 // We use <tmp_cells_count> to calculate <Connectivity->_count> then we release it
420 Connectivity->_geometricTypes = new MED_EN::medGeometryElement [Connectivity->_numberOfTypes] ; // Double emploi pour des raisons pratiques
421 Connectivity->_type = new CELLMODEL [Connectivity->_numberOfTypes] ; //
422 Connectivity->_count = new int [Connectivity->_numberOfTypes+1] ;
423 Connectivity->_count[0] = 1;
427 for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) { // no point1 cell type (?)
428 if (tmp_cells_count[i]>0) {
430 Connectivity->_count[TypeNumber]=Connectivity->_count[TypeNumber-1]+tmp_cells_count[i];
432 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ;
433 Connectivity->_type[TypeNumber-1]=t ;
435 Connectivity->_geometricTypes[TypeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ;
437 // probleme avec les mailles de dimension < a dimension du maillage :
438 // Il faut oter le zero a la lecture est le remettre a l'ecriture : ce n'est pas fait !!!!! On interdit ce cas pour l'instant !!!
441 size+=tmp_cells_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ;
444 << Connectivity->_count[TypeNumber]-1 << " cells of type "
445 << all_cell_type_tab[i] );
450 // Creation of the MEDSKYLINEARRAY
451 Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,size) ;
452 int * NodalIndex = Connectivity->_nodal->getIndex() ;
455 // Fill the MEDSKYLINEARRAY by reading the MED file.
456 for (int i=0;i<Connectivity->_numberOfTypes;i++) {
458 MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) Connectivity->_type[i].getType() ;
459 // if ( Connectivity->_type[i].getDimension() < Connectivity->_entityDimension)
460 if (Connectivity->_entity == MED_CELL)
461 if ( Connectivity->_type[i].getDimension() < _ptrMesh->_spaceDimension)
464 // int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
465 int NumberOfNodeByCell = Connectivity->_type[i].getNumberOfNodes() ;
468 for (int j=Connectivity->_count[i]; j<Connectivity->_count[i+1];j++)
469 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByCell ;
471 int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i] ;
472 int * tmp_ConnectivityArray = new int[(NumberOfNodeByCell+multi)*tmp_numberOfCells];
474 // int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
475 // Connectivity->_entityDimension,tmp_ConnectivityArray,
476 // MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD);
477 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
478 _ptrMesh->_spaceDimension,tmp_ConnectivityArray,
479 MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD);
480 if ( err != MED_VALID) {
481 delete[] tmp_ConnectivityArray;
482 delete[] tmp_cells_count;
483 delete[] tmp_faces_count;
484 delete[] tmp_edges_count;
485 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
488 int * ConnectivityArray = Connectivity->_nodal->getI(Connectivity->_count[i]) ;
489 for (int j=0; j<tmp_numberOfCells; j++)
490 for (int k=0; k<NumberOfNodeByCell; k++)
491 ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
493 delete[] tmp_ConnectivityArray;
496 } // end of bloc to read CELL
498 delete[] tmp_cells_count;
503 if (numberOfFacesTypes!=0) {
504 CONNECTIVITY * constituent = new CONNECTIVITY(numberOfFacesTypes,MED_EN::MED_FACE) ;
505 constituent->_entityDimension = 2 ;
506 constituent->_count[0]=1 ;
509 int size_more_one = 0 ;
511 for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) { // no point1 cell type (?)
512 if (tmp_faces_count[i]>0) {
514 constituent->_count[TypeNumber]=constituent->_count[TypeNumber-1]+tmp_faces_count[i];
515 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ;
516 constituent->_type[TypeNumber-1]=t ;
518 constituent->_geometricTypes[TypeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ;
520 size+=tmp_faces_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ;
525 // Creation of the MEDSKYLINEARRAY
526 constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ;
527 int * NodalIndex = constituent->_nodal->getIndex() ;
530 // Fill the MEDSKYLINEARRAY by reading the MED file.
531 for (int i=0;i<constituent->_numberOfTypes;i++) {
532 MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) constituent->_type[i].getType() ;
534 int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes() ;
537 for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
538 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByFace ;
540 int tmp_numberOfFaces = constituent->_count[i+1]-constituent->_count[i] ;
541 // Il faut ajouter 1 pour le zero a la lecture !!!
542 int * tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ;
544 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
545 Connectivity->_entityDimension,tmp_constituentArray,
546 MED_FR::MED_FULL_INTERLACE,NULL,0,MED_FR::MED_MAILLE,med_type,MED_FR::MED_NOD);
547 if ( err != MED_VALID) {
548 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
550 delete[] tmp_constituentArray;
551 delete[] tmp_faces_count;
552 delete[] tmp_edges_count;
556 int * constituentArray = constituent->_nodal->getI(constituent->_count[i]) ;
557 for (int j=0; j<tmp_numberOfFaces; j++)
558 for (int k=0; k<NumberOfNodeByFace; k++)
559 constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
561 delete[] tmp_constituentArray;
564 Connectivity->_constituent = constituent ;
567 delete[] tmp_faces_count;
571 if (numberOfEdgesTypes!=0) {
572 CONNECTIVITY * constituent = new CONNECTIVITY(numberOfEdgesTypes,MED_EDGE) ;
573 constituent->_entityDimension = 2 ;
574 constituent->_count[0]=1 ;
577 int size_more_one = 0 ;
579 for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) { // no point1 cell type (?)
580 if (tmp_edges_count[i]>0) {
582 constituent->_count[TypeNumber]=constituent->_count[TypeNumber-1]+tmp_edges_count[i];
583 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ;
584 constituent->_type[TypeNumber-1]=t ;
586 constituent->_geometricTypes[TypeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ;
588 size+=tmp_edges_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ;
593 // Creation of the MEDSKYLINEARRAY
594 constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ;
595 int * NodalIndex = constituent->_nodal->getIndex() ;
598 // Fill the MEDSKYLINEARRAY by reading the MED file.
599 for (int i=0;i<constituent->_numberOfTypes;i++) {
600 MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) constituent->_type[i].getType() ;
602 int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes() ;
605 for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
606 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByEdge ;
608 int tmp_numberOfEdges = constituent->_count[i+1]-constituent->_count[i] ;
609 // Il faut ajouter 1 pour le zero a la lecture !!!
610 int * tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ;
612 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
613 Connectivity->_entityDimension,tmp_constituentArray,
614 MED_FR::MED_FULL_INTERLACE,NULL,0,MED_FR::MED_MAILLE,med_type,MED_FR::MED_NOD);
615 if ( err != MED_VALID) {
616 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
618 delete[] tmp_constituentArray;
619 delete[] tmp_edges_count;
623 int * constituentArray = constituent->_nodal->getI(constituent->_count[i]) ;
624 for (int j=0; j<tmp_numberOfEdges; j++)
625 for (int k=0; k<NumberOfNodeByEdge; k++)
626 constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k] ;
628 delete[] tmp_constituentArray;
631 if (Connectivity->_entityDimension == 3) {
632 if (Connectivity->_constituent==NULL)
633 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Edges are defined but there are no Faces !"));
634 Connectivity->_constituent->_constituent = constituent ;
636 Connectivity->_constituent = constituent ;
639 delete[] tmp_edges_count;
646 int MED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
648 const char * LOC = "MED_MESH_RDONLY_DRIVER::getDescendingConnectivity " ;
649 if (_status==MED_OPENED)
651 MESSAGE(LOC<<" Not implemented !");
656 // int MED_MESH_RDONLY_DRIVER::getElementFamilies(CONNECTIVITY * Connectivity)
659 // int NumberOfTypes = Connectivity->_numberOfTypes ;
660 // int * Count = Connectivity->_count ;
661 // medGeometryElement * GeometricTypes= Connectivity->_geometricTypes ;
662 // int ** tmp_array = new int*[NumberOfTypes] ;
663 // for (int i=0; i<NumberOfTypes; i++)
664 // tmp_array[i]=NULL ;
665 // for (int i=0; i<NumberOfTypes; i++) {
666 // int NumberOfElements = Count[i+1]-Count[i] ;
667 // int * tmp_families_number = new int[NumberOfElements] ;
668 // err = MEDfamLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
669 // tmp_families_number,NumberOfElements,
670 // Connectivity->_entity,GeometricTypes[i]);
671 // tmp_array[i]=tmp_families_number ;
672 // if (err != MED_VALID) {
673 // for (int j=0; j<NumberOfTypes; j++)
674 // if (tmp_array[j] != NULL)
675 // delete[] tmp_array[j] ;
676 // delete[] tmp_array ;
677 // throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getElementFamilies : No Family in element GeometricTypes[i]");
681 // if (Connectivity->_entity == MED_CELL)
682 // _ptrMesh->_MEDArrayCellFamily = tmp_array ;
683 // else if (Connectivity->_entity == MED_FACE)
684 // _ptrMesh->_MEDArrayFaceFamily = tmp_array ;
685 // else if (Connectivity->_entity == MED_EDGE)
686 // _ptrMesh->_MEDArrayEdgeFamily = tmp_array ;
688 // return MED_VALID ;
691 int MED_MESH_RDONLY_DRIVER::getFAMILY()
693 const char * LOC = "MED_MESH_RDONLY_DRIVER::getFAMILY() : " ;
696 if (_status==MED_OPENED) {
700 err = getNodesFamiliesNumber() ; // error only if (_status!=MED_OPENED), other case exeception !
702 _ptrMesh->_MEDArrayCellFamily = new (int*)[_ptrMesh->_connectivity->_numberOfTypes] ; // ET SI IL N'Y A PAS DE CELLS ?
703 getCellsFamiliesNumber(_ptrMesh->_MEDArrayCellFamily,_ptrMesh->_connectivity) ;
704 if (_ptrMesh->_connectivity->_constituent != NULL) {
705 if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE) {
707 _ptrMesh->_MEDArrayFaceFamily = new (int*)[_ptrMesh->_connectivity->_constituent->_numberOfTypes] ;
708 getCellsFamiliesNumber(_ptrMesh->_MEDArrayFaceFamily,_ptrMesh->_connectivity->_constituent) ;
711 _ptrMesh->_MEDArrayEdgeFamily = new (int*)[_ptrMesh->_connectivity->_constituent->_numberOfTypes] ;
712 getCellsFamiliesNumber(_ptrMesh->_MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent) ;
715 if (_ptrMesh->_connectivity->_constituent->_constituent != NULL) {
716 _ptrMesh->_MEDArrayEdgeFamily = new (int*)[_ptrMesh->_connectivity->_constituent->_constituent->_numberOfTypes] ;
717 getCellsFamiliesNumber(_ptrMesh->_MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent) ; // we are in 3D !
721 // Creation of the families
722 int NumberOfFamilies = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),0,MED_FR::MED_FAMILLE) ;
723 if ( NumberOfFamilies < 1 ) // at least family 0 must exist
724 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"There is no FAMILY, FAMILY 0 must exists" ));
726 vector<FAMILY*> &NodeFamilyVector = _ptrMesh->_familyNode ;
727 vector<FAMILY*> &CellFamilyVector = _ptrMesh->_familyCell ;
728 vector<FAMILY*> &FaceFamilyVector = _ptrMesh->_familyFace ;
729 vector<FAMILY*> &EdgeFamilyVector = _ptrMesh->_familyEdge ;
731 int numberOfNodesFamilies = 0 ;
732 int numberOfCellsFamilies = 0 ;
733 int numberOfFacesFamilies = 0 ;
734 int numberOfEdgesFamilies = 0 ;
736 for (int i=0;i<NumberOfFamilies;i++) {
738 int NumberOfAttributes = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,MED_FR::MED_ATTR) ;
739 if (NumberOfAttributes < 0)
740 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : NumberOfAttributes" );
742 int NumberOfGroups = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,MED_FR::MED_GROUPE) ;
743 if (NumberOfGroups < 0)
744 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : NumberOfGroups" );
746 int FamilyIdentifier ;
747 string FamilyName(MED_TAILLE_NOM,' ');
748 int * AttributesIdentifier = new int[NumberOfAttributes] ;
749 int * AttributesValues = new int[NumberOfAttributes] ;
750 string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ;
751 string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups,' ') ;
752 err = MEDfamInfo(_medIdt,const_cast <char *> (_meshName.c_str()),
753 i+1,const_cast <char *> (FamilyName.c_str()),
754 &FamilyIdentifier,AttributesIdentifier,AttributesValues,
755 const_cast <char *> (AttributesDescription.c_str()),
757 const_cast <char *> (GroupsNames.c_str()),&NumberOfGroups
759 //SCRUTE(GroupsNames);
760 if (err != MED_VALID)
761 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : ERROR when get FAMILY informations" );
762 if (FamilyIdentifier != 0 ) {
763 FAMILY * Family = new FAMILY(_ptrMesh,FamilyIdentifier,FamilyName,
764 NumberOfAttributes,AttributesIdentifier,
765 AttributesValues,AttributesDescription,
766 NumberOfGroups,GroupsNames) ;
767 switch (Family->getEntity()) {
768 case MED_EN::MED_NODE :
769 NodeFamilyVector.push_back(Family) ;
770 numberOfNodesFamilies++ ;
772 case MED_EN::MED_CELL :
773 CellFamilyVector.push_back(Family) ;
774 numberOfCellsFamilies++ ;
776 case MED_EN::MED_FACE :
777 FaceFamilyVector.push_back(Family) ;
778 numberOfFacesFamilies++ ;
780 case MED_EN::MED_EDGE :
781 EdgeFamilyVector.push_back(Family) ;
782 numberOfEdgesFamilies++ ;
787 _ptrMesh->_numberOfNodesFamilies = numberOfNodesFamilies ;
788 _ptrMesh->_numberOfCellsFamilies = numberOfCellsFamilies ;
789 _ptrMesh->_numberOfFacesFamilies = numberOfFacesFamilies ;
790 _ptrMesh->_numberOfEdgesFamilies = numberOfEdgesFamilies ;
798 int MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber()
800 const char * LOC = "MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber() : " ;
802 if (_status==MED_OPENED) {
804 int * tmp_NodesFamilies = new int[_ptrMesh->getNumberOfNodes()] ;
805 err = MEDfamLire(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
806 tmp_NodesFamilies, _ptrMesh->getNumberOfNodes(),
807 MED_NOEUD,(enum MED_FR::med_geometrie_element) MED_NONE);
808 if ( err != MED_VALID) {
809 delete[] tmp_NodesFamilies ;
810 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "There is no family for the |"<< _ptrMesh->getNumberOfNodes()
811 << "| nodes in mesh |"
812 << _ptrMesh->_name.c_str() << "|" ));
814 _ptrMesh->_MEDArrayNodeFamily = tmp_NodesFamilies ;
821 int MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber(int **MEDArrayFamily,CONNECTIVITY *Connectivity)
823 const char * LOC = "MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber " ;
826 if (_status==MED_OPENED) {
828 for (i=0;i<Connectivity->_numberOfTypes;i++) {
829 int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
830 int * fam = new int[NumberOfCell] ;
832 err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
834 (MED_FR::med_entite_maillage) Connectivity->_entity,
835 (MED_FR::med_geometrie_element) Connectivity->_geometricTypes[i]);
837 // provisoire : si les faces ou les aretes sont des mailles !!!
838 if (err != MED_VALID) {
839 MESSAGE(LOC<<"search face/edge family on cell !!!");
840 err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
843 (MED_FR::med_geometrie_element) Connectivity->_geometricTypes[i]);
846 MEDArrayFamily[i]=fam ;
847 if (err != MED_VALID)
848 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<Connectivity->_geometricTypes[i]));
856 void MED_MESH_RDONLY_DRIVER::buildAllGroups(vector<GROUP*> & Groups, vector<FAMILY*> & Families)
858 const char * LOC = "MED_MESH_RDONLY_DRIVER::buildAllGroups " ;
861 int numberOfFamilies = Families.size() ;
862 //SCRUTE(numberOfFamilies);
863 map< string,list<FAMILY*> > groupsNames ;
864 for(int i=0; i<numberOfFamilies; i++) {
865 FAMILY * myFamily = Families[i] ;
866 int numberOfGroups_ = myFamily->getNumberOfGroups();
868 //SCRUTE(numberOfGroups_);
869 for (int j=0; j<numberOfGroups_; j++) {
871 //SCRUTE(myFamily->getGroupName(j+1));
872 groupsNames[myFamily->getGroupName(j+1)].push_back(myFamily);
875 int numberOfGroups = groupsNames.size() ;
876 SCRUTE(numberOfGroups);
877 Groups.resize(numberOfGroups);
878 map< string,list<FAMILY*> >::const_iterator currentGroup ;
880 for(currentGroup=groupsNames.begin();currentGroup!=groupsNames.end();currentGroup++) {
881 GROUP * myGroup = new GROUP((*currentGroup).first,(*currentGroup).second) ;
882 // GROUP * myGroup = new GROUP() ;
883 // myGroup->setName((*currentGroup).first);
884 // SCRUTE(myGroup->getName());
885 // //myGroup->setMesh(_ptrMesh);
886 // myGroup->init((*currentGroup).second);
895 void MED_MESH_RDONLY_DRIVER::updateFamily()
897 const char * LOC = "MED_MESH_RDONLY_DRIVER::updateFamily() " ;
900 // we need to update family on constituent if we have constituent, but no
901 // descending connectivity, so, we must calculate all constituent and
902 // numbering correctly family !
903 _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyFace) ; // in 2d, do nothing
904 _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyEdge) ; // in 3d, do nothing
910 void MED_MESH_RDONLY_DRIVER::write( void ) const { INFOS("MED_MESH_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");}
912 /*--------------------- RDWR PART -------------------------------*/
914 void MED_MESH_RDWR_DRIVER::write(void) const { MED_MESH_WRONLY_DRIVER::write(); }
915 void MED_MESH_RDWR_DRIVER::read (void) { MED_MESH_RDONLY_DRIVER::read(); }
918 /*--------------------- WRONLY PART -------------------------------*/
919 void MED_MESH_WRONLY_DRIVER::read (void) { INFOS("MED_MESH_WRONLY_DRIVER::write : Can't read with a WRONLY driver !");}
921 void MED_MESH_WRONLY_DRIVER::write(void) const {
922 const char * LOC = "void MED_MESH_WRONLY_DRIVER::write(void) const : ";
925 // we must first create mesh !!
926 MESSAGE(LOC << "MeshName : |" << _meshName << "| FileName : |"<<_fileName<<"| MedIdt : | "<< _medIdt << "|");
928 if (writeCoordinates()!=MED_VALID)
929 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()" )) ;
931 if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID)
932 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)" )) ;
933 if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID)
934 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)" )) ;
935 if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID)
936 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)" )) ;
938 if (writeFamilyNumbers() !=MED_VALID)
939 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilyNumbers()" )) ;
941 // well we must first write zero family :
942 if (_status==MED_OPENED) {
944 // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
945 string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_0/";
946 SCRUTE("|"<<dataGroupFam<<"|");
947 if ( err =_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) < MED_VALID ) {
950 err = MEDfamCr( _medIdt, const_cast <char *> ( _meshName.c_str() ),
952 (int*)NULL, (int*)NULL, (char*)NULL, 0,
955 if ( err != MED_VALID)
956 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_0| with identifier |0| groups names || and attributes descriptions ||")) ;
959 _MEDdatagroupFermer(_medIdt);
963 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyNode)");
964 if (writeFamilies(_ptrMesh->_familyNode) !=MED_VALID)
965 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyNode)" )) ;
967 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyCell)");
968 if (writeFamilies(_ptrMesh->_familyCell) !=MED_VALID)
969 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyCell)" )) ;
971 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyFace)");
972 if (writeFamilies(_ptrMesh->_familyFace) !=MED_VALID)
973 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyFace)" )) ;
975 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyEdge)");
976 if (writeFamilies(_ptrMesh->_familyEdge) !=MED_VALID)
977 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyEdge)" )) ;
983 int MED_MESH_WRONLY_DRIVER::writeCoordinates() const {
985 const char * LOC = "int MED_MESH_WRONLY_DRIVER::writeCoordinates() const : ";
987 if (_status==MED_OPENED) {
989 MED_FR::med_err err = MED_ERROR;
990 MED_FR::med_repere rep;
991 string tmp_name,tmp_unit;
993 // Recompose the <_spaceDimension> strings in 1 string
994 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
995 tmp_name += _ptrMesh->_coordinate->_coordinateName[i];
996 tmp_unit += _ptrMesh->_coordinate->_coordinateUnit[i];
1000 // Test if the mesh <_meshName> already exists
1001 // If it doesn't exists create it
1002 // If it already exists verify if its dimension is the same as <_ptrMesh->_spaceDimension>
1003 // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
1004 int dim = MEDdimLire(_medIdt, const_cast <char *> (_meshName.c_str()) );
1005 if (dim < MED_VALID)
1006 if (MEDmaaCr(_medIdt,const_cast <char *> (_meshName.c_str()),_ptrMesh->_spaceDimension) != 0 )
1007 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|"));
1010 MESSAGE(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !");
1012 else if (dim != _ptrMesh->_spaceDimension)
1013 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| already exists in file |" << _fileName
1014 << "| with dimension |" << dim << "| but the dimension of the mesh we want to write is |"
1015 << _ptrMesh->_spaceDimension <<"|" )) ;
1017 // Pourquoi le stocker sous forme de chaîne ?
1018 const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
1019 if (coordinateSystem == "CARTESIAN")
1020 rep = MED_FR::MED_CART;
1021 else if ( coordinateSystem == "CYLINDRICAL")
1022 rep = MED_FR::MED_CYL;
1023 else if ( coordinateSystem == "SPHERICAL" )
1024 rep = MED_FR::MED_SPHER;
1026 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |"
1027 << _ptrMesh->_coordinate->_coordinateSystem
1030 err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
1031 _ptrMesh->_spaceDimension,
1032 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
1033 MED_FR::MED_FULL_INTERLACE,
1034 _ptrMesh->_numberOfNodes, // _ptrMesh->_coordinate->_numberOfNodes
1037 const_cast <char *> (tmp_name.c_str()),
1038 const_cast <char *> (tmp_unit.c_str())
1042 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName
1043 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
1044 << " with units names |" << tmp_name
1045 << "| and units |" << tmp_unit
1053 MESSAGE (LOC<<" Not open !!!");
1060 int MED_MESH_WRONLY_DRIVER::writeConnectivities(medEntityMesh entity) const {
1062 const char * LOC="int MED_MESH_WRONLY_DRIVER::writeConnectivities() const : ";
1065 MED_FR::med_err err;
1067 if (_status==MED_OPENED) {
1069 // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB !
1071 // A FAIRE : A tester surtout dans les methodes de MESH.
1072 // if ( _ptrMesh->_connectivity == (CONNECTIVITY *) MED_INVALID )
1073 if ( _ptrMesh->_connectivity == (CONNECTIVITY *) NULL )
1074 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object ")) ;
1076 if ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) {
1078 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
1079 medGeometryElement * types = _ptrMesh->getTypes (entity) ;
1081 for (int i=0; i<numberOfTypes; i++) {
1083 int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
1084 int * connectivity = _ptrMesh->getConnectivity (MED_EN::MED_FULL_INTERLACE,
1085 MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ??
1087 // Pour l'instant la class utilise le multi.....
1089 if (entity==MED_EN::MED_CELL)
1090 if ( (types[i]/ 100) < _ptrMesh->_spaceDimension)
1092 int numberOfNodes = types[i]%100 ;
1093 int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)];
1094 for (int j=0 ; j<numberOfElements; j++) {
1095 for (int k=0; k<numberOfNodes; k++)
1096 connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ;
1098 connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
1100 err = MEDconnEcr( _medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension,
1101 connectivityArray, MED_FR::MED_FULL_INTERLACE , numberOfElements,
1103 (MED_FR::med_entite_maillage ) entity,
1104 (MED_FR::med_geometrie_element) types[i], MED_NOD );
1105 delete[] connectivityArray ;
1107 if (err<0) // ETENDRE LES EXPLICATIONS
1108 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
1109 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
1113 // Connctivity descending :
1114 if ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) {
1116 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
1117 medGeometryElement * types = _ptrMesh->getTypes (entity) ;
1119 for (int i=0; i<numberOfTypes; i++) {
1121 int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
1122 int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]);
1124 // Pour l'instant la class utilise le multi.....
1125 err = MEDconnEcr( _medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension,
1126 connectivity, MED_FR::MED_FULL_INTERLACE , numberOfElements,
1128 (MED_FR::med_entite_maillage ) entity,
1129 (MED_FR::med_geometrie_element) types[i], MED_DESC );
1131 if (err<0) // ETENDRE LES EXPLICATIONS
1132 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
1133 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
1144 int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const {
1146 const char * LOC="int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const : ";
1149 MED_FR::med_err err;
1151 if (_status==MED_OPENED) {
1153 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH
1154 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
1155 _ptrMesh->_MEDArrayNodeFamily, _ptrMesh->getNumberOfNodes(),MED_FR::MED_REMP ,
1156 MED_NOEUD,(enum MED_FR::med_geometrie_element) MED_NONE);
1157 if ( err != MED_VALID)
1158 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< _ptrMesh->getNumberOfNodes()
1159 << "| nodes in mesh |"
1160 << _ptrMesh->_name.c_str() << "|" ));
1163 { // CELLS RELATED BLOCK
1164 medEntityMesh entity=MED_EN::MED_CELL;
1165 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
1166 if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
1168 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
1169 medGeometryElement * types = _ptrMesh->getTypes (entity) ;
1171 for (int i=0; i<numberOfTypes; i++) {
1173 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
1174 _ptrMesh->_MEDArrayCellFamily[i], _ptrMesh->getNumberOfElements(entity, types[i]),
1176 (MED_FR::med_entite_maillage) entity,
1177 (MED_FR::med_geometrie_element) types[i]);
1179 if ( err != MED_VALID)
1180 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
1181 << "| cells of geometric type |" << geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |"
1182 << _ptrMesh->_name.c_str() << "|" ));
1187 { // FACE RELATED BLOCK
1188 medEntityMesh entity=MED_EN::MED_FACE;
1189 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
1190 if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
1192 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
1193 medGeometryElement * types = _ptrMesh->getTypes (entity) ;
1195 int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
1196 int * familyArray = new int[numberOfElements] ;
1197 for (int i=0;i<numberOfElements;i++)
1200 int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
1201 vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
1202 for (int i=0;i<numberOfFamilies;i++) {
1203 int familyNumber = myFamilies[i]->getIdentifier() ;
1204 int numberOfFamilyElements = myFamilies[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
1205 int * myFamilyElements = myFamilies[i]->getNumber(MED_ALL_ELEMENTS) ;
1206 for (int ii=0;ii<numberOfFamilyElements;ii++)
1207 familyArray[myFamilyElements[ii]-1]=familyNumber;
1210 int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
1212 for (int i=0; i<numberOfTypes; i++) {
1214 int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
1215 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
1216 familyArray+typeCount[i]-1, typeNumberOfElements,
1218 (MED_FR::med_entite_maillage) entity,
1219 (MED_FR::med_geometrie_element) types[i]);
1221 if ( err != MED_VALID)
1222 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
1223 << "| faces of geometric type |" << geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |"
1224 << _ptrMesh->_name.c_str() << "|" ));
1226 delete[] familyArray ;
1230 { // EDGE RELATED BLOCK
1231 //medEntityMesh entity=MED_EN::MED_FACE;
1232 medEntityMesh entity=MED_EN::MED_EDGE;
1233 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
1234 if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
1236 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
1237 medGeometryElement * types = _ptrMesh->getTypes (entity) ;
1239 int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
1240 int * familyArray = new int[numberOfElements] ;
1241 for (int i=0;i<numberOfElements;i++)
1244 int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
1245 vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
1246 for (int i=0;i<numberOfFamilies;i++) {
1247 int familyNumber = myFamilies[i]->getIdentifier() ;
1248 int numberOfFamilyElements = myFamilies[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
1249 int * myFamilyElements = myFamilies[i]->getNumber(MED_ALL_ELEMENTS) ;
1250 for (int ii=0;ii<numberOfFamilyElements;ii++)
1251 familyArray[myFamilyElements[ii]-1]=familyNumber;
1254 int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
1256 for (int i=0; i<numberOfTypes; i++) {
1258 int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
1259 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
1260 familyArray+typeCount[i]-1, typeNumberOfElements,
1262 (MED_FR::med_entite_maillage) entity,
1263 (MED_FR::med_geometrie_element) types[i]);
1265 if ( err != MED_VALID)
1266 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
1267 << "| edges of geometric type |" << geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |"
1268 << _ptrMesh->_name.c_str() << "|" ));
1280 int MED_MESH_WRONLY_DRIVER::writeFamilies(vector<FAMILY*> & families ) const {
1282 const char * LOC="int MED_MESH_WRONLY_DRIVER::writeFamilies(vector<FAMILY*> families) const : ";
1285 MED_FR::med_err err;
1287 if (_status==MED_OPENED) {
1289 MESSAGE(LOC<<" families.size() :"<<families.size());
1291 for (int i=0; i< families.size(); i++) {
1293 int numberOfAttributes = families[i]->getNumberOfAttributes ();
1294 string attributesDescriptions = "";
1296 // Recompose the attributes descriptions arg for MED
1297 for (int j=0; j < numberOfAttributes; j++) {
1299 string attributeDescription = families[i]->getAttributeDescription(j+1);
1301 if ( attributeDescription.size() > MED_TAILLE_DESC )
1302 throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |" << j+1 << "| of the family |" << families[i]->getName()
1303 << "| with identifier |" << families[i]->getIdentifier() << "| is |"
1304 << attributeDescription.size() <<"| and is more than |" << MED_TAILLE_DESC << "|")) ;
1306 attributesDescriptions += attributeDescription;
1310 int numberOfGroups = families[i]->getNumberOfGroups();
1311 string groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0') ;
1312 // Recompose the groups names arg for MED
1313 for (int j=0; j < numberOfGroups; j++) {
1315 string groupName = families[i]->getGroupName(j+1);
1317 if ( groupName.size() > MED_TAILLE_LNOM )
1318 throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name n° |" << j+1 << "| of the family |" << families[i]->getName()
1319 << "| with identifier |" << families[i]->getIdentifier() << "| is |"
1320 << groupName.size() <<"| and is more than |" << MED_TAILLE_LNOM << "|")) ;
1323 int length = min(MED_TAILLE_LNOM,(int)groupName.size());
1324 groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length);
1328 // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
1329 string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/"+families[i]->getName()+"/";
1330 SCRUTE("|"<<dataGroupFam<<"|");
1331 if ( err =_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) < MED_VALID ) {
1334 MESSAGE(LOC<<"families[i]->getName().c_str() : "<<families[i]->getName().c_str());
1335 MESSAGE(LOC<<"_meshName.c_str() : "<<_meshName.c_str());
1336 MESSAGE(LOC<<"families[i]->getIdentifier() : "<<families[i]->getIdentifier());
1337 MESSAGE(LOC<<"families[i]->getAttributesIdentifiers() : "<<families[i]->getAttributesIdentifiers()[0]);
1338 MESSAGE(LOC<<"families[i]->getAttributesValues() : "<<families[i]->getAttributesValues()[0]);
1339 MESSAGE(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str());
1340 MESSAGE(LOC<<"numberOfAttributes : "<<numberOfAttributes);
1341 MESSAGE(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str());
1342 MESSAGE(LOC<<"numberOfGroups : "<<numberOfGroups);
1344 err = MEDfamCr( _medIdt,
1345 const_cast <char *> ( _meshName.c_str() ),
1346 const_cast <char *> ( families[i]->getName().c_str() ),
1347 families[i]->getIdentifier(),
1348 families[i]->getAttributesIdentifiers(),
1349 families[i]->getAttributesValues(),
1350 const_cast <char *> (attributesDescriptions.c_str()),
1352 const_cast <char *> (groupsNames.c_str()),
1355 if ( err != MED_VALID)
1356 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName()
1357 << "| with identifier |" << families[i]->getIdentifier() << "| groups names |"
1358 << groupsNames <<"| and attributes descriptions |" << attributesDescriptions << "|")) ;
1361 _MEDdatagroupFermer(_medIdt);
1374 // A FAIRE POUR LES NOEUDS ET LES ELEMENTS ret = MEDfamEcr(