1 #include "MEDMEM_Field.hxx"
2 #include "MEDMEM_Mesh.hxx"
5 using namespace MEDMEM;
6 using namespace MED_EN;
8 // ---------------------------------
9 // FIELD_ : Constructors
10 // ---------------------------------
13 _name(""), _description(""), _support((SUPPORT *)NULL),
14 _numberOfComponents(0), _numberOfValues(0),_componentsTypes((int *)NULL),
15 _componentsNames((string *)NULL),
16 _componentsDescriptions((string *)NULL),
17 _componentsUnits((UNIT*)NULL),
18 _MEDComponentsUnits((string *)NULL),
19 _iterationNumber(-1),_time(0.0),_orderNumber(-1)
21 MESSAGE("Constructeur FIELD_ sans parametre");
24 FIELD_::FIELD_(const SUPPORT * Support, const int NumberOfComponents):
26 _name(""), _description(""), _support(Support),
27 _numberOfComponents(NumberOfComponents),
28 _iterationNumber(-1),_time(0.0),_orderNumber(-1)
30 MESSAGE("FIELD_(const SUPPORT * Support, const int NumberOfComponents)");
32 _numberOfValues = Support->getNumberOfElements(MED_ALL_ELEMENTS);
33 _componentsTypes = new int[NumberOfComponents] ;
34 _componentsNames = new string[NumberOfComponents];
35 _componentsDescriptions = new string[NumberOfComponents];
36 _componentsUnits = new UNIT[NumberOfComponents];
37 _MEDComponentsUnits = new string[NumberOfComponents];
38 for(int i=0;i<NumberOfComponents;i++) {
39 _componentsTypes[i] = 0 ;
42 _support->addReference();
45 FIELD_::FIELD_(const FIELD_ &m)
49 _description = m._description;
50 _support = m._support;
52 _support->addReference();
53 _numberOfComponents = m._numberOfComponents;
54 _numberOfValues = m._numberOfValues;
56 _valueType = m._valueType;
57 //_drivers = m._drivers ; // PG : Well, same driver, what about m destructor !
63 if ( _componentsTypes !=NULL)
64 delete[] _componentsTypes ;
65 if ( _componentsNames !=NULL)
66 delete[] _componentsNames ;
67 if ( _componentsDescriptions !=NULL)
68 delete[] _componentsDescriptions ;
69 if ( _componentsUnits !=NULL)
70 delete[] _componentsUnits ;
71 if ( _MEDComponentsUnits !=NULL)
72 delete[] _MEDComponentsUnits ;
74 // vector<GENDRIVER *>::const_iterator it ;
75 // SCRUTE(_drivers.size());
77 // for (it=_drivers.begin();it!=_drivers.end();it++) {
83 MESSAGE("In this object FIELD_ there is(are) " << _drivers.size() << " driver(s)");
85 for (unsigned int index=0; index < _drivers.size(); index++ )
87 SCRUTE(_drivers[index]);
88 if ( _drivers[index] != NULL) delete _drivers[index];
94 PROVISOIRE : retourne des volumes, surfaces ou longueurs suivant les cas
97 FIELD<double>* FIELD_::_getFieldSize() const
99 FIELD<double>* p_field_size;
100 switch (getSupport()->getEntity())
103 switch (getSupport()->getMesh()->getSpaceDimension() )
106 p_field_size=getSupport()->getMesh()->getLength(getSupport() );
109 p_field_size=getSupport()->getMesh()->getArea(getSupport() );
112 p_field_size=getSupport()->getMesh()->getVolume(getSupport() );
118 p_field_size=getSupport()->getMesh()->getArea(getSupport() );
122 p_field_size=getSupport()->getMesh()->getLength(getSupport() );
131 Check up the compatibility of field before computing sobolev norm
134 void FIELD_::_checkNormCompatibility(const FIELD<double>* support_volume) const throw (MEDEXCEPTION)
137 if( getSupport()->getEntity() == MED_NODE )
139 diagnosis="Cannot compute sobolev norm on a field "+getName()+
140 " : it has support on nodes!";
141 throw MEDEXCEPTION(diagnosis.c_str());
144 if (getNumberOfValues()*getNumberOfComponents()<= 0) // Size of array has to be strictly positive
146 diagnosis="Cannot compute the norm of "+getName()+
147 " : it size is non positive!";
148 throw MEDEXCEPTION(diagnosis.c_str());
151 const int* nbGauss=getSupport()->getNumberOfGaussPoint();
152 for (int i=0; i<getSupport()->getNumberOfTypes(); ++i)
155 diagnosis="Cannot compute Lnorm of "+getName()+
156 " : Gauss numbers greater than one are not yet implemented!";
157 throw MEDEXCEPTION(diagnosis.c_str());
160 if(support_volume) // if the user has supplied the volume
162 if(support_volume->getSupport()!=getSupport())
164 diagnosis="Cannot compute Lnorm of "+getName()+
165 " : the volume furnished has not the same support!";
166 throw MEDEXCEPTION(diagnosis.c_str());
168 if(support_volume->getNumberOfValues()!=getNumberOfValues())
170 diagnosis="Cannot compute Lnorm of "+getName()+
171 " : the volume furnished has not the same number of values!";
172 throw MEDEXCEPTION(diagnosis.c_str());
180 Check up the compatibility of fields before performing an arithmetic operation
183 void FIELD_::_checkFieldCompatibility(const FIELD_& m, const FIELD_& n, bool checkUnit) throw (MEDEXCEPTION)
187 // check-up, fill diagnosis if some incompatibility is found.
188 if(m._support != n._support)
190 if(!(*m._support==*n._support))
191 diagnosis+="They don't have the same support!";
193 else if(m._numberOfComponents != n._numberOfComponents)
194 diagnosis+="They don't have the same number of components!";
195 else if(m._numberOfValues != n._numberOfValues)
196 diagnosis+="They don't have the same number of values!";
201 for(int i=0; i<m._numberOfComponents; i++)
203 // Not yet implemented
204 // if(m._componentsTypes[i] != n._componentsTypes[i])
206 // diagnosis+="Components don't have the same types!";
209 if(m._MEDComponentsUnits[i] != n._MEDComponentsUnits[i])
211 diagnosis+="Components don't have the same units!";
218 if(diagnosis.size()) // if fields are not compatible : complete diagnosis and throw exception
220 diagnosis="Field's operation not allowed!\nThe fields " + m._name + " and "
221 + n._name + " are not compatible.\n" + diagnosis;
222 throw MEDEXCEPTION(diagnosis.c_str());
225 if( m.getNumberOfValues()<=0 || m.getNumberOfComponents()<=0) // check up the size is strictly positive
227 diagnosis="Field's operation not allowed!\nThe fields " + m._name + " and "
228 + n._name + " are empty! (size<=0).\n";
229 throw MEDEXCEPTION(diagnosis.c_str());
234 void FIELD_::_deepCheckFieldCompatibility(const FIELD_& m, const FIELD_& n , bool checkUnit ) throw (MEDEXCEPTION)
238 // check-up, fill diagnosis if some incompatibility is found.
239 if(m._support != n._support)
241 if(!(m._support->deepCompare(*n._support)))
242 diagnosis+="They don't have the same support!";
244 else if(m._numberOfComponents != n._numberOfComponents)
245 diagnosis+="They don't have the same number of components!";
246 else if(m._numberOfValues != n._numberOfValues)
247 diagnosis+="They don't have the same number of values!";
252 for(int i=0; i<m._numberOfComponents; i++)
254 if(m._MEDComponentsUnits[i] != n._MEDComponentsUnits[i])
256 diagnosis+="Components don't have the same units!";
263 if(diagnosis.size()) // if fields are not compatible : complete diagnosis and throw exception
265 diagnosis="Field's operation not allowed!\nThe fields " + m._name + " and "
266 + n._name + " are not compatible.\n" + diagnosis;
267 throw MEDEXCEPTION(diagnosis.c_str());
270 if( m.getNumberOfValues()<=0 || m.getNumberOfComponents()<=0) // check up the size is strictly positive
272 diagnosis="Field's operation not allowed!\nThe fields " + m._name + " and "
273 + n._name + " are empty! (size<=0).\n";
274 throw MEDEXCEPTION(diagnosis.c_str());
278 void FIELD_::rmDriver (int index)
280 MESSAGE("void FIELD_::rmDriver(int index) : removing the driver " << index);
282 int FIELD_::addDriver (driverTypes driverType,
283 const string & fileName,
284 const string & driverFieldName,
285 med_mode_acces access)
287 MESSAGE("int FIELD_::addDriver(driverTypes driverType, const string & fileName, const string & driverFieldName) : adding the driver " << driverType << " fileName = " << fileName.c_str() << " driverFieldName = " << driverFieldName.c_str());
291 int FIELD_::addDriver (GENDRIVER & driver)
293 MESSAGE("int FIELD_::addDriver(GENDRIVER & driver) : driver " << driver);
297 void FIELD_::openAppend ( void ) {};
298 void FIELD_::write (const GENDRIVER &) {};
299 void FIELD_::writeAppend (const GENDRIVER &) {};
300 void FIELD_::read (const GENDRIVER &) {};
301 void FIELD_::write (int , const string & ) {};
302 void FIELD_::writeAppend (int , const string & ) {};
303 void FIELD_::read (int ) {};
304 void FIELD_::copyGlobalInfo(const FIELD_& m)
306 if (m._componentsTypes != NULL)
308 _componentsTypes = new int[m._numberOfComponents] ;
309 memcpy(_componentsTypes,m._componentsTypes,sizeof(int)*m._numberOfComponents);
312 _componentsTypes = (int *) NULL;
314 _componentsNames = new string[m._numberOfComponents];
315 for (int i=0; i<m._numberOfComponents; i++)
316 _componentsNames[i]=m._componentsNames[i];
317 _componentsDescriptions = new string[m._numberOfComponents];
318 for (int i=0; i<m._numberOfComponents; i++)
319 _componentsDescriptions[i]=m._componentsDescriptions[i];
321 if (m._componentsUnits != NULL)
323 _componentsUnits = new UNIT[m._numberOfComponents];
324 for (int i=0; i<m._numberOfComponents; i++)
325 _componentsUnits[i] = m._componentsUnits[i];
328 _componentsUnits=(UNIT*)NULL;
330 // L'operateur '=' est defini dans la classe UNIT
331 _MEDComponentsUnits = new string[m._numberOfComponents];
332 for (int i=0; i<m._numberOfComponents; i++)
333 {_MEDComponentsUnits[i] = m._MEDComponentsUnits[i];}
334 _iterationNumber = m._iterationNumber;
336 _orderNumber = m._orderNumber;