Salome HOME
adding some castem mesh file to test the GIBI driver of Med Memory.
[modules/med.git] / src / MEDMEM / MEDMEM_Field.cxx
1 using namespace std;
2 #include "MEDMEM_Field.hxx"
3
4 // ---------------------------------
5 // FIELD_ : Constructors
6 // ---------------------------------
7 FIELD_::FIELD_(): 
8   _isRead(false),
9   _name(""), _description(""), _support((SUPPORT *)NULL),
10   _numberOfComponents(0), _numberOfValues(0),_componentsTypes((int *)NULL),
11   _componentsNames((string *)NULL), 
12   _componentsDescriptions((string *)NULL),
13   _componentsUnits((UNIT*)NULL),
14   _MEDComponentsUnits((string *)NULL),
15   _iterationNumber(-1),_time(0.0),_orderNumber(-1)
16 {
17   MESSAGE("Constructeur FIELD_ sans parametre");
18 }
19
20 FIELD_::FIELD_(const SUPPORT * Support, const int NumberOfComponents):
21   _isRead(false),
22   _name(""), _description(""), _support(Support),
23   _numberOfComponents(NumberOfComponents),
24   _iterationNumber(-1),_time(0.0),_orderNumber(-1)
25 {
26   MESSAGE("FIELD_(const SUPPORT * Support, const int NumberOfComponents)");
27
28   _numberOfValues = Support->getNumberOfElements(MED_ALL_ELEMENTS);
29   _componentsTypes = new int[NumberOfComponents] ;
30   _componentsNames = new string[NumberOfComponents];
31   _componentsDescriptions = new string[NumberOfComponents];
32   _componentsUnits = new UNIT[NumberOfComponents];
33   _MEDComponentsUnits = new string[NumberOfComponents];
34   for(int i=0;i<NumberOfComponents;i++) {
35     _componentsTypes[i] = 0 ;
36   }
37 }
38
39 FIELD_::FIELD_(const FIELD_ &m)
40 {
41   _isRead = m._isRead ;
42   _name = m._name;
43   _description = m._description;
44   _support = m._support;
45   _numberOfComponents = m._numberOfComponents;
46   _numberOfValues = m._numberOfValues;
47
48   if (m._componentsTypes != NULL)
49     {
50       _componentsTypes = new int[m._numberOfComponents] ;
51       memcpy(_componentsTypes,m._componentsTypes,sizeof(int)*m._numberOfComponents);
52       /*
53       _componentsTypes = new int[m._numberOfComponents] ;
54       for(int i=0;i<m._numberOfComponents;i++) {
55         _componentsTypes[i] = m._componentsTypes[i] ;
56       }
57       */
58     }
59   else _componentsTypes = (int *) NULL;
60
61   _componentsNames = new string[m._numberOfComponents];
62   for (int i=0; i<m._numberOfComponents; i++)
63     {_componentsNames[i]=m._componentsNames[i];}
64   _componentsDescriptions = new string[m._numberOfComponents];
65   for (int i=0; i<m._numberOfComponents; i++)
66     {_componentsDescriptions[i]=m._componentsDescriptions[i];}
67   _componentsUnits = new UNIT[m._numberOfComponents];
68   for (int i=0; i<m._numberOfComponents; i++)
69     {_componentsUnits[i] = m._componentsUnits[i];}
70   // L'operateur '=' est defini dans la classe UNIT
71   _MEDComponentsUnits = new string[m._numberOfComponents];
72   for (int i=0; i<m._numberOfComponents; i++)
73     {_MEDComponentsUnits[i] = m._MEDComponentsUnits[i];}
74   _iterationNumber = m._iterationNumber;
75   _time = m._time;
76   _orderNumber = m._orderNumber;
77   _valueType = m._valueType;
78   //_drivers = m._drivers ; // PG : Well, same driver, what about m destructor !
79
80 }
81
82 FIELD_::~FIELD_()
83 {   
84   MESSAGE("~FIELD_()");
85   if ( _componentsTypes !=NULL)
86     delete[] _componentsTypes ;
87   if ( _componentsNames !=NULL)
88     delete[] _componentsNames ;
89   if ( _componentsDescriptions !=NULL)
90     delete[] _componentsDescriptions ;
91   if ( _componentsUnits !=NULL)
92     delete[] _componentsUnits ;
93   if ( _MEDComponentsUnits !=NULL)
94     delete[] _MEDComponentsUnits ;
95
96   // delete driver
97 //   vector<GENDRIVER *>::const_iterator it ;
98 //   SCRUTE(_drivers.size());
99 //   int i=0;
100 //   for (it=_drivers.begin();it!=_drivers.end();it++) {
101 //     i++;
102 //     SCRUTE(i);
103 //     delete (*it) ;
104
105
106   MESSAGE("In this object FIELD_ there is(are) " << _drivers.size() << " driver(s)");
107
108   for (unsigned int index=0; index < _drivers.size(); index++ )
109     {
110       SCRUTE(_drivers[index]);
111       if ( _drivers[index] != NULL) delete _drivers[index];
112     }
113 }
114
115 /*! 
116   \if developper
117   PROVISOIRE : retourne des volumes, surfaces ou longueurs suivant les cas
118   \endif
119 */
120 FIELD<double>* FIELD_::_getFieldSize() const
121 {
122     FIELD<double>* p_field_size;
123     switch (getSupport()->getEntity())
124     {
125         case MED_CELL :
126             switch (getSupport()->getMesh()->getSpaceDimension() ) 
127             {
128                 case 1:
129                     p_field_size=getSupport()->getMesh()->getLength(getSupport() );
130                     break;
131                 case 2:
132                     p_field_size=getSupport()->getMesh()->getArea(getSupport() );
133                     break;
134                 case 3:
135                     p_field_size=getSupport()->getMesh()->getVolume(getSupport() );
136                     break;
137             }
138             break;
139             
140         case MED_FACE :
141             p_field_size=getSupport()->getMesh()->getArea(getSupport() );
142             break;
143
144         case MED_EDGE :
145             p_field_size=getSupport()->getMesh()->getLength(getSupport() );
146             break;
147     }
148     return p_field_size;
149 }
150
151
152 /*! 
153   \if developper
154   Check up the compatibility of field before computing sobolev norm 
155   \endif
156 */
157 void FIELD_::_checkNormCompatibility(const FIELD<double>* support_volume) const throw (MEDEXCEPTION)
158 {
159     string diagnosis;
160     if( getSupport()->getEntity() == MED_NODE )
161     {
162         diagnosis="Cannot compute sobolev norm on a field "+getName()+
163             " : it has support on nodes!";
164         throw MEDEXCEPTION(diagnosis.c_str());
165     }
166         
167     if (getNumberOfValues()*getNumberOfComponents()<= 0) // Size of array has to be strictly positive
168     {
169         diagnosis="Cannot compute the norm of "+getName()+
170             " : it size is non positive!";
171         throw MEDEXCEPTION(diagnosis.c_str());
172     }
173
174     const int* nbGauss=getSupport()->getNumberOfGaussPoint();
175     for (int i=0; i<getSupport()->getNumberOfTypes(); ++i)
176         if(nbGauss[i]!=1)
177         {
178             diagnosis="Cannot compute Lnorm of "+getName()+
179             " : Gauss numbers greater than one are not yet implemented!";
180             throw MEDEXCEPTION(diagnosis.c_str());
181         }
182
183     if(support_volume) // if the user has supplied the volume
184     {
185         if(support_volume->getSupport()!=getSupport())
186         {
187             diagnosis="Cannot compute Lnorm of "+getName()+
188             " : the volume furnished has not the same support!";
189             throw MEDEXCEPTION(diagnosis.c_str());
190         }
191         if(support_volume->getNumberOfValues()!=getNumberOfValues())
192         {
193             diagnosis="Cannot compute Lnorm of "+getName()+
194             " : the volume furnished has not the same number of values!";
195             throw MEDEXCEPTION(diagnosis.c_str());
196         }
197     }
198
199 }
200
201 /*! 
202   \if developper
203    Check up the compatibility of fields before performing an arithmetic operation
204   \endif
205 */
206 void FIELD_::_checkFieldCompatibility(const FIELD_& m, const FIELD_& n ) throw (MEDEXCEPTION)
207 {
208     string diagnosis;
209
210     // check-up, fill diagnosis if some incompatibility is found.
211     if(m._support != n._support)
212         diagnosis+="They don't have the same support!";
213     else if(m._numberOfComponents != n._numberOfComponents)
214         diagnosis+="They don't have the same number of components!";
215     else if(m._numberOfValues != n._numberOfValues)
216         diagnosis+="They don't have the same number of values!";
217     else
218     {
219         for(int i=0; i<m._numberOfComponents; i++)
220         {
221 // Not yet implemented   
222 //          if(m._componentsTypes[i] != n._componentsTypes[i])
223 //          {
224 //              diagnosis+="Components don't have the same types!";
225 //              break;
226 //          }
227             if(m._MEDComponentsUnits[i] != n._MEDComponentsUnits[i])
228             {
229                 diagnosis+="Components don't have the same units!";
230                 break;
231             }
232         }
233     }
234
235     if(diagnosis.size()) // if fields are not compatible : complete diagnosis and throw exception
236     {
237         diagnosis="Field's operation not allowed!\nThe fields " + m._name + " and " 
238                  + n._name + " are not compatible.\n" + diagnosis;
239         throw MEDEXCEPTION(diagnosis.c_str());
240     }
241
242     if( m.getNumberOfValues()<=0 || m.getNumberOfComponents()<=0) // check up the size is strictly positive
243     {
244         diagnosis="Field's operation not allowed!\nThe fields " + m._name + " and " 
245                  + n._name + " are empty! (size<=0).\n";
246         throw MEDEXCEPTION(diagnosis.c_str());
247     }
248
249 }
250
251 //  void     FIELD_::setIterationNumber (int IterationNumber)           {};
252 //  void     FIELD_::setOrderNumber     (int OrderNumber)               {}; 
253 //  void     FIELD_::setFieldName       (string& fieldName)             {}; 
254          
255 void     FIELD_::rmDriver      (int index)
256 {
257   MESSAGE("void FIELD_::rmDriver(int index) : removing the driver " << index);
258 };
259 int      FIELD_::addDriver     (driverTypes driverType, 
260                                 const string & fileName,
261                                 const string & driverFieldName)
262 {
263   MESSAGE("int FIELD_::addDriver(driverTypes driverType, const string & fileName, const string & driverFieldName) : adding the driver " << driverType << " fileName = " << fileName.c_str() << " driverFieldName = " << driverFieldName.c_str());
264   return 0;
265 };
266 int      FIELD_::addDriver     (GENDRIVER & driver)
267 {
268   MESSAGE("int FIELD_::addDriver(GENDRIVER & driver) : driver " << driver);
269   return 0;
270 };
271 void     FIELD_::openAppend    ( void )                               {};
272 void     FIELD_::write         (const GENDRIVER &)                    {};
273 void     FIELD_::writeAppend   (const GENDRIVER &)                    {};
274 void     FIELD_::read          (const GENDRIVER &)                    {};
275 void     FIELD_::write         (int , const string & ) {};
276 void     FIELD_::writeAppend   (int , const string & ) {};
277 void     FIELD_::read          (int )                                  {};
278
279 //  void                     FIELD_::setValueType(med_type_champ ValueType) {};
280 //  med_type_champ FIELD_::getValueType() {};