Salome HOME
Very first implementation of MEDCouplingFieldInt.
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingFieldDouble.cxx
1 // Copyright (C) 2007-2016  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 "MCAuto.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 MEDCoupling;
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 MEDCoupling::ON_CELLS "ON_CELLS", 
44  *         \ref MEDCoupling::ON_NODES "ON_NODES",
45  *         \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
46  *         \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
47  *         \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
48  * \param [in] td - the type of time discretization of the created field, one of
49  *        (\ref MEDCoupling::NO_TIME "NO_TIME", 
50  *         \ref MEDCoupling::ONE_TIME "ONE_TIME", 
51  *         \ref MEDCoupling::LINEAR_TIME "LINEAR_TIME", 
52  *         \ref MEDCoupling::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 MEDCoupling::NO_TIME "NO_TIME", 
73  *         \ref MEDCoupling::ONE_TIME "ONE_TIME", 
74  *         \ref MEDCoupling::LINEAR_TIME "LINEAR_TIME", 
75  *         \ref MEDCoupling::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 deepCopy() 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 deepCopy().
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   MCAuto<MEDCouplingFieldDouble> ret=clone(recDeepCpy);
164   if(_mesh)
165     {
166       MCAuto<MEDCouplingMesh> mCpy=_mesh->deepCopy();
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::deepCopy() 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 MEDCoupling::NO_TIME "NO_TIME", 
195  *         \ref MEDCoupling::ONE_TIME "ONE_TIME", 
196  *         \ref MEDCoupling::LINEAR_TIME "LINEAR_TIME", 
197  *         \ref MEDCoupling::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   MCAuto<MEDCouplingFieldDiscretization> disc;
213   if(_type)
214     disc=_type->clone();
215   MCAuto<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::checkConsistencyLight).
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 MEDCoupling::MEDCouplingRemapper class should be used instead with "P1P0" method.
234  */
235 MEDCouplingFieldDouble *MEDCouplingFieldDouble::nodeToCellDiscretization() const
236 {
237   checkConsistencyLight();
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   MCAuto<MEDCouplingFieldDouble> ret(clone(false));
242   MCAuto<MEDCouplingFieldDiscretizationP0> nsp(new MEDCouplingFieldDiscretizationP0);
243   ret->setDiscretization(nsp);
244   const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkConsistencyLight call
245   int nbCells(m->getNumberOfCells());
246   std::vector<DataArrayDouble *> arrs(getArrays());
247   std::size_t sz(arrs.size());
248   std::vector< MCAuto<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::checkConsistencyLight).
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 MEDCoupling::MEDCouplingRemapper class should be used instead with "P0P1" method.
290  */
291 MEDCouplingFieldDouble *MEDCouplingFieldDouble::cellToNodeDiscretization() const
292 {
293   checkConsistencyLight();
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   MCAuto<MEDCouplingFieldDouble> ret(clone(false));
298   MCAuto<MEDCouplingFieldDiscretizationP1> nsp(new MEDCouplingFieldDiscretizationP1);
299   ret->setDiscretization(nsp);
300   const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkConsistencyLight call
301   MCAuto<DataArrayInt> rn(DataArrayInt::New()),rni(DataArrayInt::New());
302   m->getReverseNodalConnectivity(rn,rni);
303   MCAuto<DataArrayInt> rni2(rni->deltaShiftIndex());
304   MCAuto<DataArrayDouble> rni3(rni2->convertToDblArr()); rni2=0;
305   std::vector<DataArrayDouble *> arrs(getArrays());
306   std::size_t sz(arrs.size());
307   std::vector< MCAuto<DataArrayDouble> > outArrsSafe(sz); std::vector<DataArrayDouble *> outArrs(sz);
308   for(std::size_t j=0;j<sz;j++)
309     {
310       MCAuto<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 std::string MEDCouplingFieldDouble::writeVTK(const std::string& fileName, bool isBinary) const
455 {
456   std::vector<const MEDCouplingFieldDouble *> fs(1,this);
457   return 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::areStrictlyCompatibleForMulDiv 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::areStrictlyCompatibleForMulDiv(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::areStrictlyCompatibleForMulDiv 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::areStrictlyCompatibleForMulDiv(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   MCAuto<MEDCouplingMesh> m=_mesh->deepCopy();
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   MCAuto<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCopy());
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::findIdsInRange().
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::findIdsInRange(double vmin, double vmax) const
730 {
731   if(getArray()==0)
732     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::findIdsInRange : no default array set !");
733   return getArray()->findIdsInRange(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 MEDCoupling::ON_CELLS "ON_CELLS", 
742  * \ref MEDCoupling::ON_NODES "ON_NODES",
743  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
744  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
745  * \ref MEDCoupling::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->checkConsistencyLight() 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 MEDCoupling::ON_CELLS "ON_CELLS", 
780  * \ref MEDCoupling::ON_NODES "ON_NODES",
781  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
782  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
783  * \ref MEDCoupling::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 MEDCoupling::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   MCAuto<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
813   MCAuto<DataArrayInt> arrSelect2(arrSelect);
814   MCAuto<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
815   const MEDCouplingFieldDiscretization *disc=getDiscretization();
816   if(disc)
817     ret->setDiscretization(MCAuto<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< MCAuto<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   MCAuto<MEDCouplingMesh> m=_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect);
849   MCAuto<DataArrayInt> arrSelect2(arrSelect);
850   MCAuto<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
851   const MEDCouplingFieldDiscretization *disc=getDiscretization();
852   if(disc)
853     ret->setDiscretization(MCAuto<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< MCAuto<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)->selectByTupleIdSafeSlice(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 MEDCoupling::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->performCopyOrIncrRef(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::checkConsistencyLight() const
926 {
927   MEDCouplingField::checkConsistencyLight();
928   _time_discr->checkConsistencyLight();
929   _type->checkCoherencyBetween(_mesh,getArray());
930 }
931
932 /*!
933  * Accumulate values of a given component of \a this field.
934  *  \param [in] compId - the index of the component of interest.
935  *  \return double - a sum value of *compId*-th component.
936  *  \throw If the data array is not set.
937  *  \throw If \a the condition ( 0 <= \a compId < \a this->getNumberOfComponents() ) is
938  *         not respected.
939  */
940 double MEDCouplingFieldDouble::accumulate(int compId) const
941 {
942   if(getArray()==0)
943     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
944   return getArray()->accumulate(compId);
945 }
946
947 /*!
948  * Accumulates values of each component of \a this array.
949  *  \param [out] res - an array of length \a this->getNumberOfComponents(), allocated 
950  *         by the caller, that is filled by this method with sum value for each
951  *         component.
952  *  \throw If the data array is not set.
953  */
954 void MEDCouplingFieldDouble::accumulate(double *res) const
955 {
956   if(getArray()==0)
957     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
958   getArray()->accumulate(res);
959 }
960
961 /*!
962  * Returns the maximal value within \a this scalar field. Values of all arrays stored
963  * in \a this->_time_discr are checked.
964  *  \return double - the maximal value among all values of \a this field.
965  *  \throw If \a this->getNumberOfComponents() != 1
966  *  \throw If the data array is not set.
967  *  \throw If there is an empty data array in \a this field.
968  */
969 double MEDCouplingFieldDouble::getMaxValue() const
970 {
971   std::vector<DataArrayDouble *> arrays;
972   _time_discr->getArrays(arrays);
973   double ret=-std::numeric_limits<double>::max();
974   bool isExistingArr=false;
975   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
976     {
977       if(*iter)
978         {
979           isExistingArr=true;
980           int loc;
981           ret=std::max(ret,(*iter)->getMaxValue(loc));
982         }
983     }
984   if(!isExistingArr)
985     throw INTERP_KERNEL::Exception("getMaxValue : No arrays defined !");
986   return ret;
987 }
988
989 /*!
990  * Returns the maximal value and all its locations within \a this scalar field.
991  * Only the first of available data arrays is checked.
992  *  \param [out] tupleIds - a new instance of DataArrayInt containg indices of
993  *               tuples holding the maximal value. The caller is to delete it using
994  *               decrRef() as it is no more needed.
995  *  \return double - the maximal value among all values of the first array of \a this filed.
996  *  \throw If \a this->getNumberOfComponents() != 1.
997  *  \throw If there is an empty data array in \a this field.
998  */
999 double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const
1000 {
1001   std::vector<DataArrayDouble *> arrays;
1002   _time_discr->getArrays(arrays);
1003   double ret=-std::numeric_limits<double>::max();
1004   bool isExistingArr=false;
1005   tupleIds=0;
1006   MCAuto<DataArrayInt> ret1;
1007   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
1008     {
1009       if(*iter)
1010         {
1011           isExistingArr=true;
1012           DataArrayInt *tmp;
1013           ret=std::max(ret,(*iter)->getMaxValue2(tmp));
1014           MCAuto<DataArrayInt> tmpSafe(tmp);
1015           if(!((const DataArrayInt *)ret1))
1016             ret1=tmpSafe;
1017         }
1018     }
1019   if(!isExistingArr)
1020     throw INTERP_KERNEL::Exception("getMaxValue2 : No arrays defined !");
1021   tupleIds=ret1.retn();
1022   return ret;
1023 }
1024
1025 /*!
1026  * Returns the minimal value within \a this scalar field. Values of all arrays stored
1027  * in \a this->_time_discr are checked.
1028  *  \return double - the minimal value among all values of \a this field.
1029  *  \throw If \a this->getNumberOfComponents() != 1
1030  *  \throw If the data array is not set.
1031  *  \throw If there is an empty data array in \a this field.
1032  */
1033 double MEDCouplingFieldDouble::getMinValue() const
1034 {
1035   std::vector<DataArrayDouble *> arrays;
1036   _time_discr->getArrays(arrays);
1037   double ret=std::numeric_limits<double>::max();
1038   bool isExistingArr=false;
1039   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
1040     {
1041       if(*iter)
1042         {
1043           isExistingArr=true;
1044           int loc;
1045           ret=std::min(ret,(*iter)->getMinValue(loc));
1046         }
1047     }
1048   if(!isExistingArr)
1049     throw INTERP_KERNEL::Exception("getMinValue : No arrays defined !");
1050   return ret;
1051 }
1052
1053 /*!
1054  * Returns the minimal value and all its locations within \a this scalar field.
1055  * Only the first of available data arrays is checked.
1056  *  \param [out] tupleIds - a new instance of DataArrayInt containg indices of
1057  *               tuples holding the minimal value. The caller is to delete it using
1058  *               decrRef() as it is no more needed.
1059  *  \return double - the minimal value among all values of the first array of \a this filed.
1060  *  \throw If \a this->getNumberOfComponents() != 1.
1061  *  \throw If there is an empty data array in \a this field.
1062  */
1063 double MEDCouplingFieldDouble::getMinValue2(DataArrayInt*& tupleIds) const
1064 {
1065   std::vector<DataArrayDouble *> arrays;
1066   _time_discr->getArrays(arrays);
1067   double ret=-std::numeric_limits<double>::max();
1068   bool isExistingArr=false;
1069   tupleIds=0;
1070   MCAuto<DataArrayInt> ret1;
1071   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
1072     {
1073       if(*iter)
1074         {
1075           isExistingArr=true;
1076           DataArrayInt *tmp;
1077           ret=std::max(ret,(*iter)->getMinValue2(tmp));
1078           MCAuto<DataArrayInt> tmpSafe(tmp);
1079           if(!((const DataArrayInt *)ret1))
1080             ret1=tmpSafe;
1081         }
1082     }
1083   if(!isExistingArr)
1084     throw INTERP_KERNEL::Exception("getMinValue2 : No arrays defined !");
1085   tupleIds=ret1.retn();
1086   return ret;
1087 }
1088
1089 /*!
1090  * Returns the average value of \a this scalar field.
1091  *  \return double - the average value over all values of the data array.
1092  *  \throw If \a this->getNumberOfComponents() != 1
1093  *  \throw If the data array is not set or it is empty.
1094  */
1095 double MEDCouplingFieldDouble::getAverageValue() const
1096 {
1097   if(getArray()==0)
1098     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getAverageValue : no default array defined !");
1099   return getArray()->getAverageValue();
1100 }
1101
1102 /*!
1103  * This method returns the euclidean norm of \a this field.
1104  * \f[
1105  * \sqrt{\sum_{0 \leq i < nbOfEntity}val[i]*val[i]}
1106  * \f]
1107  *  \throw If the data array is not set.
1108  */
1109 double MEDCouplingFieldDouble::norm2() const
1110 {
1111   if(getArray()==0)
1112     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::norm2 : no default array defined !");
1113   return getArray()->norm2();
1114 }
1115
1116 /*!
1117  * This method returns the max norm of \a this field.
1118  * \f[
1119  * \max_{0 \leq i < nbOfEntity}{abs(val[i])}
1120  * \f]
1121  *  \throw If the data array is not set.
1122  */
1123 double MEDCouplingFieldDouble::normMax() const
1124 {
1125   if(getArray()==0)
1126     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::normMax : no default array defined !");
1127   return getArray()->normMax();
1128 }
1129
1130 /*!
1131  * Computes the weighted average of values of each component of \a this field, the weights being the
1132  * values returned by buildMeasureField().  
1133  *  \param [out] res - pointer to an array of result sum values, of size at least \a
1134  *         this->getNumberOfComponents(), that is to be allocated by the caller.
1135  *  \param [in] isWAbs - if \c true (default), \c abs() is applied to the weights computed by
1136  *         buildMeasureField(). It makes this method slower. If you are sure that all
1137  *         the cells of the underlying mesh have a correct orientation (no negative volume), you can put \a isWAbs ==
1138  *         \c false to speed up the method.
1139  *  \throw If the mesh is not set.
1140  *  \throw If the data array is not set.
1141  */
1142 void MEDCouplingFieldDouble::getWeightedAverageValue(double *res, bool isWAbs) const
1143 {
1144   if(getArray()==0)
1145     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getWeightedAverageValue : no default array defined !");
1146   MCAuto<MEDCouplingFieldDouble> w=buildMeasureField(isWAbs);
1147   double deno=w->getArray()->accumulate(0);
1148   MCAuto<DataArrayDouble> arr=getArray()->deepCopy();
1149   arr->multiplyEqual(w->getArray());
1150   arr->accumulate(res);
1151   int nCompo = getArray()->getNumberOfComponents();
1152   std::transform(res,res+nCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
1153 }
1154
1155 /*!
1156  * Computes the weighted average of values of a given component of \a this field, the weights being the
1157  * values returned by buildMeasureField().
1158  *  \param [in] compId - an index of the component of interest.
1159  *  \param [in] isWAbs - if \c true (default), \c abs() is applied to the weights computed by
1160  *         buildMeasureField(). It makes this method slower. If you are sure that all
1161  *         the cells of the underlying mesh have a correct orientation (no negative volume), you can put \a isWAbs ==
1162  *         \c false to speed up the method.
1163  *  \throw If the mesh is not set.
1164  *  \throw If the data array is not set.
1165  *  \throw If \a compId is not valid.
1166            A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1167  */
1168 double MEDCouplingFieldDouble::getWeightedAverageValue(int compId, bool isWAbs) const
1169 {
1170   int nbComps=getArray()->getNumberOfComponents();
1171   if(compId<0 || compId>=nbComps)
1172     {
1173       std::ostringstream oss; oss << "MEDCouplingFieldDouble::getWeightedAverageValue : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1174       throw INTERP_KERNEL::Exception(oss.str().c_str());
1175     }
1176   INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1177   getWeightedAverageValue(res,isWAbs);
1178   return res[compId];
1179 }
1180
1181 /*!
1182  * Returns the \c normL1 of values of a given component of \a this field:
1183  * \f[
1184  * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1185  * \f]
1186  *  \param [in] compId - an index of the component of interest.
1187  *  \throw If the mesh is not set.
1188  *  \throw If the spatial discretization of \a this field is NULL.
1189  *  \throw If \a compId is not valid.
1190            A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1191  */
1192 double MEDCouplingFieldDouble::normL1(int compId) const
1193 {
1194   if(!_mesh)
1195     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1 !");
1196   if(!((const MEDCouplingFieldDiscretization *)_type))
1197     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1198   int nbComps=getArray()->getNumberOfComponents();
1199   if(compId<0 || compId>=nbComps)
1200     {
1201       std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL1 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1202       throw INTERP_KERNEL::Exception(oss.str().c_str());
1203     }
1204   INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1205   _type->normL1(_mesh,getArray(),res);
1206   return res[compId];
1207 }
1208
1209 /*!
1210  * Returns the \c normL1 of values of each component of \a this field:
1211  * \f[
1212  * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1213  * \f]
1214  *  \param [out] res - pointer to an array of result values, of size at least \a
1215  *         this->getNumberOfComponents(), that is to be allocated by the caller.
1216  *  \throw If the mesh is not set.
1217  *  \throw If the spatial discretization of \a this field is NULL.
1218  */
1219 void MEDCouplingFieldDouble::normL1(double *res) const
1220 {
1221   if(!_mesh)
1222     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1");
1223   if(!((const MEDCouplingFieldDiscretization *)_type))
1224     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1225   _type->normL1(_mesh,getArray(),res);
1226 }
1227
1228 /*!
1229  * Returns the \c normL2 of values of a given component of \a this field:
1230  * \f[
1231  * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1232  * \f]
1233  *  \param [in] compId - an index of the component of interest.
1234  *  \throw If the mesh is not set.
1235  *  \throw If the spatial discretization of \a this field is NULL.
1236  *  \throw If \a compId is not valid.
1237            A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1238  */
1239 double MEDCouplingFieldDouble::normL2(int compId) const
1240 {
1241   if(!_mesh)
1242     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1243   if(!((const MEDCouplingFieldDiscretization *)_type))
1244     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1245   int nbComps=getArray()->getNumberOfComponents();
1246   if(compId<0 || compId>=nbComps)
1247     {
1248       std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL2 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1249       throw INTERP_KERNEL::Exception(oss.str().c_str());
1250     }
1251   INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1252   _type->normL2(_mesh,getArray(),res);
1253   return res[compId];
1254 }
1255
1256 /*!
1257  * Returns the \c normL2 of values of each component of \a this field:
1258  * \f[
1259  * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1260  * \f]
1261  *  \param [out] res - pointer to an array of result values, of size at least \a
1262  *         this->getNumberOfComponents(), that is to be allocated by the caller.
1263  *  \throw If the mesh is not set.
1264  *  \throw If the spatial discretization of \a this field is NULL.
1265  */
1266 void MEDCouplingFieldDouble::normL2(double *res) const
1267 {
1268   if(!_mesh)
1269     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1270   if(!((const MEDCouplingFieldDiscretization *)_type))
1271     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1272   _type->normL2(_mesh,getArray(),res);
1273 }
1274
1275 /*!
1276  * Computes a sum of values of a given component of \a this field multiplied by
1277  * values returned by buildMeasureField().
1278  * This method is useful to check the conservativity of interpolation method.
1279  *  \param [in] compId - an index of the component of interest.
1280  *  \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1281  *         buildMeasureField() that makes this method slower. If a user is sure that all
1282  *         cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1283  *         \c false that speeds up this method.
1284  *  \throw If the mesh is not set.
1285  *  \throw If the data array is not set.
1286  *  \throw If \a compId is not valid.
1287            A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1288  */
1289 double MEDCouplingFieldDouble::integral(int compId, bool isWAbs) const
1290 {
1291   if(!_mesh)
1292     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral");
1293   if(!((const MEDCouplingFieldDiscretization *)_type))
1294     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral !");
1295   int nbComps=getArray()->getNumberOfComponents();
1296   if(compId<0 || compId>=nbComps)
1297     {
1298       std::ostringstream oss; oss << "MEDCouplingFieldDouble::integral : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1299       throw INTERP_KERNEL::Exception(oss.str().c_str());
1300     }
1301   INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1302   _type->integral(_mesh,getArray(),isWAbs,res);
1303   return res[compId];
1304 }
1305
1306 /*!
1307  * Computes a sum of values of each component of \a this field multiplied by
1308  * values returned by buildMeasureField().
1309  * This method is useful to check the conservativity of interpolation method.
1310  *  \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1311  *         buildMeasureField() that makes this method slower. If a user is sure that all
1312  *         cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1313  *         \c false that speeds up this method.
1314  *  \param [out] res - pointer to an array of result sum values, of size at least \a
1315  *         this->getNumberOfComponents(), that is to be allocated by the caller.
1316  *  \throw If the mesh is not set.
1317  *  \throw If the data array is not set.
1318  *  \throw If the spatial discretization of \a this field is NULL.
1319  */
1320 void MEDCouplingFieldDouble::integral(bool isWAbs, double *res) const
1321 {
1322   if(!_mesh)
1323     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral2");
1324   if(!((const MEDCouplingFieldDiscretization *)_type))
1325     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral2 !");
1326   _type->integral(_mesh,getArray(),isWAbs,res);
1327 }
1328
1329 /*!
1330  * Returns a value at a given cell of a structured mesh. The cell is specified by its
1331  * (i,j,k) index.
1332  *  \param [in] i - a index of node coordinates array along X axis. The cell is
1333  *         located between the i-th and ( i + 1 )-th nodes along X axis.
1334  *  \param [in] j - a index of node coordinates array along Y axis. The cell is
1335  *         located between the j-th and ( j + 1 )-th nodes along Y axis.
1336  *  \param [in] k - a index of node coordinates array along Z axis. The cell is
1337  *         located between the k-th and ( k + 1 )-th nodes along Z axis.
1338  *  \param [out] res - pointer to an array returning a feild value, of size at least
1339  *         \a this->getNumberOfComponents(), that is to be allocated by the caller.
1340  *  \throw If the spatial discretization of \a this field is NULL.
1341  *  \throw If the mesh is not set.
1342  *  \throw If the mesh is not a structured one.
1343  *
1344  *  \if ENABLE_EXAMPLES
1345  *  \ref cpp_mcfielddouble_getValueOnPos "Here is a C++ example".<br>
1346  *  \ref  py_mcfielddouble_getValueOnPos "Here is a Python example".
1347  *  \endif
1348  */
1349 void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) const
1350 {
1351   const DataArrayDouble *arr=_time_discr->getArray();
1352   if(!_mesh)
1353     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnPos");
1354   if(!((const MEDCouplingFieldDiscretization *)_type))
1355     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1356   _type->getValueOnPos(arr,_mesh,i,j,k,res);
1357 }
1358
1359 /*!
1360  * Returns a value of \a this at a given point using spatial discretization.
1361  *  \param [in] spaceLoc - the point of interest.
1362  *  \param [out] res - pointer to an array returning a feild value, of size at least
1363  *         \a this->getNumberOfComponents(), that is to be allocated by the caller.
1364  *  \throw If the spatial discretization of \a this field is NULL.
1365  *  \throw If the mesh is not set.
1366  *  \throw If \a spaceLoc is out of the spatial discretization.
1367  *
1368  *  \if ENABLE_EXAMPLES
1369  *  \ref cpp_mcfielddouble_getValueOn "Here is a C++ example".<br>
1370  *  \ref  py_mcfielddouble_getValueOn "Here is a Python example".
1371  *  \endif
1372  */
1373 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) const
1374 {
1375   const DataArrayDouble *arr=_time_discr->getArray();
1376   if(!_mesh)
1377     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1378   if(!((const MEDCouplingFieldDiscretization *)_type))
1379     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1380   _type->getValueOn(arr,_mesh,spaceLoc,res);
1381 }
1382
1383 /*!
1384  * Returns values of \a this at given points using spatial discretization.
1385  *  \param [in] spaceLoc - coordinates of points of interest in full-interlace
1386  *          mode. This array is to be of size ( \a nbOfPoints * \a this->getNumberOfComponents() ).
1387  *  \param [in] nbOfPoints - number of points of interest.
1388  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding field
1389  *         values relating to the input points. This array is of size \a nbOfPoints
1390  *         tuples per \a this->getNumberOfComponents() components. The caller is to 
1391  *         delete this array using decrRef() as it is no more needed.
1392  *  \throw If the spatial discretization of \a this field is NULL.
1393  *  \throw If the mesh is not set.
1394  *  \throw If any point in \a spaceLoc is out of the spatial discretization.
1395  *
1396  *  \if ENABLE_EXAMPLES
1397  *  \ref cpp_mcfielddouble_getValueOnMulti "Here is a C++ example".<br>
1398  *  \ref  py_mcfielddouble_getValueOnMulti "Here is a Python example".
1399  *  \endif
1400  */
1401 DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, int nbOfPoints) const
1402 {
1403   const DataArrayDouble *arr=_time_discr->getArray();
1404   if(!_mesh)
1405     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnMulti");
1406   if(!((const MEDCouplingFieldDiscretization *)_type))
1407     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnMulti !");
1408   return _type->getValueOnMulti(arr,_mesh,spaceLoc,nbOfPoints);
1409 }
1410
1411 /*!
1412  * Returns a value of \a this field at a given point at a given time using spatial discretization.
1413  * If the time is not covered by \a this->_time_discr, an exception is thrown.
1414  *  \param [in] spaceLoc - the point of interest.
1415  *  \param [in] time - the time of interest.
1416  *  \param [out] res - pointer to an array returning a feild value, of size at least
1417  *         \a this->getNumberOfComponents(), that is to be allocated by the caller.
1418  *  \throw If the spatial discretization of \a this field is NULL.
1419  *  \throw If the mesh is not set.
1420  *  \throw If \a spaceLoc is out of the spatial discretization.
1421  *  \throw If \a time is not covered by \a this->_time_discr.
1422  *
1423  *  \if ENABLE_EXAMPLES
1424  *  \ref cpp_mcfielddouble_getValueOn_time "Here is a C++ example".<br>
1425  *  \ref  py_mcfielddouble_getValueOn_time "Here is a Python example".
1426  *  \endif
1427  */
1428 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, double *res) const
1429 {
1430   std::vector< const DataArrayDouble *> arrs=_time_discr->getArraysForTime(time);
1431   if(!_mesh)
1432     throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1433   if(!((const MEDCouplingFieldDiscretization *)_type))
1434     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOn !");
1435   std::vector<double> res2;
1436   for(std::vector< const DataArrayDouble *>::const_iterator iter=arrs.begin();iter!=arrs.end();iter++)
1437     {
1438       int sz=(int)res2.size();
1439       res2.resize(sz+(*iter)->getNumberOfComponents());
1440       _type->getValueOn(*iter,_mesh,spaceLoc,&res2[sz]);
1441     }
1442   _time_discr->getValueForTime(time,res2,res);
1443 }
1444
1445 /*!
1446  * Apply a linear function to a given component of \a this field, so that
1447  * a component value <em>(x)</em> becomes \f$ a * x + b \f$.
1448  *  \param [in] a - the first coefficient of the function.
1449  *  \param [in] b - the second coefficient of the function.
1450  *  \param [in] compoId - the index of component to modify.
1451  *  \throw If the data array(s) is(are) not set.
1452  */
1453 void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId)
1454 {
1455   _time_discr->applyLin(a,b,compoId);
1456 }
1457
1458 /*!
1459  * Apply a linear function to all components of \a this field, so that
1460  * values <em>(x)</em> becomes \f$ a * x + b \f$.
1461  *  \param [in] a - the first coefficient of the function.
1462  *  \param [in] b - the second coefficient of the function.
1463  *  \throw If the data array(s) is(are) not set.
1464  */
1465 void MEDCouplingFieldDouble::applyLin(double a, double b)
1466 {
1467   _time_discr->applyLin(a,b);
1468 }
1469
1470 /*!
1471  * This method sets \a this to a uniform scalar field with one component.
1472  * All tuples will have the same value 'value'.
1473  * An exception is thrown if no underlying mesh is defined.
1474  */
1475 MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value)
1476 {
1477   if(!_mesh)
1478     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !");
1479   if(!((const MEDCouplingFieldDiscretization *)_type))
1480     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform operator = !");
1481   int nbOfTuple=_type->getNumberOfTuples(_mesh);
1482   _time_discr->setOrCreateUniformValueOnAllComponents(nbOfTuple,value);
1483   return *this;
1484 }
1485
1486 /*!
1487  * Creates data array(s) of \a this field by using a C function for value generation.
1488  *  \param [in] nbOfComp - the number of components for \a this field to have.
1489  *  \param [in] func - the function used to compute values of \a this field.
1490  *         This function is to compute a field value basing on coordinates of value
1491  *         location point.
1492  *  \throw If the mesh is not set.
1493  *  \throw If \a func returns \c false.
1494  *  \throw If the spatial discretization of \a this field is NULL.
1495  *
1496  *  \if ENABLE_EXAMPLES
1497  *  \ref cpp_mcfielddouble_fillFromAnalytic_c_func "Here is a C++ example".
1498  *  \endif
1499  */
1500 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate func)
1501 {
1502   if(!_mesh)
1503     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1504   if(!((const MEDCouplingFieldDiscretization *)_type))
1505     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1506   MCAuto<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1507   _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1508 }
1509
1510 /*!
1511  * Creates data array(s) of \a this field by using a function for value generation.<br>
1512  * The function is applied to coordinates of value location points. For example, if
1513  * \a this field is on cells, the function is applied to cell barycenters.
1514  * For more info on supported expressions that can be used in the function, see \ref
1515  * MEDCouplingArrayApplyFuncExpr. <br>
1516  * The function can include arbitrary named variables
1517  * (e.g. "x","y" or "va44") to refer to components of point coordinates. Names of
1518  * variables are sorted in \b alphabetical \b order to associate a variable name with a
1519  * component. For example, in the expression "2*x+z", "x" stands for the component #0
1520  * and "z" stands for the component #1 (\b not #2)!<br>
1521  * In a general case, a value resulting from the function evaluation is assigned to all
1522  * components of a field value. But there is a possibility to have its own expression for
1523  * each component within one function. For this purpose, there are predefined variable
1524  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1525  * the component #0 etc). A factor of such a variable is added to the
1526  * corresponding component only.<br>
1527  * For example, \a nbOfComp == 4, coordinates of a 3D point are (1.,3.,7.), then
1528  *   - "2*x + z"               produces (5.,5.,5.,5.)
1529  *   - "2*x + 0*y + z"         produces (9.,9.,9.,9.)
1530  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1531  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1532  *
1533  *  \param [in] nbOfComp - the number of components for \a this field to have.
1534  *  \param [in] func - the function used to compute values of \a this field.
1535  *         This function is used to compute a field value basing on coordinates of value
1536  *         location point. For example, if \a this field is on cells, the function
1537  *         is applied to cell barycenters.
1538  *  \throw If the mesh is not set.
1539  *  \throw If the spatial discretization of \a this field is NULL.
1540  *  \throw If computing \a func fails.
1541  *
1542  *  \if ENABLE_EXAMPLES
1543  *  \ref cpp_mcfielddouble_fillFromAnalytic "Here is a C++ example".<br>
1544  *  \ref  py_mcfielddouble_fillFromAnalytic "Here is a Python example".
1545  *  \endif
1546  */
1547 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func)
1548 {
1549   if(!_mesh)
1550     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1551   if(!((const MEDCouplingFieldDiscretization *)_type))
1552     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1553   MCAuto<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1554   _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1555 }
1556
1557 /*!
1558  * Creates data array(s) of \a this field by using a function for value generation.<br>
1559  * The function is applied to coordinates of value location points. For example, if
1560  * \a this field is on cells, the function is applied to cell barycenters.<br>
1561  * This method differs from
1562  * \ref MEDCoupling::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func) "fillFromAnalytic()"
1563  * by the way how variable
1564  * names, used in the function, are associated with components of coordinates of field
1565  * location points; here, a variable name corresponding to a component is retrieved from
1566  * a corresponding node coordinates array (where it is set via
1567  * DataArrayDouble::setInfoOnComponent()).<br>
1568  * For more info on supported expressions that can be used in the function, see \ref
1569  * MEDCouplingArrayApplyFuncExpr. <br> 
1570  * In a general case, a value resulting from the function evaluation is assigned to all
1571  * components of a field value. But there is a possibility to have its own expression for
1572  * each component within one function. For this purpose, there are predefined variable
1573  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1574  * the component #0 etc). A factor of such a variable is added to the
1575  * corresponding component only.<br>
1576  * For example, \a nbOfComp == 4, names of spatial components are "x", "y" and "z",
1577  * coordinates of a 3D point are (1.,3.,7.), then
1578  *   - "2*x + z"               produces (9.,9.,9.,9.)
1579  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1580  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1581  *
1582  *  \param [in] nbOfComp - the number of components for \a this field to have.
1583  *  \param [in] func - the function used to compute values of \a this field.
1584  *         This function is used to compute a field value basing on coordinates of value
1585  *         location point. For example, if \a this field is on cells, the function
1586  *         is applied to cell barycenters.
1587  *  \throw If the mesh is not set.
1588  *  \throw If the spatial discretization of \a this field is NULL.
1589  *  \throw If computing \a func fails.
1590  *
1591  *  \if ENABLE_EXAMPLES
1592  *  \ref cpp_mcfielddouble_fillFromAnalytic2 "Here is a C++ example".<br>
1593  *  \ref  py_mcfielddouble_fillFromAnalytic2 "Here is a Python example".
1594  *  \endif
1595  */
1596 void MEDCouplingFieldDouble::fillFromAnalyticCompo(int nbOfComp, const std::string& func)
1597 {
1598   if(!_mesh)
1599     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalyticCompo : no mesh defined !");
1600   if(!((const MEDCouplingFieldDiscretization *)_type))
1601     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalyticCompo !");
1602   MCAuto<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1603   _time_discr->fillFromAnalyticCompo(loc,nbOfComp,func);
1604 }
1605
1606 /*!
1607  * Creates data array(s) of \a this field by using a function for value generation.<br>
1608  * The function is applied to coordinates of value location points. For example, if
1609  * \a this field is on cells, the function is applied to cell barycenters.<br>
1610  * This method differs from
1611  * \ref MEDCoupling::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func) "fillFromAnalytic()"
1612  * by the way how variable
1613  * names, used in the function, are associated with components of coordinates of field
1614  * location points; here, a component index of a variable is defined by a
1615  * rank of the variable within the input array \a varsOrder.<br>
1616  * For more info on supported expressions that can be used in the function, see \ref
1617  * MEDCouplingArrayApplyFuncExpr.
1618  * In a general case, a value resulting from the function evaluation is assigned to all
1619  * components of a field value. But there is a possibility to have its own expression for
1620  * each component within one function. For this purpose, there are predefined variable
1621  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1622  * the component #0 etc). A factor of such a variable is added to the
1623  * corresponding component only.<br>
1624  * For example, \a nbOfComp == 4, names of
1625  * spatial components are given in \a varsOrder: ["x", "y","z"], coordinates of a
1626  * 3D point are (1.,3.,7.), then
1627  *   - "2*x + z"               produces (9.,9.,9.,9.)
1628  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1629  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1630  *
1631  *  \param [in] nbOfComp - the number of components for \a this field to have.
1632  *  \param [in] func - the function used to compute values of \a this field.
1633  *         This function is used to compute a field value basing on coordinates of value
1634  *         location point. For example, if \a this field is on cells, the function
1635  *         is applied to cell barycenters.
1636  *  \throw If the mesh is not set.
1637  *  \throw If the spatial discretization of \a this field is NULL.
1638  *  \throw If computing \a func fails.
1639  *
1640  *  \if ENABLE_EXAMPLES
1641  *  \ref cpp_mcfielddouble_fillFromAnalytic3 "Here is a C++ example".<br>
1642  *  \ref  py_mcfielddouble_fillFromAnalytic3 "Here is a Python example".
1643  *  \endif
1644  */
1645 void MEDCouplingFieldDouble::fillFromAnalyticNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
1646 {
1647   if(!_mesh)
1648     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalyticCompo : no mesh defined !");
1649   if(!((const MEDCouplingFieldDiscretization *)_type))
1650     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalyticNamedCompo !");
1651   MCAuto<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1652   _time_discr->fillFromAnalyticNamedCompo(loc,nbOfComp,varsOrder,func);
1653 }
1654
1655 /*!
1656  * Modifies values of \a this field by applying a C function to each tuple of all
1657  * data arrays.
1658  *  \param [in] nbOfComp - the number of components for \a this field to have.
1659  *  \param [in] func - the function used to compute values of \a this field.
1660  *         This function is to compute a field value basing on a current field value.
1661  *  \throw If \a func returns \c false.
1662  *
1663  *  \if ENABLE_EXAMPLES
1664  *  \ref cpp_mcfielddouble_applyFunc_c_func "Here is a C++ example".
1665  *  \endif
1666  */
1667 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, FunctionToEvaluate func)
1668 {
1669   _time_discr->applyFunc(nbOfComp,func);
1670 }
1671
1672 /*!
1673  * Fill \a this field with a given value.<br>
1674  * This method is a specialization of other overloaded methods. When \a nbOfComp == 1
1675  * this method is equivalent to MEDCoupling::MEDCouplingFieldDouble::operator=().
1676  *  \param [in] nbOfComp - the number of components for \a this field to have.
1677  *  \param [in] val - the value to assign to every atomic value of \a this field.
1678  *  \throw If the spatial discretization of \a this field is NULL.
1679  *  \throw If the mesh is not set.
1680  *
1681  *  \if ENABLE_EXAMPLES
1682  *  \ref cpp_mcfielddouble_applyFunc_val "Here is a C++ example".<br>
1683  *  \ref  py_mcfielddouble_applyFunc_val "Here is a Python example".
1684  *  \endif
1685  */
1686 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val)
1687 {
1688   if(!_mesh)
1689     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::applyFunc : no mesh defined !");
1690   if(!((const MEDCouplingFieldDiscretization *)_type))
1691     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform applyFunc !");
1692   int nbOfTuple=_type->getNumberOfTuples(_mesh);
1693   _time_discr->setUniformValue(nbOfTuple,nbOfComp,val);
1694 }
1695
1696 /*!
1697  * Modifies values of \a this field by applying a function to each tuple of all
1698  * data arrays.
1699  * For more info on supported expressions that can be used in the function, see \ref
1700  * MEDCouplingArrayApplyFuncExpr. <br>
1701  * The function can include arbitrary named variables
1702  * (e.g. "x","y" or "va44") to refer to components of a field value. Names of
1703  * variables are sorted in \b alphabetical \b order to associate a variable name with a
1704  * component. For example, in the expression "2*x+z", "x" stands for the component #0
1705  * and "z" stands for the component #1 (\b not #2)!<br>
1706  * In a general case, a value resulting from the function evaluation is assigned to all
1707  * components of a field value. But there is a possibility to have its own expression for
1708  * each component within one function. For this purpose, there are predefined variable
1709  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1710  * the component #0 etc). A factor of such a variable is added to the
1711  * corresponding component only.<br>
1712  * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1713  *   - "2*x + z"               produces (5.,5.,5.,5.)
1714  *   - "2*x + 0*y + z"         produces (9.,9.,9.,9.)
1715  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1716  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1717  *
1718  *  \param [in] nbOfComp - the number of components for \a this field to have.
1719  *  \param [in] func - the function used to compute values of \a this field.
1720  *         This function is to compute a field value basing on a current field value.
1721  *  \throw If computing \a func fails.
1722  *
1723  *  \if ENABLE_EXAMPLES
1724  *  \ref cpp_mcfielddouble_applyFunc "Here is a C++ example".<br>
1725  *  \ref  py_mcfielddouble_applyFunc "Here is a Python example".
1726  *  \endif
1727  */
1728 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func)
1729 {
1730   _time_discr->applyFunc(nbOfComp,func);
1731 }
1732
1733
1734 /*!
1735  * Modifies values of \a this field by applying a function to each tuple of all
1736  * data arrays.
1737  * For more info on supported expressions that can be used in the function, see \ref
1738  * MEDCouplingArrayApplyFuncExpr. <br>
1739  * This method differs from
1740  * \ref MEDCoupling::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) "applyFunc()"
1741  * by the way how variable
1742  * names, used in the function, are associated with components of field values;
1743  * here, a variable name corresponding to a component is retrieved from
1744  * component information of an array (where it is set via
1745  * DataArrayDouble::setInfoOnComponent()).<br>
1746  * In a general case, a value resulting from the function evaluation is assigned to all
1747  * components of a field value. But there is a possibility to have its own expression for
1748  * each component within one function. For this purpose, there are predefined variable
1749  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1750  * the component #0 etc). A factor of such a variable is added to the
1751  * corresponding component only.<br>
1752  * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1753  *   - "2*x + z"               produces (5.,5.,5.,5.)
1754  *   - "2*x + 0*y + z"         produces (9.,9.,9.,9.)
1755  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1756  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1757  *
1758  *  \param [in] nbOfComp - the number of components for \a this field to have.
1759  *  \param [in] func - the function used to compute values of \a this field.
1760  *         This function is to compute a new field value basing on a current field value.
1761  *  \throw If computing \a func fails.
1762  *
1763  *  \if ENABLE_EXAMPLES
1764  *  \ref cpp_mcfielddouble_applyFunc2 "Here is a C++ example".<br>
1765  *  \ref  py_mcfielddouble_applyFunc2 "Here is a Python example".
1766  *  \endif
1767  */
1768 void MEDCouplingFieldDouble::applyFuncCompo(int nbOfComp, const std::string& func)
1769 {
1770   _time_discr->applyFuncCompo(nbOfComp,func);
1771 }
1772
1773 /*!
1774  * Modifies values of \a this field by applying a function to each tuple of all
1775  * data arrays.
1776  * This method differs from
1777  * \ref MEDCoupling::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) "applyFunc()"
1778  * by the way how variable
1779  * names, used in the function, are associated with components of field values;
1780  * here, a component index of a variable is defined by a
1781  * rank of the variable within the input array \a varsOrder.<br>
1782  * For more info on supported expressions that can be used in the function, see \ref
1783  * MEDCouplingArrayApplyFuncExpr.
1784  * In a general case, a value resulting from the function evaluation is assigned to all
1785  * components of a field value. But there is a possibility to have its own expression for
1786  * each component within one function. For this purpose, there are predefined variable
1787  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1788  * the component #0 etc). A factor of such a variable is added to the
1789  * corresponding component only.<br>
1790  * For example, \a nbOfComp == 4, names of
1791  * components are given in \a varsOrder: ["x", "y","z"], components of a
1792  * 3D vector are (1.,3.,7.), then
1793  *   - "2*x + z"               produces (9.,9.,9.,9.)
1794  *   - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1795  *   - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1796  *
1797  *  \param [in] nbOfComp - the number of components for \a this field to have.
1798  *  \param [in] func - the function used to compute values of \a this field.
1799  *         This function is to compute a new field value basing on a current field value.
1800  *  \throw If computing \a func fails.
1801  *
1802  *  \if ENABLE_EXAMPLES
1803  *  \ref cpp_mcfielddouble_applyFunc3 "Here is a C++ example".<br>
1804  *  \ref  py_mcfielddouble_applyFunc3 "Here is a Python example".
1805  *  \endif
1806  */
1807 void MEDCouplingFieldDouble::applyFuncNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
1808 {
1809   _time_discr->applyFuncNamedCompo(nbOfComp,varsOrder,func);
1810 }
1811
1812 /*!
1813  * Modifies values of \a this field by applying a function to each atomic value of all
1814  * data arrays. The function computes a new single value basing on an old single value.
1815  * For more info on supported expressions that can be used in the function, see \ref
1816  * MEDCouplingArrayApplyFuncExpr. <br>
1817  * The function can include **only one** arbitrary named variable
1818  * (e.g. "x","y" or "va44") to refer to a field atomic value. <br>
1819  * In a general case, a value resulting from the function evaluation is assigned to 
1820  * a single field value. But there is a possibility to have its own expression for
1821  * each component within one function. For this purpose, there are predefined variable
1822  * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1823  * the component #0 etc). A factor of such a variable is added to the
1824  * corresponding component only.<br>
1825  * For example, components of a field value are (1.,3.,7.), then
1826  *   - "2*x - 1"               produces (1.,5.,13.)
1827  *   - "2*x*IVec + (x+3)*KVec" produces (2.,0.,10.)
1828  *   - "2*x*IVec + (x+3)*KVec + 1" produces (3.,1.,11.)
1829  *
1830  *  \param [in] func - the function used to compute values of \a this field.
1831  *         This function is to compute a field value basing on a current field value.
1832  *  \throw If computing \a func fails.
1833  *
1834  *  \if ENABLE_EXAMPLES
1835  *  \ref cpp_mcfielddouble_applyFunc_same_nb_comp "Here is a C++ example".<br>
1836  *  \ref  py_mcfielddouble_applyFunc_same_nb_comp "Here is a Python example".
1837  *  \endif
1838  */
1839 void MEDCouplingFieldDouble::applyFunc(const std::string& func)
1840 {
1841   _time_discr->applyFunc(func);
1842 }
1843
1844 /*!
1845  * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1846  * The field will contain exactly the same number of components after the call.
1847  * Use is not warranted for the moment !
1848  */
1849 void MEDCouplingFieldDouble::applyFuncFast32(const std::string& func)
1850 {
1851   _time_discr->applyFuncFast32(func);
1852 }
1853
1854 /*!
1855  * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1856  * The field will contain exactly the same number of components after the call.
1857  * Use is not warranted for the moment !
1858  */
1859 void MEDCouplingFieldDouble::applyFuncFast64(const std::string& func)
1860 {
1861   _time_discr->applyFuncFast64(func);
1862 }
1863
1864 /*!
1865  * Returns number of components in the data array. For more info on the data arrays,
1866  * see \ref arrays.
1867  *  \return int - the number of components in the data array.
1868  *  \throw If the data array is not set.
1869  */
1870 int MEDCouplingFieldDouble::getNumberOfComponents() const
1871 {
1872   if(getArray()==0)
1873     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfComponents : No array specified !");
1874   return getArray()->getNumberOfComponents();
1875 }
1876
1877 /*!
1878  * Use MEDCouplingField::getNumberOfTuplesExpected instead of this method. This method will be removed soon, because it is
1879  * confusing compared to getNumberOfComponents() and getNumberOfValues() behaviour.
1880  *
1881  * Returns number of tuples in \a this field, that depends on 
1882  * - the number of entities in the underlying mesh
1883  * - \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field (e.g. number
1884  * of Gauss points if \a this->getTypeOfField() == 
1885  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT").
1886  *
1887  * The returned value does \b not \b depend on the number of tuples in the data array
1888  * (which has to be equal to the returned value), \b contrary to
1889  * getNumberOfComponents() and getNumberOfValues() that retrieve information from the
1890  * data array (Sorry, it is confusing !).
1891  * So \b this \b method \b behaves \b exactly \b as MEDCouplingField::getNumberOfTuplesExpected \b method.
1892  *
1893  * \warning No checkConsistencyLight() is done here.
1894  * For more info on the data arrays, see \ref arrays.
1895  *  \return int - the number of tuples.
1896  *  \throw If the mesh is not set.
1897  *  \throw If the spatial discretization of \a this field is NULL.
1898  *  \throw If the spatial discretization is not fully defined.
1899  *  \sa MEDCouplingField::getNumberOfTuplesExpected
1900  */
1901 int MEDCouplingFieldDouble::getNumberOfTuples() const
1902 {
1903   //std::cerr << " ******* MEDCouplingFieldDouble::getNumberOfTuples is deprecated : use MEDCouplingField::getNumberOfTuplesExpected instead ! ******" << std::endl;
1904   if(!_mesh)
1905     throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !");
1906   if(!((const MEDCouplingFieldDiscretization *)_type))
1907     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getNumberOfTuples !");
1908   return _type->getNumberOfTuples(_mesh);
1909 }
1910
1911 /*!
1912  * Returns number of atomic double values in the data array of \a this field.
1913  * For more info on the data arrays, see \ref arrays.
1914  *  \return int - (number of tuples) * (number of components) of the
1915  *  data array.
1916  *  \throw If the data array is not set.
1917  */
1918 int MEDCouplingFieldDouble::getNumberOfValues() const
1919 {
1920   if(getArray()==0)
1921     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfValues : No array specified !");
1922   return getArray()->getNbOfElems();
1923 }
1924
1925 /*!
1926  * Sets own modification time by the most recently modified element of data (the mesh,
1927  * the data array etc). For more info, see \ref MEDCouplingTimeLabelPage.
1928  */
1929 void MEDCouplingFieldDouble::updateTime() const
1930 {
1931   MEDCouplingField::updateTime();
1932   updateTimeWith(*_time_discr);
1933 }
1934
1935 std::size_t MEDCouplingFieldDouble::getHeapMemorySizeWithoutChildren() const
1936 {
1937   return MEDCouplingField::getHeapMemorySizeWithoutChildren();
1938 }
1939
1940 std::vector<const BigMemoryObject *> MEDCouplingFieldDouble::getDirectChildrenWithNull() const
1941 {
1942   std::vector<const BigMemoryObject *> ret(MEDCouplingField::getDirectChildrenWithNull());
1943   if(_time_discr)
1944     {
1945       std::vector<const BigMemoryObject *> ret2(_time_discr->getDirectChildrenWithNull());
1946       ret.insert(ret.end(),ret2.begin(),ret2.end());
1947     }
1948   return ret;
1949 }
1950
1951 /*!
1952  * Sets \ref NatureOfField.
1953  *  \param [in] nat - an item of enum MEDCoupling::NatureOfField.
1954  */
1955 void MEDCouplingFieldDouble::setNature(NatureOfField nat)
1956 {
1957   MEDCouplingField::setNature(nat);
1958   if(_type)
1959     _type->checkCompatibilityWithNature(nat);
1960 }
1961
1962 /*!
1963  * This method synchronizes time information (time, iteration, order, time unit) regarding the information in \c this->_mesh.
1964  * \throw If no mesh is set in this. Or if \a this is not compatible with time setting (typically NO_TIME)
1965  */
1966 void MEDCouplingFieldDouble::synchronizeTimeWithMesh()
1967 {
1968   if(!_mesh)
1969     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::synchronizeTimeWithMesh : no mesh set in this !");
1970   int it=-1,ordr=-1;
1971   double val=_mesh->getTime(it,ordr);
1972   std::string timeUnit(_mesh->getTimeUnit());
1973   setTime(val,it,ordr);
1974   setTimeUnit(timeUnit);
1975 }
1976
1977 /*!
1978  * Returns a value of \a this field of type either
1979  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" or
1980  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
1981  *  \param [in] cellId - an id of cell of interest.
1982  *  \param [in] nodeIdInCell - a node index within the cell.
1983  *  \param [in] compoId - an index of component.
1984  *  \return double - the field value corresponding to the specified parameters.
1985  *  \throw If the data array is not set.
1986  *  \throw If the mesh is not set.
1987  *  \throw If the spatial discretization of \a this field is NULL.
1988  *  \throw If \a this field if of type other than 
1989  *         \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" or
1990  *         \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
1991  */
1992 double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) const
1993 {
1994   if(!((const MEDCouplingFieldDiscretization *)_type))
1995     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getIJK !");
1996   return _type->getIJK(_mesh,getArray(),cellId,nodeIdInCell,compoId);
1997 }
1998
1999 /*!
2000  * Sets the data array. 
2001  *  \param [in] array - the data array holding values of \a this field. It's size
2002  *         should correspond to the mesh and
2003  *         \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
2004  *         (see getNumberOfTuples()), but this size is not checked here.
2005  */
2006 void MEDCouplingFieldDouble::setArray(DataArrayDouble *array)
2007 {
2008   _time_discr->setArray(array,this);
2009 }
2010
2011 /*!
2012  * Sets the data array holding values corresponding to an end of a time interval
2013  * for which \a this field is defined.
2014  *  \param [in] array - the data array holding values of \a this field. It's size
2015  *         should correspond to the mesh and
2016  *         \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
2017  *         (see getNumberOfTuples()), but this size is not checked here.
2018  */
2019 void MEDCouplingFieldDouble::setEndArray(DataArrayDouble *array)
2020 {
2021   _time_discr->setEndArray(array,this);
2022 }
2023
2024 /*!
2025  * Sets all data arrays needed to define the field values.
2026  *  \param [in] arrs - a vector of DataArrayDouble's holding values of \a this
2027  *         field. Size of each array should correspond to the mesh and
2028  *         \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
2029  *         (see getNumberOfTuples()), but this size is not checked here.
2030  *  \throw If number of arrays in \a arrs does not correspond to type of
2031  *         \ref MEDCouplingTemporalDisc "temporal discretization" of \a this field.
2032  */
2033 void MEDCouplingFieldDouble::setArrays(const std::vector<DataArrayDouble *>& arrs)
2034 {
2035   _time_discr->setArrays(arrs,this);
2036 }
2037
2038 void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2039 {
2040   tinyInfo.clear();
2041   _time_discr->getTinySerializationStrInformation(tinyInfo);
2042   tinyInfo.push_back(_name);
2043   tinyInfo.push_back(_desc);
2044   tinyInfo.push_back(getTimeUnit());
2045 }
2046
2047 /*!
2048  * This method retrieves some critical values to resize and prepare remote instance.
2049  * The first two elements returned in tinyInfo correspond to the parameters to give in constructor.
2050  * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
2051  */
2052 void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2053 {
2054   if(!((const MEDCouplingFieldDiscretization *)_type))
2055     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
2056   tinyInfo.clear();
2057   tinyInfo.push_back((int)_type->getEnum());
2058   tinyInfo.push_back((int)_time_discr->getEnum());
2059   tinyInfo.push_back((int)_nature);
2060   _time_discr->getTinySerializationIntInformation(tinyInfo);
2061   std::vector<int> tinyInfo2;
2062   _type->getTinySerializationIntInformation(tinyInfo2);
2063   tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
2064   tinyInfo.push_back((int)tinyInfo2.size());
2065 }
2066
2067 /*!
2068  * This method retrieves some critical values to resize and prepare remote instance.
2069  * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
2070  */
2071 void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2072 {
2073   if(!((const MEDCouplingFieldDiscretization *)_type))
2074     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
2075   tinyInfo.clear();
2076   _time_discr->getTinySerializationDbleInformation(tinyInfo);
2077   std::vector<double> tinyInfo2;
2078   _type->getTinySerializationDbleInformation(tinyInfo2);
2079   tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
2080   tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it
2081 }
2082
2083 /*!
2084  * This method has to be called to the new instance filled by CORBA, MPI, File...
2085  * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied.
2086  * @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.
2087  * @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.
2088  *               No decrRef must be applied to every instances in returned vector.
2089  * \sa checkForUnserialization
2090  */
2091 void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays)
2092 {
2093   if(!((const MEDCouplingFieldDiscretization *)_type))
2094     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
2095   dataInt=0;
2096   std::vector<int> tinyInfoITmp(tinyInfoI);
2097   int sz=tinyInfoITmp.back();
2098   tinyInfoITmp.pop_back();
2099   std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
2100   std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
2101   _time_discr->resizeForUnserialization(tinyInfoI2,arrays);
2102   std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
2103   _type->resizeForUnserialization(tinyInfoITmp3,dataInt);
2104 }
2105
2106 /*!
2107  * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this
2108  * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data.
2109  * \sa resizeForUnserialization
2110  */
2111 void MEDCouplingFieldDouble::checkForUnserialization(const std::vector<int>& tinyInfoI, const DataArrayInt *dataInt, const std::vector<DataArrayDouble *>& arrays)
2112 {
2113   if(!((const MEDCouplingFieldDiscretization *)_type))
2114     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
2115   std::vector<int> tinyInfoITmp(tinyInfoI);
2116   int sz=tinyInfoITmp.back();
2117   tinyInfoITmp.pop_back();
2118   std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
2119   std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
2120   _time_discr->checkForUnserialization(tinyInfoI2,arrays);
2121   std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
2122   _type->checkForUnserialization(tinyInfoITmp3,dataInt);
2123 }
2124
2125 void MEDCouplingFieldDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2126 {
2127   if(!((const MEDCouplingFieldDiscretization *)_type))
2128     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
2129   std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
2130   //
2131   std::vector<double> tmp(tinyInfoD);
2132   int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it
2133   tmp.pop_back();
2134   std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
2135   std::vector<double> tmp2(tmp.end()-sz,tmp.end());
2136   //
2137   _time_discr->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
2138   _nature=(NatureOfField)tinyInfoI[2];
2139   _type->finishUnserialization(tmp2);
2140   int nbOfElemS=(int)tinyInfoS.size();
2141   _name=tinyInfoS[nbOfElemS-3];
2142   _desc=tinyInfoS[nbOfElemS-2];
2143   setTimeUnit(tinyInfoS[nbOfElemS-1]);
2144 }
2145
2146 /*!
2147  * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller.
2148  * The values returned must be consulted only in readonly mode.
2149  */
2150 void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays) const
2151 {
2152   if(!((const MEDCouplingFieldDiscretization *)_type))
2153     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");
2154   _time_discr->getArrays(arrays);
2155   _type->getSerializationIntArray(dataInt);
2156 }
2157
2158 /*!
2159  * Tries to set an \a other mesh as the support of \a this field. An attempt fails, if
2160  * a current and the \a other meshes are different with use of specified equality
2161  * criteria, and then an exception is thrown.
2162  *  \param [in] other - the mesh to use as the field support if this mesh can be
2163  *         considered equal to the current mesh.
2164  *  \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
2165  *         it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
2166  *         is used for mesh comparison.
2167  *  \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
2168  *         It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
2169  *  \param [in] eps - a precision used at node renumbering (if needed) to compare field
2170  *         values at merged nodes. If the values differ more than \a eps, an
2171  *         exception is thrown.
2172  *  \throw If the mesh is not set.
2173  *  \throw If \a other == NULL.
2174  *  \throw If any of the meshes is not well defined.
2175  *  \throw If the two meshes do not match.
2176  *  \throw If field values at merged nodes (if any) deffer more than \a eps.
2177  *
2178  *  \if ENABLE_EXAMPLES
2179  *  \ref cpp_mcfielddouble_changeUnderlyingMesh "Here is a C++ example".<br>
2180  *  \ref  py_mcfielddouble_changeUnderlyingMesh "Here is a Python example".
2181  *  \endif
2182  */
2183 void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps)
2184 {
2185   if(_mesh==0 || other==0)
2186     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::changeUnderlyingMesh : is expected to operate on not null meshes !");
2187   DataArrayInt *cellCor=0,*nodeCor=0;
2188   other->checkGeoEquivalWith(_mesh,levOfCheck,precOnMesh,cellCor,nodeCor);
2189   MCAuto<DataArrayInt> cellCor2(cellCor),nodeCor2(nodeCor);
2190   if(cellCor)
2191     renumberCellsWithoutMesh(cellCor->getConstPointer(),false);
2192   if(nodeCor)
2193     renumberNodesWithoutMesh(nodeCor->getConstPointer(),nodeCor->getMaxValueInArray()+1,eps);
2194   setMesh(other);
2195 }
2196
2197 /*!
2198  * Subtracts another field from \a this one in case when the two fields have different
2199  * supporting meshes. The subtraction is performed provided that the tho meshes can be
2200  * considered equal with use of specified equality criteria, else an exception is thrown.
2201  * If the meshes match, the mesh of \a f is set to \a this field (\a this is permuted if 
2202  * necessary) and field values are subtracted. No interpolation is done here, only an
2203  * analysis of two underlying mesh is done to see if the meshes are geometrically
2204  * equivalent.<br>
2205  * The job of this method consists in calling
2206  * \a this->changeUnderlyingMesh() with \a f->getMesh() as the first parameter, and then
2207  * \a this -= \a f.<br>
2208  * This method requires that \a f and \a this are coherent (checkConsistencyLight()) and that \a f
2209  * and \a this are coherent for a merge.<br>
2210  * "DM" in the method name stands for "different meshes".
2211  *  \param [in] f - the field to subtract from this.
2212  *  \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
2213  *         it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
2214  *         is used for mesh comparison.
2215  *  \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
2216  *         It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
2217  *  \param [in] eps - a precision used at node renumbering (if needed) to compare field
2218  *         values at merged nodes. If the values differ more than \a eps, an
2219  *         exception is thrown.
2220  *  \throw If \a f == NULL.
2221  *  \throw If any of the meshes is not set or is not well defined.
2222  *  \throw If the two meshes do not match.
2223  *  \throw If the two fields are not coherent for merge.
2224  *  \throw If field values at merged nodes (if any) deffer more than \a eps.
2225  *
2226  *  \if ENABLE_EXAMPLES
2227  *  \ref cpp_mcfielddouble_substractInPlaceDM "Here is a C++ example".<br>
2228  *  \ref  py_mcfielddouble_substractInPlaceDM "Here is a Python example".
2229  *  \endif
2230  *  \sa changeUnderlyingMesh().
2231  */
2232 void MEDCouplingFieldDouble::substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps)
2233 {
2234   checkConsistencyLight();
2235   if(!f)
2236     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : input field is NULL !");
2237   f->checkConsistencyLight();
2238   if(!areCompatibleForMerge(f))
2239     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : Fields are not compatible ; unable to apply mergeFields on them !");
2240   changeUnderlyingMesh(f->getMesh(),levOfCheck,precOnMesh,eps);
2241   operator-=(*f);
2242 }
2243
2244 /*!
2245  * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2246  * underlying mesh is replaced by a new mesh instance where the coincident nodes are merged.
2247  *  \param [in] eps - a precision used to compare nodes of the two meshes.
2248  *  \param [in] epsOnVals - a precision used to compare field
2249  *         values at merged nodes. If the values differ more than \a epsOnVals, an
2250  *         exception is thrown.
2251  *  \return bool - \c true if some nodes have been merged and hence \a this field lies
2252  *         on another mesh.
2253  *  \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2254  *  \throw If the mesh is not well defined.
2255  *  \throw If the spatial discretization of \a this field is NULL.
2256  *  \throw If the data array is not set.
2257  *  \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2258  */
2259 bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals)
2260 {
2261   const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2262   if(!meshC)
2263     throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2264   if(!((const MEDCouplingFieldDiscretization *)_type))
2265     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes !");
2266   MCAuto<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCopy());
2267   bool ret;
2268   int ret2;
2269   MCAuto<DataArrayInt> arr=meshC2->mergeNodes(eps,ret,ret2);
2270   if(!ret)//no nodes have been merged.
2271     return ret;
2272   std::vector<DataArrayDouble *> arrays;
2273   _time_discr->getArrays(arrays);
2274   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2275     if(*iter)
2276       _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2277   setMesh(meshC2);
2278   return true;
2279 }
2280
2281 /*!
2282  * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2283  * underlying mesh is replaced by a new mesh instance where the coincident nodes are
2284  * merged.<br>
2285  * In contrast to mergeNodes(), location of merged nodes is changed to be at their barycenter.
2286  *  \param [in] eps - a precision used to compare nodes of the two meshes.
2287  *  \param [in] epsOnVals - a precision used to compare field
2288  *         values at merged nodes. If the values differ more than \a epsOnVals, an
2289  *         exception is thrown.
2290  *  \return bool - \c true if some nodes have been merged and hence \a this field lies
2291  *         on another mesh.
2292  *  \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2293  *  \throw If the mesh is not well defined.
2294  *  \throw If the spatial discretization of \a this field is NULL.
2295  *  \throw If the data array is not set.
2296  *  \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2297  */
2298 bool MEDCouplingFieldDouble::mergeNodesCenter(double eps, double epsOnVals)
2299 {
2300   const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2301   if(!meshC)
2302     throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2303   if(!((const MEDCouplingFieldDiscretization *)_type))
2304     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodesCenter !");
2305   MCAuto<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCopy());
2306   bool ret;
2307   int ret2;
2308   MCAuto<DataArrayInt> arr=meshC2->mergeNodesCenter(eps,ret,ret2);
2309   if(!ret)//no nodes have been merged.
2310     return ret;
2311   std::vector<DataArrayDouble *> arrays;
2312   _time_discr->getArrays(arrays);
2313   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2314     if(*iter)
2315       _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2316   setMesh(meshC2);
2317   return true;
2318 }
2319
2320 /*!
2321  * Removes from the underlying mesh nodes not used in any cell. If some nodes are
2322  * removed, the underlying mesh is replaced by a new mesh instance where the unused
2323  * nodes are removed.<br>
2324  *  \param [in] epsOnVals - a precision used to compare field
2325  *         values at merged nodes. If the values differ more than \a epsOnVals, an
2326  *         exception is thrown.
2327  *  \return bool - \c true if some nodes have been removed and hence \a this field lies
2328  *         on another mesh.
2329  *  \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2330  *  \throw If the mesh is not well defined.
2331  *  \throw If the spatial discretization of \a this field is NULL.
2332  *  \throw If the data array is not set.
2333  *  \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2334  */
2335 bool MEDCouplingFieldDouble::zipCoords(double epsOnVals)
2336 {
2337   const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2338   if(!meshC)
2339     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2340   if(!((const MEDCouplingFieldDiscretization *)_type))
2341     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipCoords !");
2342   MCAuto<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCopy());
2343   int oldNbOfNodes=meshC2->getNumberOfNodes();
2344   MCAuto<DataArrayInt> arr=meshC2->zipCoordsTraducer();
2345   if(meshC2->getNumberOfNodes()!=oldNbOfNodes)
2346     {
2347       std::vector<DataArrayDouble *> arrays;
2348       _time_discr->getArrays(arrays);
2349       for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2350         if(*iter)
2351           _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2352       setMesh(meshC2);
2353       return true;
2354     }
2355   return false;
2356 }
2357
2358 /*!
2359  * Removes duplicates of cells from the understanding mesh. If some cells are
2360  * removed, the underlying mesh is replaced by a new mesh instance where the cells
2361  * duplicates are removed.<br>
2362  *  \param [in] compType - specifies a cell comparison technique. Meaning of its
2363  *          valid values [0,1,2] is explained in the description of
2364  *          MEDCouplingPointSet::zipConnectivityTraducer() which is called by this method.
2365  *  \param [in] epsOnVals - a precision used to compare field
2366  *         values at merged cells. If the values differ more than \a epsOnVals, an
2367  *         exception is thrown.
2368  *  \return bool - \c true if some cells have been removed and hence \a this field lies
2369  *         on another mesh.
2370  *  \throw If the mesh is not an instance of MEDCouplingUMesh.
2371  *  \throw If the mesh is not well defined.
2372  *  \throw If the spatial discretization of \a this field is NULL.
2373  *  \throw If the data array is not set.
2374  *  \throw If field values at merged cells (if any) deffer more than \a epsOnVals.
2375  */
2376 bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals)
2377 {
2378   const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(_mesh);
2379   if(!meshC)
2380     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipConnectivity : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2381   if(!((const MEDCouplingFieldDiscretization *)_type))
2382     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipConnectivity !");
2383   MCAuto<MEDCouplingUMesh> meshC2((MEDCouplingUMesh *)meshC->deepCopy());
2384   int oldNbOfCells=meshC2->getNumberOfCells();
2385   MCAuto<DataArrayInt> arr=meshC2->zipConnectivityTraducer(compType);
2386   if(meshC2->getNumberOfCells()!=oldNbOfCells)
2387     {
2388       std::vector<DataArrayDouble *> arrays;
2389       _time_discr->getArrays(arrays);
2390       for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2391         if(*iter)
2392           _type->renumberValuesOnCells(epsOnVals,meshC,arr->getConstPointer(),meshC2->getNumberOfCells(),*iter);
2393       setMesh(meshC2);
2394       return true;
2395     }
2396   return false;
2397 }
2398
2399 /*!
2400  * This method calls MEDCouplingUMesh::buildSlice3D method. So this method makes the assumption that underlying mesh exists.
2401  * For the moment, this method is implemented for fields on cells.
2402  * 
2403  * \return a newly allocated field double containing the result that the user should deallocate.
2404  */
2405 MEDCouplingFieldDouble *MEDCouplingFieldDouble::extractSlice3D(const double *origin, const double *vec, double eps) const
2406 {
2407   const MEDCouplingMesh *mesh=getMesh();
2408   if(!mesh)
2409     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : underlying mesh is null !");
2410   if(getTypeOfField()!=ON_CELLS)
2411     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : only implemented for fields on cells !");
2412   const MCAuto<MEDCouplingUMesh> umesh(mesh->buildUnstructured());
2413   MCAuto<MEDCouplingFieldDouble> ret=clone(false);
2414   ret->setMesh(umesh);
2415   DataArrayInt *cellIds=0;
2416   MCAuto<MEDCouplingUMesh> mesh2=umesh->buildSlice3D(origin,vec,eps,cellIds);
2417   MCAuto<DataArrayInt> cellIds2=cellIds;
2418   ret->setMesh(mesh2);
2419   MCAuto<DataArrayInt> tupleIds=computeTupleIdsToSelectFromCellIds(cellIds->begin(),cellIds->end());
2420   std::vector<DataArrayDouble *> arrays;
2421   _time_discr->getArrays(arrays);
2422   int i=0;
2423   std::vector<DataArrayDouble *> newArr(arrays.size());
2424   std::vector< MCAuto<DataArrayDouble> > newArr2(arrays.size());
2425   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,i++)
2426     {
2427       if(*iter)
2428         {
2429           newArr2[i]=(*iter)->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
2430           newArr[i]=newArr2[i];
2431         }
2432     }
2433   ret->setArrays(newArr);
2434   return ret.retn();
2435 }
2436
2437 /*!
2438  * Divides every cell of the underlying mesh into simplices (triangles in 2D and
2439  * tetrahedra in 3D). If some cells are divided, the underlying mesh is replaced by a new
2440  * mesh instance containing the simplices.<br> 
2441  *  \param [in] policy - specifies a pattern used for splitting. For its description, see
2442  *          MEDCouplingUMesh::simplexize().
2443  *  \return bool - \c true if some cells have been divided and hence \a this field lies
2444  *         on another mesh.
2445  *  \throw If \a policy has an invalid value. For valid values, see the description of 
2446  *         MEDCouplingUMesh::simplexize().
2447  *  \throw If MEDCouplingMesh::simplexize() is not applicable to the underlying mesh.
2448  *  \throw If the mesh is not well defined.
2449  *  \throw If the spatial discretization of \a this field is NULL.
2450  *  \throw If the data array is not set.
2451  */
2452 bool MEDCouplingFieldDouble::simplexize(int policy)
2453 {
2454   if(!_mesh)
2455     throw INTERP_KERNEL::Exception("No underlying mesh on this field to perform simplexize !");
2456   if(!((const MEDCouplingFieldDiscretization *)_type))
2457     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform simplexize !");
2458   int oldNbOfCells=_mesh->getNumberOfCells();
2459   MCAuto<MEDCouplingMesh> meshC2(_mesh->deepCopy());
2460   MCAuto<DataArrayInt> arr=meshC2->simplexize(policy);
2461   int newNbOfCells=meshC2->getNumberOfCells();
2462   if(oldNbOfCells==newNbOfCells)
2463     return false;
2464   std::vector<DataArrayDouble *> arrays;
2465   _time_discr->getArrays(arrays);
2466   for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2467     if(*iter)
2468       _type->renumberValuesOnCellsR(_mesh,arr->getConstPointer(),arr->getNbOfElems(),*iter);
2469   setMesh(meshC2);
2470   return true;
2471 }
2472
2473 /*!
2474  * Creates a new MEDCouplingFieldDouble filled with the doubly contracted product of
2475  * every tensor of \a this 6-componental field.
2476  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2477  *          each tuple is calculated from the tuple <em>(t)</em> of \a this field as
2478  *          follows: \f$ t[0]^2+t[1]^2+t[2]^2+2*t[3]^2+2*t[4]^2+2*t[5]^2\f$. 
2479  *          This new field lies on the same mesh as \a this one. The caller is to delete
2480  *          this field using decrRef() as it is no more needed.
2481  *  \throw If \a this->getNumberOfComponents() != 6.
2482  *  \throw If the spatial discretization of \a this field is NULL.
2483  */
2484 MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const
2485 {
2486   if(!((const MEDCouplingFieldDiscretization *)_type))
2487     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform doublyContractedProduct !");
2488   MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct();
2489   td->copyTinyAttrFrom(*_time_discr);
2490   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2491   ret->setName("DoublyContractedProduct");
2492   ret->setMesh(getMesh());
2493   return ret.retn();
2494 }
2495
2496 /*!
2497  * Creates a new MEDCouplingFieldDouble filled with the determinant of a square
2498  * matrix defined by every tuple of \a this field, having either 4, 6 or 9 components.
2499  * The case of 6 components corresponds to that of the upper triangular matrix. 
2500  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2501  *          each tuple is the determinant of matrix of the corresponding tuple of \a this 
2502  *          field. This new field lies on the same mesh as \a this one. The caller is to 
2503  *          delete this field using decrRef() as it is no more needed.
2504  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2505  *  \throw If the spatial discretization of \a this field is NULL.
2506  */
2507 MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const
2508 {
2509   if(!((const MEDCouplingFieldDiscretization *)_type))
2510     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform determinant !");
2511   MEDCouplingTimeDiscretization *td=_time_discr->determinant();
2512   td->copyTinyAttrFrom(*_time_discr);
2513   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2514   ret->setName("Determinant");
2515   ret->setMesh(getMesh());
2516   return ret.retn();
2517 }
2518
2519
2520 /*!
2521  * Creates a new MEDCouplingFieldDouble with 3 components filled with 3 eigenvalues of
2522  * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2523  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2524  *          having 3 components, whose each tuple contains the eigenvalues of the matrix of
2525  *          corresponding tuple of \a this field. This new field lies on the same mesh as
2526  *          \a this one. The caller is to delete this field using decrRef() as it is no
2527  *          more needed.  
2528  *  \throw If \a this->getNumberOfComponents() != 6.
2529  *  \throw If the spatial discretization of \a this field is NULL.
2530  */
2531 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const
2532 {
2533   if(!((const MEDCouplingFieldDiscretization *)_type))
2534     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenValues !");
2535   MEDCouplingTimeDiscretization *td=_time_discr->eigenValues();
2536   td->copyTinyAttrFrom(*_time_discr);
2537   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2538   ret->setName("EigenValues");
2539   ret->setMesh(getMesh());
2540   return ret.retn();
2541 }
2542
2543 /*!
2544  * Creates a new MEDCouplingFieldDouble with 9 components filled with 3 eigenvectors of
2545  * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2546  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2547  *          having 9 components, whose each tuple contains the eigenvectors of the matrix of
2548  *          corresponding tuple of \a this field. This new field lies on the same mesh as
2549  *          \a this one. The caller is to delete this field using decrRef() as it is no
2550  *          more needed.  
2551  *  \throw If \a this->getNumberOfComponents() != 6.
2552  *  \throw If the spatial discretization of \a this field is NULL.
2553  */
2554 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const
2555 {
2556   if(!((const MEDCouplingFieldDiscretization *)_type))
2557     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenVectors !");
2558   MEDCouplingTimeDiscretization *td=_time_discr->eigenVectors();
2559   td->copyTinyAttrFrom(*_time_discr);
2560   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2561   ret->setName("EigenVectors");
2562   ret->setMesh(getMesh());
2563   return ret.retn();
2564 }
2565
2566 /*!
2567  * Creates a new MEDCouplingFieldDouble filled with the inverse matrix 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 the same number of components as \a this one, whose each tuple
2573  *          contains the inverse matrix of the matrix of corresponding tuple of \a this
2574  *          field. 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::inverse() const
2580 {
2581   if(!((const MEDCouplingFieldDiscretization *)_type))
2582     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform inverse !");
2583   MEDCouplingTimeDiscretization *td=_time_discr->inverse();
2584   td->copyTinyAttrFrom(*_time_discr);
2585   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2586   ret->setName("Inversion");
2587   ret->setMesh(getMesh());
2588   return ret.retn();
2589 }
2590
2591 /*!
2592  * Creates a new MEDCouplingFieldDouble filled with the trace of
2593  * a matrix defined by every tuple of \a this field having either 4, 6 or 9
2594  * components. The case of 6 components corresponds to that of the upper triangular
2595  * matrix.
2596  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2597  *          having 1 component, whose each tuple is the trace of the matrix of
2598  *          corresponding tuple of \a this field.
2599  *          This new field lies on the same mesh as \a this one. The caller is to
2600  *          delete this field using decrRef() as it is no more needed.  
2601  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2602  *  \throw If the spatial discretization of \a this field is NULL.
2603  */
2604 MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const
2605 {
2606   if(!((const MEDCouplingFieldDiscretization *)_type))
2607     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform trace !");
2608   MEDCouplingTimeDiscretization *td=_time_discr->trace();
2609   td->copyTinyAttrFrom(*_time_discr);
2610   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2611   ret->setName("Trace");
2612   ret->setMesh(getMesh());
2613   return ret.retn();
2614 }
2615
2616 /*!
2617  * Creates a new MEDCouplingFieldDouble filled with the stress deviator tensor of
2618  * a stress tensor defined by every tuple of \a this 6-componental field.
2619  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2620  *          having same number of components and tuples as \a this field,
2621  *          whose each tuple contains the stress deviator tensor of the stress tensor of
2622  *          corresponding tuple of \a this field. This new field lies on the same mesh as
2623  *          \a this one. The caller is to delete this field using decrRef() as it is no
2624  *          more needed.  
2625  *  \throw If \a this->getNumberOfComponents() != 6.
2626  *  \throw If the spatial discretization of \a this field is NULL.
2627  */
2628 MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const
2629 {
2630   if(!((const MEDCouplingFieldDiscretization *)_type))
2631     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform deviator !");
2632   MEDCouplingTimeDiscretization *td=_time_discr->deviator();
2633   td->copyTinyAttrFrom(*_time_discr);
2634   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2635   ret->setName("Deviator");
2636   ret->setMesh(getMesh());
2637   return ret.retn();
2638 }
2639
2640 /*!
2641  * Creates a new MEDCouplingFieldDouble filled with the magnitude of
2642  * every vector of \a this field.
2643  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, 
2644  *          having one component, whose each tuple is the magnitude of the vector
2645  *          of corresponding tuple of \a this field. This new field lies on the
2646  *          same mesh as \a this one. The caller is to
2647  *          delete this field using decrRef() as it is no more needed.  
2648  *  \throw If the spatial discretization of \a this field is NULL.
2649  */
2650 MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const
2651 {
2652   if(!((const MEDCouplingFieldDiscretization *)_type))
2653     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform magnitude !");
2654   MEDCouplingTimeDiscretization *td=_time_discr->magnitude();
2655   td->copyTinyAttrFrom(*_time_discr);
2656   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2657   ret->setName("Magnitude");
2658   ret->setMesh(getMesh());
2659   return ret.retn();
2660 }
2661
2662 /*!
2663  * Creates a new scalar MEDCouplingFieldDouble filled with the maximal value among
2664  * values of every tuple of \a this field.
2665  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2666  *          This new field lies on the same mesh as \a this one. The caller is to
2667  *          delete this field using decrRef() as it is no more needed.  
2668  *  \throw If the spatial discretization of \a this field is NULL.
2669  */
2670 MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const
2671 {
2672   if(!((const MEDCouplingFieldDiscretization *)_type))
2673     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform maxPerTuple !");
2674   MEDCouplingTimeDiscretization *td=_time_discr->maxPerTuple();
2675   td->copyTinyAttrFrom(*_time_discr);
2676   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2677   std::ostringstream oss;
2678   oss << "Max_" << getName();
2679   ret->setName(oss.str());
2680   ret->setMesh(getMesh());
2681   return ret.retn();
2682 }
2683
2684 /*!
2685  * Changes number of components in \a this field. If \a newNbOfComp is less
2686  * than \a this->getNumberOfComponents() then each tuple
2687  * is truncated to have \a newNbOfComp components, keeping first components. If \a
2688  * newNbOfComp is more than \a this->getNumberOfComponents() then 
2689  * each tuple is populated with \a dftValue to have \a newNbOfComp components.  
2690  *  \param [in] newNbOfComp - number of components for the new field to have.
2691  *  \param [in] dftValue - value assigned to new values added to \a this field.
2692  *  \throw If \a this is not allocated.
2693  */
2694 void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftValue)
2695 {
2696   _time_discr->changeNbOfComponents(newNbOfComp,dftValue);
2697 }
2698
2699 /*!
2700  * Creates a new MEDCouplingFieldDouble composed of selected components of \a this field.
2701  * The new MEDCouplingFieldDouble has the same number of tuples but includes components
2702  * specified by \a compoIds parameter. So that getNbOfElems() of the result field
2703  * can be either less, same or more than \a this->getNumberOfValues().
2704  *  \param [in] compoIds - sequence of zero based indices of components to include
2705  *              into the new field.
2706  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble that the caller
2707  *          is to delete using decrRef() as it is no more needed.
2708  *  \throw If a component index (\a i) is not valid: 
2709  *         \a i < 0 || \a i >= \a this->getNumberOfComponents().
2710  */
2711 MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std::vector<int>& compoIds) const
2712 {
2713   if(!((const MEDCouplingFieldDiscretization *)_type))
2714     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform keepSelectedComponents !");
2715   MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds);
2716   td->copyTinyAttrFrom(*_time_discr);
2717   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2718   ret->setName(getName());
2719   ret->setMesh(getMesh());
2720   return ret.retn();
2721 }
2722
2723
2724 /*!
2725  * Copy all components in a specified order from another field.
2726  * The number of tuples in \a this and the other field can be different.
2727  *  \param [in] f - the field to copy data from.
2728  *  \param [in] compoIds - sequence of zero based indices of components, data of which is
2729  *              to be copied.
2730  *  \throw If the two fields have different number of data arrays.
2731  *  \throw If a data array is set in one of fields and is not set in the other.
2732  *  \throw If \a compoIds.size() != \a a->getNumberOfComponents().
2733  *  \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
2734  */
2735 void MEDCouplingFieldDouble::setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector<int>& compoIds)
2736 {
2737   _time_discr->setSelectedComponents(f->_time_discr,compoIds);
2738 }
2739
2740 /*!
2741  * Sorts value within every tuple of \a this field.
2742  *  \param [in] asc - if \a true, the values are sorted in ascending order, else,
2743  *              in descending order.
2744  *  \throw If a data array is not allocated.
2745  */
2746 void MEDCouplingFieldDouble::sortPerTuple(bool asc)
2747 {
2748   _time_discr->sortPerTuple(asc);
2749 }
2750
2751 /*!
2752  * Creates a new MEDCouplingFieldDouble by concatenating two given fields.
2753  * Values of
2754  * the first field precede values of the second field within the result field.
2755  *  \param [in] f1 - the first field.
2756  *  \param [in] f2 - the second field.
2757  *  \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2758  *          MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef() 
2759  *          as it is no more needed.
2760  *  \throw If the fields are not compatible for the merge.
2761  *  \throw If the spatial discretization of \a f1 is NULL.
2762  *  \throw If the time discretization of \a f1 is NULL.
2763  *
2764  *  \if ENABLE_EXAMPLES
2765  *  \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2766  *  \ref  py_mcfielddouble_MergeFields "Here is a Python example".
2767  *  \endif
2768  */
2769 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2770 {
2771   if(!f1->areCompatibleForMerge(f2))
2772     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MergeFields on them ! Check support mesh, field nature, and spatial and time discretisation.");
2773   const MEDCouplingMesh *m1(f1->getMesh()),*m2(f2->getMesh());
2774   if(!f1->_time_discr)
2775     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no time discr of f1 !");
2776   if(!f1->_type)
2777     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no spatial discr of f1 !");
2778   MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr);
2779   td->copyTinyAttrFrom(*f1->_time_discr);
2780   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2781   ret->setName(f1->getName());
2782   ret->setDescription(f1->getDescription());
2783   if(m1)
2784     {
2785       MCAuto<MEDCouplingMesh> m=m1->mergeMyselfWith(m2);
2786       ret->setMesh(m);
2787     }
2788   return ret.retn();
2789 }
2790
2791 /*!
2792  * Creates a new MEDCouplingFieldDouble by concatenating all given fields.
2793  * Values of the *i*-th field precede values of the (*i*+1)-th field within the result.
2794  * If there is only one field in \a a, a deepCopy() (except time information of mesh and
2795  * field) of the field is returned. 
2796  * Generally speaking the first field in \a a is used to assign tiny attributes of the
2797  * returned field. 
2798  *  \param [in] a - a vector of fields (MEDCouplingFieldDouble) to concatenate.
2799  *  \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2800  *          MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef() 
2801  *          as it is no more needed.
2802  *  \throw If \a a is empty.
2803  *  \throw If the fields are not compatible for the merge.
2804  *
2805  *  \if ENABLE_EXAMPLES
2806  *  \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2807  *  \ref  py_mcfielddouble_MergeFields "Here is a Python example".
2808  *  \endif
2809  */
2810 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector<const MEDCouplingFieldDouble *>& a)
2811 {
2812   if(a.size()<1)
2813     throw INTERP_KERNEL::Exception("FieldDouble::MergeFields : size of array must be >= 1 !");
2814   std::vector< MCAuto<MEDCouplingUMesh> > ms(a.size());
2815   std::vector< const MEDCouplingUMesh *> ms2(a.size());
2816   std::vector< const MEDCouplingTimeDiscretization *> tds(a.size());
2817   std::vector<const MEDCouplingFieldDouble *>::const_iterator it=a.begin();
2818   const MEDCouplingFieldDouble *ref=(*it++);
2819   if(!ref)
2820     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : presence of NULL instance in first place of input vector !");
2821   for(;it!=a.end();it++)
2822     if(!ref->areCompatibleForMerge(*it))
2823       throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MergeFields on them! Check support mesh, field nature, and spatial and time discretisation.");
2824   for(int i=0;i<(int)a.size();i++)
2825     {
2826       if(a[i]->getMesh())
2827         { ms[i]=a[i]->getMesh()->buildUnstructured(); ms2[i]=ms[i]; }
2828       else
2829         { ms[i]=0; ms2[i]=0; }
2830       tds[i]=a[i]->_time_discr;
2831     }
2832   MEDCouplingTimeDiscretization *td=tds[0]->aggregate(tds);
2833   td->copyTinyAttrFrom(*(a[0]->_time_discr));
2834   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone());
2835   ret->setName(a[0]->getName());
2836   ret->setDescription(a[0]->getDescription());
2837   if(ms2[0])
2838     {
2839       MCAuto<MEDCouplingUMesh> m=MEDCouplingUMesh::MergeUMeshes(ms2);
2840       m->copyTinyInfoFrom(ms2[0]);
2841       ret->setMesh(m);
2842     }
2843   return ret.retn();
2844 }
2845
2846 /*!
2847  * Creates a new MEDCouplingFieldDouble by concatenating components of two given fields.
2848  * The number of components in the result field is a sum of the number of components of
2849  * given fields. The number of tuples in the result field is same as that of each of given
2850  * arrays.
2851  * Number of tuples in the given fields must be the same.
2852  *  \param [in] f1 - a field to include in the result field.
2853  *  \param [in] f2 - another field to include in the result 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 the fields are not compatible for a meld (areCompatibleForMeld()).
2858  *  \throw If any of data arrays is not allocated.
2859  *  \throw If \a f1->getNumberOfTuples() != \a f2->getNumberOfTuples()
2860  */
2861 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MeldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2862 {
2863   if(!f1->areCompatibleForMeld(f2))
2864     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MeldFields on them ! Check support mesh, field nature, and spatial and time discretisation.");
2865   MEDCouplingTimeDiscretization *td=f1->_time_discr->meld(f2->_time_discr);
2866   td->copyTinyAttrFrom(*f1->_time_discr);
2867   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2868   ret->setMesh(f1->getMesh());
2869   return ret.retn();
2870 }
2871
2872 /*!
2873  * Returns a new MEDCouplingFieldDouble containing a dot product of two given fields, 
2874  * so that the i-th tuple of the result field is a sum of products of j-th components of
2875  * i-th tuples of given fields (\f$ f_i = \sum_{j=1}^n f1_j * f2_j \f$). 
2876  * Number of tuples and components in the given fields must be the same.
2877  *  \param [in] f1 - a given field.
2878  *  \param [in] f2 - another given field.
2879  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2880  *          The caller is to delete this result field using decrRef() as it is no more
2881  *          needed.
2882  *  \throw If either \a f1 or \a f2 is NULL.
2883  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2884  *         differ not only in values.
2885  */
2886 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2887 {
2888   if(!f1)
2889     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DotFields : input field is NULL !");
2890   if(!f1->areStrictlyCompatibleForMulDiv(f2))
2891     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply DotFields on them!  Check support mesh, and spatial and time discretisation.");
2892   MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr);
2893   td->copyTinyAttrFrom(*f1->_time_discr);
2894   MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
2895   ret->setMesh(f1->getMesh());
2896   return ret;
2897 }
2898
2899 /*!
2900  * Returns a new MEDCouplingFieldDouble containing a cross product of two given fields, 
2901  * so that
2902  * the i-th tuple of the result field is a 3D vector which is a cross
2903  * product of two vectors defined by the i-th tuples of given fields.
2904  * Number of tuples in the given fields must be the same.
2905  * Number of components in the given fields must be 3.
2906  *  \param [in] f1 - a given field.
2907  *  \param [in] f2 - another given field.
2908  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2909  *          The caller is to delete this result field using decrRef() as it is no more
2910  *          needed.
2911  *  \throw If either \a f1 or \a f2 is NULL.
2912  *  \throw If \a f1->getNumberOfComponents() != 3
2913  *  \throw If \a f2->getNumberOfComponents() != 3
2914  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2915  *         differ not only in values.
2916  */
2917 MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2918 {
2919   if(!f1)
2920     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::CrossProductFields : input field is NULL !");
2921   if(!f1->areStrictlyCompatibleForMulDiv(f2))
2922     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply CrossProductFields on them! Check support mesh, and spatial and time discretisation.");
2923   MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr);
2924   td->copyTinyAttrFrom(*f1->_time_discr);
2925   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
2926   ret->setMesh(f1->getMesh());
2927   return ret.retn();
2928 }
2929
2930 /*!
2931  * Returns a new MEDCouplingFieldDouble containing maximal values of two given fields.
2932  * Number of tuples and components in the given fields must be the same.
2933  *  \param [in] f1 - a field to compare values with another one.
2934  *  \param [in] f2 - another field to compare values with the first one.
2935  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2936  *          The caller is to delete this result field using decrRef() as it is no more
2937  *          needed.
2938  *  \throw If either \a f1 or \a f2 is NULL.
2939  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2940  *         differ not only in values.
2941  *
2942  *  \if ENABLE_EXAMPLES
2943  *  \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2944  *  \ref  py_mcfielddouble_MaxFields "Here is a Python example".
2945  *  \endif
2946  */
2947 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2948 {
2949   if(!f1)
2950     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MaxFields : input field is NULL !");
2951   if(!f1->areStrictlyCompatible(f2))
2952     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MaxFields on them! Check support mesh, field nature, and spatial and time discretisation.");
2953   MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr);
2954   td->copyTinyAttrFrom(*f1->_time_discr);
2955   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2956   ret->setMesh(f1->getMesh());
2957   return ret.retn();
2958 }
2959
2960 /*!
2961  * Returns a new MEDCouplingFieldDouble containing minimal values of two given fields.
2962  * Number of tuples and components in the given fields must be the same.
2963  *  \param [in] f1 - a field to compare values with another one.
2964  *  \param [in] f2 - another field to compare values with the first one.
2965  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2966  *          The caller is to delete this result field using decrRef() as it is no more
2967  *          needed.
2968  *  \throw If either \a f1 or \a f2 is NULL.
2969  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2970  *         differ not only in values.
2971  *
2972  *  \if ENABLE_EXAMPLES
2973  *  \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2974  *  \ref  py_mcfielddouble_MaxFields "Here is a Python example".
2975  *  \endif
2976  */
2977 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2978 {
2979   if(!f1)
2980     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MinFields : input field is NULL !");
2981   if(!f1->areStrictlyCompatible(f2))
2982     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MinFields on them! Check support mesh, field nature, and spatial and time discretisation.");
2983   MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr);
2984   td->copyTinyAttrFrom(*f1->_time_discr);
2985   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2986   ret->setMesh(f1->getMesh());
2987   return ret.retn();
2988 }
2989
2990 /*!
2991  * Returns a copy of \a this field in which sign of all values is reversed.
2992  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble
2993  *         containing the same number of tuples and components as \a this field. 
2994  *         The caller is to delete this result field using decrRef() as it is no more
2995  *         needed. 
2996  *  \throw If the spatial discretization of \a this field is NULL.
2997  *  \throw If a data array is not allocated.
2998  */
2999 MEDCouplingFieldDouble *MEDCouplingFieldDouble::negate() const
3000 {
3001   if(!((const MEDCouplingFieldDiscretization *)_type))
3002     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform negate !");
3003   MEDCouplingTimeDiscretization *td=_time_discr->negate();
3004   td->copyTinyAttrFrom(*_time_discr);
3005   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
3006   ret->setMesh(getMesh());
3007   return ret.retn();
3008 }
3009
3010 /*!
3011  * Returns a new MEDCouplingFieldDouble containing sum values of corresponding values of
3012  * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] + _f2_ [ i, j ] ).
3013  * Number of tuples and components in the given fields must be the same.
3014  *  \param [in] f1 - a field to sum up.
3015  *  \param [in] f2 - another field to sum up.
3016  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
3017  *          The caller is to delete this result field using decrRef() as it is no more
3018  *          needed.
3019  *  \throw If either \a f1 or \a f2 is NULL.
3020  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3021  *         differ not only in values.
3022  */
3023 MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3024 {
3025   if(!f1)
3026     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::AddFields : input field is NULL !");
3027   if(!f1->areStrictlyCompatible(f2))
3028     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply AddFields on them! Check support mesh, field nature, and spatial and time discretisation.");
3029   MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr);
3030   td->copyTinyAttrFrom(*f1->_time_discr);
3031   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3032   ret->setMesh(f1->getMesh());
3033   return ret.retn();
3034 }
3035
3036 /*!
3037  * Adds values of another MEDCouplingFieldDouble to values of \a this one
3038  * ( _this_ [ i, j ] += _other_ [ i, j ] ) using DataArrayDouble::addEqual().
3039  * The two fields must have same number of tuples, components and same underlying mesh.
3040  *  \param [in] other - the field to add to \a this one.
3041  *  \return const MEDCouplingFieldDouble & - a reference to \a this field.
3042  *  \throw If \a other is NULL.
3043  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3044  *         differ not only in values.
3045  */
3046 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other)
3047 {
3048   if(!areStrictlyCompatible(&other))
3049     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply += on them! Check support mesh, field nature, and spatial and time discretisation.");
3050   _time_discr->addEqual(other._time_discr);
3051   return *this;
3052 }
3053
3054 /*!
3055  * Returns a new MEDCouplingFieldDouble containing subtraction of corresponding values of
3056  * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] - _f2_ [ i, j ] ).
3057  * Number of tuples and components in the given fields must be the same.
3058  *  \param [in] f1 - a field to subtract from.
3059  *  \param [in] f2 - a field to subtract.
3060  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
3061  *          The caller is to delete this result field using decrRef() as it is no more
3062  *          needed.
3063  *  \throw If either \a f1 or \a f2 is NULL.
3064  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3065  *         differ not only in values.
3066  */
3067 MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3068 {
3069   if(!f1)
3070     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::SubstractFields : input field is NULL !");
3071   if(!f1->areStrictlyCompatible(f2))
3072     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply SubstractFields on them! Check support mesh, field nature, and spatial and time discretisation.");
3073   MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr);
3074   td->copyTinyAttrFrom(*f1->_time_discr);
3075   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3076   ret->setMesh(f1->getMesh());
3077   return ret.retn();
3078 }
3079
3080 /*!
3081  * Subtract values of another MEDCouplingFieldDouble from values of \a this one
3082  * ( _this_ [ i, j ] -= _other_ [ i, j ] ) using DataArrayDouble::substractEqual().
3083  * The two fields must have same number of tuples, components and same underlying mesh.
3084  *  \param [in] other - the field to subtract from \a this one.
3085  *  \return const MEDCouplingFieldDouble & - a reference to \a this field.
3086  *  \throw If \a other is NULL.
3087  *  \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3088  *         differ not only in values.
3089  */
3090 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other)
3091 {
3092   if(!areStrictlyCompatible(&other))
3093     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply -= on them! Check support mesh, field nature, and spatial and time discretisation.");
3094   _time_discr->substractEqual(other._time_discr);
3095   return *this;
3096 }
3097
3098 /*!
3099  * Returns a new MEDCouplingFieldDouble containing product values of
3100  * two given fields. There are 2 valid cases.
3101  * 1.  The fields have same number of tuples and components. Then each value of
3102  *   the result field (_f_) is a product of the corresponding values of _f1_ and
3103  *   _f2_, i.e. _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, j ].
3104  * 2.  The fields have same number of tuples and one field, say _f2_, has one
3105  *   component. Then
3106  *   _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, 0 ].
3107  *
3108  * The two fields must have same number of tuples and same underlying mesh.
3109  *  \param [in] f1 - a factor field.
3110  *  \param [in] f2 - another factor field.
3111  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, with no nature set.
3112  *          The caller is to delete this result field using decrRef() as it is no more
3113  *          needed.
3114  *  \throw If either \a f1 or \a f2 is NULL.
3115  *  \throw If the fields are not compatible for multiplication (areCompatibleForMul()),
3116  *         i.e. they differ not only in values and possibly number of components.
3117  */
3118 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3119 {
3120   if(!f1)
3121     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MultiplyFields : input field is NULL !");
3122   if(!f1->areCompatibleForMul(f2))
3123     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MultiplyFields on them! Check support mesh, and spatial and time discretisation.");
3124   MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr);
3125   td->copyTinyAttrFrom(*f1->_time_discr);
3126   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
3127   ret->setMesh(f1->getMesh());
3128   return ret.retn();
3129 }
3130
3131 /*!
3132  * Multiply values of another MEDCouplingFieldDouble to values of \a this one
3133  * using DataArrayDouble::multiplyEqual().
3134  * The two fields must have same number of tuples and same underlying mesh.
3135  * There are 2 valid cases.
3136  * 1.  The fields have same number of components. Then each value of
3137  *   \a other is multiplied to the corresponding value of \a this field, i.e.
3138  *   _this_ [ i, j ] *= _other_ [ i, j ].
3139  * 2. The _other_ field has one component. Then
3140  *   _this_ [ i, j ] *= _other_ [ i, 0 ].
3141  *
3142  * The two fields must have same number of tuples and same underlying mesh.
3143  *  \param [in] other - an field to multiply to \a this one.
3144  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, with no nature set.
3145  *          The caller is to delete this result field using decrRef() as it is no more
3146  *          needed.
3147  *  \throw If \a other is NULL.
3148  *  \throw If the fields are not strictly compatible for multiplication
3149  *         (areCompatibleForMul()),
3150  *         i.e. they differ not only in values and possibly in number of components.
3151  */
3152 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other)
3153 {
3154   if(!areCompatibleForMul(&other))
3155     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply *= on them! Check support mesh, and spatial and time discretisation.");
3156   _time_discr->multiplyEqual(other._time_discr);
3157   _nature = NoNature;
3158   return *this;
3159 }
3160
3161 /*!
3162  * Returns a new MEDCouplingFieldDouble containing division of two given fields.
3163  * There are 2 valid cases.
3164  * 1.  The fields have same number of tuples and components. Then each value of
3165  *   the result field (_f_) is a division of the corresponding values of \a f1 and
3166  *   \a f2, i.e. _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, j ].
3167  * 2.  The fields have same number of tuples and _f2_ has one component. Then
3168  *   _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, 0 ].
3169  *
3170  *  \param [in] f1 - a numerator field.
3171  *  \param [in] f2 - a denominator field.
3172  *  \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, with no nature set.
3173  *          The caller is to delete this result field using decrRef() as it is no more
3174  *          needed.
3175  *  \throw If either \a f1 or \a f2 is NULL.
3176  *  \throw If the fields are not compatible for division (areCompatibleForDiv()),
3177  *         i.e. they differ not only in values and possibly in number of components.
3178  */
3179 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3180 {
3181   if(!f1)
3182     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DivideFields : input field is NULL !");
3183   if(!f1->areCompatibleForDiv(f2))
3184     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply DivideFields on them! Check support mesh, and spatial and time discretisation.");
3185   MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr);
3186   td->copyTinyAttrFrom(*f1->_time_discr);
3187   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
3188   ret->setMesh(f1->getMesh());
3189   return ret.retn();
3190 }
3191
3192 /*!
3193  * Divide values of \a this field by values of another MEDCouplingFieldDouble
3194  * using DataArrayDouble::divideEqual().
3195  * The two fields must have same number of tuples and same underlying mesh.
3196  * There are 2 valid cases.
3197  * 1.  The fields have same number of components. Then each value of
3198  *    \a this field is divided by the corresponding value of \a other one, i.e.
3199  *   _this_ [ i, j ] /= _other_ [ i, j ].
3200  * 2.  The \a other field has one component. Then
3201  *   _this_ [ i, j ] /= _other_ [ i, 0 ].
3202  *
3203  *  \warning No check of division by zero is performed!
3204  *  \param [in] other - an field to divide \a this one by.
3205  *  \throw If \a other is NULL.
3206  *  \throw If the fields are not compatible for division (areCompatibleForDiv()),
3207  *         i.e. they differ not only in values and possibly in number of components.
3208  */
3209 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other)
3210 {
3211   if(!areCompatibleForDiv(&other))
3212     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply /= on them! Check support mesh, and spatial and time discretisation.");
3213   _time_discr->divideEqual(other._time_discr);
3214   _nature = NoNature;
3215   return *this;
3216 }
3217
3218 /*!
3219  * Directly called by MEDCouplingFieldDouble::operator^.
3220  * 
3221  * \sa MEDCouplingFieldDouble::operator^
3222  */
3223 MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3224 {
3225   if(!f1)
3226     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::PowFields : input field is NULL !");
3227   if(!f1->areCompatibleForMul(f2))
3228     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply PowFields on them! Check support mesh, and spatial and time discretisation.");
3229   MEDCouplingTimeDiscretization *td=f1->_time_discr->pow(f2->_time_discr);
3230   td->copyTinyAttrFrom(*f1->_time_discr);
3231   MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
3232   ret->setMesh(f1->getMesh());
3233   return ret.retn();
3234 }
3235
3236 /*!
3237  * Directly call MEDCouplingFieldDouble::PowFields static method.
3238  * 
3239  * \sa MEDCouplingFieldDouble::PowFields
3240  */
3241 MEDCouplingFieldDouble *MEDCouplingFieldDouble::operator^(const MEDCouplingFieldDouble& other) const
3242 {
3243   return PowFields(this,&other);
3244 }
3245
3246 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCouplingFieldDouble& other)
3247 {
3248   if(!areCompatibleForDiv(&other))
3249     throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply ^= on them!  Check support mesh, and spatial and time discretisation.");
3250   _time_discr->powEqual(other._time_discr);
3251   _nature = NoNature;
3252   return *this;
3253 }
3254
3255 /*!
3256  * Writes the field series \a fs and the mesh the fields lie on in the VTK file \a fileName.
3257  * If \a fs is empty no file is written.
3258  * The result file is valid provided that no exception is thrown.
3259  * \warning All the fields must be named and lie on the same non NULL mesh.
3260  *  \param [in] fileName - the name of a VTK file to write in.
3261  *  \param [in] fs - the fields to write.
3262  *  \param [in] isBinary - specifies the VTK format of the written file. By default true (Binary mode)
3263  *  \throw If \a fs[ 0 ] == NULL.
3264  *  \throw If the fields lie not on the same mesh.
3265  *  \throw If the mesh is not set.
3266  *  \throw If any of the fields has no name.
3267  *
3268  *  \if ENABLE_EXAMPLES
3269  *  \ref cpp_mcfielddouble_WriteVTK "Here is a C++ example".<br>
3270  *  \ref  py_mcfielddouble_WriteVTK "Here is a Python example".
3271  *  \endif
3272  */
3273 std::string MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const std::vector<const MEDCouplingFieldDouble *>& fs, bool isBinary)
3274 {
3275   if(fs.empty())
3276     return std::string();
3277   std::size_t nfs=fs.size();
3278   if(!fs[0])
3279     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field is NULL !");
3280   const MEDCouplingMesh *m=fs[0]->getMesh();
3281   if(!m)
3282     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field lies on NULL mesh !");
3283   for(std::size_t i=1;i<nfs;i++)
3284     if(fs[i]->getMesh()!=m)
3285       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.");
3286   if(!m)
3287     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are lying on a same mesh but it is empty !");
3288   std::string ret(m->getVTKFileNameOf(fileName));
3289   MCAuto<DataArrayByte> byteArr;
3290   if(isBinary)
3291     { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); }
3292   std::ostringstream coss,noss;
3293   for(std::size_t i=0;i<nfs;i++)
3294     {
3295       const MEDCouplingFieldDouble *cur=fs[i];
3296       std::string name(cur->getName());
3297       if(name.empty())
3298         {
3299           std::ostringstream oss; oss << "MEDCouplingFieldDouble::WriteVTK : Field in pos #" << i << " has no name !";
3300           throw INTERP_KERNEL::Exception(oss.str().c_str());
3301         }
3302       TypeOfField typ=cur->getTypeOfField();
3303       if(typ==ON_CELLS)
3304         cur->getArray()->writeVTK(coss,8,cur->getName(),byteArr);
3305       else if(typ==ON_NODES)
3306         cur->getArray()->writeVTK(noss,8,cur->getName(),byteArr);
3307       else
3308         throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : only node and cell fields supported for the moment !");
3309     }
3310   m->writeVTKAdvanced(ret,coss.str(),noss.str(),byteArr);
3311   return ret;
3312 }
3313
3314 void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const
3315 {
3316   stream << "MEDCouplingFieldDouble C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
3317   const char *nat=0;
3318   try
3319   {
3320       nat=MEDCouplingNatureOfField::GetRepr(_nature);
3321       stream << "Nature of field : " << nat << ".\n";
3322   }
3323   catch(INTERP_KERNEL::Exception& /*e*/)
3324   {  }
3325   const MEDCouplingFieldDiscretization *fd(_type);
3326   if(!fd)
3327     stream << "No spatial discretization set !";
3328   else
3329     fd->reprQuickOverview(stream);
3330   stream << std::endl;
3331   if(!_mesh)
3332     stream << "\nNo mesh support defined !";
3333   else
3334     {
3335       std::ostringstream oss;
3336       _mesh->reprQuickOverview(oss);
3337       std::string tmp(oss.str());
3338       stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
3339     }
3340   if(_time_discr)
3341     {
3342       const DataArrayDouble *arr=_time_discr->getArray();
3343       if(arr)
3344         {
3345           stream << "\n\nArray info : ";
3346           arr->reprQuickOverview(stream);
3347         }
3348       else
3349         {
3350           stream << "\n\nNo data array set !";
3351         }
3352     }
3353 }