Salome HOME
13380262dd7420c8ad6958ea346a5126054e9931
[modules/med.git] / src / MEDMEM_SWIG / libMEDMEM_Swig.i
1 // Copyright (C) 2007-2013  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
23 %module libMEDMEM_Swig
24
25 %{
26 #include <sstream>
27 #include <string>
28 #include "MEDMEM_CellModel.hxx"
29 #include "MEDMEM_GenDriver.hxx"
30 #include "MEDMEM_MedMeshDriver.hxx"
31 #include "MEDMEM_GibiMeshDriver.hxx"
32 #include "MEDMEM_PorflowMeshDriver.hxx"
33 #include "MEDMEM_Connectivity.hxx"
34 #include "MEDMEM_Group.hxx"
35 #include "MEDMEM_SkyLineArray.hxx"
36 #include "MEDMEM_Coordinate.hxx"
37 #include "MEDMEM_Array.hxx"
38 #include "MEDMEM_Mesh.hxx"
39 #include "MEDMEM_define.hxx"
40 #include "MEDMEM_Exception.hxx"
41 #include "MEDMEM_STRING.hxx"
42 #include "MEDMEM_DriversDef.hxx"
43 #include "MEDMEM_MedFieldDriver.hxx"
44 #include "MEDMEM_Support.hxx"
45 #include "MEDMEM_Family.hxx"
46 #include "MEDMEM_Unit.hxx"
47 #include "MEDMEM_Field.hxx"
48 #include "MEDMEM_FieldConvert.hxx"
49 #include "MEDMEM_Grid.hxx"
50 #include "MEDMEM_Meshing.hxx"
51 #include "MEDMEM_DriverFactory.hxx"
52 #include "MEDMEM_GaussLocalization.hxx"
53 #include "MEDMEM_EnsightMedDriver.hxx"
54 #include "MEDMEM_EnsightMeshDriver.hxx"
55 #include "MEDMEM_EnsightFieldDriver.hxx"
56 #include "MEDMEM_ArrayInterface.hxx"
57 #include "MEDMEM_MedFileBrowser.hxx"
58 #include "PointLocator.hxx"
59 #include "MEDMEM_VtkMedDriver.hxx"
60
61 #include "MEDMEM_SWIG_Templates.hxx"
62 #ifdef WITH_NUMPY
63   template< typename T >
64     PyObject * TYPEMAP_OUTPUT_PY_ARRAY(const T* value, int size)
65   {
66     npy_intp dim = (npy_intp) size;
67     return PyArray_SimpleNewFromData(1,&dim, Binding<T>::numpy_type(),(T*)value);
68   }
69 #endif
70
71   using namespace MEDMEM;
72   using namespace MED_EN;
73   using namespace INTERP_KERNEL;
74   typedef FIELD <double, FullInterlace> FIELDDOUBLE;
75   typedef FIELD <int   , FullInterlace> FIELDINT;
76   typedef FIELD <double, NoInterlace> FIELDDOUBLENOINTERLACE;
77   typedef FIELD <int   , NoInterlace> FIELDINTNOINTERLACE;
78   typedef FIELD <double, NoInterlaceByType> FIELDDOUBLENOINTERLACEBYTYPE;
79   typedef FIELD <int   , NoInterlaceByType> FIELDINTNOINTERLACEBYTYPE;
80
81   // to keep old scripts working
82   typedef enum {MED_LECT=RDONLY, MED_ECRI=WRONLY, MED_REMP=RDWR} med_mode_acces_old;
83   
84 %}
85
86 /*
87   SWIG needs these typedefs to wrap FIELDDOUBLE*, for ex., to something like
88   <C++ FIELD<double> instance at _d0709808_p_FIELDDOUBLE>, not to
89   <SWIG Object at _d0709808_p_FIELDDOUBLE> which has no attributes
90 */
91
92 typedef FIELD <double, FullInterlace> FIELDDOUBLE;
93 typedef FIELD <int   , FullInterlace> FIELDINT;
94 typedef FIELD <double, NoInterlace> FIELDDOUBLENOINTERLACE;
95 typedef FIELD <int   , NoInterlace> FIELDINTNOINTERLACE;
96 typedef FIELD <double, NoInterlaceByType> FIELDDOUBLENOINTERLACEBYTYPE;
97 typedef FIELD <int   , NoInterlaceByType> FIELDINTNOINTERLACEBYTYPE;
98
99 %include "typemaps.i"
100 %include "my_typemap.i"
101
102 %typecheck(SWIG_TYPECHECK_POINTER) double *, const double *,
103  const double * const, int *, const int *, const int * const, string *,
104  const string *, const string * const, medGeometryElement *,
105  const medGeometryElement *, const medGeometryElement * const
106 {
107   $1 = ($input != 0);
108 }
109
110 /*
111   mapping between stl string and python string 
112 */
113
114 %include "std_string.i"
115
116
117 /*
118   managing C++ exception in the Python API
119 */
120
121 %exception
122 {
123   //class PyAllowThreadsGuard {
124   // public:
125   //  PyAllowThreadsGuard() { _save = PyEval_SaveThread(); }
126   //  ~PyAllowThreadsGuard() { PyEval_RestoreThread(_save); }
127   // private:
128   //  PyThreadState *_save;
129   //};
130
131   try
132     {
133       //PyAllowThreadsGuard guard;
134       $action
135     }
136   catch(MEDEXCEPTION& exception)
137     {
138       PyErr_SetString(PyExc_RuntimeError,exception.what());
139       return NULL;
140     }
141 }
142
143 /*
144   managing the use of operator= of any class by renaming it assign()
145   because assignment can't be overloaded in python.
146
147   In python, you would then use
148
149   a.assign(b)              # a = b
150 */
151
152 %rename(assign) *::operator=;
153
154 /*
155   typemap in for PyObject * fonction Python wrapping of a
156   double or int fonction pointeur
157 */
158
159 #if defined(SWIGPYTHON)
160 %typemap(in) PyObject * double_function, PyObject * integer_function
161 {
162   /* typemap in for double or integer callable fonction pointeur */
163   /* Check if it is a callable fonction pointer */
164
165   if(PyCallable_Check($input) == 0)
166     {
167       const char * message = "Error in typemap(python,in) for double or integer callable fonction pointeur : the argument should be a callable object";
168       PyErr_SetString(PyExc_RuntimeError, message);
169       return NULL;
170     }
171
172   $1 = $input;
173 }
174 #endif
175
176 /*
177   MACRO converting C++ MEDMEM::FIELD_ pointer into a PyObject pointer rightly
178   casted following its value type (int or double) and its interlacing mode
179   (FullInterlace or NoInterlace) by calling the function SWIG_NewPointer with
180   the appropriate $descriptor(...)
181 */
182
183 %define TYPEMAP_OUTPUT_FIELDT(myField)
184 {
185   FIELD_ *arg1=myField;
186   PyObject *myResult=NULL;
187   if(arg1)
188     {
189       FIELD<double> *try1=dynamic_cast<FIELD<double> *>(arg1);
190       if(try1)
191         myResult = SWIG_NewPointerObj((void *) try1, $descriptor(FIELD<double, FullInterlace> *), 0);
192       else
193         {
194           FIELD<int> *try2=dynamic_cast<FIELD<int> *>(arg1);
195           if(try2)
196             myResult = SWIG_NewPointerObj((void *) try2, $descriptor(FIELD<int, FullInterlace> *), 0);
197           else
198             {
199               FIELD<double, NoInterlace> *try3=dynamic_cast<FIELD<double, NoInterlace> *>(arg1);
200               if(try3)
201                 myResult = SWIG_NewPointerObj((void *) try3, $descriptor(FIELD<double, NoInterlace> *), 0);
202               else
203                 {
204                    FIELD<int, NoInterlace> *try4=dynamic_cast<FIELD<int, NoInterlace> *>(arg1);
205                    if(try4)
206                      myResult = SWIG_NewPointerObj((void *) try4, $descriptor(FIELD<int, NoInterlace> *), 0);
207                    else
208                      {
209                        myResult = SWIG_NewPointerObj((void *) arg1, $descriptor(FIELD_ *), 0);
210                      }
211                 }
212             }
213         }
214      }
215   return myResult;
216 }
217 %enddef
218
219 /*
220   MACRO converting C array <arrayvar> of length <size> into a PyList
221   by calling type_converter() for each array element.
222   It reports error in <method> in failure case
223 */
224
225 %define TYPEMAP_OUTPUT_ARRAY(arrayvar, size, type_converter, method)
226 {
227   PyObject *py_list = PyList_New(size);
228   for (int i=0; i < int(size); i++)
229     {
230       int err = PyList_SetItem(py_list, i, type_converter( arrayvar[ i ]));
231       if(err)
232         {
233           const char * message = "Error in " #method;
234           PyErr_SetString(PyExc_RuntimeError, message);
235           return NULL;
236         }
237     }
238
239   PyObject * result = Py_BuildValue("O", py_list);
240   Py_DECREF(py_list);
241   return result;
242 }
243 %enddef
244
245 /*
246   Helper function to be used as type_converter in TYPEMAP_OUTPUT_ARRAY
247 */
248
249 %{
250   PyObject *PyString_FromStdString(const std::string &str)
251     {
252       return PyString_FromString(str.c_str());
253     }
254 %}
255
256 /**************************************************
257   IN typemaps for some std::vector's
258 **************************************************/
259
260 /*  MACRO: IN typemap for std::vector<TYPE> C++ object */
261 %define TYPEMAP_INPUT_VECTOR_BY_VALUE( TYPE )
262 {
263   /* typemap in for vector<TYPE> */
264   /* Check if is a list */
265   if (PyList_Check($input))
266   {
267     int size = PyList_Size($input);
268     vector< TYPE > tmpVec(size);
269
270     for (int i=0; i < size; i++)
271     {
272       PyObject * tmp = PyList_GetItem($input,i);
273       TYPE elem;
274
275       int err = SWIG_ConvertPtr(tmp, (void **) &elem, $descriptor(TYPE),
276                                 SWIG_POINTER_EXCEPTION);
277       if (err == -1)
278       {
279         const char * message = "Error in typemap(python,in) for vector<TYPE>"
280           "each component should be a TYPE";
281         PyErr_SetString(PyExc_RuntimeError, message);
282         return NULL;
283       }
284       tmpVec[i] = elem;
285     }
286     $1 = tmpVec;
287   }
288   else
289   {
290     PyErr_SetString(PyExc_TypeError,"not a list");
291     return NULL;
292   }
293 }
294 %enddef
295
296 #if defined(SWIGPYTHON)
297 %typemap(in) vector< FAMILY* >, const vector< FAMILY* >
298 { TYPEMAP_INPUT_VECTOR_BY_VALUE( FAMILY * ) }
299 #endif
300
301 #if defined(SWIGPYTHON)
302 %typemap(in) vector< SUPPORT* >, const vector< SUPPORT* >
303 { TYPEMAP_INPUT_VECTOR_BY_VALUE( SUPPORT * ) }
304 #endif
305
306 #if defined(SWIGPYTHON)
307 %typemap(in) vector< FIELDDOUBLE* >, const vector< FIELDDOUBLE* >
308 { TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELDDOUBLE * ) }
309 #endif
310
311 #if defined(SWIGPYTHON)
312 %typemap(in) vector< FIELD_* >, const vector< FIELD_* >
313 { TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELD_ * ) }
314 #endif
315
316 #if defined(SWIGPYTHON)
317 %typemap(in) vector< const FIELD_* >, const vector< const FIELD_* >
318 { TYPEMAP_INPUT_VECTOR_BY_VALUE( const FIELD_ * ) }
319 #endif
320
321 #if defined(SWIGPYTHON)
322 %typemap(in) vector< FIELDINT* >, const vector< FIELDINT* >
323 { TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELDINT * ) }
324 #endif
325
326 #if defined(SWIGPYTHON)
327 %typemap(in) vector< FIELDDOUBLENOINTERLACE* >, const vector< FIELDDOUBLENOINTERLACE* >
328 { TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELDDOUBLENOINTERLACE * ) }
329 #endif
330
331 #if defined(SWIGPYTHON)
332 %typemap(in) vector< FIELDINTNOINTERLACE* >, const vector< FIELDINTNOINTERLACE* >
333 { TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELDINTNOINTERLACE * ) }
334 #endif
335
336 /**************************************************
337   OUT typemaps for some std::vector's
338 **************************************************/
339
340 /*  MACRO: OUT typemap for std::vector<TYPE> C++ object */
341 %define TYPEMAP_OUTPUT_VECTOR_BY_VALUE( TYPE )
342 {
343   /* typemap out for vector<TYPE> */
344   int size = $1.size();
345   $result = PyList_New(size);
346
347   for (int i=0;i<size;i++)
348   {
349     PyObject * tmp = SWIG_NewPointerObj($1.at(i),$descriptor(TYPE),0);
350
351     PyList_SetItem($result,i,tmp);
352   }
353 }
354 %enddef
355
356 #if defined(SWIGPYTHON)
357 %typemap(out) vector< FAMILY* >
358 { TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FAMILY * ) }
359 #endif
360
361 #if defined(SWIGPYTHON)
362 %typemap(out) vector< SUPPORT* >
363 { TYPEMAP_OUTPUT_VECTOR_BY_VALUE( SUPPORT * ) }
364 #endif
365
366 #if defined(SWIGPYTHON)
367 %typemap(out) vector< FIELDDOUBLE* >
368 { TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FIELDDOUBLE * ) }
369 #endif
370
371 #if defined(SWIGPYTHON)
372 %typemap(out) vector< FIELDINT* >
373 { TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FIELDINT * )  }
374 #endif
375
376 #if defined(SWIGPYTHON)
377 %typemap(out) vector< FIELDDOUBLENOINTERLACE* >
378 { TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FIELDDOUBLENOINTERLACE * ) }
379 #endif
380
381 #if defined(SWIGPYTHON)
382 %typemap(out) vector< FIELDINTNOINTERLACE* >
383 { TYPEMAP_OUTPUT_VECTOR_BY_VALUE( FIELDINTNOINTERLACE * ) }
384 #endif
385
386
387 /*
388   enum of the C++ MED used in the Python API
389 */
390
391 typedef enum {MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED} med_grid_type;
392
393 typedef enum {MED_FULL_INTERLACE, MED_NO_INTERLACE} medModeSwitch;
394
395 typedef enum {RDONLY, WRONLY, RDWR} med_mode_acces;
396 typedef enum {MED_LECT, MED_ECRI, MED_REMP} med_mode_acces_old;// to keep old scripts working
397
398 typedef enum {ASCENDING=7,DESCENDING=77} med_sort_direc;
399
400 typedef enum {MED_CELL, MED_FACE, MED_EDGE, MED_NODE,
401               MED_ALL_ENTITIES} medEntityMesh;
402
403 typedef enum {MED_NONE=0, MED_POINT1=1, MED_SEG2=102, MED_SEG3=103,
404               MED_TRIA3=203, MED_QUAD4=204, MED_TRIA6=206, MED_QUAD8=208,
405               MED_TETRA4=304, MED_PYRA5=305, MED_PENTA6=306,
406               MED_HEXA8=308, MED_TETRA10=310, MED_PYRA13=313,
407               MED_PENTA15=315, MED_HEXA20=320, MED_POLYGON = 400, MED_POLYHEDRA = 500,
408               MED_ALL_ELEMENTS=999} medGeometryElement;
409
410 typedef enum {MED_NODAL, MED_DESCENDING} medConnectivity ;
411
412 typedef enum {MED_DRIVER=0, GIBI_DRIVER=1, PORFLOW_DRIVER = 2, VTK_DRIVER=254,
413               NO_DRIVER=255, ASCII_DRIVER = 3, ENSIGHT_DRIVER = 250 } driverTypes;
414
415 typedef enum {MED_REEL64=6, MED_INT32=24, MED_INT64=26} med_type_champ;
416
417 typedef struct { int dt; int it; } DT_IT_;
418
419 typedef enum {V21 = 26, V22 = 75} medFileVersion;
420
421 %feature("unref") SUPPORT "$this->removeReference();"
422 %feature("unref") GMESH "$this->removeReference();"
423 %feature("unref") MESH "$this->removeReference();"
424 %feature("unref") FIELDDOUBLE "$this->removeReference();"
425 %feature("unref") FIELDINT "$this->removeReference();"
426 %feature("unref") FIELDDOUBLENOINTERLACE "$this->removeReference();"
427 %feature("unref") FIELDINTNOINTERLACE "$this->removeReference();"
428 %feature("unref") FIELDDOUBLENOINTERLACEBYTYPE "$this->removeReference();"
429 %feature("unref") FIELDINTNOINTERLACEBYTYPE "$this->removeReference();"
430
431 %extend DT_IT_ {
432   int getdt()
433     {
434       return self->dt;
435     }
436
437   int getit()
438     {
439       return self->it;
440     }
441 }
442
443 %typecheck(SWIG_TYPECHECK_POINTER) vector< SUPPORT * >, const vector< SUPPORT * >, vector< const FIELD_* >
444 {
445   $1 = ($input != 0);
446 }
447
448 /*
449   Class et methodes du MED++ que l'on utilise dans l'API Python
450 */
451
452 class CELLMODEL
453 {
454  public:
455   CELLMODEL();
456
457   CELLMODEL(medGeometryElement t);
458
459   CELLMODEL(const CELLMODEL &m);
460
461   int getNumberOfVertexes();
462
463   int getNumberOfNodes();
464
465   int getDimension();
466
467   medGeometryElement getType();
468
469   int getNumberOfConstituents(int dim);
470
471   int getNodeConstituent(int dim,int num,int nodes_index);
472
473   medGeometryElement getConstituentType(int dim,int num);
474
475   int getNumberOfConstituentsType();
476
477   std::string getName() const;
478
479   ~CELLMODEL();
480
481   %extend {
482     %newobject __str__();
483     const char* __str__()
484       {
485         ostringstream mess;
486         mess << "Python Printing CELLMODEL : " << *self << endl;
487         return strdup(mess.str().c_str());
488       }
489   }
490 };
491
492 class SUPPORT
493 {
494  public:
495   SUPPORT();
496
497   SUPPORT(const SUPPORT & m);
498
499   ~SUPPORT();
500
501   void update ( void );
502
503   MESH * getMesh() const;
504
505   std::string getMeshName() const;
506
507   void setMesh(MESH * Mesh) const;
508
509   medEntityMesh getEntity() const;
510
511   void setEntity(medEntityMesh Entity);
512
513   bool isOnAllElements() const;
514
515   void setAll(bool All);
516
517   int getNumberOfTypes() const;
518
519   void setNumberOfGeometricType(int NumberOfGeometricType);
520
521   int getNumberOfElements(medGeometryElement GeometricType) const;
522
523   void setGeometricType(medGeometryElement *GeometricType);
524
525   void setNumberOfElements(int *NumberOfElements);
526
527   void getBoundaryElements();
528
529   void setNumber(const int * index, const int* value);
530
531   bool deepCompare(const SUPPORT &support) const;
532
533   void setpartial(std::string Description, int NumberOfGeometricType,
534                   int TotalNumberOfElements, medGeometryElement *GeometricType,
535                   int *NumberOfElements, int *NumberValue);
536
537   std::string getName() const;
538
539   void setName(std::string Name);
540
541   std::string getDescription();
542
543   void setDescription(std::string Description);
544
545   MESH* makeMesh();
546
547   SUPPORT* buildSupportOnNode();
548
549   %extend {
550     %newobject __str__();
551     const char* __str__()
552       {
553         ostringstream mess;
554         mess << "Python Printing SUPPORT : " << *self << endl;
555         char * tmp = const_cast <char *> (mess.str().c_str());
556         char * returned = strdup(tmp);
557         return returned;
558       }
559
560     PyObject * getTypes()
561       {
562         const medGeometryElement * types = self->getTypes();
563         int size = self->getNumberOfTypes();
564         TYPEMAP_OUTPUT_ARRAY(types, size, PyInt_FromLong, SUPPORT::getTypes);
565       }
566
567     PyObject * getNumber(medGeometryElement GeometricType)
568       {
569         const int * number = self->getNumber(GeometricType);
570         int size = self->getNumberOfElements(GeometricType);
571         TYPEMAP_OUTPUT_ARRAY(number, size, PyInt_FromLong,
572                              SUPPORT::getNumber);
573       }
574
575     PyObject * getNumberIndex()
576       {
577         const int * numberindex = self->getNumberIndex();
578         int size = (self->getNumberOfTypes())+1;
579         TYPEMAP_OUTPUT_ARRAY(numberindex, size, PyInt_FromLong,
580                              SUPPORT::getNumberIndex);
581       }
582
583     %newobject getComplement() const;
584     SUPPORT *getComplement() const
585       {
586         return self->getComplement();
587       }
588
589     %newobject substract(const SUPPORT& other) const;
590     SUPPORT *substract(const SUPPORT& other) const
591       {
592         return self->substract(other);
593       }
594
595     %newobject getBoundaryElements(medEntityMesh Entity) const;
596     SUPPORT *getBoundaryElements(medEntityMesh Entity) const
597       {
598         return self->getBoundaryElements(Entity);
599       }
600   }
601 };
602
603 class FAMILY : public SUPPORT
604 {
605  public:
606   FAMILY();
607
608   FAMILY(const FAMILY & m);
609
610   ~FAMILY();
611
612   FAMILY & operator=(const FAMILY &fam);
613
614   void setIdentifier(int Identifier);
615
616   void setNumberOfAttributes(int NumberOfAttribute);
617
618   void setAttributesIdentifiers(int * AttributeIdentifier);
619
620   void setAttributesValues(int * AttributeValue);
621
622   void setAttributesDescriptions(std::string * AttributeDescription);
623
624   void setNumberOfGroups(int NumberOfGroups);
625
626   void setGroupsNames(std::string * GroupName);
627
628   int getIdentifier() const;
629
630   int getNumberOfAttributes() const;
631
632   int getNumberOfGroups() const;
633
634   FAMILY(MESH* Mesh, int Identifier, std::string Name, int NumberOfAttribute,
635          int *AttributeIdentifier, int *AttributeValue,
636          std::string AttributeDescription, int NumberOfGroup,
637          std::string GroupName, int * MEDArrayNodeFamily,
638          int ** MEDArrayCellFamily, int ** MEDArrayFaceFamily,
639          int ** MEDArrayEdgeFamily);
640
641   std::string getAttributeDescription(int i);
642
643   std::string getGroupName(int i);
644
645   %extend {
646     %newobject __str__();
647     const char* __str__()
648       {
649         ostringstream mess;
650         mess << "Python Printing Family : " << *self << endl;
651         return strdup(mess.str().c_str());
652       }
653
654     PyObject * getAttributesIdentifiers()
655       {
656         const int * attributesids = self->getAttributesIdentifiers();
657         int size = self->getNumberOfAttributes();
658         TYPEMAP_OUTPUT_ARRAY(attributesids,size,PyInt_FromLong,
659                              FAMILY::getAttributesIdentifiers);
660       }
661
662     PyObject * getAttributesValues()
663       {
664         const int * attributesvals = self->getAttributesValues();
665         int size = self->getNumberOfAttributes();
666         TYPEMAP_OUTPUT_ARRAY(attributesvals,size,PyInt_FromLong,
667                              FAMILY::getAttributesValues);
668       }
669   }
670 };
671
672 class GENDRIVER
673 {
674   GENDRIVER();
675 public:
676   void open();
677   void write();
678   void read ();
679   void close();
680
681   std::string getFileName () const;
682   void setFileName ( const std::string & fileName);
683
684   void setMeshName    ( const std::string & meshName);
685   std::string getMeshName();
686
687   void setFieldName   ( const std::string & fieldName);
688   std::string getFieldName() const;
689
690 };
691
692 class FIELD_
693 {
694 public:
695   FIELD_(const SUPPORT * Support, const int NumberOfComponents);
696
697   ~FIELD_();
698
699   void rmDriver(int index=0);
700
701   void read (driverTypes driverType, const std::string & fileName);
702   void read (const GENDRIVER &);
703   void read(int index=0);
704
705   void write(const GENDRIVER& driver, med_mode_acces medMode=RDWR);
706   void write(driverTypes driverType, const char* filename,
707              med_mode_acces medMode=RDWR);
708   void write(int index=0);
709
710   void writeAppend(int index=0, const std::string& driverName="");
711
712   void setIterationNumber (int IterationNumber);
713   int getIterationNumber() const;
714
715   void setTime(double Time);
716   double   getTime() const;
717
718   void setOrderNumber (int OrderNumber);
719   int getOrderNumber() const;
720
721   med_type_champ getValueType() ;
722
723   medModeSwitch getInterlacingType();
724
725   SUPPORT * getSupport();
726   void setSupport(SUPPORT * support);
727
728   void  setNumberOfComponents(int NumberOfComponents);
729   int getNumberOfComponents() const;
730
731   void setNumberOfValues(int NumberOfValues);
732   int getNumberOfValues() const;
733
734   std::string   getName() const;
735
736   std::string   getDescription() const;
737
738   std::string   getComponentName(int i) const;
739
740   std::string   getComponentDescription(int i) const;
741
742   std::string   getMEDComponentUnit(int i) const;
743
744   void     setName(std::string Name);
745
746   void     setComponentName(int i, std::string ComponentName);
747
748   void     setMEDComponentUnit(int i, std::string MEDComponentUnit);
749
750   void     setDescription(std::string Description);
751
752   void     setComponentDescription(int i, std::string ComponentDescription);
753
754   int addDriver(driverTypes driverType,
755                 const std::string& fileName="Default File Name.med",
756                 const std::string& driverName="Default Field Name",
757                 med_mode_acces access=RDWR);
758
759   %extend {
760     %newobject getSupportAndOwner();
761     SUPPORT * getSupportAndOwner()
762       {
763         return (SUPPORT *)self->getSupport();
764       }
765   PyObject* castToTypedField()
766   {
767     if ( self->getValueType() == MED_REEL64 )
768       switch( self->getInterlacingType() ) {
769       case MED_FULL_INTERLACE:
770         return SWIG_NewPointerObj((void *)self, $descriptor(FIELDDOUBLE *), 0);
771       case MED_NO_INTERLACE:
772         return SWIG_NewPointerObj((void *)self, $descriptor(FIELDDOUBLENOINTERLACE *), 0);
773       case MED_NO_INTERLACE_BY_TYPE:
774         return SWIG_NewPointerObj((void *)self, $descriptor(FIELDDOUBLENOINTERLACEBYTYPE *), 0);
775       default:
776         PyErr_SetString(PyExc_RuntimeError,"Invalid interlacing type of a field");
777         return NULL;
778       }
779     else
780       switch( self->getInterlacingType() ) {
781       case MED_FULL_INTERLACE:
782         return SWIG_NewPointerObj((void *)self, $descriptor(FIELD<int, FullInterlace> *), 0);
783       case MED_NO_INTERLACE:
784         return SWIG_NewPointerObj((void *)self, $descriptor(FIELD<int, NoInterlace> *), 0);
785       case MED_NO_INTERLACE_BY_TYPE:
786         return SWIG_NewPointerObj((void *)self, $descriptor(FIELD<int, NoInterlaceByType> *), 0);
787       default:
788         PyErr_SetString(PyExc_RuntimeError,"Invalid interlacing type of a field");
789         return NULL;
790       }
791     return NULL;
792   }
793   }
794 };
795
796 /*
797   Class FIELD has now two template parameters: T1 is a double or an int,
798   INTERLACING_TAG is FullInterlace or NoInterlace
799 */
800
801 template<class T1, class INTERLACING_TAG> class FIELD : public FIELD_
802 {
803 public:
804   ~FIELD();
805
806   FIELD(const SUPPORT * Support, const int NumberOfComponents);
807
808   FIELD();
809
810   FIELD(const FIELD & m);
811
812   FIELD(const SUPPORT * Support, driverTypes driverType,
813         const std::string& fileName, const std::string& fieldName,
814         const int iterationNumber, const int orderNumber);
815
816   FIELD(driverTypes driverType, const char* fileName, const char* fieldName,
817         int iterationNumber, int orderNumber, GMESH* mesh=0);
818
819   T1 getValueIJ(int i,int j) const;
820
821   T1 getValueIJK(int i,int j, int k) const;
822
823   T1 getValueIJByType(int i,int j, int type) const;
824
825   T1 getValueIJKByType(int i,int j, int k, int type) const;
826
827   void setValue(T1* value);
828
829   void setRow( int i, T1 * value);
830
831   void setColumn( int i, T1 * value);
832
833   void setValueIJ(int i, int j, T1 value);
834
835   void setValueIJK(int i, int j, int k, T1 value);
836
837   void setValueIJByType(int i, int j, int type, T1 value);
838
839   void setValueIJKByType(int i, int j, int k, int type, T1 value);
840
841   void allocValue(const int NumberOfComponents);
842
843   void deallocValue();
844
845   void applyLin(T1 a, T1 n);
846
847   void applyPow(T1 scalar);
848
849   double normMax();
850
851   double norm2();
852
853   double normL2(int component,const FIELD<double, FullInterlace> *
854                 p_field_volume=NULL) const;
855
856   double normL2(const FIELD<double, FullInterlace> *
857                 p_field_volume=NULL) const;
858
859   double normL1(int component, const FIELD<double, FullInterlace> *
860                 p_field_volume=NULL) const;
861
862   double normL1(const FIELD<double, FullInterlace> *
863                 p_field_volume=NULL) const;
864
865   double integral(const SUPPORT* subSupport=0);
866
867   bool getGaussPresence();
868
869   GAUSS_LOCALIZATION<INTERLACING_TAG> * getGaussLocalizationPtr(medGeometryElement geomElement);
870
871   int getNbGaussI(int i);
872
873   %extend {
874
875     /*!
876      * \brief create a field with default gauss localizations
877      */
878     FIELD(const SUPPORT * support, const int numberOfComponents, const int* nbGaussByType)
879       {
880         FIELD<T1,INTERLACING_TAG>* f = new FIELD<T1,INTERLACING_TAG>(support,numberOfComponents);
881
882         int nbtypegeo = support->getNumberOfTypes();
883         vector<int> nbelgeoc (nbtypegeo+1,0);
884         const int * nbElemByType = support->getNumberOfElements();
885         for (int iType = 0; iType < nbtypegeo; ++iType)
886         {
887           nbelgeoc  [ iType+1 ] = nbelgeoc[ iType ] + nbElemByType[ iType ];
888           MED_EN::medGeometryElement type = support->getTypes()[ iType ];
889           ostringstream locname;
890           locname << nbGaussByType[iType] << "points_on" << type << "geomType";
891           f->setGaussLocalization
892             ( type,
893               GAUSS_LOCALIZATION_::makeDefaultLocalization( locname.str(),
894                                                             type,
895                                                             nbGaussByType[ iType ]));
896         }
897         typedef MEDMEM_ArrayInterface<T1,INTERLACING_TAG,Gauss>::Array Array;
898         Array* array = new Array(numberOfComponents,
899                                  support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS),
900                                  support->getNumberOfTypes(),
901                                  &nbelgeoc[0],
902                                  nbGaussByType-1);
903         f->setArray( array );
904         return f;
905       }
906
907     PyObject * getNumberOfGaussPoints()
908       {
909         int size = self->getNumberOfGeometricTypes();
910
911         const int * value = self->getNumberOfGaussPoints();
912         TYPEMAP_OUTPUT_ARRAY(value, size, PyInt_FromLong, FIELD::getNumberOfGaussPoints());
913       }
914
915
916
917     PyObject *  applyPyFunc( PyObject * func )
918       {
919         MESSAGE_MED("Appel de applyPyFunc");
920         if (!PyCallable_Check(func)) {
921           PyErr_SetString(PyExc_TypeError, "FIELD.applyPyFunc prend en argument une fonction");
922           return NULL;
923         }
924
925         int nComp=self->getNumberOfComponents();
926         int nVal=self->getNumberOfValues();
927         for (int i=1; i!=nVal+1; ++i)
928           for ( int j=1 ;j!=nComp+1 ;++j )
929           {
930             self->setValueIJ(i,j, Binding<T1>::Functor( func, self->getValueIJ(i,j) ) );
931           }
932
933         PyObject * result = Binding<double>::Traducer(nComp*nVal);
934         return result;
935       }
936       
937     %newobject execFunc( int nbOfCompo, PyObject * func );
938     FIELD<T1, INTERLACING_TAG> *execFunc( int nbOfCompo, PyObject *func )
939       {
940         MyFunction<T1,T1>::_pyFunc=func;
941         MyFunction<T1,T1>::_nbOfComponent=nbOfCompo;
942         MyFunction<T1,T1>::_spaceDim=self->getNumberOfComponents();
943         return self->execFunc(nbOfCompo, MyFunction<T1,T1>::EvalPy2Cpp);
944       }
945
946     %newobject __add__(const FIELD<T1, INTERLACING_TAG> & );
947     FIELD<T1, INTERLACING_TAG> * __add__(const FIELD<T1, INTERLACING_TAG> & m)
948       {
949         MESSAGE_MED("operator +  : Creation of the addition of two FIELDs");
950         
951         FIELD<T1, INTERLACING_TAG>* result =
952           FIELD<T1, INTERLACING_TAG>::add( *(FIELD<T1, INTERLACING_TAG>*)self ,
953                                            (FIELD<T1, INTERLACING_TAG>&)m );
954         return (FIELD<T1, INTERLACING_TAG>*) result;
955       }
956
957     %newobject __sub__(const FIELD<T1, INTERLACING_TAG> & );
958     FIELD<T1, INTERLACING_TAG> * __sub__(const FIELD<T1, INTERLACING_TAG> & m)
959       {
960         MESSAGE_MED("operator -  : Creation of the substraction of two FIELDs");
961         FIELD<T1, INTERLACING_TAG>* result =
962           FIELD<T1, INTERLACING_TAG>::sub( *(FIELD<T1, INTERLACING_TAG>*)self ,
963                                            (FIELD<T1, INTERLACING_TAG>&)m );
964         return (FIELD<T1, INTERLACING_TAG>*) result;
965       }
966
967     %newobject __mul__(const FIELD<T1, INTERLACING_TAG> & );
968     FIELD<T1, INTERLACING_TAG> * __mul__(const FIELD<T1, INTERLACING_TAG> & m)
969       {
970         MESSAGE_MED("operator *  : Creation of the multiplication of two FIELDs");
971         FIELD<T1, INTERLACING_TAG>* result =
972           FIELD<T1, INTERLACING_TAG>::mul( *(FIELD<T1, INTERLACING_TAG>*)self ,
973                                            (FIELD<T1, INTERLACING_TAG>&)m );
974         return (FIELD<T1, INTERLACING_TAG>*) result;
975       }
976
977     %newobject __div__(const FIELD<T1, INTERLACING_TAG> & );
978     FIELD<T1, INTERLACING_TAG> * __div__(const FIELD<T1, INTERLACING_TAG> & m)
979       {
980         MESSAGE_MED("operator /  : Creation of the division of two FIELDs");
981         FIELD<T1, INTERLACING_TAG>* result =
982           FIELD<T1, INTERLACING_TAG>::div( *(FIELD<T1, INTERLACING_TAG>*)self ,
983                                            (FIELD<T1, INTERLACING_TAG>&)m );
984         return (FIELD<T1, INTERLACING_TAG>*) result;
985       }
986
987     %newobject addDeep(const FIELD<T1, INTERLACING_TAG> & );
988     FIELD<T1, INTERLACING_TAG> * addDeep(const FIELD<T1, INTERLACING_TAG> & m)
989       {
990         MESSAGE_MED("operator +  : Creation of the addition of two FIELDINTs");
991         FIELD<T1, INTERLACING_TAG>* result =
992           FIELD<T1, INTERLACING_TAG>::addDeep( *(FIELD<T1, INTERLACING_TAG>*)self ,
993                                                (FIELD<T1, INTERLACING_TAG>&)m );
994         return (FIELD<T1, INTERLACING_TAG>*) result;
995       }
996
997     %newobject subDeep(const FIELD<T1, INTERLACING_TAG> & );
998     FIELD<T1, INTERLACING_TAG> * subDeep(const FIELD<T1, INTERLACING_TAG> & m)
999       {
1000         MESSAGE_MED("operator -  : Creation of the substraction of two FIELDs");
1001         FIELD<T1, INTERLACING_TAG>* result =
1002           FIELD<T1, INTERLACING_TAG>::subDeep( *(FIELD<T1, INTERLACING_TAG>*)self ,
1003                                                (FIELD<T1, INTERLACING_TAG>&)m );
1004         return (FIELD<T1, INTERLACING_TAG>*) result;
1005       }
1006
1007     %newobject mulDeep(const FIELD<T1, INTERLACING_TAG> & );
1008     FIELD<T1, INTERLACING_TAG> * mulDeep(const FIELD<T1, INTERLACING_TAG> & m)
1009       {
1010         MESSAGE_MED("operator *  : Creation of the multiplication of two FIELDs");
1011         FIELD<T1, INTERLACING_TAG>* result =
1012           FIELD<T1, INTERLACING_TAG>::mulDeep( *(FIELD<T1, INTERLACING_TAG>*)self ,
1013                                                (FIELD<T1, INTERLACING_TAG>&)m );
1014         return (FIELD<T1, INTERLACING_TAG>*) result;
1015       }
1016
1017     %newobject divDeep(const FIELD<T1, INTERLACING_TAG> & );
1018     FIELD<T1, INTERLACING_TAG> * divDeep(const FIELD<T1, INTERLACING_TAG> & m)
1019       {
1020         MESSAGE_MED("operator /  : Creation of the division of two FIELDs");
1021         FIELD<T1, INTERLACING_TAG>* result =
1022           FIELD<T1, INTERLACING_TAG>::divDeep( *(FIELD<T1, INTERLACING_TAG>*)self ,
1023                                                (FIELD<T1, INTERLACING_TAG>&)m );
1024         return (FIELD<T1, INTERLACING_TAG>*) result;
1025       }
1026
1027     PyObject * getValue()
1028       {
1029         int size = self->getValueLength();
1030
1031         const T1 * value = self->getValue();
1032
1033 #ifdef WITH_NUMPY
1034         return TYPEMAP_OUTPUT_PY_ARRAY( value, size );
1035 #else
1036         TYPEMAP_OUTPUT_ARRAY(value, size, Binding< T1 >::Traducer,FIELD::getValue);
1037 #endif
1038       }
1039
1040     // returns values for geom type in NoInterlaceByType mode
1041     PyObject * getValueByType(int type)
1042       {
1043         int size = self->getValueByTypeLength(type);
1044
1045         const T1 * value = self->getValueByType(type);
1046
1047 #ifdef WITH_NUMPY
1048         return TYPEMAP_OUTPUT_PY_ARRAY( value, size );
1049 #else
1050         TYPEMAP_OUTPUT_ARRAY(value, size, Binding< T1 >::Traducer,FIELD::getValueByType());
1051 #endif
1052       }
1053
1054     // this method replaces getValueI() in FullInterlace mode
1055     PyObject * getRow(int index)
1056       {
1057         int size = self->getNumberOfComponents() * self->getNbGaussI( index );
1058
1059         const T1 * value = self->getRow(index);
1060
1061         TYPEMAP_OUTPUT_ARRAY(value, size, Binding< T1 >::Traducer,
1062                              FIELD::getRow);
1063       }
1064
1065     // this method replaces getValueI() in NoInterlace mode
1066     PyObject * getColumn(int index)
1067       {
1068         int size = (self->getSupport())->getNumberOfElements(MED_ALL_ELEMENTS);
1069
1070         const T1 * value = self->getColumn(index);
1071
1072         TYPEMAP_OUTPUT_ARRAY(value, size, Binding< T1 >::Traducer,
1073                              FIELD::getColumn);
1074       }
1075
1076     void allocValue2(int NumberOfComponents, int LengthValue)
1077       {
1078         self->allocValue(NumberOfComponents, LengthValue);
1079       }
1080
1081     %newobject extract(const SUPPORT *subSupport);
1082     FIELD<T1, INTERLACING_TAG> *extract(const SUPPORT *subSupport)
1083       {
1084         FIELD<T1, INTERLACING_TAG>* result=self->extract(subSupport);
1085         return (FIELD<T1, INTERLACING_TAG> *)result;
1086       }
1087   }
1088 };
1089
1090 %template(FIELDDOUBLE) FIELD<double, FullInterlace>;
1091 %template(FIELDDOUBLENOINTERLACE) FIELD<double, NoInterlace>;
1092 %template(FIELDDOUBLENOINTERLACEBYTYPE) FIELD<double, NoInterlaceByType>;
1093 %template(FIELDINT) FIELD<int, FullInterlace>;
1094 %template(FIELDINTNOINTERLACE) FIELD<int, NoInterlace>;
1095 %template(FIELDINTNOINTERLACEBYTYPE) FIELD<int, NoInterlaceByType>;
1096
1097 class GROUP : public SUPPORT
1098 {
1099 public:
1100   GROUP();
1101
1102   ~GROUP();
1103
1104   void setNumberOfFamilies(int numberOfFamilies);
1105   void setFamilies(vector< FAMILY * > Family);
1106
1107   int getNumberOfFamilies() const ;
1108   vector< FAMILY * > getFamilies() const ;
1109   FAMILY * getFamily(int i) const ;
1110 };
1111
1112 class GMESH
1113 {
1114 public :
1115   int addDriver(driverTypes driverType,
1116                 const char * fileName="Default File Name.med",
1117                 const char * driverName="Default Mesh Name",
1118                 med_mode_acces access=RDWR);
1119
1120   void rmDriver(int index=0);
1121
1122   void read(int index=0);
1123   void read(const GENDRIVER & genDriver);
1124   void read(driverTypes        driverType,
1125             const std::string& filename,
1126             const std::string& meshname);
1127
1128   void write(int index=0);
1129   void write(const GENDRIVER & driver,
1130              med_mode_acces medMode=WRONLY);
1131   void write(driverTypes        driverType,
1132              const std::string& filename,
1133              const std::string& meshname="",
1134              med_mode_acces medMode=WRONLY);
1135
1136   void setName(char * name);
1137
1138   int getSpaceDimension();
1139
1140   int getMeshDimension();
1141
1142   int getNumberOfNodes();
1143   
1144   bool getIsAGrid();
1145
1146   int getNumberOfTypes(medEntityMesh Entity);
1147
1148   int  getNumberOfElements(medEntityMesh Entity,medGeometryElement Type);
1149
1150   int getNumberOfFamilies(medEntityMesh Entity);
1151
1152   FAMILY* getFamily(medEntityMesh Entity,int i);
1153
1154   int getNumberOfGroups(medEntityMesh Entity);
1155
1156   GROUP * getGroup(medEntityMesh Entity,int i);
1157   GROUP*  getGroup(char* name);
1158
1159   medGeometryElement getElementType(medEntityMesh Entity,int Number);
1160
1161   SUPPORT * getSupportOnAll(medEntityMesh Entity);
1162
1163   std::string getName() const;
1164   
1165   std::string getCoordinatesSystem();
1166
1167   %extend {
1168
1169     PyObject* convertInMESH()
1170     {
1171       const MESH* mesh = self->convertInMESH();
1172       return SWIG_NewPointerObj((void *)mesh, $descriptor(MESH *), self->getIsAGrid() );
1173     }
1174
1175     %newobject getBoundaryElements(medEntityMesh );
1176     SUPPORT * getBoundaryElements(medEntityMesh Entity)
1177       {
1178         return self->getBoundaryElements(Entity);
1179       }
1180
1181     %newobject getSkin(const SUPPORT * );
1182     SUPPORT * getSkin(const SUPPORT * Support3D)
1183       {
1184         return self->getSkin(Support3D);
1185       }
1186
1187     %newobject mergeSupports(const vector< SUPPORT * > );
1188     SUPPORT * mergeSupports(const vector< SUPPORT * > Supports)
1189       {
1190         return self->mergeSupports(Supports);
1191       }
1192
1193     %newobject intersectSupports(const vector< SUPPORT * > );
1194     SUPPORT * intersectSupports(const vector< SUPPORT * > Supports)
1195       {
1196         return self->intersectSupports(Supports);
1197       }
1198
1199     %newobject mergeFieldsDouble(const vector< FIELDDOUBLE* > others);
1200     FIELD<double, FullInterlace> * mergeFieldsDouble(const vector< FIELDDOUBLE* > others)
1201       {
1202         return (FIELD<double, FullInterlace> *)self->mergeFields<double>(others);
1203       }
1204
1205     %newobject mergeFieldsInt(const vector< FIELDINT* > others);
1206     FIELD<int, FullInterlace> * mergeFieldsInt(const vector< FIELDINT* > others)
1207       {
1208         return (FIELD<int, FullInterlace> *)self->mergeFields<int>(others);
1209       }
1210
1211     %newobject __str__();
1212     const char* __str__()
1213       {
1214         ostringstream mess;
1215         mess << "Python Printing GMESH : " << *self << endl;
1216         return strdup(mess.str().c_str());
1217       }
1218
1219     %newobject getCoordinateName(int );
1220     const char * getCoordinateName(int i)
1221       {
1222         string tmp_str = self->getCoordinatesNames()[i];
1223         char * tmp = new char[strlen(tmp_str.c_str())+1];
1224         strcpy(tmp,tmp_str.c_str());
1225         return tmp;
1226       }
1227
1228     %newobject getCoordinateUnit(int );
1229     const char * getCoordinateUnit(int i)
1230       {
1231         string tmp_str = self->getCoordinatesUnits()[i];
1232         char * tmp = new char[strlen(tmp_str.c_str())+1];
1233         strcpy(tmp,tmp_str.c_str());
1234         return tmp;
1235       }
1236
1237     PyObject * getCoordinatesNames()
1238       {
1239         const string * array = self->getCoordinatesNames();
1240         int size = self->getSpaceDimension();
1241         TYPEMAP_OUTPUT_ARRAY(array, size, PyString_FromStdString,
1242                              MESH::getCoordinatesNames);
1243       }
1244
1245     PyObject * getCoordinatesUnits()
1246       {
1247         const string * array = self->getCoordinatesUnits();
1248         int size = self->getSpaceDimension();
1249         TYPEMAP_OUTPUT_ARRAY(array, size, PyString_FromStdString,
1250                              MESH::getCoordinatesUnits);
1251       }
1252
1253     PyObject * getTypes(medEntityMesh Entity)
1254       {
1255         const medGeometryElement * types = self->getTypes(Entity);
1256         int size = self->getNumberOfTypes(Entity);
1257         TYPEMAP_OUTPUT_ARRAY(types, size, PyInt_FromLong, MESH::getTypes);
1258       }
1259
1260     %newobject getVolume(const SUPPORT * , bool );
1261     FIELD<double, FullInterlace> * getVolume(const SUPPORT * Support, bool isAbs = true)
1262       {
1263         return (FIELD<double, FullInterlace> *) self->getVolume(Support,isAbs);
1264       }
1265
1266     %newobject getArea(const SUPPORT * );
1267     FIELD<double, FullInterlace> * getArea(const SUPPORT * Support)
1268       {
1269         return (FIELD<double, FullInterlace> *) self->getArea(Support);
1270       }
1271
1272     %newobject getLength(const SUPPORT * );
1273     FIELD<double, FullInterlace> * getLength(const SUPPORT * Support)
1274       {
1275         return (FIELD<double, FullInterlace> *) self->getLength(Support);
1276       }
1277
1278     %newobject getNormal(const SUPPORT * );
1279     FIELD<double, FullInterlace> * getNormal(const SUPPORT * Support)
1280       {
1281         return (FIELD<double, FullInterlace> *) self->getNormal(Support);
1282       }
1283
1284     %newobject getBarycenter(const SUPPORT * );
1285     FIELD<double, FullInterlace> * getBarycenter(const SUPPORT * Support)
1286       {
1287         return (FIELD<double, FullInterlace> *) self->getBarycenter(Support);
1288       }
1289   }
1290 private:
1291   GMESH(); // prohibit SWIG to generate a default constructor
1292
1293 };
1294
1295 class MESH : public GMESH
1296 {
1297 public :
1298   MESH();
1299   MESH(MESH &m);
1300   MESH (driverTypes driverType, const char* fileName, const char* meshName);
1301
1302   ~MESH();
1303
1304   void convertToPoly();
1305
1306   const double getCoordinate(int Number, int Axis);
1307
1308   void calculateConnectivity(medConnectivity ConnectivityType,medEntityMesh Entity);
1309
1310   int getElementNumber(medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type, int * connectivity);
1311
1312   CELLMODEL * getCellsTypes(medEntityMesh Entity);
1313
1314   int getElementContainingPoint(const double *coord);
1315
1316   %extend {
1317
1318     CELLMODEL getCellType(medEntityMesh Entity,int i)
1319       {
1320         return self->getCellsTypes(Entity)[i];
1321       }
1322
1323     %newobject __str__();
1324     const char* __str__()
1325       {
1326         ostringstream mess;
1327         mess << "Python Printing MESH : " << *self << endl;
1328         return strdup(mess.str().c_str());
1329       }
1330
1331     PyObject * getCoordinates(medModeSwitch Mode)
1332       {
1333         const double * array = self->getCoordinates(Mode);
1334         int size = (self->getSpaceDimension())*(self->getNumberOfNodes());
1335 #ifdef WITH_NUMPY
1336         return TYPEMAP_OUTPUT_PY_ARRAY( array, size );
1337 #else
1338         TYPEMAP_OUTPUT_ARRAY(array, size, PyFloat_FromDouble,MESH::getCoordinates);
1339 #endif
1340       }
1341
1342     PyObject * getConnectivity(medConnectivity ConnectivityType,
1343                                medEntityMesh Entity,
1344                                medGeometryElement Type)
1345       {
1346         const int * connectivity = self->getConnectivity(ConnectivityType, Entity,Type);
1347         int size = self->getConnectivityLength(ConnectivityType,Entity,Type);
1348 #ifdef WITH_NUMPY
1349         return TYPEMAP_OUTPUT_PY_ARRAY( connectivity, size );
1350 #else
1351         TYPEMAP_OUTPUT_ARRAY(connectivity, size, PyInt_FromLong,MESH::getConnectivity );
1352 #endif
1353       }
1354
1355     PyObject * getConnectivityIndex(medConnectivity ConnectivityType,
1356                                     medEntityMesh Entity)
1357       {
1358         const int * index = self->getConnectivityIndex(ConnectivityType,Entity);
1359         int size = (self->getNumberOfElements(Entity,MED_ALL_ELEMENTS))+1;
1360 #ifdef WITH_NUMPY
1361         return TYPEMAP_OUTPUT_PY_ARRAY( index, size );
1362 #else
1363         TYPEMAP_OUTPUT_ARRAY(index,size,PyInt_FromLong,MESH::getConnectivityIndex);
1364 #endif
1365       }
1366
1367     PyObject * getReverseConnectivity(medConnectivity ConnectivityType,
1368                                       medEntityMesh Entity=MED_CELL)
1369       {
1370         const int * conn = self->getReverseConnectivity(ConnectivityType,Entity);
1371         int size = self->getReverseConnectivityLength(ConnectivityType,Entity);
1372 #ifdef WITH_NUMPY
1373         return TYPEMAP_OUTPUT_PY_ARRAY( conn, size );
1374 #else
1375         TYPEMAP_OUTPUT_ARRAY(conn, size, PyInt_FromLong,MESH::getReverseConnectivity);
1376 #endif
1377       }
1378
1379     PyObject * getReverseConnectivityIndex(medConnectivity ConnectivityType,
1380                                            medEntityMesh Entity=MED_CELL)
1381       {
1382         const int * index = self->getReverseConnectivityIndex(ConnectivityType,Entity);
1383         int size=self->getReverseConnectivityIndexLength(ConnectivityType,Entity);
1384 #ifdef WITH_NUMPY
1385         return TYPEMAP_OUTPUT_PY_ARRAY( index, size );
1386 #else
1387         TYPEMAP_OUTPUT_ARRAY(index,size, PyInt_FromLong,MESH::getReverseConnectivityIndex);
1388 #endif
1389       }
1390
1391     PyObject * getGlobalNumberingIndex(medEntityMesh Entity)
1392       {
1393         const int * numberingIndex = self->getGlobalNumberingIndex(Entity);
1394         int nbOfTypes = self->getNumberOfTypes(Entity);
1395         int size = nbOfTypes+1;
1396         TYPEMAP_OUTPUT_ARRAY(numberingIndex, size, PyInt_FromLong,
1397                              MESH::getGlobalNumberingIndex);
1398       }
1399   }
1400 } ;
1401
1402 class MESHING: public MESH
1403 {
1404 public :
1405   MESHING();
1406   ~MESHING();
1407
1408   void setCoordinates      (const int SpaceDimension,
1409                             const int NumberOfNodes,
1410                             const double * Coordinates,
1411                             std::string System,
1412                             const medModeSwitch Mode) ;
1413   void setCoordinatesNames (const std::string * names) ;
1414   void setCoordinateName   (const std::string name, const int i) ;
1415   void setCoordinatesUnits (const std::string * units);
1416   void setCoordinateUnit   (const std::string unit, const int i) ;
1417
1418   void setNumberOfTypes    (const int NumberOfTypes,
1419                             const medEntityMesh Entity) ;
1420
1421   void setTypes            (const medGeometryElement * Types,
1422                             const medEntityMesh Entity) ;
1423
1424   void setNumberOfElements (const int * NumberOfElements,
1425                             const medEntityMesh Entity) ;
1426
1427   void setConnectivity     (const medEntityMesh Entity,
1428                             const medGeometryElement Type,
1429                             const int * Connectivity,
1430                             const int * ConnectivityIndex=0) ;
1431
1432   void addGroup            (const GROUP & Group) ;
1433
1434 };
1435
1436 class GRID : public GMESH
1437 {
1438  public:
1439   GRID();
1440
1441   GRID(driverTypes driverType, const char * fileName, const char * meshName);
1442
1443   GRID(const GRID &m);
1444
1445   ~GRID();
1446
1447   int getNodeNumber(const int i, const int j=0, const int k=0) const ;
1448
1449   int getCellNumber(const int i, const int j=0, const int k=0) const ;
1450
1451   int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0) const ;
1452
1453   int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0) const ;
1454
1455   med_grid_type getGridType();
1456
1457   int getArrayLength( const int Axis );
1458
1459   const double getArrayValue (const int Axis, const int i);
1460
1461   void setGridType(med_grid_type gridType);
1462
1463   %extend {
1464
1465     PyObject * getEntityPosition(const medEntityMesh Entity, const int Number)
1466     {
1467       int ijk[3], Axis;
1468       int i=0, size = self->getSpaceDimension();
1469       int j=0;
1470       switch (Entity) {
1471       case MED_CELL:
1472         self->getCellPosition(Number, ijk[0], ijk[1], ijk[2]);
1473         break;
1474       case MED_NODE:
1475         self->getNodePosition(Number, ijk[0], ijk[1], ijk[2]);
1476         break;
1477       case MED_FACE:
1478         self->getFacePosition(Number, Axis, ijk[0], ijk[1], ijk[2]);
1479         size++;
1480         i++;
1481         break;
1482       case MED_EDGE:
1483         self->getEdgePosition(Number, Axis, ijk[0], ijk[1], ijk[2]);
1484         size++;
1485         i++;
1486         break;
1487       default:
1488         const char * message = "Error in GRID::getEntityPosition: wrong Entity";
1489         PyErr_SetString(PyExc_RuntimeError, (char *)message);
1490         return NULL;
1491       }
1492       PyObject *py_list = PyList_New( size );
1493       for (; i < size; ++i)
1494       {
1495         int err = PyList_SetItem(py_list, i,
1496                                  Py_BuildValue("i", ijk[j++]));
1497         if(err)
1498         {
1499           const char * message = "Error in GRID::getNodePosition";
1500           PyErr_SetString(PyExc_RuntimeError, (char *)message);
1501           return NULL;
1502         }
1503       }
1504       if (Entity == MED_FACE || Entity == MED_EDGE)
1505         PyList_SetItem(py_list, 0, Py_BuildValue("i", Axis));
1506
1507       PyObject * result = Py_BuildValue("O", py_list);
1508       Py_DECREF(py_list);
1509       return result;
1510     }
1511   }
1512 };
1513
1514 class PointLocator
1515 {
1516 public:
1517         PointLocator(const MESH& mesh);
1518         virtual ~PointLocator();
1519         %extend{
1520           PyObject* locate(const double* x)
1521             {
1522                     std::list<int> mylist = self->locate(x);
1523                           if (mylist.size()>10)
1524                           {
1525                           const char * message = "Error in PointLocator : SWIG interface limits the number of cells to 10";
1526         PyErr_SetString(PyExc_RuntimeError, (char *)message);
1527         return NULL;
1528                                 }
1529                           
1530                           int array[10]; // maximum number of cells in which the point lies
1531                           int index=0;
1532                           for (list<int>::const_iterator iter= mylist.begin();
1533                            iter != mylist.end();
1534                                 iter++)
1535                                     array[index++]= *iter;
1536                     TYPEMAP_OUTPUT_ARRAY(array, mylist.size(), PyInt_FromLong,
1537                              PointLocator::locate);
1538       }
1539    }
1540 };
1541
1542 class MEDFILEBROWSER
1543 {
1544  public:
1545   MEDFILEBROWSER();
1546   MEDFILEBROWSER (const std::string & fileName);
1547   void readFileStruct(const std::string & fileName);
1548
1549   std::string  getFileName();
1550
1551   int getNumberOfMeshes ();
1552   int getNumberOfFields ();
1553
1554   bool isStructuredMesh(const std::string & meshName);
1555
1556   med_type_champ getFieldType (const std::string & fieldName);
1557   std::string    getMeshName  (const std::string & fieldName);
1558
1559   %extend {
1560
1561     std::string getMeshName(int i)
1562     {
1563       return self->getMeshNames().at(i);
1564     }
1565
1566     std::string getFieldName(int i)
1567     {
1568       return self->getFieldNames().at(i);
1569     }
1570
1571     PyObject *getMeshNames()
1572       {
1573         std::vector< std::string > names = self->getMeshNames();
1574         std::string* array = &names[0];
1575         TYPEMAP_OUTPUT_ARRAY(array, names.size(), PyString_FromStdString,
1576                              MEDFILEBROWSER::getMeshNames);
1577       }
1578
1579
1580     PyObject *getFieldNames()
1581       {
1582         std::vector< std::string > names = self->getFieldNames();
1583         std::string* array = &names[0];
1584         TYPEMAP_OUTPUT_ARRAY(array, names.size(), PyString_FromStdString,
1585                              MEDFILEBROWSER::getMeshNames);
1586       }
1587
1588     PyObject* getFieldIteration (char* fieldName)
1589       {
1590         VEC_DT_IT_ vec_dtit = self->getFieldIteration (fieldName);
1591         PyObject *py_list = PyList_New(vec_dtit.size());
1592         for (unsigned i=0; i < vec_dtit.size(); i++)
1593         {
1594           DT_IT_* dtit = new DT_IT_(vec_dtit[i]);
1595           PyObject * pyDTIT= SWIG_NewPointerObj((void *) dtit, $descriptor(DT_IT_*), 1);
1596           int err = PyList_SetItem(py_list, i, pyDTIT);
1597           if(err)
1598           {
1599             PyErr_SetString(PyExc_RuntimeError, "Error in getFieldIteration");
1600             return NULL;
1601           }
1602         }
1603
1604         PyObject * result = Py_BuildValue("O", py_list);
1605         Py_DECREF(py_list);
1606         return result;
1607         
1608       }
1609   }
1610 };
1611
1612 /*
1613   API de GIBI_MESH_[RDONLY,WRONLY,RDWR]_DRIVER
1614 */
1615
1616 class GIBI_MESH_RDONLY_DRIVER : public GENDRIVER
1617 {
1618 public :
1619   GIBI_MESH_RDONLY_DRIVER() ;
1620
1621   GIBI_MESH_RDONLY_DRIVER(const GIBI_MESH_RDONLY_DRIVER & driver) ;
1622
1623   GIBI_MESH_RDONLY_DRIVER(const char* fileName, MESH * ptrMesh);
1624
1625   ~GIBI_MESH_RDONLY_DRIVER() ;
1626
1627   %extend {
1628
1629     %newobject __str__();
1630     const char* __str__()
1631       {
1632         ostringstream mess;
1633         mess << "Python Printing GIBI_MESH_RDONLY_DRIVER : " << *self << endl;
1634         return strdup(mess.str().c_str());
1635       }
1636   }
1637 };
1638
1639 class GIBI_MESH_WRONLY_DRIVER : public GENDRIVER
1640 {
1641 public :
1642   GIBI_MESH_WRONLY_DRIVER() ;
1643
1644   GIBI_MESH_WRONLY_DRIVER(const GIBI_MESH_WRONLY_DRIVER & driver) ;
1645
1646   GIBI_MESH_WRONLY_DRIVER(const char* fileName, GMESH * ptrMesh);
1647
1648   ~GIBI_MESH_WRONLY_DRIVER() ;
1649
1650   %extend {
1651
1652     %newobject __str__();
1653     const char* __str__()
1654       {
1655         ostringstream mess;
1656         mess << "Python Printing GIBI_MESH_WRONLY_DRIVER : " << *self << endl;
1657         return strdup(mess.str().c_str());
1658       }
1659   }
1660 };
1661
1662 class GIBI_MESH_RDWR_DRIVER : public virtual GIBI_MESH_RDONLY_DRIVER,
1663                               public virtual GIBI_MESH_WRONLY_DRIVER
1664 {
1665 public :
1666   GIBI_MESH_RDWR_DRIVER() ;
1667
1668   GIBI_MESH_RDWR_DRIVER(const GIBI_MESH_RDWR_DRIVER & driver) ;
1669
1670   GIBI_MESH_RDWR_DRIVER(const char* fileName, MESH * ptrMesh);
1671
1672   ~GIBI_MESH_RDWR_DRIVER() ;
1673
1674   %extend {
1675
1676     %newobject __str__();
1677     const char* __str__()
1678       {
1679         ostringstream mess;
1680         mess << "Python Printing GIBI_MESH_RDWR_DRIVER : " << *self << endl;
1681         return strdup(mess.str().c_str());
1682       }
1683   }
1684 };
1685
1686 class GIBI_MED_RDONLY_DRIVER : public GENDRIVER
1687 {
1688 public :
1689   GIBI_MED_RDONLY_DRIVER() ;
1690
1691   GIBI_MED_RDONLY_DRIVER(const GIBI_MED_RDONLY_DRIVER & driver) ;
1692
1693   MESH* getMesh();
1694
1695   %extend {
1696     GIBI_MED_RDONLY_DRIVER(char * fileName)
1697       {
1698         std::vector< FIELD_* > fields;
1699         return new GIBI_MED_RDONLY_DRIVER(string(fileName), fields) ;
1700       }
1701
1702     PyObject * read ( void )
1703     {
1704       std::vector< FIELD_* > fields;
1705       GIBI_MED_RDONLY_DRIVER tmp( self->getFileName(), fields) ;
1706       tmp.open();
1707       tmp.read();
1708       tmp.close();
1709       *self = tmp;
1710       tmp.getMesh();
1711
1712       PyObject* py_list = PyList_New(fields.size());
1713
1714       for (unsigned i=0;i<fields.size();i++)
1715       {
1716         PyObject * f = SWIG_NewPointerObj((void*)fields.at(i),$descriptor(FIELDDOUBLE*),1);
1717         PyList_SetItem(py_list,i,f);
1718       }
1719       PyObject * result = Py_BuildValue("O", py_list);
1720       Py_DECREF(py_list);
1721       return result;
1722     }
1723
1724     %newobject __str__();
1725     const char* __str__()
1726       {
1727         ostringstream mess;
1728         mess << "Python Printing GIBI_MED_RDONLY_DRIVER : " << *self << endl;
1729         return strdup(mess.str().c_str());
1730       }
1731
1732   }
1733 };
1734
1735 class GIBI_MED_WRONLY_DRIVER : public GENDRIVER
1736 {
1737 public :
1738   GIBI_MED_WRONLY_DRIVER() ;
1739
1740   GIBI_MED_WRONLY_DRIVER(const GIBI_MED_WRONLY_DRIVER & driver) ;
1741
1742   GIBI_MED_WRONLY_DRIVER(const char*             fileName,
1743                          vector< const FIELD_* > fields,
1744                          GMESH *                 ptrMesh) ;
1745
1746   %extend {
1747     %newobject __str__();
1748     const char* __str__()
1749       {
1750         ostringstream mess;
1751         mess << "Python Printing GIBI_MED_WRONLY_DRIVER : " << *self << endl;
1752         return strdup(mess.str().c_str());
1753       }
1754
1755   }
1756 };
1757
1758 /*!
1759  * \brief set/get format of vtk file
1760  */
1761 bool getVtkBinaryFormatForWriting();
1762
1763 void setVtkBinaryFormatForWriting(bool isBinary);
1764
1765 %{
1766   bool getVtkBinaryFormatForWriting()
1767     {
1768       return DRIVERFACTORY::getVtkBinaryFormatForWriting();
1769     }
1770   void setVtkBinaryFormatForWriting(bool isBinary)
1771     {
1772       DRIVERFACTORY::setVtkBinaryFormatForWriting(isBinary);
1773     }
1774 %}
1775 /*!
1776  * \brief Driver to write fields to vtk file
1777  */
1778 class VTK_MED_DRIVER : public GENDRIVER
1779 {
1780 public:
1781   VTK_MED_DRIVER(const char* fileName, vector< const FIELD_* > fields);
1782 };
1783
1784 /*
1785   API de PORFLOW_MESH_[RDONLY,WRONLY,RDWR]_DRIVER
1786 */
1787
1788 class PORFLOW_MESH_RDONLY_DRIVER : public GENDRIVER
1789 {
1790 public :
1791   PORFLOW_MESH_RDONLY_DRIVER() ;
1792
1793   PORFLOW_MESH_RDONLY_DRIVER(const PORFLOW_MESH_RDONLY_DRIVER & driver) ;
1794
1795   PORFLOW_MESH_RDONLY_DRIVER(const char* fileName, MESH * ptrMesh);
1796
1797   ~PORFLOW_MESH_RDONLY_DRIVER() ;
1798
1799   %extend {
1800
1801     %newobject __str__();
1802     const char* __str__()
1803       {
1804         ostringstream mess;
1805         mess << "Python Printing PORFLOW_MESH_RDONLY_DRIVER : " << *self << endl;
1806         return strdup(mess.str().c_str());
1807       }
1808   }
1809 };
1810
1811 class PORFLOW_MESH_WRONLY_DRIVER : public GENDRIVER
1812 {
1813 public :
1814   PORFLOW_MESH_WRONLY_DRIVER() ;
1815
1816   PORFLOW_MESH_WRONLY_DRIVER(const PORFLOW_MESH_WRONLY_DRIVER & driver) ;
1817
1818   PORFLOW_MESH_WRONLY_DRIVER(char * fileName, GMESH * ptrMesh);
1819
1820   ~PORFLOW_MESH_WRONLY_DRIVER() ;
1821
1822   %extend {
1823
1824     %newobject __str__();
1825     const char* __str__()
1826       {
1827         ostringstream mess;
1828         mess << "Python Printing PORFLOW_MESH_WRONLY_DRIVER : " << *self << endl;
1829         return strdup(mess.str().c_str());
1830       }
1831   }
1832 };
1833
1834 class PORFLOW_MESH_RDWR_DRIVER : public virtual PORFLOW_MESH_RDONLY_DRIVER,
1835                                  public virtual PORFLOW_MESH_WRONLY_DRIVER
1836 {
1837 public :
1838   PORFLOW_MESH_RDWR_DRIVER() ;
1839
1840   PORFLOW_MESH_RDWR_DRIVER(const PORFLOW_MESH_RDWR_DRIVER & driver) ;
1841
1842   PORFLOW_MESH_RDWR_DRIVER(const char * fileName, MESH * ptrMesh);
1843
1844   ~PORFLOW_MESH_RDWR_DRIVER() ;
1845
1846   %extend {
1847
1848     %newobject __str__();
1849     const char* __str__()
1850       {
1851         ostringstream mess;
1852         mess << "Python Printing PORFLOW_MESH_RDWR_DRIVER : " << *self << endl;
1853         return strdup(mess.str().c_str());
1854       }
1855   }
1856 };
1857
1858 /*
1859   API de MED_MESH_[RDONLY,WRONLY,RDWR]_DRIVER
1860 */
1861
1862 class MED_MESH_RDONLY_DRIVER : public GENDRIVER
1863 {
1864  public :
1865
1866   MED_MESH_RDONLY_DRIVER(const char * fileName,  GMESH * ptrMesh);
1867
1868   ~MED_MESH_RDONLY_DRIVER();
1869
1870   void desactivateFacesComputation();
1871
1872   void activateFacesComputation();
1873
1874   %extend {
1875
1876     %newobject __str__();
1877     const char* __str__()
1878       {
1879         ostringstream mess;
1880         mess << "Python Printing MED_MESH_RDONLY_DRIVER : " << *self << endl;
1881         return strdup(mess.str().c_str());
1882       }
1883   }
1884 };
1885
1886 class MED_MESH_WRONLY_DRIVER : public GENDRIVER
1887 {
1888  public :
1889   ~MED_MESH_WRONLY_DRIVER();
1890
1891   MED_MESH_WRONLY_DRIVER(const char * fileName,  GMESH * ptrMesh);
1892
1893   %extend {
1894
1895     %newobject __str__();
1896     const char* __str__()
1897       {
1898         ostringstream mess;
1899         mess << "Python Printing MED_MESH_WRONLY_DRIVER : " << *self << endl;
1900         return strdup(mess.str().c_str());
1901       }
1902   }
1903 };
1904
1905 class MED_MESH_RDWR_DRIVER : public virtual MED_MESH_RDONLY_DRIVER,
1906                              public virtual MED_MESH_WRONLY_DRIVER
1907 {
1908  public :
1909
1910   ~MED_MESH_RDWR_DRIVER();
1911
1912   MED_MESH_RDWR_DRIVER(const char * fileName,  GMESH * ptrMesh);
1913
1914   %extend {
1915
1916     %newobject __str__();
1917     const char* __str__()
1918       {
1919         ostringstream mess;
1920         mess << "Python Printing MED_MESH_RDWR_DRIVER : " << *self << endl;
1921         return strdup(mess.str().c_str());
1922       }
1923   }
1924 };
1925
1926 /*
1927   API de MED_FIELD_[RDONLY,WRONLY,RDWR]_DRIVER
1928 */
1929
1930 template< class T1 >
1931 class MED_FIELD_RDONLY_DRIVER : public GENDRIVER
1932 {
1933 public:
1934
1935   MED_FIELD_RDONLY_DRIVER(const char * fileName, FIELD<T1, FullInterlace > * ptrField);
1936
1937   ~MED_FIELD_RDONLY_DRIVER();
1938
1939   %extend {
1940
1941     %newobject __str__();
1942     const char* __str__()
1943       {
1944         ostringstream mess;
1945         mess << "Python Printing MED_FIELD_RDONLY_DRIVER : " << *self << endl;
1946         return strdup(mess.str().c_str());
1947       }
1948   }
1949 };
1950 %template ( MED_FIELDDOUBLE_RDONLY_DRIVER ) MED_FIELD_RDONLY_DRIVER< double >;
1951 %template ( MED_FIELDINT_RDONLY_DRIVER ) MED_FIELD_RDONLY_DRIVER< int >;
1952
1953
1954 template < class T1 >
1955 class MED_FIELD_WRONLY_DRIVER : public GENDRIVER
1956 {
1957 public:
1958
1959   MED_FIELD_WRONLY_DRIVER(const char * fileName, FIELD<T1, FullInterlace> * ptrField);
1960
1961   ~MED_FIELD_WRONLY_DRIVER();
1962
1963   %extend {
1964     %newobject __str__();
1965     const char* __str__()
1966       {
1967         ostringstream mess;
1968         mess << "Python Printing MED_FIELD_WRONLY_DRIVER : " << *self << endl;
1969         return strdup(mess.str().c_str());
1970       }
1971   }
1972 };
1973 %template ( MED_FIELDDOUBLE_WRONLY_DRIVER ) MED_FIELD_WRONLY_DRIVER< double >;
1974 %template ( MED_FIELDINT_WRONLY_DRIVER ) MED_FIELD_WRONLY_DRIVER< int >;
1975
1976
1977 template< class T1 >
1978 class MED_FIELD_RDWR_DRIVER : public virtual MED_FIELD_RDONLY_DRIVER< T1 >, public virtual MED_FIELD_WRONLY_DRIVER< T1 >
1979 {
1980 public:
1981
1982   MED_FIELD_RDWR_DRIVER(const char * fileName, FIELD<T1, FullInterlace> * ptrField);
1983
1984   ~MED_FIELD_RDWR_DRIVER();
1985
1986   %extend {
1987
1988     %newobject __str__();
1989     const char* __str__()
1990       {
1991         ostringstream mess;
1992         mess << "Python Printing MED_FIELD_RDWR_DRIVER : " << *self << endl;
1993         return strdup(mess.str().c_str());
1994       }
1995   }
1996 };
1997 %template ( MED_FIELDDOUBLE_RDWR_DRIVER ) MED_FIELD_RDWR_DRIVER< double >;
1998 %template ( MED_FIELDINT_RDWR_DRIVER ) MED_FIELD_RDWR_DRIVER< int >;
1999
2000
2001 template< class T1 >
2002 class ASCII_FIELD_DRIVER  : public GENDRIVER
2003 {
2004 public:
2005   ASCII_FIELD_DRIVER(const char *fileName, FIELD<T1, FullInterlace> * ptrField, med_sort_direc direction, const char *priority);
2006   ~ASCII_FIELD_DRIVER();
2007 };
2008
2009 %template (ASCII_FIELDDOUBLE_DRIVER) ASCII_FIELD_DRIVER< double >;
2010 %template (ASCII_FIELDINT_DRIVER) ASCII_FIELD_DRIVER< int >;
2011
2012 //=======================================================================
2013 /*
2014   EnSight drivers
2015 */
2016 // ---------------------------------------------------------------
2017 //!< supported formats
2018 enum EnSightFormat { ENSIGHT_6, ENSIGHT_GOLD };
2019
2020 // ---------------------------------------------------------------
2021 //!< set writing format
2022
2023 void setEnSightFormatForWriting (EnSightFormat format, bool isBinary);
2024
2025 // ---------------------------------------------------------------
2026 //!< To raise or not if MEDMEM-EnSight incompatibility encounters or suspected.
2027 // See MEDMEM_EnsightUtils.hxx for raison why
2028
2029 void setIgnoreIncompatibility(bool toIgnore=true);
2030
2031 // ---------------------------------------------------------------
2032 //!< EnSight reading driver reads all meshes and fields
2033
2034 class ENSIGHT_MED_RDONLY_DRIVER : public GENDRIVER
2035 {
2036 public:
2037
2038   %extend {
2039     ENSIGHT_MED_RDONLY_DRIVER(const std::string & fileName)
2040     {
2041       vector< FIELD_* > fields;
2042       return new ENSIGHT_MED_RDONLY_DRIVER(fileName,fields);
2043     }
2044
2045     PyObject * read()
2046     {
2047       std::vector< FIELD_* > fields;
2048       ENSIGHT_MED_RDONLY_DRIVER tmp( self->getFileName(), fields) ;
2049       tmp.read();
2050
2051       PyObject* py_list = PyList_New(fields.size());
2052
2053       for (unsigned i=0;i<fields.size();i++)
2054       {
2055         PyObject * f = SWIG_NewPointerObj((void*)fields.at(i),$descriptor(FIELD_*),1);
2056         PyList_SetItem(py_list,i,f);
2057       }
2058       PyObject * result = Py_BuildValue("O", py_list);
2059       Py_DECREF(py_list);
2060       return result;
2061     }
2062   }
2063 };
2064 // ---------------------------------------------------------------
2065 //!< EnSight writing driver
2066
2067 class ENSIGHT_MED_WRONLY_DRIVER : public GENDRIVER
2068 {
2069 public :
2070   ENSIGHT_MED_WRONLY_DRIVER(const std::string & fileName, const vector< const FIELD_* > fields);
2071   void write();
2072 };
2073 // ---------------------------------------------------------------
2074 //!< EnSight mesh reading driver
2075
2076 class ENSIGHT_MESH_RDONLY_DRIVER : public GENDRIVER
2077 {
2078 public :
2079   //!< to read mesh of index-th time step
2080   ENSIGHT_MESH_RDONLY_DRIVER(const std::string & fileName, MESH * ptrMesh, int index=1);
2081   void read();
2082 };
2083 // ---------------------------------------------------------------
2084 //!< Writing EnSight mesh driver.
2085
2086 class ENSIGHT_MESH_WRONLY_DRIVER : public GENDRIVER
2087 {
2088 public :
2089   ENSIGHT_MESH_WRONLY_DRIVER(const std::string & fileName, GMESH * ptrMesh, bool append=false);
2090   void write();
2091 };
2092 // ---------------------------------------------------------------
2093 //!< EnSight field reading driver
2094
2095 class ENSIGHT_FIELD_RDONLY_DRIVER : public GENDRIVER
2096 {
2097 public :
2098   //!< Set the name of the FIELD in EnSight file
2099   void setFieldName(const std::string & fieldName);
2100   //!<  read the field of a specified name and index-th time step.
2101   ENSIGHT_FIELD_RDONLY_DRIVER(const std::string & fileName, FIELD_ * ptrField, int step=1);
2102   void read();
2103 };
2104 // ---------------------------------------------------------------
2105 //!< Writing EnSight field driver.
2106
2107 class ENSIGHT_FIELD_WRONLY_DRIVER : public GENDRIVER
2108 {
2109 public :
2110   //!< Set the name of the FIELD in EnSight file
2111   void setFieldName(const std::string & fieldName);
2112   ENSIGHT_FIELD_WRONLY_DRIVER(const std::string & fileName, FIELD_ * ptrField);
2113   //!<  Write FIELD, the mesh is supposed to be written in this file.
2114   void write();
2115 };
2116 // end of EnSight drivers
2117 //=======================================================================
2118
2119
2120 template <class INTERLACING_TAG> class GAUSS_LOCALIZATION
2121 {
2122  public:
2123
2124   GAUSS_LOCALIZATION();
2125
2126   ~GAUSS_LOCALIZATION();
2127
2128   std::string getName() const ;
2129
2130   medGeometryElement getType() const ;
2131
2132   int getNbGauss() const ;
2133
2134   medModeSwitch  getInterlacingType() const;
2135
2136   %extend {
2137     GAUSS_LOCALIZATION<INTERLACING_TAG>(char * locName,
2138                                         const medGeometryElement
2139                                         typeGeo,
2140                                         const int  nGauss,
2141                                         const double * cooRef,
2142                                         const double * cooGauss,
2143                                         const double * wg)
2144       {
2145         return new GAUSS_LOCALIZATION<INTERLACING_TAG>(string(locName),
2146                                                        typeGeo, nGauss, cooRef,
2147                                                        cooGauss, wg);
2148       }
2149
2150     %newobject __str__();
2151     const char* __str__()
2152       {
2153         ostringstream mess;
2154         mess << "Python Printing GAUSS_LOCALIZATION : " << *self << endl;
2155         return strdup(mess.str().c_str());
2156       }
2157
2158     PyObject * getRefCoo () const
2159       {
2160         typedef  MEDMEM_ArrayInterface<double,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss;
2161
2162         ArrayNoGauss cooRef = self->getRefCoo();
2163         int size = cooRef.getArraySize();
2164         double * cooRefPtr = cooRef.getPtr();
2165         TYPEMAP_OUTPUT_ARRAY(cooRefPtr, size, PyFloat_FromDouble,
2166                              GAUSS_LOCALIZATION::getRefCoo);
2167       }
2168
2169     PyObject * getGsCoo () const
2170       {
2171         typedef  MEDMEM_ArrayInterface<double,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss;
2172         ArrayNoGauss cooGauss = self->getGsCoo();
2173         int size = cooGauss.getArraySize();
2174         double * cooGaussPtr = cooGauss.getPtr();
2175         TYPEMAP_OUTPUT_ARRAY(cooGaussPtr, size, PyFloat_FromDouble,
2176                              GAUSS_LOCALIZATION::getGsCoo);
2177       }
2178
2179     PyObject * getWeight () const
2180       {
2181         vector<double> wg = self->getWeight();
2182         double * wgPtr = &wg[0];
2183         TYPEMAP_OUTPUT_ARRAY(wgPtr, wg.size(), PyFloat_FromDouble,
2184                              GAUSS_LOCALIZATION::getWeight);
2185       }
2186   }
2187 };
2188
2189 %template (GAUSS_LOCALIZATION_FULL) GAUSS_LOCALIZATION<FullInterlace> ;
2190 %template (GAUSS_LOCALIZATION_NO) GAUSS_LOCALIZATION<NoInterlace> ;
2191
2192 %{
2193   template <class T, class INTERLACING_TAG>
2194     FIELD<T, INTERLACING_TAG> * createFieldScalarProduct(FIELD<T, INTERLACING_TAG> * field1,
2195                                                          FIELD<T, INTERLACING_TAG> * field2)
2196     {
2197       return (FIELD<T, INTERLACING_TAG> *)
2198         FIELD<T, INTERLACING_TAG>::scalarProduct((FIELD<T, INTERLACING_TAG>)*field1,
2199                                                  (FIELD<T, INTERLACING_TAG>)*field2);
2200     }
2201
2202   template <class T, class INTERLACING_TAG>
2203     FIELD<T, INTERLACING_TAG> * createFieldScalarProductDeep(FIELD<T, INTERLACING_TAG> * field1,
2204                                                              FIELD<T, INTERLACING_TAG> * field2)
2205     {
2206       return (FIELD<T, INTERLACING_TAG>*) FIELD<T, INTERLACING_TAG>::scalarProduct((FIELD<T, INTERLACING_TAG>)*field1,
2207                                                                                    (FIELD<T, INTERLACING_TAG>)*field2, true);
2208     }
2209
2210   template<class T, class INTERLACING_TAG>
2211     FIELD<T, INTERLACING_TAG> * createTypedFieldFromField(FIELD_ * field)
2212     {
2213       MESSAGE_MED("createTypedFieldFromField : Constructor (for Python API) FIELD<T> with parameter FIELD_");
2214       MESSAGE_MED("Its returns a proper cast of the input pointer :: FIELD_ --> FIELD<T>");
2215       if ( field ) {
2216         if (field->getInterlacingType() != SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType)
2217           throw MEDEXCEPTION("cast to wrong medModeSwitch (_interlacingType)");
2218         if (field->getValueType() != SET_VALUE_TYPE<T>::_valueType)
2219           throw MEDEXCEPTION("cast to wrong med_type_champ (_valueType)");
2220       }
2221       return (FIELD<T, INTERLACING_TAG> *) field;
2222     }
2223
2224   template <class T> FIELD<T, FullInterlace> *
2225     createTypedFieldConvertFullInterlace(const FIELD<T, NoInterlace> & field )
2226     {
2227       return FieldConvert(field);
2228     }
2229
2230   template <class T> FIELD<T, NoInterlace> *
2231     createTypedFieldConvertNoInterlace(const FIELD<T, FullInterlace> & field )
2232     {
2233       return FieldConvert(field);
2234     }
2235 %}
2236
2237 template<class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createTypedFieldFromField(FIELD_ * field);
2238 %template ( createFieldDoubleFromField ) createTypedFieldFromField < double, FullInterlace>;
2239 %template ( createFieldIntFromField ) createTypedFieldFromField < int, FullInterlace >;
2240 %template ( createFieldDoubleNoInterlaceFromField ) createTypedFieldFromField < double, NoInterlace>;
2241 %template ( createFieldIntNoInterlaceFromField ) createTypedFieldFromField < int, NoInterlace >;
2242 %template ( createFieldDoubleNoInterlaceByTypeFromField ) createTypedFieldFromField < double, NoInterlaceByType>;
2243 %template ( createFieldIntNoInterlaceByTypeFromField ) createTypedFieldFromField < int, NoInterlaceByType >;
2244
2245 template <class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createFieldScalarProduct(FIELD<T, INTERLACING_TAG> * field1, FIELD<T, INTERLACING_TAG> * field2);
2246 %newobject createFieldDoubleScalarProduct ;
2247 %newobject createFieldIntScalarProduct ;
2248 %newobject createFieldDoubleNoInterlaceScalarProduct ;
2249 %newobject createFieldIntNoInterlaceScalarProduct ;
2250 %newobject createFieldDoubleNoInterlaceByTypeScalarProduct ;
2251 %newobject createFieldIntNoInterlaceByTypeScalarProduct ;
2252 %template ( createFieldDoubleScalarProduct ) createFieldScalarProduct < double, FullInterlace >;
2253 %template ( createFieldIntScalarProduct ) createFieldScalarProduct < int, FullInterlace >;
2254 %template ( createFieldDoubleNoInterlaceScalarProduct ) createFieldScalarProduct < double, NoInterlace >;
2255 %template ( createFieldIntNoInterlaceScalarProduct ) createFieldScalarProduct < int, NoInterlace >;
2256 %template ( createFieldDoubleNoInterlaceByTypeScalarProduct ) createFieldScalarProduct < double, NoInterlaceByType >;
2257 %template ( createFieldIntNoInterlaceByTypeScalarProduct ) createFieldScalarProduct < int, NoInterlaceByType >;
2258
2259 template <class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createFieldScalarProductDeep(FIELD<T, INTERLACING_TAG> * field1, FIELD<T, INTERLACING_TAG> * field2);
2260 %newobject createFieldDoubleScalarProductDeep ;
2261 %newobject createFieldIntScalarProductDeep ;
2262 %newobject createFieldDoubleNoInterlaceScalarProductDeep ;
2263 %newobject createFieldIntNoInterlaceScalarProductDeep ;
2264 %newobject createFieldDoubleNoInterlaceByTypeScalarProductDeep ;
2265 %newobject createFieldIntNoInterlaceByTypeScalarProductDeep ;
2266 %template ( createFieldDoubleScalarProductDeep ) createFieldScalarProductDeep < double, FullInterlace >;
2267 %template ( createFieldIntScalarProductDeep ) createFieldScalarProductDeep < int, FullInterlace >;
2268 %template ( createFieldDoubleNoInterlaceScalarProductDeep ) createFieldScalarProductDeep < double, NoInterlace >;
2269 %template ( createFieldIntNoInterlaceScalarProductDeep ) createFieldScalarProductDeep < int, NoInterlace >;
2270 %template ( createFieldDoubleNoInterlaceByTypeScalarProductDeep ) createFieldScalarProductDeep < double, NoInterlaceByType >;
2271 %template ( createFieldIntNoInterlaceByTypeScalarProductDeep ) createFieldScalarProductDeep < int, NoInterlaceByType >;
2272
2273 template<class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createFieldFromAnalytic(SUPPORT * Support, int NumberOfComponents, PyObject * double_function);
2274
2275 template <class T> FIELD<T, FullInterlace> * createTypedFieldConvertFullInterlace(const FIELD<T, NoInterlace> & field );
2276
2277 %template (createFieldDoubleConvertFullInterlace) createTypedFieldConvertFullInterlace<double>;
2278
2279 %template (createFieldIntConvertFullInterlace) createTypedFieldConvertFullInterlace<int>;
2280
2281 template <class T> FIELD<T, NoInterlace> * createTypedFieldConvertNoInterlace(const FIELD<T, FullInterlace> & field );
2282 //template <class T> FIELD<T, NoInterlace> * createTypedFieldConvertNoInterlace(const FIELD<T, NoInterlaceByType> & field );
2283
2284 %template (createFieldDoubleConvertNoInterlace) createTypedFieldConvertNoInterlace<double>;
2285
2286 %template (createFieldIntConvertNoInterlace) createTypedFieldConvertNoInterlace<int>;
2287
2288 %newobject createFieldDoubleConvertFullInterlace ;
2289 %newobject createFieldIntConvertFullInterlace ;
2290
2291 %newobject createFieldDoubleConvertNoInterlace ;
2292 %newobject createFieldIntConvertNoInterlace ;
2293
2294 GRID * createGridFromMesh( MESH * aMesh );
2295
2296 %{
2297   GRID * createGridFromMesh( MESH * aMesh )
2298     {
2299       MESSAGE_MED("createGridFromMesh : Constructor (for Python API) GRID with parameter MESH *");
2300       MESSAGE_MED("Its returns a proper cast of the input pointer :: MESH --> GRID");
2301
2302       if (aMesh->getIsAGrid())
2303         return (GRID *) aMesh;
2304
2305       const char * message = "Error in GRID(mesh): mesh is not a grid";
2306       PyErr_SetString(PyExc_RuntimeError, (char *)message);
2307       return NULL;
2308     }
2309
2310   template<class T, class INTERLACING_TAG>
2311     FIELD<T, INTERLACING_TAG> * createFieldFromAnalytic(SUPPORT * Support,
2312                                                         int NumberOfComponents,
2313                                                         PyObject * double_function)
2314     {
2315       MESSAGE_MED("createFieldFromAnalytic : Constructor (for Python API) FIELD from an analytic fonction");
2316
2317       FIELD<T, INTERLACING_TAG> * fieldAnalytic =
2318         new FIELD<T, INTERLACING_TAG>(Support, NumberOfComponents);
2319
2320       MyFunction<T,double>::_pyFunc=double_function;
2321       MyFunction<T,double>::_nbOfComponent=NumberOfComponents;
2322       MyFunction<T,double>::_spaceDim=Support->getMesh()->getSpaceDimension();
2323       fieldAnalytic->fillFromAnalytic(MyFunction<T,double>::EvalPy2Cpp);
2324       return fieldAnalytic;
2325     }
2326 %}
2327
2328 %template (createFieldDoubleFromAnalytic) createFieldFromAnalytic<double, FullInterlace>;
2329 %template (createFieldIntFromAnalytic) createFieldFromAnalytic<int, FullInterlace>;
2330 %template (createFieldDoubleNoInterlaceFromAnalytic) createFieldFromAnalytic<double, NoInterlace>;
2331 %template (createFieldIntNoInterlaceFromAnalytic) createFieldFromAnalytic<int, NoInterlace>;