1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 #include "MEDMEM_MedMeshDriver.hxx"
21 #include "MEDMEM_MedMeshDriver21.hxx"
22 #include "MEDMEM_DriverFactory.hxx"
23 #include "MEDMEM_DriversDef.hxx"
25 #include "MEDMEM_Family.hxx"
26 #include "MEDMEM_Group.hxx"
27 #include "MEDMEM_Coordinate.hxx"
28 #include "MEDMEM_Connectivity.hxx"
29 #include "MEDMEM_Mesh.hxx"
30 #include "MEDMEM_CellModel.hxx"
31 #include "MEDMEM_Grid.hxx"
35 using namespace MEDMEM;
36 using namespace MED_EN;
38 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor
40 MED_MESH_DRIVER::MED_MESH_DRIVER():
42 _ptrMesh(( MESH *)MED_NULL),
48 MED_MESH_DRIVER::MED_MESH_DRIVER(const string & fileName,
50 MED_EN::med_mode_acces accessMode):
51 GENDRIVER(fileName,accessMode),
58 MED_MESH_DRIVER::MED_MESH_DRIVER(const MED_MESH_DRIVER & driver):
60 _ptrMesh(driver._ptrMesh),
61 _meshName(driver._meshName),
62 _meshNum(driver._meshNum)
67 MED_MESH_DRIVER::~MED_MESH_DRIVER()
69 MESSAGE("MED_MESH_DRIVER::~MED_MESH_DRIVER()has been destroyed");
73 void MED_MESH_DRIVER::setMeshName(const string & meshName)
78 string MED_MESH_DRIVER::getMeshName() const
83 //---------------------------------- RDONLY PART -------------------------------------------------------------
85 IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(): MED_MESH_DRIVER()
89 IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(const string & fileName,
91 MED_MESH_DRIVER(fileName, ptrMesh, MED_EN::MED_RDONLY)
93 MESSAGE("IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
96 IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(const IMED_MESH_RDONLY_DRIVER & driver):
97 MED_MESH_DRIVER(driver)
101 int IMED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
103 const char * LOC = "MED_MESH_RDONLY_DRIVER::getDescendingConnectivity : " ;
104 if (_status==MED_OPENED)
106 MESSAGE(LOC<<"call on the object " << Connectivity);
107 MESSAGE(LOC<<"Not yet implemented !");
112 void IMED_MESH_RDONLY_DRIVER::buildAllGroups(vector<GROUP*> & Groups, vector<FAMILY*> & Families)
114 const char * LOC = "MED_MESH_RDONLY_DRIVER::buildAllGroups " ;
117 int numberOfFamilies = Families.size() ;
118 //SCRUTE(numberOfFamilies);
119 map< string,list<FAMILY*> > groupsNames ;
120 for(int i=0; i<numberOfFamilies; i++) {
121 FAMILY * myFamily = Families[i] ;
122 int numberOfGroups_ = myFamily->getNumberOfGroups();
124 //SCRUTE(numberOfGroups_);
125 for (int j=0; j<numberOfGroups_; j++) {
127 //SCRUTE(myFamily->getGroupName(j+1));
128 groupsNames[myFamily->getGroupName(j+1)].push_back(myFamily);
131 int numberOfGroups = groupsNames.size() ;
132 SCRUTE(numberOfGroups);
133 Groups.resize(numberOfGroups);
134 map< string,list<FAMILY*> >::const_iterator currentGroup ;
136 for(currentGroup=groupsNames.begin();currentGroup!=groupsNames.end();currentGroup++) {
137 GROUP * myGroup = new GROUP((*currentGroup).first,(*currentGroup).second) ;
138 // GROUP * myGroup = new GROUP() ;
139 // myGroup->setName((*currentGroup).first);
140 // SCRUTE(myGroup->getName());
141 // //myGroup->setMesh(_ptrMesh);
142 // myGroup->init((*currentGroup).second);
151 void IMED_MESH_RDONLY_DRIVER::updateFamily()
153 const char * LOC = "MED_MESH_RDONLY_DRIVER::updateFamily() " ;
156 // we need to update family on constituent if we have constituent, but no
157 // descending connectivity, so, we must calculate all constituent and
158 // numbering correctly family !
159 _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyFace) ; // in 2d, do nothing
160 _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyEdge) ; // in 3d, do nothing
166 void IMED_MESH_RDONLY_DRIVER::write( void ) const
168 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
171 /*--------------------- WRONLY PART -------------------------------*/
173 IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER():MED_MESH_DRIVER()
177 IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER(const string & fileName,
179 MED_MESH_DRIVER(fileName,ptrMesh,MED_WRONLY)
181 MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
184 IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER(const IMED_MESH_WRONLY_DRIVER & driver):
185 MED_MESH_DRIVER(driver)
189 IMED_MESH_WRONLY_DRIVER::~IMED_MESH_WRONLY_DRIVER()
191 //MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed");
194 void IMED_MESH_WRONLY_DRIVER::read (void)
196 throw MEDEXCEPTION("MED_MESH_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
199 /*--------------------- RDWR PART -------------------------------*/
201 IMED_MESH_RDWR_DRIVER::IMED_MESH_RDWR_DRIVER()
205 IMED_MESH_RDWR_DRIVER::IMED_MESH_RDWR_DRIVER(const string & fileName,
207 IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,MED_RDWR)
209 MESSAGE("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
212 IMED_MESH_RDWR_DRIVER::IMED_MESH_RDWR_DRIVER(const IMED_MESH_RDWR_DRIVER & driver):
213 IMED_MESH_RDONLY_DRIVER(driver),IMED_MESH_WRONLY_DRIVER(driver),MED_MESH_DRIVER(driver)
217 IMED_MESH_RDWR_DRIVER::~IMED_MESH_RDWR_DRIVER() {
218 //MESSAGE("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed");
221 /////////// Concrete MED_MESH_DRIVERS implementations
223 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER()
225 MESSAGE("You are using the default constructor of the Mesh read only Driver and it is 2.1 one");
226 _concreteMeshDrv = new MED_MESH_RDONLY_DRIVER21();
229 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh)
231 _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_LECT);
234 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const MED_MESH_RDONLY_DRIVER & driver):MED_MESH_DRIVER(driver)
236 _concreteMeshDrv = driver._concreteMeshDrv->copy();
239 MED_MESH_RDONLY_DRIVER::~MED_MESH_RDONLY_DRIVER()
241 if (_concreteMeshDrv) delete _concreteMeshDrv;
244 void MED_MESH_RDONLY_DRIVER::write( void ) const
246 _concreteMeshDrv->write();
249 void MED_MESH_RDONLY_DRIVER::read ( void )
251 _concreteMeshDrv->read();
254 void MED_MESH_RDONLY_DRIVER::open()
256 _concreteMeshDrv->open();
259 void MED_MESH_RDONLY_DRIVER::close()
261 _concreteMeshDrv->close();
264 void MED_MESH_RDONLY_DRIVER::setMeshName(const string & meshName)
266 _concreteMeshDrv->setMeshName(meshName);
269 string MED_MESH_RDONLY_DRIVER::getMeshName() const
271 return MED_MESH_DRIVER::getMeshName();
274 GENDRIVER * MED_MESH_RDONLY_DRIVER::copy ( void ) const
276 return new MED_MESH_RDONLY_DRIVER(*this);
279 // int MED_MESH_RDONLY_DRIVER::getCOORDINATE()
281 // return _concreteMeshDrv->getCOORDINATE();
284 // int MED_MESH_RDONLY_DRIVER::getCONNECTIVITY()
286 // return _concreteMeshDrv->getCONNECTIVITY();
289 // int MED_MESH_RDONLY_DRIVER::getFAMILY()
291 // return _concreteMeshDrv->getFAMILY();
294 // int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity)
296 // return _concreteMeshDrv->getNodalConnectivity(Connectivity);
299 // int MED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
301 // return _concreteMeshDrv->getDescendingConnectivity(Connectivity);
304 // int MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
306 // return _concreteMeshDrv->getNodesFamiliesNumber(MEDArrayNodeFamily);
309 // int MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber(int** Arrays, CONNECTIVITY* Connectivity, MED_EN::medEntityMesh entity)
311 // return _concreteMeshDrv->getCellsFamiliesNumber(Arrays,Connectivity,entity);
314 // void MED_MESH_RDONLY_DRIVER::getGRID()
316 // _concreteMeshDrv->getGRID();
319 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER()
321 MESSAGE("You are using the default constructor of the Mesh write only Driver and it is 2.1 one");
322 _concreteMeshDrv = new MED_MESH_WRONLY_DRIVER21();
325 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh)
327 _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_ECRI);
330 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver):MED_MESH_DRIVER(driver)
332 _concreteMeshDrv = driver._concreteMeshDrv->copy();
335 MED_MESH_WRONLY_DRIVER::~MED_MESH_WRONLY_DRIVER()
337 if (_concreteMeshDrv) delete _concreteMeshDrv;
340 void MED_MESH_WRONLY_DRIVER::open()
342 _concreteMeshDrv->open();
345 void MED_MESH_WRONLY_DRIVER::close()
347 _concreteMeshDrv->close();
350 void MED_MESH_WRONLY_DRIVER::setMeshName(const string & meshName)
352 _concreteMeshDrv->setMeshName(meshName);
355 string MED_MESH_WRONLY_DRIVER::getMeshName() const
357 return MED_MESH_DRIVER::getMeshName();
360 GENDRIVER * MED_MESH_WRONLY_DRIVER::copy ( void ) const
362 return new MED_MESH_WRONLY_DRIVER(*this);
365 void MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::read ( void )
367 _concreteMeshDrv->read();
370 void MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::write( void ) const
372 _concreteMeshDrv->write();
375 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeCoordinates () const
377 // return _concreteMeshDrv->writeCoordinates();
380 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeConnectivities (MED_EN::medEntityMesh entity) const
382 // return _concreteMeshDrv->writeConnectivities(entity);
385 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeFamilyNumbers () const
387 // return _concreteMeshDrv->writeFamilyNumbers();
390 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeFamilies (vector<FAMILY*> & families) const
392 // return _concreteMeshDrv->writeFamilies(families);
395 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeGRID() const
397 // return _concreteMeshDrv->writeGRID();
400 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER()
402 _concreteMeshDrv=new MED_MESH_RDWR_DRIVER21();
405 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh)
407 _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_REMP);
410 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const MED_MESH_RDWR_DRIVER & driver): MED_MESH_DRIVER(driver)
412 _concreteMeshDrv = driver._concreteMeshDrv->copy();
415 MED_MESH_RDWR_DRIVER::~MED_MESH_RDWR_DRIVER()
417 if (_concreteMeshDrv) delete _concreteMeshDrv;
420 void MED_MESH_RDWR_DRIVER::read ( void )
422 _concreteMeshDrv->read();
425 void MED_MESH_RDWR_DRIVER::write( void ) const
427 _concreteMeshDrv->write();
430 void MED_MESH_RDWR_DRIVER::open()
432 _concreteMeshDrv->open();
435 void MED_MESH_RDWR_DRIVER::close()
437 _concreteMeshDrv->close();
440 // int MED_MESH_RDWR_DRIVER::getCOORDINATE()
442 // return _concreteMeshDrv->getCOORDINATE();
445 // int MED_MESH_RDWR_DRIVER::getCONNECTIVITY()
447 // return _concreteMeshDrv->getCONNECTIVITY();
450 // int MED_MESH_RDWR_DRIVER::getFAMILY()
452 // return _concreteMeshDrv->getFAMILY();
455 // int MED_MESH_RDWR_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity)
457 // return _concreteMeshDrv->getNodalConnectivity(Connectivity);
460 // int MED_MESH_RDWR_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
462 // return _concreteMeshDrv->getDescendingConnectivity(Connectivity);
465 // int MED_MESH_RDWR_DRIVER::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
467 // return _concreteMeshDrv->getNodesFamiliesNumber(MEDArrayNodeFamily);
470 // int MED_MESH_RDWR_DRIVER::getCellsFamiliesNumber(int** Arrays, CONNECTIVITY* Connectivity, MED_EN::medEntityMesh entity)
472 // return _concreteMeshDrv->getCellsFamiliesNumber(Arrays,Connectivity,entity);
475 // void MED_MESH_RDWR_DRIVER::getGRID ()
477 // _concreteMeshDrv->getGRID();
480 // int MED_MESH_RDWR_DRIVER::writeCoordinates () const
482 // _concreteMeshDrv->writeCoordinates();
485 // int MED_MESH_RDWR_DRIVER::writeConnectivities (MED_EN::medEntityMesh entity) const
487 // return _concreteMeshDrv->writeConnectivities (entity);
490 // int MED_MESH_RDWR_DRIVER::writeFamilyNumbers () const
492 // return _concreteMeshDrv->writeFamilyNumbers();
495 // int MED_MESH_RDWR_DRIVER::writeFamilies (vector<FAMILY*> & families) const
497 // return _concreteMeshDrv->writeFamilies(families);
500 // int MED_MESH_RDWR_DRIVER::writeGRID() const
502 // return _concreteMeshDrv->writeGRID();
505 void MED_MESH_RDWR_DRIVER::setMeshName(const string & meshName)
507 _concreteMeshDrv->setMeshName(meshName);
510 string MED_MESH_RDWR_DRIVER::getMeshName() const
512 return MED_MESH_DRIVER::getMeshName();
515 GENDRIVER * MED_MESH_RDWR_DRIVER::copy ( void ) const
517 return new MED_MESH_RDWR_DRIVER(*this);