2 #include "MEDMEM_Field.hxx"
4 // ---------------------------------
5 // FIELD_ : Constructors
6 // ---------------------------------
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)
17 MESSAGE("Constructeur FIELD_ sans parametre");
20 FIELD_::FIELD_(const SUPPORT * Support, const int NumberOfComponents):
22 _name(""), _description(""), _support(Support),
23 _numberOfComponents(NumberOfComponents),
24 _iterationNumber(-1),_time(0.0),_orderNumber(-1)
26 MESSAGE("FIELD_(const SUPPORT * Support, const int NumberOfComponents)");
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 ;
39 FIELD_::FIELD_(const FIELD_ &m)
43 _description = m._description;
44 _support = m._support;
45 _numberOfComponents = m._numberOfComponents;
46 _numberOfValues = m._numberOfValues;
48 if (m._componentsTypes != NULL)
50 _componentsTypes = new int[m._numberOfComponents] ;
51 memcpy(_componentsTypes,m._componentsTypes,sizeof(int)*m._numberOfComponents);
53 _componentsTypes = new int[m._numberOfComponents] ;
54 for(int i=0;i<m._numberOfComponents;i++) {
55 _componentsTypes[i] = m._componentsTypes[i] ;
59 else _componentsTypes = (int *) NULL;
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;
76 _orderNumber = m._orderNumber;
77 _valueType = m._valueType;
78 //_drivers = m._drivers ; // PG : Well, same driver, what about m destructor !
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 ;
97 // vector<GENDRIVER *>::const_iterator it ;
98 // SCRUTE(_drivers.size());
100 // for (it=_drivers.begin();it!=_drivers.end();it++) {
106 MESSAGE("In this object FIELD_ there is(are) " << _drivers.size() << " driver(s)");
108 for (unsigned int index=0; index < _drivers.size(); index++ )
110 SCRUTE(_drivers[index]);
111 if ( _drivers[index] != NULL) delete _drivers[index];
117 PROVISOIRE : retourne des volumes, surfaces ou longueurs suivant les cas
120 FIELD<double>* FIELD_::_getFieldSize() const
122 FIELD<double>* p_field_size;
123 switch (getSupport()->getEntity())
126 switch (getSupport()->getMesh()->getSpaceDimension() )
129 p_field_size=getSupport()->getMesh()->getLength(getSupport() );
132 p_field_size=getSupport()->getMesh()->getArea(getSupport() );
135 p_field_size=getSupport()->getMesh()->getVolume(getSupport() );
141 p_field_size=getSupport()->getMesh()->getArea(getSupport() );
145 p_field_size=getSupport()->getMesh()->getLength(getSupport() );
154 Check up the compatibility of field before computing sobolev norm
157 void FIELD_::_checkNormCompatibility(const FIELD<double>* support_volume) const throw (MEDEXCEPTION)
160 if( getSupport()->getEntity() == MED_NODE )
162 diagnosis="Cannot compute sobolev norm on a field "+getName()+
163 " : it has support on nodes!";
164 throw MEDEXCEPTION(diagnosis.c_str());
167 if (getNumberOfValues()*getNumberOfComponents()<= 0) // Size of array has to be strictly positive
169 diagnosis="Cannot compute the norm of "+getName()+
170 " : it size is non positive!";
171 throw MEDEXCEPTION(diagnosis.c_str());
174 const int* nbGauss=getSupport()->getNumberOfGaussPoint();
175 for (int i=0; i<getSupport()->getNumberOfTypes(); ++i)
178 diagnosis="Cannot compute Lnorm of "+getName()+
179 " : Gauss numbers greater than one are not yet implemented!";
180 throw MEDEXCEPTION(diagnosis.c_str());
183 if(support_volume) // if the user has supplied the volume
185 if(support_volume->getSupport()!=getSupport())
187 diagnosis="Cannot compute Lnorm of "+getName()+
188 " : the volume furnished has not the same support!";
189 throw MEDEXCEPTION(diagnosis.c_str());
191 if(support_volume->getNumberOfValues()!=getNumberOfValues())
193 diagnosis="Cannot compute Lnorm of "+getName()+
194 " : the volume furnished has not the same number of values!";
195 throw MEDEXCEPTION(diagnosis.c_str());
203 Check up the compatibility of fields before performing an arithmetic operation
206 void FIELD_::_checkFieldCompatibility(const FIELD_& m, const FIELD_& n ) throw (MEDEXCEPTION)
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!";
219 for(int i=0; i<m._numberOfComponents; i++)
221 // Not yet implemented
222 // if(m._componentsTypes[i] != n._componentsTypes[i])
224 // diagnosis+="Components don't have the same types!";
227 if(m._MEDComponentsUnits[i] != n._MEDComponentsUnits[i])
229 diagnosis+="Components don't have the same units!";
235 if(diagnosis.size()) // if fields are not compatible : complete diagnosis and throw exception
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());
242 if( m.getNumberOfValues()<=0 || m.getNumberOfComponents()<=0) // check up the size is strictly positive
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());
251 // void FIELD_::setIterationNumber (int IterationNumber) {};
252 // void FIELD_::setOrderNumber (int OrderNumber) {};
253 // void FIELD_::setFieldName (string& fieldName) {};
255 void FIELD_::rmDriver (int index)
257 MESSAGE("void FIELD_::rmDriver(int index) : removing the driver " << index);
259 int FIELD_::addDriver (driverTypes driverType,
260 const string & fileName,
261 const string & driverFieldName)
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());
266 int FIELD_::addDriver (GENDRIVER & driver)
268 MESSAGE("int FIELD_::addDriver(GENDRIVER & driver) : driver " << driver);
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 ) {};
279 // void FIELD_::setValueType(med_type_champ ValueType) {};
280 // med_type_champ FIELD_::getValueType() {};