1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MEDMEM_MedMeshDriver.hxx"
23 #include "MEDMEM_GenDriver.hxx"
24 #include "MEDMEM_MedMeshDriver22.hxx"
25 #include "MEDMEM_DriversDef.hxx"
27 #include "MEDMEM_Family.hxx"
28 #include "MEDMEM_Group.hxx"
29 #include "MEDMEM_Coordinate.hxx"
30 #include "MEDMEM_Connectivity.hxx"
31 #include "MEDMEM_Mesh.hxx"
32 #include "MEDMEM_CellModel.hxx"
33 #include "MEDMEM_Grid.hxx"
34 #include "MEDMEM_MedVersion.hxx"
37 using namespace MED_EN;
38 using namespace MEDMEM;
42 extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom);
43 extern med_err _MEDdatagroupFermer(med_idt id);
47 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor
49 MED_MESH_DRIVER22::MED_MESH_DRIVER22(): _medIdt(MED_INVALID)
53 MED_MESH_DRIVER22::MED_MESH_DRIVER22(const string & fileName,
55 MED_EN::med_mode_acces accessMode):
56 _medIdt(MED_INVALID), MED_MESH_DRIVER(fileName,ptrMesh,accessMode)
60 MED_MESH_DRIVER22::MED_MESH_DRIVER22(const MED_MESH_DRIVER22 & driver):
61 MED_MESH_DRIVER(driver),_medIdt(driver._medIdt)
65 MED_MESH_DRIVER22::~MED_MESH_DRIVER22()
69 void MED_MESH_DRIVER22::open()
71 const char * LOC = "MED_MESH_DRIVER22::open()" ;
74 int accessMode = getMedAccessMode( _accessMode, MED_EN::V22 );
75 MESSAGE_MED(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< accessMode);
76 _medIdt = med_2_3::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(med_2_3::med_mode_acces) accessMode);
77 MESSAGE_MED(LOC<<" _medIdt : "<< _medIdt );
81 _medIdt = MED_INVALID;
83 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Could not open file "<<_fileName<<" in mode "<<_accessMode));
89 void MED_MESH_DRIVER22::close()
91 const char * LOC = "MED_MESH_DRIVER22::close() " ;
94 if ( _status == MED_OPENED) {
95 err = med_2_3::MEDfermer(_medIdt);
96 // san -- MED5873 : Calling H5close() here leads to failure of SALOMEDS::StudyManager_i::_SaveAs()
97 // method during study saving process. MEDfermer() seems sufficient for closing a file.
98 //H5close(); // If we call H5close() all the files are closed.
100 throw MEDEXCEPTION( LOCALIZED(STRING(LOC)
101 <<" Error when closing file !"
104 MESSAGE_MED(LOC <<": _medIdt= " << _medIdt );
105 MESSAGE_MED(LOC<<": MEDfermer : err = " << err );
106 _status = MED_CLOSED;
107 _medIdt = MED_INVALID;
112 //A FAIRE UTILISER LES MAPS...
113 const med_2_3::med_geometrie_element MED_MESH_DRIVER22::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]=
114 { med_2_3::MED_POINT1,med_2_3::MED_SEG2,med_2_3::MED_SEG3,med_2_3::MED_TRIA3,med_2_3::MED_QUAD4,med_2_3::MED_TRIA6,med_2_3::MED_QUAD8,
115 med_2_3::MED_TETRA4,med_2_3::MED_PYRA5,med_2_3::MED_PENTA6,med_2_3::MED_HEXA8,med_2_3::MED_TETRA10,med_2_3::MED_PYRA13,
116 med_2_3::MED_PENTA15, med_2_3::MED_HEXA20};
118 const char * const MED_MESH_DRIVER22::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]=
119 { "MED_POINT1","MED_SEG2","MED_SEG3","MED_TRIA3","MED_QUAD4","MED_TRIA6","MED_QUAD8",
120 "MED_TETRA4","MED_PYRA5","MED_PENTA6","MED_HEXA8","MED_TETRA10","MED_PYRA13",
121 "MED_PENTA15","MED_HEXA20"};
124 //---------------------------------- RDONLY PART -------------------------------------------------------------
126 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22():_computeFaces(true)
128 this->GENDRIVER::_accessMode = MED_EN::RDONLY;
131 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName,
133 IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),
134 MED_MESH_DRIVER22(fileName,ptrMesh,RDONLY),
135 MED_MESH_DRIVER(fileName,ptrMesh,RDONLY),
138 MESSAGE_MED("MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
141 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const MED_MESH_RDONLY_DRIVER22 & driver):
142 IMED_MESH_RDONLY_DRIVER(driver),
143 MED_MESH_DRIVER22(driver),
144 MED_MESH_DRIVER(driver),
145 _computeFaces(driver._computeFaces)
149 MED_MESH_RDONLY_DRIVER22::~MED_MESH_RDONLY_DRIVER22()
151 //MESSAGE_MED("MED_MESH_RDONLY_DRIVER22::~MED_MESH_RDONLY_DRIVER() has been destroyed");
154 GENDRIVER * MED_MESH_RDONLY_DRIVER22::copy(void) const
156 return new MED_MESH_RDONLY_DRIVER22(*this);
159 void MED_MESH_RDONLY_DRIVER22::merge ( const GENDRIVER& driver )
161 MED_MESH_DRIVER::merge( driver );
163 const MED_MESH_RDONLY_DRIVER22* other =
164 dynamic_cast< const MED_MESH_RDONLY_DRIVER22* >( &driver );
166 _computeFaces = other->_computeFaces;
170 void MED_MESH_RDONLY_DRIVER22::read(void)
172 const char * LOC = "MED_MESH_RDONLY_DRIVER22::read() : " ;
174 if (_status != MED_OPENED)
175 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName
176 << " is : " << _medIdt << " (the file is not opened)."));
178 if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() ) )
179 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
180 <<" neither <meshName> is set in driver nor in object MESH."));
182 // If _meshName is not set in driver, try to use _ptrMesh->_name
183 if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() ) )
184 _meshName = _ptrMesh->_name;
186 if ( _meshName.size() > MED_TAILLE_NOM )
187 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
188 <<" <meshName> size in object driver MESH is > MED_TAILLE_NOM ."));
190 _ptrMesh->_name = _meshName;
192 // 0020058: Check version of med, which was used to save the file.
193 // 0020058: An assertion happens in MEDcoordLire(), if this version
194 // 0020058: is higher than the currently used version of med product.
195 med_2_3::med_int aMajor, aMinor, aRelease;
196 med_2_3::med_int aMajorCurr, aMinorCurr, aReleaseCurr;
198 med_err aRet = med_2_3::MEDversionLire(_medIdt, &aMajor, &aMinor, &aRelease);
199 med_2_3::MEDversionDonner(&aMajorCurr, &aMinorCurr, &aReleaseCurr);
201 int aVersionHex = (aMajor << 16 | aMinor << 8 | aRelease);
202 int aVersionHexCurr = (aMajorCurr << 16 | aMinorCurr << 8 | aReleaseCurr);
204 if (aRet != 0 || aVersionHex > aVersionHexCurr)
205 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
206 <<" cannot read a file of version higher than the currently used version of med."));
207 // 0020058: end of version check
209 SCRUTE_MED(_ptrMesh->getIsAGrid());
211 if (_ptrMesh->getIsAGrid())
215 if (getFAMILY() != MED_VALID)
216 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid")) ;
217 buildAllGroups(_ptrMesh->_groupNode, _ptrMesh->_familyNode);
222 else // check that the mesh is really unstructured (PAL14113)
224 char meshName[MED_TAILLE_NOM+1] = "";
225 char meshDescription[MED_TAILLE_DESC+1] = "";
226 med_2_3::med_int meshDim;
227 med_2_3::med_maillage meshType;
228 int numberOfMeshes = med_2_3::MEDnMaa(_medIdt);
230 for (int i = 1; i <= numberOfMeshes; i++)
232 MEDmaaInfo(_medIdt, i, meshName, &meshDim, &meshType, meshDescription);
233 if (_meshName == string(meshName)) {
234 if (meshType == med_2_3::MED_STRUCTURE) {
235 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
236 "class GRID must be used for a structured mesh"));
245 if (getCOORDINATE() != MED_VALID)
246 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE" ));
248 if (getCONNECTIVITY() != MED_VALID)
249 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOONECTIVITY"));
251 if (getFAMILY() != MED_VALID)
252 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY" ));
257 // we build all groups
259 buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
261 buildAllGroups(_ptrMesh->_groupCell,_ptrMesh->_familyCell) ;
263 if (_ptrMesh->_meshDimension == 3)
265 buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace) ;
266 // else if (_ptrMesh->_meshDimension == 2) -- PAL13414
267 if (_ptrMesh->_meshDimension > 1)
269 buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ;
271 _ptrMesh->_name = healName( _ptrMesh->_name );
272 // MESSAGE_MED(LOC<<"Checking of CellModel !!!!!!!");
274 // int nbOfTypes = _ptrMesh->_connectivity->_numberOfTypes;
275 // for(int i=0;i<nbOfTypes;i++)
277 // MESSAGE_MED(LOC << _ptrMesh->_connectivity->_type[i]) ;
283 //=======================================================================
286 //=======================================================================
288 void MED_MESH_RDONLY_DRIVER22::getGRID()
290 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getGRID() : " ;
293 if (_status!=MED_OPENED)
294 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "med file is not opened"));
296 GRID * ptrGrid = (GRID *) _ptrMesh;
302 int numberOfMeshesInFile = med_2_3::MEDnMaa(_medIdt);
304 if (numberOfMeshesInFile == MED_INVALID)
305 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName << " is supposed to be stored"));
307 for (int index = 0; index < numberOfMeshesInFile; index++)
309 char meshName[MED_TAILLE_NOM+1]="";
310 char meshDescription[MED_TAILLE_DESC+1]="";
312 med_2_3::med_int meshDim;
313 med_2_3::med_maillage meshType;
315 err = med_2_3::MEDmaaInfo(_medIdt, (index+1),meshName, &meshDim,
316 &meshType, meshDescription) ;
318 MESSAGE_MED(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
320 if (_meshName == string(meshName))
322 _ptrMesh->_description = meshDescription;
323 _ptrMesh->_name = meshName;
327 MED_EN::med_grid_type gridType = ptrGrid->getGridType();
328 if ( ptrGrid->_is_default_gridType )
330 med_2_3::med_type_grille type;
331 err = med_2_3::MEDnatureGrilleLire(_medIdt,
332 const_cast <char *>(_meshName.c_str()),
334 if (err != MED_VALID)
335 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get the nature of the grid which is the mesh n°" << i << " of the file |" << _fileName << "| !"));
337 gridType = ptrGrid->_gridType = (MED_EN::med_grid_type) type;
338 ptrGrid->_is_default_gridType = false;
341 MESSAGE_MED(LOC<<": Mesh processed is nammed "<< _ptrMesh->_name << " with the description " << _ptrMesh->_description << " is structured with the type " << gridType);
343 // Read the dimension of the mesh <_meshName>
344 int MeshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *>
345 (_meshName.c_str())) ;
347 if (MeshDimension == MED_INVALID)
348 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The mesh dimension |" <<
349 MeshDimension << "| seems to be incorrect " <<
350 "for the mesh : |" << _meshName << "|")) ;
352 _ptrMesh->_meshDimension = MeshDimension;
354 // Read or get the dimension of the space for the mesh <_meshName>
355 int SpaceDimension = MeshDimension;
357 int SpaceDimensionRead = med_2_3::MEDdimEspaceLire(_medIdt,
359 (_meshName.c_str())) ;
361 if (SpaceDimensionRead != MED_INVALID) SpaceDimension = SpaceDimensionRead;
363 _ptrMesh->_spaceDimension = SpaceDimension;
365 med_2_3::med_repere rep ;
366 string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' ');
367 string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' ');
368 char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str()) ) ;
369 char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
372 int * ArrayLen[] = { & ptrGrid->_iArrayLength,
373 & ptrGrid->_jArrayLength,
374 & ptrGrid->_kArrayLength };
376 MESSAGE_MED(LOC << "The mesh is a " << _ptrMesh->_meshDimension << "D mesh on a " << _ptrMesh->_spaceDimension << "D space");
380 // if (gridType == MED_EN::MED_GRILLE_STANDARD)
381 if (gridType == MED_EN::MED_BODY_FITTED)
383 //CCRT int * structure = new int[MeshDimension];
384 med_2_3::med_int * structure = new med_2_3::med_int[MeshDimension];
386 err = med_2_3::MEDstructureCoordLire(_medIdt,
388 (_ptrMesh->_name.c_str()),
389 MeshDimension,structure);
391 if (err != MED_VALID)
392 throw MEDEXCEPTION(STRING(LOC) <<"Error in reading the structure of grid : |" << _meshName << "|" ) ;
396 for (int idim = 0; idim < MeshDimension; idim++)
398 MESSAGE_MED(LOC<<"structure dim " << idim << " " << structure[idim]);
400 ArrayLen [idim][0] = structure[idim];
401 NumberOfNodes = NumberOfNodes*structure[idim];
406 // NumberOfNodes = MED_FR::MEDnEntMaa(_medIdt,
407 // const_cast <char *>
408 // (_ptrMesh->_name.c_str()),
409 // MED_FR::MED_COOR,MED_FR::MED_NOEUD,
410 // (MED_FR::med_geometrie_element) 0,
411 // (MED_FR::med_connectivite) 0);
413 if ( NumberOfNodes == MED_INVALID )
414 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" <<
416 "| seems to be incorrect "
417 << "for the mesh : |" <<
418 _meshName << "|" )) ;
420 _ptrMesh->_numberOfNodes = NumberOfNodes ;
422 // create coordinates and its structure
423 _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
424 MED_EN::MED_FULL_INTERLACE);
426 err = MEDcoordLire(_medIdt,
427 const_cast <char *> (_ptrMesh->_name.c_str()),
428 _ptrMesh->_spaceDimension,
429 //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
430 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
431 med_2_3::MED_FULL_INTERLACE,
432 MED_ALL, // we read all the coordinates
433 NULL, // we don't use a profile
434 0, // so the profile's size is 0
435 &rep,tmp_nom,tmp_unit);
437 if (err != MED_VALID)
438 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" <<
439 NumberOfNodes << "| nodes for the mesh : |" <<
440 _meshName << "| of space dimension |" <<
441 SpaceDimension << "| with units names |" <<
442 tmp_nom << "| and units |" <<
445 ptrGrid->_is_coordinates_filled = true;
447 else if ((gridType == MED_EN::MED_CARTESIAN) ||
448 (gridType == MED_EN::MED_POLAR))
452 double * Array[] = { (double*) 0, (double*) 0, (double*) 0 };
454 for (int idim = 0; idim < _ptrMesh->_meshDimension; ++idim)
456 med_2_3::med_table table;
457 if (idim == 0) table = med_2_3::MED_COOR_IND1;
458 else if (idim == 1) table = med_2_3::MED_COOR_IND2;
459 else if (idim == 2) table = med_2_3::MED_COOR_IND3;
461 int length = med_2_3::MEDnEntMaa(_medIdt,
462 const_cast <char *> (_ptrMesh->_name.c_str()),
463 table,med_2_3::MED_NOEUD,
466 if ( length <= MED_VALID )
467 throw MEDEXCEPTION(STRING(LOC) <<"The number of nodes |" << length <<
468 "| seems to be incorrect "
469 << "for the mesh : |" << _meshName << "|" ) ;
471 ArrayLen [idim][0] = length;
472 NumberOfNodes *= length;
474 Array [idim] = new double [ length ];
476 err = med_2_3::MEDindicesCoordLire(_medIdt, const_cast <char *>
477 (_ptrMesh->_name.c_str()),
478 _ptrMesh->_meshDimension,
479 Array [idim], length, (idim+1),
480 tmp_nom+(idim*MED_TAILLE_PNOM22),
481 tmp_unit+(idim*MED_TAILLE_PNOM22));
483 if (err != MED_VALID)
484 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Error in reading coordinates indices " <<
485 idim << "of the grid : |" <<
486 _meshName << "|" )) ;
489 ptrGrid->_iArray = Array[0];
490 ptrGrid->_jArray = Array[1];
491 ptrGrid->_kArray = Array[2];
493 _ptrMesh->_numberOfNodes = NumberOfNodes ;
495 // create coordinates
496 _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
497 MED_EN::MED_FULL_INTERLACE);
499 if (gridType == MED_EN::MED_CARTESIAN)
500 rep = med_2_3::MED_CART;
501 else if (gridType == MED_EN::MED_POLAR)
503 if (SpaceDimension == 2) rep = med_2_3::MED_CYL;
504 else if (SpaceDimension == 3) rep = med_2_3::MED_SPHER;
508 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" bad grid type : " << gridType));
510 // set coordinate names
512 for (i=0; i<_ptrMesh->_spaceDimension; ++i ) {
513 string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
514 string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
515 // suppress space at the end
517 for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
518 if (myStringName[j] != ' ') break ;
519 _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
520 for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
521 if (myStringUnit[j] != ' ') break ;
522 _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
525 string coordinateSystem = "UNDEFINED";
527 if( rep == med_2_3::MED_CART) coordinateSystem = "CARTESIAN";
528 else if ( rep == med_2_3::MED_CYL) coordinateSystem = "CYLINDRICAL";
529 else if ( rep == med_2_3::MED_SPHER) coordinateSystem = "SPHERICAL";
531 _ptrMesh->_coordinate->setCoordinatesSystem(coordinateSystem);
536 //=======================================================================
537 //function : getCOORDINATE
538 // A FAIRE : RENVOYER DU VOID
539 //=======================================================================
540 int MED_MESH_RDONLY_DRIVER22::getCOORDINATE()
542 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCOORDINATE() : " ;
546 if (_status==MED_OPENED)
550 int numberOfMeshesInFile = med_2_3::MEDnMaa(_medIdt);
552 if (numberOfMeshesInFile == MED_INVALID)
553 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName
554 << " is supposed to be stored"));
556 for (int index = 0; index < numberOfMeshesInFile; index++)
558 char meshName[MED_TAILLE_NOM+1]="";
559 char meshDescription[MED_TAILLE_DESC+1]="";
561 med_2_3::med_int meshDim;
562 med_2_3::med_maillage meshType;
564 err = med_2_3::MEDmaaInfo(_medIdt, (index+1), meshName, &meshDim,
565 &meshType, meshDescription) ;
567 MESSAGE_MED(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName
568 << " with the description " << meshDescription << " is structured");
570 if (_meshName == string(meshName))
572 _ptrMesh->_description = meshDescription;
576 // Read the dimension of the mesh <_meshName>
577 int MeshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *>
578 (_meshName.c_str())) ;
580 if ( MeshDimension == MED_INVALID )
581 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The mesh dimension |" << MeshDimension
582 << "| seems to be incorrect for the mesh : |" << _meshName << "|"));
584 _ptrMesh->_meshDimension = MeshDimension;
586 // Read or get the dimension of the space for the mesh <_meshName>
587 int SpaceDimension = MeshDimension;
589 int SpaceDimensionRead = med_2_3::MEDdimEspaceLire(_medIdt,
591 (_meshName.c_str())) ;
593 if (SpaceDimensionRead != MED_INVALID)
594 SpaceDimension = SpaceDimensionRead;
596 _ptrMesh->_spaceDimension = SpaceDimension;
598 // Read the number of nodes used in the mesh <_meshName>
599 // to be able to create a COORDINATE object
600 int NumberOfNodes=MEDnEntMaa(_medIdt,
601 const_cast <char *> (_meshName.c_str()),
604 (med_2_3::med_geometrie_element) MED_NONE,
605 (med_2_3::med_connectivite) MED_NONE);
606 if ( NumberOfNodes <= MED_VALID )
607 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes
608 << "| seems to be incorrect for the mesh : |" << _meshName << "|" ));
609 _ptrMesh->_numberOfNodes = NumberOfNodes;
611 // create a COORDINATE object
612 if (_ptrMesh->_coordinate)
613 delete _ptrMesh->_coordinate;
614 _ptrMesh->_coordinate = new COORDINATE(SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE);
616 med_2_3::med_repere rep; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON?
617 string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0');
618 string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0');
619 char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str()) ) ;
620 char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
622 err=MEDcoordLire(_medIdt,
623 const_cast <char *> (_ptrMesh->_name.c_str()),
624 _ptrMesh->_spaceDimension,
625 const_cast<double *>(_ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE)),
626 med_2_3::MED_FULL_INTERLACE,
627 MED_ALL, // we read all the coordinates
628 NULL, // we don't use a profile
629 0, // so the profile's size is 0
630 &rep,tmp_nom,tmp_unit);
631 if (err != MED_VALID)
632 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" << NumberOfNodes
633 << "| nodes for the mesh : |" << _meshName
634 << "| of space dimension |" << SpaceDimension
635 << "| with units names |" << tmp_nom
636 << "| and units |" << tmp_unit
639 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
640 string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
641 string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
642 // suppress space at the end
644 for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
645 if (myStringName[j] != ' ') break ;
646 _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
647 for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
648 if (myStringUnit[j] != ' ') break ;
649 _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
652 // Pourquoi le stocker sous forme de chaîne ?
655 case med_2_3::MED_CART :
657 _ptrMesh->_coordinate->_coordinateSystem = "CARTESIAN";
660 case med_2_3::MED_CYL :
662 _ptrMesh->_coordinate->_coordinateSystem = "CYLINDRICAL";
665 case med_2_3::MED_SPHER :
667 _ptrMesh->_coordinate->_coordinateSystem = "SPHERICAL";
672 _ptrMesh->_coordinate->_coordinateSystem = "UNDEFINED"; // ?Erreur ?
677 // Read the unused optional node Names
678 char * tmp_node_name = new char[NumberOfNodes*MED_TAILLE_PNOM22+1];
679 tmp_node_name[NumberOfNodes]='\0' ;
680 err=MEDnomLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
681 tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM22,med_2_3::MED_NOEUD,
682 (med_2_3::med_geometrie_element) MED_NONE);
683 if (err == MED_VALID)
684 MESSAGE_MED(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !");
685 delete[] tmp_node_name ;
687 // ??? Read the unused optional node Numbers ???
688 med_2_3::med_int * tmp_node_number = new med_2_3::med_int[NumberOfNodes] ;
689 err=MEDnumLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
690 tmp_node_number,NumberOfNodes,med_2_3::MED_NOEUD,(med_2_3::med_geometrie_element)0);
691 if (err == MED_VALID) {
692 // INFOS_MED(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
693 // INFOS_MED(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !");
694 // INFOS_MED(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
695 MESSAGE_MED(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : Nodes have numbers, we DO TAKE care of them !");
696 _ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes) ;
697 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
698 for(med_2_3::med_int i2=0;i2<NumberOfNodes;i2++)
699 _ptrMesh->_coordinate->_nodeNumber[i2]=(int)(tmp_node_number[i2]);
701 memcpy((int*)_ptrMesh->_coordinate->_nodeNumber,tmp_node_number,sizeof(int)*NumberOfNodes) ;
704 //////////////////////////////////////////////////////////////////////////////////////
705 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
706 //////////////////////////////////////////////////////////////////////////////////////
708 /// Calcule _optionnalToCanonicNodesNumbers de telle sorte que _optionnalToCanonicNodesNumbers[OptionnalNumber]==CanonicNumber
710 // _ptrMesh->_arePresentOptionnalNodesNumbers=1;
711 // for (int canonicNumber=1;canonicNumber<=NumberOfNodes;canonicNumber++) _ptrMesh->_optionnalToCanonicNodesNumbers[tmp_node_number[canonicNumber-1]]=canonicNumber;
712 // ICI RETOUR A LA NORMALE::: AUCUNE PRISE EN COMPTE D'UN NUMEROTATION OPTIONNEL
713 _ptrMesh->_arePresentOptionnalNodesNumbers=0;
715 else _ptrMesh->_arePresentOptionnalNodesNumbers=0;
717 //////////////////////////////////////////////////////////////////////////////////////
719 delete[] tmp_node_number;
728 int MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY()
730 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY : " ;
733 if (_status==MED_OPENED)
737 // read MED_CELL connectivity
738 CONNECTIVITY * Connectivity = new CONNECTIVITY(MED_CELL) ;
739 Connectivity->_numberOfNodes = _ptrMesh->_numberOfNodes ; // EF : Pourquoi cet attribut est-il dans MESH et non dans COORDINATE ?
741 // Try to read nodal connectivity of the cells <Connectivity->_nodal>
742 // then try to read descending connectivity <Connectivity->_descending>
743 // if neither nodal nor descending connectivity exists
744 // throw an exception.
745 err = getNodalConnectivity(Connectivity) ;
748 Connectivity->_typeConnectivity = MED_DESCENDING ;
749 err = getDescendingConnectivity(Connectivity) ;
752 getDescendingConnectivity(Connectivity) ; // we read it if there is one
756 delete Connectivity ;
757 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "We could not read " <<
758 "any Connectivity")) ;
761 if (Connectivity->_entityDimension != _ptrMesh->_meshDimension)
762 MESSAGE_MED(LOC << "Small mesh dimension problem on the med file mounted in memory : diim stored " << _ptrMesh->_meshDimension << " dim computed using the connectivity " << Connectivity->_entityDimension);
764 _ptrMesh->_meshDimension = Connectivity->_entityDimension ;
766 // At this point Connectivity->_typeConnectivity is either NODAL or DESCENDING
767 // If both connectivities are found Connectivity->_typeConnectivity is NODAL
768 // If space dimension is 3
769 // try to read the nodal connectivity of the faces <ConnectivityFace->_nodal> then
770 // try to read the descending connectivity <ConnectivityFace->_descending>
771 // if there is no descending connectivity and the CELLS are
772 // defined in descending mode then throw an exception
774 // PROVISOIRE : if we have some face or edge in MED_MAILLE, we don't read more. There could not be have face or edge !!!!
776 if(Connectivity->_constituent==NULL) {
778 SCRUTE_MED(_ptrMesh->_meshDimension);
779 SCRUTE_MED(Connectivity->_entityDimension);
780 if (_ptrMesh->_meshDimension == 3) {
781 MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES FACES..." );
782 CONNECTIVITY * ConnectivityFace = new CONNECTIVITY(MED_EN::MED_FACE) ;
783 ConnectivityFace->_typeConnectivity = Connectivity->_typeConnectivity ; // NODAL or DESCENDING
784 SCRUTE_MED(ConnectivityFace->_typeConnectivity);
785 if (Connectivity->_typeConnectivity == MED_DESCENDING) {
786 MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES FACES" );
787 err = getDescendingConnectivity(ConnectivityFace) ;
789 throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No FACE in descending connectivity")) ;
790 getNodalConnectivity(ConnectivityFace) ; // if any !
792 MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES FACES" );
793 err = getNodalConnectivity(ConnectivityFace) ;
794 if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
795 err = getDescendingConnectivity(ConnectivityFace) ;
797 getDescendingConnectivity(ConnectivityFace); // if any !
799 if (err!=MED_VALID) {
800 delete ConnectivityFace ;
801 MESSAGE_MED(LOC<<"No FACE defined.") ;
803 MESSAGE_MED(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES FACES DANS L'OBJET CONNECTIVITY" );
804 delete Connectivity->_constituent;
805 Connectivity->_constituent=ConnectivityFace;
809 // read MED_EDGE connectivity
810 if (_ptrMesh->_meshDimension > 1) { // we are in 3 or 2D
811 MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES ARRETES...." );
812 CONNECTIVITY * ConnectivityEdge = new CONNECTIVITY(MED_EDGE) ;
813 ConnectivityEdge->_typeConnectivity = Connectivity->_typeConnectivity ;
814 if (Connectivity->_typeConnectivity == MED_DESCENDING) {
815 MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES ARRETES" );
816 err = getDescendingConnectivity(ConnectivityEdge) ;
818 throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No EDGE in descending connectivity")) ;
819 getNodalConnectivity(ConnectivityEdge) ; // if any !
821 MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES ARRETES" );
822 err = getNodalConnectivity(ConnectivityEdge) ;
823 if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
824 err = getDescendingConnectivity(ConnectivityEdge) ;
826 getDescendingConnectivity(ConnectivityEdge) ; // if any !
828 if (err!=MED_VALID) {
829 delete ConnectivityEdge ;
830 MESSAGE_MED(LOC<<"No EDGE defined.") ;
832 if (_ptrMesh->_meshDimension == 3)
833 if (Connectivity->_constituent != NULL)
834 Connectivity->_constituent->_constituent=ConnectivityEdge ;
836 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "EDGE defined but there are no FACE !")) ;
838 MESSAGE_MED(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES ARETES DANS L'OBJET CONNECTIVITY" );
839 Connectivity->_constituent=ConnectivityEdge ;
844 if (_ptrMesh->_connectivity)
845 delete _ptrMesh->_connectivity;
846 _ptrMesh->_connectivity = Connectivity ;
850 // we have read all connectivity in file, now we must build descending connectivity if necessary !
852 // If connectivity descending is defined, we have nothing to do, all constituent are defined !
853 // If connectivity is only nodal, we must rebuild descending if we have some contituent !
856 // if (Connectivity->_descending == NULL)
857 // if (Connectivity->_constituent != NULL){
858 // // update Connectivity->_constituent
859 // CONNECTIVITY * myConstituentOld = Connectivity->_constituent ;
860 // Connectivity->_constituent = (CONNECTIVITY *)NULL ;
861 // Connectivity->calculateDescendingConnectivity() ;
871 int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity)
873 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getNodalConnectivity : " ;
876 if (_status==MED_OPENED)
878 int spaceDimension = _ptrMesh->_spaceDimension;
880 // Get the type of entity to work on (previously set in the Connectivity Object)
881 med_2_3::med_entite_maillage Entity = (med_2_3::med_entite_maillage) Connectivity->getEntity();
883 // Get the number of cells of each type & store it in <tmp_cells_count>.
884 int * tmp_cells_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
886 for (i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)
887 { // EF :ON SCANNE DES GEOMETRIES INUTILES, UTILISER LES MAPS
888 tmp_cells_count[i]=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
889 med_2_3::MED_CONN,(med_2_3::med_entite_maillage) Entity,
890 all_cell_type[i],med_2_3::MED_NOD);
893 // Get the greatest dimension of the cells : Connectivity->_entityDimension
894 // We suppose there is no cells used as faces in MED 2.2.x , this is forbidden !!!
895 // In version prior to 2.2.x, it is possible
896 if (tmp_cells_count[i]>0)
898 Connectivity->_entityDimension=all_cell_type[i]/100;
899 Connectivity->_numberOfTypes++;
904 // VBD fix to be able reading polygons and polyhedrons
905 // "in the case when the space dimension is 3 and the mesh dimension 2"
907 //checking for the number of polygons/polyhedra to get an appropriate mesh dimension
908 int nbpolygons=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
909 med_2_3::MED_CONN,(med_2_3::med_entite_maillage) Entity,
910 med_2_3::MED_POLYGONE,med_2_3::MED_NOD);
913 if (Connectivity->_entityDimension<2)
914 Connectivity->_entityDimension=2;
916 int nbpolyhedra=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
917 med_2_3::MED_CONN,(med_2_3::med_entite_maillage) Entity,
918 med_2_3::MED_POLYEDRE,med_2_3::MED_NOD);
920 Connectivity->_entityDimension=3;
922 //setting a correct mesh dimension as being the dimnsion corresponding to
923 // the highest dimension element
924 if (Entity==med_2_3::MED_MAILLE)
925 _ptrMesh->_meshDimension = Connectivity->_entityDimension;
928 // begin classic geometric types
929 if (Connectivity->_numberOfTypes > 0)
931 // if MED version < 2.2.x, we read only entity with dimention = Connectivity->_entityDimension. Lesser dimension are face or edge !
933 med_2_3::med_int major, minor, release;
935 if ( med_2_3::MEDversionLire(_medIdt, &major, &minor, &release) != 0 )
937 // error : we suppose we have not a good med file !
938 delete[] tmp_cells_count ;
942 // we get MED version number
943 // If MED version is < 2.2 then the cells which dimension
944 // is lesser than the main dimension ( Connectivity->_entityDimension )
945 // are either faces or edges
947 int * tmpEdgeCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
948 tmpEdgeCount[0] = 0 ;
949 int numberOfEdgesTypes = 0;
950 int * tmpFaceCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
951 tmpFaceCount[0] = 0 ;
952 int numberOfFacesTypes = 0;
955 if (Entity==med_2_3::MED_MAILLE)
957 Connectivity->_numberOfTypes=0;
959 for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)
963 if (tmp_cells_count[i]!=0)
965 int dimension = all_cell_type[i]/100 ;
966 if (Connectivity->_entityDimension==dimension)
967 Connectivity->_numberOfTypes++ ;
970 if (Connectivity->_entityDimension==3)
972 tmpFaceCount[i]=tmp_cells_count[i] ;
973 //tmp_cells_count[i]=0 ;
974 //Connectivity->_numberOfTypes++ ;
975 numberOfFacesTypes++;
978 if (Connectivity->_entityDimension>dimension)
980 tmpEdgeCount[i]=tmp_cells_count[i] ;
981 //tmp_cells_count[i]=0;
982 //Connectivity->_numberOfTypes++ ;
983 numberOfEdgesTypes++ ;
989 // bloc to read CELL :
991 // Prepare an array of indexes on the different cell types to create a MEDSKYLINEARRAY
992 // We use <tmp_cells_count> to calculate <Connectivity->_count> then we release it
993 Connectivity->_geometricTypes = new MED_EN::medGeometryElement [Connectivity->_numberOfTypes] ; // Double emploi pour des raisons pratiques
994 Connectivity->_type = new CELLMODEL [Connectivity->_numberOfTypes] ; //
995 if(Connectivity->_count)
996 delete [] Connectivity->_count;
997 Connectivity->_count = new int [Connectivity->_numberOfTypes+1] ;
998 Connectivity->_count[0] = 1;
1003 for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)
1004 { // no point1 cell type (?)
1005 int dimension = all_cell_type[i]/100 ;
1006 if ((tmp_cells_count[i]>0) && (Connectivity->_entityDimension == dimension))
1008 Connectivity->_count[typeNumber]=Connectivity->_count[typeNumber-1]+tmp_cells_count[i];
1010 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1012 Connectivity->_type[typeNumber-1] = t ;
1014 Connectivity->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1016 // probleme avec les mailles de dimension < a dimension du maillage :
1017 // 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 !!!
1020 size+=tmp_cells_count[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1023 << Connectivity->_count[typeNumber]-1 << " cells of type "
1024 << all_cell_type_tab[i] );
1029 // Creation of the MEDSKYLINEARRAY
1030 //Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,size) ;
1031 //int * NodalIndex = Connectivity->_nodal->getIndex() ;
1032 int * NodalValue = new int[size] ;
1033 int * NodalIndex = new int[Connectivity->_count[Connectivity->_numberOfTypes]] ;
1036 // Fill the MEDSKYLINEARRAY by reading the MED file.
1038 for ( i=0;i<Connectivity->_numberOfTypes;i++)
1041 med_2_3::med_geometrie_element med_type = (med_2_3::med_geometrie_element) Connectivity->_type[i].getType() ;
1042 // if ( Connectivity->_type[i].getDimension() < Connectivity->_entityDimension)
1043 // if (Connectivity->_entity == MED_CELL)
1044 // if ( Connectivity->_type[i].getDimension() < _ptrMesh->_spaceDimension)
1047 // int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
1048 int NumberOfNodeByCell = Connectivity->_type[i].getNumberOfNodes() ;
1051 for ( j=Connectivity->_count[i]; j<Connectivity->_count[i+1];j++)
1052 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByCell ;
1054 int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i] ;
1055 //CCRT int * tmp_ConnectivityArray = new int[(NumberOfNodeByCell+multi)*tmp_numberOfCells];
1056 med_2_3::med_int * tmp_ConnectivityArray = new med_2_3::med_int[(NumberOfNodeByCell+multi)*tmp_numberOfCells];
1057 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1058 spaceDimension,tmp_ConnectivityArray,
1059 med_2_3::MED_FULL_INTERLACE,NULL,0,Entity,med_type,med_2_3::MED_NOD);
1061 if ( err != MED_VALID)
1063 delete[] tmp_ConnectivityArray;
1064 delete[] tmp_cells_count;
1065 delete[] tmpFaceCount;
1066 delete[] tmpEdgeCount;
1067 MESSAGE_MED(LOC<<": MEDconnLire returns "<<err) ;
1071 int * ConnectivityArray = NodalValue + NodalIndex[Connectivity->_count[i]-1]-1 ;
1073 // version originale sans prise en compte des numéros optionnels
1075 for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
1076 ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
1078 //////////////////////////////////////////////////////////////////////////////
1079 // Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1080 //////////////////////////////////////////////////////////////////////////////
1082 // Rénumérote le tableau temporaire tmp_ConnectivityArray en utilisant _optionnalToCanonicNodesNumbers
1083 // Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1085 // if (_ptrMesh->_arePresentOptionnalNodesNumbers==1)
1087 // for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
1088 // ConnectivityArray[j*NumberOfNodeByCell+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k]] ;
1092 // for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
1093 // ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
1095 ////////////////////////////////////////////////////////////////////////////
1097 delete[] tmp_ConnectivityArray;
1101 Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,
1106 delete[] NodalIndex;
1107 delete[] NodalValue;
1109 } // end of bloc to read CELL
1115 if (numberOfFacesTypes!=0)
1118 // Create a CONNECTIVITY constituent to put in the top level CONNECTIVITY recursive class
1119 CONNECTIVITY * constituent = new CONNECTIVITY(numberOfFacesTypes,MED_EN::MED_FACE) ;
1120 constituent->_entityDimension = 2 ;
1121 constituent->_count[0]=1 ;
1123 // In order to create the MEDSKYLINEARRAY of the constituent object we need :
1125 // To initialize the _count array of the constituent object (containning cumulated face count by geometric type)
1126 // _count[0]=1 and _count[_numberOfTypes] give the size of NodalIndex
1128 // To calculate the total number of face nodes whatever the geometric type is.
1129 // The result is the size of the array containning all the nodes : NodalValue
1131 // To calculate the starting indexes of the different face types in NodalValue,
1132 // this is the NodalIndex array.
1135 int typeNumber = 1 ;
1137 for ( i=1; i < MED_NBR_GEOMETRIE_MAILLE; i++)
1138 { // no point1 cell type (?)
1139 if (tmpFaceCount[i]>0)
1141 constituent->_count[typeNumber] = constituent->_count[typeNumber-1] + tmpFaceCount[i];
1142 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1143 constituent->_type[typeNumber-1]=t ;
1145 constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1147 size+=tmpFaceCount[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1152 // Creation of the MEDSKYLINEARRAY
1153 //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ;
1154 //int * NodalIndex = constituent->_nodal->getIndex() ;
1155 int * NodalValue = new int[size] ;
1156 int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
1159 // Fill the MEDSKYLINEARRAY by reading the MED file.
1160 for ( i=0; i<constituent->_numberOfTypes; i++)
1162 med_2_3::med_geometrie_element med_type = (med_2_3::med_geometrie_element) constituent->_type[i].getType() ;
1164 int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes() ;
1166 // initialise NodalIndex
1167 for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
1168 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByFace ;
1170 int tmp_numberOfFaces = constituent->_count[i+1]-constituent->_count[i] ;
1171 // Il faut ajouter 1 pour le zero a la lecture !!!
1172 // ATTENTION UNIQUEMENT POUR MED < 2.2.x
1173 //CCRT int * tmp_constituentArray = NULL;
1174 med_2_3::med_int * tmp_constituentArray = NULL;
1176 MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
1178 if ((major == 2) && (minor <= 1))
1179 //CCRT tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ;
1180 tmp_constituentArray = new med_2_3::med_int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ;
1181 else if ((major == 2) && (minor >= 2))
1183 //CCRT tmp_constituentArray = new int[NumberOfNodeByFace*tmp_numberOfFaces] ;
1184 tmp_constituentArray = new med_2_3::med_int[NumberOfNodeByFace*tmp_numberOfFaces] ;
1185 MESSAGE_MED(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ;
1188 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1189 Connectivity->_entityDimension,tmp_constituentArray,
1190 med_2_3::MED_FULL_INTERLACE,NULL,0,med_2_3::MED_MAILLE,med_type,med_2_3::MED_NOD);
1192 if ( err != MED_VALID)
1194 MESSAGE_MED(LOC<<": MEDconnLire returns "<<err) ;
1195 delete constituent ;
1196 delete[] tmp_constituentArray;
1197 delete[] tmpFaceCount;
1198 delete[] tmpEdgeCount;
1202 int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
1204 // version originale sans prise en compte des numéros optionnels
1206 int multi = 0; // quand est-ce que multi vaut 1 ?? en MED-fichier < 2.2 ??
1207 MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
1209 if ((major == 2) && (minor <= 1))
1210 for (int j=0; j<tmp_numberOfFaces; j++)
1211 for (int k=0; k<NumberOfNodeByFace; k++)
1212 constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
1213 else if ((major == 2) && (minor >= 2))
1214 for (int j=0; j<tmp_numberOfFaces; j++)
1215 for (int k=0; k<NumberOfNodeByFace; k++)
1216 constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+multi)+k] ;
1218 //////////////////////////////////////////////////////////////////////////////////////
1219 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1220 //////////////////////////////////////////////////////////////////////////////////////
1222 /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
1223 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1225 // if (_ptrMesh->_arePresentOptionnalNodesNumbers)
1227 // for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
1228 // constituentArray[j*NumberOfNodeByFace+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByFace+1)+k]] ;
1232 // for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
1233 // constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
1236 //////////////////////////////////////////////////////////////////////////////////////
1238 delete[] tmp_constituentArray;
1241 constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1245 delete[] NodalIndex ;
1246 delete[] NodalValue ;
1249 Connectivity->_constituent = constituent ;
1252 delete[] tmpFaceCount;
1257 if (numberOfEdgesTypes!=0)
1259 CONNECTIVITY * constituent = new CONNECTIVITY(numberOfEdgesTypes,MED_EDGE) ;
1260 constituent->_entityDimension = 1 ;
1261 constituent->_count[0]=1 ;
1265 // if you declare a variable <i> in two <for> initialization statement,
1266 // compiler gcc2.95.3 says nothing but there are two <i> variables in the same block
1267 //and the value you get in the common block seems to be the value of the first variable !
1270 for ( i=1; i<MED_NBR_GEOMETRIE_MAILLE; i++)
1271 { // no point1 cell type (?)
1272 if (tmpEdgeCount[i]>0)
1275 constituent->_count[typeNumber]=constituent->_count[typeNumber-1]+tmpEdgeCount[i];
1276 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1277 constituent->_type[typeNumber-1]=t ;
1279 constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1281 size+=tmpEdgeCount[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1286 // Creation of the MEDSKYLINEARRAY
1287 //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ;
1288 //int * NodalIndex = constituent->_nodal->getIndex() ;
1289 int * NodalValue = new int[size] ;
1290 int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
1293 // Fill the MEDSKYLINEARRAY by reading the MED file.
1294 for ( i=0; i<constituent->_numberOfTypes; i++)
1296 med_2_3::med_geometrie_element med_type = (med_2_3::med_geometrie_element) constituent->_type[i].getType() ;
1298 int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes() ;
1301 for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
1302 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByEdge ;
1304 int tmp_numberOfEdges = constituent->_count[i+1]-constituent->_count[i] ;
1305 // Il faut ajouter 1 pour le zero a la lecture !!!
1307 // ATTENTION UNIQUEMENT POUR MED < 2.2.x
1308 //CCRT int * tmp_constituentArray = NULL;
1309 med_2_3::med_int * tmp_constituentArray = NULL;
1311 MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
1313 if ((major == 2) && (minor <= 1))
1314 //CCRT tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ;
1315 tmp_constituentArray = new med_2_3::med_int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ;
1316 else if ((major == 2) && (minor >= 2))
1318 //CCRT tmp_constituentArray = new int[NumberOfNodeByEdge*tmp_numberOfEdges] ;
1319 tmp_constituentArray = new med_2_3::med_int[NumberOfNodeByEdge*tmp_numberOfEdges] ;
1320 MESSAGE_MED(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ;
1323 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1324 spaceDimension,tmp_constituentArray,
1325 med_2_3::MED_FULL_INTERLACE,NULL,0,med_2_3::MED_MAILLE,med_type,med_2_3::MED_NOD);
1326 if ( err != MED_VALID)
1328 MESSAGE_MED(LOC<<": MEDconnLire returns "<<err) ;
1329 delete constituent ;
1330 delete[] tmp_constituentArray;
1331 delete[] tmpEdgeCount;
1335 int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
1337 // version originale sans prise en compte des numéros optionnels
1339 int multi = 0; // quand est-ce que multi vaut 1 ?? en MED-fichier < 2.2 ??
1340 MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
1342 if ((major == 2) && (minor <= 1))
1343 for (int j=0; j<tmp_numberOfEdges; j++)
1344 for (int k=0; k<NumberOfNodeByEdge; k++)
1345 constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+multi)+k] ;
1346 else if ((major == 2) && (minor >= 2))
1347 for (int j=0; j<tmp_numberOfEdges; j++)
1348 for (int k=0; k<NumberOfNodeByEdge; k++)
1349 constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge)+k] ;
1351 //////////////////////////////////////////////////////////////////////////////////////
1352 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1353 //////////////////////////////////////////////////////////////////////////////////////
1355 /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
1356 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1358 // if (_ptrMesh->_arePresentOptionnalNodesNumbers)
1360 // for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1361 // constituentArray[j*NumberOfNodeByEdge+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k]] ;
1365 // for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1366 // constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k] ;
1369 //////////////////////////////////////////////////////////////////////////////////////
1371 delete[] tmp_constituentArray;
1374 constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1379 delete[] NodalIndex ;
1380 delete[] NodalValue ;
1382 if (Connectivity->_entityDimension == 3)
1384 if (Connectivity->_constituent==NULL)
1385 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Edges are defined but there are no Faces !"));
1386 Connectivity->_constituent->_constituent = constituent ;
1388 Connectivity->_constituent = constituent ;
1391 delete[] tmpEdgeCount;
1394 } // end classic geometric types
1396 {//Polyg/Polh only...
1397 delete [] Connectivity->_count;
1398 Connectivity->_count=new int[1];
1399 Connectivity->_count[0]=1;
1401 delete[] tmp_cells_count;
1403 int NumberOfPolygons = MEDnEntMaa(_medIdt,
1404 const_cast <char *> (_ptrMesh->_name.c_str()),
1406 med_2_3::MED_MAILLE,
1407 med_2_3::MED_POLYGONE,
1410 // Correction to permit the loading of mesh dimensionned at 2 even
1411 // if it has only MED_POLYGON elements
1413 if (NumberOfPolygons > 0)
1415 if (Connectivity->_entityDimension < 2) Connectivity->_entityDimension = 2;
1418 if (NumberOfPolygons > 0)
1420 // By consequence this exception will never occur
1421 if (Connectivity->_entityDimension == 1)
1422 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 2D mesh, polygons need at least one 2D cell of a classic geometric type !"));
1423 med_2_3::med_int ConnectivitySize;
1424 med_2_3::med_err err1 = MEDpolygoneInfo(_medIdt,
1425 const_cast <char *> (_ptrMesh->_name.c_str()),
1426 med_2_3::MED_MAILLE,
1429 if (err1 != MED_VALID)
1431 MESSAGE_MED(LOC<<": MEDpolygoneInfo returns "<<err1);
1435 med_2_3::med_int* PolygonsConnectivity = new med_2_3::med_int[ConnectivitySize];
1436 med_2_3::med_int* PolygonsConnectivityIndex = new med_2_3::med_int[NumberOfPolygons+1];
1438 med_2_3::med_err err2 = MEDpolygoneConnLire(_medIdt,
1439 const_cast <char *> (_ptrMesh->_name.c_str()),
1440 PolygonsConnectivityIndex,
1442 PolygonsConnectivity,
1443 med_2_3::MED_MAILLE,
1445 if (err2 != MED_VALID)
1447 MESSAGE_MED(LOC<<": MEDpolygoneConnLire returns "<<err2);
1451 if (Connectivity->_entityDimension == 2) // 2D mesh : polygons in Connectivity
1454 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1455 int* tmp_PolygonsConnectivity = new int[ConnectivitySize];
1457 for ( i = 0 ; i < ConnectivitySize ; i++ )
1458 tmp_PolygonsConnectivity[i] = PolygonsConnectivity[i] ;
1460 int* tmp_PolygonsConnectivityIndex = new int[NumberOfPolygons+1];
1461 for ( i = 0 ; i < NumberOfPolygons+1 ; i++ )
1462 tmp_PolygonsConnectivityIndex[i] = PolygonsConnectivityIndex[i] ;
1464 Connectivity->setPolygonsConnectivity
1465 (MED_NODAL, (medEntityMesh) Entity, tmp_PolygonsConnectivity,
1466 tmp_PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons);
1468 delete [] tmp_PolygonsConnectivity ;
1469 delete [] tmp_PolygonsConnectivityIndex ;
1471 Connectivity->setPolygonsConnectivity
1472 (MED_NODAL, (medEntityMesh) Entity, PolygonsConnectivity,
1473 PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons);
1476 else if (Connectivity->_entityDimension == 3)
1478 if (Connectivity->_constituent == NULL) // 3D mesh : polygons in Connectivity->_constituent
1479 Connectivity->_constituent = new CONNECTIVITY(MED_FACE);
1481 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1482 int* tmp_PolygonsConnectivity = new int[ConnectivitySize];
1484 for ( i = 0 ; i < ConnectivitySize ; i++ )
1485 tmp_PolygonsConnectivity[i] = PolygonsConnectivity[i] ;
1487 int* tmp_PolygonsConnectivityIndex = new int[NumberOfPolygons+1];
1488 for ( i = 0 ; i < NumberOfPolygons+1 ; i++ )
1489 tmp_PolygonsConnectivityIndex[i] = PolygonsConnectivityIndex[i] ;
1491 Connectivity->_constituent->setPolygonsConnectivity
1492 (MED_NODAL, MED_FACE, tmp_PolygonsConnectivity,
1493 tmp_PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons);
1495 delete [] tmp_PolygonsConnectivity ;
1496 delete [] tmp_PolygonsConnectivityIndex ;
1498 Connectivity->_constituent->setPolygonsConnectivity
1499 (MED_NODAL, MED_FACE, PolygonsConnectivity,
1500 PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons);
1504 delete[] PolygonsConnectivity;
1505 delete[] PolygonsConnectivityIndex;
1509 // Lecture des polyedres MED_CELL
1510 med_int NumberOfPolyhedron = MEDnEntMaa(_medIdt,
1511 const_cast <char *> (_ptrMesh->_name.c_str()),
1514 med_2_3::MED_POLYEDRE,
1517 // Correction to permit the loading of mesh dimensionned at 3 even
1518 // if it has only MED_POLYEDRE elements
1520 if (NumberOfPolyhedron > 0)
1522 Connectivity->_entityDimension = 3;
1525 if (NumberOfPolyhedron > 0)
1527 // By consequence this exception will never occur
1528 if (Connectivity->_entityDimension == 2 || Connectivity->_entityDimension == 1)
1529 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 3D mesh, polyhedron need at least one 3D cell of a classic geometric type !"));
1530 med_2_3::med_int FacesIndexSize, NumberOfNodes, NumberOfFaces;
1531 med_2_3::med_err err3 = MEDpolyedreInfo(_medIdt,
1532 const_cast <char *> (_ptrMesh->_name.c_str()),
1536 NumberOfFaces = FacesIndexSize-1;
1537 if (err3 != MED_VALID)
1539 MESSAGE_MED(LOC<<": MEDpolyhedreInfo returns "<<err3);
1543 med_2_3::med_int* Nodes = new med_2_3::med_int[NumberOfNodes];
1544 med_2_3::med_int* FacesIndex = new med_2_3::med_int[NumberOfFaces+1];
1545 med_2_3::med_int* PolyhedronIndex = new med_2_3::med_int[NumberOfPolyhedron+1];
1547 med_2_3::med_err err4 = MEDpolyedreConnLire(_medIdt,
1548 const_cast <char *> (_ptrMesh->_name.c_str()),
1550 NumberOfPolyhedron+1,
1555 if (err4 != MED_VALID)
1557 MESSAGE_MED(LOC<<": MEDpolyedreConnLire returns "<<err4);
1562 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1563 int* tmp_Nodes = new int[NumberOfNodes];
1565 for ( i = 0 ; i < NumberOfNodes ; i++ )
1566 tmp_Nodes[i] = Nodes[i] ;
1567 int* tmp_FacesIndex = new int[NumberOfFaces+1];
1568 for ( i = 0 ; i < NumberOfFaces+1 ; i++ )
1569 tmp_FacesIndex[i] = FacesIndex[i] ;
1570 int* tmp_PolyhedronIndex = new int[NumberOfPolyhedron+1];
1571 for ( i = 0 ; i < NumberOfPolyhedron+1 ; i++ )
1572 tmp_PolyhedronIndex[i] = PolyhedronIndex[i] ;
1573 Connectivity->setPolyhedronConnectivity(MED_NODAL,tmp_Nodes,tmp_PolyhedronIndex,NumberOfNodes,NumberOfPolyhedron,tmp_FacesIndex,NumberOfFaces);
1575 delete[] tmp_FacesIndex;
1576 delete[] tmp_PolyhedronIndex;
1578 Connectivity->setPolyhedronConnectivity(MED_NODAL,Nodes,PolyhedronIndex,NumberOfNodes,NumberOfPolyhedron,FacesIndex,NumberOfFaces);
1582 delete[] FacesIndex;
1583 delete[] PolyhedronIndex;
1588 // If there is no nodal connectivity, we return MED_ERROR !
1589 if (Connectivity->_numberOfTypes == 0 && NumberOfPolygons == 0 && NumberOfPolyhedron == 0)
1598 int MED_MESH_RDONLY_DRIVER22::getFAMILY()
1600 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getFAMILY() : " ;
1603 if (_status==MED_OPENED)
1607 int * MEDArrayNodeFamily = NULL ;
1608 int ** MEDArrayCellFamily = NULL ;
1609 int ** MEDArrayFaceFamily = NULL ;
1610 int ** MEDArrayEdgeFamily = NULL ;
1613 MEDArrayNodeFamily = new int[_ptrMesh->getNumberOfNodes()] ;
1615 err = getNodesFamiliesNumber(MEDArrayNodeFamily) ;
1616 // error only if (_status!=MED_OPENED), other case exeception !
1619 MESSAGE_MED(LOC << "error returned from getNodesFamiliesNumber " << err);
1621 MEDArrayCellFamily = new int* [_ptrMesh->getNumberOfTypesWithPoly(MED_CELL)] ;
1622 // ET SI IL N'Y A PAS DE CELLS ?
1624 medGeometryElement * myTypes = _ptrMesh->getTypesWithPoly(MED_CELL);
1625 for (int i=0;i<_ptrMesh->getNumberOfTypesWithPoly(MED_CELL);i++)
1626 MEDArrayCellFamily[i] = new
1627 int[_ptrMesh->getNumberOfElementsWithPoly(MED_CELL,myTypes[i])] ;
1629 // assure connectivety exists in case of GRID
1630 _ptrMesh->getConnectivityptr(); //PAL14113
1632 err = getCellsFamiliesNumber(MEDArrayCellFamily,
1633 _ptrMesh->_connectivity,MED_CELL) ;
1636 MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Cells " << err);
1638 if (_ptrMesh->_connectivity->_constituent != NULL)
1640 if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE)
1643 MEDArrayFaceFamily = new
1644 int* [_ptrMesh->getNumberOfTypesWithPoly(MED_FACE)] ;
1646 myTypes = _ptrMesh->getTypesWithPoly(MED_FACE);
1647 for (int i=0;i<_ptrMesh->getNumberOfTypesWithPoly(MED_FACE);i++) {
1648 int nbOfElements = _ptrMesh->_connectivity->_constituent->getNumberOfElementsWithPoly(MED_FACE,myTypes[i]);
1649 MEDArrayFaceFamily[i] = new int[nbOfElements];
1653 getCellsFamiliesNumber(MEDArrayFaceFamily,
1654 _ptrMesh->_connectivity->_constituent,MED_FACE) ;
1656 MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Faces " << err);
1661 MEDArrayEdgeFamily = new
1662 int* [_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1664 const medGeometryElement *myTypes2 = _ptrMesh->getTypes(MED_EDGE);
1665 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1666 MEDArrayEdgeFamily[i] = new
1667 int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes2[i])] ;
1670 getCellsFamiliesNumber(MEDArrayEdgeFamily,
1671 _ptrMesh->_connectivity->_constituent,MED_EDGE) ;
1673 MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Edges in 2D " << err);
1676 if (_ptrMesh->_connectivity->_constituent->_constituent != NULL)
1678 MEDArrayEdgeFamily = new
1679 int* [_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1681 const medGeometryElement *myTypes2 = _ptrMesh->getTypes(MED_EDGE);
1682 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++) {
1683 int nbOfElements = _ptrMesh->_connectivity->_constituent->_constituent->getNumberOfElementsWithPoly(MED_EDGE,myTypes2[i]);
1684 MEDArrayEdgeFamily[i] = new int[nbOfElements] ;
1688 getCellsFamiliesNumber(MEDArrayEdgeFamily,
1689 _ptrMesh->_connectivity->_constituent->_constituent,MED_EDGE);
1692 MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Edges in 3D " << err);
1697 int NumberOfFamilies = med_2_3::MEDnFam(_medIdt, const_cast <char *>
1698 (_meshName.c_str())) ;
1700 if ( NumberOfFamilies < 1 ) // at least family 0 must exist
1701 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"There is no FAMILY, FAMILY 0 must exists" ));
1703 SCRUTE_MED(NumberOfFamilies);
1705 vector<FAMILY*> &NodeFamilyVector = _ptrMesh->_familyNode ;
1706 vector<FAMILY*> &CellFamilyVector = _ptrMesh->_familyCell ;
1707 vector<FAMILY*> &FaceFamilyVector = _ptrMesh->_familyFace ;
1708 vector<FAMILY*> &EdgeFamilyVector = _ptrMesh->_familyEdge ;
1710 int numberOfNodesFamilies = 0 ;
1711 int numberOfCellsFamilies = 0 ;
1712 int numberOfFacesFamilies = 0 ;
1713 int numberOfEdgesFamilies = 0 ;
1715 for (int i=0;i<NumberOfFamilies;i++)
1717 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1718 med_2_3::med_int tmp_NumberOfAttributes = med_2_3::MEDnAttribut(_medIdt,
1719 const_cast <char *>(_meshName.c_str()),
1721 med_2_3::med_int NumberOfAttributes = tmp_NumberOfAttributes ;
1723 int NumberOfAttributes = med_2_3::MEDnAttribut(_medIdt,
1725 (_meshName.c_str()),
1729 if (NumberOfAttributes < 0)
1730 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : NumberOfAttributes" );
1732 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1733 med_2_3::med_int tmp_NumberOfGroups = med_2_3::MEDnGroupe(_medIdt,
1734 const_cast <char *>(_meshName.c_str()),
1736 int NumberOfGroups = tmp_NumberOfGroups ;
1738 int NumberOfGroups = med_2_3::MEDnGroupe(_medIdt,
1739 const_cast <char *>(_meshName.c_str()),
1743 if (NumberOfGroups < 0)
1744 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : NumberOfGroups" );
1746 int FamilyIdentifier ;
1747 string FamilyName(MED_TAILLE_NOM,'\0');
1748 // 0020071: Crash of V4_1_4rc2 (of testMedMemGeneral.py)
1749 // Pb with Mistrat_import22.med: it's zero family has non-empty AttributesIdentifier's and
1750 // AttributesValues' but MEDnAttribut() returns 0 (0 is hardcoded for zero family).
1751 // So we allocate nothing but MEDfamInfo() reads file contents so overwritting
1752 // stranger's memory. Stupid solution: allocate more than MEDnAttribut()
1753 const int iSafe = 10;
1754 int * AttributesIdentifier = new int[NumberOfAttributes+iSafe] ;
1755 int * AttributesValues = new int[NumberOfAttributes+iSafe] ;
1756 string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ;
1757 string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups+1,'\0') ;
1758 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1759 med_2_3::med_int tmp_FamilyIdentifier ;
1760 med_2_3::med_int * tmp_AttributesIdentifier = new med_2_3::med_int[NumberOfAttributes+iSafe] ;
1761 med_2_3::med_int * tmp_AttributesValues = new med_2_3::med_int[NumberOfAttributes+iSafe] ;
1762 err = med_2_3::MEDfamInfo(_medIdt,
1763 const_cast <char *>(_meshName.c_str()),
1765 const_cast <char *>(FamilyName.c_str()),
1766 &tmp_FamilyIdentifier,
1767 tmp_AttributesIdentifier,
1768 tmp_AttributesValues,
1769 const_cast <char *>(AttributesDescription.c_str()),
1770 &tmp_NumberOfAttributes,
1771 const_cast <char *>(GroupsNames.c_str()),
1772 &tmp_NumberOfGroups);
1773 FamilyIdentifier = tmp_FamilyIdentifier ;
1775 for ( ii = 0 ; ii < NumberOfAttributes ; ii++ ) {
1776 AttributesIdentifier[ii] = tmp_AttributesIdentifier[ii] ;
1777 AttributesValues[ii] = tmp_AttributesValues[ii] ;
1779 NumberOfAttributes = tmp_NumberOfAttributes ;
1780 NumberOfGroups = tmp_NumberOfGroups ;
1781 delete [] tmp_AttributesIdentifier ;
1782 delete [] tmp_AttributesValues ;
1784 err = med_2_3::MEDfamInfo(_medIdt,const_cast <char *>
1785 (_meshName.c_str()),
1786 (i+1),const_cast <char *>
1787 (FamilyName.c_str()), &FamilyIdentifier,
1788 AttributesIdentifier,AttributesValues,
1790 (AttributesDescription.c_str()),
1791 &NumberOfAttributes, const_cast <char *>
1792 (GroupsNames.c_str()),&NumberOfGroups);
1796 SCRUTE_MED(GroupsNames);
1797 SCRUTE_MED(FamilyName);
1801 if (err != MED_VALID)
1802 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : ERROR when get FAMILY informations" );
1804 if (FamilyIdentifier != 0 )
1806 FAMILY * Family = new FAMILY(_ptrMesh,FamilyIdentifier,FamilyName,
1808 AttributesIdentifier,
1810 AttributesDescription,
1811 NumberOfGroups,GroupsNames,
1815 MEDArrayEdgeFamily) ;
1818 // if nothing found, delete Family
1820 /*! \todo TODO : once unit tests are ready, check that there is no side effect
1821 and let the driver read empty families by removing the if case of the
1822 few following lines */
1824 if (Family->getNumberOfTypes() == 0)
1826 MESSAGE_MED(LOC<<"Nothing found for family "<<FamilyName<<
1831 switch (Family->getEntity())
1833 case MED_EN::MED_NODE :
1834 NodeFamilyVector.push_back(Family) ;
1835 numberOfNodesFamilies++ ;
1837 case MED_EN::MED_CELL :
1838 CellFamilyVector.push_back(Family) ;
1839 numberOfCellsFamilies++ ;
1841 case MED_EN::MED_FACE :
1842 FaceFamilyVector.push_back(Family) ;
1843 numberOfFacesFamilies++ ;
1845 case MED_EN::MED_EDGE :
1846 EdgeFamilyVector.push_back(Family) ;
1847 numberOfEdgesFamilies++ ;
1850 // MESSAGE_MED(LOC << (*Family));
1853 delete [] AttributesIdentifier ;
1854 delete [] AttributesValues ;
1857 if (MEDArrayNodeFamily != NULL)
1858 delete[] MEDArrayNodeFamily ;
1860 if (MEDArrayCellFamily != NULL)
1862 for (int i=0; i<_ptrMesh->getNumberOfTypesWithPoly(MED_CELL); i++)
1863 delete[] MEDArrayCellFamily[i] ;
1864 delete[] MEDArrayCellFamily ;
1867 if (MEDArrayFaceFamily != NULL)
1869 for (int i=0; i<_ptrMesh->getNumberOfTypesWithPoly(MED_FACE); i++)
1870 delete[] MEDArrayFaceFamily[i] ;
1871 delete[] MEDArrayFaceFamily ;
1874 if (MEDArrayEdgeFamily != NULL)
1876 for (int i=0; i<_ptrMesh->getNumberOfTypesWithPoly(MED_EDGE); i++)
1877 delete[] MEDArrayEdgeFamily[i] ;
1878 delete[] MEDArrayEdgeFamily ;
1888 int MED_MESH_RDONLY_DRIVER22::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
1890 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getNodesFamiliesNumber() : " ;
1894 if (_status==MED_OPENED)
1898 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1899 med_2_3::med_int * tmp_MEDArrayNodeFamily = new med_2_3::med_int[_ptrMesh->getNumberOfNodes()] ;
1900 err = MEDfamLire(_medIdt, const_cast <char *>
1901 (_ptrMesh->_name.c_str()), tmp_MEDArrayNodeFamily,
1902 _ptrMesh->getNumberOfNodes(), med_2_3::MED_NOEUD,
1903 (med_2_3::med_geometrie_element) MED_NONE);
1905 for ( i = 0 ; i < _ptrMesh->getNumberOfNodes() ; i++ )
1906 MEDArrayNodeFamily[i] = tmp_MEDArrayNodeFamily[i] ;
1908 err = MEDfamLire(_medIdt, const_cast <char *>
1909 (_ptrMesh->_name.c_str()), MEDArrayNodeFamily,
1910 _ptrMesh->getNumberOfNodes(), med_2_3::MED_NOEUD,
1911 (med_2_3::med_geometrie_element) MED_NONE);
1914 if ( err != MED_VALID)
1915 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "There is no family for the |"<< _ptrMesh->getNumberOfNodes() << "| nodes in mesh |" << _ptrMesh->_name.c_str() << "|"));
1924 int MED_MESH_RDONLY_DRIVER22::getCellsFamiliesNumber(int **MEDArrayFamily,
1925 CONNECTIVITY *Connectivity,
1926 MED_EN::medEntityMesh entity)
1928 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCellsFamiliesNumber " ;
1932 if (_status==MED_OPENED)
1935 MED_EN::medGeometryElement *types=Connectivity->getGeometricTypesWithPoly(Connectivity->_entity);
1936 for (i=0;i<Connectivity->getNumberOfTypesWithPoly(Connectivity->_entity);i++)
1938 int NumberOfCell=Connectivity->getNumberOfElementsWithPoly(Connectivity->_entity,types[i]);
1939 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1940 med_2_3::med_int * tmp_MEDArrayFamily = new med_2_3::med_int[NumberOfCell] ;
1941 err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1942 tmp_MEDArrayFamily,NumberOfCell,
1943 (med_2_3::med_entite_maillage) Connectivity->_entity,
1944 (med_2_3::med_geometrie_element)types[i]);
1945 if (err != MED_VALID
1946 && !_ptrMesh->getIsAGrid()) // it's normal for a grid (PAL14113)
1948 err=MEDfamLire(_medIdt,const_cast <char *>
1949 (_ptrMesh->_name.c_str()),
1950 tmp_MEDArrayFamily,NumberOfCell,
1951 med_2_3::MED_MAILLE,
1952 (med_2_3::med_geometrie_element)types[i]);
1953 if (err != MED_VALID )
1954 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<types[i]));
1956 if (err == MED_VALID) {
1958 for ( ii = 0 ; ii < NumberOfCell ; ii++ )
1959 MEDArrayFamily[i][ii] = tmp_MEDArrayFamily[ii] ;
1961 delete [] tmp_MEDArrayFamily ;
1963 err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1964 MEDArrayFamily[i],NumberOfCell,
1965 (med_2_3::med_entite_maillage) Connectivity->_entity,
1966 (med_2_3::med_geometrie_element)types[i]);
1967 if (err != MED_VALID
1968 && !_ptrMesh->getIsAGrid() ) // it's normal for a grid (PAL14113)
1970 err=MEDfamLire(_medIdt,const_cast <char *>
1971 (_ptrMesh->_name.c_str()),
1972 MEDArrayFamily[i],NumberOfCell,
1973 med_2_3::MED_MAILLE,
1974 (med_2_3::med_geometrie_element)types[i]);
1975 if (err != MED_VALID)
1976 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<types[i]));
1981 return err ? MED_INVALID : MED_VALID;
1986 /*--------------------- WRONLY PART -------------------------------*/
1988 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22()
1990 this->GENDRIVER::_accessMode = MED_EN::WRONLY;
1993 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName,
1995 MED_EN::med_mode_acces access):
1996 MED_MESH_DRIVER22(fileName,ptrMesh,access),IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,access)
1998 MESSAGE_MED("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
2001 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const MED_MESH_WRONLY_DRIVER22 & driver):
2002 IMED_MESH_WRONLY_DRIVER(driver),MED_MESH_DRIVER22(driver),MED_MESH_DRIVER(driver)
2007 MED_MESH_WRONLY_DRIVER22::~MED_MESH_WRONLY_DRIVER22()
2009 //MESSAGE_MED("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed");
2013 GENDRIVER * MED_MESH_WRONLY_DRIVER22::copy(void) const
2015 return new MED_MESH_WRONLY_DRIVER22(*this);
2018 void MED_MESH_WRONLY_DRIVER22::write(void) const
2021 if (_ptrMesh==NULL || _ptrMesh->getCoordinateptr()==NULL)
2022 throw MEDEXCEPTION("Error trying to write an empty mesh");
2024 const char * LOC = "void MED_MESH_WRONLY_DRIVER22::write(void) const : ";
2027 // we must first create mesh !!
2028 MESSAGE_MED(LOC << "MeshName : |" << _meshName << "| FileName : |"<<_fileName<<"| MedIdt : | "<< _medIdt << "|");
2030 if (_status!=MED_OPENED)
2031 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "File "<<_fileName<<" is not open. Open it before write !"));
2035 if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() ) )
2036 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
2037 <<" neither <meshName> is set in driver nor in object MESH.")) ;
2039 // If _meshName is not set in driver, try to use _ptrmesh->_meshName
2040 if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() ) )
2041 _meshName = healName(_ptrMesh->_name );
2043 if ( _meshName.size() > MED_TAILLE_NOM )
2044 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
2045 <<" <meshName> size in object driver MESH is > MED_TAILLE_NOM ."));
2048 if (_ptrMesh->getIsAGrid())
2050 if ( writeGRID() != MED_VALID )
2051 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeGRID()" )) ;
2055 if (writeCoordinates()!=MED_VALID)
2056 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()" )) ;
2058 if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID)
2059 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)" )) ;
2060 if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID)
2061 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)" )) ;
2062 if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID)
2063 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)" )) ;
2066 if (writeFamilyNumbers() !=MED_VALID)
2067 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilyNumbers()" )) ;
2070 // well we must first write zero family :
2071 if (_status==MED_OPENED) {
2073 // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
2074 string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_ZERO/";
2075 MESSAGE_MED("|"<<dataGroupFam<<"|");
2076 err =med_2_3::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) );
2077 if ( err < MED_VALID ) {
2080 char familyName[MED_TAILLE_NOM+1];
2081 // strcpy(familyName,"FAMILLE_ZERO");
2082 err = med_2_3::MEDfamCr( _medIdt,
2083 const_cast <char *> ( _meshName.c_str() ),
2085 //CCRT (int*)NULL, (int*)NULL, (char*)NULL, 0,
2086 (med_2_3::med_int*)NULL, (med_2_3::med_int*)NULL, (char*)NULL, 0,
2089 SCRUTE_MED(familyName);
2091 if ( err != MED_VALID)
2092 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_ZERO| with identifier |0| groups names || and attributes descriptions ||")) ;
2095 med_2_3::_MEDdatagroupFermer(_medIdt);
2099 MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyNode)");
2100 if (writeFamilies(_ptrMesh->_familyNode) !=MED_VALID)
2101 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyNode)" )) ;
2103 MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyCell)");
2104 if (writeFamilies(_ptrMesh->_familyCell) !=MED_VALID)
2105 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyCell)" )) ;
2107 MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyFace)");
2108 if (writeFamilies(_ptrMesh->_familyFace) !=MED_VALID)
2109 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyFace)" )) ;
2111 MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyEdge)");
2112 if (writeFamilies(_ptrMesh->_familyEdge) !=MED_VALID)
2113 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyEdge)" )) ;
2118 //=======================================================================
2119 //function : writeGRID
2121 //=======================================================================
2123 int MED_MESH_WRONLY_DRIVER22::writeGRID() const
2125 const char * LOC = "MED_MESH_WRONLY_DRIVER22::writeGRID() : " ;
2128 if (_status!=MED_OPENED)
2130 MESSAGE_MED (LOC<<" Not open !!!");
2133 GRID * ptrGrid = (GRID*) _ptrMesh;
2135 med_2_3::med_err err = MED_ERROR;
2136 med_2_3::med_repere rep;
2137 string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2138 string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2140 // Test if the mesh <_meshName> already exists
2141 // If it doesn't exists create it
2142 // If it already exists verify if its space and mesh dimensions are the same
2143 // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively
2144 // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
2146 int spaceDimension = med_2_3::MEDdimEspaceLire(_medIdt, const_cast <char *>
2147 (_meshName.c_str()) );
2149 int meshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *>
2150 (_meshName.c_str()) );
2153 MESSAGE_MED(LOC << "spacedim " << spaceDimension << " meshdim " << meshDimension);
2155 MESSAGE_MED(LOC << "From the mesh spacedim " << _ptrMesh->_spaceDimension << " meshdim " << _ptrMesh->_meshDimension);
2157 if ((spaceDimension <= MED_VALID) && (meshDimension <= MED_VALID))
2159 err = MEDmaaCr(_medIdt,
2160 const_cast <char *> (_meshName.c_str()),
2161 _ptrMesh->_meshDimension,med_2_3::MED_STRUCTURE,
2162 const_cast <char *> (_ptrMesh->_description.c_str()));
2164 meshDimension = _ptrMesh->_meshDimension;
2166 if (err != MED_VALID)
2167 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Grid"));
2169 MESSAGE_MED(LOC<<"Grid "<<_meshName<<" created in file "<<_fileName<<" !");
2171 else if ((spaceDimension != _ptrMesh->_spaceDimension) &&
2172 (meshDimension != _ptrMesh->_meshDimension))
2173 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
2174 "| already exists in file |" << _fileName <<
2175 "| with space dimension |" << spaceDimension <<
2176 "| and mesh dimension |" << meshDimension <<
2177 "| but the space dimension and the mesh dimension of the mesh we want to write are respectively |"
2178 << _ptrMesh->_spaceDimension <<"|" <<
2179 _ptrMesh->_meshDimension <<"|" )) ;
2181 MED_EN::med_grid_type gridType = ptrGrid->getGridType();
2183 err = med_2_3::MEDnatureGrilleEcr(_medIdt,
2184 const_cast <char *> (_meshName.c_str()),
2185 (med_2_3::med_type_grille) gridType);
2187 if (err != MED_VALID)
2188 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to write the type of the Grid"));
2190 // Recompose the <_spaceDimension> strings in 1 string
2192 string valueString ;
2193 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
2195 valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
2196 lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2197 tmp_name.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2198 valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
2199 lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2200 tmp_unit.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2203 // Pourquoi le stocker sous forme de chaîne ?
2204 const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
2205 if (coordinateSystem == "CARTESIAN")
2206 rep = med_2_3::MED_CART;
2207 else if ( coordinateSystem == "CYLINDRICAL")
2208 rep = med_2_3::MED_CYL;
2209 else if ( coordinateSystem == "SPHERICAL" )
2210 rep = med_2_3::MED_SPHER;
2212 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
2213 "| doesn't have a valid coordinate system : |"
2214 << _ptrMesh->_coordinate->_coordinateSystem
2217 med_2_3::med_int ArrayLen[] = { (med_2_3::med_int) ptrGrid->_iArrayLength,
2218 (med_2_3::med_int) ptrGrid->_jArrayLength,
2219 (med_2_3::med_int) ptrGrid->_kArrayLength };
2221 // Write node coordinates for MED_BODY_FITTED grid
2222 if (gridType == MED_EN::MED_BODY_FITTED)
2224 // Write Coordinates and families
2225 // double * coo = const_cast <double *>
2226 // (_ptrMesh->_coordinate->getCoordinates(MED_EN::MED_FULL_INTERLACE));
2228 err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2229 _ptrMesh->_spaceDimension,
2230 //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
2231 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
2232 med_2_3::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes,
2233 // _ptrMesh->_coordinate->_numberOfNodes
2234 rep, const_cast <char *> (tmp_name.c_str()),
2235 const_cast <char *> (tmp_unit.c_str()));
2237 if (err != MED_VALID)
2238 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of the grid |" << _meshName.c_str() << "| in file |" << _fileName
2239 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2240 << " with units names |" << tmp_name
2241 << "| and units |" << tmp_unit
2244 //CCRT int* structure = new int [meshDimension];
2245 med_2_3::med_int* structure = new med_2_3::med_int [meshDimension];
2247 for (int idim = 0; idim < meshDimension; ++idim)
2248 structure[idim] = ArrayLen [idim];
2251 err = med_2_3::MEDstructureCoordEcr(_medIdt, const_cast <char *>
2252 (_meshName.c_str()), meshDimension,
2255 if (err != MED_VALID)
2256 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in writing the structure of the grid |" << _meshName.c_str()));
2258 delete [] structure;
2260 else if ((gridType == MED_EN::MED_CARTESIAN) ||
2261 (gridType == MED_EN::MED_POLAR))
2263 // Write Arrays of Cartesian or Polar Grid
2265 double * Array[] = { ptrGrid->_iArray,
2269 for (int idim = 0; idim < _ptrMesh->_meshDimension; ++idim)
2271 string str_name = string (tmp_name,idim*MED_TAILLE_PNOM22,
2273 string str_unit = string (tmp_unit,idim*MED_TAILLE_PNOM22,
2276 err = med_2_3::MEDindicesCoordEcr(_medIdt, const_cast <char *>
2277 (_meshName.c_str()),
2278 _ptrMesh->_meshDimension,
2279 Array[idim], ArrayLen[idim],
2280 (idim+1), const_cast <char *>
2283 (str_unit.c_str()));
2285 if (err != MED_VALID)
2286 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
2287 "Can't write grid coordinates for " <<
2288 idim << "-th dimention"));
2290 } // end Write Cartesian or Polar Grid
2296 //=======================================================================
2297 //function : writeCoordinates
2299 //=======================================================================
2301 int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const {
2303 const char * LOC = "int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const : ";
2306 med_2_3::med_err err = MED_ERROR;
2307 med_2_3::med_repere rep;
2308 string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2309 string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2311 // Recompose the <_spaceDimension> strings in 1 string
2313 string valueString ;
2314 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
2315 valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
2316 lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2317 tmp_name.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2318 valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
2319 lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2320 tmp_unit.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2323 // Test if the mesh <_meshName> already exists
2324 // If it doesn't exists create it
2325 // If it already exists verify if its space and mesh dimensions are the same
2326 // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively
2327 // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
2329 int spaceDimension = med_2_3::MEDdimEspaceLire(_medIdt, const_cast <char *>
2330 (_meshName.c_str()));
2332 int meshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *>
2333 (_meshName.c_str()) );
2335 SCRUTE_MED(spaceDimension);
2336 SCRUTE_MED(meshDimension);
2337 SCRUTE_MED(_ptrMesh->_spaceDimension);
2338 SCRUTE_MED(_ptrMesh->_meshDimension);
2340 if ((spaceDimension != MED_VALID) && (meshDimension < MED_VALID))
2342 err = MEDmaaCr(_medIdt, const_cast <char *> (_meshName.c_str()),
2343 _ptrMesh->_meshDimension, med_2_3::MED_NON_STRUCTURE,
2344 const_cast <char *> (_ptrMesh->_description.c_str()));
2346 if (err < MED_VALID)
2347 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|"));
2349 MESSAGE_MED(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !");
2351 // PAL14544. Write _spaceDimension if _spaceDimension != _meshDimension
2352 if ( _ptrMesh->_spaceDimension != _ptrMesh->_meshDimension )
2354 err = med_2_3::MEDdimEspaceCr(_medIdt, const_cast <char *> (_meshName.c_str()),
2355 _ptrMesh->_spaceDimension);
2356 if (err < MED_VALID)
2357 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write spaceDimension of Mesh : |"
2358 << _meshName << "|"));
2361 else if ((spaceDimension != _ptrMesh->_spaceDimension) &&
2362 (meshDimension != _ptrMesh->_meshDimension))
2363 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() <<
2364 "| already exists in file |" << _fileName <<
2365 "| with space dimension |" << spaceDimension <<
2366 "| and mesh dimension |" << meshDimension <<
2367 "| but the space dimension and the mesh dimension of the mesh we want to write are respectively |"
2368 << _ptrMesh->_spaceDimension <<"|" <<
2369 _ptrMesh->_meshDimension << "|")) ;
2371 // Pourquoi le stocker sous forme de chaîne ?
2372 const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
2373 if (coordinateSystem == "CARTESIAN")
2374 rep = med_2_3::MED_CART;
2375 else if ( coordinateSystem == "CYLINDRICAL")
2376 rep = med_2_3::MED_CYL;
2377 else if ( coordinateSystem == "SPHERICAL" )
2378 rep = med_2_3::MED_SPHER;
2380 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |"
2381 << _ptrMesh->_coordinate->_coordinateSystem
2384 // err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2385 // _ptrMesh->_spaceDimension,
2386 // //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
2387 // const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
2388 // MED_FR::MED_FULL_INTERLACE,
2389 // _ptrMesh->_numberOfNodes, // _ptrMesh->_coordinate->_numberOfNodes
2390 // MED_FR::MED_LECTURE_ECRITURE,
2392 // const_cast <char *> (tmp_name.c_str()),
2393 // const_cast <char *> (tmp_unit.c_str())
2396 err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2397 _ptrMesh->_spaceDimension,
2398 //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
2399 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
2400 med_2_3::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes,
2401 // _ptrMesh->_coordinate->_numberOfNodes
2402 rep, const_cast <char *> (tmp_name.c_str()),
2403 const_cast <char *> (tmp_unit.c_str()));
2406 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2407 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2408 << " with units names |" << tmp_name
2409 << "| and units |" << tmp_unit
2413 //////////////////////////////////////////////////////////////////////////////////////
2414 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
2415 //////////////////////////////////////////////////////////////////////////////////////
2417 /// Ecrit les numéros optionnels des noeuds
2418 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
2421 if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) {
2423 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2424 const int * NodesNumbers = _ptrMesh->_coordinate->getNodesNumbers() ;
2425 med_2_3::med_int * tmp_NodesNumbers = new med_2_3::med_int[_ptrMesh->_numberOfNodes] ;
2427 for ( ii = 0 ; ii < _ptrMesh->_numberOfNodes ; ii++ )
2428 tmp_NodesNumbers[ii] = NodesNumbers[ii] ;
2429 err = MEDnumEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2431 _ptrMesh->_numberOfNodes, med_2_3::MED_NOEUD,
2432 med_2_3::med_geometrie_element(0) );
2433 delete [] tmp_NodesNumbers ;
2435 err = MEDnumEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2436 const_cast <med_int *> (_ptrMesh->_coordinate->getNodesNumbers() ),
2437 _ptrMesh->_numberOfNodes, med_2_3::MED_NOEUD,
2438 med_2_3::med_geometrie_element(0) );
2441 if (err != MED_VALID)
2442 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write optionnal numbers of mesh |" <<
2443 _meshName.c_str() << "| in file |" <<
2444 _fileName << " |")) ;
2446 //////////////////////////////////////////////////////////////////////////////////////
2456 int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const
2458 const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeConnectivities() const : ";
2461 med_2_3::med_err err;
2463 // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB !
2464 // PG : IMPOSSIBLE : LA METHODE EST PRIVEE !
2466 // A FAIRE : A tester surtout dans les methodes de MESH.
2467 // if ( _ptrMesh->_connectivity == (CONNECTIVITY *) MED_INVALID )
2468 if ( _ptrMesh->_connectivity == (CONNECTIVITY *) NULL )
2469 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object ")) ;
2472 // Nodal connectivity for classic geometric types
2473 if ( _ptrMesh->existConnectivity(MED_NODAL,entity) )
2475 int numberOfTypes = _ptrMesh->getNumberOfTypes(entity);
2476 const medGeometryElement * types = _ptrMesh->getTypes(entity);
2478 for (int i=0; i<numberOfTypes; i++)
2480 int numberOfElements = _ptrMesh->getNumberOfElements(entity,types[i]);
2481 const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE,
2482 MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ??
2484 // Pour l'instant la class utilise le multi.....
2486 // if (entity==MED_EN::MED_CELL)
2487 // if ( (types[i]/ 100) < _ptrMesh->_spaceDimension)
2489 int numberOfNodes = types[i]%100;
2490 //CCRT int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)];
2491 med_2_3::med_int * connectivityArray = new med_2_3::med_int[numberOfElements*(numberOfNodes+multi)];
2493 // version originale sans prise en compte des numéros optionnels
2495 for (int j=0 ; j<numberOfElements; j++)
2497 for (int k=0; k<numberOfNodes; k++)
2498 connectivityArray[j*(numberOfNodes+multi)+k] = connectivity[j*numberOfNodes+k];
2500 if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes] = 0;
2503 //////////////////////////////////////////////////////////////////////////////////////
2504 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
2505 //////////////////////////////////////////////////////////////////////////////////////
2507 /// Dénumérote les sommets des mailles pour leur rendre leurs numéros optionnels
2508 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
2510 //if (_ptrMesh->_arePresentOptionnalNodesNumbers==1)
2512 // const int * nodesNumbers = _ptrMesh->_coordinate->getNodesNumbers();
2513 // for (int j=0 ; j<numberOfElements; j++)
2515 // for (int k=0; k<numberOfNodes; k++)
2516 // connectivityArray[j*(numberOfNodes+multi)+k] =
2517 // nodesNumbers[connectivity[j*numberOfNodes+k]-1];
2518 // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes] = 0;
2523 // for (int j=0 ; j<numberOfElements; j++)
2525 // for (int k=0; k<numberOfNodes; k++)
2526 // connectivityArray[j*(numberOfNodes+multi)+k] = connectivity[j*numberOfNodes+k];
2527 // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
2531 //////////////////////////////////////////////////////////////////////////////////////
2533 //err = MEDconnEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2534 // _ptrMesh->_spaceDimension, connectivityArray,
2535 // MED_FR::MED_FULL_INTERLACE, numberOfElements,
2536 // MED_FR::MED_LECTURE_ECRITURE,
2537 // (MED_FR::med_entite_maillage ) entity,
2538 // (MED_FR::med_geometrie_element) types[i], MED_FR::MED_NOD);
2540 //err = MEDconnEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2541 // _ptrMesh->_spaceDimension, connectivityArray,
2542 // MED_FR::MED_FULL_INTERLACE, numberOfElements,
2543 // (MED_FR::med_entite_maillage ) entity,
2544 // (MED_FR::med_geometrie_element) types[i], med_2_3::MED_NOD);
2546 err = MEDconnEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2547 _ptrMesh->_spaceDimension, connectivityArray,
2548 med_2_3::MED_FULL_INTERLACE, numberOfElements,
2549 //(med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
2550 (med_2_3::med_entite_maillage ) MED_CELL,
2551 (med_2_3::med_geometrie_element) types[i], med_2_3::MED_NOD);
2552 err = med_2_3::MEDdimEspaceCr
2553 (_medIdt, const_cast<char *>(_meshName.c_str()), _ptrMesh->_spaceDimension);
2555 delete[] connectivityArray;
2557 if (err<0) // ETENDRE LES EXPLICATIONS
2558 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |"
2559 << _meshName.c_str() << "| in file |" << _fileName
2560 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2568 if (_ptrMesh->existPolygonsConnectivity(MED_NODAL,entity))
2570 int nbPolygons = _ptrMesh->getNumberOfPolygons(entity);
2571 const int * PolygonsConnectivityIndex = _ptrMesh->getPolygonsConnectivityIndex(MED_NODAL,entity);
2572 const int * PolygonsConnectivity = _ptrMesh->getPolygonsConnectivity(MED_NODAL, entity);
2574 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2575 int ii, polygonsConnectivityLength = _ptrMesh->getPolygonsConnectivityLength(MED_NODAL, entity);
2577 med_2_3::med_int * tmp_PolygonsConnectivityIndex = new med_2_3::med_int[nbPolygons + 1];
2578 for (ii = 0; ii < nbPolygons + 1; ii++)
2579 tmp_PolygonsConnectivityIndex[ii] = PolygonsConnectivityIndex[ii];
2581 med_2_3::med_int * tmp_PolygonsConnectivity = new med_2_3::med_int[polygonsConnectivityLength];
2582 for (ii = 0; ii < polygonsConnectivityLength; ii++)
2583 tmp_PolygonsConnectivity[ii] = PolygonsConnectivity[ii];
2585 err = MEDpolygoneConnEcr(_medIdt,
2586 const_cast <char *> (_meshName.c_str()),
2587 tmp_PolygonsConnectivityIndex,
2589 tmp_PolygonsConnectivity,
2590 //(med_2_3::med_entite_maillage) entity,
2591 //because Med Memory works only in Nodal connectivity
2592 (med_2_3::med_entite_maillage) MED_CELL,
2595 delete [] tmp_PolygonsConnectivityIndex;
2596 delete [] tmp_PolygonsConnectivity;
2598 err = MEDpolygoneConnEcr(_medIdt,
2599 const_cast <char *> (_meshName.c_str()),
2600 const_cast <med_int*> (PolygonsConnectivityIndex),
2602 const_cast <med_int*> (PolygonsConnectivity),
2603 //(med_2_3::med_entite_maillage) entity,
2604 //because Med Memory works only in Nodal connectivity
2605 (med_2_3::med_entite_maillage) MED_CELL,
2610 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons nodal connectivities of mesh |"
2611 << _meshName.c_str() << "| in file |" << _fileName
2612 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2617 // Polyhedron writing
2618 if (_ptrMesh->existPolyhedronConnectivity(MED_NODAL,entity))
2620 //int nbPolyhedron = _ptrMesh->getNumberOfPolyhedron(entity);
2621 int nbPolyhedron = _ptrMesh->getNumberOfPolyhedron();
2622 int nbPolyhedronFaces = _ptrMesh->getNumberOfPolyhedronFaces();
2623 const int * PolyhedronIndex = _ptrMesh->getPolyhedronIndex(MED_NODAL);
2624 const int * PolyhedronFacesIndex = _ptrMesh->getPolyhedronFacesIndex();
2625 const int * PolyhedronConnectivity = _ptrMesh->getPolyhedronConnectivity(MED_NODAL);
2627 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2628 int ii, polyhedronConnectivityLength = _ptrMesh->getPolyhedronConnectivityLength(MED_NODAL);
2630 med_2_3::med_int * tmp_PolyhedronIndex = new med_2_3::med_int[nbPolyhedron + 1];
2631 for (ii = 0; ii < nbPolyhedron + 1; ii++)
2632 tmp_PolyhedronIndex[ii] = PolyhedronIndex[ii];
2634 med_2_3::med_int * tmp_PolyhedronFacesIndex = new med_2_3::med_int[nbPolyhedronFaces + 1];
2635 for (ii = 0; ii < nbPolyhedronFaces + 1; ii++)
2636 tmp_PolyhedronFacesIndex[ii] = PolyhedronFacesIndex[ii];
2638 med_2_3::med_int * tmp_PolyhedronConnectivity = new med_2_3::med_int[polyhedronConnectivityLength];
2639 for (ii = 0; ii < polyhedronConnectivityLength; ii++)
2640 tmp_PolyhedronConnectivity[ii] = PolyhedronConnectivity[ii];
2642 err = MEDpolyedreConnEcr(_medIdt,
2643 const_cast <char *> (_meshName.c_str()),
2644 tmp_PolyhedronIndex,
2646 tmp_PolyhedronFacesIndex,
2647 nbPolyhedronFaces + 1,
2648 tmp_PolyhedronConnectivity,
2651 delete [] tmp_PolyhedronIndex;
2652 delete [] tmp_PolyhedronFacesIndex;
2653 delete [] tmp_PolyhedronConnectivity;
2655 err = MEDpolyedreConnEcr(_medIdt,
2656 const_cast <char *> (_meshName.c_str()),
2657 const_cast <med_int*> (PolyhedronIndex),
2659 const_cast <med_int*> (PolyhedronFacesIndex),
2660 nbPolyhedronFaces + 1,
2661 const_cast <med_int*> (PolyhedronConnectivity),
2666 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron nodal connectivities of mesh |"
2667 << _meshName.c_str() << "| in file |" << _fileName
2668 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2673 // Descending connectivity for classic geometric types
2674 if ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) )
2676 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
2677 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
2679 for (int i=0; i<numberOfTypes; i++)
2681 int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
2682 const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]);
2684 // Pour l'instant la class utilise le multi.....
2685 // err = MED_FR::MEDconnEcr( _medIdt,
2686 // const_cast <char *> ( _meshName.c_str()),
2687 // _ptrMesh->_spaceDimension,
2688 // const_cast <int *> (connectivity),
2689 // MED_FR::MED_FULL_INTERLACE,
2690 // numberOfElements,
2691 // MED_FR::MED_LECTURE_ECRITURE,
2692 // (MED_FR::med_entite_maillage ) entity,
2693 // (MED_FR::med_geometrie_element) types[i],
2694 // MED_FR::MED_DESC );
2696 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2697 int lgth = _ptrMesh->getConnectivityLength(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]);
2698 med_2_3::med_int * tmp_Connectivity = new med_2_3::med_int[lgth] ;
2700 for ( ii = 0 ; ii < lgth ; ii++ )
2701 tmp_Connectivity[ii] = connectivity[ii] ;
2702 err = med_2_3::MEDconnEcr(_medIdt,
2703 const_cast <char *> ( _meshName.c_str()),
2704 _ptrMesh->_spaceDimension,
2706 med_2_3::MED_FULL_INTERLACE,
2708 //(med_2_3::med_entite_maillage ) entity,
2709 //because Med Memory works only in Nodal connectivity
2710 (med_2_3::med_entite_maillage ) MED_CELL,
2711 (med_2_3::med_geometrie_element) types[i],
2713 delete [] tmp_Connectivity ;
2715 err = med_2_3::MEDconnEcr(_medIdt,
2716 const_cast <char *> ( _meshName.c_str()),
2717 _ptrMesh->_spaceDimension,
2718 const_cast <int *> (connectivity),
2719 med_2_3::MED_FULL_INTERLACE,
2721 //(med_2_3::med_entite_maillage ) entity,
2722 //because Med Memory works only in Nodal connectivity
2723 (med_2_3::med_entite_maillage ) MED_CELL,
2724 (med_2_3::med_geometrie_element) types[i],
2728 if (err<0) // ETENDRE LES EXPLICATIONS
2729 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |"
2730 << _meshName.c_str() << "| in file |" << _fileName
2731 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2739 if (_ptrMesh->existPolygonsConnectivity(MED_DESCENDING,entity))
2741 int nbPolygons = _ptrMesh->getNumberOfPolygons(entity);
2742 // ??? //int nbPolygons = _ptrMesh->getNumberOfPolygons();
2743 const int * PolygonsConnectivityIndex = _ptrMesh->getPolygonsConnectivityIndex(MED_DESCENDING, entity);
2744 const int * PolygonsConnectivity = _ptrMesh->getPolygonsConnectivity(MED_DESCENDING, entity);
2746 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2747 int ii, polygonsConnectivityLength = _ptrMesh->getPolygonsConnectivityLength(MED_DESCENDING, entity);
2749 med_2_3::med_int * tmp_PolygonsConnectivityIndex = new med_2_3::med_int[nbPolygons + 1];
2750 for (ii = 0; ii < nbPolygons + 1; ii++)
2751 tmp_PolygonsConnectivityIndex[ii] = PolygonsConnectivityIndex[ii];
2753 med_2_3::med_int * tmp_PolygonsConnectivity = new med_2_3::med_int[polygonsConnectivityLength];
2754 for (ii = 0; ii < polygonsConnectivityLength; ii++)
2755 tmp_PolygonsConnectivity[ii] = PolygonsConnectivity[ii];
2757 err = MEDpolygoneConnEcr(_medIdt,
2758 const_cast <char *> (_meshName.c_str()),
2759 tmp_PolygonsConnectivityIndex,
2761 tmp_PolygonsConnectivity,
2762 //(med_2_3::med_entite_maillage) entity,
2763 //because Med Memory works only in Nodal connectivity
2764 (med_2_3::med_entite_maillage) MED_CELL,
2767 delete [] tmp_PolygonsConnectivityIndex;
2768 delete [] tmp_PolygonsConnectivity;
2770 err = MEDpolygoneConnEcr(_medIdt,
2771 const_cast <char *> (_meshName.c_str()),
2772 const_cast <med_int*> (PolygonsConnectivityIndex),
2774 const_cast <med_int*> (PolygonsConnectivity),
2775 //(med_2_3::med_entite_maillage) entity,
2776 //because Med Memory works only in Nodal connectivity
2777 (med_2_3::med_entite_maillage) entity,
2782 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons descending connectivities of mesh |"
2783 << _meshName.c_str() << "| in file |" << _fileName
2784 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2789 // Polyhedron writing
2790 if (_ptrMesh->existPolyhedronConnectivity(MED_DESCENDING, entity))
2792 med_2_3::med_int nbPolyhedron = _ptrMesh->getNumberOfPolyhedron();
2793 med_2_3::med_int NumberOfFaces = _ptrMesh->getNumberOfPolyhedronFaces();
2794 // ??? //_ptrMesh->getPolyhedronIndex(MED_DESCENDING)[nbPolyhedron] - 1;
2795 // by default all polyhedron faces are polygons
2796 vector<med_2_3::med_int> FacesGeometricTypes (NumberOfFaces, MED_POLYGON);
2797 const int * PolyhedronIndex = _ptrMesh->getPolyhedronIndex(MED_DESCENDING);
2798 const int * PolyhedronConnectivity = _ptrMesh->getPolyhedronConnectivity(MED_DESCENDING);
2800 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2801 int ii, polyhedronConnectivityLength = _ptrMesh->getPolyhedronConnectivityLength(MED_DESCENDING);
2803 med_2_3::med_int * tmp_PolyhedronIndex = new med_2_3::med_int[nbPolyhedron + 1];
2804 for (ii = 0; ii < nbPolyhedron + 1; ii++)
2805 tmp_PolyhedronIndex[ii] = PolyhedronIndex[ii];
2807 med_2_3::med_int * tmp_PolyhedronConnectivity = new med_2_3::med_int[polyhedronConnectivityLength];
2808 for (ii = 0; ii < polyhedronConnectivityLength; ii++)
2809 tmp_PolyhedronConnectivity[ii] = PolyhedronConnectivity[ii];
2811 err = MEDpolyedreConnEcr(_medIdt,
2812 const_cast <char *> (_meshName.c_str()),
2813 tmp_PolyhedronIndex,
2815 &FacesGeometricTypes[0],
2817 tmp_PolyhedronConnectivity,
2820 delete [] tmp_PolyhedronIndex;
2821 delete [] tmp_PolyhedronConnectivity;
2823 err = MEDpolyedreConnEcr(_medIdt,
2824 const_cast <char *> (_meshName.c_str()),
2825 const_cast <med_int*> (PolyhedronIndex),
2827 &FacesGeometricTypes[0],
2829 const_cast <med_int*> (PolyhedronConnectivity),
2834 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron descending connectivities of mesh |"
2835 << _meshName.c_str() << "| in file |" << _fileName
2836 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2845 /*!creates a vector of families from a vector of groups
2847 * \param myGroups input : vector of groups
2848 * \param myFamilies output vector of families
2850 * Routine is meant to be called to reconstruct families from existing groups
2851 * typically for writing meshes created by MEDMEM::MESHING containing overlapping groups
2853 * if the groups do not overlap, the vector of families will have the same size
2854 * as the vector of groups
2855 * otherwise, the size of the family vector will be larger
2858 void MED_MESH_WRONLY_DRIVER22::groupFamilyConverter(const vector <GROUP*>& myGroups, vector <FAMILY*>& myFamilies ) const
2861 const char* LOC = "MED_MESH_WRONLY_DRIVER::groupFamilyConverter";
2863 if (myGroups.empty()) return;
2865 // if (!myFamilies.empty())
2866 // throw MEDEXCEPTION(LOCALIZED("Family vector must be empty on call "
2867 // << "to groupFamilyConverter"));
2869 //mapping elements to all the groups containing it
2870 std::multimap <int,int> elem2groups;
2871 for (int igroup=0; igroup< myGroups.size(); igroup++)
2873 // if the support is on all Mesh elements
2874 //all the items from 1 to nb are in the group
2875 if (myGroups[igroup]->isOnAllElements())
2877 for (int ielem = 0; ielem< myGroups[igroup]->getNumberOfElements(MED_ALL_ELEMENTS); ielem++)
2879 elem2groups.insert(make_pair(ielem+1, igroup));
2882 //otherwise getNumber() gives the appropriate number of items
2885 const int*Number = myGroups[igroup]->getNumber(MED_ALL_ELEMENTS) ;
2886 for (int ielem = 0; ielem< myGroups[igroup]->getNumberOfElements(MED_ALL_ELEMENTS); ielem++)
2888 elem2groups.insert(make_pair(Number[ielem], igroup));
2893 //creating a set of signatures for the groups intersections
2894 std::multimap<vector<int>,int> signatures;
2896 typedef multimap<int,int>::iterator MI;
2897 MI iter=elem2groups.begin();
2899 while (iter!=elem2groups.end())
2901 vector<int> sign (1, iter -> second );
2902 int key = iter -> first;
2904 while (iter!=elem2groups.end()&&iter-> first == key)
2906 sign.push_back(iter -> second);
2909 signatures.insert(make_pair(sign,key));
2912 elem2groups.clear();
2914 //creating the families from the signatures mapping
2915 //each signature will correspond to a new family
2916 std::multimap<vector<int>,int>::const_iterator iter_signatures = signatures.begin();
2918 //retrieving the entity type (all the groups have the same)
2919 // node families are numbered above 0
2920 // cell families are numbered from -1 to -MAX_NB_GROUPS
2921 // face falimies are numbered from -MAX_NB_GROUPS-1 to -2*MAX_NB_GROUPS
2922 // edge families are numbered from -2*MAX_NB_GROUPS to -3*MAX_NB_GROUPS
2923 // MAX_NB_GROUPS is defined in MEDMEM_define.hxx
2925 medEntityMesh entity = myGroups[0]->getEntity();
2926 MESH* mesh=myGroups[0]->getMesh();
2935 ifamily=-MAX_NB_GROUP;
2938 ifamily=-2*MAX_NB_GROUP;
2941 ifamily=-3*MAX_NB_GROUP;
2945 //browsing signatures to build all the families
2946 //each signature corresponds to a new family
2948 while (iter_signatures!= signatures.end())
2950 const vector<int>& key= iter_signatures->first;
2951 int size = signatures.count(key);
2955 for (int i=0; i< size; i++)
2957 numbers.push_back(iter_signatures->second);
2961 //TODO : see if build SupportOnElementFromElementList could not be built from another container
2963 // for nodes, the family is built directly from the node list
2964 // for elements, it is built from the buildSupportOnElementsFromElementList
2965 // which allocates a support
2967 if (entity!=MED_NODE)
2970 support=mesh->buildSupportOnElementsFromElementList(numbers, entity);
2971 myFamily=new FAMILY(*support);
2976 myFamily= new FAMILY();
2977 myFamily->setMesh(mesh);
2978 myFamily->fillFromNodeList(numbers);
2982 // the identifier and the groups are set
2983 myFamily->setIdentifier(ifamily);
2984 myFamily->setNumberOfGroups(key.size());
2985 char family_name[MED_TAILLE_NOM];
2987 //if the family has one group to which only one family
2988 //is associated, the name of the family underlying the group
2989 //is given back to the family
2990 if (key.size()==1 && myGroups[key[0]]->getNumberOfFamilies()==0)
2992 vector<FAMILY*> families;
2993 families.push_back(myFamily);
2994 myGroups[key[0]]->setFamilies(families);
2995 //it is necessary to use strncpy because group and family
2996 //have different name sizes
2997 strncpy(family_name,myGroups[key[0]]->getName().c_str(),MED_TAILLE_NOM);
2998 family_name[MED_TAILLE_NOM-1]='\0';
3001 sprintf(family_name,"family%d",ifamily);
3003 myFamily->setName( healName( family_name ));
3005 string* groupnames=new string[key.size()];
3006 //myFamily->getGroupsNames();
3007 //groupnames.set(key.size());
3009 for (int igroup=0; igroup<key.size(); igroup++)
3011 groupnames[igroup]=myGroups[key[igroup]]->getName();
3014 myFamily->setGroupsNames(groupnames,true);
3016 myFamilies.push_back(myFamily);
3020 //adding empty families corresponding to empty groups
3021 for (int i=0; i<myGroups.size(); i++)
3023 if (myGroups[i]->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)==0)
3025 FAMILY* myFamily=new FAMILY(*(myGroups[i]));
3026 char family_name[MED_TAILLE_NOM];
3027 //it is necessary to use strncpy because group and family
3028 //have different name sizes
3029 strncpy(family_name,myGroups[i]->getName().c_str(),MED_TAILLE_NOM);
3030 family_name[MED_TAILLE_NOM-1]='\0';
3031 myFamily->setName( healName( family_name ));
3032 myFamily->setIdentifier(ifamily);
3034 vector<string> groupnames;
3035 groupnames.push_back(myGroups[i]->getName());
3036 myFamily->setNumberOfGroups(1);
3037 myFamily->setGroupsNames(&groupnames[0]);
3038 myFamilies.push_back(myFamily);
3044 int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const {
3046 const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const : ";
3049 med_2_3::med_err err;
3051 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH
3053 { // Node related block
3055 // We build the array from the families list objects :
3056 int NumberOfNodes = _ptrMesh->getNumberOfNodes() ;
3057 //CCRT int * MEDArrayNodeFamily = new int[NumberOfNodes] ;
3058 med_2_3::med_int * MEDArrayNodeFamily = new med_2_3::med_int[NumberOfNodes] ;
3059 // family 0 by default
3060 for (int i=0; i<NumberOfNodes; i++)
3061 MEDArrayNodeFamily[i]=0;
3062 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(MED_NODE);
3063 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyNode;
3064 int NumberOfNodesFamilies = myFamilies->size() ;
3065 // bool ToDestroy = false;
3066 if (0 == NumberOfNodesFamilies) {
3067 // ToDestroy = true ;
3068 vector<GROUP*> myGroups = _ptrMesh->getGroups(MED_NODE);
3070 groupFamilyConverter(myGroups,*myFamilies);
3072 NumberOfNodesFamilies=myFamilies->size() ;
3074 for (int i=0 ; i<NumberOfNodesFamilies; i++) {
3076 //SCRUTE_MED(myFamilies[i]->getName());
3077 int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
3078 int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
3079 if ((*myFamilies)[i]->isOnAllElements())
3080 for (int j=0; j<TotalNumber; j++)
3081 MEDArrayNodeFamily[j]=FamilyIdentifier;
3083 const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
3084 for (int j=0; j<TotalNumber; j++)
3085 MEDArrayNodeFamily[Number[j]-1]=FamilyIdentifier ;
3089 // for(int j=0; j<NumberOfNodes; j++) {
3090 // SCRUTE_MED(MEDArrayNodeFamily[j]);
3093 // if ( !_ptrMesh->getIsAGrid() )
3095 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3096 MEDArrayNodeFamily, NumberOfNodes, med_2_3::MED_NOEUD,
3097 (med_2_3::med_geometrie_element) MED_NONE);
3100 // err = MEDfamGridEcr(_medIdt,
3101 // const_cast <char *> (_ptrMesh->_name.c_str()),
3102 // MEDArrayNodeFamily,
3104 // MED_FR::MED_LECTURE_ECRITURE,
3105 // MED_FR::MED_NOEUD);
3107 if ( err != MED_VALID)
3108 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< NumberOfNodes
3109 << "| nodes in mesh |"
3110 << _ptrMesh->_name.c_str() << "|" ));
3111 delete[] MEDArrayNodeFamily;
3112 //if (true == ToDestroy)
3113 // for (int i=0; i<NumberOfNodesFamilies; i++)
3114 // delete (*myFamilies)[i];
3117 { // CELLS RELATED BLOCK
3118 medEntityMesh entity=MED_EN::MED_CELL;
3119 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
3120 if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID
3121 (_ptrMesh->existConnectivityWithPoly(MED_NODAL,entity)) ||
3122 (_ptrMesh->existConnectivityWithPoly(MED_DESCENDING,entity)))
3124 int numberOfTypes = _ptrMesh->getNumberOfTypesWithPoly(entity) ;
3125 medGeometryElement * types = _ptrMesh->getTypesWithPoly(entity) ;
3127 // We build the array from the families list objects :
3128 //int NumberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS);
3129 int NumberOfElements = _ptrMesh->getNumberOfElementsWithPoly(entity, MED_ALL_ELEMENTS);
3130 int * MEDArrayFamily = new int[NumberOfElements] ;
3131 // family 0 by default
3132 for (int i=0; i<NumberOfElements; i++)
3133 MEDArrayFamily[i]=0;
3134 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity);
3135 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyCell ;
3136 int NumberOfFamilies = myFamilies->size() ;
3137 // bool ToDestroy = false;
3138 if (0 == NumberOfFamilies) {
3139 // ToDestroy = true ;
3140 vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
3141 groupFamilyConverter(myGroups,*myFamilies);
3142 NumberOfFamilies=myFamilies->size() ;
3144 for (int i=0 ; i<NumberOfFamilies; i++) {
3145 int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
3146 int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
3147 if ((*myFamilies)[i]->isOnAllElements())
3148 for (int ii=0; ii<TotalNumber; ii++)
3149 MEDArrayFamily[ii]=FamilyIdentifier;
3151 const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
3152 for (int ii=0; ii<TotalNumber; ii++)
3153 MEDArrayFamily[Number[ii]-1]=FamilyIdentifier ;
3159 // for (int i=0; i<NumberOfElements; i++)
3160 // SCRUTE_MED(MEDArrayFamily[i]);
3163 //const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity);
3165 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3166 int lgth=NumberOfElements;
3167 med_2_3::med_int *temp=new med_2_3::med_int[lgth];
3168 for(int i2=0;i2<lgth;i2++)
3169 temp[i2]=(med_2_3::med_int) (MEDArrayFamily[i2]);
3171 for (int i=0; i<numberOfTypes; i++) {
3172 int typeNumberOfElements=_ptrMesh->getNumberOfElementsWithPoly(entity,types[i]);
3173 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3174 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3175 //(temp+offset),(typeCount[i+1]-typeCount[i]),
3176 (temp+offset), typeNumberOfElements,
3177 //CCRT med_2_3::MED_REMP ,
3178 // (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3179 (med_2_3::med_entite_maillage) MED_CELL,
3180 (med_2_3::med_geometrie_element) types[i]);
3182 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3183 (MEDArrayFamily+offset),
3184 typeNumberOfElements,
3185 // (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3186 (med_2_3::med_entite_maillage) MED_CELL,
3187 (med_2_3::med_geometrie_element) types[i]);
3189 MESSAGE_MED("OK "<<i);
3190 if ( err != MED_VALID)
3191 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< typeNumberOfElements
3192 << "| cells of geometric type |" << geoNames[types[i]] <<"|in mesh |"
3193 << _ptrMesh->_name.c_str() << "|" ));
3194 offset+=typeNumberOfElements;
3197 //CCRT#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3198 //CCRT delete [] temp;
3200 delete[] MEDArrayFamily ;
3202 // if (true == ToDestroy) {
3203 // int NumberOfFamilies = myFamilies->size();
3204 // for (int i=0; i<NumberOfFamilies; i++)
3205 // delete (*myFamilies)[i];
3210 if (!_ptrMesh->getIsAGrid() || _ptrMesh->_meshDimension == 3 ) // for grid - only in 3D mesh
3212 { // FACE RELATED BLOCK
3213 medEntityMesh entity=MED_EN::MED_FACE;
3214 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
3215 if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID
3216 (_ptrMesh->existConnectivityWithPoly(MED_NODAL,entity)) ||
3217 (_ptrMesh->existConnectivityWithPoly(MED_DESCENDING,entity)))
3219 int numberOfTypes = _ptrMesh->getNumberOfTypesWithPoly(entity) ;
3220 medGeometryElement * types = _ptrMesh->getTypesWithPoly(entity) ;
3221 SCRUTE_MED(numberOfTypes);
3223 int numberOfElements = _ptrMesh->getNumberOfElementsWithPoly(entity, MED_ALL_ELEMENTS) ;
3224 int * familyArray = new int[numberOfElements] ;
3225 for (int i=0;i<numberOfElements;i++)
3228 int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
3229 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
3230 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyFace ;
3231 // bool ToDestroy = false;
3232 if (0 == numberOfFamilies) {
3233 //ToDestroy = true ;
3234 vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
3236 groupFamilyConverter(myGroups,*myFamilies);
3238 numberOfFamilies=myFamilies->size() ;
3240 for (int i=0;i<numberOfFamilies;i++) {
3241 int familyNumber = (*myFamilies)[i]->getIdentifier() ;
3242 int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
3243 if ((*myFamilies)[i]->isOnAllElements())
3244 for (int ii=0; ii<numberOfFamilyElements; ii++)
3245 familyArray[ii]=familyNumber;
3247 const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
3248 for (int ii=0;ii<numberOfFamilyElements;ii++)
3249 familyArray[myFamilyElements[ii]-1]=familyNumber;
3253 for (int i=0;i<numberOfElements;i++)
3254 SCRUTE_MED(familyArray[i]);
3257 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3258 int lgth=numberOfElements;
3259 med_2_3::med_int *temp=new med_2_3::med_int[lgth];
3260 for(int i2=0;i2<lgth;i2++)
3261 temp[i2]=(med_2_3::med_int) (familyArray[i2]);
3263 SCRUTE_MED(numberOfTypes);
3265 for (int i=0; i<numberOfTypes; i++) {
3266 int typeNumberOfElements = _ptrMesh->getNumberOfElementsWithPoly(entity,types[i]) ;
3267 SCRUTE_MED(typeNumberOfElements);
3269 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3270 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3271 (temp+offset), typeNumberOfElements,
3272 // (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3273 (med_2_3::med_entite_maillage) MED_CELL,
3274 (med_2_3::med_geometrie_element) types[i]);
3276 MESSAGE_MED("On est bien la !!! entity = " << entity << " type " << types[i]);
3278 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3279 (familyArray+offset), typeNumberOfElements,
3280 // (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3281 (med_2_3::med_entite_maillage) MED_CELL,
3282 (med_2_3::med_geometrie_element) types[i]);
3284 if ( err != MED_VALID)
3285 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< typeNumberOfElements
3286 << "| faces of geometric type |" << geoNames[types[i]] <<"|in mesh |"
3287 << _ptrMesh->_name.c_str() << "|" ));
3288 offset+=typeNumberOfElements;
3290 //CCRT there was "temp" and "familyArray" for OSF, but only "familyArray" for Linux ...
3291 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3295 delete[] familyArray ;
3297 // if (true == ToDestroy) {
3298 // int NumberOfFamilies = myFamilies->size();
3299 // for (int i=0; i<NumberOfFamilies; i++)
3300 // delete (*myFamilies)[i];
3305 if (!_ptrMesh->getIsAGrid() || _ptrMesh->_meshDimension > 1 ) // for grid - only in 3D and 2D mesh
3307 { // EDGE RELATED BLOCK
3308 //medEntityMesh entity=MED_EN::MED_FACE;
3309 medEntityMesh entity=MED_EN::MED_EDGE;
3310 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
3311 if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID
3312 ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) ||
3313 ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
3315 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
3316 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
3318 int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
3319 int * familyArray = new int[numberOfElements] ;
3320 // med_2_3::med_int * familyArray = new int[numberOfElements] ;
3321 for (int i=0;i<numberOfElements;i++)
3324 int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
3325 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
3326 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyEdge ;
3327 //bool ToDestroy = false;
3328 if (0 == numberOfFamilies) {
3329 //ToDestroy = true ;
3330 vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
3332 groupFamilyConverter(myGroups,*myFamilies);
3334 numberOfFamilies=myFamilies->size() ;
3338 for (int i=0;i<numberOfFamilies;i++) {
3339 int familyNumber = (*myFamilies)[i]->getIdentifier() ;
3340 int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
3341 if ((*myFamilies)[i]->isOnAllElements())
3342 for (int ii=0; ii<numberOfFamilyElements; ii++)
3343 familyArray[ii]=familyNumber;
3345 const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
3346 for (int ii=0;ii<numberOfFamilyElements;ii++)
3347 familyArray[myFamilyElements[ii]-1]=familyNumber;
3352 for (int i=0;i<numberOfElements;i++)
3353 SCRUTE_MED(familyArray[i]);
3356 const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
3358 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3359 int lgth=numberOfElements;
3360 med_2_3::med_int *temp=new med_2_3::med_int[lgth];
3361 for(int i2=0;i2<lgth;i2++)
3362 temp[i2]=(med_2_3::med_int) (familyArray[i2]);
3364 SCRUTE_MED(numberOfTypes);
3366 for (int i=0; i<numberOfTypes; i++) {
3367 int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
3368 SCRUTE_MED(typeNumberOfElements);
3369 SCRUTE_MED(typeCount[i+1]);
3370 SCRUTE_MED(typeCount[i]);
3371 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3372 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3373 (temp+(typeCount[i]-1)), typeNumberOfElements,
3374 // (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3375 (med_2_3::med_entite_maillage) MED_CELL,
3376 (med_2_3::med_geometrie_element) types[i]);
3378 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3379 (familyArray+(typeCount[i]-1)), typeNumberOfElements,
3380 // (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3381 (med_2_3::med_entite_maillage) MED_CELL,
3382 (med_2_3::med_geometrie_element) types[i]);
3384 if ( err != MED_VALID)
3385 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
3386 << "| edges of geometric type |" << geoNames[types[i]] <<"|in mesh |"
3387 << _ptrMesh->_name.c_str() << "|" ));
3390 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3393 delete[] familyArray ;
3394 // if (true == ToDestroy) {
3395 // int NumberOfFamilies = myFamilies->size();
3396 // for (int i=0; i<NumberOfFamilies; i++)
3397 // delete (*myFamilies)[i];
3406 int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> & families ) const
3409 const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> families) const : ";
3412 med_2_3::med_err err;
3414 MESSAGE_MED(LOC<<" families.size() :"<<families.size());
3416 for (unsigned int i=0; i< families.size(); i++) {
3418 int numberOfAttributes = families[i]->getNumberOfAttributes ();
3419 string attributesDescriptions (numberOfAttributes*MED_TAILLE_DESC,'\0');
3421 // Recompose the attributes descriptions arg for MED
3422 for (int j=0; j < numberOfAttributes; j++)
3424 string attributeDescription = families[i]->getAttributeDescription(j+1);
3426 if ( attributeDescription.size() > MED_TAILLE_DESC )
3427 throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |"
3428 << j+1 << "| of the family |" << families[i]->getName()
3429 << "| with identifier |" << families[i]->getIdentifier()
3430 << "| is |" << attributeDescription.size()
3431 <<"| and is more than |" << MED_TAILLE_DESC << "|"));
3433 int length = min(MED_TAILLE_LNOM,(int)attributeDescription.size());
3434 attributesDescriptions.replace(j*MED_TAILLE_DESC,length, attributeDescription,0,length);
3438 int numberOfGroups = families[i]->getNumberOfGroups();
3439 string groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0');
3441 // Recompose the groups names arg for MED
3442 for (int j=0; j < numberOfGroups; j++)
3444 string groupName = families[i]->getGroupName(j+1);
3446 if ( groupName.size() > MED_TAILLE_LNOM )
3447 throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name n° |"
3448 << j+1 << "| of the family |" << families[i]->getName()
3449 << "| with identifier |" << families[i]->getIdentifier()
3450 << "| is |" << groupName.size()
3451 <<"| and is more than |" << MED_TAILLE_LNOM << "|"));
3453 int length = min(MED_TAILLE_LNOM,(int)groupName.size());
3454 groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length);
3457 // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
3459 string dataGroupFam;
3460 if (families[i]->getEntity() == MED_NODE)
3461 dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/NOEUD/"+families[i]->getName()+"/";
3463 dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/ELEME/"+families[i]->getName()+"/";
3465 SCRUTE_MED("|"<<dataGroupFam<<"|");
3466 err = med_2_3::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) ;
3467 if ( err < MED_VALID ) {
3469 if ( families[i]->getName().size() > MED_TAILLE_NOM )
3471 ( LOCALIZED(STRING(LOC) << "The size of the name of the family |" << i+1
3472 << "| |" << families[i]->getName()
3473 << "| with identifier |" << families[i]->getIdentifier() << "| is |"
3474 << families[i]->getName().size() <<"| and is more than |"
3475 << MED_TAILLE_NOM << "|")) ;
3477 MESSAGE_MED(LOC<<"families[i]->getName().c_str() : "<<families[i]->getName().c_str());
3478 MESSAGE_MED(LOC<<"_meshName.c_str() : "<<_meshName.c_str());
3479 MESSAGE_MED(LOC<<"families[i]->getIdentifier() : "<<families[i]->getIdentifier());
3480 MESSAGE_MED(LOC<<"numberOfAttributes : "<<numberOfAttributes);
3482 //MESSAGE_MED(LOC<<"families[i]->getAttributesIdentifiers() : "<<families[i]->getAttributesIdentifiers()[0]);
3483 //MESSAGE_MED(LOC<<"families[i]->getAttributesValues() : "<<families[i]->getAttributesValues()[0]);
3484 MESSAGE_MED(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str());
3485 MESSAGE_MED(LOC<<"numberOfGroups : "<<numberOfGroups);
3486 MESSAGE_MED(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str());
3487 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3488 int lgth=families[i]->getNumberOfAttributes();
3489 med_2_3::med_int * AttributesIdentifier2 = new med_2_3::med_int[lgth] ;
3490 med_2_3::med_int * AttributesValues2 = new med_2_3::med_int[lgth] ;
3491 for(med_2_3::med_int i2=0;i2<lgth;i2++)
3493 AttributesIdentifier2[i2]=(med_2_3::med_int)(families[i]->getAttributesIdentifiers()[i2]);
3494 AttributesValues2[i2]=(med_2_3::med_int)(families[i]->getAttributesValues()[i2]);
3496 err = med_2_3::MEDfamCr( _medIdt,
3497 const_cast <char *> ( _meshName.c_str() ),
3498 const_cast <char *> ( healName(families[i]->getName()).c_str() ),
3499 families[i]->getIdentifier(),
3500 AttributesIdentifier2,
3502 const_cast <char *> (attributesDescriptions.c_str()),
3504 const_cast <char *> (groupsNames.c_str()),
3506 delete [] AttributesIdentifier2;
3507 delete [] AttributesValues2;
3509 err = med_2_3::MEDfamCr( _medIdt,
3510 const_cast <char *> ( _meshName.c_str() ),
3511 const_cast <char *> ( healName(families[i]->getName()).c_str() ),
3512 families[i]->getIdentifier(),
3513 (med_2_3::med_int*)families[i]->getAttributesIdentifiers(),
3514 (med_2_3::med_int*)families[i]->getAttributesValues(),
3515 const_cast <char *> (attributesDescriptions.c_str()),
3517 const_cast <char *> (groupsNames.c_str()),
3521 if (err != MED_VALID)
3522 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName()
3523 << "| with identifier |" << families[i]->getIdentifier()
3524 << "| groups names |" << groupsNames
3525 << "| and attributes descriptions |" << attributesDescriptions << "|"));
3528 med_2_3::_MEDdatagroupFermer(_medIdt);
3538 // A FAIRE POUR LES NOEUDS ET LES ELEMENTS ret = MEDfamEcr(
3542 /*--------------------- RDWR PART -------------------------------*/
3544 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22()
3546 this->GENDRIVER::_accessMode = MED_EN::RDWR;
3549 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName,
3551 MED_MESH_DRIVER(fileName,ptrMesh,RDWR),
3552 IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),
3553 IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),
3554 IMED_MESH_RDWR_DRIVER(fileName,ptrMesh),
3555 MED_MESH_DRIVER22(fileName,ptrMesh,RDWR),
3556 MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh),
3557 MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh)
3560 MESSAGE_MED("MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
3563 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const MED_MESH_RDWR_DRIVER22 & driver):
3564 MED_MESH_DRIVER(driver),
3565 IMED_MESH_RDONLY_DRIVER(driver),
3566 IMED_MESH_WRONLY_DRIVER(driver),
3567 MED_MESH_DRIVER22(driver),
3568 MED_MESH_RDONLY_DRIVER22(driver),
3569 MED_MESH_WRONLY_DRIVER22(driver),
3570 IMED_MESH_RDWR_DRIVER(driver)
3575 MED_MESH_RDWR_DRIVER22::~MED_MESH_RDWR_DRIVER22() {
3576 //MESSAGE_MED("MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed");
3579 GENDRIVER * MED_MESH_RDWR_DRIVER22::copy(void) const
3581 return new MED_MESH_RDWR_DRIVER22(*this);
3584 void MED_MESH_RDWR_DRIVER22::write(void) const
3586 MED_MESH_WRONLY_DRIVER22::write();
3588 void MED_MESH_RDWR_DRIVER22::read (void)
3590 MED_MESH_RDONLY_DRIVER22::read();