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