]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Field.hxx
Salome HOME
NRI : Merge from V1_2.
[modules/med.git] / src / MEDMEM / MEDMEM_Field.hxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MEDMEM_Field.hxx
25 //  Module : MED
26
27 /*
28  File Field.hxx
29  $Header$
30 */
31
32 #ifndef FIELD_HXX
33 #define FIELD_HXX
34
35 #include <vector>
36
37 #include "utilities.h"
38 #include "MEDMEM_Exception.hxx"
39 #include "MEDMEM_define.hxx"
40
41 #include "MEDMEM_Support.hxx"
42 #include "MEDMEM_Unit.hxx"
43 #include "MEDMEM_Array.hxx"
44 #include "MEDMEM_GenDriver.hxx"
45
46 #include "MEDMEM_MedFieldDriver.hxx"
47 #include "MEDMEM_MedMedDriver.hxx"
48
49 using namespace MED_EN;
50
51 /*!
52
53   This class contains all the informations related with a template class FIELD :
54   - Components descriptions
55   - Time step description
56   - Location of the values (a SUPPORT class)
57
58 */
59
60 class FIELD_    // GENERIC POINTER TO a template <class T> class FIELD
61 {
62 protected:
63
64   bool            _isRead ;
65
66   /*!
67     \if developper
68     Field name.
69     \endif
70   */
71   string          _name ;
72   /*!
73     \if developper
74     Field description.
75     \endif
76   */
77   string          _description ;
78   /*!
79     \if developper
80     Pointer to the support the field deals with.
81     \endif
82   */
83   const SUPPORT * _support ;
84
85   /*!
86     \if developper
87     Number of field's components.
88     \endif
89   */
90   int             _numberOfComponents ;
91   /*!
92     \if developper
93     Number of field's values.
94     \endif
95   */
96   int             _numberOfValues ;
97
98   /*!
99     \if developper
100     Array of size _numberOfComponents. /n
101     (constant, scalar, vector, tensor)/n
102     We could use an array of integer to store
103     numbers of values: /n
104     - 1 for scalar,/n
105     - space dimension for vector,/n
106     - space dimension square for tensor./n
107     So numbers of values per entities would be
108     sum of _componentsTypes array.
109
110     Not implemented yet! All type are scalar !
111     \endif
112   */
113   int *           _componentsTypes ;
114   /*!
115     \if developper
116     Array of size _numberOfComponents
117     storing components names if any.
118     \endif
119   */
120   string *        _componentsNames;     
121   /*!
122     \if developper
123     Array of size _numberOfComponents
124     storing components descriptions if any.
125     \endif
126  */
127   string *        _componentsDescriptions;
128   /*!
129     \if developper
130     Array of size _numberOfComponents
131     storing components units if any.
132     \endif
133  */
134   UNIT *          _componentsUnits;
135   /*!
136     \if developper
137     Array of size _numberOfComponents
138     storing components units if any.
139     \endif
140   */
141   string *        _MEDComponentsUnits;
142   int             _iterationNumber ;
143   double          _time;
144   int             _orderNumber ;
145
146   med_type_champ _valueType ;
147
148   vector<GENDRIVER *> _drivers; // Storage of the drivers currently in use
149
150 public:
151
152   friend class MED_MED_RDONLY_DRIVER;
153   friend class MED_MED_WRONLY_DRIVER;
154   friend class MED_MED_RDWR_DRIVER;
155
156   /*!
157     Constructor.
158   */
159   FIELD_ ();
160   /*!
161     Constructor.
162   */
163   FIELD_(const SUPPORT * Support, const int NumberOfComponents);
164   /*!
165     Copy constructor.
166   */
167   FIELD_(const FIELD_ &m);
168
169   /*!
170     Destructor.
171   */
172   ~FIELD_();
173
174 //    virtual  void     setIterationNumber (int IterationNumber);
175 //    virtual  void     setOrderNumber     (int OrderNumber);
176 //    virtual  void     setFieldName       (string& fieldName);
177
178   virtual  void     rmDriver(int index);
179   virtual   int     addDriver(driverTypes driverType,
180                               const string & fileName="Default File Name.med",
181                               const string & driverFieldName="Default Field Nam") ;
182   virtual  int      addDriver( GENDRIVER & driver);
183   virtual  void     read (const GENDRIVER &);
184   virtual  void     read(int index=0);
185   virtual  void     write(const GENDRIVER &);
186   virtual  void     write(int index=0, const string & driverName="");
187
188   inline void     setName(string Name);
189   inline string   getName() const;
190   inline void     setDescription(string Description);
191   inline string   getDescription() const;
192   inline const SUPPORT * getSupport() const;
193   inline void     setSupport(SUPPORT * support);
194   inline void     setNumberOfComponents(int NumberOfComponents);
195   inline int      getNumberOfComponents() const;
196   inline void     setNumberOfValues(int NumberOfValues);
197   inline int      getNumberOfValues() const;
198   //    inline void     setComponentType(int *ComponentType);
199   //    inline int *    getComponentType() const;
200   //    inline int      getComponentTypeI(int i) const;
201   inline void     setComponentsNames(string * ComponentsNames);
202   inline void     setComponentName(int i, string ComponentName);
203   inline const string * getComponentsNames() const;
204   inline string   getComponentName(int i) const;
205   inline void     setComponentsDescriptions(string *ComponentsDescriptions);
206   inline void     setComponentDescription(int i, string ComponentDescription);
207   inline const string * getComponentsDescriptions() const;
208   inline string   getComponentDescription(int i) const;
209
210   // provisoire : en attendant de regler le probleme des unites !
211   inline void     setComponentsUnits(UNIT * ComponentsUnits);
212   inline const UNIT *   getComponentsUnits() const;
213   inline const UNIT *   getComponentUnit(int i) const;
214   inline void     setMEDComponentsUnits(string * MEDComponentsUnits);
215   inline void     setMEDComponentUnit(int i, string MEDComponentUnit);
216   inline const string * getMEDComponentsUnits() const;
217   inline string   getMEDComponentUnit(int i) const;
218
219   inline void     setIterationNumber(int IterationNumber);
220   inline int      getIterationNumber() const;
221   inline void     setTime(double Time);
222   inline double   getTime() const;
223   inline void     setOrderNumber(int OrderNumber);
224   inline int      getOrderNumber() const;
225
226   inline void     setValueType (med_type_champ ValueType) ;
227   inline med_type_champ getValueType () const;
228
229 };
230
231 // ---------------------------------
232 // Implemented Methods : constructor
233 // ---------------------------------
234
235 // -----------------
236 // Methodes Inline
237 // -----------------
238 /*!
239   Set FIELD name.
240 */
241 inline void FIELD_::setName(string Name)
242 {
243   _name=Name;
244 }
245 /*!
246   Get FIELD name.
247 */
248 inline string FIELD_::getName() const
249 {
250   return _name;
251 }
252 /*!
253   Set FIELD description.
254 */
255 inline void FIELD_::setDescription(string Description)
256 {
257   _description=Description;
258 }
259 /*!
260   Get FIELD description.
261 */
262 inline string FIELD_::getDescription() const
263 {
264   return _description;
265 }
266 /*!
267   Set FIELD number of components.
268 */
269 inline void FIELD_::setNumberOfComponents(int NumberOfComponents)
270 {
271   _numberOfComponents=NumberOfComponents;
272 }
273 /*!
274   Get FIELD number of components.
275 */
276 inline int FIELD_::getNumberOfComponents() const
277 {
278   return _numberOfComponents ;
279 }
280 /*!
281   Set FIELD number of values.
282
283   It must be the same than in the associated SUPPORT object.
284 */
285 inline void FIELD_::setNumberOfValues(int NumberOfValues)
286 {
287   _numberOfValues=NumberOfValues;
288 }
289 /*!
290   Get FIELD number of value.
291 */
292 inline int FIELD_::getNumberOfValues() const
293 {
294   return _numberOfValues ;
295 }
296
297 //  inline void FIELD_::setComponentType(int *ComponentType)
298 //  {
299 //    _componentsTypes=ComponentType ;
300 //  }
301 //  inline int * FIELD_::getComponentType() const
302 //  {
303 //    return _componentsTypes ;
304 //  }
305 //  inline int FIELD_::getComponentTypeI(int i) const
306 //  {
307 //    return _componentsTypes[i-1] ;
308 //  }
309
310 /*!
311   Set FIELD components names.
312
313   Duplicate the ComponentsNames string array to put components names in
314   FIELD. ComponentsNames size must be equal to number of components.
315 */
316 inline void FIELD_::setComponentsNames(string * ComponentsNames)
317 {
318   if (NULL == _componentsNames)
319     _componentsNames = new string[_numberOfComponents] ;
320   for (int i=0; i<_numberOfComponents; i++)
321     _componentsNames[i]=ComponentsNames[i] ;
322 }
323 /*!
324   Set FIELD i^th component name.
325
326   i must be >=1 and <= number of components.
327 */
328 inline void FIELD_::setComponentName(int i, string ComponentName)
329 {
330   _componentsNames[i-1]=ComponentName ;
331 }
332 /*!
333   Get a reference to the string array which contain the components names.
334
335   This Array size is equal to number of components
336 */
337 inline const string * FIELD_::getComponentsNames() const
338 {
339   return _componentsNames ;
340 }
341 /*!
342   Get the name of the i^th component.
343 */
344 inline string FIELD_::getComponentName(int i) const
345 {
346   return _componentsNames[i-1] ;
347 }
348 /*!
349   Set FIELD components descriptions.
350
351   Duplicate the ComponentsDescriptions string array to put components 
352   descriptions in FIELD.
353   ComponentsDescriptions size must be equal to number of components.
354 */
355 inline void FIELD_::setComponentsDescriptions(string *ComponentsDescriptions)
356 {
357   if (NULL == _componentsDescriptions)
358     _componentsDescriptions = new string[_numberOfComponents] ;
359   for (int i=0; i<_numberOfComponents; i++)
360     _componentsDescriptions[i]=ComponentsDescriptions[i] ;
361 }
362 /*!
363   Set FIELD i^th component description.
364
365   i must be >=1 and <= number of components.
366 */
367 inline void FIELD_::setComponentDescription(int i,string ComponentDescription)
368 {
369   _componentsDescriptions[i-1]=ComponentDescription ;
370 }
371 /*!
372   Get a reference to the string array which contain the components descriptions.
373
374   This Array size is equal to number of components
375 */
376 inline const string * FIELD_::getComponentsDescriptions() const
377 {
378   return _componentsDescriptions ;
379 }
380 /*!
381   Get the description of the i^th component.
382 */
383 inline string FIELD_::getComponentDescription(int i) const
384 {
385   return _componentsDescriptions[i-1];
386 }
387
388 /*!
389   \todo
390   Set FIELD components UNIT.
391
392   Duplicate the ComponentsUnits UNIT array to put components 
393   units in FIELD.
394   ComponentsUnits size must be equal to number of components.
395 */
396 inline void FIELD_::setComponentsUnits(UNIT * ComponentsUnits)
397 {
398   if (NULL == _componentsUnits)
399     _componentsUnits = new UNIT[_numberOfComponents] ;
400   for (int i=0; i<_numberOfComponents; i++)
401     _componentsUnits[i]=ComponentsUnits[i] ;
402 }
403 /*!
404   Get a reference to the UNIT array which contain the components units.
405
406   This Array size is equal to number of components
407 */
408 inline const UNIT * FIELD_::getComponentsUnits() const
409 {
410   return _componentsUnits ;
411 }
412 /*!
413   Get the UNIT of the i^th component.
414 */
415 inline const UNIT * FIELD_::getComponentUnit(int i) const
416 {
417   return &_componentsUnits[i-1] ;
418 }
419 /*!
420   Set FIELD components unit.
421
422   Duplicate the MEDComponentsUnits string array to put components 
423   units in FIELD.
424   MEDComponentsUnits size must be equal to number of components.
425   
426 */
427 inline void FIELD_::setMEDComponentsUnits(string * MEDComponentsUnits)
428 {
429   if (NULL == _MEDComponentsUnits)
430     _MEDComponentsUnits = new string[_numberOfComponents] ;
431   for (int i=0; i<_numberOfComponents; i++)
432     _MEDComponentsUnits[i]=MEDComponentsUnits[i] ;
433 }
434 /*!
435   Set FIELD i^th component unit.
436
437   i must be >=1 and <= number of components.
438 */
439 inline void FIELD_::setMEDComponentUnit(int i, string MEDComponentUnit)
440 {
441   _MEDComponentsUnits[i-1]=MEDComponentUnit ;
442 }
443 /*!
444   Get a reference to the string array which contain the components units.
445
446   This Array size is equal to number of components
447 */
448 inline const string * FIELD_::getMEDComponentsUnits() const
449 {
450   return _MEDComponentsUnits ;
451 }
452 /*!
453   Get the string for unit of the i^th component.
454 */
455 inline string FIELD_::getMEDComponentUnit(int i) const
456 {
457   return _MEDComponentsUnits[i-1] ;
458 }
459 /*!
460   Set the iteration number where FIELD has been calculated.
461 */
462 inline void FIELD_::setIterationNumber(int IterationNumber)
463 {
464   _iterationNumber=IterationNumber;
465 }
466 /*!
467   Get the iteration number where FIELD has been calculated.
468 */
469 inline int FIELD_::getIterationNumber() const
470 {
471   return _iterationNumber ;
472 }
473 /*!
474   Set the time (in second) where FIELD has been calculated.
475 */
476 inline void FIELD_::setTime(double Time)
477 {
478   _time=Time ;
479 }
480 /*!
481   Get the time (in second) where FIELD has been calculated.
482 */
483 inline double FIELD_::getTime() const
484 {
485   return _time ;
486 }
487 /*!
488   Set the order number where FIELD has been calculated.
489
490   It corresponds to internal iteration during one time step.
491 */
492 inline void FIELD_::setOrderNumber(int OrderNumber)
493 {
494   _orderNumber=OrderNumber ;
495 }
496 /*!
497   Get the order number where FIELD has been calculated.
498 */
499 inline int FIELD_::getOrderNumber() const
500 {
501   return _orderNumber ;
502 }
503 /*!
504   Get a reference to the SUPPORT object associated to FIELD.
505 */
506 inline  const SUPPORT * FIELD_::getSupport() const
507 {
508   return _support ;
509 }
510 /*!
511   Set the reference to the SUPPORT object associated to FIELD.
512
513   Reference is not duplicate, so it must not be deleted.
514 */
515 inline void FIELD_::setSupport(SUPPORT * support)
516 {
517   _support = support ;
518 }
519 /*!
520   Get the FIELD med value type (MED_INT32 or MED_REEL64).
521 */
522 inline med_type_champ FIELD_::getValueType () const
523 {
524   return _valueType ;
525 }
526 /*!
527   Set the FIELD med value type (MED_INT32 or MED_REEL64).
528 */
529 inline void FIELD_::setValueType (med_type_champ ValueType)
530 {
531   _valueType = ValueType ;
532 }
533
534 /////////////////////////
535 // END OF CLASS FIELD_ //
536 /////////////////////////
537
538 /*!
539
540   This template class contains informations related with a FIELD :
541   - Values of the field
542
543 */
544
545 template <class T> class FIELD : public FIELD_
546 {
547
548   // ------- Drivers Management Part
549 protected:
550
551  //-----------------------//
552    class INSTANCE
553   //-----------------------//
554   {
555   public:
556     virtual GENDRIVER * run(const string & fileName, FIELD<T> * ptrFIELD) const = 0 ;
557   } ;
558
559   //-------------------------------------------------------//
560   template <class T2> class INSTANCE_DE : public INSTANCE
561   //-------------------------------------------------------//
562   {
563   public :
564     GENDRIVER * run(const string & fileName, FIELD<T> * ptrFIELD) const
565     {
566       return new T2(fileName,ptrFIELD);
567     }
568   } ;
569
570   //    static INSTANCE_DE<MED_FIELD_RDONLY_DRIVER> inst_med_rdonly ;
571   static INSTANCE_DE<MED_FIELD_RDWR_DRIVER<T> >   inst_med ;
572   static const INSTANCE * const instances[] ;
573
574   // ------ End of Drivers Management Part
575
576   // array of value of type T
577   MEDARRAY<T> *_value ;
578
579 private:
580   //setValueType() ;
581
582 public:
583   FIELD();
584   FIELD(const FIELD &m);
585   FIELD & operator=(const FIELD &m);    // A FAIRE
586   FIELD(const SUPPORT * Support, const int NumberOfComponents); // Ajout NB Constructeur FIELD avec allocation de memoire de tous ses attribut
587   FIELD(const SUPPORT * Support, driverTypes driverType,
588         const string & fileName="", const string & fieldName="");
589   ~FIELD();
590
591   friend class MED_FIELD_RDONLY_DRIVER<T>;
592   friend class MED_FIELD_WRONLY_DRIVER<T>;
593   //friend class MED_FIELD_RDWR_DRIVER  <T>;
594
595   void init ();
596   void rmDriver(int index=0);
597   int  addDriver(driverTypes driverType,
598                  const string & fileName="Default File Name.med",
599                  const string & driverFieldName="Default Field Name") ;
600   int  addDriver(GENDRIVER & driver);
601
602   void allocValue(const int NumberOfComponents);
603   void allocValue(const int NumberOfComponents, const int LengthValue);
604
605   void deallocValue();
606
607   inline void read(int index=0);
608   inline void read(const GENDRIVER & genDriver);
609   inline void write(int index=0, const string & driverName = "");
610   inline void write(const GENDRIVER &);
611
612   inline void     setValue(MEDARRAY<T> *Value);
613
614   inline MEDARRAY<T>* getvalue() const;
615   inline const T*       getValue(medModeSwitch Mode) const;
616   inline const T*       getValueI(medModeSwitch Mode,int i) const;
617   inline T        getValueIJ(int i,int j) const;
618
619   inline void setValue(medModeSwitch mode, T* value);
620   inline void setValueI(medModeSwitch mode, int i, T* value);
621   inline void setValueIJ(int i, int j, T value);
622
623   /*!
624     This fonction feeds the FIELD<double> private attributs _value with the
625     volume of each cells belonging to the argument Support. The field has to be
626     initialised via the constructor FIELD<double>(const SUPPORT * , const int )
627     with Support as SUPPORT argument, 1 has the number of components, and Support
628     has be a SUPPORT on 3D cells. This initialisation could be done by the empty
629     constructor followed by a setSupport and setNumberOfComponents call but it has
630     be followed by a setValueType(MED_REEL64) call.
631    */
632   void getVolume() const throw (MEDEXCEPTION) ;
633   /*!
634     This fonction feeds the FIELD<double> private attributs _value with the
635     area of each cells (or faces) belonging to the attribut _support. The field
636     has to be initialised via the constructor FIELD<double>(const SUPPORT * ,
637     const int ) with 1 has the number of components, and _support has be a
638     SUPPORT on 2D cells or 3D faces. This initialisation could be done by the
639     empty constructor followed by a setSupport and setNumberOfComponents call but
640     it has be followed by a setValueType(MED_REEL64) call.
641    */
642   void getArea() const throw (MEDEXCEPTION) ;
643   /*!
644     This fonction feeds the FIELD<double> private attributs _value with the
645     length of each segments belonging to the attribut _support. The field has
646     to be initialised via the constructor FIELD<double>(const SUPPORT * ,
647     const int ) with 1 has the number of components, and _support has be a
648     SUPPORT on 3D edges or 2D faces. This initialisation could be done by the
649     empty constructor followed by a setSupport and setNumberOfComponents call but
650     it has be followed by a setValueType(MED_REEL64) call.
651    */
652   void getLength() const throw (MEDEXCEPTION) ;
653   /*!
654     This fonction feeds the FIELD<double> private attributs _value with the
655     normal vector of each faces belonging to the attribut _support. The field
656     has to be initialised via the constructor FIELD<double>(const SUPPORT * ,
657     const int ) with the space dimension has the number of components, and
658     _support has be a SUPPORT on 3D or 2D faces. This initialisation could be done
659     by the empty constructor followed by a setSupport and setNumberOfComponents
660     call but it has be followed by a setValueType(MED_REEL64) call.
661    */
662   void getNormal() const throw (MEDEXCEPTION) ;
663   /*!
664     This fonction feeds the FIELD<double> private attributs _value with the
665     barycenter of each faces or cells or edges belonging to the attribut _support.
666     The field has to be initialised via the constructor
667     FIELD<double>(const SUPPORT * ,const int ) with the space dimension has the
668     number of components, and _support has be a SUPPORT on 3D cells or 2D faces.
669     This initialisation could be done by the empty constructor followed by a
670     setSupport and setNumberOfComponents call but it has be followed by a
671     setValueType(MED_REEL64) call.
672    */
673   void getBarycenter() const throw (MEDEXCEPTION) ;
674 };
675
676 // --------------------
677 // Implemented Methods
678 // --------------------
679
680 /*!
681   Constructor.
682 */
683 template <class T>  FIELD<T>::FIELD():
684  _value((MEDARRAY<T>*)NULL)
685 {
686   MESSAGE("Constructeur FIELD sans parametre");
687 }
688
689 /*!
690   Constructor.
691 */
692 template <class T>  FIELD<T>::FIELD(const SUPPORT * Support,
693                                     const int NumberOfComponents):
694   FIELD_(Support, NumberOfComponents)
695 {
696   BEGIN_OF("FIELD<T>::FIELD(const SUPPORT * Support, const int NumberOfComponents)");
697
698   try {
699     _numberOfValues = Support->getNumberOfElements(MED_ALL_ELEMENTS);
700   }
701   catch (MEDEXCEPTION &ex) {
702     MESSAGE("No value defined ! ("<<ex.what()<<")");
703     _value = (MEDARRAY<T>*)NULL ;
704   }
705   MESSAGE("FIELD : constructeur : "<< _numberOfValues <<" et "<< NumberOfComponents);
706   if (0<_numberOfValues) {
707     _value = new MEDARRAY<T>::MEDARRAY(_numberOfComponents,_numberOfValues);
708     _isRead = true ;
709   } else
710     _value = (MEDARRAY<T>*)NULL ;
711
712   END_OF("FIELD<T>::FIELD(const SUPPORT * Support, const int NumberOfComponents)");
713 }
714
715 /*!
716   \if developper
717   \endif
718 */
719 template <class T> void FIELD<T>::init ()
720 {
721 }
722
723 /*!
724   Copy constructor.
725 */
726 template <class T> FIELD<T>::FIELD(const FIELD & m):
727   FIELD_((FIELD_) m)
728 {
729   if (m._value != NULL)
730     {
731       // copie only default !
732       _value = new MEDARRAY<T>::MEDARRAY(* m._value,false);
733     }
734   else
735     _value = (MEDARRAY<T> *) NULL;
736   //_drivers = m._drivers;
737 }
738
739 /*!
740   
741 */
742 template <class T> FIELD<T> & FIELD<T>::operator=(const FIELD &m)
743 {
744 }
745
746 /*!
747   Constructor.
748 */
749 template <class T> FIELD<T>::FIELD(const SUPPORT * Support,
750                                    driverTypes driverType,
751                                    const string & fileName/*=""*/,
752                                    const string & fieldDriverName/*=""*/)
753 {
754   const char * LOC = "template <class T> FIELD<T>::FIELD(const SUPPORT * Support, driverTypes driverType, const string & fileName=\"\", const string & fieldName=\"\") : ";
755
756   int current;
757
758   BEGIN_OF(LOC);
759
760   init();
761
762   _support = Support;
763   _value = (MEDARRAY<T>*)NULL;
764
765   MED_FIELD_RDONLY_DRIVER<T> myDriver(fileName,this);
766   myDriver.setFieldName(fieldDriverName);
767   current = addDriver(myDriver);
768 //   current = addDriver(driverType,fileName,fieldDriverName);
769 //   switch(_drivers[current]->getAccessMode() ) {
770 //   case MED_WRONLY : {
771 //     MESSAGE("FIELD<T>::FIELD(driverTypes driverType, .....) : driverType must have a MED_RDONLY or MED_RDWR accessMode");
772 //     rmDriver(current);
773 //     break;}
774 //   default : {
775 //   }
776 //   }
777   _drivers[current]->open();
778   _drivers[current]->read();
779   _drivers[current]->close();
780
781   END_OF(LOC);
782 }
783
784 /*!
785   Destructor.
786 */
787 template <class T> FIELD<T>::~FIELD()
788 {
789   BEGIN_OF(" Destructeur FIELD<T>::~FIELD()");
790   if (_value) delete _value;
791   END_OF(" Destructeur FIELD<T>::~FIELD()");
792 }
793
794 /*!
795   
796 */
797 template <class T> void FIELD<T>::allocValue(const int NumberOfComponents)
798 {
799   const char* LOC = "FIELD<T>::allocValue(const int NumberOfComponents)" ;
800   BEGIN_OF(LOC);
801
802   _numberOfComponents = NumberOfComponents ;
803   if (_componentsTypes == NULL)
804     _componentsTypes = new int[NumberOfComponents] ;
805   if (_componentsNames == NULL)
806     _componentsNames = new string[NumberOfComponents];
807   if (_componentsDescriptions == NULL)
808     _componentsDescriptions = new string[NumberOfComponents];
809   if (_componentsUnits == NULL)
810     _componentsUnits = new UNIT[NumberOfComponents];
811   if (_MEDComponentsUnits == NULL)
812     _MEDComponentsUnits = new string[NumberOfComponents];
813   for (int i=0;i<NumberOfComponents;i++) {
814     _componentsTypes[i] = 0 ;
815   }
816
817   try {
818     _numberOfValues = _support->getNumberOfElements(MED_ALL_ELEMENTS);
819     MESSAGE(LOC <<" : "<<_numberOfValues <<" et "<< NumberOfComponents);
820
821     _value = new MEDARRAY<T>::MEDARRAY(_numberOfComponents,_numberOfValues);
822
823     _isRead = true ;
824   }
825   catch (MEDEXCEPTION &ex) {
826     MESSAGE("No value defined, problem with NumberOfComponents (and may be _support) size of MEDARRAY<T>::_value !");
827     _value = (MEDARRAY<T>*)NULL ;
828   }
829
830   SCRUTE(_value);
831   END_OF("void FIELD<T>::allocValue(const int NumberOfComponents)");
832 }
833
834 /*!
835   
836 */
837 template <class T> void FIELD<T>::allocValue(const int NumberOfComponents, const int LengthValue)
838 {
839   BEGIN_OF("void FIELD<T>::allocValue(const int NumberOfComponents,const int LengthValue)");
840
841   _numberOfComponents = NumberOfComponents ;
842   if (_componentsTypes == NULL)
843     _componentsTypes = new int[NumberOfComponents] ;
844   if (_componentsNames == NULL)
845     _componentsNames = new string[NumberOfComponents];
846   if (_componentsDescriptions == NULL)
847     _componentsDescriptions = new string[NumberOfComponents];
848   if (_componentsUnits == NULL)
849     _componentsUnits = new UNIT[NumberOfComponents];
850   if (_MEDComponentsUnits == NULL)
851     _MEDComponentsUnits = new string[NumberOfComponents];
852   for (int i=0;i<NumberOfComponents;i++) {
853     _componentsTypes[i] = 0 ;
854   }
855
856   MESSAGE("FIELD : constructeur : "<<LengthValue <<" et "<< NumberOfComponents);
857   _numberOfValues = LengthValue ;
858   _value = new MEDARRAY<T>::MEDARRAY(_numberOfComponents,_numberOfValues);
859   _isRead = true ;
860
861   SCRUTE(_value);
862   END_OF("void FIELD<T>::allocValue(const int NumberOfComponents,const int LengthValue)");
863 }
864
865 /*!
866   
867 */
868 template <class T> void FIELD<T>::deallocValue()
869 {
870   BEGIN_OF("void FIELD<T>::deallocValue()");
871   _numberOfValues = 0 ;
872   _numberOfComponents = 0 ;
873   if (_value != NULL)
874     delete _value;
875
876   END_OF("void FIELD<T>::deallocValue()");
877 }
878
879 // -----------------
880 // Methodes Inline
881 // -----------------
882
883
884 template <class T>       FIELD<T>::INSTANCE_DE<MED_FIELD_RDWR_DRIVER<T> >     FIELD<T>::inst_med  ;
885 template <class T> const FIELD<T>::INSTANCE * const FIELD<T>::instances[] = { &FIELD<T>::inst_med } ;
886
887
888 /*!
889   Create the specified driver and return its index reference to path to 
890   read or write methods.
891 */
892 template <class T> int FIELD<T>::addDriver(driverTypes driverType,
893                                            const string & fileName/*="Default File Name.med"*/,
894                                            const string & driverName/*="Default Field Name"*/)
895 {
896   const char * LOC = "FIELD<T>::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\",const string & driverName=\"Default Field Name\") : ";
897
898   GENDRIVER * driver;
899   int current;
900
901   BEGIN_OF(LOC);
902
903   driver = instances[driverType]->run(fileName, this) ;
904   _drivers.push_back(driver);
905   current = _drivers.size()-1;
906
907   _drivers[current]->setFieldName(driverName);
908   return current;
909
910   END_OF(LOC);
911
912 }
913
914
915 /*!
916   Duplicate the given driver and return its index reference to path to 
917   read or write methods.
918 */
919 template <class T> inline int FIELD<T>::addDriver (GENDRIVER & driver )
920 {
921   const char * LOC = "FIELD<T>::addDriver(GENDRIVER &) : ";
922   BEGIN_OF(LOC);
923
924   // duplicate driver to delete it with destructor !
925   GENDRIVER * newDriver = driver.copy() ;
926
927   _drivers.push_back(newDriver);
928   return _drivers.size() -1 ;
929   
930   END_OF(LOC);
931 };
932
933 /*!
934   Remove the driver referenced by its index.
935 */
936 template <class T> void FIELD<T>::rmDriver (int index/*=0*/)
937 {
938   const char * LOC = "FIELD<T>::rmDriver (int index=0): ";
939   BEGIN_OF(LOC);
940
941   if ( _drivers[index] ) {
942     //_drivers.erase(&_drivers[index]);
943     // why not ????
944     MESSAGE ("detruire");
945   }
946   else
947     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
948                                      << "The index given is invalid, index must be between  0 and  |"
949                                      << _drivers.size()
950                                      )
951                           );
952
953   END_OF(LOC);
954 }
955
956 /*!
957   Read FIELD in the file specified in the driver given by its index.
958 */
959 template <class T> inline  void FIELD<T>::read(int index/*=0*/)
960 {
961   const char * LOC = "FIELD<T>::read(int index=0) : ";
962   BEGIN_OF(LOC);
963
964   if ( _drivers[index] ) {
965     _drivers[index]->open();
966     _drivers[index]->read();
967     _drivers[index]->close();
968   }
969   else
970     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
971                                      << "The index given is invalid, index must be between  0 and |"
972                                      << _drivers.size()
973                                      )
974                           );
975   END_OF(LOC);
976 }
977
978 /*!
979   Write FIELD in the file specified in the driver given by its index.
980 */
981 template <class T> inline void FIELD<T>::write(int index/*=0*/, const string & driverName /*= ""*/)
982 {
983   const char * LOC = "FIELD<T>::write(int index=0, const string & driverName = \"\") : ";
984   BEGIN_OF(LOC);
985
986   if( _drivers[index] ) {
987     _drivers[index]->open();
988     if (driverName != "") _drivers[index]->setFieldName(driverName);
989     _drivers[index]->write();
990     _drivers[index]->close();
991   }
992   else
993     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
994                                      << "The index given is invalid, index must be between  0 and |"
995                                      << _drivers.size()
996                                      )
997                           );
998   END_OF(LOC);
999 }
1000
1001 /*!
1002   \internal
1003   Write FIELD with the driver which is equal to the given driver.
1004
1005   Use by MED object.
1006 */
1007 template <class T> inline void FIELD<T>::write(const GENDRIVER & genDriver)
1008 {
1009   const char * LOC = " FIELD<T>::write(const GENDRIVER &) : ";
1010   BEGIN_OF(LOC);
1011
1012   for (int index=0; index < _drivers.size(); index++ )
1013     if ( *_drivers[index] == genDriver ) {
1014       _drivers[index]->open();
1015       _drivers[index]->write();
1016       _drivers[index]->close();
1017     }
1018
1019   END_OF(LOC);
1020
1021 }
1022
1023 /*!
1024   \internal
1025   Read FIELD with the driver which is equal to the given driver.
1026
1027   Use by MED object.
1028 */
1029 template <class T> inline void FIELD<T>::read(const GENDRIVER & genDriver)
1030 {
1031   const char * LOC = " FIELD<T>::read(const GENDRIVER &) : ";
1032   BEGIN_OF(LOC);
1033
1034   for (int index=0; index < _drivers.size(); index++ )
1035     if ( *_drivers[index] == genDriver ) {
1036       _drivers[index]->open();
1037       _drivers[index]->read();
1038       _drivers[index]->close();
1039     }
1040
1041   END_OF(LOC);
1042
1043 }
1044
1045 /*!
1046   \if developper
1047   Destroy the MEDARRAY<T> in FIELD and put the new one without copy.
1048   \endif
1049 */
1050 template <class T> inline void FIELD<T>::setValue(MEDARRAY<T> *Value)
1051 {
1052   if (NULL != _value) delete _value ;
1053   _value=Value ;
1054 }
1055
1056 /*!
1057   \if developper
1058   Return a reference to  the MEDARRAY<T> in FIELD.
1059   \endif  
1060 */
1061 template <class T> inline MEDARRAY<T>* FIELD<T>::getvalue() const
1062 {
1063   return _value ;
1064 }
1065
1066 /*!
1067   Return a reference to values array to read them.
1068 */
1069 template <class T> inline const T* FIELD<T>::getValue(medModeSwitch Mode) const
1070 {
1071   return _value->get(Mode) ;
1072 }
1073
1074 /*!
1075   Return a reference to i^{th} row or column - component - (depend on Mode value)
1076   of FIELD values array.
1077 */
1078 template <class T> inline const T* FIELD<T>::getValueI(medModeSwitch Mode,int i) const
1079 {
1080  if ( Mode == MED_FULL_INTERLACE )
1081  {
1082          return _value->getRow(i) ;
1083  }
1084  ASSERT (  Mode == MED_NO_INTERLACE);
1085  return _value->getColumn(i);
1086 }
1087
1088 /*!
1089   Return the value of i^{th} element and j^{th} component.
1090 */
1091 template <class T> inline T FIELD<T>::getValueIJ(int i,int j) const
1092 {
1093   return _value->getIJ(i,j) ;
1094 }
1095
1096 /*!
1097   Copy new values array in FIELD according to the given mode.
1098
1099   Array must have right size. If not results are unpredicable.
1100 */
1101 template <class T> inline void FIELD<T>::setValue(medModeSwitch mode, T* value)
1102 {
1103   _value->set(mode,value);
1104 }
1105
1106 /*!
1107   Update values array in FIELD with the given ones according to specified mode.
1108 */
1109 template <class T> inline void FIELD<T>::setValueI(medModeSwitch mode, int i, T* value)
1110 {
1111   // PROVISOIRE :
1112   if (MED_FULL_INTERLACE == mode)
1113     _value->setI(i,value);
1114   else if (MED_NO_INTERLACE == mode)
1115     _value->setJ(i,value);
1116   else
1117     throw MEDEXCEPTION(LOCALIZED("FIELD<T>::setValueI : bad medModeSwitch")) ;
1118 }
1119
1120 /*!
1121   Set the value of i^{th} element and j^{th} component with the given one.
1122 */
1123 template <class T> inline void FIELD<T>::setValueIJ(int i, int j, T value)
1124 {
1125   _value->setIJ(i,j,value);
1126 }
1127
1128 /*
1129   METHODS
1130 */
1131
1132 /*!
1133   Fill values array with volume values.
1134 */
1135 template <class T> void FIELD<T>::getVolume() const throw (MEDEXCEPTION)
1136 {
1137   const char * LOC = "FIELD<double>::getVolume() const : ";
1138   BEGIN_OF(LOC);
1139
1140   // The field has to be initilised by a non empty support and a
1141   // number of components = 1 and its value type has to be set to MED_REEL64
1142   // (ie a FIELD<double>)
1143
1144   if ((_support == (SUPPORT *) NULL) || (_numberOfComponents != 1) || (_valueType != MED_REEL64))
1145       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The field has to be initialised with a non empty support, a number of components set to 1 and a value type set to MED_REEL64"));
1146
1147   END_OF(LOC);
1148 }
1149
1150 /*!
1151   Fill values array with area values.
1152 */
1153 template <class T> void FIELD<T>::getArea() const throw (MEDEXCEPTION)
1154 {
1155   const char * LOC = "FIELD<double>::getArea() const : ";
1156   BEGIN_OF(LOC);
1157
1158   // The field has to be initilised by a non empty support and a
1159   // number of components = 1 and its value type has to be set to MED_REEL64
1160   // (ie a FIELD<double>)
1161
1162   if ((_support == (SUPPORT *) NULL) || (_numberOfComponents != 1) || (_valueType != MED_REEL64))
1163       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The field has to be initialised with a non empty support, a number of components set to 1 and a value type set to MED_REEL64"));
1164
1165   END_OF(LOC);
1166 }
1167
1168 /*!
1169   Fill values array with length values.
1170 */
1171 template <class T> void FIELD<T>::getLength() const throw (MEDEXCEPTION)
1172 {
1173   const char * LOC = "FIELD<double>::getLength() const : ";
1174   BEGIN_OF(LOC);
1175
1176   // The field has to be initilised by a non empty support and a
1177   // number of components = 1 and its value type has to be set to MED_REEL64
1178   // (ie a FIELD<double>)
1179
1180   if ((_support == (SUPPORT *) NULL) || (_numberOfComponents != 1) || (_valueType != MED_REEL64))
1181       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The field has to be initialised with a non empty support, a number of components set to 1 and a value type set to MED_REEL64"));
1182
1183   END_OF(LOC);
1184 }
1185
1186 /*!
1187   Fill values array with normal values.
1188 */
1189 template <class T> void FIELD<T>::getNormal() const throw (MEDEXCEPTION)
1190 {
1191   const char * LOC = "FIELD<double>::getNormal() const : ";
1192   BEGIN_OF(LOC);
1193
1194   // The field has to be initilised by a non empty support and a
1195   // number of components = 1 and its value type has to be set to MED_REEL64
1196   // (ie a FIELD<double>)
1197
1198   if (_support == (SUPPORT *) NULL)
1199       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The field has to be initialised with a non empty support, a number of components set to the space dimension and a value type set to MED_REEL64"));
1200
1201   int dim_space = _support->getMesh()->getSpaceDimension();
1202
1203   if ((_numberOfComponents != dim_space) || (_valueType != MED_REEL64))
1204       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The field has to be initialised with a non empty support, a number of components set to the space dimension and a value type set to MED_REEL64"));
1205
1206   END_OF(LOC);
1207 }
1208
1209 /*!
1210   Fill values array with barycenter values.
1211 */
1212 template <class T> void FIELD<T>::getBarycenter() const throw (MEDEXCEPTION)
1213 {
1214   const char * LOC = "FIELD<double>::getBarycenter() const : ";
1215   BEGIN_OF(LOC);
1216
1217   // The field has to be initilised by a non empty support and a number of
1218   //components = space dimension and its value type has to be set to MED_REEL64
1219   // (ie a FIELD<double>)
1220
1221   if (_support == (SUPPORT *) NULL)
1222       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The field has to be initialised with a non empty support, a number of components set to the space dimension and a value type set to MED_REEL64"));
1223
1224   int dim_space = _support->getMesh()->getSpaceDimension();
1225
1226   if ((_numberOfComponents != dim_space) || (_valueType != MED_REEL64))
1227       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The field has to be initialised with a non empty support, a number of components set to the space dimension and a value type set to MED_REEL64"));
1228
1229   END_OF(LOC);
1230 }
1231
1232 #endif /* FIELD_HXX */