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 ;
43 FIELD_::FIELD_(const FIELD_ &m)
47 _description = m._description;
48 _support = m._support;
49 _numberOfComponents = m._numberOfComponents;
50 _numberOfValues = m._numberOfValues;
52 if (m._componentsTypes != NULL)
54 _componentsTypes = new int[m._numberOfComponents] ;
55 memcpy(_componentsTypes,m._componentsTypes,sizeof(int)*m._numberOfComponents);
57 _componentsTypes = new int[m._numberOfComponents] ;
58 for(int i=0;i<m._numberOfComponents;i++) {
59 _componentsTypes[i] = m._componentsTypes[i] ;
63 else _componentsTypes = (int *) NULL;
65 _componentsNames = new string[m._numberOfComponents];
66 for (int i=0; i<m._numberOfComponents; i++)
67 {_componentsNames[i]=m._componentsNames[i];}
68 _componentsDescriptions = new string[m._numberOfComponents];
69 for (int i=0; i<m._numberOfComponents; i++)
70 {_componentsDescriptions[i]=m._componentsDescriptions[i];}
71 _componentsUnits = new UNIT[m._numberOfComponents];
72 for (int i=0; i<m._numberOfComponents; i++)
73 {_componentsUnits[i] = m._componentsUnits[i];}
74 // L'operateur '=' est defini dans la classe UNIT
75 _MEDComponentsUnits = new string[m._numberOfComponents];
76 for (int i=0; i<m._numberOfComponents; i++)
77 {_MEDComponentsUnits[i] = m._MEDComponentsUnits[i];}
78 _iterationNumber = m._iterationNumber;
80 _orderNumber = m._orderNumber;
81 _valueType = m._valueType;
82 //_drivers = m._drivers ; // PG : Well, same driver, what about m destructor !
89 if ( _componentsTypes !=NULL)
90 delete[] _componentsTypes ;
91 if ( _componentsNames !=NULL)
92 delete[] _componentsNames ;
93 if ( _componentsDescriptions !=NULL)
94 delete[] _componentsDescriptions ;
95 if ( _componentsUnits !=NULL)
96 delete[] _componentsUnits ;
97 if ( _MEDComponentsUnits !=NULL)
98 delete[] _MEDComponentsUnits ;
101 // vector<GENDRIVER *>::const_iterator it ;
102 // SCRUTE(_drivers.size());
104 // for (it=_drivers.begin();it!=_drivers.end();it++) {
110 MESSAGE("In this object FIELD_ there is(are) " << _drivers.size() << " driver(s)");
112 for (unsigned int index=0; index < _drivers.size(); index++ )
114 SCRUTE(_drivers[index]);
115 if ( _drivers[index] != NULL) delete _drivers[index];
121 PROVISOIRE : retourne des volumes, surfaces ou longueurs suivant les cas
124 FIELD<double>* FIELD_::_getFieldSize() const
126 FIELD<double>* p_field_size;
127 switch (getSupport()->getEntity())
130 switch (getSupport()->getMesh()->getSpaceDimension() )
133 p_field_size=getSupport()->getMesh()->getLength(getSupport() );
136 p_field_size=getSupport()->getMesh()->getArea(getSupport() );
139 p_field_size=getSupport()->getMesh()->getVolume(getSupport() );
145 p_field_size=getSupport()->getMesh()->getArea(getSupport() );
149 p_field_size=getSupport()->getMesh()->getLength(getSupport() );
158 Check up the compatibility of field before computing sobolev norm
161 void FIELD_::_checkNormCompatibility(const FIELD<double>* support_volume) const throw (MEDEXCEPTION)
164 if( getSupport()->getEntity() == MED_NODE )
166 diagnosis="Cannot compute sobolev norm on a field "+getName()+
167 " : it has support on nodes!";
168 throw MEDEXCEPTION(diagnosis.c_str());
171 if (getNumberOfValues()*getNumberOfComponents()<= 0) // Size of array has to be strictly positive
173 diagnosis="Cannot compute the norm of "+getName()+
174 " : it size is non positive!";
175 throw MEDEXCEPTION(diagnosis.c_str());
178 const int* nbGauss=getSupport()->getNumberOfGaussPoint();
179 for (int i=0; i<getSupport()->getNumberOfTypes(); ++i)
182 diagnosis="Cannot compute Lnorm of "+getName()+
183 " : Gauss numbers greater than one are not yet implemented!";
184 throw MEDEXCEPTION(diagnosis.c_str());
187 if(support_volume) // if the user has supplied the volume
189 if(support_volume->getSupport()!=getSupport())
191 diagnosis="Cannot compute Lnorm of "+getName()+
192 " : the volume furnished has not the same support!";
193 throw MEDEXCEPTION(diagnosis.c_str());
195 if(support_volume->getNumberOfValues()!=getNumberOfValues())
197 diagnosis="Cannot compute Lnorm of "+getName()+
198 " : the volume furnished has not the same number of values!";
199 throw MEDEXCEPTION(diagnosis.c_str());
207 Check up the compatibility of fields before performing an arithmetic operation
210 void FIELD_::_checkFieldCompatibility(const FIELD_& m, const FIELD_& n ) throw (MEDEXCEPTION)
214 // check-up, fill diagnosis if some incompatibility is found.
215 if(m._support != n._support)
217 if(!(*m._support==*n._support))
218 diagnosis+="They don't have the same support!";
220 else if(m._numberOfComponents != n._numberOfComponents)
221 diagnosis+="They don't have the same number of components!";
222 else if(m._numberOfValues != n._numberOfValues)
223 diagnosis+="They don't have the same number of values!";
226 for(int i=0; i<m._numberOfComponents; i++)
228 // Not yet implemented
229 // if(m._componentsTypes[i] != n._componentsTypes[i])
231 // diagnosis+="Components don't have the same types!";
234 if(m._MEDComponentsUnits[i] != n._MEDComponentsUnits[i])
236 diagnosis+="Components don't have the same units!";
242 if(diagnosis.size()) // if fields are not compatible : complete diagnosis and throw exception
244 diagnosis="Field's operation not allowed!\nThe fields " + m._name + " and "
245 + n._name + " are not compatible.\n" + diagnosis;
246 throw MEDEXCEPTION(diagnosis.c_str());
249 if( m.getNumberOfValues()<=0 || m.getNumberOfComponents()<=0) // check up the size is strictly positive
251 diagnosis="Field's operation not allowed!\nThe fields " + m._name + " and "
252 + n._name + " are empty! (size<=0).\n";
253 throw MEDEXCEPTION(diagnosis.c_str());
258 // void FIELD_::setIterationNumber (int IterationNumber) {};
259 // void FIELD_::setOrderNumber (int OrderNumber) {};
260 // void FIELD_::setFieldName (string& fieldName) {};
262 void FIELD_::rmDriver (int index)
264 MESSAGE("void FIELD_::rmDriver(int index) : removing the driver " << index);
266 int FIELD_::addDriver (driverTypes driverType,
267 const string & fileName,
268 const string & driverFieldName,
269 med_mode_acces access)
271 MESSAGE("int FIELD_::addDriver(driverTypes driverType, const string & fileName, const string & driverFieldName) : adding the driver " << driverType << " fileName = " << fileName.c_str() << " driverFieldName = " << driverFieldName.c_str());
274 int FIELD_::addDriver (GENDRIVER & driver)
276 MESSAGE("int FIELD_::addDriver(GENDRIVER & driver) : driver " << driver);
279 void FIELD_::openAppend ( void ) {};
280 void FIELD_::write (const GENDRIVER &) {};
281 void FIELD_::writeAppend (const GENDRIVER &) {};
282 void FIELD_::read (const GENDRIVER &) {};
283 void FIELD_::write (int , const string & ) {};
284 void FIELD_::writeAppend (int , const string & ) {};
285 void FIELD_::read (int ) {};
287 // void FIELD_::setValueType(med_type_champ ValueType) {};
288 // med_type_champ FIELD_::getValueType() {};