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