1 #include "MEDMEM_MedMeshDriver.hxx"
2 #include "MEDMEM_MedMeshDriver21.hxx"
3 #include "MEDMEM_DriverFactory.hxx"
4 #include "MEDMEM_DriversDef.hxx"
6 #include "MEDMEM_Family.hxx"
7 #include "MEDMEM_Group.hxx"
8 #include "MEDMEM_Coordinate.hxx"
9 #include "MEDMEM_Connectivity.hxx"
10 #include "MEDMEM_Mesh.hxx"
11 #include "MEDMEM_CellModel.hxx"
12 #include "MEDMEM_Grid.hxx"
16 using namespace MEDMEM;
17 using namespace MED_EN;
19 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor
21 MED_MESH_DRIVER::MED_MESH_DRIVER():
23 _ptrMesh(( MESH *)MED_NULL),
29 MED_MESH_DRIVER::MED_MESH_DRIVER(const string & fileName,
31 MED_EN::med_mode_acces accessMode):
32 GENDRIVER(fileName,accessMode),
39 MED_MESH_DRIVER::MED_MESH_DRIVER(const MED_MESH_DRIVER & driver):
41 _ptrMesh(driver._ptrMesh),
42 _meshName(driver._meshName),
43 _meshNum(driver._meshNum)
48 MED_MESH_DRIVER::~MED_MESH_DRIVER()
50 MESSAGE("MED_MESH_DRIVER::~MED_MESH_DRIVER()has been destroyed");
54 void MED_MESH_DRIVER::setMeshName(const string & meshName)
59 string MED_MESH_DRIVER::getMeshName() const
64 //---------------------------------- RDONLY PART -------------------------------------------------------------
66 IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(): MED_MESH_DRIVER()
70 IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(const string & fileName,
72 MED_MESH_DRIVER(fileName, ptrMesh, MED_EN::MED_RDONLY)
74 MESSAGE("IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
77 IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(const IMED_MESH_RDONLY_DRIVER & driver):
78 MED_MESH_DRIVER(driver)
82 int IMED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
84 const char * LOC = "MED_MESH_RDONLY_DRIVER::getDescendingConnectivity : " ;
85 if (_status==MED_OPENED)
87 MESSAGE(LOC<<"call on the object " << Connectivity);
88 MESSAGE(LOC<<"Not yet implemented !");
93 void IMED_MESH_RDONLY_DRIVER::buildAllGroups(vector<GROUP*> & Groups, vector<FAMILY*> & Families)
95 const char * LOC = "MED_MESH_RDONLY_DRIVER::buildAllGroups " ;
98 int numberOfFamilies = Families.size() ;
99 //SCRUTE(numberOfFamilies);
100 map< string,list<FAMILY*> > groupsNames ;
101 for(int i=0; i<numberOfFamilies; i++) {
102 FAMILY * myFamily = Families[i] ;
103 int numberOfGroups_ = myFamily->getNumberOfGroups();
105 //SCRUTE(numberOfGroups_);
106 for (int j=0; j<numberOfGroups_; j++) {
108 //SCRUTE(myFamily->getGroupName(j+1));
109 groupsNames[myFamily->getGroupName(j+1)].push_back(myFamily);
112 int numberOfGroups = groupsNames.size() ;
113 SCRUTE(numberOfGroups);
114 Groups.resize(numberOfGroups);
115 map< string,list<FAMILY*> >::const_iterator currentGroup ;
117 for(currentGroup=groupsNames.begin();currentGroup!=groupsNames.end();currentGroup++) {
118 GROUP * myGroup = new GROUP((*currentGroup).first,(*currentGroup).second) ;
119 // GROUP * myGroup = new GROUP() ;
120 // myGroup->setName((*currentGroup).first);
121 // SCRUTE(myGroup->getName());
122 // //myGroup->setMesh(_ptrMesh);
123 // myGroup->init((*currentGroup).second);
132 void IMED_MESH_RDONLY_DRIVER::updateFamily()
134 const char * LOC = "MED_MESH_RDONLY_DRIVER::updateFamily() " ;
137 // we need to update family on constituent if we have constituent, but no
138 // descending connectivity, so, we must calculate all constituent and
139 // numbering correctly family !
140 _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyFace) ; // in 2d, do nothing
141 _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyEdge) ; // in 3d, do nothing
147 void IMED_MESH_RDONLY_DRIVER::write( void ) const
149 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
152 /*--------------------- WRONLY PART -------------------------------*/
154 IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER():MED_MESH_DRIVER()
158 IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER(const string & fileName,
160 MED_MESH_DRIVER(fileName,ptrMesh,MED_WRONLY)
162 MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
165 IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER(const IMED_MESH_WRONLY_DRIVER & driver):
166 MED_MESH_DRIVER(driver)
170 IMED_MESH_WRONLY_DRIVER::~IMED_MESH_WRONLY_DRIVER()
172 //MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed");
175 void IMED_MESH_WRONLY_DRIVER::read (void)
177 throw MEDEXCEPTION("MED_MESH_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
180 /*--------------------- RDWR PART -------------------------------*/
182 IMED_MESH_RDWR_DRIVER::IMED_MESH_RDWR_DRIVER()
186 IMED_MESH_RDWR_DRIVER::IMED_MESH_RDWR_DRIVER(const string & fileName,
188 IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,MED_RDWR)
190 MESSAGE("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
193 IMED_MESH_RDWR_DRIVER::IMED_MESH_RDWR_DRIVER(const IMED_MESH_RDWR_DRIVER & driver):
194 IMED_MESH_RDONLY_DRIVER(driver),IMED_MESH_WRONLY_DRIVER(driver),MED_MESH_DRIVER(driver)
198 IMED_MESH_RDWR_DRIVER::~IMED_MESH_RDWR_DRIVER() {
199 //MESSAGE("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed");
202 /////////// Concrete MED_MESH_DRIVERS implementations
204 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER()
206 MESSAGE("You are using the default constructor of the Mesh read only Driver and it is 2.1 one");
207 _concreteMeshDrv = new MED_MESH_RDONLY_DRIVER21();
210 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh)
212 _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_LECT);
215 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const MED_MESH_RDONLY_DRIVER & driver):MED_MESH_DRIVER(driver)
217 _concreteMeshDrv = driver._concreteMeshDrv->copy();
220 MED_MESH_RDONLY_DRIVER::~MED_MESH_RDONLY_DRIVER()
222 if (_concreteMeshDrv) delete _concreteMeshDrv;
225 void MED_MESH_RDONLY_DRIVER::write( void ) const
227 _concreteMeshDrv->write();
230 void MED_MESH_RDONLY_DRIVER::read ( void )
232 _concreteMeshDrv->read();
235 void MED_MESH_RDONLY_DRIVER::open()
237 _concreteMeshDrv->open();
240 void MED_MESH_RDONLY_DRIVER::close()
242 _concreteMeshDrv->close();
245 void MED_MESH_RDONLY_DRIVER::setMeshName(const string & meshName)
247 _concreteMeshDrv->setMeshName(meshName);
250 string MED_MESH_RDONLY_DRIVER::getMeshName() const
252 return MED_MESH_DRIVER::getMeshName();
255 GENDRIVER * MED_MESH_RDONLY_DRIVER::copy ( void ) const
257 return new MED_MESH_RDONLY_DRIVER(*this);
260 // int MED_MESH_RDONLY_DRIVER::getCOORDINATE()
262 // return _concreteMeshDrv->getCOORDINATE();
265 // int MED_MESH_RDONLY_DRIVER::getCONNECTIVITY()
267 // return _concreteMeshDrv->getCONNECTIVITY();
270 // int MED_MESH_RDONLY_DRIVER::getFAMILY()
272 // return _concreteMeshDrv->getFAMILY();
275 // int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity)
277 // return _concreteMeshDrv->getNodalConnectivity(Connectivity);
280 // int MED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
282 // return _concreteMeshDrv->getDescendingConnectivity(Connectivity);
285 // int MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
287 // return _concreteMeshDrv->getNodesFamiliesNumber(MEDArrayNodeFamily);
290 // int MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber(int** Arrays, CONNECTIVITY* Connectivity, MED_EN::medEntityMesh entity)
292 // return _concreteMeshDrv->getCellsFamiliesNumber(Arrays,Connectivity,entity);
295 // void MED_MESH_RDONLY_DRIVER::getGRID()
297 // _concreteMeshDrv->getGRID();
300 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER()
302 MESSAGE("You are using the default constructor of the Mesh write only Driver and it is 2.1 one");
303 _concreteMeshDrv = new MED_MESH_WRONLY_DRIVER21();
306 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh)
308 _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_ECRI);
311 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver):MED_MESH_DRIVER(driver)
313 _concreteMeshDrv = driver._concreteMeshDrv->copy();
316 MED_MESH_WRONLY_DRIVER::~MED_MESH_WRONLY_DRIVER()
318 if (_concreteMeshDrv) delete _concreteMeshDrv;
321 void MED_MESH_WRONLY_DRIVER::open()
323 _concreteMeshDrv->open();
326 void MED_MESH_WRONLY_DRIVER::close()
328 _concreteMeshDrv->close();
331 void MED_MESH_WRONLY_DRIVER::setMeshName(const string & meshName)
333 _concreteMeshDrv->setMeshName(meshName);
336 string MED_MESH_WRONLY_DRIVER::getMeshName() const
338 return MED_MESH_DRIVER::getMeshName();
341 GENDRIVER * MED_MESH_WRONLY_DRIVER::copy ( void ) const
343 return new MED_MESH_WRONLY_DRIVER(*this);
346 void MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::read ( void )
348 _concreteMeshDrv->read();
351 void MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::write( void ) const
353 _concreteMeshDrv->write();
356 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeCoordinates () const
358 // return _concreteMeshDrv->writeCoordinates();
361 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeConnectivities (MED_EN::medEntityMesh entity) const
363 // return _concreteMeshDrv->writeConnectivities(entity);
366 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeFamilyNumbers () const
368 // return _concreteMeshDrv->writeFamilyNumbers();
371 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeFamilies (vector<FAMILY*> & families) const
373 // return _concreteMeshDrv->writeFamilies(families);
376 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeGRID() const
378 // return _concreteMeshDrv->writeGRID();
381 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER()
383 _concreteMeshDrv=new MED_MESH_RDWR_DRIVER21();
386 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh)
388 _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_REMP);
391 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const MED_MESH_RDWR_DRIVER & driver): MED_MESH_DRIVER(driver)
393 _concreteMeshDrv = driver._concreteMeshDrv->copy();
396 MED_MESH_RDWR_DRIVER::~MED_MESH_RDWR_DRIVER()
398 if (_concreteMeshDrv) delete _concreteMeshDrv;
401 void MED_MESH_RDWR_DRIVER::read ( void )
403 _concreteMeshDrv->read();
406 void MED_MESH_RDWR_DRIVER::write( void ) const
408 _concreteMeshDrv->write();
411 void MED_MESH_RDWR_DRIVER::open()
413 _concreteMeshDrv->open();
416 void MED_MESH_RDWR_DRIVER::close()
418 _concreteMeshDrv->close();
421 // int MED_MESH_RDWR_DRIVER::getCOORDINATE()
423 // return _concreteMeshDrv->getCOORDINATE();
426 // int MED_MESH_RDWR_DRIVER::getCONNECTIVITY()
428 // return _concreteMeshDrv->getCONNECTIVITY();
431 // int MED_MESH_RDWR_DRIVER::getFAMILY()
433 // return _concreteMeshDrv->getFAMILY();
436 // int MED_MESH_RDWR_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity)
438 // return _concreteMeshDrv->getNodalConnectivity(Connectivity);
441 // int MED_MESH_RDWR_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
443 // return _concreteMeshDrv->getDescendingConnectivity(Connectivity);
446 // int MED_MESH_RDWR_DRIVER::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
448 // return _concreteMeshDrv->getNodesFamiliesNumber(MEDArrayNodeFamily);
451 // int MED_MESH_RDWR_DRIVER::getCellsFamiliesNumber(int** Arrays, CONNECTIVITY* Connectivity, MED_EN::medEntityMesh entity)
453 // return _concreteMeshDrv->getCellsFamiliesNumber(Arrays,Connectivity,entity);
456 // void MED_MESH_RDWR_DRIVER::getGRID ()
458 // _concreteMeshDrv->getGRID();
461 // int MED_MESH_RDWR_DRIVER::writeCoordinates () const
463 // _concreteMeshDrv->writeCoordinates();
466 // int MED_MESH_RDWR_DRIVER::writeConnectivities (MED_EN::medEntityMesh entity) const
468 // return _concreteMeshDrv->writeConnectivities (entity);
471 // int MED_MESH_RDWR_DRIVER::writeFamilyNumbers () const
473 // return _concreteMeshDrv->writeFamilyNumbers();
476 // int MED_MESH_RDWR_DRIVER::writeFamilies (vector<FAMILY*> & families) const
478 // return _concreteMeshDrv->writeFamilies(families);
481 // int MED_MESH_RDWR_DRIVER::writeGRID() const
483 // return _concreteMeshDrv->writeGRID();
486 void MED_MESH_RDWR_DRIVER::setMeshName(const string & meshName)
488 _concreteMeshDrv->setMeshName(meshName);
491 string MED_MESH_RDWR_DRIVER::getMeshName() const
493 return MED_MESH_DRIVER::getMeshName();
496 GENDRIVER * MED_MESH_RDWR_DRIVER::copy ( void ) const
498 return new MED_MESH_RDWR_DRIVER(*this);