00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef GIBI_MESH_DRIVER_HXX
00024 #define GIBI_MESH_DRIVER_HXX
00025
00026 #include <MEDMEM.hxx>
00027
00028 #include <string>
00029 #include <vector>
00030 #include <map>
00031 #include <fstream>
00032 #include <list>
00033
00034 #include "MEDMEM_define.hxx"
00035 #include "MEDMEM_GenDriver.hxx"
00036
00037 #include "MEDMEM_STRING.hxx"
00038 #include "MEDMEM_Exception.hxx"
00039 #include "MEDMEM_Utilities.hxx"
00040
00041 #include "MEDMEM_FieldForward.hxx"
00042
00044 #include <sstream>
00045 #include <iomanip>
00047
00048 #ifdef WNT
00049 #else
00050 #define HAS_XDR
00051 #endif
00052
00061 namespace MEDMEM {
00062 class GMESH;
00063 class MESH;
00064 class FAMILY;
00065 class GROUP;
00066 class SUPPORT;
00067 class CONNECTIVITY;
00068 class FIELD_;
00069 struct _intermediateMED;
00070
00071
00072 struct nameGIBItoMED {
00073
00074 int gibi_pile;
00075 int gibi_id;
00076 string gibi_name;
00077
00078
00079 int med_id;
00080 string med_name;
00081 };
00082
00083 class MEDMEM_EXPORT GIBI_MESH_DRIVER : public GENDRIVER
00084 {
00085 protected:
00086
00087 GMESH * _mesh;
00088 std::string _meshName;
00089
00090
00091
00092 enum
00093 {
00094 nb_geometrie_gibi = 47
00095 };
00096
00097
00098 static const MED_EN::medGeometryElement geomGIBItoMED[nb_geometrie_gibi];
00100
00101 public :
00102
00106 GIBI_MESH_DRIVER() ;
00110 GIBI_MESH_DRIVER(const string & fileName,
00111 GMESH * ptrMesh,
00112 MED_EN::med_mode_acces accessMode) ;
00116 GIBI_MESH_DRIVER(const GIBI_MESH_DRIVER & driver) ;
00117
00121 virtual ~GIBI_MESH_DRIVER() ;
00122
00123 virtual void write( void ) const = 0 ;
00124 virtual void read ( void ) = 0 ;
00125
00131 void setMeshName(const string & meshName) ;
00135 string getMeshName() const ;
00136
00137 static MED_EN::medGeometryElement gibi2medGeom( size_t gibiTypeNb );
00138 static int med2gibiGeom( MED_EN::medGeometryElement medGeomType );
00139
00140 private:
00141 virtual GENDRIVER * copy ( void ) const = 0 ;
00142
00143 };
00144
00145
00146 class MEDMEM_EXPORT GIBI_MESH_RDONLY_DRIVER : public virtual GIBI_MESH_DRIVER
00147 {
00148 public :
00149
00153 GIBI_MESH_RDONLY_DRIVER() ;
00157 GIBI_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
00161 GIBI_MESH_RDONLY_DRIVER(const GIBI_MESH_RDONLY_DRIVER & driver) ;
00162
00166 virtual ~GIBI_MESH_RDONLY_DRIVER() ;
00167
00171 void write( void ) const throw (MEDEXCEPTION);
00175 void read ( void ) throw (MEDEXCEPTION);
00176
00177 void open();
00178 void close();
00179
00180 protected:
00181
00182 bool readFile(_intermediateMED* medi, bool readFields );
00183
00184 void fillMesh(_intermediateMED* medi);
00185
00186 void updateSupports();
00187
00188 private:
00189
00190 GENDRIVER * copy ( void ) const ;
00191
00192
00193
00194 bool getLine(char* & line);
00195 bool getNextLine (char* & line, bool raiseIfNot = true ) throw (MEDEXCEPTION)
00196 {
00197 if ( getLine( line )) return true;
00198 if ( raiseIfNot ) throw MEDEXCEPTION(LOCALIZED(STRING("Unexpected EOF on ln ")<<_lineNb));
00199 return false;
00200 }
00201 void initNameReading(int nbValues, int width = 8);
00202 void initIntReading(int nbValues);
00203 void initDoubleReading(int nbValues);
00204 void init( int nbToRead, int nbPosInLine, int width, int shift = 0 );
00205 bool more() const;
00206 void next();
00207 char* str() const { return _curPos; }
00208 int index() const { return _iRead; }
00209 int getInt() const;
00210 float getFloat() const;
00211 double getDouble() const;
00212 string getName() const;
00213
00214
00215 int _File;
00216 char* _start;
00217 char* _ptr;
00218 char* _eptr;
00219 int _lineNb;
00220
00221
00222 int _iPos, _nbPosInLine, _width, _shift;
00223 int _iRead, _nbToRead;
00224 char* _curPos;
00225
00226
00227 #ifdef HAS_XDR
00228 bool _is_xdr;
00229 FILE* _xdrs_file;
00230 void* _xdrs;
00231 char* _xdr_cvals;
00232 int* _xdr_ivals;
00233 double* _xdr_dvals;
00234 int _xdr_kind;
00235 enum
00236 {
00237 _xdr_kind_null,
00238 _xdr_kind_char,
00239 _xdr_kind_int,
00240 _xdr_kind_double
00241 };
00242 #endif
00243 };
00244
00253 class MEDMEM_EXPORT GIBI_MESH_WRONLY_DRIVER : public virtual GIBI_MESH_DRIVER {
00254
00255 public :
00256
00260 GIBI_MESH_WRONLY_DRIVER() ;
00264 GIBI_MESH_WRONLY_DRIVER(const string & fileName, GMESH * ptrMesh) ;
00268 GIBI_MESH_WRONLY_DRIVER(const GIBI_MESH_WRONLY_DRIVER & driver) ;
00269
00273 virtual ~GIBI_MESH_WRONLY_DRIVER() ;
00274
00278 void write( void ) const throw (MEDEXCEPTION);
00282 void read ( void ) throw (MEDEXCEPTION);
00283
00284 void open();
00285 void close();
00286
00287 protected:
00288
00289 fstream _gibi;
00290
00294 bool addSupport( const SUPPORT * support );
00298 int getSubMeshIdAndSize(const SUPPORT * support,
00299 std::list<std::pair<int,int> > & idsAndSizes ) const;
00303 void writeSupportsAndMesh(list<nameGIBItoMED>& listGIBItoMED_mail);
00309 void writeMEDNames(const std::list<nameGIBItoMED>& listGIBItoMED_mail,
00310 const std::list<nameGIBItoMED>& listGIBItoMED_cham,
00311 const std::list<nameGIBItoMED>& listGIBItoMED_comp);
00315 void writeLastRecord();
00316
00317
00318 static void addName( std::map<std::string,int>& nameMap,
00319 std::map<std::string,int>& namePrefixesMap,
00320 const std::string& name,
00321 int index);
00322
00323 void writeNames( std::map<std::string,int>& nameMap );
00324
00325 private:
00326
00327 struct typeData
00328 {
00329 int _nbElems;
00330 const int * _ptrElemIDs;
00331 int _elemID1;
00332 typeData( int nbElems=0, const int * ptrElemIDs=NULL, int elemID1=0 )
00333 : _nbElems(nbElems), _ptrElemIDs(ptrElemIDs), _elemID1(elemID1) {}
00334 };
00335 struct supportData
00336 {
00337 typedef map< MED_EN::medGeometryElement, list< typeData > >::iterator typeIterator;
00338 int _id;
00339 string _cleanName;
00340 map< MED_EN::medGeometryElement, list< typeData > > _types;
00341 supportData(): _id(0) {}
00342 int getNumberOfTypes() const { return _types.size(); }
00343 int getNumberObjects() const
00344 { return _types.size() < 2 ? _types.size() : _types.size() + !_cleanName.empty(); }
00345 void addTypeData(MED_EN::medGeometryElement type, int nbElems,
00346 const int * ptrElemIDs, int elemID1 )
00347 { _types[type].push_back( typeData( nbElems, ptrElemIDs, elemID1 )); }
00348 };
00349
00350 void writeElements (MED_EN::medGeometryElement geomType,
00351 list< typeData >& typeDataList,
00352 const int * nodalConnect,
00353 const int * nodalConnectIndex);
00354
00355 map<const SUPPORT*, supportData> _supports;
00356
00357 GENDRIVER * copy ( void ) const ;
00358 };
00359
00360
00369 class MEDMEM_EXPORT GIBI_MESH_RDWR_DRIVER : public GIBI_MESH_RDONLY_DRIVER, public GIBI_MESH_WRONLY_DRIVER {
00370
00371 public :
00372
00376 GIBI_MESH_RDWR_DRIVER() ;
00380 GIBI_MESH_RDWR_DRIVER(const std::string & fileName, MESH * ptrMesh) ;
00384 GIBI_MESH_RDWR_DRIVER(const GIBI_MESH_RDWR_DRIVER & driver) ;
00385
00389 ~GIBI_MESH_RDWR_DRIVER() ;
00390
00394 void write(void) const throw (MEDEXCEPTION);
00398 void read (void) throw (MEDEXCEPTION);
00399
00400 void open();
00401 void close();
00402
00403 private:
00404 GENDRIVER * copy(void) const ;
00405
00406 };
00407
00408 class MEDMEM_EXPORT GIBI_MED_RDONLY_DRIVER : public GIBI_MESH_RDONLY_DRIVER {
00409
00410 std::vector<FIELD_*> * _fields;
00411
00412 public:
00413
00417 GIBI_MED_RDONLY_DRIVER() ;
00421 GIBI_MED_RDONLY_DRIVER(const std::string & fileName, std::vector<FIELD_*>& ptrFields) ;
00425 GIBI_MED_RDONLY_DRIVER(const GIBI_MED_RDONLY_DRIVER & driver) ;
00426
00430 virtual ~GIBI_MED_RDONLY_DRIVER() ;
00431
00435 void read ( void ) throw (MEDEXCEPTION);
00436
00437 MESH* getMesh() const;
00438
00439 private:
00440
00441 GENDRIVER * copy ( void ) const ;
00442
00443 };
00444
00453 class MEDMEM_EXPORT GIBI_MED_WRONLY_DRIVER : public GIBI_MESH_WRONLY_DRIVER {
00454
00455 std::vector<const FIELD_*> _fields;
00456
00457 public :
00458
00462 GIBI_MED_WRONLY_DRIVER() ;
00466 GIBI_MED_WRONLY_DRIVER(const std::string & fileName,
00467 const std::vector<const FIELD_*>& fields,
00468 GMESH * ptrMesh);
00472 GIBI_MED_WRONLY_DRIVER(const GIBI_MED_WRONLY_DRIVER & driver) ;
00473
00477 virtual ~GIBI_MED_WRONLY_DRIVER() ;
00478
00482 void write( void ) const throw (MEDEXCEPTION);
00483
00484
00485
00486 private:
00487
00488 GENDRIVER * copy ( void ) const ;
00489 };
00490
00491 }
00492
00493
00494 #endif