1 // MED MEDMEM : MED files in memory
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MEDMEM_Field.hxx
37 #include "utilities.h"
38 #include "MEDMEM_Exception.hxx"
39 #include "MEDMEM_define.hxx"
41 #include "MEDMEM_Support.hxx"
42 #include "MEDMEM_Unit.hxx"
43 #include "MEDMEM_Array.hxx"
44 #include "MEDMEM_GenDriver.hxx"
46 #include "MEDMEM_MedFieldDriver.hxx"
47 #include "MEDMEM_MedMedDriver.hxx"
49 using namespace MED_EN;
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)
60 class FIELD_ // GENERIC POINTER TO a template <class T> class FIELD
80 Pointer to the support the field deals with.
83 const SUPPORT * _support ;
87 Number of field's components.
90 int _numberOfComponents ;
93 Number of field's values.
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
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.
110 Not implemented yet! All type are scalar !
113 int * _componentsTypes ;
116 Array of size _numberOfComponents
117 storing components names if any.
120 string * _componentsNames;
123 Array of size _numberOfComponents
124 storing components descriptions if any.
127 string * _componentsDescriptions;
130 Array of size _numberOfComponents
131 storing components units if any.
134 UNIT * _componentsUnits;
137 Array of size _numberOfComponents
138 storing components units if any.
141 string * _MEDComponentsUnits;
142 int _iterationNumber ;
146 med_type_champ _valueType ;
148 vector<GENDRIVER *> _drivers; // Storage of the drivers currently in use
152 friend class MED_MED_RDONLY_DRIVER;
153 friend class MED_MED_WRONLY_DRIVER;
154 friend class MED_MED_RDWR_DRIVER;
163 FIELD_(const SUPPORT * Support, const int NumberOfComponents);
167 FIELD_(const FIELD_ &m);
174 // virtual void setIterationNumber (int IterationNumber);
175 // virtual void setOrderNumber (int OrderNumber);
176 // virtual void setFieldName (string& fieldName);
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="");
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;
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;
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;
226 inline void setValueType (med_type_champ ValueType) ;
227 inline med_type_champ getValueType () const;
231 // ---------------------------------
232 // Implemented Methods : constructor
233 // ---------------------------------
241 inline void FIELD_::setName(string Name)
248 inline string FIELD_::getName() const
253 Set FIELD description.
255 inline void FIELD_::setDescription(string Description)
257 _description=Description;
260 Get FIELD description.
262 inline string FIELD_::getDescription() const
267 Set FIELD number of components.
269 inline void FIELD_::setNumberOfComponents(int NumberOfComponents)
271 _numberOfComponents=NumberOfComponents;
274 Get FIELD number of components.
276 inline int FIELD_::getNumberOfComponents() const
278 return _numberOfComponents ;
281 Set FIELD number of values.
283 It must be the same than in the associated SUPPORT object.
285 inline void FIELD_::setNumberOfValues(int NumberOfValues)
287 _numberOfValues=NumberOfValues;
290 Get FIELD number of value.
292 inline int FIELD_::getNumberOfValues() const
294 return _numberOfValues ;
297 // inline void FIELD_::setComponentType(int *ComponentType)
299 // _componentsTypes=ComponentType ;
301 // inline int * FIELD_::getComponentType() const
303 // return _componentsTypes ;
305 // inline int FIELD_::getComponentTypeI(int i) const
307 // return _componentsTypes[i-1] ;
311 Set FIELD components names.
313 Duplicate the ComponentsNames string array to put components names in
314 FIELD. ComponentsNames size must be equal to number of components.
316 inline void FIELD_::setComponentsNames(string * ComponentsNames)
318 if (NULL == _componentsNames)
319 _componentsNames = new string[_numberOfComponents] ;
320 for (int i=0; i<_numberOfComponents; i++)
321 _componentsNames[i]=ComponentsNames[i] ;
324 Set FIELD i^th component name.
326 i must be >=1 and <= number of components.
328 inline void FIELD_::setComponentName(int i, string ComponentName)
330 _componentsNames[i-1]=ComponentName ;
333 Get a reference to the string array which contain the components names.
335 This Array size is equal to number of components
337 inline const string * FIELD_::getComponentsNames() const
339 return _componentsNames ;
342 Get the name of the i^th component.
344 inline string FIELD_::getComponentName(int i) const
346 return _componentsNames[i-1] ;
349 Set FIELD components descriptions.
351 Duplicate the ComponentsDescriptions string array to put components
352 descriptions in FIELD.
353 ComponentsDescriptions size must be equal to number of components.
355 inline void FIELD_::setComponentsDescriptions(string *ComponentsDescriptions)
357 if (NULL == _componentsDescriptions)
358 _componentsDescriptions = new string[_numberOfComponents] ;
359 for (int i=0; i<_numberOfComponents; i++)
360 _componentsDescriptions[i]=ComponentsDescriptions[i] ;
363 Set FIELD i^th component description.
365 i must be >=1 and <= number of components.
367 inline void FIELD_::setComponentDescription(int i,string ComponentDescription)
369 _componentsDescriptions[i-1]=ComponentDescription ;
372 Get a reference to the string array which contain the components descriptions.
374 This Array size is equal to number of components
376 inline const string * FIELD_::getComponentsDescriptions() const
378 return _componentsDescriptions ;
381 Get the description of the i^th component.
383 inline string FIELD_::getComponentDescription(int i) const
385 return _componentsDescriptions[i-1];
390 Set FIELD components UNIT.
392 Duplicate the ComponentsUnits UNIT array to put components
394 ComponentsUnits size must be equal to number of components.
396 inline void FIELD_::setComponentsUnits(UNIT * ComponentsUnits)
398 if (NULL == _componentsUnits)
399 _componentsUnits = new UNIT[_numberOfComponents] ;
400 for (int i=0; i<_numberOfComponents; i++)
401 _componentsUnits[i]=ComponentsUnits[i] ;
404 Get a reference to the UNIT array which contain the components units.
406 This Array size is equal to number of components
408 inline const UNIT * FIELD_::getComponentsUnits() const
410 return _componentsUnits ;
413 Get the UNIT of the i^th component.
415 inline const UNIT * FIELD_::getComponentUnit(int i) const
417 return &_componentsUnits[i-1] ;
420 Set FIELD components unit.
422 Duplicate the MEDComponentsUnits string array to put components
424 MEDComponentsUnits size must be equal to number of components.
427 inline void FIELD_::setMEDComponentsUnits(string * MEDComponentsUnits)
429 if (NULL == _MEDComponentsUnits)
430 _MEDComponentsUnits = new string[_numberOfComponents] ;
431 for (int i=0; i<_numberOfComponents; i++)
432 _MEDComponentsUnits[i]=MEDComponentsUnits[i] ;
435 Set FIELD i^th component unit.
437 i must be >=1 and <= number of components.
439 inline void FIELD_::setMEDComponentUnit(int i, string MEDComponentUnit)
441 _MEDComponentsUnits[i-1]=MEDComponentUnit ;
444 Get a reference to the string array which contain the components units.
446 This Array size is equal to number of components
448 inline const string * FIELD_::getMEDComponentsUnits() const
450 return _MEDComponentsUnits ;
453 Get the string for unit of the i^th component.
455 inline string FIELD_::getMEDComponentUnit(int i) const
457 return _MEDComponentsUnits[i-1] ;
460 Set the iteration number where FIELD has been calculated.
462 inline void FIELD_::setIterationNumber(int IterationNumber)
464 _iterationNumber=IterationNumber;
467 Get the iteration number where FIELD has been calculated.
469 inline int FIELD_::getIterationNumber() const
471 return _iterationNumber ;
474 Set the time (in second) where FIELD has been calculated.
476 inline void FIELD_::setTime(double Time)
481 Get the time (in second) where FIELD has been calculated.
483 inline double FIELD_::getTime() const
488 Set the order number where FIELD has been calculated.
490 It corresponds to internal iteration during one time step.
492 inline void FIELD_::setOrderNumber(int OrderNumber)
494 _orderNumber=OrderNumber ;
497 Get the order number where FIELD has been calculated.
499 inline int FIELD_::getOrderNumber() const
501 return _orderNumber ;
504 Get a reference to the SUPPORT object associated to FIELD.
506 inline const SUPPORT * FIELD_::getSupport() const
511 Set the reference to the SUPPORT object associated to FIELD.
513 Reference is not duplicate, so it must not be deleted.
515 inline void FIELD_::setSupport(SUPPORT * support)
520 Get the FIELD med value type (MED_INT32 or MED_REEL64).
522 inline med_type_champ FIELD_::getValueType () const
527 Set the FIELD med value type (MED_INT32 or MED_REEL64).
529 inline void FIELD_::setValueType (med_type_champ ValueType)
531 _valueType = ValueType ;
534 /////////////////////////
535 // END OF CLASS FIELD_ //
536 /////////////////////////
540 This template class contains informations related with a FIELD :
541 - Values of the field
545 template <class T> class FIELD : public FIELD_
548 // ------- Drivers Management Part
551 //-----------------------//
553 //-----------------------//
556 virtual GENDRIVER * run(const string & fileName, FIELD<T> * ptrFIELD) const = 0 ;
559 //-------------------------------------------------------//
560 template <class T2> class INSTANCE_DE : public INSTANCE
561 //-------------------------------------------------------//
564 GENDRIVER * run(const string & fileName, FIELD<T> * ptrFIELD) const
566 return new T2(fileName,ptrFIELD);
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[] ;
574 // ------ End of Drivers Management Part
576 // array of value of type T
577 MEDARRAY<T> *_value ;
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="");
591 friend class MED_FIELD_RDONLY_DRIVER<T>;
592 friend class MED_FIELD_WRONLY_DRIVER<T>;
593 //friend class MED_FIELD_RDWR_DRIVER <T>;
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);
602 void allocValue(const int NumberOfComponents);
603 void allocValue(const int NumberOfComponents, const int LengthValue);
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 &);
612 inline void setValue(MEDARRAY<T> *Value);
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;
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);
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.
632 void getVolume() const throw (MEDEXCEPTION) ;
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.
642 void getArea() const throw (MEDEXCEPTION) ;
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.
652 void getLength() const throw (MEDEXCEPTION) ;
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.
662 void getNormal() const throw (MEDEXCEPTION) ;
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.
673 void getBarycenter() const throw (MEDEXCEPTION) ;
676 // --------------------
677 // Implemented Methods
678 // --------------------
683 template <class T> FIELD<T>::FIELD():
684 _value((MEDARRAY<T>*)NULL)
686 MESSAGE("Constructeur FIELD sans parametre");
692 template <class T> FIELD<T>::FIELD(const SUPPORT * Support,
693 const int NumberOfComponents):
694 FIELD_(Support, NumberOfComponents)
696 BEGIN_OF("FIELD<T>::FIELD(const SUPPORT * Support, const int NumberOfComponents)");
699 _numberOfValues = Support->getNumberOfElements(MED_ALL_ELEMENTS);
701 catch (MEDEXCEPTION &ex) {
702 MESSAGE("No value defined ! ("<<ex.what()<<")");
703 _value = (MEDARRAY<T>*)NULL ;
705 MESSAGE("FIELD : constructeur : "<< _numberOfValues <<" et "<< NumberOfComponents);
706 if (0<_numberOfValues) {
707 _value = new MEDARRAY<T>::MEDARRAY(_numberOfComponents,_numberOfValues);
710 _value = (MEDARRAY<T>*)NULL ;
712 END_OF("FIELD<T>::FIELD(const SUPPORT * Support, const int NumberOfComponents)");
719 template <class T> void FIELD<T>::init ()
726 template <class T> FIELD<T>::FIELD(const FIELD & m):
729 if (m._value != NULL)
731 // copie only default !
732 _value = new MEDARRAY<T>::MEDARRAY(* m._value,false);
735 _value = (MEDARRAY<T> *) NULL;
736 //_drivers = m._drivers;
742 template <class T> FIELD<T> & FIELD<T>::operator=(const FIELD &m)
749 template <class T> FIELD<T>::FIELD(const SUPPORT * Support,
750 driverTypes driverType,
751 const string & fileName/*=""*/,
752 const string & fieldDriverName/*=""*/)
754 const char * LOC = "template <class T> FIELD<T>::FIELD(const SUPPORT * Support, driverTypes driverType, const string & fileName=\"\", const string & fieldName=\"\") : ";
763 _value = (MEDARRAY<T>*)NULL;
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);
777 _drivers[current]->open();
778 _drivers[current]->read();
779 _drivers[current]->close();
787 template <class T> FIELD<T>::~FIELD()
789 BEGIN_OF(" Destructeur FIELD<T>::~FIELD()");
790 if (_value) delete _value;
791 END_OF(" Destructeur FIELD<T>::~FIELD()");
797 template <class T> void FIELD<T>::allocValue(const int NumberOfComponents)
799 const char* LOC = "FIELD<T>::allocValue(const int NumberOfComponents)" ;
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 ;
818 _numberOfValues = _support->getNumberOfElements(MED_ALL_ELEMENTS);
819 MESSAGE(LOC <<" : "<<_numberOfValues <<" et "<< NumberOfComponents);
821 _value = new MEDARRAY<T>::MEDARRAY(_numberOfComponents,_numberOfValues);
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 ;
831 END_OF("void FIELD<T>::allocValue(const int NumberOfComponents)");
837 template <class T> void FIELD<T>::allocValue(const int NumberOfComponents, const int LengthValue)
839 BEGIN_OF("void FIELD<T>::allocValue(const int NumberOfComponents,const int LengthValue)");
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 ;
856 MESSAGE("FIELD : constructeur : "<<LengthValue <<" et "<< NumberOfComponents);
857 _numberOfValues = LengthValue ;
858 _value = new MEDARRAY<T>::MEDARRAY(_numberOfComponents,_numberOfValues);
862 END_OF("void FIELD<T>::allocValue(const int NumberOfComponents,const int LengthValue)");
868 template <class T> void FIELD<T>::deallocValue()
870 BEGIN_OF("void FIELD<T>::deallocValue()");
871 _numberOfValues = 0 ;
872 _numberOfComponents = 0 ;
876 END_OF("void FIELD<T>::deallocValue()");
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 } ;
889 Create the specified driver and return its index reference to path to
890 read or write methods.
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"*/)
896 const char * LOC = "FIELD<T>::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\",const string & driverName=\"Default Field Name\") : ";
903 driver = instances[driverType]->run(fileName, this) ;
904 _drivers.push_back(driver);
905 current = _drivers.size()-1;
907 _drivers[current]->setFieldName(driverName);
916 Duplicate the given driver and return its index reference to path to
917 read or write methods.
919 template <class T> inline int FIELD<T>::addDriver (GENDRIVER & driver )
921 const char * LOC = "FIELD<T>::addDriver(GENDRIVER &) : ";
924 // duplicate driver to delete it with destructor !
925 GENDRIVER * newDriver = driver.copy() ;
927 _drivers.push_back(newDriver);
928 return _drivers.size() -1 ;
934 Remove the driver referenced by its index.
936 template <class T> void FIELD<T>::rmDriver (int index/*=0*/)
938 const char * LOC = "FIELD<T>::rmDriver (int index=0): ";
941 if ( _drivers[index] ) {
942 //_drivers.erase(&_drivers[index]);
944 MESSAGE ("detruire");
947 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
948 << "The index given is invalid, index must be between 0 and |"
957 Read FIELD in the file specified in the driver given by its index.
959 template <class T> inline void FIELD<T>::read(int index/*=0*/)
961 const char * LOC = "FIELD<T>::read(int index=0) : ";
964 if ( _drivers[index] ) {
965 _drivers[index]->open();
966 _drivers[index]->read();
967 _drivers[index]->close();
970 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
971 << "The index given is invalid, index must be between 0 and |"
979 Write FIELD in the file specified in the driver given by its index.
981 template <class T> inline void FIELD<T>::write(int index/*=0*/, const string & driverName /*= ""*/)
983 const char * LOC = "FIELD<T>::write(int index=0, const string & driverName = \"\") : ";
986 if( _drivers[index] ) {
987 _drivers[index]->open();
988 if (driverName != "") _drivers[index]->setFieldName(driverName);
989 _drivers[index]->write();
990 _drivers[index]->close();
993 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
994 << "The index given is invalid, index must be between 0 and |"
1003 Write FIELD with the driver which is equal to the given driver.
1007 template <class T> inline void FIELD<T>::write(const GENDRIVER & genDriver)
1009 const char * LOC = " FIELD<T>::write(const GENDRIVER &) : ";
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();
1025 Read FIELD with the driver which is equal to the given driver.
1029 template <class T> inline void FIELD<T>::read(const GENDRIVER & genDriver)
1031 const char * LOC = " FIELD<T>::read(const GENDRIVER &) : ";
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();
1047 Destroy the MEDARRAY<T> in FIELD and put the new one without copy.
1050 template <class T> inline void FIELD<T>::setValue(MEDARRAY<T> *Value)
1052 if (NULL != _value) delete _value ;
1058 Return a reference to the MEDARRAY<T> in FIELD.
1061 template <class T> inline MEDARRAY<T>* FIELD<T>::getvalue() const
1067 Return a reference to values array to read them.
1069 template <class T> inline const T* FIELD<T>::getValue(medModeSwitch Mode) const
1071 return _value->get(Mode) ;
1075 Return a reference to i^{th} row or column - component - (depend on Mode value)
1076 of FIELD values array.
1078 template <class T> inline const T* FIELD<T>::getValueI(medModeSwitch Mode,int i) const
1080 if ( Mode == MED_FULL_INTERLACE )
1082 return _value->getRow(i) ;
1084 ASSERT ( Mode == MED_NO_INTERLACE);
1085 return _value->getColumn(i);
1089 Return the value of i^{th} element and j^{th} component.
1091 template <class T> inline T FIELD<T>::getValueIJ(int i,int j) const
1093 return _value->getIJ(i,j) ;
1097 Copy new values array in FIELD according to the given mode.
1099 Array must have right size. If not results are unpredicable.
1101 template <class T> inline void FIELD<T>::setValue(medModeSwitch mode, T* value)
1103 _value->set(mode,value);
1107 Update values array in FIELD with the given ones according to specified mode.
1109 template <class T> inline void FIELD<T>::setValueI(medModeSwitch mode, int i, T* value)
1112 if (MED_FULL_INTERLACE == mode)
1113 _value->setI(i,value);
1114 else if (MED_NO_INTERLACE == mode)
1115 _value->setJ(i,value);
1117 throw MEDEXCEPTION(LOCALIZED("FIELD<T>::setValueI : bad medModeSwitch")) ;
1121 Set the value of i^{th} element and j^{th} component with the given one.
1123 template <class T> inline void FIELD<T>::setValueIJ(int i, int j, T value)
1125 _value->setIJ(i,j,value);
1133 Fill values array with volume values.
1135 template <class T> void FIELD<T>::getVolume() const throw (MEDEXCEPTION)
1137 const char * LOC = "FIELD<double>::getVolume() const : ";
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>)
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"));
1151 Fill values array with area values.
1153 template <class T> void FIELD<T>::getArea() const throw (MEDEXCEPTION)
1155 const char * LOC = "FIELD<double>::getArea() const : ";
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>)
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"));
1169 Fill values array with length values.
1171 template <class T> void FIELD<T>::getLength() const throw (MEDEXCEPTION)
1173 const char * LOC = "FIELD<double>::getLength() const : ";
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>)
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"));
1187 Fill values array with normal values.
1189 template <class T> void FIELD<T>::getNormal() const throw (MEDEXCEPTION)
1191 const char * LOC = "FIELD<double>::getNormal() const : ";
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>)
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"));
1201 int dim_space = _support->getMesh()->getSpaceDimension();
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"));
1210 Fill values array with barycenter values.
1212 template <class T> void FIELD<T>::getBarycenter() const throw (MEDEXCEPTION)
1214 const char * LOC = "FIELD<double>::getBarycenter() const : ";
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>)
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"));
1224 int dim_space = _support->getMesh()->getSpaceDimension();
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"));
1232 #endif /* FIELD_HXX */