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"
12 #include "MEDMEM_Grid.hxx"
14 using namespace MEDMEM;
16 extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom);
17 extern med_err _MEDdatagroupFermer(med_idt id);
20 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor
22 MED_MESH_DRIVER::MED_MESH_DRIVER():
24 _ptrMesh(( MESH *)MED_NULL),
31 MED_MESH_DRIVER::MED_MESH_DRIVER(const string & fileName,
33 MED_EN::med_mode_acces accessMode):
34 GENDRIVER(fileName,accessMode),
42 MED_MESH_DRIVER::MED_MESH_DRIVER(const MED_MESH_DRIVER & driver):
44 _ptrMesh(driver._ptrMesh),
46 _meshName(driver._meshName),
47 _meshNum(driver._meshNum)
51 MED_MESH_DRIVER::~MED_MESH_DRIVER()
55 void MED_MESH_DRIVER::open()
57 const char * LOC = "MED_MESH_DRIVER::open()" ;
59 MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode);
60 _medIdt = MED_FR::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(MED_FR::med_mode_acces) _accessMode);
61 MESSAGE(LOC<<" _medIdt : "<< _medIdt );
65 _medIdt = MED_INVALID;
67 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Could not open file "<<_fileName<<" in mode "<<_accessMode));
73 void MED_MESH_DRIVER::close()
75 const char * LOC = "MED_MESH_DRIVER::close() " ;
78 if ( _status == MED_OPENED) {
79 err=MED_FR::MEDfermer(_medIdt);
80 // san -- MED5873 : Calling H5close() here leads to failure of SALOMEDS::StudyManager_i::_SaveAs()
81 // method during study saving process. MEDfermer() seems sufficient for closing a file.
82 //H5close(); // If we call H5close() all the files are closed.
84 throw MEDEXCEPTION( LOCALIZED(STRING(LOC)
85 <<" Error when closing file !"
88 MESSAGE(LOC <<": _medIdt= " << _medIdt );
89 MESSAGE(LOC<<": MEDfermer : err = " << err );
91 _medIdt = MED_INVALID;
96 void MED_MESH_DRIVER::setMeshName(const string & meshName) { _meshName = meshName; };
97 string MED_MESH_DRIVER::getMeshName() const { return _meshName; };
99 //A FAIRE UTILISER LES MAPS...
100 const MED_FR::med_geometrie_element MED_MESH_DRIVER::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]=
101 { 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,
102 MED_FR::MED_TETRA4,MED_FR::MED_PYRA5,MED_FR::MED_PENTA6,MED_FR::MED_HEXA8,MED_FR::MED_TETRA10,MED_FR::MED_PYRA13,
103 MED_FR::MED_PENTA15, MED_FR::MED_HEXA20};
105 const char * const MED_MESH_DRIVER::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]=
106 { "MED_POINT1","MED_SEG2","MED_SEG3","MED_TRIA3","MED_QUAD4","MED_TRIA6","MED_QUAD8",
107 "MED_TETRA4","MED_PYRA5","MED_PENTA6","MED_HEXA8","MED_TETRA10","MED_PYRA13",
108 "MED_PENTA15","MED_HEXA20"};
111 //---------------------------------- RDONLY PART -------------------------------------------------------------
113 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(): MED_MESH_DRIVER()
117 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName,
119 MED_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY)
121 MESSAGE("MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
124 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const MED_MESH_RDONLY_DRIVER & driver):
125 MED_MESH_DRIVER(driver)
129 MED_MESH_RDONLY_DRIVER::~MED_MESH_RDONLY_DRIVER()
131 //MESSAGE("MED_MESH_RDONLY_DRIVER::~MED_MESH_RDONLY_DRIVER() has been destroyed");
134 GENDRIVER * MED_MESH_RDONLY_DRIVER::copy(void) const
136 return new MED_MESH_RDONLY_DRIVER(*this);
139 void MED_MESH_RDONLY_DRIVER::read(void)
141 const char * LOC = "MED_MESH_RDONLY_DRIVER::read() : " ;
143 if (_status!=MED_OPENED)
144 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName << " is : " << _medIdt << " (the file is not opened)." )) ;
146 _ptrMesh->_name = _meshName;
148 SCRUTE(_ptrMesh->getIsAGrid());
150 if (_ptrMesh->getIsAGrid())
154 // always call getFAMILY : families are requiered !!!!
156 // int nbFam = MEDnFam(_medIdt,
157 // const_cast <char *> (_meshName.c_str()),
159 // MED_FR::MED_FAMILLE);
164 if (getFAMILY()!=MED_VALID)
165 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid")) ;
167 buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
174 if (getCOORDINATE()!=MED_VALID)
175 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE" )) ;
177 if (getCONNECTIVITY()!=MED_VALID)
178 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOONECTIVITY")) ;
180 if (getFAMILY()!=MED_VALID)
181 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY" )) ;
185 // we build all groups
187 buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
189 buildAllGroups(_ptrMesh->_groupCell,_ptrMesh->_familyCell) ;
191 buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace) ;
193 buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ;
195 // MESSAGE(LOC<<"Checking of CellModel !!!!!!!");
197 // int nbOfTypes = _ptrMesh->_connectivity->_numberOfTypes;
198 // for(int i=0;i<nbOfTypes;i++)
200 // MESSAGE(LOC << _ptrMesh->_connectivity->_type[i]) ;
206 //=======================================================================
209 //=======================================================================
211 void MED_MESH_RDONLY_DRIVER::getGRID()
213 const char * LOC = "MED_MESH_RDONLY_DRIVER::getGRID() : " ;
216 if (_status!=MED_OPENED)
217 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "med file is not opened"));
219 GRID * ptrGrid = (GRID *) _ptrMesh;
223 // Read the dimension of the space for the mesh <_meshName>
224 int SpaceDimension = MED_FR::MEDdimLire(_medIdt,const_cast <char *> (_meshName.c_str())) ;
225 if ( SpaceDimension <= MED_VALID )
226 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The space dimension |" << SpaceDimension <<
227 "| seems to be incorrect " << "for the mesh : |" <<
229 _ptrMesh->_spaceDimension = SpaceDimension;
232 int * ArrayLen[] = { & ptrGrid->_iArrayLength,
233 & ptrGrid->_jArrayLength,
234 & ptrGrid->_kArrayLength };
236 for (idim = 0; idim < _ptrMesh->_spaceDimension; ++idim)
238 int lenght = MED_FR::MEDnGrid(_medIdt,
239 const_cast <char *> (_ptrMesh->_name.c_str()),
243 if ( lenght <= MED_VALID )
244 throw MEDEXCEPTION(STRING(LOC) <<"The number of nodes |" << lenght <<
245 "| seems to be incorrect "
246 << "for the mesh : |" << _meshName << "|" ) ;
248 ArrayLen [idim][0] = lenght;
251 MED_FR::med_repere rep ;
252 string tmp_nom_coord (MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,' ');
253 string tmp_unit_coord(MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,' ');
254 char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str()) ) ;
255 char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
257 // Read node coordinates for MED_BODY_FITTED grid
259 SCRUTE(ptrGrid->getGridType());
261 if (ptrGrid->getGridType() == MED_EN::MED_BODY_FITTED)
264 int NumberOfNodes = MED_FR::MEDnGrid(_medIdt,
265 const_cast <char *> (_meshName.c_str()),
266 MED_FR::MED_GRID_NOEUD);
267 if ( NumberOfNodes <= MED_VALID )
268 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes <<
269 "| seems to be incorrect "
270 << "for the mesh : |" << _meshName << "|" )) ;
271 _ptrMesh->_numberOfNodes = NumberOfNodes ;
273 // this array is useless because families numbers are read in getFAMILY
274 int * MEDArrayNodeFamily = new int[ NumberOfNodes ];
275 // create coordinates
276 _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
277 MED_EN::MED_FULL_INTERLACE);
279 // Read coordinates and families
280 // double * coo = const_cast <double *>
281 // (_ptrMesh->_coordinate->getCoordinates(MED_EN::MED_FULL_INTERLACE));
283 // err = MED_FR::MEDbodyFittedLire (_medIdt,
284 // const_cast <char *> (_ptrMesh->_name.c_str()),
285 // _ptrMesh->_spaceDimension,
287 // MED_FR::MED_FULL_INTERLACE,
291 // MEDArrayNodeFamily,
294 err = MED_FR::MEDbodyFittedLire (_medIdt,
295 const_cast <char *> (_ptrMesh->_name.c_str()),
296 _ptrMesh->_spaceDimension,
297 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
298 MED_FR::MED_FULL_INTERLACE,
305 MESSAGE(LOC << " NumberOfNodes = " << NumberOfNodes << " SpaceDimension = " << SpaceDimension);
307 ptrGrid->_is_coordinates_filled = true;
309 // for (int icoor = 0 ; icoor<NumberOfNodes ; icoor++)
310 // for(int jcoor = 0 ; jcoor<SpaceDimension ; jcoor++)
311 // MESSAGE(LOC << " icoor = " << icoor << " jcoor = " << jcoor << " COOR = " << _ptrMesh->getCoordinates(MED_FULL_INTERLACE)[icoor*SpaceDimension+jcoor]);
313 delete[] MEDArrayNodeFamily;
314 if (err != MED_VALID)
315 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in MEDbodyFittedLire()"));
317 // _ptrMesh->_MEDArrayNodeFamily = fam ;
322 // Read Arrays and Node families in Cartesian or Polar Grid
325 double * Array[] = { (double*) 0, (double*) 0, (double*) 0 };
326 for (idim = 0; idim < _ptrMesh->_spaceDimension; ++idim)
328 int nbNodesDim = * ArrayLen [idim];
329 nbNodes *= nbNodesDim;
330 Array [idim] = new double [ nbNodesDim ];
331 err = MED_FR::MEDgridLire (_medIdt,
332 const_cast <char *> (_ptrMesh->_name.c_str()),
333 _ptrMesh->_spaceDimension,
336 MED_FR::MED_FULL_INTERLACE,
340 if (err != MED_VALID)
341 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Error in MEDgridLire for dimention" << idim ));
344 ptrGrid->_iArray = Array[0];
345 ptrGrid->_jArray = Array[1];
346 ptrGrid->_kArray = Array[2];
348 _ptrMesh->_numberOfNodes = nbNodes ;
350 // create coordinates
351 _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,nbNodes,
352 MED_EN::MED_FULL_INTERLACE);
353 // Read node families
354 // int nbFamNodes = MED_FR::MEDnGrid(_medIdt,
355 // const_cast <char *> (_ptrMesh->_name.c_str()),
356 // MED_FR::MED_FAM_NOEUD);
357 // if (nbFamNodes > 0)
359 // // int * fam = new int[ nbFamNodes ];
361 // //_ptrMesh->_MEDArrayNodeFamily = new int[ nbFamNodes ];
362 // // this array is useless because families numbers are read in getFAMILY
363 // int * MEDArrayNodeFamily = new int[ nbFamNodes ];
365 // err = MED_FR::MEDfamGridLire (_medIdt,
366 // const_cast <char *> (_ptrMesh->_name.c_str()),
367 // MEDArrayNodeFamily,
369 // MED_FR::MED_NOEUD);
371 // if (err != MED_VALID)
372 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read grid nodes families for "
373 // << idim << "-th dimention"));
375 // _ptrMesh->_MEDArrayNodeFamily = fam;
378 } // end read Cartesian or Polar Grid
380 // set coordinate names
382 for (i=0; i<_ptrMesh->_spaceDimension; ++i ) {
383 string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ;
384 string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ;
385 // suppress space at the end
387 for(j=MED_TAILLE_PNOM-1;j>=0;j--)
388 if (myStringName[j] != ' ') break ;
389 _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
390 for(j=MED_TAILLE_PNOM-1;j>=0;j--)
391 if (myStringUnit[j] != ' ') break ;
392 _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
395 string coordinateSystem = "UNDEFINED";
397 if( rep == MED_FR::MED_CART) coordinateSystem = "CARTESIAN";
398 else if ( rep == MED_FR::MED_CYL) coordinateSystem = "CYLINDRICAL";
399 else if ( rep == MED_FR::MED_SPHER) coordinateSystem = "SPHERICAL";
401 _ptrMesh->_coordinate->setCoordinatesSystem(coordinateSystem);
407 //=======================================================================
408 //function : getCOORDINATE
409 // A FAIRE : RENVOYER DU VOID
410 //=======================================================================
411 int MED_MESH_RDONLY_DRIVER::getCOORDINATE()
413 const char * LOC = "MED_MESH_RDONLY_DRIVER::getCOORDINATE() : " ;
416 if (_status==MED_OPENED)
420 // Read the dimension of the space for the mesh <_meshName>
421 // to be able to create a COORDINATE object
422 int SpaceDimension = MED_FR::MEDdimLire(_medIdt,const_cast <char *> (_meshName.c_str())) ;
423 if ( SpaceDimension <= MED_VALID )
424 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The space dimension |" << SpaceDimension << "| seems to be incorrect "
425 << "for the mesh : |" << _meshName << "|")) ;
426 _ptrMesh->_spaceDimension = SpaceDimension ;
430 // Read the number of nodes used in the mesh <_meshName>
431 // to be able to create a COORDINATE object
432 int NumberOfNodes=MEDnEntMaa(_medIdt,
433 const_cast <char *> (_meshName.c_str()),
436 (MED_FR::med_geometrie_element) MED_NONE,
437 (MED_FR::med_connectivite) MED_NONE);
438 if ( NumberOfNodes <= MED_VALID )
439 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes << "| seems to be incorrect "
440 << "for the mesh : |" << _meshName << "|" )) ;
441 _ptrMesh->_numberOfNodes = NumberOfNodes ;
445 // create a COORDINATE object
446 _ptrMesh->_coordinate = new COORDINATE(SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE);
448 MED_FR::med_repere rep ; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON?
449 string tmp_nom_coord (MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,'\0');
450 string tmp_unit_coord(MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,'\0');
451 char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str()) ) ;
452 char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
454 err=MEDcoordLire(_medIdt,
455 const_cast <char *> (_ptrMesh->_name.c_str()),
456 _ptrMesh->_spaceDimension,
457 //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
458 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
459 MED_FR::MED_FULL_INTERLACE,
460 MED_ALL, // we read all the coordinates
461 NULL, // we don't use a profile
462 0, // so the profile's size is 0
463 &rep,tmp_nom,tmp_unit);
464 if (err != MED_VALID)
465 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" << NumberOfNodes << "| nodes "
466 << "for the mesh : |" << _meshName
467 << "| of space dimension |" << SpaceDimension
468 << "| with units names |" << tmp_nom
469 << "| and units |" << tmp_unit
473 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
474 string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ;
475 string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ;
476 // suppress space at the end
478 for(j=MED_TAILLE_PNOM-1;j>=0;j--)
479 if (myStringName[j] != ' ') break ;
480 _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
481 for(j=MED_TAILLE_PNOM-1;j>=0;j--)
482 if (myStringUnit[j] != ' ') break ;
483 _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
486 // Pourquoi le stocker sous forme de chaîne ?
489 case MED_FR::MED_CART :
491 _ptrMesh->_coordinate->_coordinateSystem = "CARTESIAN";
494 case MED_FR::MED_CYL :
496 _ptrMesh->_coordinate->_coordinateSystem = "CYLINDRICAL";
499 case MED_FR::MED_SPHER :
501 _ptrMesh->_coordinate->_coordinateSystem = "SPHERICAL";
506 _ptrMesh->_coordinate->_coordinateSystem = "UNDEFINED"; // ?Erreur ?
511 // Read the unused optional node Names
512 char * tmp_node_name = new char[NumberOfNodes*MED_TAILLE_PNOM+1];
513 tmp_node_name[NumberOfNodes]='\0' ;
514 err=MEDnomLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
515 tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM,MED_FR::MED_NOEUD,
516 (MED_FR::med_geometrie_element) MED_NONE);
517 if (err == MED_VALID)
518 MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !");
519 delete[] tmp_node_name ;
522 // ??? Read the unused optional node Numbers ???
523 int * tmp_node_number = new int[NumberOfNodes] ;
524 err=MEDnumLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
525 tmp_node_number,NumberOfNodes,MED_FR::MED_NOEUD,(MED_FR::med_geometrie_element)0);
526 if (err == MED_VALID) {
527 // INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
528 // INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !");
529 // INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
530 MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : Nodes have numbers, we DO TAKE care of them !");
531 _ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes) ;
532 memcpy((int*)_ptrMesh->_coordinate->_nodeNumber,tmp_node_number,sizeof(int)*NumberOfNodes) ;
534 //////////////////////////////////////////////////////////////////////////////////////
535 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
536 //////////////////////////////////////////////////////////////////////////////////////
538 /// Calcule _optionnalToCanonicNodesNumbers de telle sorte que _optionnalToCanonicNodesNumbers[OptionnalNumber]==CanonicNumber
540 // _ptrMesh->_arePresentOptionnalNodesNumbers=1;
541 // for (int canonicNumber=1;canonicNumber<=NumberOfNodes;canonicNumber++) _ptrMesh->_optionnalToCanonicNodesNumbers[tmp_node_number[canonicNumber-1]]=canonicNumber;
542 // ICI RETOUR A LA NORMALE::: AUCUNE PRISE EN COMPTE D'UN NUMEROTATION OPTIONNEL
543 _ptrMesh->_arePresentOptionnalNodesNumbers=0;
545 else _ptrMesh->_arePresentOptionnalNodesNumbers=0;
547 //////////////////////////////////////////////////////////////////////////////////////
549 delete[] tmp_node_number ;
558 int MED_MESH_RDONLY_DRIVER::getCONNECTIVITY()
560 const char * LOC = "MED_MESH_RDONLY_DRIVER::getCONNECTIVITY : " ;
563 if (_status==MED_OPENED)
567 // read MED_CELL connectivity
568 CONNECTIVITY * Connectivity = new CONNECTIVITY(MED_CELL) ;
569 Connectivity->_numberOfNodes = _ptrMesh->_numberOfNodes ; // EF : Pourquoi cet attribut est-il dans MESH et non dans COORDINATE ?
571 // Try to read nodal connectivity of the cells <Connectivity->_nodal>
572 // then try to read descending connectivity <Connectivity->_descending>
573 // if neither nodal nor descending connectivity exists
574 // throw an exception.
575 err = getNodalConnectivity(Connectivity) ;
576 if (err!=MED_VALID) {
577 Connectivity->_typeConnectivity = MED_DESCENDING ;
578 err = getDescendingConnectivity(Connectivity) ;
580 getDescendingConnectivity(Connectivity) ; // we read it if there is one
582 if (err!=MED_VALID) {
583 delete Connectivity ;
584 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "We could not read any Connectivity")) ;
587 _ptrMesh->_meshDimension = Connectivity->_entityDimension ;
589 // At this point Connectivity->_typeConnectivity is either NODAL or DESCENDING
590 // If both connectivities are found Connectivity->_typeConnectivity is NODAL
591 // If space dimension is 3
592 // try to read the nodal connectivity of the faces <ConnectivityFace->_nodal> then
593 // try to read the descending connectivity <ConnectivityFace->_descending>
594 // if there is no descending connectivity and the CELLS are
595 // defined in descending mode then throw an exception
597 // PROVISOIRE : if we have some face or edge in MED_MAILLE, we don't read more. There could not be have face or edge !!!!
599 if(Connectivity->_constituent==NULL) {
601 SCRUTE(_ptrMesh->_meshDimension);
602 if (_ptrMesh->_meshDimension == 3) {
603 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES FACES..." );
604 CONNECTIVITY * ConnectivityFace = new CONNECTIVITY(MED_EN::MED_FACE) ;
605 ConnectivityFace->_typeConnectivity = Connectivity->_typeConnectivity ; // NODAL or DESCENDING
606 SCRUTE(ConnectivityFace->_typeConnectivity);
607 if (Connectivity->_typeConnectivity == MED_DESCENDING) {
608 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES FACES" );
609 err = getDescendingConnectivity(ConnectivityFace) ;
611 throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No FACE in descending connectivity")) ;
612 getNodalConnectivity(ConnectivityFace) ; // if any !
614 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES FACES" );
615 err = getNodalConnectivity(ConnectivityFace) ;
616 if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
617 err = getDescendingConnectivity(ConnectivityFace) ;
619 getDescendingConnectivity(ConnectivityFace); // if any !
621 if (err!=MED_VALID) {
622 delete ConnectivityFace ;
623 MESSAGE(LOC<<"No FACE defined.") ;
625 MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES FACES DANS L'OBJET CONNECTIVITY" );
626 Connectivity->_constituent=ConnectivityFace ;
630 // read MED_EDGE connectivity
631 if (_ptrMesh->_meshDimension > 1) { // we are in 3 or 2D
632 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES ARRETES...." );
633 CONNECTIVITY * ConnectivityEdge = new CONNECTIVITY(MED_EDGE) ;
634 ConnectivityEdge->_typeConnectivity = Connectivity->_typeConnectivity ;
635 if (Connectivity->_typeConnectivity == MED_DESCENDING) {
636 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES ARRETES" );
637 err = getDescendingConnectivity(ConnectivityEdge) ;
639 throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No EDGE in descending connectivity")) ;
640 getNodalConnectivity(ConnectivityEdge) ; // if any !
642 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES ARRETES" );
643 err = getNodalConnectivity(ConnectivityEdge) ;
644 if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
645 err = getDescendingConnectivity(ConnectivityEdge) ;
647 getDescendingConnectivity(ConnectivityEdge) ; // if any !
649 if (err!=MED_VALID) {
650 delete ConnectivityEdge ;
651 MESSAGE(LOC<<"No EDGE defined.") ;
653 if (_ptrMesh->_meshDimension == 3)
654 if (Connectivity->_constituent != NULL)
655 Connectivity->_constituent->_constituent=ConnectivityEdge ;
657 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "EDGE defined but there are no FACE !")) ;
659 MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES ARETES DANS L'OBJET CONNECTIVITY" );
660 Connectivity->_constituent=ConnectivityEdge ;
665 _ptrMesh->_connectivity = Connectivity ;
669 // we have read all connectivity in file, now we must build descending connectivity if necessary !
671 // If connectivity descending is defined, we have nothing to do, all constituent are defined !
672 // If connectivity is only nodal, we must rebuild descending if we have some contituent !
675 // if (Connectivity->_descending == NULL)
676 // if (Connectivity->_constituent != NULL){
677 // // update Connectivity->_constituent
678 // CONNECTIVITY * myConstituentOld = Connectivity->_constituent ;
679 // Connectivity->_constituent = (CONNECTIVITY *)NULL ;
680 // Connectivity->calculateDescendingConnectivity() ;
690 int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity)
692 const char * LOC = "MED_MESH_RDONLY_DRIVER::getNodalConnectivity : " ;
694 if (_status==MED_OPENED)
696 // Get the type of entity to work on (previously set in the Connectivity Object)
697 MED_FR::med_entite_maillage Entity = (MED_FR::med_entite_maillage) Connectivity->getEntity();
699 // Get the number of cells of each type & store it in <tmp_cells_count>.
700 int * tmp_cells_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
702 for (i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) { // EF :ON SCANNE DES GEOMETRIES INUTILES, UTILISER LES MAPS
703 tmp_cells_count[i]=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
704 MED_FR::MED_CONN,(MED_FR::med_entite_maillage) Entity,
705 all_cell_type[i],MED_FR::MED_NOD);
708 // Get the greatest dimension of the cells : Connectivity->_entityDimension
709 // We suppose there is no cells used as faces in MED 2.2.x , this is forbidden !!!
710 // In version prior to 2.2.x, it is possible
711 if (tmp_cells_count[i]>0) {
712 Connectivity->_entityDimension=all_cell_type[i]/100;
713 Connectivity->_numberOfTypes++;
718 // If there is no nodal connectivity, we quit !
719 if ( Connectivity->_numberOfTypes == 0 ) {
720 delete[] tmp_cells_count ;
724 // if MED version < 2.2.x, we read only entity with dimention = Connectivity->_entityDimension. Lesser dimension are face or edge !
726 char version_med[10] ;
727 if ( MEDfichEntete(_medIdt,MED_FR::MED_VERSION,version_med) != 0 ){
728 // error : we suppose we have not a good med file !
729 delete[] tmp_cells_count ;
733 // we get MED version number
734 // If MED version is < 2.2 then the cells which dimension
735 // is lesser than the main dimension ( Connectivity->_entityDimension )
736 // are either faces or edges
738 // string medVersion(version_med);
740 int * tmpEdgeCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
741 tmpEdgeCount[0] = 0 ;
742 int numberOfEdgesTypes = 0;
743 int * tmpFaceCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
744 tmpFaceCount[0] = 0 ;
745 int numberOfFacesTypes = 0;
747 if ((version_med != "2.2")&(Entity==MED_FR::MED_MAILLE)) {
749 Connectivity->_numberOfTypes=0;
751 for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) {
754 if (tmp_cells_count[i]!=0) {
755 int dimension = all_cell_type[i]/100 ;
756 if (Connectivity->_entityDimension==dimension)
757 Connectivity->_numberOfTypes++ ;
760 if (Connectivity->_entityDimension==3) {
761 tmpFaceCount[i]=tmp_cells_count[i] ;
762 tmp_cells_count[i]=0 ;
763 numberOfFacesTypes++;
766 if (Connectivity->_entityDimension>dimension) {
767 tmpEdgeCount[i]=tmp_cells_count[i] ;
768 tmp_cells_count[i]=0;
769 numberOfEdgesTypes++ ;
775 // bloc to read CELL :
777 // Prepare an array of indexes on the different cell types to create a MEDSKYLINEARRAY
778 // We use <tmp_cells_count> to calculate <Connectivity->_count> then we release it
779 Connectivity->_geometricTypes = new MED_EN::medGeometryElement [Connectivity->_numberOfTypes] ; // Double emploi pour des raisons pratiques
780 Connectivity->_type = new CELLMODEL [Connectivity->_numberOfTypes] ; //
781 Connectivity->_count = new int [Connectivity->_numberOfTypes+1] ;
782 Connectivity->_count[0] = 1;
787 for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) { // no point1 cell type (?)
788 if (tmp_cells_count[i]>0) {
789 Connectivity->_count[typeNumber]=Connectivity->_count[typeNumber-1]+tmp_cells_count[i];
791 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ;
792 Connectivity->_type[typeNumber-1]=t ;
794 Connectivity->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ;
796 // probleme avec les mailles de dimension < a dimension du maillage :
797 // 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 !!!
800 size+=tmp_cells_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ;
803 << Connectivity->_count[typeNumber]-1 << " cells of type "
804 << all_cell_type_tab[i] );
809 // Creation of the MEDSKYLINEARRAY
810 //Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,size) ;
811 //int * NodalIndex = Connectivity->_nodal->getIndex() ;
812 int * NodalValue = new int[size] ;
813 int * NodalIndex = new int[Connectivity->_count[Connectivity->_numberOfTypes]] ;
816 // Fill the MEDSKYLINEARRAY by reading the MED file.
818 for ( i=0;i<Connectivity->_numberOfTypes;i++) {
820 MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) Connectivity->_type[i].getType() ;
821 // if ( Connectivity->_type[i].getDimension() < Connectivity->_entityDimension)
822 if (Connectivity->_entity == MED_CELL)
823 if ( Connectivity->_type[i].getDimension() < _ptrMesh->_spaceDimension)
826 // int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
827 int NumberOfNodeByCell = Connectivity->_type[i].getNumberOfNodes() ;
830 for ( j=Connectivity->_count[i]; j<Connectivity->_count[i+1];j++)
831 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByCell ;
833 int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i] ;
834 int * tmp_ConnectivityArray = new int[(NumberOfNodeByCell+multi)*tmp_numberOfCells];
836 // int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
837 // Connectivity->_entityDimension,tmp_ConnectivityArray,
838 // MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD);
839 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
840 _ptrMesh->_spaceDimension,tmp_ConnectivityArray,
841 MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD);
843 if ( err != MED_VALID) {
844 delete[] tmp_ConnectivityArray;
845 delete[] tmp_cells_count;
846 delete[] tmpFaceCount;
847 delete[] tmpEdgeCount;
848 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
852 int * ConnectivityArray = NodalValue + NodalIndex[Connectivity->_count[i]-1]-1 ;
854 // version originale sans prise en compte des numéros optionnels
856 for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
857 ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
859 //////////////////////////////////////////////////////////////////////////////////////
860 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
861 //////////////////////////////////////////////////////////////////////////////////////
863 /// Rénumérote le tableau temporaire tmp_ConnectivityArray en utilisant _optionnalToCanonicNodesNumbers
864 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
866 // if (_ptrMesh->_arePresentOptionnalNodesNumbers==1)
868 // for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
869 // ConnectivityArray[j*NumberOfNodeByCell+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k]] ;
873 // for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
874 // ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
877 //////////////////////////////////////////////////////////////////////////////////////
880 delete[] tmp_ConnectivityArray;
884 Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,
891 } // end of bloc to read CELL
893 delete[] tmp_cells_count;
900 if (numberOfFacesTypes!=0) {
902 // Create a CONNECTIVITY constituent to put in the top level CONNECTIVITY recursive class
903 CONNECTIVITY * constituent = new CONNECTIVITY(numberOfFacesTypes,MED_EN::MED_FACE) ;
904 constituent->_entityDimension = 2 ;
905 constituent->_count[0]=1 ;
907 // In order to create the MEDSKYLINEARRAY of the constituent object we need :
909 // To initialize the _count array of the constituent object (containning cumulated face count by geometric type)
910 // _count[0]=1 and _count[_numberOfTypes] give the size of NodalIndex
912 // To calculate the total number of face nodes whatever the geometric type is.
913 // The result is the size of the array containning all the nodes : NodalValue
915 // To calculate the starting indexes of the different face types in NodalValue,
916 // this is the NodalIndex array.
921 for ( i=1; i < MED_NBR_GEOMETRIE_MAILLE; i++) { // no point1 cell type (?)
922 if (tmpFaceCount[i]>0) {
924 constituent->_count[typeNumber] = constituent->_count[typeNumber-1] + tmpFaceCount[i];
925 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ;
926 constituent->_type[typeNumber-1]=t ;
928 constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ;
930 size+=tmpFaceCount[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ;
935 // Creation of the MEDSKYLINEARRAY
936 //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ;
937 //int * NodalIndex = constituent->_nodal->getIndex() ;
938 int * NodalValue = new int[size] ;
939 int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
942 // Fill the MEDSKYLINEARRAY by reading the MED file.
943 for ( i=0; i<constituent->_numberOfTypes; i++) {
944 MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) constituent->_type[i].getType() ;
946 int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes() ;
948 // initialise NodalIndex
949 for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
950 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByFace ;
952 int tmp_numberOfFaces = constituent->_count[i+1]-constituent->_count[i] ;
953 // Il faut ajouter 1 pour le zero a la lecture !!!
954 // ATTENTION UNIQUEMENT POUR MED < 2.2.x
955 int * tmp_constituentArray = NULL;
956 if (version_med != "2.2")
957 tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ;
959 tmp_constituentArray = new int[NumberOfNodeByFace*tmp_numberOfFaces] ;
960 MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ;
962 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
963 Connectivity->_entityDimension,tmp_constituentArray,
964 MED_FR::MED_FULL_INTERLACE,NULL,0,MED_FR::MED_MAILLE,med_type,MED_FR::MED_NOD);
966 if ( err != MED_VALID) {
967 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
969 delete[] tmp_constituentArray;
970 delete[] tmpFaceCount;
971 delete[] tmpEdgeCount;
975 int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
977 // version originale sans prise en compte des numéros optionnels
979 for (int j=0; j<tmp_numberOfFaces; j++)
980 for (int k=0; k<NumberOfNodeByFace; k++)
981 constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
983 //////////////////////////////////////////////////////////////////////////////////////
984 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
985 //////////////////////////////////////////////////////////////////////////////////////
987 /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
988 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
990 // if (_ptrMesh->_arePresentOptionnalNodesNumbers)
992 // for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
993 // constituentArray[j*NumberOfNodeByFace+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByFace+1)+k]] ;
997 // for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
998 // constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
1001 //////////////////////////////////////////////////////////////////////////////////////
1003 delete[] tmp_constituentArray;
1006 constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1010 delete[] NodalIndex ;
1011 delete[] NodalValue ;
1013 Connectivity->_constituent = constituent ;
1016 delete[] tmpFaceCount;
1020 if (numberOfEdgesTypes!=0) {
1021 CONNECTIVITY * constituent = new CONNECTIVITY(numberOfEdgesTypes,MED_EDGE) ;
1022 constituent->_entityDimension = 1 ;
1023 constituent->_count[0]=1 ;
1027 // if you declare a variable <i> in two <for> initialization statement,
1028 // compiler gcc2.95.3 says nothing but there are two <i> variables in the same block
1029 //and the value you get in the common block seems to be the value of the first variable !
1032 for ( i=1; i<MED_NBR_GEOMETRIE_MAILLE; i++) { // no point1 cell type (?)
1033 if (tmpEdgeCount[i]>0) {
1035 constituent->_count[typeNumber]=constituent->_count[typeNumber-1]+tmpEdgeCount[i];
1036 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ;
1037 constituent->_type[typeNumber-1]=t ;
1039 constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ;
1041 size+=tmpEdgeCount[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ;
1046 // Creation of the MEDSKYLINEARRAY
1047 //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ;
1048 //int * NodalIndex = constituent->_nodal->getIndex() ;
1049 int * NodalValue = new int[size] ;
1050 int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
1053 // Fill the MEDSKYLINEARRAY by reading the MED file.
1054 for ( i=0; i<constituent->_numberOfTypes; i++) {
1055 MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) constituent->_type[i].getType() ;
1057 int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes() ;
1060 for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
1061 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByEdge ;
1063 int tmp_numberOfEdges = constituent->_count[i+1]-constituent->_count[i] ;
1064 // Il faut ajouter 1 pour le zero a la lecture !!!
1066 // ATTENTION UNIQUEMENT POUR MED < 2.2.x
1067 int * tmp_constituentArray = NULL;
1068 if (version_med != "2.2")
1069 tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ;
1071 tmp_constituentArray = new int[NumberOfNodeByEdge*tmp_numberOfEdges] ;
1072 MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ;
1075 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1076 _ptrMesh->_spaceDimension,tmp_constituentArray,
1077 MED_FR::MED_FULL_INTERLACE,NULL,0,MED_FR::MED_MAILLE,med_type,MED_FR::MED_NOD);
1078 if ( err != MED_VALID) {
1079 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
1080 delete constituent ;
1081 delete[] tmp_constituentArray;
1082 delete[] tmpEdgeCount;
1086 int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
1088 // version originale sans prise en compte des numéros optionnels
1090 for (int j=0; j<tmp_numberOfEdges; j++)
1091 for (int k=0; k<NumberOfNodeByEdge; k++)
1092 constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k] ;
1094 //////////////////////////////////////////////////////////////////////////////////////
1095 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1096 //////////////////////////////////////////////////////////////////////////////////////
1098 /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
1099 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1101 // if (_ptrMesh->_arePresentOptionnalNodesNumbers)
1103 // for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1104 // constituentArray[j*NumberOfNodeByEdge+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k]] ;
1108 // for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1109 // constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k] ;
1112 //////////////////////////////////////////////////////////////////////////////////////
1114 delete[] tmp_constituentArray;
1117 constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1122 delete[] NodalIndex ;
1123 delete[] NodalValue ;
1125 if (Connectivity->_entityDimension == 3) {
1126 if (Connectivity->_constituent==NULL)
1127 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Edges are defined but there are no Faces !"));
1128 Connectivity->_constituent->_constituent = constituent ;
1130 Connectivity->_constituent = constituent ;
1133 delete[] tmpEdgeCount;
1141 int MED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
1143 const char * LOC = "MED_MESH_RDONLY_DRIVER::getDescendingConnectivity : " ;
1144 if (_status==MED_OPENED)
1146 MESSAGE(LOC<<"call on the object " << Connectivity);
1147 MESSAGE(LOC<<"Not yet implemented !");
1152 // int MED_MESH_RDONLY_DRIVER::getElementFamilies(CONNECTIVITY * Connectivity)
1155 // int NumberOfTypes = Connectivity->_numberOfTypes ;
1156 // int * Count = Connectivity->_count ;
1157 // medGeometryElement * GeometricTypes= Connectivity->_geometricTypes ;
1158 // int ** tmp_array = new int*[NumberOfTypes] ;
1159 // for (int i=0; i<NumberOfTypes; i++)
1160 // tmp_array[i]=NULL ;
1161 // for (int i=0; i<NumberOfTypes; i++) {
1162 // int NumberOfElements = Count[i+1]-Count[i] ;
1163 // int * tmp_families_number = new int[NumberOfElements] ;
1164 // err = MEDfamLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
1165 // tmp_families_number,NumberOfElements,
1166 // Connectivity->_entity,GeometricTypes[i]);
1167 // tmp_array[i]=tmp_families_number ;
1168 // if (err != MED_VALID) {
1169 // for (int j=0; j<NumberOfTypes; j++)
1170 // if (tmp_array[j] != NULL)
1171 // delete[] tmp_array[j] ;
1172 // delete[] tmp_array ;
1173 // throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getElementFamilies : No Family in element GeometricTypes[i]");
1177 // if (Connectivity->_entity == MED_CELL)
1178 // _ptrMesh->_MEDArrayCellFamily = tmp_array ;
1179 // else if (Connectivity->_entity == MED_FACE)
1180 // _ptrMesh->_MEDArrayFaceFamily = tmp_array ;
1181 // else if (Connectivity->_entity == MED_EDGE)
1182 // _ptrMesh->_MEDArrayEdgeFamily = tmp_array ;
1184 // return MED_VALID ;
1187 int MED_MESH_RDONLY_DRIVER::getFAMILY()
1189 const char * LOC = "MED_MESH_RDONLY_DRIVER::getFAMILY() : " ;
1192 if (_status==MED_OPENED) {
1195 int * MEDArrayNodeFamily = NULL ;
1196 int ** MEDArrayCellFamily = NULL ;
1197 int ** MEDArrayFaceFamily = NULL ;
1198 int ** MEDArrayEdgeFamily = NULL ;
1200 if ( !_ptrMesh->getIsAGrid() )
1204 MEDArrayNodeFamily = new int[_ptrMesh->getNumberOfNodes()] ;
1205 err = getNodesFamiliesNumber(MEDArrayNodeFamily) ; // error only if (_status!=MED_OPENED), other case exeception !
1208 MESSAGE(LOC << "error returned from getNodesFamiliesNumber " << err);
1210 MEDArrayCellFamily = new (int*)[_ptrMesh->getNumberOfTypes(MED_CELL)] ; // ET SI IL N'Y A PAS DE CELLS ?
1211 const medGeometryElement * myTypes = _ptrMesh->getTypes(MED_CELL);
1212 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_CELL);i++)
1213 MEDArrayCellFamily[i] = new int[_ptrMesh->getNumberOfElements(MED_CELL,myTypes[i])] ;
1215 err = getCellsFamiliesNumber(MEDArrayCellFamily,_ptrMesh->_connectivity) ;
1217 MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Cells " << err);
1219 if (_ptrMesh->_connectivity->_constituent != NULL) {
1220 if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE) {
1222 MEDArrayFaceFamily = new (int*)[_ptrMesh->getNumberOfTypes(MED_FACE)] ;
1223 myTypes = _ptrMesh->getTypes(MED_FACE);
1224 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_FACE);i++)
1225 MEDArrayFaceFamily[i] = new int[_ptrMesh->getNumberOfElements(MED_FACE,myTypes[i])] ;
1227 err = getCellsFamiliesNumber(MEDArrayFaceFamily,_ptrMesh->_connectivity->_constituent) ;
1229 MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Faces " << err);
1233 MEDArrayEdgeFamily = new (int*)[_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1234 myTypes = _ptrMesh->getTypes(MED_EDGE);
1235 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1236 MEDArrayEdgeFamily[i] = new int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes[i])] ;
1237 err = getCellsFamiliesNumber(MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent) ;
1239 MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Edges in 2D " << err);
1243 if (_ptrMesh->_connectivity->_constituent->_constituent != NULL) {
1244 MEDArrayEdgeFamily = new (int*)[_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1245 myTypes = _ptrMesh->getTypes(MED_EDGE);
1246 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1247 MEDArrayEdgeFamily[i] = new int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes[i])] ;
1248 err = getCellsFamiliesNumber(MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent->_constituent) ; // we are in 3D !
1250 MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Edges in 3D " << err);
1258 int NumberOfNodes = _ptrMesh->getNumberOfNodes() ;
1259 MEDArrayNodeFamily = new int[ NumberOfNodes ];
1260 err = MED_FR::MEDfamGridLire (_medIdt,
1261 const_cast <char *> (_ptrMesh->_name.c_str()),
1266 // what about cell face and edge ?
1269 // Creation of the families
1270 int NumberOfFamilies = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),0,MED_FR::MED_FAMILLE) ;
1271 if ( NumberOfFamilies < 1 ) // at least family 0 must exist
1272 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"There is no FAMILY, FAMILY 0 must exists" ));
1274 SCRUTE(NumberOfFamilies);
1276 vector<FAMILY*> &NodeFamilyVector = _ptrMesh->_familyNode ;
1277 vector<FAMILY*> &CellFamilyVector = _ptrMesh->_familyCell ;
1278 vector<FAMILY*> &FaceFamilyVector = _ptrMesh->_familyFace ;
1279 vector<FAMILY*> &EdgeFamilyVector = _ptrMesh->_familyEdge ;
1281 int numberOfNodesFamilies = 0 ;
1282 int numberOfCellsFamilies = 0 ;
1283 int numberOfFacesFamilies = 0 ;
1284 int numberOfEdgesFamilies = 0 ;
1286 for (int i=0;i<NumberOfFamilies;i++) {
1288 int NumberOfAttributes = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,MED_FR::MED_ATTR) ;
1289 if (NumberOfAttributes < 0)
1290 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : NumberOfAttributes" );
1292 int NumberOfGroups = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,MED_FR::MED_GROUPE) ;
1293 if (NumberOfGroups < 0)
1294 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : NumberOfGroups" );
1296 int FamilyIdentifier ;
1297 string FamilyName(MED_TAILLE_NOM,'\0');
1298 int * AttributesIdentifier = new int[NumberOfAttributes] ;
1299 int * AttributesValues = new int[NumberOfAttributes] ;
1300 string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ;
1301 string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups+1,'\0') ;
1302 err = MED_FR::MEDfamInfo(_medIdt,const_cast <char *> (_meshName.c_str()),
1303 i+1,const_cast <char *> (FamilyName.c_str()),
1304 &FamilyIdentifier,AttributesIdentifier,AttributesValues,
1305 const_cast <char *> (AttributesDescription.c_str()),
1306 &NumberOfAttributes,
1307 const_cast <char *> (GroupsNames.c_str()),&NumberOfGroups
1311 SCRUTE(GroupsNames);
1316 if (err != MED_VALID)
1317 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : ERROR when get FAMILY informations" );
1318 if (FamilyIdentifier != 0 ) {
1319 FAMILY * Family = new FAMILY(_ptrMesh,FamilyIdentifier,FamilyName,
1320 NumberOfAttributes,AttributesIdentifier,
1321 AttributesValues,AttributesDescription,
1322 NumberOfGroups,GroupsNames,
1329 // if nothing found, delete Family
1332 //MESSAGE(LOC << " Well is that OK now ?? " << (*Family));
1336 if (Family->getNumberOfTypes() == 0) {
1337 MESSAGE(LOC<<"Nothing found for family "<<FamilyName<< " : skip");
1340 switch (Family->getEntity()) {
1341 case MED_EN::MED_NODE :
1342 NodeFamilyVector.push_back(Family) ;
1343 numberOfNodesFamilies++ ;
1345 case MED_EN::MED_CELL :
1346 CellFamilyVector.push_back(Family) ;
1347 numberOfCellsFamilies++ ;
1349 case MED_EN::MED_FACE :
1350 FaceFamilyVector.push_back(Family) ;
1351 numberOfFacesFamilies++ ;
1353 case MED_EN::MED_EDGE :
1354 EdgeFamilyVector.push_back(Family) ;
1355 numberOfEdgesFamilies++ ;
1359 // MESSAGE(LOC << (*Family));
1366 delete [] AttributesIdentifier ;
1367 delete [] AttributesValues ;
1370 if (MEDArrayNodeFamily != NULL)
1371 delete[] MEDArrayNodeFamily ;
1372 if (MEDArrayCellFamily != NULL) {
1373 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_CELL);i++)
1374 delete[] MEDArrayCellFamily[i] ;
1375 delete[] MEDArrayCellFamily ;
1377 if (MEDArrayFaceFamily != NULL) {
1378 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_FACE);i++)
1379 delete[] MEDArrayFaceFamily[i] ;
1380 delete[] MEDArrayFaceFamily ;
1382 if (MEDArrayEdgeFamily != NULL) {
1383 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1384 delete[] MEDArrayEdgeFamily[i] ;
1385 delete[] MEDArrayEdgeFamily ;
1394 int MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
1396 const char * LOC = "MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber() : " ;
1398 if (_status==MED_OPENED) {
1400 err = MEDfamLire(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
1402 _ptrMesh->getNumberOfNodes(),
1403 MED_FR::MED_NOEUD,(enum MED_FR::med_geometrie_element) MED_NONE);
1404 if ( err != MED_VALID) {
1405 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "There is no family for the |"<< _ptrMesh->getNumberOfNodes()
1406 << "| nodes in mesh |"
1407 << _ptrMesh->_name.c_str() << "|" ));
1415 int MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber(int **MEDArrayFamily,CONNECTIVITY *Connectivity)
1417 const char * LOC = "MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber " ;
1420 if (_status==MED_OPENED) {
1422 for (i=0;i<Connectivity->_numberOfTypes;i++) {
1423 int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
1424 err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1425 MEDArrayFamily[i],NumberOfCell,
1426 (MED_FR::med_entite_maillage) Connectivity->_entity,
1427 (MED_FR::med_geometrie_element) Connectivity->_geometricTypes[i]);
1429 // provisoire : si les faces ou les aretes sont des mailles !!!
1430 if (err != MED_VALID) {
1431 MESSAGE(LOC<<"search face/edge family on cell !!!");
1432 err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1433 MEDArrayFamily[i],NumberOfCell,
1435 (MED_FR::med_geometrie_element) Connectivity->_geometricTypes[i]);
1438 if (err != MED_VALID)
1439 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<Connectivity->_geometricTypes[i]));
1447 void MED_MESH_RDONLY_DRIVER::buildAllGroups(vector<GROUP*> & Groups, vector<FAMILY*> & Families)
1449 const char * LOC = "MED_MESH_RDONLY_DRIVER::buildAllGroups " ;
1452 int numberOfFamilies = Families.size() ;
1453 //SCRUTE(numberOfFamilies);
1454 map< string,list<FAMILY*> > groupsNames ;
1455 for(int i=0; i<numberOfFamilies; i++) {
1456 FAMILY * myFamily = Families[i] ;
1457 int numberOfGroups_ = myFamily->getNumberOfGroups();
1459 //SCRUTE(numberOfGroups_);
1460 for (int j=0; j<numberOfGroups_; j++) {
1462 //SCRUTE(myFamily->getGroupName(j+1));
1463 groupsNames[myFamily->getGroupName(j+1)].push_back(myFamily);
1466 int numberOfGroups = groupsNames.size() ;
1467 SCRUTE(numberOfGroups);
1468 Groups.resize(numberOfGroups);
1469 map< string,list<FAMILY*> >::const_iterator currentGroup ;
1471 for(currentGroup=groupsNames.begin();currentGroup!=groupsNames.end();currentGroup++) {
1472 GROUP * myGroup = new GROUP((*currentGroup).first,(*currentGroup).second) ;
1473 // GROUP * myGroup = new GROUP() ;
1474 // myGroup->setName((*currentGroup).first);
1475 // SCRUTE(myGroup->getName());
1476 // //myGroup->setMesh(_ptrMesh);
1477 // myGroup->init((*currentGroup).second);
1486 void MED_MESH_RDONLY_DRIVER::updateFamily()
1488 const char * LOC = "MED_MESH_RDONLY_DRIVER::updateFamily() " ;
1491 // we need to update family on constituent if we have constituent, but no
1492 // descending connectivity, so, we must calculate all constituent and
1493 // numbering correctly family !
1494 _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyFace) ; // in 2d, do nothing
1495 _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyEdge) ; // in 3d, do nothing
1501 void MED_MESH_RDONLY_DRIVER::write( void ) const
1503 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
1506 /*--------------------- WRONLY PART -------------------------------*/
1508 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER():MED_MESH_DRIVER()
1512 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName,
1514 MED_MESH_DRIVER(fileName,ptrMesh,MED_WRONLY)
1516 MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
1519 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver):
1520 MED_MESH_DRIVER(driver)
1524 MED_MESH_WRONLY_DRIVER::~MED_MESH_WRONLY_DRIVER()
1526 //MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed");
1529 GENDRIVER * MED_MESH_WRONLY_DRIVER::copy(void) const
1531 return new MED_MESH_WRONLY_DRIVER(*this);
1534 void MED_MESH_WRONLY_DRIVER::read (void)
1536 throw MEDEXCEPTION("MED_MESH_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
1539 void MED_MESH_WRONLY_DRIVER::write(void) const
1541 const char * LOC = "void MED_MESH_WRONLY_DRIVER::write(void) const : ";
1544 // we must first create mesh !!
1545 MESSAGE(LOC << "MeshName : |" << _meshName << "| FileName : |"<<_fileName<<"| MedIdt : | "<< _medIdt << "|");
1547 if (_status!=MED_OPENED)
1548 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "File "<<_fileName<<" is not open. Open it before write !"));
1550 if (_ptrMesh->getIsAGrid())
1552 if ( writeGRID() != MED_VALID )
1553 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeGRID()" )) ;
1557 if (writeCoordinates()!=MED_VALID)
1558 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()" )) ;
1560 if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID)
1561 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)" )) ;
1562 if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID)
1563 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)" )) ;
1564 if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID)
1565 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)" )) ;
1568 if (writeFamilyNumbers() !=MED_VALID)
1569 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilyNumbers()" )) ;
1572 // well we must first write zero family :
1573 if (_status==MED_OPENED) {
1575 // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
1576 string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_0/";
1577 MESSAGE("|"<<dataGroupFam<<"|");
1578 err =_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) );
1579 if ( err < MED_VALID ) {
1582 err = MED_FR::MEDfamCr( _medIdt,
1583 const_cast <char *> ( _meshName.c_str() ),
1585 (int*)NULL, (int*)NULL, (char*)NULL, 0,
1588 if ( err != MED_VALID)
1589 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_0| with identifier |0| groups names || and attributes descriptions ||")) ;
1592 _MEDdatagroupFermer(_medIdt);
1596 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyNode)");
1597 if (writeFamilies(_ptrMesh->_familyNode) !=MED_VALID)
1598 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyNode)" )) ;
1600 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyCell)");
1601 if (writeFamilies(_ptrMesh->_familyCell) !=MED_VALID)
1602 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyCell)" )) ;
1604 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyFace)");
1605 if (writeFamilies(_ptrMesh->_familyFace) !=MED_VALID)
1606 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyFace)" )) ;
1608 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyEdge)");
1609 if (writeFamilies(_ptrMesh->_familyEdge) !=MED_VALID)
1610 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyEdge)" )) ;
1615 //=======================================================================
1616 //function : writeGRID
1618 //=======================================================================
1620 int MED_MESH_WRONLY_DRIVER::writeGRID() const
1622 const char * LOC = "MED_MESH_WRONLY_DRIVER::writeGRID() : " ;
1625 if (_status!=MED_OPENED)
1627 MESSAGE (LOC<<" Not open !!!");
1630 GRID * ptrGrid = (GRID*) _ptrMesh;
1632 MED_FR::med_err err = MED_ERROR;
1633 MED_FR::med_repere rep;
1634 string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM,' ');
1635 string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM,' ');
1637 // Test if the mesh <_meshName> already exists
1638 // If it doesn't exists create it
1639 // If it already exists verify if its dimension is the same as <_ptrMesh->_spaceDimension>
1640 // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
1641 int dim = MED_FR::MEDdimLire(_medIdt, const_cast <char *> (_meshName.c_str()) );
1642 if (dim < MED_VALID)
1644 err = MEDgridCr(_medIdt,
1645 const_cast <char *> (_meshName.c_str()),
1646 _ptrMesh->_spaceDimension,
1647 (MED_FR::med_grid_type) ptrGrid->getGridType());
1648 if (err != MED_VALID)
1649 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Grid"));
1651 MESSAGE(LOC<<"Grid "<<_meshName<<" created in file "<<_fileName<<" !");
1653 else if (dim != _ptrMesh->_spaceDimension)
1654 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
1655 "| already exists in file |" << _fileName <<
1656 "| with dimension |" << dim <<
1657 "| but the dimension of the mesh we want to write is |"
1658 << _ptrMesh->_spaceDimension <<"|" )) ;
1660 // Recompose the <_spaceDimension> strings in 1 string
1662 string valueString ;
1663 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
1665 valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
1666 lengthString = (MED_TAILLE_PNOM<valueString.size())?MED_TAILLE_PNOM:valueString.size() ;
1667 tmp_name.replace(i*MED_TAILLE_PNOM,i*MED_TAILLE_PNOM+lengthString,valueString,0,lengthString);
1668 valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
1669 lengthString = (MED_TAILLE_PNOM<valueString.size())?MED_TAILLE_PNOM:valueString.size() ;
1670 tmp_unit.replace(i*MED_TAILLE_PNOM,i*MED_TAILLE_PNOM+lengthString,valueString,0,lengthString);
1673 // Pourquoi le stocker sous forme de chaîne ?
1674 const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
1675 if (coordinateSystem == "CARTESIAN")
1676 rep = MED_FR::MED_CART;
1677 else if ( coordinateSystem == "CYLINDRICAL")
1678 rep = MED_FR::MED_CYL;
1679 else if ( coordinateSystem == "SPHERICAL" )
1680 rep = MED_FR::MED_SPHER;
1682 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
1683 "| doesn't have a valid coordinate system : |"
1684 << _ptrMesh->_coordinate->_coordinateSystem
1687 int ArrayLen[] = { ptrGrid->_iArrayLength,
1688 ptrGrid->_jArrayLength,
1689 ptrGrid->_kArrayLength };
1691 // Write node coordinates for MED_BODY_FITTED grid
1692 if (ptrGrid->getGridType() == MED_EN::MED_BODY_FITTED)
1695 // Write Coordinates and families
1696 double * coo = const_cast <double *>
1697 (_ptrMesh->_coordinate->getCoordinates(MED_EN::MED_FULL_INTERLACE));
1699 // Write unused families
1700 int * MEDArrayNodeFamily = new int[_ptrMesh->_numberOfNodes] ;
1702 err = MEDbodyFittedEcr (_medIdt,
1703 const_cast <char *> (_ptrMesh->_name.c_str()),
1704 _ptrMesh->_spaceDimension,
1707 MED_FR::MED_FULL_INTERLACE,
1709 const_cast <char *> (tmp_name.c_str()),
1710 const_cast <char *> (tmp_unit.c_str()),
1712 _ptrMesh->_numberOfNodes,
1714 delete[] MEDArrayNodeFamily;
1716 if (err != MED_VALID)
1717 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in MEDbodyFittedEcr()"));
1722 // Write Arrays of Cartesian or Polar Grid
1724 double * Array[] = { ptrGrid->_iArray,
1728 for (idim = 0; idim < _ptrMesh->_spaceDimension; ++idim)
1730 err = MEDgridEcr (_medIdt,
1731 const_cast <char *> (_ptrMesh->_name.c_str()),
1732 _ptrMesh->_spaceDimension,
1736 MED_FR::MED_FULL_INTERLACE,
1738 const_cast <char *> (tmp_name.c_str()),
1739 const_cast <char *> (tmp_unit.c_str()),
1741 if (err != MED_VALID)
1742 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read grid coordinates for "
1743 << idim << "-th dimention"));
1746 // err = MEDfamGridEcr(_medIdt,
1747 // const_cast <char *> (_ptrMesh->_name.c_str()),
1748 // _ptrMesh->_MEDArrayNodeFamily,
1749 // _ptrMesh->_numberOfNodes,
1750 // MED_FR::MED_REMP,
1751 // MED_FR::MED_NOEUD);
1752 if (err != MED_VALID)
1753 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in MEDfamGridEcr()"));
1755 } // end Write Cartesian or Polar Grid
1761 //=======================================================================
1762 //function : writeCoordinates
1764 //=======================================================================
1766 int MED_MESH_WRONLY_DRIVER::writeCoordinates() const {
1768 const char * LOC = "int MED_MESH_WRONLY_DRIVER::writeCoordinates() const : ";
1771 MED_FR::med_err err = MED_ERROR;
1772 MED_FR::med_repere rep;
1773 string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM,' ');
1774 string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM,' ');
1776 // Recompose the <_spaceDimension> strings in 1 string
1778 string valueString ;
1779 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
1780 valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
1781 lengthString = (MED_TAILLE_PNOM<valueString.size())?MED_TAILLE_PNOM:valueString.size() ;
1782 tmp_name.replace(i*MED_TAILLE_PNOM,i*MED_TAILLE_PNOM+lengthString,valueString,0,lengthString);
1783 valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
1784 lengthString = (MED_TAILLE_PNOM<valueString.size())?MED_TAILLE_PNOM:valueString.size() ;
1785 tmp_unit.replace(i*MED_TAILLE_PNOM,i*MED_TAILLE_PNOM+lengthString,valueString,0,lengthString);
1788 // Test if the mesh <_meshName> already exists
1789 // If it doesn't exists create it
1790 // If it already exists verify if its dimension is the same as <_ptrMesh->_spaceDimension>
1791 // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
1792 int dim = MED_FR::MEDdimLire(_medIdt, const_cast <char *> (_meshName.c_str()) );
1793 if (dim < MED_VALID)
1794 if (MED_FR::MEDmaaCr(_medIdt,const_cast <char *> (_meshName.c_str()),_ptrMesh->_spaceDimension) != 0 )
1795 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|"));
1798 MESSAGE(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !");
1800 else if (dim != _ptrMesh->_spaceDimension)
1801 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| already exists in file |" << _fileName
1802 << "| with dimension |" << dim << "| but the dimension of the mesh we want to write is |"
1803 << _ptrMesh->_spaceDimension <<"|" )) ;
1805 // Pourquoi le stocker sous forme de chaîne ?
1806 const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
1807 if (coordinateSystem == "CARTESIAN")
1808 rep = MED_FR::MED_CART;
1809 else if ( coordinateSystem == "CYLINDRICAL")
1810 rep = MED_FR::MED_CYL;
1811 else if ( coordinateSystem == "SPHERICAL" )
1812 rep = MED_FR::MED_SPHER;
1814 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |"
1815 << _ptrMesh->_coordinate->_coordinateSystem
1818 err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
1819 _ptrMesh->_spaceDimension,
1820 //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
1821 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
1822 MED_FR::MED_FULL_INTERLACE,
1823 _ptrMesh->_numberOfNodes, // _ptrMesh->_coordinate->_numberOfNodes
1826 const_cast <char *> (tmp_name.c_str()),
1827 const_cast <char *> (tmp_unit.c_str())
1831 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName
1832 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
1833 << " with units names |" << tmp_name
1834 << "| and units |" << tmp_unit
1838 //////////////////////////////////////////////////////////////////////////////////////
1839 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1840 //////////////////////////////////////////////////////////////////////////////////////
1842 /// Ecrit les numéros optionnels des noeuds
1843 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1846 if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) {
1848 err = MEDnumEcr(_medIdt,const_cast <char *> (_meshName.c_str()),
1849 const_cast <med_int *> (_ptrMesh->_coordinate->getNodesNumbers() ),
1850 _ptrMesh->_numberOfNodes, MED_FR::MED_REMP,
1851 MED_FR::MED_NOEUD, MED_FR::med_geometrie_element(0) );
1855 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write optionnal numbers of mesh |" << _meshName.c_str()
1856 << "| in file |" << _fileName << " |")) ;
1858 //////////////////////////////////////////////////////////////////////////////////////
1868 int MED_MESH_WRONLY_DRIVER::writeConnectivities(medEntityMesh entity) const {
1870 const char * LOC="int MED_MESH_WRONLY_DRIVER::writeConnectivities() const : ";
1873 MED_FR::med_err err;
1875 // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB !
1876 // PG : IMPOSSIBLE : LA METHODE EST PRIVEE !
1878 // A FAIRE : A tester surtout dans les methodes de MESH.
1879 // if ( _ptrMesh->_connectivity == (CONNECTIVITY *) MED_INVALID )
1880 if ( _ptrMesh->_connectivity == (CONNECTIVITY *) NULL )
1881 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object ")) ;
1883 if ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) {
1885 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
1886 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
1888 for (int i=0; i<numberOfTypes; i++) {
1890 int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
1891 const int * connectivity = _ptrMesh->getConnectivity (MED_EN::MED_FULL_INTERLACE,
1892 MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ??
1894 // Pour l'instant la class utilise le multi.....
1896 if (entity==MED_EN::MED_CELL)
1897 if ( (types[i]/ 100) < _ptrMesh->_spaceDimension)
1899 int numberOfNodes = types[i]%100 ;
1900 int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)];
1902 // version originale sans prise en compte des numéros optionnels
1904 for (int j=0 ; j<numberOfElements; j++)
1906 for (int k=0; k<numberOfNodes; k++)
1907 connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ;
1909 if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
1912 //////////////////////////////////////////////////////////////////////////////////////
1913 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1914 //////////////////////////////////////////////////////////////////////////////////////
1916 /// Dénumérote les sommets des mailles pour leur rendre leurs numéros optionnels
1917 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1919 // if (_ptrMesh->_arePresentOptionnalNodesNumbers==1)
1921 // const int * nodesNumbers = _ptrMesh->_coordinate->getNodesNumbers();
1922 // for (int j=0 ; j<numberOfElements; j++)
1924 // for (int k=0; k<numberOfNodes; k++) connectivityArray[j*(numberOfNodes+multi)+k]=nodesNumbers[connectivity[j*numberOfNodes+k]-1] ;
1925 // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
1930 // for (int j=0 ; j<numberOfElements; j++)
1932 // for (int k=0; k<numberOfNodes; k++) connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ;
1933 // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
1937 //////////////////////////////////////////////////////////////////////////////////////
1939 err = MEDconnEcr( _medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension,
1940 connectivityArray, MED_FR::MED_FULL_INTERLACE , numberOfElements,
1942 (MED_FR::med_entite_maillage ) entity,
1943 (MED_FR::med_geometrie_element) types[i], MED_FR::MED_NOD );
1944 delete[] connectivityArray ;
1946 if (err<0) // ETENDRE LES EXPLICATIONS
1947 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
1948 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
1952 // Connctivity descending :
1953 if ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) {
1955 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
1956 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
1958 for (int i=0; i<numberOfTypes; i++) {
1960 int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
1961 const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]);
1963 // Pour l'instant la class utilise le multi.....
1964 err = MED_FR::MEDconnEcr( _medIdt,
1965 const_cast <char *> ( _meshName.c_str()),
1966 _ptrMesh->_spaceDimension,
1967 const_cast <int *> (connectivity),
1968 MED_FR::MED_FULL_INTERLACE,
1971 (MED_FR::med_entite_maillage ) entity,
1972 (MED_FR::med_geometrie_element) types[i],
1975 if (err<0) // ETENDRE LES EXPLICATIONS
1976 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
1977 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
1986 int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const {
1988 const char * LOC="int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const : ";
1991 MED_FR::med_err err;
1993 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH
1995 { // Node related block
1997 // We build the array from the families list objects :
1998 int NumberOfNodes = _ptrMesh->getNumberOfNodes() ;
1999 int * MEDArrayNodeFamily = new int[NumberOfNodes] ;
2000 // family 0 by default
2001 for (int i=0; i<NumberOfNodes; i++)
2002 MEDArrayNodeFamily[i]=0;
2003 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(MED_NODE);
2004 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyNode;
2005 int NumberOfNodesFamilies = myFamilies->size() ;
2006 //bool ToDestroy = false;
2007 if (0 == NumberOfNodesFamilies) {
2008 //ToDestroy = true ;
2009 vector<GROUP*> myGroups = _ptrMesh->getGroups(MED_NODE);
2010 int NumberOfGroups = myGroups.size() ;
2011 // build families from groups
2012 for (int i=0; i<NumberOfGroups; i++) {
2013 SUPPORT * mySupport = myGroups[i] ;
2014 FAMILY* myFamily = new FAMILY(*mySupport);
2015 myFamily->setIdentifier(i+1);
2016 myFamilies->push_back(myFamily);
2018 NumberOfNodesFamilies=myFamilies->size() ;
2020 for (int i=0 ; i<NumberOfNodesFamilies; i++) {
2022 //SCRUTE(myFamilies[i]->getName());
2023 int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
2024 int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2025 if ((*myFamilies)[i]->isOnAllElements())
2026 for (int j=0; j<TotalNumber; j++)
2027 MEDArrayNodeFamily[j]=FamilyIdentifier;
2029 const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2030 for (int j=0; j<TotalNumber; j++)
2031 MEDArrayNodeFamily[Number[j]-1]=FamilyIdentifier ;
2034 for(int j=0; j<NumberOfNodes; j++) {
2035 SCRUTE(MEDArrayNodeFamily[j]);
2037 if ( !_ptrMesh->getIsAGrid() )
2038 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2039 MEDArrayNodeFamily, NumberOfNodes,MED_FR::MED_REMP ,
2041 (enum MED_FR::med_geometrie_element) MED_NONE);
2043 err = MEDfamGridEcr(_medIdt,
2044 const_cast <char *> (_ptrMesh->_name.c_str()),
2050 if ( err != MED_VALID)
2051 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< NumberOfNodes
2052 << "| nodes in mesh |"
2053 << _ptrMesh->_name.c_str() << "|" ));
2054 delete[] MEDArrayNodeFamily;
2055 //if (true == ToDestroy)
2056 // for (int i=0; i<NumberOfNodesFamilies; i++)
2057 // delete myFamilies[i];
2060 { // CELLS RELATED BLOCK
2061 medEntityMesh entity=MED_EN::MED_CELL;
2062 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
2063 if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
2065 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
2066 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
2068 // We build the array from the families list objects :
2069 int NumberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS);
2070 int * MEDArrayFamily = new int[NumberOfElements] ;
2071 // family 0 by default
2072 for (int i=0; i<NumberOfElements; i++)
2073 MEDArrayFamily[i]=0;
2074 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity);
2075 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyCell ;
2076 int NumberOfFamilies = myFamilies->size() ;
2077 //bool ToDestroy = false;
2078 if (0 == NumberOfFamilies) {
2079 //ToDestroy = true ;
2080 vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
2081 int NumberOfGroups = myGroups.size() ;
2082 // build families from groups
2083 for (int i=0; i<NumberOfGroups; i++) {
2084 SCRUTE( myGroups[i]->getName() );
2085 SUPPORT * mySupport = myGroups[i] ;
2086 FAMILY* myFamily = new FAMILY(*mySupport);
2087 myFamily->setIdentifier(-i-1);
2088 myFamilies->push_back(myFamily);
2090 NumberOfFamilies=myFamilies->size() ;
2092 for (int i=0 ; i<NumberOfFamilies; i++) {
2093 int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
2094 int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2095 if ((*myFamilies)[i]->isOnAllElements())
2096 for (int ii=0; ii<TotalNumber; ii++)
2097 MEDArrayFamily[ii]=FamilyIdentifier;
2099 const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2100 for (int ii=0; ii<TotalNumber; ii++)
2101 MEDArrayFamily[Number[ii]-1]=FamilyIdentifier ;
2105 const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
2107 for (int i=0; i<numberOfTypes; i++) {
2109 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2110 MEDArrayFamily+typeCount[i]-1,typeCount[i+1]-typeCount[i],
2112 (MED_FR::med_entite_maillage) entity,
2113 (MED_FR::med_geometrie_element) types[i]
2116 if ( err != MED_VALID)
2117 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
2118 << "| cells of geometric type |" << MED_FR::geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |"
2119 << _ptrMesh->_name.c_str() << "|" ));
2121 delete[] MEDArrayFamily ;
2122 //if (true == ToDestroy) {
2123 // int NumberOfFamilies = myFamilies->size();
2124 // for (int i=0; i<NumberOfFamilies; i++)
2125 // delete myFamilies[i];
2130 { // FACE RELATED BLOCK
2131 medEntityMesh entity=MED_EN::MED_FACE;
2132 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
2133 if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
2135 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
2136 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
2137 SCRUTE(numberOfTypes);
2139 int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
2140 int * familyArray = new int[numberOfElements] ;
2141 for (int i=0;i<numberOfElements;i++)
2144 int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
2145 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
2146 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyFace ;
2147 //bool ToDestroy = false;
2148 if (0 == numberOfFamilies) {
2149 //ToDestroy = true ;
2150 vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
2151 int NumberOfGroups = myGroups.size() ;
2152 // build families from groups
2153 for (int i=0; i<NumberOfGroups; i++) {
2154 SCRUTE( myGroups[i]->getName() );
2155 SUPPORT * mySupport = myGroups[i] ;
2156 FAMILY* myFamily = new FAMILY(*mySupport);
2157 myFamily->setIdentifier(-i-1000);
2158 myFamilies->push_back(myFamily);
2160 numberOfFamilies=myFamilies->size() ;
2162 for (int i=0;i<numberOfFamilies;i++) {
2163 int familyNumber = (*myFamilies)[i]->getIdentifier() ;
2164 int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2165 if ((*myFamilies)[i]->isOnAllElements())
2166 for (int ii=0; ii<numberOfFamilyElements; ii++)
2167 familyArray[ii]=familyNumber;
2169 const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2170 for (int ii=0;ii<numberOfFamilyElements;ii++)
2171 familyArray[myFamilyElements[ii]-1]=familyNumber;
2175 const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
2177 for (int i=0; i<numberOfTypes; i++) {
2179 int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
2180 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2181 familyArray+typeCount[i]-1, typeNumberOfElements,
2183 (MED_FR::med_entite_maillage) entity,
2184 (MED_FR::med_geometrie_element) types[i]);
2186 if ( err != MED_VALID)
2187 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
2188 << "| faces of geometric type |" << MED_FR::geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |"
2189 << _ptrMesh->_name.c_str() << "|" ));
2191 delete[] familyArray ;
2192 //if (true == ToDestroy) {
2193 // int NumberOfFamilies = myFamilies->size();
2194 // for (int i=0; i<NumberOfFamilies; i++)
2195 // delete myFamilies[i];
2200 { // EDGE RELATED BLOCK
2201 //medEntityMesh entity=MED_EN::MED_FACE;
2202 medEntityMesh entity=MED_EN::MED_EDGE;
2203 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
2204 if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
2206 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
2207 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
2209 int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
2210 int * familyArray = new int[numberOfElements] ;
2211 for (int i=0;i<numberOfElements;i++)
2214 int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
2215 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
2216 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyEdge ;
2217 //bool ToDestroy = false;
2218 if (0 == numberOfFamilies) {
2219 //ToDestroy = true ;
2220 vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
2221 int NumberOfGroups = myGroups.size() ;
2222 // build families from groups
2223 for (int i=0; i<NumberOfGroups; i++) {
2224 SCRUTE( myGroups[i]->getName() );
2225 SUPPORT * mySupport = myGroups[i] ;
2226 FAMILY* myFamily = new FAMILY(*mySupport);
2227 myFamily->setIdentifier(-i-2000);
2228 myFamilies->push_back(myFamily);
2230 numberOfFamilies=myFamilies->size() ;
2232 for (int i=0;i<numberOfFamilies;i++) {
2233 int familyNumber = (*myFamilies)[i]->getIdentifier() ;
2234 int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2235 if ((*myFamilies)[i]->isOnAllElements())
2236 for (int ii=0; ii<numberOfFamilyElements; ii++)
2237 familyArray[ii]=familyNumber;
2239 const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2240 for (int ii=0;ii<numberOfFamilyElements;ii++)
2241 familyArray[myFamilyElements[ii]-1]=familyNumber;
2245 const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
2247 for (int i=0; i<numberOfTypes; i++) {
2249 int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
2250 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2251 familyArray+typeCount[i]-1, typeNumberOfElements,
2253 (MED_FR::med_entite_maillage) entity,
2254 (MED_FR::med_geometrie_element) types[i]);
2256 if ( err != MED_VALID)
2257 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
2258 << "| edges of geometric type |" << MED_FR::geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |"
2259 << _ptrMesh->_name.c_str() << "|" ));
2261 delete[] familyArray ;
2262 //if (true == ToDestroy) {
2263 // int NumberOfFamilies = myFamilies->size();
2264 // for (int i=0; i<NumberOfFamilies; i++)
2265 // delete myFamilies[i];
2274 int MED_MESH_WRONLY_DRIVER::writeFamilies(vector<FAMILY*> & families ) const {
2276 const char * LOC="int MED_MESH_WRONLY_DRIVER::writeFamilies(vector<FAMILY*> families) const : ";
2279 MED_FR::med_err err;
2281 MESSAGE(LOC<<" families.size() :"<<families.size());
2283 for (unsigned int i=0; i< families.size(); i++) {
2285 int numberOfAttributes = families[i]->getNumberOfAttributes ();
2286 string attributesDescriptions = "";
2288 // Recompose the attributes descriptions arg for MED
2289 for (int j=0; j < numberOfAttributes; j++) {
2291 string attributeDescription = families[i]->getAttributeDescription(j+1);
2293 if ( attributeDescription.size() > MED_TAILLE_DESC )
2294 throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |" << j+1 << "| of the family |" << families[i]->getName()
2295 << "| with identifier |" << families[i]->getIdentifier() << "| is |"
2296 << attributeDescription.size() <<"| and is more than |" << MED_TAILLE_DESC << "|")) ;
2298 attributesDescriptions += attributeDescription;
2302 int numberOfGroups = families[i]->getNumberOfGroups();
2303 string groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0') ;
2304 // Recompose the groups names arg for MED
2305 for (int j=0; j < numberOfGroups; j++) {
2307 string groupName = families[i]->getGroupName(j+1);
2309 if ( groupName.size() > MED_TAILLE_LNOM )
2310 throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name n° |" << j+1 << "| of the family |" << families[i]->getName()
2311 << "| with identifier |" << families[i]->getIdentifier() << "| is |"
2312 << groupName.size() <<"| and is more than |" << MED_TAILLE_LNOM << "|")) ;
2315 int length = min(MED_TAILLE_LNOM,(int)groupName.size());
2316 groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length);
2320 // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
2321 string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/"+families[i]->getName()+"/";
2322 SCRUTE("|"<<dataGroupFam<<"|");
2323 err =_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) ;
2324 if ( err < MED_VALID ) {
2327 MESSAGE(LOC<<"families[i]->getName().c_str() : "<<families[i]->getName().c_str());
2328 MESSAGE(LOC<<"_meshName.c_str() : "<<_meshName.c_str());
2329 MESSAGE(LOC<<"families[i]->getIdentifier() : "<<families[i]->getIdentifier());
2330 MESSAGE(LOC<<"numberOfAttributes : "<<numberOfAttributes);
2332 //MESSAGE(LOC<<"families[i]->getAttributesIdentifiers() : "<<families[i]->getAttributesIdentifiers()[0]);
2333 //MESSAGE(LOC<<"families[i]->getAttributesValues() : "<<families[i]->getAttributesValues()[0]);
2334 MESSAGE(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str());
2335 MESSAGE(LOC<<"numberOfGroups : "<<numberOfGroups);
2336 MESSAGE(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str());
2338 err = MED_FR::MEDfamCr( _medIdt,
2339 const_cast <char *> ( _meshName.c_str() ),
2340 const_cast <char *> ( families[i]->getName().c_str() ),
2341 families[i]->getIdentifier(),
2342 families[i]->getAttributesIdentifiers(),
2343 families[i]->getAttributesValues(),
2344 const_cast <char *> (attributesDescriptions.c_str()),
2346 const_cast <char *> (groupsNames.c_str()),
2349 if ( err != MED_VALID)
2350 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName()
2351 << "| with identifier |" << families[i]->getIdentifier() << "| groups names |"
2352 << groupsNames <<"| and attributes descriptions |" << attributesDescriptions << "|")) ;
2355 _MEDdatagroupFermer(_medIdt);
2366 // A FAIRE POUR LES NOEUDS ET LES ELEMENTS ret = MEDfamEcr(
2370 /*--------------------- RDWR PART -------------------------------*/
2372 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER():MED_MESH_DRIVER()
2376 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName,
2378 MED_MESH_DRIVER(fileName,ptrMesh,MED_RDWR)
2380 MESSAGE("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
2383 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const MED_MESH_RDWR_DRIVER & driver):
2384 MED_MESH_RDONLY_DRIVER::MED_MESH_DRIVER(driver)
2388 MED_MESH_RDWR_DRIVER::~MED_MESH_RDWR_DRIVER() {
2389 //MESSAGE("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed");
2392 GENDRIVER * MED_MESH_RDWR_DRIVER::copy(void) const
2394 return new MED_MESH_RDWR_DRIVER(*this);
2397 void MED_MESH_RDWR_DRIVER::write(void) const
2399 MED_MESH_WRONLY_DRIVER::write();
2401 void MED_MESH_RDWR_DRIVER::read (void)
2403 MED_MESH_RDONLY_DRIVER::read();