1 // Copyright (C) 2016-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #ifndef __MEDCOUPLINGFIELDT_TXX__
22 #define __MEDCOUPLINGFIELDT_TXX__
24 #include "MEDCouplingTimeDiscretization.hxx"
25 #include "MEDCouplingMesh.hxx"
30 MEDCouplingFieldT<T>::MEDCouplingFieldT(const MEDCouplingFieldT<T>& other, bool deepCopy):MEDCouplingField(other,deepCopy),_time_discr(other._time_discr->performCopyOrIncrRef(deepCopy))
35 * Checks if \a this field is correctly defined, else an exception is thrown.
36 * \throw If the mesh is not set.
37 * \throw If the data array is not set.
38 * \throw If the spatial discretization of \a this field is NULL.
39 * \throw If \a this->getTimeTolerance() < 0.
40 * \throw If the temporal discretization data is incorrect.
41 * \throw If mesh data does not correspond to field data.
44 void MEDCouplingFieldT<T>::checkConsistencyLight() const
46 MEDCouplingField::checkConsistencyLight();
47 _time_discr->checkConsistencyLight();
48 _type->checkCoherencyBetween(_mesh,getArray());
52 MEDCouplingFieldT<T>::MEDCouplingFieldT(const MEDCouplingField& other, MEDCouplingTimeDiscretizationTemplate<T> *timeDiscr, bool deepCopy):MEDCouplingField(other,deepCopy),_time_discr(timeDiscr)
57 MEDCouplingFieldT<T>::MEDCouplingFieldT(TypeOfField type, MEDCouplingTimeDiscretizationTemplate<T> *timeDiscr):MEDCouplingField(type),_time_discr(timeDiscr)
62 MEDCouplingFieldT<T>::MEDCouplingFieldT(MEDCouplingFieldDiscretization *type, NatureOfField n, MEDCouplingTimeDiscretizationTemplate<T> *timeDiscr):MEDCouplingField(type,n),_time_discr(timeDiscr)
67 MEDCouplingFieldT<T>::~MEDCouplingFieldT()
73 * This method synchronizes time information (time, iteration, order, time unit) regarding the information in \c this->_mesh.
74 * \throw If no mesh is set in this. Or if \a this is not compatible with time setting (typically NO_TIME)
77 void MEDCouplingFieldT<T>::synchronizeTimeWithMesh()
80 throw INTERP_KERNEL::Exception("MEDCouplingFieldT::synchronizeTimeWithMesh : no mesh set in this !");
82 double val(_mesh->getTime(it,ordr));
83 std::string timeUnit(_mesh->getTimeUnit());
85 setTimeUnit(timeUnit);
89 * Returns a new MEDCouplingFieldDouble which is a copy of \a this one. The data
90 * of \a this field is copied either deep or shallow depending on \a recDeepCpy
91 * parameter. But the underlying mesh is always deep copied.
92 * Data that can be copied either deeply or shallow are:
93 * - \ref MEDCouplingTemporalDisc "temporal discretization" data that holds array(s)
95 * - \ref MEDCouplingSpatialDisc "a spatial discretization".
97 * This method behaves exactly like clone() except that here the underlying **mesh is
98 * always deeply duplicated**, whatever the value \a recDeepCpy parameter.
99 * The result of \c cloneWithMesh(true) is exactly the same as that of deepCopy().
100 * So the resulting field can not be used together with \a this one in the methods
101 * like operator+(), operator*() etc. To avoid deep copying the underlying mesh,
102 * the user can call clone().
103 * \param [in] recDeepCpy - if \c true, the copy of the underlying data arrays is
104 * deep, else all data arrays of \a this field are shared by the new field.
105 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
106 * caller is to delete this field using decrRef() as it is no more needed.
110 typename Traits<T>::FieldType *MEDCouplingFieldT<T>::cloneWithMesh(bool recDeepCpy) const
112 MCAuto< typename Traits<T>::FieldType > ret(clone(recDeepCpy));
115 MCAuto<MEDCouplingMesh> mCpy(_mesh->deepCopy());
122 bool MEDCouplingFieldT<T>::isEqual(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec) const
125 return isEqualIfNotWhy(other,meshPrec,valsPrec,tmp);
129 bool MEDCouplingFieldT<T>::isEqualIfNotWhy(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec, std::string& reason) const
132 throw INTERP_KERNEL::Exception("MEDCouplingFieldT::isEqualIfNotWhy : other instance is NULL !");
133 if(!isEqualIfNotWhyProtected(other,meshPrec,reason))
135 if(!_time_discr->isEqualIfNotWhy(other->_time_discr,T(valsPrec),reason))
137 reason.insert(0,"In FieldT time discretizations differ :");
144 * Checks equality of \a this and \a other field. Only numeric data is considered,
145 * i.e. names, description etc are not compared.
146 * \param [in] other - the field to compare with.
147 * \param [in] meshPrec - a precision used to compare node coordinates of meshes.
148 * \param [in] valsPrec - a precision used to compare data arrays of the two fields.
149 * \return bool - \c true if the two fields are equal, \c false else.
150 * \throw If \a other == NULL.
151 * \throw If the spatial discretization of \a this field is NULL.
154 bool MEDCouplingFieldT<T>::isEqualWithoutConsideringStr(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec) const
158 if(!isEqualWithoutConsideringStrProtected(other,meshPrec))
160 if(!_time_discr->isEqualWithoutConsideringStr(other->_time_discr,valsPrec))
166 * Copies tiny info (component names, name and description) from an \a other field to
168 * \warning The underlying mesh is not renamed (for safety reason).
169 * \param [in] other - the field to copy the tiny info from.
170 * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
173 void MEDCouplingFieldT<T>::copyTinyStringsFrom(const MEDCouplingField *other)
175 MEDCouplingField::copyTinyStringsFrom(other);
176 const MEDCouplingFieldT<T> *otherC(dynamic_cast<const MEDCouplingFieldT<T> *>(other));
179 _time_discr->copyTinyStringsFrom(*otherC->_time_discr);
184 * Copies only times, order and iteration from an \a other field to
185 * \a this one. The underlying mesh is not impacted by this method.
186 * Arrays are not impacted neither.
187 * \param [in] other - the field to tiny attributes from.
188 * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
191 void MEDCouplingFieldT<T>::copyTinyAttrFrom(const MEDCouplingFieldT<T> *other)
195 _time_discr->copyTinyAttrFrom(*other->_time_discr);
200 void MEDCouplingFieldT<T>::copyAllTinyAttrFrom(const MEDCouplingFieldT<T> *other)
202 copyTinyStringsFrom(other);
203 copyTinyAttrFrom(other);
207 * Permutes values of \a this field according to a given permutation array for cells
208 * renumbering. The underlying mesh is deeply copied and its cells are also permuted.
209 * The number of cells remains the same; for that the permutation array \a old2NewBg
210 * should not contain equal ids.
211 * ** Warning, this method modifies the mesh aggreagated by \a this (by performing a deep copy ) **.
213 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
214 * to be equal to \a this->getMesh()->getNumberOfCells().
215 * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
216 * array, so that its maximal cell id to correspond to (be less than) the number
217 * of cells in mesh. This new array is then used for the renumbering. If \a
218 * check == \c false, \a old2NewBg is used as is, that is less secure as validity
219 * of ids in \a old2NewBg is not checked.
220 * \throw If the mesh is not set.
221 * \throw If the spatial discretization of \a this field is NULL.
222 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
223 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
225 * \if ENABLE_EXAMPLES
226 * \ref cpp_mcfielddouble_renumberCells "Here is a C++ example".<br>
227 * \ref py_mcfielddouble_renumberCells "Here is a Python example".
231 void MEDCouplingFieldT<T>::renumberCells(const int *old2NewBg, bool check)
233 renumberCellsWithoutMesh(old2NewBg,check);
234 MCAuto<MEDCouplingMesh> m(_mesh->deepCopy());
235 m->renumberCells(old2NewBg,check);
241 * Permutes values of \a this field according to a given permutation array for cells
242 * renumbering. The underlying mesh is \b not permuted.
243 * The number of cells remains the same; for that the permutation array \a old2NewBg
244 * should not contain equal ids.
245 * This method performs a part of job of renumberCells(). The reasonable use of this
246 * method is only for multi-field instances lying on the same mesh to avoid a
247 * systematic duplication and renumbering of _mesh attribute.
248 * \warning Use this method with a lot of care!
249 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
250 * to be equal to \a this->getMesh()->getNumberOfCells().
251 * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
252 * array, so that its maximal cell id to correspond to (be less than) the number
253 * of cells in mesh. This new array is then used for the renumbering. If \a
254 * check == \c false, \a old2NewBg is used as is, that is less secure as validity
255 * of ids in \a old2NewBg is not checked.
256 * \throw If the mesh is not set.
257 * \throw If the spatial discretization of \a this field is NULL.
258 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
259 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
262 void MEDCouplingFieldT<T>::renumberCellsWithoutMesh(const int *old2NewBg, bool check)
265 throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !");
267 throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
269 _type->renumberCells(old2NewBg,check);
270 std::vector< typename MEDCoupling::Traits<T>::ArrayType *> arrays;
271 timeDiscrSafe()->getArrays(arrays);
272 std::vector<DataArray *> arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin());
273 _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check);
279 * This method is more strict than MEDCouplingField::areCompatibleForMerge method.
280 * This method is used for operation on fields to operate a first check before attempting operation.
283 bool MEDCouplingFieldT<T>::areStrictlyCompatible(const MEDCouplingField *other) const
286 if(!MEDCouplingField::areStrictlyCompatible(other))
288 const MEDCouplingFieldT<T> *otherC(dynamic_cast<const MEDCouplingFieldT<T> *>(other));
291 if(!_time_discr->areStrictlyCompatible(otherC->_time_discr,tmp))
297 bool MEDCouplingFieldT<T>::areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const
299 if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other))
301 const MEDCouplingFieldT<T> *otherC(dynamic_cast<const MEDCouplingFieldT<T> *>(other));
304 if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr))
310 * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatibleForMulDiv method except that
311 * number of components between \a this and 'other' can be different here (for operator/).
314 bool MEDCouplingFieldT<T>::areCompatibleForDiv(const MEDCouplingField *other) const
316 if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other))
318 const MEDCouplingFieldT<T> *otherC(dynamic_cast<const MEDCouplingFieldT<T> *>(other));
321 if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr))
327 bool MEDCouplingFieldT<T>::areCompatibleForMul(const MEDCouplingField *other) const
329 if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other))
331 const MEDCouplingFieldT<T> *otherC(dynamic_cast<const MEDCouplingFieldT<T> *>(other));
334 if(!_time_discr->areStrictlyCompatibleForMul(otherC->_time_discr))
340 * Returns a string describing \a this field. This string is outputted by \c print
341 * Python command. The string includes info on
344 * - \ref MEDCouplingSpatialDisc "spatial discretization",
345 * - \ref MEDCouplingTemporalDisc "time discretization",
346 * - \ref NatureOfField,
350 * \return std::string - the string describing \a this field.
353 std::string MEDCouplingFieldT<T>::simpleRepr() const
355 std::ostringstream ret;
356 ret << Traits<T>::FieldTypeName << " with name : \"" << getName() << "\"\n";
357 ret << "Description of field is : \"" << getDescription() << "\"\n";
359 { ret << Traits<T>::FieldTypeName << " space discretization is : " << _type->getStringRepr() << "\n"; }
361 { ret << Traits<T>::FieldTypeName << " has no spatial discretization !\n"; }
363 { ret << Traits<T>::FieldTypeName << " time discretization is : " << _time_discr->getStringRepr() << "\n"; }
365 { ret << Traits<T>::FieldTypeName << " has no time discretization !\n"; }
366 ret << Traits<T>::FieldTypeName << " nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
369 if(getArray()->isAllocated())
371 int nbOfCompo=getArray()->getNumberOfComponents();
372 ret << Traits<T>::FieldTypeName << " default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
373 ret << Traits<T>::FieldTypeName << " default array has following info on components : ";
374 for(int i=0;i<nbOfCompo;i++)
375 ret << "\"" << getArray()->getInfoOnComponent(i) << "\" ";
380 ret << "Array set but not allocated !\n";
384 ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
386 ret << "Mesh support information : No mesh set !\n";
391 void MEDCouplingFieldT<T>::reprQuickOverview(std::ostream& stream) const
393 stream << Traits<T>::FieldTypeName << " C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
397 nat=MEDCouplingNatureOfField::GetRepr(_nature);
398 stream << "Nature of field : " << nat << ".\n";
400 catch(INTERP_KERNEL::Exception& e)
402 const MEDCouplingFieldDiscretization *fd(_type);
404 stream << "No spatial discretization set !";
406 fd->reprQuickOverview(stream);
409 stream << "\nNo mesh support defined !";
412 std::ostringstream oss;
413 _mesh->reprQuickOverview(oss);
414 std::string tmp(oss.str());
415 stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
419 const typename Traits<T>::ArrayType *arr(_time_discr->getArray());
422 stream << "\n\nArray info : ";
423 arr->reprQuickOverview(stream);
427 stream << "\n\nNo data array set !";
433 * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field.
434 * \return MEDCoupling::TypeOfTimeDiscretization - an enum item describing the time
435 * discretization type.
438 TypeOfTimeDiscretization MEDCouplingFieldT<T>::getTimeDiscretization() const
440 return _time_discr->getEnum();
444 * Builds a newly created field, that the caller will have the responsibility to deal with.
445 * \n This method makes the assumption that \a this field is correctly defined when this method is called (\a this->checkConsistencyLight() returns without any exception thrown), **no check of this will be done**.
446 * \n This method returns a restriction of \a this so that only tuple ids specified in [ \a partBg , \a partEnd ) will be contained in the returned field.
447 * \n Parameter [\a partBg, \a partEnd ) specifies **cell ids whatever the spatial discretization** of \a this (
448 * \ref MEDCoupling::ON_CELLS "ON_CELLS",
449 * \ref MEDCoupling::ON_NODES "ON_NODES",
450 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
451 * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
452 * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
454 * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a partBg contains the following cell ids [3,7,6].
455 * Then the returned field will lie on mesh having 3 cells and will contain 3 tuples.
456 *- Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().
457 *- Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().
458 *- Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
460 * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a partBg contains following cellIds [3,7,6].
461 * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
462 * will contain 6 tuples and \a this field will lie on this restricted mesh.
464 * \param [in] partBg - start (included) of input range of cell ids to select [ \a partBg, \a partEnd )
465 * \param [in] partEnd - end (not included) of input range of cell ids to select [ \a partBg, \a partEnd )
466 * \return a newly allocated field the caller should deal with.
468 * \throw if there is presence of an invalid cell id in [ \a partBg, \a partEnd ) regarding the number of cells of \a this->getMesh().
470 * \if ENABLE_EXAMPLES
471 * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."<br>
472 * \ref py_mcfielddouble_subpart1 "Here a Python example."
474 * \sa MEDCoupling::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
477 typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const int *partBg, const int *partEnd) const
480 throw INTERP_KERNEL::Exception("MEDCouplingFieldT::buildSubPart : Expecting a not NULL spatial discretization !");
481 DataArrayInt *arrSelect;
482 MCAuto<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
483 MCAuto<DataArrayInt> arrSelect2(arrSelect);
484 MCAuto< typename Traits<T>::FieldType > ret(clone(false));//quick shallow copy.
485 const MEDCouplingFieldDiscretization *disc=getDiscretization();
487 ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePart(partBg,partEnd)));
489 std::vector<typename Traits<T>::ArrayType *> arrays;
490 timeDiscrSafe()->getArrays(arrays);
491 std::vector<typename Traits<T>::ArrayType *> arrs;
492 std::vector< MCAuto< typename Traits<T>::ArrayType > > arrsSafe;
493 const int *arrSelBg=arrSelect->begin();
494 const int *arrSelEnd=arrSelect->end();
495 for(typename std::vector<typename Traits<T>::ArrayType *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
497 typename Traits<T>::ArrayType *arr(0);
499 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
500 arrs.push_back(arr); arrsSafe.push_back(arr);
502 ret->timeDiscrSafe()->setArrays(arrs,0);
507 * Builds a newly created field, that the caller will have the responsibility to deal with (decrRef()).
508 * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done.
509 * This method returns a restriction of \a this so that only tuples with ids specified in \a part will be contained in the returned field.
510 * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (
511 * \ref MEDCoupling::ON_CELLS "ON_CELLS",
512 * \ref MEDCoupling::ON_NODES "ON_NODES",
513 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
514 * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
515 * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
517 * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a part contains following cell ids [3,7,6].
518 * Then the returned field will lie on mesh having 3 cells and the returned field will contain 3 tuples.<br>
519 * Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().<br>
520 * Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().<br>
521 * Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
523 * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a part contains following cellIds [3,7,6].
524 * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
525 * will contain 6 tuples and \a this field will lie on this restricted mesh.
527 * \param [in] part - an array of cell ids to include to the result field.
528 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The caller is to delete this field using decrRef() as it is no more needed.
530 * \if ENABLE_EXAMPLES
531 * \ref cpp_mcfielddouble_subpart1 "Here is a C++ example".<br>
532 * \ref py_mcfielddouble_subpart1 "Here is a Python example".
534 * \sa MEDCouplingFieldDouble::buildSubPartRange
537 typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const DataArrayInt *part) const
540 throw INTERP_KERNEL::Exception("MEDCouplingFieldT::buildSubPart : not empty array must be passed to this method !");
541 return buildSubPart(part->begin(),part->end());
545 * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is
546 * given using a range given \a begin, \a end and \a step to optimize the part computation.
548 * \sa MEDCouplingFieldDouble::buildSubPart
551 typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPartRange(int begin, int end, int step) const
554 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
555 DataArrayInt *arrSelect;
556 int beginOut,endOut,stepOut;
557 MCAuto<MEDCouplingMesh> m(_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect));
558 MCAuto<DataArrayInt> arrSelect2(arrSelect);
559 MCAuto< typename Traits<T>::FieldType > ret(clone(false));//quick shallow copy.
560 const MEDCouplingFieldDiscretization *disc=getDiscretization();
562 ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePartRange(begin,end,step)));
564 std::vector<typename Traits<T>::ArrayType *> arrays;
565 timeDiscrSafe()->getArrays(arrays);
566 std::vector<typename Traits<T>::ArrayType *> arrs;
567 std::vector< MCAuto< typename Traits<T>::ArrayType > > arrsSafe;
568 for(typename std::vector<typename Traits<T>::ArrayType *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
570 typename Traits<T>::ArrayType *arr(0);
575 const int *arrSelBg=arrSelect->begin();
576 const int *arrSelEnd=arrSelect->end();
577 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
580 arr=(*iter)->selectByTupleIdSafeSlice(beginOut,endOut,stepOut);
582 arrs.push_back(arr); arrsSafe.push_back(arr);
584 ret->timeDiscrSafe()->setArrays(arrs,0);
589 const MEDCouplingTimeDiscretizationTemplate<T> *MEDCouplingFieldT<T>::timeDiscrSafe() const
591 const MEDCouplingTimeDiscretizationTemplate<T> *ret(_time_discr);
593 throw INTERP_KERNEL::Exception("const FieldT : Null type of time discr !");
598 MEDCouplingTimeDiscretizationTemplate<T> *MEDCouplingFieldT<T>::timeDiscrSafe()
600 MEDCouplingTimeDiscretizationTemplate<T> *ret(_time_discr);
602 throw INTERP_KERNEL::Exception("const FieldT : Null type of time discr !");
607 void MEDCouplingFieldT<T>::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
610 timeDiscrSafe()->getTinySerializationStrInformation(tinyInfo);
611 tinyInfo.push_back(_name);
612 tinyInfo.push_back(_desc);
613 tinyInfo.push_back(getTimeUnit());
617 * This method retrieves some critical values to resize and prepare remote instance.
618 * The first two elements returned in tinyInfo correspond to the parameters to give in constructor.
619 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
622 void MEDCouplingFieldT<T>::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
625 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
627 tinyInfo.push_back((int)_type->getEnum());
628 tinyInfo.push_back((int)timeDiscrSafe()->getEnum());
629 tinyInfo.push_back((int)_nature);
630 timeDiscrSafe()->getTinySerializationIntInformation(tinyInfo);
631 std::vector<int> tinyInfo2;
632 _type->getTinySerializationIntInformation(tinyInfo2);
633 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
634 tinyInfo.push_back((int)tinyInfo2.size());
638 * This method retrieves some critical values to resize and prepare remote instance.
639 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
642 void MEDCouplingFieldT<T>::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
645 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
647 timeDiscrSafe()->getTinySerializationDbleInformation(tinyInfo);
648 std::vector<double> tinyInfo2;
649 _type->getTinySerializationDbleInformation(tinyInfo2);
650 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
651 tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it
655 * This method has to be called to the new instance filled by CORBA, MPI, File...
656 * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied.
657 * @param dataInt out parameter. If not null the pointer is already owned by \a this after the call of this method. In this case no decrRef must be applied.
658 * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by \a this after the call of this method.
659 * No decrRef must be applied to every instances in returned vector.
660 * \sa checkForUnserialization
663 void MEDCouplingFieldT<T>::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays)
666 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
668 std::vector<int> tinyInfoITmp(tinyInfoI);
669 int sz=tinyInfoITmp.back();
670 tinyInfoITmp.pop_back();
671 std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
672 std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
673 timeDiscrSafe()->resizeForUnserialization(tinyInfoI2,arrays);
674 std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
675 _type->resizeForUnserialization(tinyInfoITmp3,dataInt);
679 * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this
680 * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data.
681 * \sa resizeForUnserialization
684 void MEDCouplingFieldT<T>::checkForUnserialization(const std::vector<int>& tinyInfoI, const DataArrayInt *dataInt, const std::vector<typename Traits<T>::ArrayType *>& arrays)
687 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
688 std::vector<int> tinyInfoITmp(tinyInfoI);
689 int sz=tinyInfoITmp.back();
690 tinyInfoITmp.pop_back();
691 std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
692 std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
693 timeDiscrSafe()->checkForUnserialization(tinyInfoI2,arrays);
694 std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
695 _type->checkForUnserialization(tinyInfoITmp3,dataInt);
699 void MEDCouplingFieldT<T>::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
702 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
703 std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
705 std::vector<double> tmp(tinyInfoD);
706 int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it
708 std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
709 std::vector<double> tmp2(tmp.end()-sz,tmp.end());
711 timeDiscrSafe()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
712 _nature=(NatureOfField)tinyInfoI[2];
713 _type->finishUnserialization(tmp2);
714 int nbOfElemS=(int)tinyInfoS.size();
715 _name=tinyInfoS[nbOfElemS-3];
716 _desc=tinyInfoS[nbOfElemS-2];
717 setTimeUnit(tinyInfoS[nbOfElemS-1]);
721 * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsibilities of the caller.
722 * The values returned must be consulted only in readonly mode.
725 void MEDCouplingFieldT<T>::serialize(DataArrayInt *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays) const
728 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");
729 timeDiscrSafe()->getArrays(arrays);
730 _type->getSerializationIntArray(dataInt);