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