1 // Copyright (C) 2016-2023 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 mcIdType *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 mcIdType *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 std::size_t 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(std::size_t 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&)
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",
453 * \ref MEDCoupling::ON_NODES_FE "ON_NODES_FE").
455 * 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].
456 * Then the returned field will lie on mesh having 3 cells and will contain 3 tuples.
457 *- 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().
458 *- 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().
459 *- 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().
461 * 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].
462 * 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
463 * will contain 6 tuples and \a this field will lie on this restricted mesh.
465 * \param [in] partBg - start (included) of input range of cell ids to select [ \a partBg, \a partEnd )
466 * \param [in] partEnd - end (not included) of input range of cell ids to select [ \a partBg, \a partEnd )
467 * \return a newly allocated field the caller should deal with.
469 * \throw if there is presence of an invalid cell id in [ \a partBg, \a partEnd ) regarding the number of cells of \a this->getMesh().
471 * \if ENABLE_EXAMPLES
472 * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."<br>
473 * \ref py_mcfielddouble_subpart1 "Here a Python example."
475 * \sa MEDCoupling::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
478 typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const mcIdType *partBg, const mcIdType *partEnd) const
481 throw INTERP_KERNEL::Exception("MEDCouplingFieldT::buildSubPart : Expecting a not NULL spatial discretization !");
482 DataArrayIdType *arrSelect;
483 MCAuto<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
484 MCAuto<DataArrayIdType> arrSelect2(arrSelect);
485 MCAuto< typename Traits<T>::FieldType > ret(clone(false));//quick shallow copy.
486 const MEDCouplingFieldDiscretization *disc=getDiscretization();
488 ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePart(partBg,partEnd)));
490 std::vector<typename Traits<T>::ArrayType *> arrays;
491 timeDiscrSafe()->getArrays(arrays);
492 std::vector<typename Traits<T>::ArrayType *> arrs;
493 std::vector< MCAuto< typename Traits<T>::ArrayType > > arrsSafe;
494 const mcIdType *arrSelBg=arrSelect->begin();
495 const mcIdType *arrSelEnd=arrSelect->end();
496 for(typename std::vector<typename Traits<T>::ArrayType *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
498 typename Traits<T>::ArrayType *arr(0);
500 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
501 arrs.push_back(arr); arrsSafe.push_back(arr);
503 ret->timeDiscrSafe()->setArrays(arrs,0);
508 * Builds a newly created field, that the caller will have the responsibility to deal with (decrRef()).
509 * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done.
510 * 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.
511 * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (
512 * \ref MEDCoupling::ON_CELLS "ON_CELLS",
513 * \ref MEDCoupling::ON_NODES "ON_NODES",
514 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
515 * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
516 * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR",
517 * \ref MEDCoupling::ON_NODES_FE "ON_NODES_FE").
519 * 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].
520 * Then the returned field will lie on mesh having 3 cells and the returned field will contain 3 tuples.<br>
521 * 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>
522 * 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>
523 * 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().
525 * 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].
526 * 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
527 * will contain 6 tuples and \a this field will lie on this restricted mesh.
529 * \param [in] part - an array of cell ids to include to the result field.
530 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The caller is to delete this field using decrRef() as it is no more needed.
532 * \if ENABLE_EXAMPLES
533 * \ref cpp_mcfielddouble_subpart1 "Here is a C++ example".<br>
534 * \ref py_mcfielddouble_subpart1 "Here is a Python example".
536 * \sa MEDCouplingFieldDouble::buildSubPartRange
539 typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const DataArrayIdType *part) const
542 throw INTERP_KERNEL::Exception("MEDCouplingFieldT::buildSubPart : not empty array must be passed to this method !");
543 return buildSubPart(part->begin(),part->end());
547 * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is
548 * given using a range given \a begin, \a end and \a step to optimize the part computation.
550 * \sa MEDCouplingFieldDouble::buildSubPart
553 typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPartRange(mcIdType begin, mcIdType end, mcIdType step) const
556 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
557 DataArrayIdType *arrSelect;
558 mcIdType beginOut,endOut,stepOut;
559 MCAuto<MEDCouplingMesh> m(_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect));
560 MCAuto<DataArrayIdType> arrSelect2(arrSelect);
561 MCAuto< typename Traits<T>::FieldType > ret(clone(false));//quick shallow copy.
562 const MEDCouplingFieldDiscretization *disc=getDiscretization();
564 ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePartRange(begin,end,step)));
566 std::vector<typename Traits<T>::ArrayType *> arrays;
567 timeDiscrSafe()->getArrays(arrays);
568 std::vector<typename Traits<T>::ArrayType *> arrs;
569 std::vector< MCAuto< typename Traits<T>::ArrayType > > arrsSafe;
570 for(typename std::vector<typename Traits<T>::ArrayType *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
572 typename Traits<T>::ArrayType *arr(0);
577 const mcIdType *arrSelBg=arrSelect->begin();
578 const mcIdType *arrSelEnd=arrSelect->end();
579 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
582 arr=(*iter)->selectByTupleIdSafeSlice(beginOut,endOut,stepOut);
584 arrs.push_back(arr); arrsSafe.push_back(arr);
586 ret->timeDiscrSafe()->setArrays(arrs,0);
591 const MEDCouplingTimeDiscretizationTemplate<T> *MEDCouplingFieldT<T>::timeDiscrSafe() const
593 const MEDCouplingTimeDiscretizationTemplate<T> *ret(_time_discr);
595 throw INTERP_KERNEL::Exception("const FieldT : Null type of time discr !");
600 MEDCouplingTimeDiscretizationTemplate<T> *MEDCouplingFieldT<T>::timeDiscrSafe()
602 MEDCouplingTimeDiscretizationTemplate<T> *ret(_time_discr);
604 throw INTERP_KERNEL::Exception("const FieldT : Null type of time discr !");
609 void MEDCouplingFieldT<T>::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
612 timeDiscrSafe()->getTinySerializationStrInformation(tinyInfo);
613 tinyInfo.push_back(_name);
614 tinyInfo.push_back(_desc);
615 tinyInfo.push_back(getTimeUnit());
619 * This method retrieves some critical values to resize and prepare remote instance.
620 * The first two elements returned in tinyInfo correspond to the parameters to give in constructor.
621 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
624 void MEDCouplingFieldT<T>::getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const
627 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
629 tinyInfo.push_back(ToIdType(_type->getEnum()));
630 tinyInfo.push_back(ToIdType(timeDiscrSafe()->getEnum()));
631 tinyInfo.push_back(ToIdType(_nature));
632 timeDiscrSafe()->getTinySerializationIntInformation(tinyInfo);
633 std::vector<mcIdType> tinyInfo2;
634 _type->getTinySerializationIntInformation(tinyInfo2);
635 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
636 tinyInfo.push_back(ToIdType(tinyInfo2.size()));
640 * This method retrieves some critical values to resize and prepare remote instance.
641 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
644 void MEDCouplingFieldT<T>::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
647 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
649 timeDiscrSafe()->getTinySerializationDbleInformation(tinyInfo);
650 std::vector<double> tinyInfo2;
651 _type->getTinySerializationDbleInformation(tinyInfo2);
652 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
653 tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it
657 * This method has to be called to the new instance filled by CORBA, MPI, File...
658 * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied.
659 * @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.
660 * @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.
661 * No decrRef must be applied to every instances in returned vector.
662 * \sa checkForUnserialization
665 void MEDCouplingFieldT<T>::resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI, DataArrayIdType *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays)
668 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
670 std::vector<mcIdType> tinyInfoITmp(tinyInfoI);
671 mcIdType sz=tinyInfoITmp.back();
672 tinyInfoITmp.pop_back();
673 std::vector<mcIdType> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
674 std::vector<mcIdType> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
675 timeDiscrSafe()->resizeForUnserialization(tinyInfoI2,arrays);
676 std::vector<mcIdType> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
677 _type->resizeForUnserialization(tinyInfoITmp3,dataInt);
681 * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this
682 * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data.
683 * \sa resizeForUnserialization
686 void MEDCouplingFieldT<T>::checkForUnserialization(const std::vector<mcIdType>& tinyInfoI, const DataArrayIdType *dataInt, const std::vector<typename Traits<T>::ArrayType *>& arrays)
689 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
690 std::vector<mcIdType> tinyInfoITmp(tinyInfoI);
691 mcIdType sz=tinyInfoITmp.back();
692 tinyInfoITmp.pop_back();
693 std::vector<mcIdType> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
694 std::vector<mcIdType> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
695 timeDiscrSafe()->checkForUnserialization(tinyInfoI2,arrays);
696 std::vector<mcIdType> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
697 _type->checkForUnserialization(tinyInfoITmp3,dataInt);
701 void MEDCouplingFieldT<T>::finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
704 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
705 std::vector<mcIdType> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
707 std::vector<double> tmp(tinyInfoD);
708 mcIdType sz=ToIdType(tinyInfoD.back());//very bad, lack of time to improve it
710 std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
711 std::vector<double> tmp2(tmp.end()-sz,tmp.end());
713 timeDiscrSafe()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
714 _nature=(NatureOfField)tinyInfoI[2];
715 _type->finishUnserialization(tmp2);
716 std::size_t nbOfElemS=tinyInfoS.size();
717 _name=tinyInfoS[nbOfElemS-3];
718 _desc=tinyInfoS[nbOfElemS-2];
719 setTimeUnit(tinyInfoS[nbOfElemS-1]);
723 * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsibilities of the caller.
724 * The values returned must be consulted only in readonly mode.
727 void MEDCouplingFieldT<T>::serialize(DataArrayIdType *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays) const
730 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");
731 timeDiscrSafe()->getArrays(arrays);
732 _type->getSerializationIntArray(dataInt);