Salome HOME
OverlapDEC: bug fix. Bounding box adjustment was negative.
[modules/med.git] / src / MEDCoupling / MEDCouplingField.cxx
1 // Copyright (C) 2007-2015  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 "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
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 /*!
149  * This method is less strict than MEDCouplingField::areStrictlyCompatible method.
150  * The difference is that the nature is not checked.
151  * This method is used for multiplication and division on fields to operate a first check before attempting operation.
152  */
153 bool MEDCouplingField::areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const
154 {
155   if(!other)
156     throw INTERP_KERNEL::Exception("MEDCouplingField::areStrictlyCompatible : input field is NULL !");
157   if(!_type->isEqual(other->_type,1.e-12))
158     return false;
159   return _mesh==other->_mesh;
160 }
161
162
163 void MEDCouplingField::updateTime() const
164 {
165   if(_mesh)
166     updateTimeWith(*_mesh);
167   if(_type)
168     updateTimeWith(*_type);
169 }
170
171 std::size_t MEDCouplingField::getHeapMemorySizeWithoutChildren() const
172 {
173   std::size_t ret=0;
174   ret+=_name.capacity();
175   ret+=_desc.capacity();
176   return ret;
177 }
178
179 std::vector<const BigMemoryObject *> MEDCouplingField::getDirectChildrenWithNull() const
180 {
181   std::vector<const BigMemoryObject *> ret;
182   ret.push_back(_mesh);
183   ret.push_back((const MEDCouplingFieldDiscretization *)_type);
184   return ret;
185 }
186
187 /*!
188  * Returns a type of \ref MEDCouplingSpatialDisc "spatial discretization" of \a this
189  * field in terms of enum ParaMEDMEM::TypeOfField. 
190  * \return ParaMEDMEM::TypeOfField - the type of \a this field.
191  * \throw If the geometric type is empty.
192  */
193 TypeOfField MEDCouplingField::getTypeOfField() const
194 {
195   if(!((const MEDCouplingFieldDiscretization *)_type))
196     throw INTERP_KERNEL::Exception("MEDCouplingField::getTypeOfField : spatial discretization is null !");
197   return _type->getEnum();
198 }
199
200 /*!
201  * Returns the nature of \a this field. This information is very important during
202  * interpolation process using ParaMEDMEM::MEDCouplingRemapper or ParaMEDMEM::InterpKernelDEC.
203  * In other context than the two mentioned above, this attribute is unimportant. This
204  * attribute is not stored in the MED file.
205  * For more information of the semantics and the influence of this attribute to the
206  * result of interpolation, see
207  * - \ref NatureOfField
208  * - \ref TableNatureOfField "How interpolation coefficients depend on Field Nature"
209  */
210 NatureOfField MEDCouplingField::getNature() const
211 {
212   return _nature;
213 }
214
215 /*!
216  * Sets the nature of \a this field. This information is very important during
217  * interpolation process using ParaMEDMEM::MEDCouplingRemapper or ParaMEDMEM::InterpKernelDEC.
218  * In other context than the two mentioned above, this attribute is unimportant. This
219  * attribute is not stored in the MED file.
220  * For more information of the semantics and the influence of this attribute to the
221  * result of interpolation, see
222  * - \ref NatureOfField
223  * - \ref TableNatureOfField "How interpolation coefficients depend on Field Nature"
224  *
225  *  \param [in] nat - the nature of \a this field.
226  *  \throw If \a nat has an invalid value.
227  */
228 void MEDCouplingField::setNature(NatureOfField nat)
229 {
230   MEDCouplingNatureOfField::GetRepr(nat);//generate a throw if nat not recognized
231   _nature=nat;
232 }
233
234 /*!
235  * Returns coordinates of field location points that depend on 
236  * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field.
237  * - For a field on nodes, returns coordinates of nodes.
238  * - For a field on cells, returns barycenters of cells.
239  * - For a field on gauss points, returns coordinates of gauss points.
240  * 
241  *  \return DataArrayDouble * - a new instance of DataArrayDouble. The caller is to
242  *          delete this array using decrRef() as it is no more needed. 
243  *  \throw If the spatial discretization of \a this field is NULL.
244  *  \throw If the mesh is not set.
245  */
246 DataArrayDouble *MEDCouplingField::getLocalizationOfDiscr() const
247 {
248   if(!_mesh)
249     throw INTERP_KERNEL::Exception("MEDCouplingField::getLocalizationOfDiscr : No mesh set !");
250   if(!((const MEDCouplingFieldDiscretization *)_type))
251     throw INTERP_KERNEL::Exception("MEDCouplingField::getLocalizationOfDiscr : No spatial discretization set !");
252   return _type->getLocalizationOfDiscValues(_mesh);
253 }
254
255 /*!
256  * Returns a new MEDCouplingFieldDouble containing volumes of cells of a dual mesh whose
257  * cells are constructed around field location points (getLocalizationOfDiscr()) of \a this
258  * field. (In case of a field on cells, the dual mesh coincides with the underlying mesh).<br>
259  * For 1D cells, the returned field contains lengths.<br>
260  * For 2D cells, the returned field contains areas.<br>
261  * For 3D cells, the returned field contains volumes.
262  *  \param [in] isAbs - if \c true, the computed cell volume does not reflect cell
263  *         orientation, i.e. the volume is always positive.
264  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble.
265  *          The caller is to delete this array using decrRef() as
266  *          it is no more needed.
267  *  \throw If the mesh is not set.
268  *  \throw If the spatial discretization of \a this field is NULL.
269  *  \throw If the spatial discretization of \a this field is not well defined.
270  */
271
272 MEDCouplingFieldDouble *MEDCouplingField::buildMeasureField(bool isAbs) const
273 {
274   if(!_mesh)
275     throw INTERP_KERNEL::Exception("MEDCouplingField::buildMeasureField : no mesh defined !");
276   if(!((const MEDCouplingFieldDiscretization *)_type))
277     throw INTERP_KERNEL::Exception("MEDCouplingField::buildMeasureField : No spatial discretization set !");
278   return _type->getMeasureField(_mesh,isAbs);
279 }
280
281 /*!
282  * Sets the underlying mesh of \a this field.
283  * For examples of field construction, see \ref MEDCouplingFirstSteps3.
284  *  \param [in] mesh - the new underlying mesh.
285  */
286 void MEDCouplingField::setMesh(const MEDCouplingMesh *mesh)
287 {
288   if(mesh!=_mesh)
289     {
290       if(_mesh)
291         _mesh->decrRef();
292       _mesh=mesh;
293       declareAsNew();
294       if(_mesh)
295         {
296           _mesh->incrRef();
297           updateTimeWith(*_mesh);
298         }
299     }
300 }
301
302 /*!
303  * Sets localization of Gauss points for a given geometric type of cell.
304  *  \param [in] type - the geometric type of cell for which the Gauss localization is set.
305  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
306  *         must be \c nbOfNodesPerCell * \c dimOfType. 
307  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
308  *         must be  _wg_.size() * \c dimOfType.
309  *  \param [in] wg - the weights of Gauss points.
310  *  \throw If \a this field is not on Gauss points.
311  *  \throw If the spatial discretization of \a this field is NULL.
312  *  \throw If the mesh is not set.
313  *  \throw If size of any vector do not match the \a type.
314  */
315 void MEDCouplingField::setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
316                                                   const std::vector<double>& gsCoo, const std::vector<double>& wg)
317 {
318   if(!_mesh)
319     throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnType method !");
320   if(!((const MEDCouplingFieldDiscretization *)_type))
321     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call setGaussLocalizationOnType method !");
322   _type->setGaussLocalizationOnType(_mesh,type,refCoo,gsCoo,wg);
323 }
324
325 /*!
326  * Sets localization of Gauss points for given cells specified by their ids.
327  *  \param [in] begin - an array of cell ids of interest.
328  *  \param [in] end - the end of \a begin, i.e. a pointer to its (last+1)-th element.
329  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
330  *         must be \c nbOfNodesPerCell * \c dimOfType. 
331  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
332  *         must be  _wg_.size() * \c dimOfType.
333  *  \param [in] wg - the weights of Gauss points.
334  *  \throw If \a this field is not on Gauss points.
335  *  \throw If the spatial discretization of \a this field is NULL.
336  *  \throw If the mesh is not set.
337  *  \throw If size of any vector do not match the type of cell # \a begin[0].
338  *  \throw If type of any cell in \a begin differs from that of cell # \a begin[0].
339  *  \throw If the range [_begin_,_end_) is empty.
340  */
341 void MEDCouplingField::setGaussLocalizationOnCells(const int *begin, const int *end, const std::vector<double>& refCoo,
342                                                    const std::vector<double>& gsCoo, const std::vector<double>& wg)
343 {
344   if(!_mesh)
345     throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnCells method !");
346   if(!((const MEDCouplingFieldDiscretization *)_type))
347     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call setGaussLocalizationOnCells method !");
348   _type->setGaussLocalizationOnCells(_mesh,begin,end,refCoo,gsCoo,wg);
349 }
350
351 /*!
352  * Clears data on Gauss points localization.
353  *  \throw If \a this field is not on Gauss points.
354  *  \throw If the spatial discretization of \a this field is NULL.
355  */
356 void MEDCouplingField::clearGaussLocalizations()
357 {
358   if(!((const MEDCouplingFieldDiscretization *)_type))
359     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call clearGaussLocalizations method !");
360   _type->clearGaussLocalizations();
361 }
362
363 /*!
364  * Returns a reference to the Gauss localization object by its id.
365  * \warning This method is not const, so the returned object can be modified without any
366  *          problem.
367  *  \param [in] locId - the id of the Gauss localization object of interest.
368  *         It must be in range <em> 0 <= locId < getNbOfGaussLocalization() </em>.
369  *  \return \ref ParaMEDMEM::MEDCouplingGaussLocalization "MEDCouplingGaussLocalization" & - the
370  *  Gauss localization object.
371  *  \throw If \a this field is not on Gauss points.
372  *  \throw If \a locId is not within the valid range.
373  *  \throw If the spatial discretization of \a this field is NULL.
374  */
375 MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId)
376 {
377   if(!((const MEDCouplingFieldDiscretization *)_type))
378     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalization method !");
379   return _type->getGaussLocalization(locId);
380 }
381
382 /*!
383  * Returns an id of the Gauss localization object corresponding to a given cell type.
384  *  \param [in] type - the cell type of interest.
385  *  \return int - the id of the Gauss localization object.
386  *  \throw If \a this field is not on Gauss points.
387  *  \throw If the spatial discretization of \a this field is NULL.
388  *  \throw If no Gauss localization object found for the given cell \a type.
389  *  \throw If more than one Gauss localization object found for the given cell \a type.
390  */
391 int MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const
392 {
393   if(!((const MEDCouplingFieldDiscretization *)_type))
394     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneType method !");
395   return _type->getGaussLocalizationIdOfOneType(type);
396 }
397
398 /*!
399  * Returns ids of Gauss localization objects corresponding to a given cell type.
400  *  \param [in] type - the cell type of interest.
401  *  \return std::set<int> - ids of the Gauss localization object.
402  *  \throw If \a this field is not on Gauss points.
403  *  \throw If the spatial discretization of \a this field is NULL
404  */
405 std::set<int> MEDCouplingField::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const
406 {
407   if(!((const MEDCouplingFieldDiscretization *)_type))
408     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdsOfOneType method !");
409   return _type->getGaussLocalizationIdsOfOneType(type);
410 }
411
412 /*!
413  * Returns number of Gauss localization objects available. Implicitly all ids in
414  * [0,getNbOfGaussLocalization()) are valid Gauss localization ids. 
415  *  \return int - the number of available Gauss localization objects.
416  *  \throw If \a this field is not on Gauss points.
417  *  \throw If the spatial discretization of \a this field is NULL.
418  */
419 int MEDCouplingField::getNbOfGaussLocalization() const
420 {
421   if(!((const MEDCouplingFieldDiscretization *)_type))
422     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNbOfGaussLocalization method !");
423   return _type->getNbOfGaussLocalization();
424 }
425
426 /*!
427  * Returns an id of the Gauss localization object corresponding to a type of a given cell.
428  *  \param [in] cellId - an id of the cell of interest.
429  *  \return int - the id of the Gauss localization object.
430  *  \throw If \a this field is not on Gauss points.
431  *  \throw If the spatial discretization of \a this field is NULL.
432  *  \throw If no Gauss localization object found for the given cell.
433  */
434 int MEDCouplingField::getGaussLocalizationIdOfOneCell(int cellId) const
435 {
436   if(!((const MEDCouplingFieldDiscretization *)_type))
437     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneCell method !");
438   return _type->getGaussLocalizationIdOfOneCell(cellId);
439 }
440
441 /*!
442  * Returns ids of cells that share the same Gauss localization given by its id.
443  *  \param [in] locId - the id of the Gauss localization object of interest. 
444  *         It must be in range <em> 0 <= locId < getNbOfGaussLocalization() </em>.
445  *  \param [in,out] cellIds - a vector returning ids of found cells. It is cleared before
446  *         filling in. It remains empty if no cells found.
447  *  \throw If \a this field is not on Gauss points.
448  *  \throw If \a locId is not within the valid range.
449  *  \throw If the spatial discretization of \a this field is NULL.
450  */
451 void MEDCouplingField::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const
452 {
453   cellIds.clear();
454   if(!((const MEDCouplingFieldDiscretization *)_type))
455     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getCellIdsHavingGaussLocalization method !");
456   _type->getCellIdsHavingGaussLocalization(locId,cellIds);
457 }
458
459 /*!
460  * Returns a reference to the Gauss localization object by its id.
461  * \warning This method is const, so the returned object is not apt for modification.
462  *  \param [in] locId - the id of the Gauss localization object of interest.
463  *         It must be in range <em> 0 <= locId < getNbOfGaussLocalization() </em>.
464  *  \return const \ref MEDCouplingGaussLocalization & - the Gauss localization object.
465  *  \throw If \a this field is not on Gauss points.
466  *  \throw If \a locId is not within the valid range.
467  *  \throw If the spatial discretization of \a this field is NULL.
468  */
469 const MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId) const
470 {
471   if(!((const MEDCouplingFieldDiscretization *)_type))
472     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalization method !");
473   return _type->getGaussLocalization(locId);
474 }
475
476 MEDCouplingField::~MEDCouplingField()
477 {
478   if(_mesh)
479     _mesh->decrRef();
480 }
481
482 MEDCouplingField::MEDCouplingField(MEDCouplingFieldDiscretization *type, NatureOfField nature):_nature(nature),_mesh(0),_type(type)
483 {
484 }
485
486 MEDCouplingField::MEDCouplingField(TypeOfField type):_nature(NoNature),_mesh(0),_type(MEDCouplingFieldDiscretization::New(type))
487 {
488 }
489
490 MEDCouplingField::MEDCouplingField(const MEDCouplingField& other, bool deepCopy):RefCountObject(other),_name(other._name),_desc(other._desc),_nature(other._nature),
491     _mesh(0),_type(0)
492 {
493   if(other._mesh)
494     {
495       _mesh=other._mesh;
496       _mesh->incrRef();
497     }
498   if(deepCopy)
499     _type=other._type->clone();
500   else
501     _type=other._type;
502 }
503
504 /*!
505  * Returns a new MEDCouplingMesh constituted by some cells of the underlying mesh of \a
506  * this field, and returns ids of entities (nodes, cells, Gauss points) lying on the
507  * specified cells. The cells to include to the result mesh are specified by an array of
508  * cell ids. The new mesh shares the coordinates array with the underlying mesh. 
509  *  \param [in] start - an array of cell ids to include to the result mesh.
510  *  \param [in] end - specifies the end of the array \a start, so that
511  *              the last value of \a start is \a end[ -1 ].
512  *  \param [out] di - a new instance of DataArrayInt holding the ids of entities (nodes,
513  *         cells, Gauss points). The caller is to delete this array using decrRef() as it
514  *         is no more needed.  
515  *  \return MEDCouplingMesh * - a new instance of MEDCouplingMesh. The caller is to
516  *         delete this mesh using decrRef() as it is no more needed. 
517  *  \throw If the spatial discretization of \a this field is NULL.
518  *  \throw If the mesh is not set.
519  * \sa buildSubMeshDataRange()
520  */
521 MEDCouplingMesh *MEDCouplingField::buildSubMeshData(const int *start, const int *end, DataArrayInt *&di) const
522 {
523   if(!((const MEDCouplingFieldDiscretization *)_type))
524     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call buildSubMeshData method !");
525   return _type->buildSubMeshData(_mesh,start,end,di);
526 }
527
528 /*!
529  * 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.
530  * 
531  * \param [out] beginOut Valid only if \a di is NULL
532  * \param [out] endOut Valid only if \a di is NULL
533  * \param [out] stepOut Valid only if \a di is NULL
534  * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable.
535  * 
536  * \sa MEDCouplingField::buildSubMeshData
537  */
538 MEDCouplingMesh *MEDCouplingField::buildSubMeshDataRange(int begin, int end, int step, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
539 {
540   if(!((const MEDCouplingFieldDiscretization *)_type))
541     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call buildSubMeshDataRange method !");
542   return _type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,di);
543 }
544
545 /*!
546  * This method returns tuples ids implied by the mesh selection of the  cell ids contained in array defined as an interval [start;end).
547  * \return a newly allocated DataArrayInt instance containing tuples ids.
548  */
549 DataArrayInt *MEDCouplingField::computeTupleIdsToSelectFromCellIds(const int *startCellIds, const int *endCellIds) const
550 {
551   if(!((const MEDCouplingFieldDiscretization *)_type))
552     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call computeTupleIdsToSelectFromCellIds method !");
553   return _type->computeTupleIdsToSelectFromCellIds(_mesh,startCellIds,endCellIds);
554 }
555
556 /*!
557  * Returns number of tuples expected regarding the spatial discretization of \a this
558  * field and number of entities in the underlying mesh. This method behaves exactly as MEDCouplingFieldDouble::getNumberOfTuples.
559  *  \return int - the number of expected tuples.
560  *  \throw If the spatial discretization of \a this field is NULL.
561  *  \throw If the mesh is not set.
562  */
563 int MEDCouplingField::getNumberOfTuplesExpected() const
564 {
565   if(!((const MEDCouplingFieldDiscretization *)_type))
566     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfTuplesExpected method !");
567   if(_mesh)
568     return _type->getNumberOfTuples(_mesh);
569   else
570     throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfTuplesExpected : Empty mesh !");
571 }
572
573 void MEDCouplingField::setDiscretization(MEDCouplingFieldDiscretization *newDisc)
574 {
575   bool needUpdate=(const MEDCouplingFieldDiscretization *)_type!=newDisc;
576   _type=newDisc;
577   if(newDisc)
578     newDisc->incrRef();
579   if(needUpdate)
580     declareAsNew();
581 }
582
583 /*!
584  * Returns number of mesh entities in the underlying mesh of \a this field regarding the
585  * spatial discretization.
586  *  \return int - the number of mesh entities porting the field values.
587  *  \throw If the spatial discretization of \a this field is NULL.
588  *  \throw If the mesh is not set.
589  */
590 int MEDCouplingField::getNumberOfMeshPlacesExpected() const
591 {
592   if(!((const MEDCouplingFieldDiscretization *)_type))
593     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfMeshPlacesExpected method !");
594   if(_mesh)
595     return _type->getNumberOfMeshPlaces(_mesh);
596   else
597     throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfMeshPlacesExpected : Empty mesh !");
598 }
599
600 /*!
601  * Copy tiny info (component names, name, description) but warning the underlying mesh is not renamed (for safety reason).
602  */
603 void MEDCouplingField::copyTinyStringsFrom(const MEDCouplingField *other)
604 {
605   if(other)
606     {
607       setName(other->_name);
608       setDescription(other->_desc);    
609     }
610 }
611
612 /*!
613  * This method computes the number of tuples a DataArrayDouble instance should have to build a correct MEDCouplingFieldDouble instance starting from a 
614  * submesh of a virtual mesh on which a substraction per type had been applied regarding the spatial discretization in \a this.
615  * 
616  * For spatial discretization \b not equal to ON_GAUSS_NE this method will make the hypothesis that any positive entity id in \a code \a idsPerType is valid.
617  * So in those cases attribute \a _mesh of \a this is ignored.
618  * 
619  * For spatial discretization equal to ON_GAUSS_NE \a _mesh attribute will be taken into account.
620  *
621  * The input code is those implemented in MEDCouplingUMesh::splitProfilePerType.
622  *
623  * \param [in] code - a code with format described above.
624  * \param [in] idsPerType - a list of subparts
625  * \throw If \a this has no spatial discretization set.
626  * \throw If input code point to invalid zones in spatial discretization.
627  * \throw If spatial discretization in \a this requires a mesh and those mesh is invalid (null,...)
628  */
629 int MEDCouplingField::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
630 {
631   const MEDCouplingFieldDiscretization *t(_type);
632   if(!t)
633     throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfTuplesExpectedRegardingCode : no spatial discretization set !");
634   return t->getNumberOfTuplesExpectedRegardingCode(code,idsPerType);
635 }