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