]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_MedMeshDriver.cxx
Salome HOME
remove a reference to the $MED_ROOT_DIR in the Makefile.in wich is useless
[modules/med.git] / src / MEDMEM / MEDMEM_MedMeshDriver.cxx
1 #include "MEDMEM_MedMeshDriver.hxx"
2 #include "MEDMEM_MedMeshDriver21.hxx"
3 #include "MEDMEM_DriverFactory.hxx" 
4 #include "MEDMEM_DriversDef.hxx"
5
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"
13
14
15 using namespace std;
16 using namespace MEDMEM;
17 using namespace MED_EN;
18
19 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor 
20
21 MED_MESH_DRIVER::MED_MESH_DRIVER():
22   GENDRIVER(),
23   _ptrMesh(( MESH *)MED_NULL),
24   _meshName(""),
25   _meshNum(MED_INVALID)
26 {
27 }
28
29 MED_MESH_DRIVER::MED_MESH_DRIVER(const string & fileName,
30                                  MESH * ptrMesh,
31                                  MED_EN::med_mode_acces accessMode): 
32   GENDRIVER(fileName,accessMode),
33   _ptrMesh(ptrMesh), 
34   _meshName(""),
35   _meshNum(MED_INVALID)
36 {
37 }
38   
39 MED_MESH_DRIVER::MED_MESH_DRIVER(const MED_MESH_DRIVER & driver): 
40   GENDRIVER(driver),
41   _ptrMesh(driver._ptrMesh),
42   _meshName(driver._meshName),
43   _meshNum(driver._meshNum)
44 {
45
46 }
47
48 MED_MESH_DRIVER::~MED_MESH_DRIVER()
49 {
50   MESSAGE("MED_MESH_DRIVER::~MED_MESH_DRIVER()has been destroyed");
51
52 }
53
54 void MED_MESH_DRIVER::setMeshName(const string & meshName) 
55
56   _meshName = meshName; 
57 }
58
59 string  MED_MESH_DRIVER::getMeshName() const 
60
61   return _meshName; 
62 }
63
64 //---------------------------------- RDONLY PART -------------------------------------------------------------
65
66 IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(): MED_MESH_DRIVER()
67 {
68 }
69   
70 IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(const string & fileName,
71                                                  MESH * ptrMesh):
72   MED_MESH_DRIVER(fileName, ptrMesh, MED_EN::MED_RDONLY)
73
74   MESSAGE("IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
75 }
76   
77 IMED_MESH_RDONLY_DRIVER::IMED_MESH_RDONLY_DRIVER(const IMED_MESH_RDONLY_DRIVER & driver): 
78   MED_MESH_DRIVER(driver)
79 {
80 }
81
82 int IMED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity) 
83 {
84   const char * LOC = "MED_MESH_RDONLY_DRIVER::getDescendingConnectivity : " ;
85   if (_status==MED_OPENED)
86     {
87       MESSAGE(LOC<<"call on the object " << Connectivity);
88       MESSAGE(LOC<<"Not yet implemented !");
89     }
90   return MED_ERROR;
91 }
92
93 void IMED_MESH_RDONLY_DRIVER::buildAllGroups(vector<GROUP*> & Groups, vector<FAMILY*> & Families) 
94 {
95   const char * LOC = "MED_MESH_RDONLY_DRIVER::buildAllGroups " ;
96   BEGIN_OF(LOC);
97
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();
104     //SCRUTE(i);
105     //SCRUTE(numberOfGroups_);
106     for (int j=0; j<numberOfGroups_; j++) {
107       //SCRUTE(j);
108       //SCRUTE(myFamily->getGroupName(j+1));
109       groupsNames[myFamily->getGroupName(j+1)].push_back(myFamily);
110     }
111   }
112   int numberOfGroups = groupsNames.size() ;
113   SCRUTE(numberOfGroups);
114   Groups.resize(numberOfGroups);
115   map< string,list<FAMILY*> >::const_iterator currentGroup ;
116   int it = 0 ;
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);
124     Groups[it]=myGroup;
125     //SCRUTE(it);
126     it++;
127   }
128
129   END_OF(LOC);
130 }
131
132 void IMED_MESH_RDONLY_DRIVER::updateFamily()
133 {
134   const char * LOC = "MED_MESH_RDONLY_DRIVER::updateFamily() " ;
135   BEGIN_OF(LOC);
136
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
142
143   END_OF(LOC);
144 }
145
146
147 void IMED_MESH_RDONLY_DRIVER::write( void ) const
148 {
149   throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
150 }
151
152 /*--------------------- WRONLY PART -------------------------------*/
153
154 IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER():MED_MESH_DRIVER()
155 {
156 }
157   
158 IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER(const string & fileName,
159                                                MESH * ptrMesh):
160   MED_MESH_DRIVER(fileName,ptrMesh,MED_WRONLY)
161 {
162   MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
163 }
164
165 IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER(const IMED_MESH_WRONLY_DRIVER & driver): 
166   MED_MESH_DRIVER(driver)
167 {
168 }
169
170 IMED_MESH_WRONLY_DRIVER::~IMED_MESH_WRONLY_DRIVER()
171 {
172   //MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed");
173 }
174
175 void IMED_MESH_WRONLY_DRIVER::read (void)
176 {
177   throw MEDEXCEPTION("MED_MESH_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
178 }
179
180 /*--------------------- RDWR PART -------------------------------*/
181
182 IMED_MESH_RDWR_DRIVER::IMED_MESH_RDWR_DRIVER()
183 {
184 }
185
186 IMED_MESH_RDWR_DRIVER::IMED_MESH_RDWR_DRIVER(const string & fileName,
187                                            MESH * ptrMesh):
188    IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,MED_RDWR)
189 {
190   MESSAGE("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
191 }
192
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)
195 {
196 }
197
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");
200 }
201
202 /////////// Concrete MED_MESH_DRIVERS implementations
203
204 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER()
205 {
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();
208 }
209
210 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh)
211 {
212   _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_LECT);
213 }
214
215 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const MED_MESH_RDONLY_DRIVER & driver):MED_MESH_DRIVER(driver)
216 {
217   _concreteMeshDrv = driver._concreteMeshDrv->copy();
218 }
219
220 MED_MESH_RDONLY_DRIVER::~MED_MESH_RDONLY_DRIVER()
221 {
222   if (_concreteMeshDrv) delete _concreteMeshDrv;
223 }
224
225 void MED_MESH_RDONLY_DRIVER::write( void ) const
226 {
227   _concreteMeshDrv->write();
228 }
229
230 void MED_MESH_RDONLY_DRIVER::read ( void )
231 {
232   _concreteMeshDrv->read();
233 }
234
235 void MED_MESH_RDONLY_DRIVER::open()
236 {
237   _concreteMeshDrv->open();
238 }
239
240 void MED_MESH_RDONLY_DRIVER::close()
241 {
242   _concreteMeshDrv->close();
243 }
244
245 void MED_MESH_RDONLY_DRIVER::setMeshName(const string & meshName)
246 {
247   _concreteMeshDrv->setMeshName(meshName);
248 }
249
250 string MED_MESH_RDONLY_DRIVER::getMeshName() const
251 {
252   return MED_MESH_DRIVER::getMeshName();
253 }
254
255 GENDRIVER * MED_MESH_RDONLY_DRIVER::copy ( void ) const
256 {
257   return new MED_MESH_RDONLY_DRIVER(*this);
258 }
259
260 // int MED_MESH_RDONLY_DRIVER::getCOORDINATE()
261 // {
262 //   return _concreteMeshDrv->getCOORDINATE();
263 // }
264
265 // int MED_MESH_RDONLY_DRIVER::getCONNECTIVITY()
266 // {
267 //   return _concreteMeshDrv->getCONNECTIVITY();
268 // }
269
270 // int MED_MESH_RDONLY_DRIVER::getFAMILY()
271 // {
272 //   return _concreteMeshDrv->getFAMILY();
273 // }
274
275 // int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity)
276 // {
277 //   return _concreteMeshDrv->getNodalConnectivity(Connectivity);
278 // }
279
280 // int MED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
281 // {
282 //   return _concreteMeshDrv->getDescendingConnectivity(Connectivity);
283 // }
284
285 // int MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
286 // {
287 //   return _concreteMeshDrv->getNodesFamiliesNumber(MEDArrayNodeFamily);
288 // }
289
290 // int MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber(int** Arrays, CONNECTIVITY* Connectivity, MED_EN::medEntityMesh entity)
291 // {
292 //   return _concreteMeshDrv->getCellsFamiliesNumber(Arrays,Connectivity,entity);
293 // }
294
295 // void MED_MESH_RDONLY_DRIVER::getGRID()
296 // {
297 //   _concreteMeshDrv->getGRID();
298 // }
299
300 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER()
301 {
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();
304 }
305
306 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh)
307 {
308   _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_ECRI);
309 }
310
311 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver):MED_MESH_DRIVER(driver)
312 {
313   _concreteMeshDrv = driver._concreteMeshDrv->copy();
314 }
315
316 MED_MESH_WRONLY_DRIVER::~MED_MESH_WRONLY_DRIVER()
317 {
318   if (_concreteMeshDrv) delete _concreteMeshDrv;
319 }
320
321 void MED_MESH_WRONLY_DRIVER::open()
322 {
323   _concreteMeshDrv->open();
324 }
325
326 void MED_MESH_WRONLY_DRIVER::close()
327 {
328   _concreteMeshDrv->close();
329 }
330
331 void MED_MESH_WRONLY_DRIVER::setMeshName(const string & meshName)
332 {
333   _concreteMeshDrv->setMeshName(meshName);
334 }
335
336 string MED_MESH_WRONLY_DRIVER::getMeshName() const
337 {
338   return MED_MESH_DRIVER::getMeshName();
339 }
340
341 GENDRIVER * MED_MESH_WRONLY_DRIVER::copy ( void ) const
342 {
343   return new MED_MESH_WRONLY_DRIVER(*this);
344 }
345
346 void MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::read ( void )
347 {
348   _concreteMeshDrv->read();
349 }
350
351 void MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::write( void ) const
352 {
353   _concreteMeshDrv->write();
354 }
355
356 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeCoordinates    ()                           const
357 // {
358 //   return _concreteMeshDrv->writeCoordinates();
359 // }
360
361 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeConnectivities (MED_EN::medEntityMesh entity)       const
362 // {
363 //   return _concreteMeshDrv->writeConnectivities(entity);
364 // }
365
366 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeFamilyNumbers  ()                           const
367 // {
368 //   return _concreteMeshDrv->writeFamilyNumbers();
369 // }
370
371 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeFamilies       (vector<FAMILY*> & families) const
372 // {
373 //   return _concreteMeshDrv->writeFamilies(families);
374 // }
375
376 // int MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::writeGRID() const
377 // {
378 //   return _concreteMeshDrv->writeGRID();
379 // }
380
381 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER()
382 {
383   _concreteMeshDrv=new MED_MESH_RDWR_DRIVER21();
384 }
385
386 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh)
387 {
388   _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_REMP);
389 }
390
391 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const MED_MESH_RDWR_DRIVER & driver): MED_MESH_DRIVER(driver)
392 {
393   _concreteMeshDrv = driver._concreteMeshDrv->copy();
394 }
395
396 MED_MESH_RDWR_DRIVER::~MED_MESH_RDWR_DRIVER()
397 {
398   if (_concreteMeshDrv) delete _concreteMeshDrv;
399 }
400
401 void MED_MESH_RDWR_DRIVER::read ( void )
402 {
403   _concreteMeshDrv->read();
404 }
405
406 void MED_MESH_RDWR_DRIVER::write( void ) const
407 {
408   _concreteMeshDrv->write();
409 }
410  
411 void MED_MESH_RDWR_DRIVER::open()
412 {
413   _concreteMeshDrv->open();
414 }
415
416 void MED_MESH_RDWR_DRIVER::close()
417 {
418   _concreteMeshDrv->close();
419 }
420
421 // int MED_MESH_RDWR_DRIVER::getCOORDINATE()
422 // {
423 //   return _concreteMeshDrv->getCOORDINATE();
424 // }
425
426 // int MED_MESH_RDWR_DRIVER::getCONNECTIVITY()
427 // {
428 //   return _concreteMeshDrv->getCONNECTIVITY();
429 // }
430
431 // int MED_MESH_RDWR_DRIVER::getFAMILY()
432 // {
433 //   return _concreteMeshDrv->getFAMILY();
434 // }
435
436 // int MED_MESH_RDWR_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity)
437 // {
438 //   return _concreteMeshDrv->getNodalConnectivity(Connectivity);
439 // }
440
441 // int MED_MESH_RDWR_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity)
442 // {
443 //   return _concreteMeshDrv->getDescendingConnectivity(Connectivity);
444 // }
445  
446 // int MED_MESH_RDWR_DRIVER::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
447 // {
448 //   return _concreteMeshDrv->getNodesFamiliesNumber(MEDArrayNodeFamily);
449 // }
450
451 // int MED_MESH_RDWR_DRIVER::getCellsFamiliesNumber(int** Arrays, CONNECTIVITY* Connectivity, MED_EN::medEntityMesh entity)
452 // {
453 //   return _concreteMeshDrv->getCellsFamiliesNumber(Arrays,Connectivity,entity);
454 // }
455
456 // void MED_MESH_RDWR_DRIVER::getGRID ()
457 // {
458 //   _concreteMeshDrv->getGRID();
459 // }
460
461 // int MED_MESH_RDWR_DRIVER::writeCoordinates    ()                           const
462 // {
463 //   _concreteMeshDrv->writeCoordinates();
464 // }
465
466 // int MED_MESH_RDWR_DRIVER::writeConnectivities (MED_EN::medEntityMesh entity)       const
467 // {
468 //   return _concreteMeshDrv->writeConnectivities (entity);
469 // }
470
471 // int MED_MESH_RDWR_DRIVER::writeFamilyNumbers  ()                           const
472 // {
473 //   return _concreteMeshDrv->writeFamilyNumbers();
474 // }
475
476 // int MED_MESH_RDWR_DRIVER::writeFamilies       (vector<FAMILY*> & families) const
477 // {
478 //   return _concreteMeshDrv->writeFamilies(families);
479 // }
480
481 // int MED_MESH_RDWR_DRIVER::writeGRID() const
482 // {
483 //   return _concreteMeshDrv->writeGRID();
484 // }
485
486 void MED_MESH_RDWR_DRIVER::setMeshName(const string & meshName)
487 {
488   _concreteMeshDrv->setMeshName(meshName);
489 }
490
491 string MED_MESH_RDWR_DRIVER::getMeshName() const
492 {
493   return MED_MESH_DRIVER::getMeshName();
494 }
495
496 GENDRIVER * MED_MESH_RDWR_DRIVER::copy ( void ) const
497 {
498   return new MED_MESH_RDWR_DRIVER(*this);
499 }