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