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