Salome HOME
50% of work performed of porting tests.
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingFieldDouble.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingFieldDouble.hxx"
22 #include "MEDCouplingFieldTemplate.hxx"
23 #include "MEDCouplingUMesh.hxx"
24 #include "MEDCouplingTimeDiscretization.hxx"
25 #include "MEDCouplingFieldDiscretization.hxx"
26 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
27 #include "MEDCouplingNatureOfField.hxx"
28
29 #include "InterpKernelAutoPtr.hxx"
30
31 #include <sstream>
32 #include <limits>
33 #include <algorithm>
34 #include <functional>
35
36 using namespace ParaMEDMEM;
37
38
39 /*!
40  * Creates a new MEDCouplingFieldDouble, of given spatial type and time discretization.
41  * For more info, see \ref MEDCouplingFirstSteps3.
42  * \param [in] type - the type of spatial discretization of the created field, one of
43  *        (\ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
44  *         \ref ParaMEDMEM::ON_NODES "ON_NODES",
45  *         \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
46  *         \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
47  *         \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
48  * \param [in] td - the type of time discretization of the created field, one of
49  *        (\ref ParaMEDMEM::NO_TIME "NO_TIME", 
50  *         \ref ParaMEDMEM::ONE_TIME "ONE_TIME", 
51  *         \ref ParaMEDMEM::LINEAR_TIME "LINEAR_TIME", 
52  *         \ref ParaMEDMEM::CONST_ON_TIME_INTERVAL "CONST_ON_TIME_INTERVAL").
53  * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
54  *         caller is to delete this field using decrRef() as it is no more needed. 
55  */
56 MEDCouplingFieldDouble* MEDCouplingFieldDouble::New(TypeOfField type, TypeOfTimeDiscretization td)
57 {
58   return new MEDCouplingFieldDouble(type,td);
59 }
60
61 /*!
62  * Creates a new MEDCouplingFieldDouble, of a given time discretization and with a
63  * spatial type and supporting mesh copied from a given 
64  * \ref MEDCouplingFieldTemplatesPage "field template".
65  * For more info, see \ref MEDCouplingFirstSteps3.
66  * \warning This method does not deeply copy neither the mesh nor the spatial
67  * discretization. Only a shallow copy (reference) is done for the mesh and the spatial
68  * discretization!
69  * \param [in] ft - the \ref MEDCouplingFieldTemplatesPage "field template" defining
70  *        the spatial discretization and the supporting mesh.
71  * \param [in] td - the type of time discretization of the created field, one of
72  *        (\ref ParaMEDMEM::NO_TIME "NO_TIME", 
73  *         \ref ParaMEDMEM::ONE_TIME "ONE_TIME", 
74  *         \ref ParaMEDMEM::LINEAR_TIME "LINEAR_TIME", 
75  *         \ref ParaMEDMEM::CONST_ON_TIME_INTERVAL "CONST_ON_TIME_INTERVAL").
76  * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
77  *         caller is to delete this field using decrRef() as it is no more needed. 
78  */
79 MEDCouplingFieldDouble *MEDCouplingFieldDouble::New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td)
80 {
81   return new MEDCouplingFieldDouble(ft,td);
82 }
83
84 /*!
85  * Sets a time \a unit of \a this field. For more info, see \ref MEDCouplingFirstSteps3.
86  * \param [in] unit \a unit (string) in which time is measured.
87  */
88 void MEDCouplingFieldDouble::setTimeUnit(const std::string& unit)
89 {
90   _time_discr->setTimeUnit(unit);
91 }
92
93 /*!
94  * Returns a time unit of \a this field.
95  * \return a string describing units in which time is measured.
96  */
97 std::string MEDCouplingFieldDouble::getTimeUnit() const
98 {
99   return _time_discr->getTimeUnit();
100 }
101
102 /*!
103  * This method if possible the time information (time unit, time iteration, time unit and time value) with its support
104  * that is to say its mesh.
105  * 
106  * \throw  If \c this->_mesh is null an exception will be thrown. An exception will also be throw if the spatial discretization is
107  *         NO_TIME.
108  */
109 void MEDCouplingFieldDouble::synchronizeTimeWithSupport()
110 {
111   _time_discr->synchronizeTimeWith(_mesh);
112 }
113
114 /*!
115  * Returns a new MEDCouplingFieldDouble which is a copy of \a this one. The data
116  * of \a this field is copied either deep or shallow depending on \a recDeepCpy
117  * parameter. But the underlying mesh is always shallow copied.
118  * Data that can be copied either deeply or shallow are:
119  * - \ref MEDCouplingTemporalDisc "temporal discretization" data that holds array(s)
120  * of field values,
121  * - \ref MEDCouplingSpatialDisc "a spatial discretization".
122  * 
123  * \c clone(false) is rather dedicated for advanced users that want to limit the amount
124  * of memory. It allows the user to perform methods like operator+(), operator*()
125  * etc. with \a this and the returned field. If the user wants to duplicate deeply the
126  * underlying mesh he should call cloneWithMesh() method or deepCpy() instead. 
127  * \warning The underlying \b mesh of the returned field is **always the same**
128  *         (pointer) as \a this one **whatever the value** of \a recDeepCpy parameter.
129  *  \param [in] recDeepCpy - if \c true, the copy of the underlying data arrays is
130  *         deep, else all data arrays of \a this field are shared by the new field.
131  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
132  *         caller is to delete this field using decrRef() as it is no more needed.
133  * \sa cloneWithMesh()
134  */
135 MEDCouplingFieldDouble *MEDCouplingFieldDouble::clone(bool recDeepCpy) const
136 {
137   return new MEDCouplingFieldDouble(*this,recDeepCpy);
138 }
139
140 /*!
141  * Returns a new MEDCouplingFieldDouble which is a copy of \a this one. The data
142  * of \a this field is copied either deep or shallow depending on \a recDeepCpy
143  * parameter. But the underlying mesh is always deep copied.
144  * Data that can be copied either deeply or shallow are:
145  * - \ref MEDCouplingTemporalDisc "temporal discretization" data that holds array(s)
146  * of field values,
147  * - \ref MEDCouplingSpatialDisc "a spatial discretization".
148  * 
149  * This method behaves exactly like clone() except that here the underlying **mesh is
150  * always deeply duplicated**, whatever the value \a recDeepCpy parameter.
151  * The result of \c cloneWithMesh(true) is exactly the same as that of deepCpy().
152  * So the resulting field can not be used together with \a this one in the methods
153  * like operator+(), operator*() etc. To avoid deep copying the underlying mesh,
154  * the user can call clone().
155  *  \param [in] recDeepCpy - if \c true, the copy of the underlying data arrays is
156  *         deep, else all data arrays of \a this field are shared by the new field.
157  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
158  *         caller is to delete this field using decrRef() as it is no more needed.
159  * \sa clone()
160  */
161 MEDCouplingFieldDouble *MEDCouplingFieldDouble::cloneWithMesh(bool recDeepCpy) const
162 {
163   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(recDeepCpy);
164   if(_mesh)
165     {
166       MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mCpy=_mesh->deepCpy();
167       ret->setMesh(mCpy);
168     }
169   return ret.retn();
170 }
171
172 /*!
173  * Returns a new MEDCouplingFieldDouble which is a deep copy of \a this one **including
174  * the mesh**.
175  * The result of this method is exactly the same as that of \c cloneWithMesh(true).
176  * So the resulting field can not be used together with \a this one in the methods
177  * like operator+(), operator*() etc. To avoid deep copying the underlying mesh,
178  * the user can call clone().
179  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
180  *         caller is to delete this field using decrRef() as it is no more needed.
181  * \sa cloneWithMesh()
182  */
183 MEDCouplingFieldDouble *MEDCouplingFieldDouble::deepCpy() const
184 {
185   return cloneWithMesh(true);
186 }
187
188 /*!
189  * Creates a new MEDCouplingFieldDouble of given
190  * \ref MEDCouplingTemporalDisc "temporal discretization". The result field either
191  * shares the data array(s) with \a this field, or holds a deep copy of it, depending on
192  * \a deepCopy parameter. But the underlying \b mesh is always **shallow copied**.
193  * \param [in] td - the type of time discretization of the created field, one of
194  *        (\ref ParaMEDMEM::NO_TIME "NO_TIME", 
195  *         \ref ParaMEDMEM::ONE_TIME "ONE_TIME", 
196  *         \ref ParaMEDMEM::LINEAR_TIME "LINEAR_TIME", 
197  *         \ref ParaMEDMEM::CONST_ON_TIME_INTERVAL "CONST_ON_TIME_INTERVAL").
198  * \param [in] deepCopy - if \c true, the copy of the underlying data arrays is
199  *         deep, else all data arrays of \a this field are shared by the new field.
200  * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
201  *         caller is to delete this field using decrRef() as it is no more needed. 
202  * 
203  * \if ENABLE_EXAMPLES
204  * \ref cpp_mcfielddouble_buildNewTimeReprFromThis "Here is a C++ example."<br>
205  * \ref py_mcfielddouble_buildNewTimeReprFromThis "Here is a Python example."
206  * \endif
207  * \sa clone()
208  */
209 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const
210 {
211   MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(td,deepCopy);
212   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization> disc;
213   if(_type)
214     disc=_type->clone();
215   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),tdo,disc.retn());
216   ret->setMesh(getMesh());
217   ret->setName(getName());
218   ret->setDescription(getDescription());
219   return ret.retn();
220 }
221
222 /*!
223  * This method converts a field on nodes (\a this) to a cell field (returned field). The convertion is a \b non \b conservative remapping !
224  * This method is useful only for users that need a fast convertion from node to cell spatial discretization. The algorithm applied is simply to attach
225  * to each cell the average of values on nodes constituting this cell.
226  *
227  * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
228  *         caller is to delete this field using decrRef() as it is no more needed. The returned field will share the same mesh object object than those in \a this.
229  * \throw If \a this spatial discretization is empty or not ON_NODES.
230  * \throw If \a this is not coherent (see MEDCouplingFieldDouble::checkCoherency).
231  * 
232  * \warning This method is a \b non \b conservative method of remapping from node spatial discretization to cell spatial discretization.
233  * If a conservative method of interpolation is required ParaMEDMEM::MEDCouplingRemapper class should be used instead with "P1P0" method.
234  */
235 MEDCouplingFieldDouble *MEDCouplingFieldDouble::nodeToCellDiscretization() const
236 {
237   checkCoherency();
238   TypeOfField tf(getTypeOfField());
239   if(tf!=ON_NODES)
240     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::nodeToCellDiscretization : this field is expected to be on ON_NODES !");
241   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret(clone(false));
242   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretizationP0> nsp(new MEDCouplingFieldDiscretizationP0);
243   ret->setDiscretization(nsp);
244   const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkCoherency call
245   int nbCells(m->getNumberOfCells());
246   std::vector<DataArrayDouble *> arrs(getArrays());
247   std::size_t sz(arrs.size());
248   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > outArrsSafe(sz); std::vector<DataArrayDouble *> outArrs(sz);
249   for(std::size_t j=0;j<sz;j++)
250     {
251       int nbCompo(arrs[j]->getNumberOfComponents());
252       outArrsSafe[j]=DataArrayDouble::New(); outArrsSafe[j]->alloc(nbCells,nbCompo);
253       outArrsSafe[j]->copyStringInfoFrom(*arrs[j]);
254       outArrs[j]=outArrsSafe[j];
255       double *pt(outArrsSafe[j]->getPointer());
256       const double *srcPt(arrs[j]->begin());
257       for(int i=0;i<nbCells;i++,pt+=nbCompo)
258         {
259           std::vector<int> nodeIds;
260           m->getNodeIdsOfCell(i,nodeIds);
261           std::fill(pt,pt+nbCompo,0.);
262           std::size_t nbNodesInCell(nodeIds.size());
263           for(std::size_t k=0;k<nbNodesInCell;k++)
264             std::transform(srcPt+nodeIds[k]*nbCompo,srcPt+(nodeIds[k]+1)*nbCompo,pt,pt,std::plus<double>());
265           if(nbNodesInCell!=0)
266             std::transform(pt,pt+nbCompo,pt,std::bind2nd(std::multiplies<double>(),1./((double)nbNodesInCell)));
267           else
268             {
269               std::ostringstream oss; oss << "MEDCouplingFieldDouble::nodeToCellDiscretization : Cell id #" << i << " has been detected to have no nodes !";
270               throw INTERP_KERNEL::Exception(oss.str().c_str());
271             }
272         }
273     }
274   ret->setArrays(outArrs);
275   return ret.retn();
276 }
277
278 /*!
279  * This method converts a field on cell (\a this) to a node field (returned field). The convertion is a \b non \b conservative remapping !
280  * This method is useful only for users that need a fast convertion from cell to node spatial discretization. The algorithm applied is simply to attach
281  * to each node the average of values on cell sharing this node. If \a this lies on a mesh having orphan nodes the values applied on them will be NaN (division by 0.).
282  *
283  * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
284  *         caller is to delete this field using decrRef() as it is no more needed. The returned field will share the same mesh object object than those in \a this.
285  * \throw If \a this spatial discretization is empty or not ON_CELLS.
286  * \throw If \a this is not coherent (see MEDCouplingFieldDouble::checkCoherency).
287  *
288  * \warning This method is a \b non \b conservative method of remapping from cell spatial discretization to node spatial discretization.
289  * If a conservative method of interpolation is required ParaMEDMEM::MEDCouplingRemapper class should be used instead with "P0P1" method.
290  */
291 MEDCouplingFieldDouble *MEDCouplingFieldDouble::cellToNodeDiscretization() const
292 {
293   checkCoherency();
294   TypeOfField tf(getTypeOfField());
295   if(tf!=ON_CELLS)
296     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::cellToNodeDiscretization : this field is expected to be on ON_CELLS !");
297   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret(clone(false));
298   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretizationP1> nsp(new MEDCouplingFieldDiscretizationP1);
299   ret->setDiscretization(nsp);
300   const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkCoherency call
301   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rn(DataArrayInt::New()),rni(DataArrayInt::New());
302   m->getReverseNodalConnectivity(rn,rni);
303   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rni2(rni->deltaShiftIndex());
304   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> rni3(rni2->convertToDblArr()); rni2=0;
305   std::vector<DataArrayDouble *> arrs(getArrays());
306   std::size_t sz(arrs.size());
307   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > outArrsSafe(sz); std::vector<DataArrayDouble *> outArrs(sz);
308   for(std::size_t j=0;j<sz;j++)
309     {
310       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(arrs[j]->selectByTupleIdSafe(rn->begin(),rn->end()));
311       outArrsSafe[j]=(tmp->accumulatePerChunck(rni->begin(),rni->end())); tmp=0;
312       outArrsSafe[j]->divideEqual(rni3);
313       outArrsSafe[j]->copyStringInfoFrom(*arrs[j]);
314       outArrs[j]=outArrsSafe[j];
315     }
316   ret->setArrays(outArrs);
317   return ret.retn();
318 }
319
320 /*!
321  * Copies tiny info (component names, name and description) from an \a other field to
322  * \a this one.
323  * \warning The underlying mesh is not renamed (for safety reason).
324  *  \param [in] other - the field to copy the tiny info from.
325  *  \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
326  */
327 void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingField *other)
328 {
329   MEDCouplingField::copyTinyStringsFrom(other);
330   const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
331   if(otherC)
332     {
333       _time_discr->copyTinyStringsFrom(*otherC->_time_discr);
334     }
335 }
336
337 /*!
338  * Copies only times, order and iteration from an \a other field to
339  * \a this one. The underlying mesh is not impacted by this method.
340  * Arrays are not impacted neither.
341  *  \param [in] other - the field to tiny attributes from.
342  *  \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
343  */
344 void MEDCouplingFieldDouble::copyTinyAttrFrom(const MEDCouplingFieldDouble *other)
345 {
346   if(other)
347     {
348       _time_discr->copyTinyAttrFrom(*other->_time_discr);
349     }
350 }
351
352 void MEDCouplingFieldDouble::copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other)
353 {
354   copyTinyStringsFrom(other);
355   copyTinyAttrFrom(other);
356 }
357
358 /*!
359  * Returns a string describing \a this field. This string is outputted by \c print
360  * Python command. The string includes info on
361  * - name,
362  * - description,
363  * - \ref MEDCouplingSpatialDisc "spatial discretization",
364  * - \ref MEDCouplingTemporalDisc "time discretization",
365  * - \ref NatureOfField,
366  * - components,
367  * - mesh.
368  *
369  *  \return std::string - the string describing \a this field.
370  */
371 std::string MEDCouplingFieldDouble::simpleRepr() const
372 {
373   std::ostringstream ret;
374   ret << "FieldDouble with name : \"" << getName() << "\"\n";
375   ret << "Description of field is : \"" << getDescription() << "\"\n";
376   if(_type)
377     { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; }
378   else
379     { ret << "FieldDouble has no spatial discretization !\n"; }
380   if(_time_discr)
381     { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; }
382   else
383     { ret << "FieldDouble has no time discretization !\n"; }
384   ret << "FieldDouble nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
385   if(getArray())
386     {
387       if(getArray()->isAllocated())
388         {
389           int nbOfCompo=getArray()->getNumberOfComponents();
390           ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
391           ret << "FieldDouble default array has following info on components : ";
392           for(int i=0;i<nbOfCompo;i++)
393             ret << "\"" << getArray()->getInfoOnComponent(i) << "\" ";
394           ret << "\n";
395         }
396       else
397         {
398           ret << "Array set but not allocated !\n";
399         }
400     }
401   if(_mesh)
402     ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
403   else
404     ret << "Mesh support information : No mesh set !\n";
405   return ret.str();
406 }
407
408 /*!
409  * Returns a string describing \a this field. The string includes info on
410  * - name,
411  * - description,
412  * - \ref MEDCouplingSpatialDisc "spatial discretization",
413  * - \ref MEDCouplingTemporalDisc "time discretization",
414  * - components,
415  * - mesh,
416  * - contents of data arrays.
417  *
418  *  \return std::string - the string describing \a this field.
419  */
420 std::string MEDCouplingFieldDouble::advancedRepr() const
421 {
422   std::ostringstream ret;
423   ret << "FieldDouble with name : \"" << getName() << "\"\n";
424   ret << "Description of field is : \"" << getDescription() << "\"\n";
425   if(_type)
426     { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; }
427   else
428     { ret << "FieldDouble has no space discretization set !\n"; }
429   if(_time_discr)
430     { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; }
431   else
432     { ret << "FieldDouble has no time discretization set !\n"; }
433   if(getArray())
434     ret << "FieldDouble default array has " << getArray()->getNumberOfComponents() << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
435   if(_mesh)
436     ret << "Mesh support information :\n__________________________\n" << _mesh->advancedRepr();
437   else
438     ret << "Mesh support information : No mesh set !\n";
439   std::vector<DataArrayDouble *> arrays;
440   _time_discr->getArrays(arrays);
441   int arrayId=0;
442   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,arrayId++)
443     {
444       ret << "Array #" << arrayId << " :\n__________\n";
445       if(*iter)
446         (*iter)->reprWithoutNameStream(ret);
447       else
448         ret << "Array empty !";
449       ret << "\n";
450     }
451   return ret.str();
452 }
453
454 void MEDCouplingFieldDouble::writeVTK(const std::string& fileName, bool isBinary) const
455 {
456   std::vector<const MEDCouplingFieldDouble *> fs(1,this);
457   MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary);
458 }
459
460 bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const
461 {
462   if(!other)
463     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::isEqualIfNotWhy : other instance is NULL !");
464   const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
465   if(!otherC)
466     {
467       reason="field given in input is not castable in MEDCouplingFieldDouble !";
468       return false;
469     }
470   if(!MEDCouplingField::isEqualIfNotWhy(other,meshPrec,valsPrec,reason))
471     return false;
472   if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,valsPrec,reason))
473     {
474       reason.insert(0,"In FieldDouble time discretizations differ :");
475       return false;
476     }
477   return true;
478 }
479
480 /*!
481  * Checks equality of \a this and \a other field. Only numeric data is considered,
482  * i.e. names, description etc are not compared.
483  *  \param [in] other - the field to compare with.
484  *  \param [in] meshPrec - a precision used to compare node coordinates of meshes.
485  *  \param [in] valsPrec - a precision used to compare data arrays of the two fields.
486  *  \return bool - \c true if the two fields are equal, \c false else.
487  *  \throw If \a other == NULL.
488  *  \throw If the spatial discretization of \a this field is NULL.
489  */
490 bool MEDCouplingFieldDouble::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
491 {
492   const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
493   if(!otherC)
494     return false;
495   if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec))
496     return false;
497   if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,valsPrec))
498     return false;
499   return true;
500 }
501
502 /*!
503  * This method states if \a this and 'other' are compatibles each other before performing any treatment.
504  * This method is good for methods like : mergeFields.
505  * This method is not very demanding compared to areStrictlyCompatible that is better for operation on fields.
506  */
507 bool MEDCouplingFieldDouble::areCompatibleForMerge(const MEDCouplingField *other) const
508 {
509   if(!MEDCouplingField::areCompatibleForMerge(other))
510     return false;
511   const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
512   if(!otherC)
513     return false;
514   if(!_time_discr->areCompatible(otherC->_time_discr))
515     return false;
516   return true;
517 }
518
519 /*!
520  * This method is more strict than MEDCouplingField::areCompatibleForMerge method.
521  * This method is used for operation on fields to operate a first check before attempting operation.
522  */
523 bool MEDCouplingFieldDouble::areStrictlyCompatible(const MEDCouplingField *other) const
524 {
525   std::string tmp;
526   if(!MEDCouplingField::areStrictlyCompatible(other))
527     return false;
528   const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
529   if(!otherC)
530     return false;
531   if(!_time_discr->areStrictlyCompatible(otherC->_time_discr,tmp))
532     return false;
533   return true;
534 }
535
536 /*!
537  * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatible method except that
538  * number of components between \a this and 'other' can be different here (for operator*).
539  */
540 bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other) const
541 {
542   if(!MEDCouplingField::areStrictlyCompatible(other))
543     return false;
544   const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
545   if(!otherC)
546     return false;
547   if(!_time_discr->areStrictlyCompatibleForMul(otherC->_time_discr))
548     return false;
549   return true;
550 }
551
552 /*!
553  * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatible method except that
554  * number of components between \a this and 'other' can be different here (for operator/).
555  */
556 bool MEDCouplingFieldDouble::areCompatibleForDiv(const MEDCouplingField *other) const
557 {
558   if(!MEDCouplingField::areStrictlyCompatible(other))
559     return false;
560   const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
561   if(!otherC)
562     return false;
563   if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr))
564     return false;
565   return true;
566 }
567
568 /*!
569  * This method is invocated before any attempt of melding. This method is very close to areStrictlyCompatible,
570  * except that \a this and other can have different number of components.
571  */
572 bool MEDCouplingFieldDouble::areCompatibleForMeld(const MEDCouplingFieldDouble *other) const
573 {
574   if(!MEDCouplingField::areStrictlyCompatible(other))
575     return false;
576   if(!_time_discr->areCompatibleForMeld(other->_time_discr))
577     return false;
578   return true;
579 }
580
581 /*!
582  * Permutes values of \a this field according to a given permutation array for cells
583  * renumbering. The underlying mesh is deeply copied and its cells are also permuted. 
584  * The number of cells remains the same; for that the permutation array \a old2NewBg
585  * should not contain equal ids.
586  * ** Warning, this method modifies the mesh aggreagated by \a this (by performing a deep copy ) **.
587  *
588  *  \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
589  *         to be equal to \a this->getMesh()->getNumberOfCells().
590  *  \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
591  *         array, so that its maximal cell id to correspond to (be less than) the number
592  *         of cells in mesh. This new array is then used for the renumbering. If \a 
593  *         check == \c false, \a old2NewBg is used as is, that is less secure as validity 
594  *         of ids in \a old2NewBg is not checked.
595  *  \throw If the mesh is not set.
596  *  \throw If the spatial discretization of \a this field is NULL.
597  *  \throw If \a check == \c true and \a old2NewBg contains equal ids.
598  *  \throw If mesh nature does not allow renumbering (e.g. structured mesh).
599  * 
600  *  \if ENABLE_EXAMPLES
601  *  \ref cpp_mcfielddouble_renumberCells "Here is a C++ example".<br>
602  *  \ref  py_mcfielddouble_renumberCells "Here is a Python example".
603  *  \endif
604  */
605 void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check)
606 {
607   renumberCellsWithoutMesh(old2NewBg,check);
608   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_mesh->deepCpy();
609   m->renumberCells(old2NewBg,check);
610   setMesh(m);
611   updateTime();
612 }
613
614 /*!
615  * Permutes values of \a this field according to a given permutation array for cells
616  * renumbering. The underlying mesh is \b not permuted. 
617  * The number of cells remains the same; for that the permutation array \a old2NewBg
618  * should not contain equal ids.
619  * This method performs a part of job of renumberCells(). The reasonable use of this
620  * method is only for multi-field instances lying on the same mesh to avoid a
621  * systematic duplication and renumbering of _mesh attribute. 
622  * \warning Use this method with a lot of care!
623  *  \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
624  *         to be equal to \a this->getMesh()->getNumberOfCells().
625  *  \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
626  *         array, so that its maximal cell id to correspond to (be less than) the number
627  *         of cells in mesh. This new array is then used for the renumbering. If \a 
628  *         check == \c false, \a old2NewBg is used as is, that is less secure as validity 
629  *         of ids in \a old2NewBg is not checked.
630  *  \throw If the mesh is not set.
631  *  \throw If the spatial discretization of \a this field is NULL.
632  *  \throw If \a check == \c true and \a old2NewBg contains equal ids.
633  *  \throw If mesh nature does not allow renumbering (e.g. structured mesh).
634  */
635 void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool check)
636 {
637   if(!_mesh)
638     throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !");
639   if(!((const MEDCouplingFieldDiscretization *)_type))
640     throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
641   //
642   _type->renumberCells(old2NewBg,check);
643   std::vector<DataArrayDouble *> arrays;
644   _time_discr->getArrays(arrays);
645   std::vector<DataArray *> arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin());
646   _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check);
647   //
648   updateTime();
649 }
650
651 /*!
652  * Permutes values of \a this field according to a given permutation array for node
653  * renumbering. The underlying mesh is deeply copied and its nodes are also permuted. 
654  * The number of nodes can change, contrary to renumberCells().
655  *  \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
656  *         to be equal to \a this->getMesh()->getNumberOfNodes().
657  *  \param [in] eps - a precision used to compare field values at merged nodes. If
658  *         the values differ more than \a eps, an exception is thrown.
659  *  \throw If the mesh is not set.
660  *  \throw If the spatial discretization of \a this field is NULL.
661  *  \throw If \a check == \c true and \a old2NewBg contains equal ids.
662  *  \throw If mesh nature does not allow renumbering (e.g. structured mesh).
663  *  \throw If values at merged nodes deffer more than \a eps.
664  * 
665  *  \if ENABLE_EXAMPLES
666  *  \ref cpp_mcfielddouble_renumberNodes "Here is a C++ example".<br>
667  *  \ref  py_mcfielddouble_renumberNodes "Here is a Python example".
668  *  \endif
669  */
670 void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg, double eps)
671 {
672   const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
673   if(!meshC)
674     throw INTERP_KERNEL::Exception("Invalid mesh to apply renumberNodes on it !");
675   int nbOfNodes=meshC->getNumberOfNodes();
676   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
677   int newNbOfNodes=*std::max_element(old2NewBg,old2NewBg+nbOfNodes)+1;
678   renumberNodesWithoutMesh(old2NewBg,newNbOfNodes,eps);
679   meshC2->renumberNodes(old2NewBg,newNbOfNodes);
680   setMesh(meshC2);
681 }
682
683 /*!
684  * Permutes values of \a this field according to a given permutation array for nodes
685  * renumbering. The underlying mesh is \b not permuted. 
686  * The number of nodes can change, contrary to renumberCells().
687  * A given epsilon specifies a threshold of error in case of two nodes are merged but
688  * the difference of values on these nodes are higher than \a eps.
689  * This method performs a part of job of renumberNodes(), excluding node renumbering
690  * in mesh. The reasonable use of this
691  * method is only for multi-field instances lying on the same mesh to avoid a
692  * systematic duplication and renumbering of _mesh attribute. 
693  * \warning Use this method with a lot of care!
694  * \warning In case of an exception thrown, the contents of the data array can be
695  *         partially modified until the exception occurs. 
696  *  \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
697  *         to be equal to \a this->getMesh()->getNumberOfNodes().
698  *  \param [in] newNbOfNodes - a number of nodes in the mesh after renumbering.
699  *  \param [in] eps - a precision used to compare field values at merged nodes. If
700  *         the values differ more than \a eps, an exception is thrown.
701  *  \throw If the mesh is not set.
702  *  \throw If the spatial discretization of \a this field is NULL.
703  *  \throw If values at merged nodes deffer more than \a eps.
704  */
705 void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps)
706 {
707   if(!((const MEDCouplingFieldDiscretization *)_type))
708     throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
709   std::vector<DataArrayDouble *> arrays;
710   _time_discr->getArrays(arrays);
711   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
712     if(*iter)
713       _type->renumberValuesOnNodes(eps,old2NewBg,newNbOfNodes,*iter);
714 }
715
716 /*!
717  * Returns all tuple ids of \a this scalar field that fit the range [\a vmin,
718  * \a vmax]. This method calls DataArrayDouble::getIdsInRange().
719  *  \param [in] vmin - a lower boundary of the range. Tuples with values less than \a
720  *         vmin are not included in the result array.
721  *  \param [in] vmax - an upper boundary of the range. Tuples with values more than \a
722  *         vmax are not included in the result array.
723  *  \return DataArrayInt * - a new instance of DataArrayInt holding ids of selected
724  *          tuples. The caller is to delete this array using decrRef() as it is no
725  *          more needed.
726  *  \throw If the data array is not set.
727  *  \throw If \a this->getNumberOfComponents() != 1.
728  */
729 DataArrayInt *MEDCouplingFieldDouble::getIdsInRange(double vmin, double vmax) const
730 {
731   if(getArray()==0)
732     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getIdsInRange : no default array set !");
733   return getArray()->getIdsInRange(vmin,vmax);
734 }
735
736 /*!
737  * Builds a newly created field, that the caller will have the responsability to deal with (decrRef()).
738  * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done.
739  * This method returns a restriction of \a this so that only tuples with ids specified in \a part will be contained in the returned field.
740  * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (
741  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
742  * \ref ParaMEDMEM::ON_NODES "ON_NODES",
743  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
744  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
745  * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
746  *
747  * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a part contains following cell ids [3,7,6].
748  * Then the returned field will lie on mesh having 3 cells and the returned field will contain 3 tuples.<br>
749  * Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().<br>
750  * Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().<br>
751  * Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
752  *
753  * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a part contains following cellIds [3,7,6].
754  * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
755  * will contain 6 tuples and \a this field will lie on this restricted mesh. 
756  *
757  *  \param [in] part - an array of cell ids to include to the result field.
758  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The caller is to delete this field using decrRef() as it is no more needed.
759  *
760  *  \if ENABLE_EXAMPLES
761  *  \ref cpp_mcfielddouble_subpart1 "Here is a C++ example".<br>
762  *  \ref  py_mcfielddouble_subpart1 "Here is a Python example".
763  *  \endif
764  *  \sa MEDCouplingFieldDouble::buildSubPartRange
765  */
766
767 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *part) const
768 {
769   if(part==0)
770     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : not empty array must be passed to this method !");
771   return buildSubPart(part->begin(),part->end());
772 }
773
774 /*!
775  * Builds a newly created field, that the caller will have the responsability to deal with.
776  * \n This method makes the assumption that \a this field is correctly defined when this method is called (\a this->checkCoherency() returns without any exception thrown), **no check of this will be done**.
777  * \n This method returns a restriction of \a this so that only tuple ids specified in [ \a partBg , \a partEnd ) will be contained in the returned field.
778  * \n Parameter [\a partBg, \a partEnd ) specifies **cell ids whatever the spatial discretization** of \a this (
779  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
780  * \ref ParaMEDMEM::ON_NODES "ON_NODES",
781  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
782  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
783  * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
784  *
785  * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a partBg contains the following cell ids [3,7,6].
786  * Then the returned field will lie on mesh having 3 cells and will contain 3 tuples.
787  *- Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().
788  *- Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().
789  *- Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
790  *
791  * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a partBg contains following cellIds [3,7,6].
792  * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
793  * will contain 6 tuples and \a this field will lie on this restricted mesh. 
794  *
795  * \param [in] partBg - start (included) of input range of cell ids to select [ \a partBg, \a partEnd )
796  * \param [in] partEnd - end (not included) of input range of cell ids to select [ \a partBg, \a partEnd )
797  * \return a newly allocated field the caller should deal with.
798  * 
799  * \throw if there is presence of an invalid cell id in [ \a partBg, \a partEnd ) regarding the number of cells of \a this->getMesh().
800  *
801  * \if ENABLE_EXAMPLES
802  * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."<br>
803  * \ref py_mcfielddouble_subpart1 "Here a Python example."
804  * \endif
805  * \sa ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
806  */
807 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const
808 {
809   if(!((const MEDCouplingFieldDiscretization *)_type))
810     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
811   DataArrayInt *arrSelect;
812   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
813   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arrSelect2(arrSelect);
814   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
815   const MEDCouplingFieldDiscretization *disc=getDiscretization();
816   if(disc)
817     ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization>(disc->clonePart(partBg,partEnd)));
818   ret->setMesh(m);
819   std::vector<DataArrayDouble *> arrays;
820   _time_discr->getArrays(arrays);
821   std::vector<DataArrayDouble *> arrs;
822   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrsSafe;
823   const int *arrSelBg=arrSelect->begin();
824   const int *arrSelEnd=arrSelect->end();
825   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
826     {
827       DataArrayDouble *arr=0;
828       if(*iter)
829         arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
830       arrs.push_back(arr); arrsSafe.push_back(arr);
831     }
832   ret->_time_discr->setArrays(arrs,0);
833   return ret.retn();
834 }
835
836 /*!
837  * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is
838  * given using a range given \a begin, \a end and \a step to optimize the part computation.
839  * 
840  * \sa MEDCouplingFieldDouble::buildSubPart
841  */
842 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int end, int step) const
843 {
844   if(!((const MEDCouplingFieldDiscretization *)_type))
845     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
846   DataArrayInt *arrSelect;
847   int beginOut,endOut,stepOut;
848   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect);
849   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arrSelect2(arrSelect);
850   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
851   const MEDCouplingFieldDiscretization *disc=getDiscretization();
852   if(disc)
853     ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization>(disc->clonePartRange(begin,end,step)));
854   ret->setMesh(m);
855   std::vector<DataArrayDouble *> arrays;
856   _time_discr->getArrays(arrays);
857   std::vector<DataArrayDouble *> arrs;
858   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrsSafe;
859   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
860     {
861       DataArrayDouble *arr=0;
862       if(*iter)
863         {
864           if(arrSelect)
865             {
866               const int *arrSelBg=arrSelect->begin();
867               const int *arrSelEnd=arrSelect->end();
868               arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
869             }
870           else
871             arr=(*iter)->selectByTupleId2(beginOut,endOut,stepOut);
872         }
873       arrs.push_back(arr); arrsSafe.push_back(arr);
874     }
875   ret->_time_discr->setArrays(arrs,0);
876   return ret.retn();
877 }
878
879 /*!
880  * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field.
881  *  \return ParaMEDMEM::TypeOfTimeDiscretization - an enum item describing the time
882  *          discretization type.
883  */
884 TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const
885 {
886   return _time_discr->getEnum();
887 }
888
889 MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),
890     _time_discr(MEDCouplingTimeDiscretization::New(td))
891 {
892 }
893
894 /*!
895  * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! **
896  */
897 MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false),
898     _time_discr(MEDCouplingTimeDiscretization::New(td))
899 {
900 }
901
902 MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingField(other,deepCopy),
903     _time_discr(other._time_discr->performCpy(deepCopy))
904 {
905 }
906
907 MEDCouplingFieldDouble::MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td)
908 {
909 }
910
911 MEDCouplingFieldDouble::~MEDCouplingFieldDouble()
912 {
913   delete _time_discr;
914 }
915
916 /*!
917  * Checks if \a this field is correctly defined, else an exception is thrown.
918  *  \throw If the mesh is not set.
919  *  \throw If the data array is not set.
920  *  \throw If the spatial discretization of \a this field is NULL.
921  *  \throw If \a this->getTimeTolerance() < 0.
922  *  \throw If the temporal discretization data is incorrect.
923  *  \throw If mesh data does not correspond to field data.
924  */
925 void MEDCouplingFieldDouble::checkCoherency() const
926 {
927   if(!_mesh)
928     throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !");
929   if(!((const MEDCouplingFieldDiscretization *)_type))
930     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::checkCoherency : no spatial discretization !");
931   _time_discr->checkCoherency();
932   _type->checkCoherencyBetween(_mesh,getArray());
933 }
934
935 /*!
936  * Accumulate values of a given component of \a this field.
937  *  \param [in] compId - the index of the component of interest.
938  *  \return double - a sum value of *compId*-th component.
939  *  \throw If the data array is not set.
940  *  \throw If \a the condition ( 0 <= \a compId < \a this->getNumberOfComponents() ) is
941  *         not respected.
942  */
943 double MEDCouplingFieldDouble::accumulate(int compId) const
944 {
945   if(getArray()==0)
946     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
947   return getArray()->accumulate(compId);
948 }
949
950 /*!
951  * Accumulates values of each component of \a this array.
952  *  \param [out] res - an array of length \a this->getNumberOfComponents(), allocated 
953  *         by the caller, that is filled by this method with sum value for each
954  *         component.
955  *  \throw If the data array is not set.
956  */
957 void MEDCouplingFieldDouble::accumulate(double *res) const
958 {
959   if(getArray()==0)
960     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
961   getArray()->accumulate(res);
962 }
963
964 /*!
965  * Returns the maximal value within \a this scalar field. Values of all arrays stored
966  * in \a this->_time_discr are checked.
967  *  \return double - the maximal value among all values of \a this field.
968  *  \throw If \a this->getNumberOfComponents() != 1
969  *  \throw If the data array is not set.
970  *  \throw If there is an empty data array in \a this field.
971  */
972 double MEDCouplingFieldDouble::getMaxValue() const
973 {
974   std::vector<DataArrayDouble *> arrays;
975   _time_discr->getArrays(arrays);
976   double ret=-std::numeric_limits<double>::max();
977   bool isExistingArr=false;
978   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
979     {
980       if(*iter)
981         {
982           isExistingArr=true;
983           int loc;
984           ret=std::max(ret,(*iter)->getMaxValue(loc));
985         }
986     }
987   if(!isExistingArr)
988     throw INTERP_KERNEL::Exception("getMaxValue : No arrays defined !");
989   return ret;
990 }
991
992 /*!
993  * Returns the maximal value and all its locations within \a this scalar field.
994  * Only the first of available data arrays is checked.
995  *  \param [out] tupleIds - a new instance of DataArrayInt containg indices of
996  *               tuples holding the maximal value. The caller is to delete it using
997  *               decrRef() as it is no more needed.
998  *  \return double - the maximal value among all values of the first array of \a this filed.
999  *  \throw If \a this->getNumberOfComponents() != 1.
1000  *  \throw If there is an empty data array in \a this field.
1001  */
1002 double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const
1003 {
1004   std::vector<DataArrayDouble *> arrays;
1005   _time_discr->getArrays(arrays);
1006   double ret=-std::numeric_limits<double>::max();
1007   bool isExistingArr=false;
1008   tupleIds=0;
1009   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1;
1010   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
1011     {
1012       if(*iter)
1013         {
1014           isExistingArr=true;
1015           DataArrayInt *tmp;
1016           ret=std::max(ret,(*iter)->getMaxValue2(tmp));
1017           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmpSafe(tmp);
1018           if(!((const DataArrayInt *)ret1))
1019             ret1=tmpSafe;
1020         }
1021     }
1022   if(!isExistingArr)
1023     throw INTERP_KERNEL::Exception("getMaxValue2 : No arrays defined !");
1024   tupleIds=ret1.retn();
1025   return ret;
1026 }
1027
1028 /*!
1029  * Returns the minimal value within \a this scalar field. Values of all arrays stored
1030  * in \a this->_time_discr are checked.
1031  *  \return double - the minimal value among all values of \a this field.
1032  *  \throw If \a this->getNumberOfComponents() != 1
1033  *  \throw If the data array is not set.
1034  *  \throw If there is an empty data array in \a this field.
1035  */
1036 double MEDCouplingFieldDouble::getMinValue() const
1037 {
1038   std::vector<DataArrayDouble *> arrays;
1039   _time_discr->getArrays(arrays);
1040   double ret=std::numeric_limits<double>::max();
1041   bool isExistingArr=false;
1042   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
1043     {
1044       if(*iter)
1045         {
1046           isExistingArr=true;
1047           int loc;
1048           ret=std::min(ret,(*iter)->getMinValue(loc));
1049         }
1050     }
1051   if(!isExistingArr)
1052     throw INTERP_KERNEL::Exception("getMinValue : No arrays defined !");
1053   return ret;
1054 }
1055
1056 /*!
1057  * Returns the minimal value and all its locations within \a this scalar field.
1058  * Only the first of available data arrays is checked.
1059  *  \param [out] tupleIds - a new instance of DataArrayInt containg indices of
1060  *               tuples holding the minimal value. The caller is to delete it using
1061  *               decrRef() as it is no more needed.
1062  *  \return double - the minimal value among all values of the first array of \a this filed.
1063  *  \throw If \a this->getNumberOfComponents() != 1.
1064  *  \throw If there is an empty data array in \a this field.
1065  */
1066 double MEDCouplingFieldDouble::getMinValue2(DataArrayInt*& tupleIds) const
1067 {
1068   std::vector<DataArrayDouble *> arrays;
1069   _time_discr->getArrays(arrays);
1070   double ret=-std::numeric_limits<double>::max();
1071   bool isExistingArr=false;
1072   tupleIds=0;
1073   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1;
1074   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
1075     {
1076       if(*iter)
1077         {
1078           isExistingArr=true;
1079           DataArrayInt *tmp;
1080           ret=std::max(ret,(*iter)->getMinValue2(tmp));
1081           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmpSafe(tmp);
1082           if(!((const DataArrayInt *)ret1))
1083             ret1=tmpSafe;
1084         }
1085     }
1086   if(!isExistingArr)
1087     throw INTERP_KERNEL::Exception("getMinValue2 : No arrays defined !");
1088   tupleIds=ret1.retn();
1089   return ret;
1090 }
1091
1092 /*!
1093  * Returns the average value of \a this scalar field.
1094  *  \return double - the average value over all values of the data array.
1095  *  \throw If \a this->getNumberOfComponents() != 1
1096  *  \throw If the data array is not set or it is empty.
1097  */
1098 double MEDCouplingFieldDouble::getAverageValue() const
1099 {
1100   if(getArray()==0)
1101     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getAverageValue : no default array defined !");
1102   return getArray()->getAverageValue();
1103 }
1104
1105 /*!
1106  * This method returns the euclidean norm of \a this field.
1107  * \f[
1108  * \sqrt{\sum_{0 \leq i < nbOfEntity}val[i]*val[i]}
1109  * \f]
1110  *  \throw If the data array is not set.
1111  */
1112 double MEDCouplingFieldDouble::norm2() const
1113 {
1114   if(getArray()==0)
1115     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::norm2 : no default array defined !");
1116   return getArray()->norm2();
1117 }
1118
1119 /*!
1120  * This method returns the max norm of \a this field.
1121  * \f[
1122  * \max_{0 \leq i < nbOfEntity}{abs(val[i])}
1123  * \f]
1124  *  \throw If the data array is not set.
1125  */
1126 double MEDCouplingFieldDouble::normMax() const
1127 {
1128   if(getArray()==0)
1129     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::normMax : no default array defined !");
1130   return getArray()->normMax();
1131 }
1132
1133 /*!
1134  * Computes sums of values of each component of \a this field wighted with
1135  * values returned by buildMeasureField().  
1136  *  \param [out] res - pointer to an array of result sum values, of size at least \a
1137  *         this->getNumberOfComponents(), that is to be allocated by the caller.
1138  *  \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1139  *         buildMeasureField() that makes this method slower. If a user is sure that all
1140  *         cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1141  *         \c false that speeds up this method.
1142  *  \throw If the mesh is not set.
1143  *  \throw If the data array is not set.
1144  */
1145 void MEDCouplingFieldDouble::getWeightedAverageValue(double *res, bool isWAbs) const
1146 {
1147   if(getArray()==0)
1148     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getWeightedAverageValue : no default array defined !");
1149   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> w=buildMeasureField(isWAbs);
1150   double deno=w->getArray()->accumulate(0);
1151   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=getArray()->deepCpy();
1152   arr->multiplyEqual(w->getArray());
1153   std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::multiplies<double>(),1./deno));
1154   arr->accumulate(res);
1155 }
1156
1157 /*!
1158  * Computes a sum of values of a given component of \a this field wighted with
1159  * values returned by buildMeasureField().
1160  *  \param [in] compId - an index of the component of interest.
1161  *  \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1162  *         buildMeasureField() that makes this method slower. If a user is sure that all
1163  *         cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1164  *         \c false that speeds up this method.
1165  *  \throw If the mesh is not set.
1166  *  \throw If the data array is not set.
1167  *  \throw If \a compId is not valid.
1168            A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1169  */
1170 double MEDCouplingFieldDouble::getWeightedAverageValue(int compId, bool isWAbs) const
1171 {
1172   int nbComps=getArray()->getNumberOfComponents();
1173   if(compId<0 || compId>=nbComps)
1174     {
1175       std::ostringstream oss; oss << "MEDCouplingFieldDouble::getWeightedAverageValue : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1176       throw INTERP_KERNEL::Exception(oss.str().c_str());
1177     }
1178   INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1179   getWeightedAverageValue(res,isWAbs);
1180   return res[compId];
1181 }
1182
1183 /*!
1184  * Returns the \c normL1 of values of a given component of \a this field:
1185  * \f[
1186  * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1187  * \f]
1188  *  \param [in] compId - an index of the component of interest.
1189  *  \throw If the mesh is not set.
1190  *  \throw If the spatial discretization of \a this field is NULL.
1191  *  \throw If \a compId is not valid.
1192            A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1193  */
1194 double MEDCouplingFieldDouble::normL1(int compId) const
1195 {
1196   if(!_mesh)
1197     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1 !");
1198   if(!((const MEDCouplingFieldDiscretization *)_type))
1199     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1200   int nbComps=getArray()->getNumberOfComponents();
1201   if(compId<0 || compId>=nbComps)
1202     {
1203       std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL1 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1204       throw INTERP_KERNEL::Exception(oss.str().c_str());
1205     }
1206   INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1207   _type->normL1(_mesh,getArray(),res);
1208   return res[compId];
1209 }
1210
1211 /*!
1212  * Returns the \c normL1 of values of each component of \a this field:
1213  * \f[
1214  * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1215  * \f]
1216  *  \param [out] res - pointer to an array of result values, of size at least \a
1217  *         this->getNumberOfComponents(), that is to be allocated by the caller.
1218  *  \throw If the mesh is not set.
1219  *  \throw If the spatial discretization of \a this field is NULL.
1220  */
1221 void MEDCouplingFieldDouble::normL1(double *res) const
1222 {
1223   if(!_mesh)
1224     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1");
1225   if(!((const MEDCouplingFieldDiscretization *)_type))
1226     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1227   _type->normL1(_mesh,getArray(),res);
1228 }
1229
1230 /*!
1231  * Returns the \c normL2 of values of a given component of \a this field:
1232  * \f[
1233  * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1234  * \f]
1235  *  \param [in] compId - an index of the component of interest.
1236  *  \throw If the mesh is not set.
1237  *  \throw If the spatial discretization of \a this field is NULL.
1238  *  \throw If \a compId is not valid.
1239            A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1240  */
1241 double MEDCouplingFieldDouble::normL2(int compId) const
1242 {
1243   if(!_mesh)
1244     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1245   if(!((const MEDCouplingFieldDiscretization *)_type))
1246     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1247   int nbComps=getArray()->getNumberOfComponents();
1248   if(compId<0 || compId>=nbComps)
1249     {
1250       std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL2 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1251       throw INTERP_KERNEL::Exception(oss.str().c_str());
1252     }
1253   INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1254   _type->normL2(_mesh,getArray(),res);
1255   return res[compId];
1256 }
1257
1258 /*!
1259  * Returns the \c normL2 of values of each component of \a this field:
1260  * \f[
1261  * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1262  * \f]
1263  *  \param [out] res - pointer to an array of result values, of size at least \a
1264  *         this->getNumberOfComponents(), that is to be allocated by the caller.
1265  *  \throw If the mesh is not set.
1266  *  \throw If the spatial discretization of \a this field is NULL.
1267  */
1268 void MEDCouplingFieldDouble::normL2(double *res) const
1269 {
1270   if(!_mesh)
1271     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1272   if(!((const MEDCouplingFieldDiscretization *)_type))
1273     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1274   _type->normL2(_mesh,getArray(),res);
1275 }
1276
1277 /*!
1278  * Computes a sum of values of a given component of \a this field multiplied by
1279  * values returned by buildMeasureField().
1280  * This method is useful to check the conservativity of interpolation method.
1281  *  \param [in] compId - an index of the component of interest.
1282  *  \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1283  *         buildMeasureField() that makes this method slower. If a user is sure that all
1284  *         cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1285  *         \c false that speeds up this method.
1286  *  \throw If the mesh is not set.
1287  *  \throw If the data array is not set.
1288  *  \throw If \a compId is not valid.
1289            A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1290  */
1291 double MEDCouplingFieldDouble::integral(int compId, bool isWAbs) const
1292 {
1293   if(!_mesh)
1294     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral");
1295   if(!((const MEDCouplingFieldDiscretization *)_type))
1296     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral !");
1297   int nbComps=getArray()->getNumberOfComponents();
1298   if(compId<0 || compId>=nbComps)
1299     {
1300       std::ostringstream oss; oss << "MEDCouplingFieldDouble::integral : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1301       throw INTERP_KERNEL::Exception(oss.str().c_str());
1302     }
1303   INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1304   _type->integral(_mesh,getArray(),isWAbs,res);
1305   return res[compId];
1306 }
1307
1308 /*!
1309  * Computes a sum of values of each component of \a this field multiplied by
1310  * values returned by buildMeasureField().
1311  * This method is useful to check the conservativity of interpolation method.
1312  *  \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1313  *         buildMeasureField() that makes this method slower. If a user is sure that all
1314  *         cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1315  *         \c false that speeds up this method.
1316  *  \param [out] res - pointer to an array of result sum values, of size at least \a
1317  *         this->getNumberOfComponents(), that is to be allocated by the caller.
1318  *  \throw If the mesh is not set.
1319  *  \throw If the data array is not set.
1320  *  \throw If the spatial discretization of \a this field is NULL.
1321  */
1322 void MEDCouplingFieldDouble::integral(bool isWAbs, double *res) const
1323 {
1324   if(!_mesh)
1325     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral2");
1326   if(!((const MEDCouplingFieldDiscretization *)_type))
1327     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral2 !");
1328   _type->integral(_mesh,getArray(),isWAbs,res);
1329 }
1330
1331 /*!
1332  * Returns a value at a given cell of a structured mesh. The cell is specified by its
1333  * (i,j,k) index.
1334  *  \param [in] i - a index of node coordinates array along X axis. The cell is
1335  *         located between the i-th and ( i + 1 )-th nodes along X axis.
1336  *  \param [in] j - a index of node coordinates array along Y axis. The cell is
1337  *         located between the j-th and ( j + 1 )-th nodes along Y axis.
1338  *  \param [in] k - a index of node coordinates array along Z axis. The cell is
1339  *         located between the k-th and ( k + 1 )-th nodes along Z axis.
1340  *  \param [out] res - pointer to an array returning a feild value, of size at least
1341  *         \a this->getNumberOfComponents(), that is to be allocated by the caller.
1342  *  \throw If the spatial discretization of \a this field is NULL.
1343  *  \throw If the mesh is not set.
1344  *  \throw If the mesh is not a structured one.
1345  *
1346  *  \if ENABLE_EXAMPLES
1347  *  \ref cpp_mcfielddouble_getValueOnPos "Here is a C++ example".<br>
1348  *  \ref  py_mcfielddouble_getValueOnPos "Here is a Python example".
1349  *  \endif
1350  */
1351 void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) const
1352 {
1353   const DataArrayDouble *arr=_time_discr->getArray();
1354   if(!_mesh)
1355     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnPos");
1356   if(!((const MEDCouplingFieldDiscretization *)_type))
1357     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1358   _type->getValueOnPos(arr,_mesh,i,j,k,res);
1359 }
1360
1361 /*!
1362  * Returns a value of \a this at a given point using spatial discretization.
1363  *  \param [in] spaceLoc - the point of interest.
1364  *  \param [out] res - pointer to an array returning a feild value, of size at least
1365  *         \a this->getNumberOfComponents(), that is to be allocated by the caller.
1366  *  \throw If the spatial discretization of \a this field is NULL.
1367  *  \throw If the mesh is not set.
1368  *  \throw If \a spaceLoc is out of the spatial discretization.
1369  *
1370  *  \if ENABLE_EXAMPLES
1371  *  \ref cpp_mcfielddouble_getValueOn "Here is a C++ example".<br>
1372  *  \ref  py_mcfielddouble_getValueOn "Here is a Python example".
1373  *  \endif
1374  */
1375 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) const
1376 {
1377   const DataArrayDouble *arr=_time_discr->getArray();
1378   if(!_mesh)
1379     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1380   if(!((const MEDCouplingFieldDiscretization *)_type))
1381     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1382   _type->getValueOn(arr,_mesh,spaceLoc,res);
1383 }
1384
1385 /*!
1386  * Returns values of \a this at given points using spatial discretization.
1387  *  \param [in] spaceLoc - coordinates of points of interest in full-interlace
1388  *          mode. This array is to be of size ( \a nbOfPoints * \a this->getNumberOfComponents() ).
1389  *  \param [in] nbOfPoints - number of points of interest.
1390  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding field
1391  *         values relating to the input points. This array is of size \a nbOfPoints
1392  *         tuples per \a this->getNumberOfComponents() components. The caller is to 
1393  *         delete this array using decrRef() as it is no more needed.
1394  *  \throw If the spatial discretization of \a this field is NULL.
1395  *  \throw If the mesh is not set.
1396  *  \throw If any point in \a spaceLoc is out of the spatial discretization.
1397  *
1398  *  \if ENABLE_EXAMPLES
1399  *  \ref cpp_mcfielddouble_getValueOnMulti "Here is a C++ example".<br>
1400  *  \ref  py_mcfielddouble_getValueOnMulti "Here is a Python example".
1401  *  \endif
1402  */
1403 DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, int nbOfPoints) const
1404 {
1405   const DataArrayDouble *arr=_time_discr->getArray();
1406   if(!_mesh)
1407     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnMulti");
1408   if(!((const MEDCouplingFieldDiscretization *)_type))
1409     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnMulti !");
1410   return _type->getValueOnMulti(arr,_mesh,spaceLoc,nbOfPoints);
1411 }
1412
1413 /*!
1414  * Returns a value of \a this field at a given point at a given time using spatial discretization.
1415  * If the time is not covered by \a this->_time_discr, an exception is thrown.
1416  *  \param [in] spaceLoc - the point of interest.
1417  *  \param [in] time - the time of interest.
1418  *  \param [out] res - pointer to an array returning a feild value, of size at least
1419  *         \a this->getNumberOfComponents(), that is to be allocated by the caller.
1420  *  \throw If the spatial discretization of \a this field is NULL.
1421  *  \throw If the mesh is not set.
1422  *  \throw If \a spaceLoc is out of the spatial discretization.
1423  *  \throw If \a time is not covered by \a this->_time_discr.
1424  *
1425  *  \if ENABLE_EXAMPLES
1426  *  \ref cpp_mcfielddouble_getValueOn_time "Here is a C++ example".<br>
1427  *  \ref  py_mcfielddouble_getValueOn_time "Here is a Python example".
1428  *  \endif
1429  */
1430 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, double *res) const
1431 {
1432   std::vector< const DataArrayDouble *> arrs=_time_discr->getArraysForTime(time);
1433   if(!_mesh)
1434     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1435   if(!((const MEDCouplingFieldDiscretization *)_type))
1436     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOn !");
1437   std::vector<double> res2;
1438   for(std::vector< const DataArrayDouble *>::const_iterator iter=arrs.begin();iter!=arrs.end();iter++)
1439     {
1440       int sz=(int)res2.size();
1441       res2.resize(sz+(*iter)->getNumberOfComponents());
1442       _type->getValueOn(*iter,_mesh,spaceLoc,&res2[sz]);
1443     }
1444   _time_discr->getValueForTime(time,res2,res);
1445 }
1446
1447 /*!
1448  * Apply a linear function to a given component of \a this field, so that
1449  * a component value <em>(x)</em> becomes \f$ a * x + b \f$.
1450  *  \param [in] a - the first coefficient of the function.
1451  *  \param [in] b - the second coefficient of the function.
1452  *  \param [in] compoId - the index of component to modify.
1453  *  \throw If the data array(s) is(are) not set.
1454  */
1455 void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId)
1456 {
1457   _time_discr->applyLin(a,b,compoId);
1458 }
1459
1460 /*!
1461  * Apply a linear function to all components of \a this field, so that
1462  * values <em>(x)</em> becomes \f$ a * x + b \f$.
1463  *  \param [in] a - the first coefficient of the function.
1464  *  \param [in] b - the second coefficient of the function.
1465  *  \throw If the data array(s) is(are) not set.
1466  */
1467 void MEDCouplingFieldDouble::applyLin(double a, double b)
1468 {
1469   _time_discr->applyLin(a,b);
1470 }
1471
1472 /*!
1473  * This method sets \a this to a uniform scalar field with one component.
1474  * All tuples will have the same value 'value'.
1475  * An exception is thrown if no underlying mesh is defined.
1476  */
1477 MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value)
1478 {
1479   if(!_mesh)
1480     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !");
1481   if(!((const MEDCouplingFieldDiscretization *)_type))
1482     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform operator = !");
1483   int nbOfTuple=_type->getNumberOfTuples(_mesh);
1484   _time_discr->setOrCreateUniformValueOnAllComponents(nbOfTuple,value);
1485   return *this;
1486 }
1487
1488 /*!
1489  * Creates data array(s) of \a this field by using a C function for value generation.
1490  *  \param [in] nbOfComp - the number of components for \a this field to have.
1491  *  \param [in] func - the function used to compute values of \a this field.
1492  *         This function is to compute a field value basing on coordinates of value
1493  *         location point.
1494  *  \throw If the mesh is not set.
1495  *  \throw If \a func returns \c false.
1496  *  \throw If the spatial discretization of \a this field is NULL.
1497  *
1498  *  \if ENABLE_EXAMPLES
1499  *  \ref cpp_mcfielddouble_fillFromAnalytic_c_func "Here is a C++ example".
1500  *  \endif
1501  */
1502 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate func)
1503 {
1504   if(!_mesh)
1505     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1506   if(!((const MEDCouplingFieldDiscretization *)_type))
1507     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1508   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1509   _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1510 }
1511
1512 /*!
1513  * Creates data array(s) of \a this field by using a function for value generation.<br>
1514  * The function is applied to coordinates of value location points. For example, if
1515  * \a this field is on cells, the function is applied to cell barycenters.
1516  * For more info on supported expressions that can be used in the function, see \ref
1517  * MEDCouplingArrayApplyFuncExpr. <br>
1518  * The function can include arbitrary named variables
1519  * (e.g. "x","y" or "va44") to refer to components of point coordinates. Names of
1520  * variables are sorted in \b alphabetical \b order to associate a variable name with a
1521  * component. For example, in the expression "2*x+z", "x" stands for the component #0
1522  * and "z" stands for the component #1 (\b not #2)!<br>
1523  * In a general case, a value resulting from the function evaluation is assigned to all
1524  * components of a field value. But there is a possibility to have its own expression for
1525  * each component within one function. For this purpose, there are predefined variable
1526  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1527  * the component #0 etc). A factor of such a variable is added to the
1528  * corresponding component only.<br>
1529  * For example, \a nbOfComp == 4, coordinates of a 3D point are (1.,3.,7.), then
1530  *   - "2*x + z"               produces (5.,5.,5.,5.)
1531  *   - "2*x + 0*y + z"         produces (9.,9.,9.,9.)
1532  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1533  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1534  *
1535  *  \param [in] nbOfComp - the number of components for \a this field to have.
1536  *  \param [in] func - the function used to compute values of \a this field.
1537  *         This function is used to compute a field value basing on coordinates of value
1538  *         location point. For example, if \a this field is on cells, the function
1539  *         is applied to cell barycenters.
1540  *  \throw If the mesh is not set.
1541  *  \throw If the spatial discretization of \a this field is NULL.
1542  *  \throw If computing \a func fails.
1543  *
1544  *  \if ENABLE_EXAMPLES
1545  *  \ref cpp_mcfielddouble_fillFromAnalytic "Here is a C++ example".<br>
1546  *  \ref  py_mcfielddouble_fillFromAnalytic "Here is a Python example".
1547  *  \endif
1548  */
1549 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func)
1550 {
1551   if(!_mesh)
1552     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1553   if(!((const MEDCouplingFieldDiscretization *)_type))
1554     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1555   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1556   _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1557 }
1558
1559 /*!
1560  * Creates data array(s) of \a this field by using a function for value generation.<br>
1561  * The function is applied to coordinates of value location points. For example, if
1562  * \a this field is on cells, the function is applied to cell barycenters.<br>
1563  * This method differs from
1564  * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func) "fillFromAnalytic()"
1565  * by the way how variable
1566  * names, used in the function, are associated with components of coordinates of field
1567  * location points; here, a variable name corresponding to a component is retrieved from
1568  * a corresponding node coordinates array (where it is set via
1569  * DataArrayDouble::setInfoOnComponent()).<br>
1570  * For more info on supported expressions that can be used in the function, see \ref
1571  * MEDCouplingArrayApplyFuncExpr. <br> 
1572  * In a general case, a value resulting from the function evaluation is assigned to all
1573  * components of a field value. But there is a possibility to have its own expression for
1574  * each component within one function. For this purpose, there are predefined variable
1575  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1576  * the component #0 etc). A factor of such a variable is added to the
1577  * corresponding component only.<br>
1578  * For example, \a nbOfComp == 4, names of spatial components are "x", "y" and "z",
1579  * coordinates of a 3D point are (1.,3.,7.), then
1580  *   - "2*x + z"               produces (9.,9.,9.,9.)
1581  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1582  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1583  *
1584  *  \param [in] nbOfComp - the number of components for \a this field to have.
1585  *  \param [in] func - the function used to compute values of \a this field.
1586  *         This function is used to compute a field value basing on coordinates of value
1587  *         location point. For example, if \a this field is on cells, the function
1588  *         is applied to cell barycenters.
1589  *  \throw If the mesh is not set.
1590  *  \throw If the spatial discretization of \a this field is NULL.
1591  *  \throw If computing \a func fails.
1592  *
1593  *  \if ENABLE_EXAMPLES
1594  *  \ref cpp_mcfielddouble_fillFromAnalytic2 "Here is a C++ example".<br>
1595  *  \ref  py_mcfielddouble_fillFromAnalytic2 "Here is a Python example".
1596  *  \endif
1597  */
1598 void MEDCouplingFieldDouble::fillFromAnalytic2(int nbOfComp, const std::string& func)
1599 {
1600   if(!_mesh)
1601     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !");
1602   if(!((const MEDCouplingFieldDiscretization *)_type))
1603     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic2 !");
1604   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1605   _time_discr->fillFromAnalytic2(loc,nbOfComp,func);
1606 }
1607
1608 /*!
1609  * Creates data array(s) of \a this field by using a function for value generation.<br>
1610  * The function is applied to coordinates of value location points. For example, if
1611  * \a this field is on cells, the function is applied to cell barycenters.<br>
1612  * This method differs from
1613  * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func) "fillFromAnalytic()"
1614  * by the way how variable
1615  * names, used in the function, are associated with components of coordinates of field
1616  * location points; here, a component index of a variable is defined by a
1617  * rank of the variable within the input array \a varsOrder.<br>
1618  * For more info on supported expressions that can be used in the function, see \ref
1619  * MEDCouplingArrayApplyFuncExpr.
1620  * In a general case, a value resulting from the function evaluation is assigned to all
1621  * components of a field value. But there is a possibility to have its own expression for
1622  * each component within one function. For this purpose, there are predefined variable
1623  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1624  * the component #0 etc). A factor of such a variable is added to the
1625  * corresponding component only.<br>
1626  * For example, \a nbOfComp == 4, names of
1627  * spatial components are given in \a varsOrder: ["x", "y","z"], coordinates of a
1628  * 3D point are (1.,3.,7.), then
1629  *   - "2*x + z"               produces (9.,9.,9.,9.)
1630  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1631  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1632  *
1633  *  \param [in] nbOfComp - the number of components for \a this field to have.
1634  *  \param [in] func - the function used to compute values of \a this field.
1635  *         This function is used to compute a field value basing on coordinates of value
1636  *         location point. For example, if \a this field is on cells, the function
1637  *         is applied to cell barycenters.
1638  *  \throw If the mesh is not set.
1639  *  \throw If the spatial discretization of \a this field is NULL.
1640  *  \throw If computing \a func fails.
1641  *
1642  *  \if ENABLE_EXAMPLES
1643  *  \ref cpp_mcfielddouble_fillFromAnalytic3 "Here is a C++ example".<br>
1644  *  \ref  py_mcfielddouble_fillFromAnalytic3 "Here is a Python example".
1645  *  \endif
1646  */
1647 void MEDCouplingFieldDouble::fillFromAnalytic3(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
1648 {
1649   if(!_mesh)
1650     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !");
1651   if(!((const MEDCouplingFieldDiscretization *)_type))
1652     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic3 !");
1653   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1654   _time_discr->fillFromAnalytic3(loc,nbOfComp,varsOrder,func);
1655 }
1656
1657 /*!
1658  * Modifies values of \a this field by applying a C function to each tuple of all
1659  * data arrays.
1660  *  \param [in] nbOfComp - the number of components for \a this field to have.
1661  *  \param [in] func - the function used to compute values of \a this field.
1662  *         This function is to compute a field value basing on a current field value.
1663  *  \throw If \a func returns \c false.
1664  *
1665  *  \if ENABLE_EXAMPLES
1666  *  \ref cpp_mcfielddouble_applyFunc_c_func "Here is a C++ example".
1667  *  \endif
1668  */
1669 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, FunctionToEvaluate func)
1670 {
1671   _time_discr->applyFunc(nbOfComp,func);
1672 }
1673
1674 /*!
1675  * Fill \a this field with a given value.<br>
1676  * This method is a specialization of other overloaded methods. When \a nbOfComp == 1
1677  * this method is equivalent to ParaMEDMEM::MEDCouplingFieldDouble::operator=().
1678  *  \param [in] nbOfComp - the number of components for \a this field to have.
1679  *  \param [in] val - the value to assign to every atomic value of \a this field.
1680  *  \throw If the spatial discretization of \a this field is NULL.
1681  *  \throw If the mesh is not set.
1682  *
1683  *  \if ENABLE_EXAMPLES
1684  *  \ref cpp_mcfielddouble_applyFunc_val "Here is a C++ example".<br>
1685  *  \ref  py_mcfielddouble_applyFunc_val "Here is a Python example".
1686  *  \endif
1687  */
1688 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val)
1689 {
1690   if(!_mesh)
1691     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::applyFunc : no mesh defined !");
1692   if(!((const MEDCouplingFieldDiscretization *)_type))
1693     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform applyFunc !");
1694   int nbOfTuple=_type->getNumberOfTuples(_mesh);
1695   _time_discr->setUniformValue(nbOfTuple,nbOfComp,val);
1696 }
1697
1698 /*!
1699  * Modifies values of \a this field by applying a function to each tuple of all
1700  * data arrays.
1701  * For more info on supported expressions that can be used in the function, see \ref
1702  * MEDCouplingArrayApplyFuncExpr. <br>
1703  * The function can include arbitrary named variables
1704  * (e.g. "x","y" or "va44") to refer to components of a field value. Names of
1705  * variables are sorted in \b alphabetical \b order to associate a variable name with a
1706  * component. For example, in the expression "2*x+z", "x" stands for the component #0
1707  * and "z" stands for the component #1 (\b not #2)!<br>
1708  * In a general case, a value resulting from the function evaluation is assigned to all
1709  * components of a field value. But there is a possibility to have its own expression for
1710  * each component within one function. For this purpose, there are predefined variable
1711  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1712  * the component #0 etc). A factor of such a variable is added to the
1713  * corresponding component only.<br>
1714  * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1715  *   - "2*x + z"               produces (5.,5.,5.,5.)
1716  *   - "2*x + 0*y + z"         produces (9.,9.,9.,9.)
1717  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1718  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1719  *
1720  *  \param [in] nbOfComp - the number of components for \a this field to have.
1721  *  \param [in] func - the function used to compute values of \a this field.
1722  *         This function is to compute a field value basing on a current field value.
1723  *  \throw If computing \a func fails.
1724  *
1725  *  \if ENABLE_EXAMPLES
1726  *  \ref cpp_mcfielddouble_applyFunc "Here is a C++ example".<br>
1727  *  \ref  py_mcfielddouble_applyFunc "Here is a Python example".
1728  *  \endif
1729  */
1730 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func)
1731 {
1732   _time_discr->applyFunc(nbOfComp,func);
1733 }
1734
1735
1736 /*!
1737  * Modifies values of \a this field by applying a function to each tuple of all
1738  * data arrays.
1739  * For more info on supported expressions that can be used in the function, see \ref
1740  * MEDCouplingArrayApplyFuncExpr. <br>
1741  * This method differs from
1742  * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) "applyFunc()"
1743  * by the way how variable
1744  * names, used in the function, are associated with components of field values;
1745  * here, a variable name corresponding to a component is retrieved from
1746  * component information of an array (where it is set via
1747  * DataArrayDouble::setInfoOnComponent()).<br>
1748  * In a general case, a value resulting from the function evaluation is assigned to all
1749  * components of a field value. But there is a possibility to have its own expression for
1750  * each component within one function. For this purpose, there are predefined variable
1751  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1752  * the component #0 etc). A factor of such a variable is added to the
1753  * corresponding component only.<br>
1754  * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1755  *   - "2*x + z"               produces (5.,5.,5.,5.)
1756  *   - "2*x + 0*y + z"         produces (9.,9.,9.,9.)
1757  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1758  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1759  *
1760  *  \param [in] nbOfComp - the number of components for \a this field to have.
1761  *  \param [in] func - the function used to compute values of \a this field.
1762  *         This function is to compute a new field value basing on a current field value.
1763  *  \throw If computing \a func fails.
1764  *
1765  *  \if ENABLE_EXAMPLES
1766  *  \ref cpp_mcfielddouble_applyFunc2 "Here is a C++ example".<br>
1767  *  \ref  py_mcfielddouble_applyFunc2 "Here is a Python example".
1768  *  \endif
1769  */
1770 void MEDCouplingFieldDouble::applyFunc2(int nbOfComp, const std::string& func)
1771 {
1772   _time_discr->applyFunc2(nbOfComp,func);
1773 }
1774
1775 /*!
1776  * Modifies values of \a this field by applying a function to each tuple of all
1777  * data arrays.
1778  * This method differs from
1779  * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) "applyFunc()"
1780  * by the way how variable
1781  * names, used in the function, are associated with components of field values;
1782  * here, a component index of a variable is defined by a
1783  * rank of the variable within the input array \a varsOrder.<br>
1784  * For more info on supported expressions that can be used in the function, see \ref
1785  * MEDCouplingArrayApplyFuncExpr.
1786  * In a general case, a value resulting from the function evaluation is assigned to all
1787  * components of a field value. But there is a possibility to have its own expression for
1788  * each component within one function. For this purpose, there are predefined variable
1789  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1790  * the component #0 etc). A factor of such a variable is added to the
1791  * corresponding component only.<br>
1792  * For example, \a nbOfComp == 4, names of
1793  * components are given in \a varsOrder: ["x", "y","z"], components of a
1794  * 3D vector are (1.,3.,7.), then
1795  *   - "2*x + z"               produces (9.,9.,9.,9.)
1796  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1797  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1798  *
1799  *  \param [in] nbOfComp - the number of components for \a this field to have.
1800  *  \param [in] func - the function used to compute values of \a this field.
1801  *         This function is to compute a new field value basing on a current field value.
1802  *  \throw If computing \a func fails.
1803  *
1804  *  \if ENABLE_EXAMPLES
1805  *  \ref cpp_mcfielddouble_applyFunc3 "Here is a C++ example".<br>
1806  *  \ref  py_mcfielddouble_applyFunc3 "Here is a Python example".
1807  *  \endif
1808  */
1809 void MEDCouplingFieldDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
1810 {
1811   _time_discr->applyFunc3(nbOfComp,varsOrder,func);
1812 }
1813
1814 /*!
1815  * Modifies values of \a this field by applying a function to each atomic value of all
1816  * data arrays. The function computes a new single value basing on an old single value.
1817  * For more info on supported expressions that can be used in the function, see \ref
1818  * MEDCouplingArrayApplyFuncExpr. <br>
1819  * The function can include **only one** arbitrary named variable
1820  * (e.g. "x","y" or "va44") to refer to a field atomic value. <br>
1821  * In a general case, a value resulting from the function evaluation is assigned to 
1822  * a single field value. But there is a possibility to have its own expression for
1823  * each component within one function. For this purpose, there are predefined variable
1824  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1825  * the component #0 etc). A factor of such a variable is added to the
1826  * corresponding component only.<br>
1827  * For example, components of a field value are (1.,3.,7.), then
1828  *   - "2*x - 1"               produces (1.,5.,13.)
1829  *   - "2*x*IVec + (x+3)*KVec" produces (2.,0.,10.)
1830  *   - "2*x*IVec + (x+3)*KVec + 1" produces (3.,1.,11.)
1831  *
1832  *  \param [in] func - the function used to compute values of \a this field.
1833  *         This function is to compute a field value basing on a current field value.
1834  *  \throw If computing \a func fails.
1835  *
1836  *  \if ENABLE_EXAMPLES
1837  *  \ref cpp_mcfielddouble_applyFunc_same_nb_comp "Here is a C++ example".<br>
1838  *  \ref  py_mcfielddouble_applyFunc_same_nb_comp "Here is a Python example".
1839  *  \endif
1840  */
1841 void MEDCouplingFieldDouble::applyFunc(const std::string& func)
1842 {
1843   _time_discr->applyFunc(func);
1844 }
1845
1846 /*!
1847  * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1848  * The field will contain exactly the same number of components after the call.
1849  * Use is not warranted for the moment !
1850  */
1851 void MEDCouplingFieldDouble::applyFuncFast32(const std::string& func)
1852 {
1853   _time_discr->applyFuncFast32(func);
1854 }
1855
1856 /*!
1857  * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1858  * The field will contain exactly the same number of components after the call.
1859  * Use is not warranted for the moment !
1860  */
1861 void MEDCouplingFieldDouble::applyFuncFast64(const std::string& func)
1862 {
1863   _time_discr->applyFuncFast64(func);
1864 }
1865
1866 /*!
1867  * Returns number of components in the data array. For more info on the data arrays,
1868  * see \ref MEDCouplingArrayPage.
1869  *  \return int - the number of components in the data array.
1870  *  \throw If the data array is not set.
1871  */
1872 int MEDCouplingFieldDouble::getNumberOfComponents() const
1873 {
1874   if(getArray()==0)
1875     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfComponents : No array specified !");
1876   return getArray()->getNumberOfComponents();
1877 }
1878
1879 /*!
1880  * Returns number of tuples in \a this field, that depends on 
1881  * - the number of entities in the underlying mesh
1882  * - \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field (e.g. number
1883  * of Gauss points if \a this->getTypeOfField() == 
1884  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT").
1885  *
1886  * The returned value does **not depend** on the number of tuples in the data array
1887  * (which has to be equal to the returned value), \b contrary to
1888  * getNumberOfComponents() and getNumberOfValues() that retrieve information from the
1889  * data array.
1890  * \warning No checkCoherency() is done here.
1891  * For more info on the data arrays, see \ref MEDCouplingArrayPage.
1892  *  \return int - the number of tuples.
1893  *  \throw If the mesh is not set.
1894  *  \throw If the spatial discretization of \a this field is NULL.
1895  *  \throw If the spatial discretization is not fully defined.
1896  */
1897 int MEDCouplingFieldDouble::getNumberOfTuples() const
1898 {
1899   if(!_mesh)
1900     throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !");
1901   if(!((const MEDCouplingFieldDiscretization *)_type))
1902     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getNumberOfTuples !");
1903   return _type->getNumberOfTuples(_mesh);
1904 }
1905
1906 /*!
1907  * Returns number of atomic double values in the data array of \a this field.
1908  * For more info on the data arrays, see \ref MEDCouplingArrayPage.
1909  *  \return int - (number of tuples) * (number of components) of the
1910  *  data array.
1911  *  \throw If the data array is not set.
1912  */
1913 int MEDCouplingFieldDouble::getNumberOfValues() const
1914 {
1915   if(getArray()==0)
1916     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfValues : No array specified !");
1917   return getArray()->getNbOfElems();
1918 }
1919
1920 /*!
1921  * Sets own modification time by the most recently modified element of data (the mesh,
1922  * the data array etc). For more info, see \ref MEDCouplingTimeLabelPage.
1923  */
1924 void MEDCouplingFieldDouble::updateTime() const
1925 {
1926   MEDCouplingField::updateTime();
1927   updateTimeWith(*_time_discr);
1928 }
1929
1930 std::size_t MEDCouplingFieldDouble::getHeapMemorySizeWithoutChildren() const
1931 {
1932   return MEDCouplingField::getHeapMemorySizeWithoutChildren();
1933 }
1934
1935 std::vector<const BigMemoryObject *> MEDCouplingFieldDouble::getDirectChildren() const
1936 {
1937   std::vector<const BigMemoryObject *> ret(MEDCouplingField::getDirectChildren());
1938   if(_time_discr)
1939     {
1940       std::vector<const BigMemoryObject *> ret2(_time_discr->getDirectChildren());
1941       ret.insert(ret.end(),ret2.begin(),ret2.end());
1942     }
1943   return ret;
1944 }
1945
1946 /*!
1947  * Sets \ref NatureOfField.
1948  *  \param [in] nat - an item of enum ParaMEDMEM::NatureOfField.
1949  */
1950 void MEDCouplingFieldDouble::setNature(NatureOfField nat)
1951 {
1952   MEDCouplingField::setNature(nat);
1953   if(_type)
1954     _type->checkCompatibilityWithNature(nat);
1955 }
1956
1957 /*!
1958  * This method synchronizes time information (time, iteration, order, time unit) regarding the information in \c this->_mesh.
1959  * \throw If no mesh is set in this. Or if \a this is not compatible with time setting (typically NO_TIME)
1960  */
1961 void MEDCouplingFieldDouble::synchronizeTimeWithMesh()
1962 {
1963   if(!_mesh)
1964     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::synchronizeTimeWithMesh : no mesh set in this !");
1965   int it=-1,ordr=-1;
1966   double val=_mesh->getTime(it,ordr);
1967   std::string timeUnit(_mesh->getTimeUnit());
1968   setTime(val,it,ordr);
1969   setTimeUnit(timeUnit);
1970 }
1971
1972 /*!
1973  * Returns a value of \a this field of type either
1974  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" or
1975  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
1976  *  \param [in] cellId - an id of cell of interest.
1977  *  \param [in] nodeIdInCell - a node index within the cell.
1978  *  \param [in] compoId - an index of component.
1979  *  \return double - the field value corresponding to the specified parameters.
1980  *  \throw If the data array is not set.
1981  *  \throw If the mesh is not set.
1982  *  \throw If the spatial discretization of \a this field is NULL.
1983  *  \throw If \a this field if of type other than 
1984  *         \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" or
1985  *         \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
1986  */
1987 double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) const
1988 {
1989   if(!((const MEDCouplingFieldDiscretization *)_type))
1990     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getIJK !");
1991   return _type->getIJK(_mesh,getArray(),cellId,nodeIdInCell,compoId);
1992 }
1993
1994 /*!
1995  * Sets the data array. 
1996  *  \param [in] array - the data array holding values of \a this field. It's size
1997  *         should correspond to the mesh and
1998  *         \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
1999  *         (see getNumberOfTuples()), but this size is not checked here.
2000  */
2001 void MEDCouplingFieldDouble::setArray(DataArrayDouble *array)
2002 {
2003   _time_discr->setArray(array,this);
2004 }
2005
2006 /*!
2007  * Sets the data array holding values corresponding to an end of a time interval
2008  * for which \a this field is defined.
2009  *  \param [in] array - the data array holding values of \a this field. It's size
2010  *         should correspond to the mesh and
2011  *         \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
2012  *         (see getNumberOfTuples()), but this size is not checked here.
2013  */
2014 void MEDCouplingFieldDouble::setEndArray(DataArrayDouble *array)
2015 {
2016   _time_discr->setEndArray(array,this);
2017 }
2018
2019 /*!
2020  * Sets all data arrays needed to define the field values.
2021  *  \param [in] arrs - a vector of DataArrayDouble's holding values of \a this
2022  *         field. Size of each array should correspond to the mesh and
2023  *         \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
2024  *         (see getNumberOfTuples()), but this size is not checked here.
2025  *  \throw If number of arrays in \a arrs does not correspond to type of
2026  *         \ref MEDCouplingTemporalDisc "temporal discretization" of \a this field.
2027  */
2028 void MEDCouplingFieldDouble::setArrays(const std::vector<DataArrayDouble *>& arrs)
2029 {
2030   _time_discr->setArrays(arrs,this);
2031 }
2032
2033 void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2034 {
2035   tinyInfo.clear();
2036   _time_discr->getTinySerializationStrInformation(tinyInfo);
2037   tinyInfo.push_back(_name);
2038   tinyInfo.push_back(_desc);
2039   tinyInfo.push_back(getTimeUnit());
2040 }
2041
2042 /*!
2043  * This method retrieves some critical values to resize and prepare remote instance.
2044  * The first two elements returned in tinyInfo correspond to the parameters to give in constructor.
2045  * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
2046  */
2047 void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2048 {
2049   if(!((const MEDCouplingFieldDiscretization *)_type))
2050     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
2051   tinyInfo.clear();
2052   tinyInfo.push_back((int)_type->getEnum());
2053   tinyInfo.push_back((int)_time_discr->getEnum());
2054   tinyInfo.push_back((int)_nature);
2055   _time_discr->getTinySerializationIntInformation(tinyInfo);
2056   std::vector<int> tinyInfo2;
2057   _type->getTinySerializationIntInformation(tinyInfo2);
2058   tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
2059   tinyInfo.push_back((int)tinyInfo2.size());
2060 }
2061
2062 /*!
2063  * This method retrieves some critical values to resize and prepare remote instance.
2064  * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
2065  */
2066 void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2067 {
2068   if(!((const MEDCouplingFieldDiscretization *)_type))
2069     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
2070   tinyInfo.clear();
2071   _time_discr->getTinySerializationDbleInformation(tinyInfo);
2072   std::vector<double> tinyInfo2;
2073   _type->getTinySerializationDbleInformation(tinyInfo2);
2074   tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
2075   tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it
2076 }
2077
2078 /*!
2079  * This method has to be called to the new instance filled by CORBA, MPI, File...
2080  * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied.
2081  * @param dataInt out parameter. If not null the pointer is already owned by \a this after the call of this method. In this case no decrRef must be applied.
2082  * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by \a this after the call of this method.
2083  *               No decrRef must be applied to every instances in returned vector.
2084  */
2085 void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays)
2086 {
2087   if(!((const MEDCouplingFieldDiscretization *)_type))
2088     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
2089   dataInt=0;
2090   std::vector<int> tinyInfoITmp(tinyInfoI);
2091   int sz=tinyInfoITmp.back();
2092   tinyInfoITmp.pop_back();
2093   std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
2094   std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
2095   _time_discr->resizeForUnserialization(tinyInfoI2,arrays);
2096   std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
2097   _type->resizeForUnserialization(tinyInfoITmp3,dataInt);
2098 }
2099
2100 void MEDCouplingFieldDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2101 {
2102   if(!((const MEDCouplingFieldDiscretization *)_type))
2103     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
2104   std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
2105   //
2106   std::vector<double> tmp(tinyInfoD);
2107   int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it
2108   tmp.pop_back();
2109   std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
2110   std::vector<double> tmp2(tmp.end()-sz,tmp.end());
2111   //
2112   _time_discr->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
2113   _nature=(NatureOfField)tinyInfoI[2];
2114   _type->finishUnserialization(tmp2);
2115   int nbOfElemS=(int)tinyInfoS.size();
2116   _name=tinyInfoS[nbOfElemS-3];
2117   _desc=tinyInfoS[nbOfElemS-2];
2118   setTimeUnit(tinyInfoS[nbOfElemS-1]);
2119 }
2120
2121 /*!
2122  * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller.
2123  * The values returned must be consulted only in readonly mode.
2124  */
2125 void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays) const
2126 {
2127   if(!((const MEDCouplingFieldDiscretization *)_type))
2128     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");
2129   _time_discr->getArrays(arrays);
2130   _type->getSerializationIntArray(dataInt);
2131 }
2132
2133 /*!
2134  * Tries to set an \a other mesh as the support of \a this field. An attempt fails, if
2135  * a current and the \a other meshes are different with use of specified equality
2136  * criteria, and then an exception is thrown.
2137  *  \param [in] other - the mesh to use as the field support if this mesh can be
2138  *         considered equal to the current mesh.
2139  *  \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
2140  *         it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
2141  *         is used for mesh comparison.
2142  *  \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
2143  *         It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
2144  *  \param [in] eps - a precision used at node renumbering (if needed) to compare field
2145  *         values at merged nodes. If the values differ more than \a eps, an
2146  *         exception is thrown.
2147  *  \throw If the mesh is not set.
2148  *  \throw If \a other == NULL.
2149  *  \throw If any of the meshes is not well defined.
2150  *  \throw If the two meshes do not match.
2151  *  \throw If field values at merged nodes (if any) deffer more than \a eps.
2152  *
2153  *  \if ENABLE_EXAMPLES
2154  *  \ref cpp_mcfielddouble_changeUnderlyingMesh "Here is a C++ example".<br>
2155  *  \ref  py_mcfielddouble_changeUnderlyingMesh "Here is a Python example".
2156  *  \endif
2157  */
2158 void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps)
2159 {
2160   if(_mesh==0 || other==0)
2161     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::changeUnderlyingMesh : is expected to operate on not null meshes !");
2162   DataArrayInt *cellCor=0,*nodeCor=0;
2163   other->checkGeoEquivalWith(_mesh,levOfCheck,precOnMesh,cellCor,nodeCor);
2164   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellCor2(cellCor),nodeCor2(nodeCor);
2165   if(cellCor)
2166     renumberCellsWithoutMesh(cellCor->getConstPointer(),false);
2167   if(nodeCor)
2168     renumberNodesWithoutMesh(nodeCor->getConstPointer(),nodeCor->getMaxValueInArray()+1,eps);
2169   setMesh(other);
2170 }
2171
2172 /*!
2173  * Subtracts another field from \a this one in case when the two fields have different
2174  * supporting meshes. The subtraction is performed provided that the tho meshes can be
2175  * considered equal with use of specified equality criteria, else an exception is thrown.
2176  * If the meshes match, the mesh of \a f is set to \a this field (\a this is permuted if 
2177  * necessary) and field values are subtracted. No interpolation is done here, only an
2178  * analysis of two underlying mesh is done to see if the meshes are geometrically
2179  * equivalent.<br>
2180  * The job of this method consists in calling
2181  * \a this->changeUnderlyingMesh() with \a f->getMesh() as the first parameter, and then
2182  * \a this -= \a f.<br>
2183  * This method requires that \a f and \a this are coherent (checkCoherency()) and that \a f
2184  * and \a this are coherent for a merge.<br>
2185  * "DM" in the method name stands for "different meshes".
2186  *  \param [in] f - the field to subtract from this.
2187  *  \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
2188  *         it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
2189  *         is used for mesh comparison.
2190  *  \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
2191  *         It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
2192  *  \param [in] eps - a precision used at node renumbering (if needed) to compare field
2193  *         values at merged nodes. If the values differ more than \a eps, an
2194  *         exception is thrown.
2195  *  \throw If \a f == NULL.
2196  *  \throw If any of the meshes is not set or is not well defined.
2197  *  \throw If the two meshes do not match.
2198  *  \throw If the two fields are not coherent for merge.
2199  *  \throw If field values at merged nodes (if any) deffer more than \a eps.
2200  *
2201  *  \if ENABLE_EXAMPLES
2202  *  \ref cpp_mcfielddouble_substractInPlaceDM "Here is a C++ example".<br>
2203  *  \ref  py_mcfielddouble_substractInPlaceDM "Here is a Python example".
2204  *  \endif
2205  *  \sa changeUnderlyingMesh().
2206  */
2207 void MEDCouplingFieldDouble::substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps)
2208 {
2209   checkCoherency();
2210   if(!f)
2211     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : input field is NULL !");
2212   f->checkCoherency();
2213   if(!areCompatibleForMerge(f))
2214     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : Fields are not compatible ; unable to apply mergeFields on them !");
2215   changeUnderlyingMesh(f->getMesh(),levOfCheck,precOnMesh,eps);
2216   operator-=(*f);
2217 }
2218
2219 /*!
2220  * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2221  * underlying mesh is replaced by a new mesh instance where the coincident nodes are merged.
2222  *  \param [in] eps - a precision used to compare nodes of the two meshes.
2223  *  \param [in] epsOnVals - a precision used to compare field
2224  *         values at merged nodes. If the values differ more than \a epsOnVals, an
2225  *         exception is thrown.
2226  *  \return bool - \c true if some nodes have been merged and hence \a this field lies
2227  *         on another mesh.
2228  *  \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2229  *  \throw If the mesh is not well defined.
2230  *  \throw If the spatial discretization of \a this field is NULL.
2231  *  \throw If the data array is not set.
2232  *  \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2233  */
2234 bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals)
2235 {
2236   const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2237   if(!meshC)
2238     throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2239   if(!((const MEDCouplingFieldDiscretization *)_type))
2240     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes !");
2241   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
2242   bool ret;
2243   int ret2;
2244   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->mergeNodes(eps,ret,ret2);
2245   if(!ret)//no nodes have been merged.
2246     return ret;
2247   std::vector<DataArrayDouble *> arrays;
2248   _time_discr->getArrays(arrays);
2249   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2250     if(*iter)
2251       _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2252   setMesh(meshC2);
2253   return true;
2254 }
2255
2256 /*!
2257  * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2258  * underlying mesh is replaced by a new mesh instance where the coincident nodes are
2259  * merged.<br>
2260  * In contrast to mergeNodes(), location of merged nodes is changed to be at their barycenter.
2261  *  \param [in] eps - a precision used to compare nodes of the two meshes.
2262  *  \param [in] epsOnVals - a precision used to compare field
2263  *         values at merged nodes. If the values differ more than \a epsOnVals, an
2264  *         exception is thrown.
2265  *  \return bool - \c true if some nodes have been merged and hence \a this field lies
2266  *         on another mesh.
2267  *  \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2268  *  \throw If the mesh is not well defined.
2269  *  \throw If the spatial discretization of \a this field is NULL.
2270  *  \throw If the data array is not set.
2271  *  \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2272  */
2273 bool MEDCouplingFieldDouble::mergeNodes2(double eps, double epsOnVals)
2274 {
2275   const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2276   if(!meshC)
2277     throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2278   if(!((const MEDCouplingFieldDiscretization *)_type))
2279     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes2 !");
2280   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
2281   bool ret;
2282   int ret2;
2283   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->mergeNodes2(eps,ret,ret2);
2284   if(!ret)//no nodes have been merged.
2285     return ret;
2286   std::vector<DataArrayDouble *> arrays;
2287   _time_discr->getArrays(arrays);
2288   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2289     if(*iter)
2290       _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2291   setMesh(meshC2);
2292   return true;
2293 }
2294
2295 /*!
2296  * Removes from the underlying mesh nodes not used in any cell. If some nodes are
2297  * removed, the underlying mesh is replaced by a new mesh instance where the unused
2298  * nodes are removed.<br>
2299  *  \param [in] epsOnVals - a precision used to compare field
2300  *         values at merged nodes. If the values differ more than \a epsOnVals, an
2301  *         exception is thrown.
2302  *  \return bool - \c true if some nodes have been removed and hence \a this field lies
2303  *         on another mesh.
2304  *  \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2305  *  \throw If the mesh is not well defined.
2306  *  \throw If the spatial discretization of \a this field is NULL.
2307  *  \throw If the data array is not set.
2308  *  \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2309  */
2310 bool MEDCouplingFieldDouble::zipCoords(double epsOnVals)
2311 {
2312   const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2313   if(!meshC)
2314     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2315   if(!((const MEDCouplingFieldDiscretization *)_type))
2316     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipCoords !");
2317   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
2318   int oldNbOfNodes=meshC2->getNumberOfNodes();
2319   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->zipCoordsTraducer();
2320   if(meshC2->getNumberOfNodes()!=oldNbOfNodes)
2321     {
2322       std::vector<DataArrayDouble *> arrays;
2323       _time_discr->getArrays(arrays);
2324       for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2325         if(*iter)
2326           _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2327       setMesh(meshC2);
2328       return true;
2329     }
2330   return false;
2331 }
2332
2333 /*!
2334  * Removes duplicates of cells from the understanding mesh. If some cells are
2335  * removed, the underlying mesh is replaced by a new mesh instance where the cells
2336  * duplicates are removed.<br>
2337  *  \param [in] compType - specifies a cell comparison technique. Meaning of its
2338  *          valid values [0,1,2] is explained in the description of
2339  *          MEDCouplingPointSet::zipConnectivityTraducer() which is called by this method.
2340  *  \param [in] epsOnVals - a precision used to compare field
2341  *         values at merged cells. If the values differ more than \a epsOnVals, an
2342  *         exception is thrown.
2343  *  \return bool - \c true if some cells have been removed and hence \a this field lies
2344  *         on another mesh.
2345  *  \throw If the mesh is not an instance of MEDCouplingUMesh.
2346  *  \throw If the mesh is not well defined.
2347  *  \throw If the spatial discretization of \a this field is NULL.
2348  *  \throw If the data array is not set.
2349  *  \throw If field values at merged cells (if any) deffer more than \a epsOnVals.
2350  */
2351 bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals)
2352 {
2353   const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(_mesh);
2354   if(!meshC)
2355     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipConnectivity : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2356   if(!((const MEDCouplingFieldDiscretization *)_type))
2357     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipConnectivity !");
2358   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> meshC2((MEDCouplingUMesh *)meshC->deepCpy());
2359   int oldNbOfCells=meshC2->getNumberOfCells();
2360   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->zipConnectivityTraducer(compType);
2361   if(meshC2->getNumberOfCells()!=oldNbOfCells)
2362     {
2363       std::vector<DataArrayDouble *> arrays;
2364       _time_discr->getArrays(arrays);
2365       for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2366         if(*iter)
2367           _type->renumberValuesOnCells(epsOnVals,meshC,arr->getConstPointer(),meshC2->getNumberOfCells(),*iter);
2368       setMesh(meshC2);
2369       return true;
2370     }
2371   return false;
2372 }
2373
2374 /*!
2375  * This method calls MEDCouplingUMesh::buildSlice3D method. So this method makes the assumption that underlying mesh exists.
2376  * For the moment, this method is implemented for fields on cells.
2377  * 
2378  * \return a newly allocated field double containing the result that the user should deallocate.
2379  */
2380 MEDCouplingFieldDouble *MEDCouplingFieldDouble::extractSlice3D(const double *origin, const double *vec, double eps) const
2381 {
2382   const MEDCouplingMesh *mesh=getMesh();
2383   if(!mesh)
2384     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : underlying mesh is null !");
2385   if(getTypeOfField()!=ON_CELLS)
2386     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : only implemented for fields on cells !");
2387   const MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> umesh(mesh->buildUnstructured());
2388   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);
2389   ret->setMesh(umesh);
2390   DataArrayInt *cellIds=0;
2391   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2=umesh->buildSlice3D(origin,vec,eps,cellIds);
2392   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds2=cellIds;
2393   ret->setMesh(mesh2);
2394   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tupleIds=computeTupleIdsToSelectFromCellIds(cellIds->begin(),cellIds->end());
2395   std::vector<DataArrayDouble *> arrays;
2396   _time_discr->getArrays(arrays);
2397   int i=0;
2398   std::vector<DataArrayDouble *> newArr(arrays.size());
2399   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > newArr2(arrays.size());
2400   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,i++)
2401     {
2402       if(*iter)
2403         {
2404           newArr2[i]=(*iter)->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
2405           newArr[i]=newArr2[i];
2406         }
2407     }
2408   ret->setArrays(newArr);
2409   return ret.retn();
2410 }
2411
2412 /*!
2413  * Divides every cell of the underlying mesh into simplices (triangles in 2D and
2414  * tetrahedra in 3D). If some cells are divided, the underlying mesh is replaced by a new
2415  * mesh instance containing the simplices.<br> 
2416  *  \param [in] policy - specifies a pattern used for splitting. For its description, see
2417  *          MEDCouplingUMesh::simplexize().
2418  *  \return bool - \c true if some cells have been divided and hence \a this field lies
2419  *         on another mesh.
2420  *  \throw If \a policy has an invalid value. For valid values, see the description of 
2421  *         MEDCouplingUMesh::simplexize().
2422  *  \throw If MEDCouplingMesh::simplexize() is not applicable to the underlying mesh.
2423  *  \throw If the mesh is not well defined.
2424  *  \throw If the spatial discretization of \a this field is NULL.
2425  *  \throw If the data array is not set.
2426  */
2427 bool MEDCouplingFieldDouble::simplexize(int policy)
2428 {
2429   if(!_mesh)
2430     throw INTERP_KERNEL::Exception("No underlying mesh on this field to perform simplexize !");
2431   if(!((const MEDCouplingFieldDiscretization *)_type))
2432     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform simplexize !");
2433   int oldNbOfCells=_mesh->getNumberOfCells();
2434   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> meshC2(_mesh->deepCpy());
2435   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->simplexize(policy);
2436   int newNbOfCells=meshC2->getNumberOfCells();
2437   if(oldNbOfCells==newNbOfCells)
2438     return false;
2439   std::vector<DataArrayDouble *> arrays;
2440   _time_discr->getArrays(arrays);
2441   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2442     if(*iter)
2443       _type->renumberValuesOnCellsR(_mesh,arr->getConstPointer(),arr->getNbOfElems(),*iter);
2444   setMesh(meshC2);
2445   return true;
2446 }
2447
2448 /*!
2449  * Creates a new MEDCouplingFieldDouble filled with the doubly contracted product of
2450  * every tensor of \a this 6-componental field.
2451  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2452  *          each tuple is calculated from the tuple <em>(t)</em> of \a this field as
2453  *          follows: \f$ t[0]^2+t[1]^2+t[2]^2+2*t[3]^2+2*t[4]^2+2*t[5]^2\f$. 
2454  *          This new field lies on the same mesh as \a this one. The caller is to delete
2455  *          this field using decrRef() as it is no more needed.
2456  *  \throw If \a this->getNumberOfComponents() != 6.
2457  *  \throw If the spatial discretization of \a this field is NULL.
2458  */
2459 MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const
2460 {
2461   if(!((const MEDCouplingFieldDiscretization *)_type))
2462     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform doublyContractedProduct !");
2463   MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct();
2464   td->copyTinyAttrFrom(*_time_discr);
2465   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2466   ret->setName("DoublyContractedProduct");
2467   ret->setMesh(getMesh());
2468   return ret.retn();
2469 }
2470
2471 /*!
2472  * Creates a new MEDCouplingFieldDouble filled with the determinant of a square
2473  * matrix defined by every tuple of \a this field, having either 4, 6 or 9 components.
2474  * The case of 6 components corresponds to that of the upper triangular matrix. 
2475  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2476  *          each tuple is the determinant of matrix of the corresponding tuple of \a this 
2477  *          field. This new field lies on the same mesh as \a this one. The caller is to 
2478  *          delete this field using decrRef() as it is no more needed.
2479  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2480  *  \throw If the spatial discretization of \a this field is NULL.
2481  */
2482 MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const
2483 {
2484   if(!((const MEDCouplingFieldDiscretization *)_type))
2485     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform determinant !");
2486   MEDCouplingTimeDiscretization *td=_time_discr->determinant();
2487   td->copyTinyAttrFrom(*_time_discr);
2488   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2489   ret->setName("Determinant");
2490   ret->setMesh(getMesh());
2491   return ret.retn();
2492 }
2493
2494
2495 /*!
2496  * Creates a new MEDCouplingFieldDouble with 3 components filled with 3 eigenvalues of
2497  * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2498  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2499  *          having 3 components, whose each tuple contains the eigenvalues of the matrix of
2500  *          corresponding tuple of \a this field. This new field lies on the same mesh as
2501  *          \a this one. The caller is to delete this field using decrRef() as it is no
2502  *          more needed.  
2503  *  \throw If \a this->getNumberOfComponents() != 6.
2504  *  \throw If the spatial discretization of \a this field is NULL.
2505  */
2506 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const
2507 {
2508   if(!((const MEDCouplingFieldDiscretization *)_type))
2509     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenValues !");
2510   MEDCouplingTimeDiscretization *td=_time_discr->eigenValues();
2511   td->copyTinyAttrFrom(*_time_discr);
2512   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2513   ret->setName("EigenValues");
2514   ret->setMesh(getMesh());
2515   return ret.retn();
2516 }
2517
2518 /*!
2519  * Creates a new MEDCouplingFieldDouble with 9 components filled with 3 eigenvectors of
2520  * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2521  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2522  *          having 9 components, whose each tuple contains the eigenvectors of the matrix of
2523  *          corresponding tuple of \a this field. This new field lies on the same mesh as
2524  *          \a this one. The caller is to delete this field using decrRef() as it is no
2525  *          more needed.  
2526  *  \throw If \a this->getNumberOfComponents() != 6.
2527  *  \throw If the spatial discretization of \a this field is NULL.
2528  */
2529 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const
2530 {
2531   if(!((const MEDCouplingFieldDiscretization *)_type))
2532     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenVectors !");
2533   MEDCouplingTimeDiscretization *td=_time_discr->eigenVectors();
2534   td->copyTinyAttrFrom(*_time_discr);
2535   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2536   ret->setName("EigenVectors");
2537   ret->setMesh(getMesh());
2538   return ret.retn();
2539 }
2540
2541 /*!
2542  * Creates a new MEDCouplingFieldDouble filled with the inverse matrix of
2543  * a matrix defined by every tuple of \a this field having either 4, 6 or 9
2544  * components. The case of 6 components corresponds to that of the upper triangular
2545  * matrix.
2546  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2547  *          having the same number of components as \a this one, whose each tuple
2548  *          contains the inverse matrix of the matrix of corresponding tuple of \a this
2549  *          field. This new field lies on the same mesh as \a this one. The caller is to
2550  *          delete this field using decrRef() as it is no more needed.  
2551  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2552  *  \throw If the spatial discretization of \a this field is NULL.
2553  */
2554 MEDCouplingFieldDouble *MEDCouplingFieldDouble::inverse() const
2555 {
2556   if(!((const MEDCouplingFieldDiscretization *)_type))
2557     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform inverse !");
2558   MEDCouplingTimeDiscretization *td=_time_discr->inverse();
2559   td->copyTinyAttrFrom(*_time_discr);
2560   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2561   ret->setName("Inversion");
2562   ret->setMesh(getMesh());
2563   return ret.retn();
2564 }
2565
2566 /*!
2567  * Creates a new MEDCouplingFieldDouble filled with the trace of
2568  * a matrix defined by every tuple of \a this field having either 4, 6 or 9
2569  * components. The case of 6 components corresponds to that of the upper triangular
2570  * matrix.
2571  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2572  *          having 1 component, whose each tuple is the trace of the matrix of
2573  *          corresponding tuple of \a this field.
2574  *          This new field lies on the same mesh as \a this one. The caller is to
2575  *          delete this field using decrRef() as it is no more needed.  
2576  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2577  *  \throw If the spatial discretization of \a this field is NULL.
2578  */
2579 MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const
2580 {
2581   if(!((const MEDCouplingFieldDiscretization *)_type))
2582     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform trace !");
2583   MEDCouplingTimeDiscretization *td=_time_discr->trace();
2584   td->copyTinyAttrFrom(*_time_discr);
2585   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2586   ret->setName("Trace");
2587   ret->setMesh(getMesh());
2588   return ret.retn();
2589 }
2590
2591 /*!
2592  * Creates a new MEDCouplingFieldDouble filled with the stress deviator tensor of
2593  * a stress tensor defined by every tuple of \a this 6-componental field.
2594  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2595  *          having same number of components and tuples as \a this field,
2596  *          whose each tuple contains the stress deviator tensor of the stress tensor of
2597  *          corresponding tuple of \a this field. This new field lies on the same mesh as
2598  *          \a this one. The caller is to delete this field using decrRef() as it is no
2599  *          more needed.  
2600  *  \throw If \a this->getNumberOfComponents() != 6.
2601  *  \throw If the spatial discretization of \a this field is NULL.
2602  */
2603 MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const
2604 {
2605   if(!((const MEDCouplingFieldDiscretization *)_type))
2606     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform deviator !");
2607   MEDCouplingTimeDiscretization *td=_time_discr->deviator();
2608   td->copyTinyAttrFrom(*_time_discr);
2609   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2610   ret->setName("Deviator");
2611   ret->setMesh(getMesh());
2612   return ret.retn();
2613 }
2614
2615 /*!
2616  * Creates a new MEDCouplingFieldDouble filled with the magnitude of
2617  * every vector of \a this field.
2618  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2619  *          having one component, whose each tuple is the magnitude of the vector
2620  *          of corresponding tuple of \a this field. This new field lies on the
2621  *          same mesh as \a this one. The caller is to
2622  *          delete this field using decrRef() as it is no more needed.  
2623  *  \throw If the spatial discretization of \a this field is NULL.
2624  */
2625 MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const
2626 {
2627   if(!((const MEDCouplingFieldDiscretization *)_type))
2628     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform magnitude !");
2629   MEDCouplingTimeDiscretization *td=_time_discr->magnitude();
2630   td->copyTinyAttrFrom(*_time_discr);
2631   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2632   ret->setName("Magnitude");
2633   ret->setMesh(getMesh());
2634   return ret.retn();
2635 }
2636
2637 /*!
2638  * Creates a new scalar MEDCouplingFieldDouble filled with the maximal value among
2639  * values of every tuple of \a this field.
2640  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2641  *          This new field lies on the same mesh as \a this one. The caller is to
2642  *          delete this field using decrRef() as it is no more needed.  
2643  *  \throw If the spatial discretization of \a this field is NULL.
2644  */
2645 MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const
2646 {
2647   if(!((const MEDCouplingFieldDiscretization *)_type))
2648     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform maxPerTuple !");
2649   MEDCouplingTimeDiscretization *td=_time_discr->maxPerTuple();
2650   td->copyTinyAttrFrom(*_time_discr);
2651   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2652   std::ostringstream oss;
2653   oss << "Max_" << getName();
2654   ret->setName(oss.str());
2655   ret->setMesh(getMesh());
2656   return ret.retn();
2657 }
2658
2659 /*!
2660  * Changes number of components in \a this field. If \a newNbOfComp is less
2661  * than \a this->getNumberOfComponents() then each tuple
2662  * is truncated to have \a newNbOfComp components, keeping first components. If \a
2663  * newNbOfComp is more than \a this->getNumberOfComponents() then 
2664  * each tuple is populated with \a dftValue to have \a newNbOfComp components.  
2665  *  \param [in] newNbOfComp - number of components for the new field to have.
2666  *  \param [in] dftValue - value assigned to new values added to \a this field.
2667  *  \throw If \a this is not allocated.
2668  */
2669 void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftValue)
2670 {
2671   _time_discr->changeNbOfComponents(newNbOfComp,dftValue);
2672 }
2673
2674 /*!
2675  * Creates a new MEDCouplingFieldDouble composed of selected components of \a this field.
2676  * The new MEDCouplingFieldDouble has the same number of tuples but includes components
2677  * specified by \a compoIds parameter. So that getNbOfElems() of the result field
2678  * can be either less, same or more than \a this->getNumberOfValues().
2679  *  \param [in] compoIds - sequence of zero based indices of components to include
2680  *              into the new field.
2681  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble that the caller
2682  *          is to delete using decrRef() as it is no more needed.
2683  *  \throw If a component index (\a i) is not valid: 
2684  *         \a i < 0 || \a i >= \a this->getNumberOfComponents().
2685  */
2686 MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std::vector<int>& compoIds) const
2687 {
2688   if(!((const MEDCouplingFieldDiscretization *)_type))
2689     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform keepSelectedComponents !");
2690   MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds);
2691   td->copyTinyAttrFrom(*_time_discr);
2692   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2693   ret->setName(getName());
2694   ret->setMesh(getMesh());
2695   return ret.retn();
2696 }
2697
2698
2699 /*!
2700  * Copy all components in a specified order from another field.
2701  * The number of tuples in \a this and the other field can be different.
2702  *  \param [in] f - the field to copy data from.
2703  *  \param [in] compoIds - sequence of zero based indices of components, data of which is
2704  *              to be copied.
2705  *  \throw If the two fields have different number of data arrays.
2706  *  \throw If a data array is set in one of fields and is not set in the other.
2707  *  \throw If \a compoIds.size() != \a a->getNumberOfComponents().
2708  *  \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
2709  */
2710 void MEDCouplingFieldDouble::setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector<int>& compoIds)
2711 {
2712   _time_discr->setSelectedComponents(f->_time_discr,compoIds);
2713 }
2714
2715 /*!
2716  * Sorts value within every tuple of \a this field.
2717  *  \param [in] asc - if \a true, the values are sorted in ascending order, else,
2718  *              in descending order.
2719  *  \throw If a data array is not allocated.
2720  */
2721 void MEDCouplingFieldDouble::sortPerTuple(bool asc)
2722 {
2723   _time_discr->sortPerTuple(asc);
2724 }
2725
2726 /*!
2727  * Creates a new MEDCouplingFieldDouble by concatenating two given fields.
2728  * Values of
2729  * the first field precede values of the second field within the result field.
2730  *  \param [in] f1 - the first field.
2731  *  \param [in] f2 - the second field.
2732  *  \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2733  *          MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef() 
2734  *          as it is no more needed.
2735  *  \throw If the fields are not compatible for the merge.
2736  *  \throw If the spatial discretization of \a f1 is NULL.
2737  *  \throw If the time discretization of \a f1 is NULL.
2738  *
2739  *  \if ENABLE_EXAMPLES
2740  *  \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2741  *  \ref  py_mcfielddouble_MergeFields "Here is a Python example".
2742  *  \endif
2743  */
2744 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2745 {
2746   if(!f1->areCompatibleForMerge(f2))
2747     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !");
2748   const MEDCouplingMesh *m1(f1->getMesh()),*m2(f2->getMesh());
2749   if(!f1->_time_discr)
2750     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no time discr of f1 !");
2751   if(!f1->_type)
2752     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no spatial discr of f1 !");
2753   MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr);
2754   td->copyTinyAttrFrom(*f1->_time_discr);
2755   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2756   ret->setName(f1->getName());
2757   ret->setDescription(f1->getDescription());
2758   if(m1)
2759     {
2760       MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=m1->mergeMyselfWith(m2);
2761       ret->setMesh(m);
2762     }
2763   return ret.retn();
2764 }
2765
2766 /*!
2767  * Creates a new MEDCouplingFieldDouble by concatenating all given fields.
2768  * Values of the *i*-th field precede values of the (*i*+1)-th field within the result.
2769  * If there is only one field in \a a, a deepCopy() (except time information of mesh and
2770  * field) of the field is returned. 
2771  * Generally speaking the first field in \a a is used to assign tiny attributes of the
2772  * returned field. 
2773  *  \param [in] a - a vector of fields (MEDCouplingFieldDouble) to concatenate.
2774  *  \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2775  *          MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef() 
2776  *          as it is no more needed.
2777  *  \throw If \a a is empty.
2778  *  \throw If the fields are not compatible for the merge.
2779  *
2780  *  \if ENABLE_EXAMPLES
2781  *  \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2782  *  \ref  py_mcfielddouble_MergeFields "Here is a Python example".
2783  *  \endif
2784  */
2785 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector<const MEDCouplingFieldDouble *>& a)
2786 {
2787   if(a.size()<1)
2788     throw INTERP_KERNEL::Exception("FieldDouble::MergeFields : size of array must be >= 1 !");
2789   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > ms(a.size());
2790   std::vector< const MEDCouplingUMesh *> ms2(a.size());
2791   std::vector< const MEDCouplingTimeDiscretization *> tds(a.size());
2792   std::vector<const MEDCouplingFieldDouble *>::const_iterator it=a.begin();
2793   const MEDCouplingFieldDouble *ref=(*it++);
2794   if(!ref)
2795     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : presence of NULL instance in first place of input vector !");
2796   for(;it!=a.end();it++)
2797     if(!ref->areCompatibleForMerge(*it))
2798       throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !");
2799   for(int i=0;i<(int)a.size();i++)
2800     {
2801       if(a[i]->getMesh())
2802         { ms[i]=a[i]->getMesh()->buildUnstructured(); ms2[i]=ms[i]; }
2803       else
2804         { ms[i]=0; ms2[i]=0; }
2805       tds[i]=a[i]->_time_discr;
2806     }
2807   MEDCouplingTimeDiscretization *td=tds[0]->aggregate(tds);
2808   td->copyTinyAttrFrom(*(a[0]->_time_discr));
2809   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone());
2810   ret->setName(a[0]->getName());
2811   ret->setDescription(a[0]->getDescription());
2812   if(ms2[0])
2813     {
2814       MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDCouplingUMesh::MergeUMeshes(ms2);
2815       m->copyTinyInfoFrom(ms2[0]);
2816       ret->setMesh(m);
2817     }
2818   return ret.retn();
2819 }
2820
2821 /*!
2822  * Creates a new MEDCouplingFieldDouble by concatenating components of two given fields.
2823  * The number of components in the result field is a sum of the number of components of
2824  * given fields. The number of tuples in the result field is same as that of each of given
2825  * arrays.
2826  * Number of tuples in the given fields must be the same.
2827  *  \param [in] f1 - a field to include in the result field.
2828  *  \param [in] f2 - another field to include in the result field.
2829  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2830  *          The caller is to delete this result field using decrRef() as it is no more
2831  *          needed.
2832  *  \throw If the fields are not compatible for a meld (areCompatibleForMeld()).
2833  *  \throw If any of data arrays is not allocated.
2834  *  \throw If \a f1->getNumberOfTuples() != \a f2->getNumberOfTuples()
2835  */
2836 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MeldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2837 {
2838   if(!f1->areCompatibleForMeld(f2))
2839     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MeldFields on them !");
2840   MEDCouplingTimeDiscretization *td=f1->_time_discr->meld(f2->_time_discr);
2841   td->copyTinyAttrFrom(*f1->_time_discr);
2842   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2843   ret->setMesh(f1->getMesh());
2844   return ret.retn();
2845 }
2846
2847 /*!
2848  * Returns a new MEDCouplingFieldDouble containing a dot product of two given fields, 
2849  * so that the i-th tuple of the result field is a sum of products of j-th components of
2850  * i-th tuples of given fields (\f$ f_i = \sum_{j=1}^n f1_j * f2_j \f$). 
2851  * Number of tuples and components in the given fields must be the same.
2852  *  \param [in] f1 - a given field.
2853  *  \param [in] f2 - another given field.
2854  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2855  *          The caller is to delete this result field using decrRef() as it is no more
2856  *          needed.
2857  *  \throw If either \a f1 or \a f2 is NULL.
2858  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2859  *         differ not only in values.
2860  */
2861 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2862 {
2863   if(!f1)
2864     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DotFields : input field is NULL !");
2865   if(!f1->areStrictlyCompatible(f2))
2866     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DotFields on them !");
2867   MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr);
2868   td->copyTinyAttrFrom(*f1->_time_discr);
2869   MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2870   ret->setMesh(f1->getMesh());
2871   return ret;
2872 }
2873
2874 /*!
2875  * Returns a new MEDCouplingFieldDouble containing a cross product of two given fields, 
2876  * so that
2877  * the i-th tuple of the result field is a 3D vector which is a cross
2878  * product of two vectors defined by the i-th tuples of given fields.
2879  * Number of tuples in the given fields must be the same.
2880  * Number of components in the given fields must be 3.
2881  *  \param [in] f1 - a given field.
2882  *  \param [in] f2 - another given field.
2883  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2884  *          The caller is to delete this result field using decrRef() as it is no more
2885  *          needed.
2886  *  \throw If either \a f1 or \a f2 is NULL.
2887  *  \throw If \a f1->getNumberOfComponents() != 3
2888  *  \throw If \a f2->getNumberOfComponents() != 3
2889  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2890  *         differ not only in values.
2891  */
2892 MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2893 {
2894   if(!f1)
2895     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::CrossProductFields : input field is NULL !");
2896   if(!f1->areStrictlyCompatible(f2))
2897     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply CrossProductFields on them !");
2898   MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr);
2899   td->copyTinyAttrFrom(*f1->_time_discr);
2900   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2901   ret->setMesh(f1->getMesh());
2902   return ret.retn();
2903 }
2904
2905 /*!
2906  * Returns a new MEDCouplingFieldDouble containing maximal values of two given fields.
2907  * Number of tuples and components in the given fields must be the same.
2908  *  \param [in] f1 - a field to compare values with another one.
2909  *  \param [in] f2 - another field to compare values with the first one.
2910  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2911  *          The caller is to delete this result field using decrRef() as it is no more
2912  *          needed.
2913  *  \throw If either \a f1 or \a f2 is NULL.
2914  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2915  *         differ not only in values.
2916  *
2917  *  \if ENABLE_EXAMPLES
2918  *  \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2919  *  \ref  py_mcfielddouble_MaxFields "Here is a Python example".
2920  *  \endif
2921  */
2922 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2923 {
2924   if(!f1)
2925     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MaxFields : input field is NULL !");
2926   if(!f1->areStrictlyCompatible(f2))
2927     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MaxFields on them !");
2928   MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr);
2929   td->copyTinyAttrFrom(*f1->_time_discr);
2930   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2931   ret->setMesh(f1->getMesh());
2932   return ret.retn();
2933 }
2934
2935 /*!
2936  * Returns a new MEDCouplingFieldDouble containing minimal values of two given fields.
2937  * Number of tuples and components in the given fields must be the same.
2938  *  \param [in] f1 - a field to compare values with another one.
2939  *  \param [in] f2 - another field to compare values with the first one.
2940  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2941  *          The caller is to delete this result field using decrRef() as it is no more
2942  *          needed.
2943  *  \throw If either \a f1 or \a f2 is NULL.
2944  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2945  *         differ not only in values.
2946  *
2947  *  \if ENABLE_EXAMPLES
2948  *  \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2949  *  \ref  py_mcfielddouble_MaxFields "Here is a Python example".
2950  *  \endif
2951  */
2952 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2953 {
2954   if(!f1)
2955     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MinFields : input field is NULL !");
2956   if(!f1->areStrictlyCompatible(f2))
2957     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MinFields on them !");
2958   MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr);
2959   td->copyTinyAttrFrom(*f1->_time_discr);
2960   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2961   ret->setMesh(f1->getMesh());
2962   return ret.retn();
2963 }
2964
2965 /*!
2966  * Returns a copy of \a this field in which sign of all values is reversed.
2967  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble
2968  *         containing the same number of tuples and components as \a this field. 
2969  *         The caller is to delete this result field using decrRef() as it is no more
2970  *         needed. 
2971  *  \throw If the spatial discretization of \a this field is NULL.
2972  *  \throw If a data array is not allocated.
2973  */
2974 MEDCouplingFieldDouble *MEDCouplingFieldDouble::negate() const
2975 {
2976   if(!((const MEDCouplingFieldDiscretization *)_type))
2977     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform negate !");
2978   MEDCouplingTimeDiscretization *td=_time_discr->negate();
2979   td->copyTinyAttrFrom(*_time_discr);
2980   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2981   ret->setMesh(getMesh());
2982   return ret.retn();
2983 }
2984
2985 /*!
2986  * Returns a new MEDCouplingFieldDouble containing sum values of corresponding values of
2987  * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] + _f2_ [ i, j ] ).
2988  * Number of tuples and components in the given fields must be the same.
2989  *  \param [in] f1 - a field to sum up.
2990  *  \param [in] f2 - another field to sum up.
2991  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2992  *          The caller is to delete this result field using decrRef() as it is no more
2993  *          needed.
2994  *  \throw If either \a f1 or \a f2 is NULL.
2995  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2996  *         differ not only in values.
2997  */
2998 MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2999 {
3000   if(!f1)
3001     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::AddFields : input field is NULL !");
3002   if(!f1->areStrictlyCompatible(f2))
3003     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply AddFields on them !");
3004   MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr);
3005   td->copyTinyAttrFrom(*f1->_time_discr);
3006   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3007   ret->setMesh(f1->getMesh());
3008   return ret.retn();
3009 }
3010
3011 /*!
3012  * Adds values of another MEDCouplingFieldDouble to values of \a this one
3013  * ( _this_ [ i, j ] += _other_ [ i, j ] ) using DataArrayDouble::addEqual().
3014  * The two fields must have same number of tuples, components and same underlying mesh.
3015  *  \param [in] other - the field to add to \a this one.
3016  *  \return const MEDCouplingFieldDouble & - a reference to \a this field.
3017  *  \throw If \a other is NULL.
3018  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3019  *         differ not only in values.
3020  */
3021 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other)
3022 {
3023   if(!areStrictlyCompatible(&other))
3024     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply += on them !");
3025   _time_discr->addEqual(other._time_discr);
3026   return *this;
3027 }
3028
3029 /*!
3030  * Returns a new MEDCouplingFieldDouble containing subtraction of corresponding values of
3031  * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] - _f2_ [ i, j ] ).
3032  * Number of tuples and components in the given fields must be the same.
3033  *  \param [in] f1 - a field to subtract from.
3034  *  \param [in] f2 - a field to subtract.
3035  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
3036  *          The caller is to delete this result field using decrRef() as it is no more
3037  *          needed.
3038  *  \throw If either \a f1 or \a f2 is NULL.
3039  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3040  *         differ not only in values.
3041  */
3042 MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3043 {
3044   if(!f1)
3045     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::SubstractFields : input field is NULL !");
3046   if(!f1->areStrictlyCompatible(f2))
3047     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply SubstractFields on them !");
3048   MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr);
3049   td->copyTinyAttrFrom(*f1->_time_discr);
3050   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3051   ret->setMesh(f1->getMesh());
3052   return ret.retn();
3053 }
3054
3055 /*!
3056  * Subtract values of another MEDCouplingFieldDouble from values of \a this one
3057  * ( _this_ [ i, j ] -= _other_ [ i, j ] ) using DataArrayDouble::substractEqual().
3058  * The two fields must have same number of tuples, components and same underlying mesh.
3059  *  \param [in] other - the field to subtract from \a this one.
3060  *  \return const MEDCouplingFieldDouble & - a reference to \a this field.
3061  *  \throw If \a other is NULL.
3062  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3063  *         differ not only in values.
3064  */
3065 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other)
3066 {
3067   if(!areStrictlyCompatible(&other))
3068     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply -= on them !");
3069   _time_discr->substractEqual(other._time_discr);
3070   return *this;
3071 }
3072
3073 /*!
3074  * Returns a new MEDCouplingFieldDouble containing product values of
3075  * two given fields. There are 2 valid cases.
3076  * 1.  The fields have same number of tuples and components. Then each value of
3077  *   the result field (_f_) is a product of the corresponding values of _f1_ and
3078  *   _f2_, i.e. _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, j ].
3079  * 2.  The fields have same number of tuples and one field, say _f2_, has one
3080  *   component. Then
3081  *   _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, 0 ].
3082  *
3083  * The two fields must have same number of tuples and same underlying mesh.
3084  *  \param [in] f1 - a factor field.
3085  *  \param [in] f2 - another factor field.
3086  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
3087  *          The caller is to delete this result field using decrRef() as it is no more
3088  *          needed.
3089  *  \throw If either \a f1 or \a f2 is NULL.
3090  *  \throw If the fields are not compatible for production (areCompatibleForMul()),
3091  *         i.e. they differ not only in values and possibly number of components.
3092  */
3093 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3094 {
3095   if(!f1)
3096     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MultiplyFields : input field is NULL !");
3097   if(!f1->areCompatibleForMul(f2))
3098     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MultiplyFields on them !");
3099   MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr);
3100   td->copyTinyAttrFrom(*f1->_time_discr);
3101   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3102   ret->setMesh(f1->getMesh());
3103   return ret.retn();
3104 }
3105
3106 /*!
3107  * Multiply values of another MEDCouplingFieldDouble to values of \a this one
3108  * using DataArrayDouble::multiplyEqual().
3109  * The two fields must have same number of tuples and same underlying mesh.
3110  * There are 2 valid cases.
3111  * 1.  The fields have same number of components. Then each value of
3112  *   \a other is multiplied to the corresponding value of \a this field, i.e.
3113  *   _this_ [ i, j ] *= _other_ [ i, j ].
3114  * 2. The _other_ field has one component. Then
3115  *   _this_ [ i, j ] *= _other_ [ i, 0 ].
3116  *
3117  * The two fields must have same number of tuples and same underlying mesh.
3118  *  \param [in] other - an field to multiply to \a this one.
3119  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
3120  *          The caller is to delete this result field using decrRef() as it is no more
3121  *          needed.
3122  *  \throw If \a other is NULL.
3123  *  \throw If the fields are not strictly compatible for production
3124  *         (areCompatibleForMul()),
3125  *         i.e. they differ not only in values and possibly in number of components.
3126  */
3127 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other)
3128 {
3129   if(!areCompatibleForMul(&other))
3130     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply *= on them !");
3131   _time_discr->multiplyEqual(other._time_discr);
3132   return *this;
3133 }
3134
3135 /*!
3136  * Returns a new MEDCouplingFieldDouble containing division of two given fields.
3137  * There are 2 valid cases.
3138  * 1.  The fields have same number of tuples and components. Then each value of
3139  *   the result field (_f_) is a division of the corresponding values of \a f1 and
3140  *   \a f2, i.e. _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, j ].
3141  * 2.  The fields have same number of tuples and _f2_ has one component. Then
3142  *   _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, 0 ].
3143  *
3144  *  \param [in] f1 - a numerator field.
3145  *  \param [in] f2 - a denominator field.
3146  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
3147  *          The caller is to delete this result field using decrRef() as it is no more
3148  *          needed.
3149  *  \throw If either \a f1 or \a f2 is NULL.
3150  *  \throw If the fields are not compatible for division (areCompatibleForDiv()),
3151  *         i.e. they differ not only in values and possibly in number of components.
3152  */
3153 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3154 {
3155   if(!f1)
3156     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DivideFields : input field is NULL !");
3157   if(!f1->areCompatibleForDiv(f2))
3158     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DivideFields on them !");
3159   MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr);
3160   td->copyTinyAttrFrom(*f1->_time_discr);
3161   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3162   ret->setMesh(f1->getMesh());
3163   return ret.retn();
3164 }
3165
3166 /*!
3167  * Divide values of \a this field by values of another MEDCouplingFieldDouble
3168  * using DataArrayDouble::divideEqual().
3169  * The two fields must have same number of tuples and same underlying mesh.
3170  * There are 2 valid cases.
3171  * 1.  The fields have same number of components. Then each value of
3172  *    \a this field is divided by the corresponding value of \a other one, i.e.
3173  *   _this_ [ i, j ] /= _other_ [ i, j ].
3174  * 2.  The \a other field has one component. Then
3175  *   _this_ [ i, j ] /= _other_ [ i, 0 ].
3176  *
3177  *  \warning No check of division by zero is performed!
3178  *  \param [in] other - an field to divide \a this one by.
3179  *  \throw If \a other is NULL.
3180  *  \throw If the fields are not compatible for division (areCompatibleForDiv()),
3181  *         i.e. they differ not only in values and possibly in number of components.
3182  */
3183 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other)
3184 {
3185   if(!areCompatibleForDiv(&other))
3186     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !");
3187   _time_discr->divideEqual(other._time_discr);
3188   return *this;
3189 }
3190
3191 /*!
3192  * Directly called by MEDCouplingFieldDouble::operator^.
3193  * 
3194  * \sa MEDCouplingFieldDouble::operator^
3195  */
3196 MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3197 {
3198   if(!f1)
3199     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::PowFields : input field is NULL !");
3200   if(!f1->areCompatibleForMul(f2))
3201     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply PowFields on them !");
3202   MEDCouplingTimeDiscretization *td=f1->_time_discr->pow(f2->_time_discr);
3203   td->copyTinyAttrFrom(*f1->_time_discr);
3204   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3205   ret->setMesh(f1->getMesh());
3206   return ret.retn();
3207 }
3208
3209 /*!
3210  * Directly call MEDCouplingFieldDouble::PowFields static method.
3211  * 
3212  * \sa MEDCouplingFieldDouble::PowFields
3213  */
3214 MEDCouplingFieldDouble *MEDCouplingFieldDouble::operator^(const MEDCouplingFieldDouble& other) const
3215 {
3216   return PowFields(this,&other);
3217 }
3218
3219 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCouplingFieldDouble& other)
3220 {
3221   if(!areCompatibleForDiv(&other))
3222     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !");
3223   _time_discr->powEqual(other._time_discr);
3224   return *this;
3225 }
3226
3227 /*!
3228  * Writes the field series \a fs and the mesh the fields lie on in the VTK file \a fileName.
3229  * If \a fs is empty no file is written.
3230  * The result file is valid provided that no exception is thrown.
3231  * \warning All the fields must be named and lie on the same non NULL mesh.
3232  *  \param [in] fileName - the name of a VTK file to write in.
3233  *  \param [in] fs - the fields to write.
3234  *  \param [in] isBinary - specifies the VTK format of the written file. By default true (Binary mode)
3235  *  \throw If \a fs[ 0 ] == NULL.
3236  *  \throw If the fields lie not on the same mesh.
3237  *  \throw If the mesh is not set.
3238  *  \throw If any of the fields has no name.
3239  *
3240  *  \if ENABLE_EXAMPLES
3241  *  \ref cpp_mcfielddouble_WriteVTK "Here is a C++ example".<br>
3242  *  \ref  py_mcfielddouble_WriteVTK "Here is a Python example".
3243  *  \endif
3244  */
3245 void MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const std::vector<const MEDCouplingFieldDouble *>& fs, bool isBinary)
3246 {
3247   if(fs.empty())
3248     return;
3249   std::size_t nfs=fs.size();
3250   if(!fs[0])
3251     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field is NULL !");
3252   const MEDCouplingMesh *m=fs[0]->getMesh();
3253   if(!m)
3254     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field lies on NULL mesh !");
3255   for(std::size_t i=1;i<nfs;i++)
3256     if(fs[i]->getMesh()!=m)
3257       throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are not lying on a same mesh ! Expected by VTK ! MEDCouplingFieldDouble::setMesh or MEDCouplingFieldDouble::changeUnderlyingMesh can help to that.");
3258   if(!m)
3259     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are lying on a same mesh but it is empty !");
3260   MEDCouplingAutoRefCountObjectPtr<DataArrayByte> byteArr;
3261   if(isBinary)
3262     { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); }
3263   std::ostringstream coss,noss;
3264   for(std::size_t i=0;i<nfs;i++)
3265     {
3266       const MEDCouplingFieldDouble *cur=fs[i];
3267       std::string name(cur->getName());
3268       if(name.empty())
3269         {
3270           std::ostringstream oss; oss << "MEDCouplingFieldDouble::WriteVTK : Field in pos #" << i << " has no name !";
3271           throw INTERP_KERNEL::Exception(oss.str().c_str());
3272         }
3273       TypeOfField typ=cur->getTypeOfField();
3274       if(typ==ON_CELLS)
3275         cur->getArray()->writeVTK(coss,8,cur->getName(),byteArr);
3276       else if(typ==ON_NODES)
3277         cur->getArray()->writeVTK(noss,8,cur->getName(),byteArr);
3278       else
3279         throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : only node and cell fields supported for the moment !");
3280     }
3281   m->writeVTKAdvanced(fileName,coss.str(),noss.str(),byteArr);
3282 }
3283
3284 void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const
3285 {
3286   stream << "MEDCouplingFieldDouble C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
3287   const char *nat=0;
3288   try
3289   {
3290       nat=MEDCouplingNatureOfField::GetRepr(_nature);
3291       stream << "Nature of field : " << nat << ".\n";
3292   }
3293   catch(INTERP_KERNEL::Exception& /*e*/)
3294   {  }
3295   const MEDCouplingFieldDiscretization *fd(_type);
3296   if(!fd)
3297     stream << "No spatial discretization set !";
3298   else
3299     fd->reprQuickOverview(stream);
3300   stream << std::endl;
3301   if(!_mesh)
3302     stream << "\nNo mesh support defined !";
3303   else
3304     {
3305       std::ostringstream oss;
3306       _mesh->reprQuickOverview(oss);
3307       std::string tmp(oss.str());
3308       stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
3309     }
3310   if(_time_discr)
3311     {
3312       const DataArrayDouble *arr=_time_discr->getArray();
3313       if(arr)
3314         {
3315           stream << "\n\nArray info : ";
3316           arr->reprQuickOverview(stream);
3317         }
3318       else
3319         {
3320           stream << "\n\nNo data array set !";
3321         }
3322     }
3323 }