2 #include "MEDMEM_Field.hxx"
3 using namespace MEDMEM;
5 // ---------------------------------
6 // FIELD_ : Constructors
7 // ---------------------------------
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)
18 MESSAGE("Constructeur FIELD_ sans parametre");
21 FIELD_::FIELD_(const SUPPORT * Support, const int NumberOfComponents):
23 _name(""), _description(""), _support(Support),
24 _numberOfComponents(NumberOfComponents),
25 _iterationNumber(-1),_time(0.0),_orderNumber(-1)
27 MESSAGE("FIELD_(const SUPPORT * Support, const int NumberOfComponents)");
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 ;
40 FIELD_::FIELD_(const FIELD_ &m)
44 _description = m._description;
45 _support = m._support;
46 _numberOfComponents = m._numberOfComponents;
47 _numberOfValues = m._numberOfValues;
49 if (m._componentsTypes != NULL)
51 _componentsTypes = new int[m._numberOfComponents] ;
52 memcpy(_componentsTypes,m._componentsTypes,sizeof(int)*m._numberOfComponents);
54 _componentsTypes = new int[m._numberOfComponents] ;
55 for(int i=0;i<m._numberOfComponents;i++) {
56 _componentsTypes[i] = m._componentsTypes[i] ;
60 else _componentsTypes = (int *) NULL;
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;
77 _orderNumber = m._orderNumber;
78 _valueType = m._valueType;
79 //_drivers = m._drivers ; // PG : Well, same driver, what about m destructor !
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 ;
98 // vector<GENDRIVER *>::const_iterator it ;
99 // SCRUTE(_drivers.size());
101 // for (it=_drivers.begin();it!=_drivers.end();it++) {
107 MESSAGE("In this object FIELD_ there is(are) " << _drivers.size() << " driver(s)");
109 for (unsigned int index=0; index < _drivers.size(); index++ )
111 SCRUTE(_drivers[index]);
112 if ( _drivers[index] != NULL) delete _drivers[index];
118 PROVISOIRE : retourne des volumes, surfaces ou longueurs suivant les cas
121 FIELD<double>* FIELD_::_getFieldSize() const
123 FIELD<double>* p_field_size;
124 switch (getSupport()->getEntity())
127 switch (getSupport()->getMesh()->getSpaceDimension() )
130 p_field_size=getSupport()->getMesh()->getLength(getSupport() );
133 p_field_size=getSupport()->getMesh()->getArea(getSupport() );
136 p_field_size=getSupport()->getMesh()->getVolume(getSupport() );
142 p_field_size=getSupport()->getMesh()->getArea(getSupport() );
146 p_field_size=getSupport()->getMesh()->getLength(getSupport() );
155 Check up the compatibility of field before computing sobolev norm
158 void FIELD_::_checkNormCompatibility(const FIELD<double>* support_volume) const throw (MEDEXCEPTION)
161 if( getSupport()->getEntity() == MED_NODE )
163 diagnosis="Cannot compute sobolev norm on a field "+getName()+
164 " : it has support on nodes!";
165 throw MEDEXCEPTION(diagnosis.c_str());
168 if (getNumberOfValues()*getNumberOfComponents()<= 0) // Size of array has to be strictly positive
170 diagnosis="Cannot compute the norm of "+getName()+
171 " : it size is non positive!";
172 throw MEDEXCEPTION(diagnosis.c_str());
175 const int* nbGauss=getSupport()->getNumberOfGaussPoint();
176 for (int i=0; i<getSupport()->getNumberOfTypes(); ++i)
179 diagnosis="Cannot compute Lnorm of "+getName()+
180 " : Gauss numbers greater than one are not yet implemented!";
181 throw MEDEXCEPTION(diagnosis.c_str());
184 if(support_volume) // if the user has supplied the volume
186 if(support_volume->getSupport()!=getSupport())
188 diagnosis="Cannot compute Lnorm of "+getName()+
189 " : the volume furnished has not the same support!";
190 throw MEDEXCEPTION(diagnosis.c_str());
192 if(support_volume->getNumberOfValues()!=getNumberOfValues())
194 diagnosis="Cannot compute Lnorm of "+getName()+
195 " : the volume furnished has not the same number of values!";
196 throw MEDEXCEPTION(diagnosis.c_str());
204 Check up the compatibility of fields before performing an arithmetic operation
207 void FIELD_::_checkFieldCompatibility(const FIELD_& m, const FIELD_& n ) throw (MEDEXCEPTION)
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!";
220 for(int i=0; i<m._numberOfComponents; i++)
222 // Not yet implemented
223 // if(m._componentsTypes[i] != n._componentsTypes[i])
225 // diagnosis+="Components don't have the same types!";
228 if(m._MEDComponentsUnits[i] != n._MEDComponentsUnits[i])
230 diagnosis+="Components don't have the same units!";
236 if(diagnosis.size()) // if fields are not compatible : complete diagnosis and throw exception
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());
243 if( m.getNumberOfValues()<=0 || m.getNumberOfComponents()<=0) // check up the size is strictly positive
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());
252 // void FIELD_::setIterationNumber (int IterationNumber) {};
253 // void FIELD_::setOrderNumber (int OrderNumber) {};
254 // void FIELD_::setFieldName (string& fieldName) {};
256 void FIELD_::rmDriver (int index)
258 MESSAGE("void FIELD_::rmDriver(int index) : removing the driver " << index);
260 int FIELD_::addDriver (driverTypes driverType,
261 const string & fileName,
262 const string & driverFieldName)
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());
267 int FIELD_::addDriver (GENDRIVER & driver)
269 MESSAGE("int FIELD_::addDriver(GENDRIVER & driver) : driver " << driver);
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 ) {};
280 // void FIELD_::setValueType(med_type_champ ValueType) {};
281 // med_type_champ FIELD_::getValueType() {};