Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_PorflowMeshDriver.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef PORFLOW_MESH_DRIVER_HXX
23 #define PORFLOW_MESH_DRIVER_HXX
24
25 #include "MEDMEM.hxx"
26
27 #include <string>
28 #include <fstream>
29
30 #include "MEDMEM_define.hxx"
31 #include "MEDMEM_GenDriver.hxx"
32 //#include "MEDMEM_DriverTools.hxx"
33
34 #include "MEDMEM_STRING.hxx"
35 #include "MEDMEM_Exception.hxx"
36 #include "MEDMEM_Utilities.hxx"
37
38 #include <vector>
39 #include <set>
40
41 /*!
42
43   Driver PORFLOW for MESH.
44
45   Generic part : implement the readopen and close methods.
46   
47 */
48
49
50 namespace MEDMEM {
51 class MESH;
52 class FAMILY;
53 class GROUP;
54 class CONNECTIVITY;
55 struct _intermediateMED;
56 struct _maille;
57 class MEDMEM_EXPORT PORFLOW_MESH_DRIVER : public GENDRIVER
58 {
59 protected:
60   
61   MESH *          _ptrMesh;
62   // A VOIR FILE DESCRIPTEUR ? MED_FR::med_idt _medIdt;
63   string          _meshName;    
64   ifstream        _porflow;
65
66   // This enumeration is used to substitude static const
67   // memers data causing link errors on VC7 compiler.
68   enum
69   {
70     nb_geometrie_porflow = 6,
71     nb_nodes_max         = 8, // maximal number of nodes for a porflow geometrie
72     nb_nodes2_max        = 4, // maximal number of nodes for a 2D porflow geometrie
73     nb_faces_max         = 6  // maximal number of faces for a porflow geometrie
74   };
75
76   // tableau de correspondance des types géométriques de PORFLOW -> MED
77   //static const size_t nb_geometrie_porflow = 6;
78   static const MED_EN::medGeometryElement geomPORFLOWtoMED[nb_geometrie_porflow];
79   // indirection table from PORFLOW order to MED one for nodes numerotation in all PORFLOW geometries
80   //static const size_t nb_nodes_max = 8;  // maximal number of nodes for a porflow geometrie
81   //static const size_t nb_nodes2_max = 4; // maximal number of nodes for a 2D porflow geometrie
82   //static const size_t nb_faces_max = 6;  // maximal number of faces for a porflow geometrie
83   static const int numPORFLOWtoMED[nb_geometrie_porflow] [nb_nodes_max];
84   static const int connectivityPORFLOW[nb_geometrie_porflow][nb_faces_max][nb_nodes2_max];
85   inline static int geomMEDtoPorflow(MED_EN::medGeometryElement medGeo);
86
87
88 public :
89
90   /*!
91     Constructor.
92   */
93   PORFLOW_MESH_DRIVER() ;
94   /*!
95     Constructor.
96   */
97   PORFLOW_MESH_DRIVER(const string & fileName,  
98                   MESH * ptrMesh, 
99                   MED_EN::med_mode_acces accessMode) ;
100   /*!
101     Copy constructor.
102   */
103   PORFLOW_MESH_DRIVER(const PORFLOW_MESH_DRIVER & driver) ;
104
105   /*!
106     Destructor.
107   */
108   virtual ~PORFLOW_MESH_DRIVER() ;
109
110   void open() throw (MEDEXCEPTION);
111   void close() throw (MEDEXCEPTION);
112
113   virtual void write( void ) const = 0 ;
114   virtual void read ( void ) = 0 ;
115
116   /*!
117     Set the name of the MESH asked in file.
118
119     It could be different than the name of the MESH object.
120   */
121   void   setMeshName(const string & meshName) ;
122   /*!
123     Get the name of the MESH asked in file.
124   */
125   string getMeshName() const ;
126
127 private:
128   virtual GENDRIVER * copy ( void ) const = 0 ;
129
130 };
131
132
133 class MEDMEM_EXPORT PORFLOW_MESH_RDONLY_DRIVER : public virtual PORFLOW_MESH_DRIVER
134 {
135  
136 public :
137   
138   /*!
139     Constructor.
140   */
141   PORFLOW_MESH_RDONLY_DRIVER() ;
142   /*!
143     Constructor.
144   */
145   PORFLOW_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
146   /*!
147     Copy constructor.
148   */
149   PORFLOW_MESH_RDONLY_DRIVER(const PORFLOW_MESH_RDONLY_DRIVER & driver) ;
150
151   /*!
152     Destructor.
153   */
154   virtual ~PORFLOW_MESH_RDONLY_DRIVER() ;
155   
156   /*!
157     Return a MEDEXCEPTION : it is the read-only driver.
158   */
159   void write( void ) const throw (MEDEXCEPTION);
160   /*!
161     Read MESH in the specified file.
162   */
163   void read ( void ) throw (MEDEXCEPTION);
164
165 private:
166  
167   GENDRIVER * copy ( void ) const ;
168
169   static void readPorflowCoordinateFile(const string & coorFileName,_intermediateMED & medi,const int space_dimension);
170   static void readPorflowConnectivityFile(bool hybride,const string & connecFileName,_intermediateMED & medi,std::vector<set<_maille>::iterator>& p_ma_table,int mesh_dimension);
171
172 };
173
174 /*!
175
176   Driver Med for MESH : Write only.
177
178   Implement write method.
179
180 */
181
182 class MEDMEM_EXPORT PORFLOW_MESH_WRONLY_DRIVER : public virtual PORFLOW_MESH_DRIVER {
183   
184 public :
185   
186   /*!
187     Constructor.
188   */
189   PORFLOW_MESH_WRONLY_DRIVER() ;
190   /*!
191     Constructor.
192   */
193   PORFLOW_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
194   /*!
195     Copy constructor.
196   */
197   PORFLOW_MESH_WRONLY_DRIVER(const PORFLOW_MESH_WRONLY_DRIVER & driver) ;
198
199   /*!
200     Destructor.
201   */
202   virtual ~PORFLOW_MESH_WRONLY_DRIVER() ;
203
204   /*!
205     Write MESH in the specified file.
206   */
207   void write( void ) const throw (MEDEXCEPTION);
208   /*!
209     Return a MEDEXCEPTION : it is the write-only driver.
210   */
211   void read ( void ) throw (MEDEXCEPTION);
212
213 private:
214
215   GENDRIVER * copy ( void ) const ;
216 };
217
218
219 /*!
220
221   Driver PORFLOW for MESH : Read write.
222   - Use read method from PORFLOW_MESH_RDONLY_DRIVER
223   - Use write method from PORFLOW_MESH_WRONLY_DRIVER
224
225 */
226
227 class MEDMEM_EXPORT PORFLOW_MESH_RDWR_DRIVER : public PORFLOW_MESH_RDONLY_DRIVER, public PORFLOW_MESH_WRONLY_DRIVER {
228
229 public :
230
231   /*!
232     Constructor.
233   */
234   PORFLOW_MESH_RDWR_DRIVER() ;
235   /*!
236     Constructor.
237   */
238   PORFLOW_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) ;
239   /*!
240     Copy constructor.
241   */
242   PORFLOW_MESH_RDWR_DRIVER(const PORFLOW_MESH_RDWR_DRIVER & driver) ;
243
244   /*!
245     Destructor.
246   */
247   ~PORFLOW_MESH_RDWR_DRIVER() ;
248
249   /*!
250     Write MESH in the specified file.
251   */
252   void write(void) const throw (MEDEXCEPTION);
253   /*!
254     Read MESH in the specified file.
255   */
256   void read (void) throw (MEDEXCEPTION);
257
258 private:
259   GENDRIVER * copy(void) const ;
260
261 };
262 }
263
264
265 #endif /* PORFLOW_MESH_DRIVER_HXX */