Salome HOME
factorizations continue
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingField.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingField.hxx"
22 #include "MEDCouplingMesh.hxx"
23 #include "MEDCouplingFieldDiscretization.hxx"
24
25 #include <sstream>
26
27 using namespace ParaMEDMEM;
28
29 bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const throw(INTERP_KERNEL::Exception)
30 {
31   if(!other)
32     throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualIfNotWhy : other instance is NULL !");
33   std::ostringstream oss; oss.precision(15);
34   if(_name!=other->_name)
35     {
36       oss << "Field names differ : this name = \"" << _name << "\" and other name = \"" << other->_name << "\" !";
37       reason=oss.str();
38       return false;
39     }
40   if(_desc!=other->_desc)
41     {
42       oss << "Field descriptions differ : this description = \"" << _desc << "\" and other description = \"" << other->_desc << "\" !";
43       reason=oss.str();
44       return false;
45     }
46   if(_nature!=other->_nature)
47     {
48       oss << "Field nature differ : this nature = \"" << MEDCouplingNatureOfField::GetRepr(_nature) << "\" and other nature = \"" << MEDCouplingNatureOfField::GetRepr(other->_nature) << "\" !";
49       reason=oss.str();
50       return false;
51     }
52   if(!_type->isEqualIfNotWhy(other->_type,valsPrec,reason))
53     {
54       reason.insert(0,"Spatial discretizations differ :");
55       return false;
56     }
57   if(_mesh==0 && other->_mesh==0)
58     return true;
59   if(_mesh==0 || other->_mesh==0)
60     {
61       reason="Only one field between the two this and other has its underlying mesh defined !";
62       return false;
63     }
64   if(_mesh==other->_mesh)
65     return true;
66   bool ret=_mesh->isEqualIfNotWhy(other->_mesh,meshPrec,reason);
67   if(!ret)
68     reason.insert(0,"Underlying meshes of fields differ for the following reason : ");
69   return ret;
70 }
71
72 /*!
73  * Checks if \a this and another MEDCouplingField are fully equal.
74  *  \param [in] other - the field to compare with \a this one.
75  *  \param [in] meshPrec - precision used to compare node coordinates of the underlying mesh.
76  *  \param [in] valsPrec - precision used to compare field values.
77  *  \return bool - \c true if the two fields are equal, \c false else.
78  *  \throw If \a other is NULL.
79  */
80 bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const
81 {
82   std::string tmp;
83   return isEqualIfNotWhy(other,meshPrec,valsPrec,tmp);
84 }
85
86 /*!
87  * Checks if \a this and another MEDCouplingField are equal. The textual
88  * information like names etc. is not considered.
89  *  \param [in] other - the field to compare with \a this one.
90  *  \param [in] meshPrec - precision used to compare node coordinates of the underlying mesh.
91  *  \param [in] valsPrec - precision used to compare field values.
92  *  \return bool - \c true if the two fields are equal, \c false else.
93  *  \throw If \a other is NULL.
94  *  \throw If the spatial discretization of \a this field is NULL.
95  */
96 bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
97 {
98   if(!other)
99     throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : input field is NULL !");
100   if(!_type)
101     throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : spatial discretization of this is NULL !");
102   if(!_type->isEqualWithoutConsideringStr(other->_type,valsPrec))
103     return false;
104   if(_nature!=other->_nature)
105     return false;
106   if(_mesh==0 && other->_mesh==0)
107     return true;
108   if(_mesh==0 || other->_mesh==0)
109     return false;
110   if(_mesh==other->_mesh)
111     return true;
112   return _mesh->isEqualWithoutConsideringStr(other->_mesh,meshPrec);
113 }
114
115 /*!
116  * This method states if 'this' and 'other' are compatibles each other before performing any treatment.
117  * This method is good for methods like : mergeFields.
118  * This method is not very demanding compared to areStrictlyCompatible that is better for operation on fields.
119  */
120 bool MEDCouplingField::areCompatibleForMerge(const MEDCouplingField *other) const
121 {
122   if(!other)
123     throw INTERP_KERNEL::Exception("MEDCouplingField::areCompatibleForMerge : input field is NULL !");
124   if(!_type->isEqual(other->_type,1.))
125     return false;
126   if(_nature!=other->_nature)
127     return false;
128   if(_mesh==other->_mesh)
129     return true;
130   return _mesh->areCompatibleForMerge(other->_mesh);
131 }
132
133 /*!
134  * This method is more strict than MEDCouplingField::areCompatibleForMerge method.
135  * This method is used for operation on fields to operate a first check before attempting operation.
136  */
137 bool MEDCouplingField::areStrictlyCompatible(const MEDCouplingField *other) const
138 {
139   if(!other)
140     throw INTERP_KERNEL::Exception("MEDCouplingField::areStrictlyCompatible : input field is NULL !");
141   if(!_type->isEqual(other->_type,1.e-12))
142     return false;
143   if(_nature!=other->_nature)
144     return false;
145   return _mesh==other->_mesh;
146 }
147
148 void MEDCouplingField::updateTime() const
149 {
150   if(_mesh)
151     updateTimeWith(*_mesh);
152   if(_type)
153     updateTimeWith(*_type);
154 }
155
156 std::size_t MEDCouplingField::getHeapMemorySize() const
157 {
158   std::size_t ret=0;
159   ret+=_name.capacity();
160   ret+=_desc.capacity();
161   if(_mesh)
162     ret+=_mesh->getHeapMemorySize();
163   if((const MEDCouplingFieldDiscretization *)_type)
164     ret+=_type->getHeapMemorySize();
165   return ret;
166 }
167
168 /*!
169  * Returns a type of \ref MEDCouplingSpatialDisc "spatial discretization" of \a this
170  * field in terms of enum ParaMEDMEM::TypeOfField. 
171  *  \return ParaMEDMEM::TypeOfField - the type of \a this field.
172  */
173 TypeOfField MEDCouplingField::getTypeOfField() const
174 {
175   return _type->getEnum();
176 }
177
178 /*!
179  * Returns the nature of \a this field. This information is very important during
180  * interpolation process using ParaMEDMEM::MEDCouplingRemapper or ParaMEDMEM::InterpKernelDEC.
181  * In other context than the two mentioned above, this attribute is unimportant. This
182  * attribute is not stored in the MED file.
183  * For more information of the semantics and the influence of this attribute to the
184  * result of interpolation, see
185  * - \ref NatureOfField
186  * - \ref TableNatureOfField "How interpolation coefficients depend on Field Nature"
187  */
188 NatureOfField MEDCouplingField::getNature() const
189 {
190   return _nature;
191 }
192
193 /*!
194  * Sets the nature of \a this field. This information is very important during
195  * interpolation process using ParaMEDMEM::MEDCouplingRemapper or ParaMEDMEM::InterpKernelDEC.
196  * In other context than the two mentioned above, this attribute is unimportant. This
197  * attribute is not stored in the MED file.
198  * For more information of the semantics and the influence of this attribute to the
199  * result of interpolation, see
200  * - \ref NatureOfField
201  * - \ref TableNatureOfField "How interpolation coefficients depend on Field Nature"
202  *
203  *  \param [in] nat - the nature of \a this field.
204  *  \throw If \a nat has an invalid value.
205  */
206 void MEDCouplingField::setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception)
207 {
208   MEDCouplingNatureOfField::GetRepr(nat);//generate a throw if nat not recognized
209   _nature=nat;
210 }
211
212 /*!
213  * Returns coordinates of field location points that depend on 
214  * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field.
215  * - For a field on nodes, returns coordinates of nodes.
216  * - For a field on cells, returns barycenters of cells.
217  * - For a field on gauss points, returns coordinates of gauss points.
218  * 
219  *  \return DataArrayDouble * - a new instance of DataArrayDouble. The caller is to
220  *          delete this array using decrRef() as it is no more needed. 
221  *  \throw If the spatial discretization of \a this field is NULL.
222  *  \throw If the mesh is not set.
223  */
224 DataArrayDouble *MEDCouplingField::getLocalizationOfDiscr() const throw(INTERP_KERNEL::Exception)
225 {
226   if(!_mesh)
227     throw INTERP_KERNEL::Exception("MEDCouplingField::getLocalizationOfDiscr : No mesh set !");
228   if(!((const MEDCouplingFieldDiscretization *)_type))
229     throw INTERP_KERNEL::Exception("MEDCouplingField::getLocalizationOfDiscr : No spatial discretization set !");
230   return _type->getLocalizationOfDiscValues(_mesh);
231 }
232
233 /*!
234  * Returns a new MEDCouplingFieldDouble containing volumes of cells of a dual mesh whose
235  * cells are constructed around field location points (getLocalizationOfDiscr()) of \a this
236  * field. (In case of a field on cells, the dual mesh coincides with the underlying mesh).<br>
237  * For 1D cells, the returned field contains lengths.<br>
238  * For 2D cells, the returned field contains areas.<br>
239  * For 3D cells, the returned field contains volumes.
240  *  \param [in] isAbs - if \c true, the computed cell volume does not reflect cell
241  *         orientation, i.e. the volume is always positive.
242  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble.
243  *          The caller is to delete this array using decrRef() as
244  *          it is no more needed.
245  *  \throw If the mesh is not set.
246  *  \throw If the spatial discretization of \a this field is NULL.
247  *  \throw If the spatial discretization of \a this field is not well defined.
248  */
249
250 MEDCouplingFieldDouble *MEDCouplingField::buildMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception)
251 {
252   if(!_mesh)
253     throw INTERP_KERNEL::Exception("MEDCouplingField::buildMeasureField : no mesh defined !");
254   if(!((const MEDCouplingFieldDiscretization *)_type))
255     throw INTERP_KERNEL::Exception("MEDCouplingField::buildMeasureField : No spatial discretization set !");
256   return _type->getMeasureField(_mesh,isAbs);
257 }
258
259 /*!
260  * Sets the underlying mesh of \a this field.
261  * For examples of field construction, see \ref MEDCouplingFirstSteps3.
262  *  \param [in] mesh - the new underlying mesh.
263  */
264 void MEDCouplingField::setMesh(const MEDCouplingMesh *mesh)
265 {
266   if(mesh!=_mesh)
267     {
268       if(_mesh)
269         _mesh->decrRef();
270       _mesh=mesh;
271       declareAsNew();
272       if(_mesh)
273         {
274           _mesh->incrRef();
275           updateTimeWith(*_mesh);
276         }
277     }
278 }
279
280 /*!
281  * Sets localization of Gauss points for a given geometric type of cell.
282  *  \param [in] type - the geometric type of cell for which the Gauss localization is set.
283  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
284  *         must be \c nbOfNodesPerCell * \c dimOfType. 
285  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
286  *         must be  _wg_.size() * \c dimOfType.
287  *  \param [in] wg - the weights of Gauss points.
288  *  \throw If \a this field is not on Gauss points.
289  *  \throw If the spatial discretization of \a this field is NULL.
290  *  \throw If the mesh is not set.
291  *  \throw If size of any vector do not match the \a type.
292  */
293 void MEDCouplingField::setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
294                                                   const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception)
295 {
296   if(!_mesh)
297     throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnType method !");
298   if(!((const MEDCouplingFieldDiscretization *)_type))
299     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call setGaussLocalizationOnType method !");
300   _type->setGaussLocalizationOnType(_mesh,type,refCoo,gsCoo,wg);
301 }
302
303 /*!
304  * Sets localization of Gauss points for given cells specified by their ids.
305  *  \param [in] begin - an array of cell ids of interest.
306  *  \param [in] end - the end of \a begin, i.e. a pointer to its (last+1)-th element.
307  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
308  *         must be \c nbOfNodesPerCell * \c dimOfType. 
309  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
310  *         must be  _wg_.size() * \c dimOfType.
311  *  \param [in] wg - the weights of Gauss points.
312  *  \throw If \a this field is not on Gauss points.
313  *  \throw If the spatial discretization of \a this field is NULL.
314  *  \throw If the mesh is not set.
315  *  \throw If size of any vector do not match the type of cell # \a begin[0].
316  *  \throw If type of any cell in \a begin differs from that of cell # \a begin[0].
317  *  \throw If the range [_begin_,_end_) is empty.
318  */
319 void MEDCouplingField::setGaussLocalizationOnCells(const int *begin, const int *end, const std::vector<double>& refCoo,
320                                                    const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception)
321 {
322   if(!_mesh)
323     throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnCells method !");
324   if(!((const MEDCouplingFieldDiscretization *)_type))
325     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call setGaussLocalizationOnCells method !");
326   _type->setGaussLocalizationOnCells(_mesh,begin,end,refCoo,gsCoo,wg);
327 }
328
329 /*!
330  * Clears data on Gauss points localization.
331  *  \throw If \a this field is not on Gauss points.
332  *  \throw If the spatial discretization of \a this field is NULL.
333  *  \throw If the mesh is not set.
334  */
335 void MEDCouplingField::clearGaussLocalizations()
336 {
337   if(!_mesh)
338     throw INTERP_KERNEL::Exception("Mesh has to be set before calling clearGaussLocalizations method !");
339   if(!((const MEDCouplingFieldDiscretization *)_type))
340     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call clearGaussLocalizations method !");
341   _type->clearGaussLocalizations();
342 }
343
344 /*!
345  * Returns a reference to the Gauss localization object by its id.
346  * \warning This method is not const, so the returned object can be modified without any
347  *          problem.
348  *  \param [in] locId - the id of the Gauss localization object of interest.
349  *         It must be in range <em> 0 <= locId < getNbOfGaussLocalization() </em>.
350  *  \return \ref MEDCouplingGaussLocalization & - the Gauss localization object.
351  *  \throw If \a this field is not on Gauss points.
352  *  \throw If \a locId is not within the valid range.
353  *  \throw If the spatial discretization of \a this field is NULL.
354  *  \throw If the mesh is not set.
355  */
356 MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception)
357 {
358   if(!_mesh)
359     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !");
360   if(!((const MEDCouplingFieldDiscretization *)_type))
361     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalization method !");
362   return _type->getGaussLocalization(locId);
363 }
364
365 /*!
366  * Returns an id of the Gauss localization object corresponding to a given cell type.
367  *  \param [in] type - the cell type of interest.
368  *  \return int - the id of the Gauss localization object.
369  *  \throw If \a this field is not on Gauss points.
370  *  \throw If the spatial discretization of \a this field is NULL.
371  *  \throw If the mesh is not set.
372  *  \throw If no Gauss localization object found for the given cell \a type.
373  *  \throw If more than one Gauss localization object found for the given cell \a type.
374  */
375 int MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
376 {
377   if(!_mesh)
378     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneType method !");
379   if(!((const MEDCouplingFieldDiscretization *)_type))
380     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneType method !");
381   return _type->getGaussLocalizationIdOfOneType(type);
382 }
383
384 /*!
385  * Returns ids of Gauss localization objects corresponding to a given cell type.
386  *  \param [in] type - the cell type of interest.
387  *  \return std::set<int> - ids of the Gauss localization object.
388  *  \throw If \a this field is not on Gauss points.
389  *  \throw If the spatial discretization of \a this field is NULL.
390  *  \throw If the mesh is not set.
391  */
392 std::set<int> MEDCouplingField::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
393 {
394   if(!_mesh)
395     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdsOfOneType method !");
396   if(!((const MEDCouplingFieldDiscretization *)_type))
397     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdsOfOneType method !");
398   return _type->getGaussLocalizationIdsOfOneType(type);
399 }
400
401 /*!
402  * Returns number of Gauss localization objects available. Implicitly all ids in
403  * [0,getNbOfGaussLocalization()) are valid Gauss localization ids. 
404  *  \return int - the number of available Gauss localization objects.
405  *  \throw If \a this field is not on Gauss points.
406  *  \throw If the spatial discretization of \a this field is NULL.
407  *  \throw If the mesh is not set.
408  */
409 int MEDCouplingField::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception)
410 {
411   if(!_mesh)
412     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getNbOfGaussLocalization method !");
413   if(!((const MEDCouplingFieldDiscretization *)_type))
414     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNbOfGaussLocalization method !");
415   return _type->getNbOfGaussLocalization();
416 }
417
418 /*!
419  * Returns an id of the Gauss localization object corresponding to a type of a given cell.
420  *  \param [in] cellId - an id of the cell of interest.
421  *  \return int - the id of the Gauss localization object.
422  *  \throw If \a this field is not on Gauss points.
423  *  \throw If the spatial discretization of \a this field is NULL.
424  *  \throw If the mesh is not set.
425  *  \throw If no Gauss localization object found for the given cell.
426  */
427 int MEDCouplingField::getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception)
428 {
429   if(!_mesh)
430     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !");
431   if(!((const MEDCouplingFieldDiscretization *)_type))
432     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneCell method !");
433   return _type->getGaussLocalizationIdOfOneCell(cellId);
434 }
435
436 /*!
437  * Returns ids of cells that share the same Gauss localization given by its id.
438  *  \param [in] locId - the id of the Gauss localization object of interest. 
439  *         It must be in range <em> 0 <= locId < getNbOfGaussLocalization() </em>.
440  *  \param [in,out] cellIds - a vector returning ids of found cells. It is cleared before
441  *         filling in. It remains empty if no cells found.
442  *  \throw If \a this field is not on Gauss points.
443  *  \throw If \a locId is not within the valid range.
444  *  \throw If the spatial discretization of \a this field is NULL.
445  *  \throw If the mesh is not set.
446  */
447 void MEDCouplingField::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const throw(INTERP_KERNEL::Exception)
448 {
449   cellIds.clear();
450   if(!_mesh)
451     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !");
452   if(!((const MEDCouplingFieldDiscretization *)_type))
453     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getCellIdsHavingGaussLocalization method !");
454   _type->getCellIdsHavingGaussLocalization(locId,cellIds);
455 }
456
457 /*!
458  * Returns a reference to the Gauss localization object by its id.
459  * \warning This method is const, so the returned object is not apt for modification.
460  *  \param [in] locId - the id of the Gauss localization object of interest.
461  *         It must be in range <em> 0 <= locId < getNbOfGaussLocalization() </em>.
462  *  \return \ref const MEDCouplingGaussLocalization & - the Gauss localization object.
463  *  \throw If \a this field is not on Gauss points.
464  *  \throw If \a locId is not within the valid range.
465  *  \throw If the spatial discretization of \a this field is NULL.
466  *  \throw If the mesh is not set.
467  */
468 const MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception)
469 {
470   if(!_mesh)
471     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !");
472   if(!((const MEDCouplingFieldDiscretization *)_type))
473     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalization method !");
474   return _type->getGaussLocalization(locId);
475 }
476
477 MEDCouplingField::~MEDCouplingField()
478 {
479   if(_mesh)
480     _mesh->decrRef();
481 }
482
483 MEDCouplingField::MEDCouplingField(MEDCouplingFieldDiscretization *type, NatureOfField nature):_nature(nature),_mesh(0),_type(type)
484 {
485 }
486
487 MEDCouplingField::MEDCouplingField(TypeOfField type):_nature(NoNature),_mesh(0),_type(MEDCouplingFieldDiscretization::New(type))
488 {
489 }
490
491 MEDCouplingField::MEDCouplingField(const MEDCouplingField& other, bool deepCopy):RefCountObject(other),_name(other._name),_desc(other._desc),_nature(other._nature),
492                                                                                  _mesh(0),_type(0)
493 {
494   if(other._mesh)
495     {
496       _mesh=other._mesh;
497       _mesh->incrRef();
498     }
499   if(deepCopy)
500     _type=other._type->clone();
501   else
502     _type=other._type;
503 }
504
505 /*!
506  * Returns a new MEDCouplingMesh constituted by some cells of the underlying mesh of \a
507  * this filed, and returns ids of entities (nodes, cells, Gauss points) lying on the 
508  * specified cells. The cells to include to the result mesh are specified by an array of
509  * cell ids. The new mesh shares the coordinates array with the underlying mesh. 
510  *  \param [in] start - an array of cell ids to include to the result mesh.
511  *  \param [in] end - specifies the end of the array \a start, so that
512  *              the last value of \a start is \a end[ -1 ].
513  *  \param [out] di - a new instance of DataArrayInt holding the ids of entities (nodes,
514  *         cells, Gauss points). The caller is to delete this array using decrRef() as it
515  *         is no more needed.  
516  *  \return MEDCouplingMesh * - a new instance of MEDCouplingMesh. The caller is to
517  *         delete this mesh using decrRef() as it is no more needed. 
518  *  \throw If the spatial discretization of \a this field is NULL.
519  *  \throw If the mesh is not set.
520  * \sa buildSubMeshDataRange()
521  */
522 MEDCouplingMesh *MEDCouplingField::buildSubMeshData(const int *start, const int *end, DataArrayInt *&di) const
523 {
524   if(!((const MEDCouplingFieldDiscretization *)_type))
525     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call buildSubMeshData method !");
526   return _type->buildSubMeshData(_mesh,start,end,di);
527 }
528
529 /*!
530  * This method returns a submesh of 'mesh' instance constituting cell ids defined by a range given by the 3 following inputs \a begin, \a end and \a step.
531  * 
532  * \param [out] beginOut Valid only if \a di is NULL
533  * \param [out] endOut Valid only if \a di is NULL
534  * \param [out] stepOut Valid only if \a di is NULL
535  * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
536  * 
537  * \sa MEDCouplingField::buildSubMeshData
538  */
539 MEDCouplingMesh *MEDCouplingField::buildSubMeshDataRange(int begin, int end, int step, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
540 {
541   if(!((const MEDCouplingFieldDiscretization *)_type))
542     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call buildSubMeshDataRange method !");
543   return _type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,di);
544 }
545
546 /*!
547  * This method returns tuples ids implied by the mesh selection of the  cell ids contained in array defined as an interval [start;end).
548  * \return a newly allocated DataArrayInt instance containing tuples ids.
549  */
550 DataArrayInt *MEDCouplingField::computeTupleIdsToSelectFromCellIds(const int *startCellIds, const int *endCellIds) const
551 {
552   if(!((const MEDCouplingFieldDiscretization *)_type))
553     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call computeTupleIdsToSelectFromCellIds method !");
554   return _type->computeTupleIdsToSelectFromCellIds(_mesh,startCellIds,endCellIds);
555 }
556
557 /*!
558  * Returns number of tuples expected regarding the spatial discretization of \a this
559  * field and number of entities in the underlying mesh.
560  *  \return int - the number of expected tuples.
561  *  \throw If the spatial discretization of \a this field is NULL.
562  *  \throw If the mesh is not set.
563  */
564 int MEDCouplingField::getNumberOfTuplesExpected() const throw(INTERP_KERNEL::Exception)
565 {
566   if(!((const MEDCouplingFieldDiscretization *)_type))
567     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfTuplesExpected method !");
568   if(_mesh)
569     return _type->getNumberOfTuples(_mesh);
570   else
571     throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfTuplesExpected : Empty mesh !");
572 }
573
574 void MEDCouplingField::setDiscretization(MEDCouplingFieldDiscretization *newDisc)
575 {
576   bool needUpdate=(const MEDCouplingFieldDiscretization *)_type!=newDisc;
577   _type=newDisc;
578   if(newDisc)
579     newDisc->incrRef();
580   if(needUpdate)
581     declareAsNew();
582 }
583
584 /*!
585  * Returns number of mesh entities in the underlying mesh of \a this field regarding the
586  * spatial discretization.
587  *  \return int - the number of mesh entities porting the field values.
588  *  \throw If the spatial discretization of \a this field is NULL.
589  *  \throw If the mesh is not set.
590  */
591 int MEDCouplingField::getNumberOfMeshPlacesExpected() const throw(INTERP_KERNEL::Exception)
592 {
593   if(!((const MEDCouplingFieldDiscretization *)_type))
594     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfMeshPlacesExpected method !");
595   if(_mesh)
596     return _type->getNumberOfMeshPlaces(_mesh);
597   else
598     throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfMeshPlacesExpected : Empty mesh !");
599 }
600
601 /*!
602  * Copy tiny info (component names, name, description) but warning the underlying mesh is not renamed (for safety reason).
603  */
604 void MEDCouplingField::copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception)
605 {
606   if(other)
607     {
608       setName(other->_name.c_str());
609       setDescription(other->_desc.c_str());    
610     }
611 }