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