1 // Copyright (C) 2007-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)
23 #include "MEDFileField.hxx"
24 #include "MEDCouplingTraits.hxx"
25 #include "MEDCouplingFieldInt32.hxx"
26 #include "MEDCouplingFieldInt64.hxx"
27 #include "MEDCouplingFieldFloat.hxx"
28 #include "MEDCouplingFieldDouble.hxx"
29 #include "MEDCouplingFieldTemplate.hxx"
34 void MEDFileField1TSTemplateWithoutSDA<T>::setArray(DataArray *arr)
38 _nb_of_tuples_to_be_allocated=-1;
42 typename Traits<T>::ArrayType *arrC=dynamic_cast<typename Traits<T>::ArrayType *>(arr);
44 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
46 _nb_of_tuples_to_be_allocated=-3;
52 * Returns a pointer to the underground DataArrayTemplate<T> instance. So the
53 * caller should not decrRef() it. This method allows for a direct access to the field
54 * values. This method is quite unusable if there is more than a nodal field or a cell
55 * field on single geometric cell type.
56 * \return DataArrayTemplate<T> * - the pointer to the field values array.
59 DataArray *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArray()
61 return getOrCreateAndGetArrayTemplate();
65 const DataArray *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArray() const
67 return getOrCreateAndGetArrayTemplate();
71 DataArray *MEDFileField1TSTemplateWithoutSDA<T>::createNewEmptyDataArrayInstance() const
73 return Traits<T>::ArrayType::New();
77 typename Traits<T>::ArrayType const *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArrayTemplate() const
79 typename Traits<T>::ArrayType const *ret(_arr);
82 (const_cast< MEDFileField1TSTemplateWithoutSDA<T> *>(this))->_arr=Traits<T>::ArrayType::New();
87 typename Traits<T>::ArrayType *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArrayTemplate()
89 typename Traits<T>::ArrayType *ret(_arr);
92 _arr=Traits<T>::ArrayType::New();
97 * Returns a pointer to the underground DataArrayTemplate<T> instance. So the
98 * caller should not decrRef() it. This method allows for a direct access to the field
99 * values. This method is quite unusable if there is more than a nodal field or a cell
100 * field on single geometric cell type.
101 * \return DataArrayTemplate<T> * - the pointer to the field values array.
104 typename Traits<T>::ArrayType *MEDFileField1TSTemplateWithoutSDA<T>::getUndergroundDataArrayTemplate() const
106 typename Traits<T>::ArrayType const *ret(_arr);
108 return const_cast<typename Traits<T>::ArrayType *>(ret);
114 * Returns a pointer to the underground DataArrayDouble instance and a
115 * sequence describing parameters of a support of each part of \a this field. The
116 * caller should not decrRef() the returned DataArrayDouble. This method allows for a
117 * direct access to the field values. This method is intended for the field lying on one
119 * \param [in,out] entries - the sequence describing parameters of a support of each
120 * part of \a this field. Each item of this sequence consists of two parts. The
121 * first part describes a type of mesh entity and an id of discretization of a
122 * current field part. The second part describes a range of values [begin,end)
123 * within the returned array relating to the current field part.
124 * \return DataArrayDouble * - the pointer to the field values array.
125 * \throw If the number of underlying meshes is not equal to 1.
126 * \throw If no field values are available.
127 * \sa getUndergroundDataArrayTemplate()
130 typename Traits<T>::ArrayType *MEDFileField1TSTemplateWithoutSDA<T>::getUndergroundDataArrayTemplateExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
132 if(this->_field_per_mesh.size()!=1)
133 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
134 if(this->_field_per_mesh[0]==0)
135 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
136 this->_field_per_mesh[0]->getUndergroundDataArrayExt(entries);
137 return getUndergroundDataArrayTemplate();
141 * Returns a pointer to the underground DataArrayDouble instance. So the
142 * caller should not decrRef() it. This method allows for a direct access to the field
143 * values. This method is quite unusable if there is more than a nodal field or a cell
144 * field on single geometric cell type.
145 * \return DataArrayDouble * - the pointer to the field values array.
148 DataArray *MEDFileField1TSTemplateWithoutSDA<T>::getUndergroundDataArray() const
150 return getUndergroundDataArrayTemplate();
154 void MEDFileField1TSTemplateWithoutSDA<T>::aggregate(const std::vector<typename MLFieldTraits<T>::F1TSWSDAType const *>& f1tss, const std::vector< std::vector< std::pair<int,mcIdType> > >& dts)
157 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : empty vector !");
158 std::size_t sz(f1tss.size()),ii(0);
159 std::vector<const MEDFileFieldPerMesh *> pms;
160 std::vector<const DataArray *> das(sz);
161 for(typename std::vector<typename MLFieldTraits<T>::F1TSWSDAType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,ii++)
164 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : presence of null pointer in input vector !");
165 if((*it)->_field_per_mesh.empty())
166 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : no info !");
167 const typename Traits<T>::ArrayType *arr((*it)->getUndergroundDataArrayTemplate());
169 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : presence of null array !");
171 pms.push_back((*it)->_field_per_mesh[0]);
173 typename MLFieldTraits<T>::F1TSWSDAType const *refPt(f1tss[0]);
174 setName(refPt->getName());
176 const DataArray *arr(refPt->getUndergroundDataArray());
177 std::size_t nbCompo(arr->getNumberOfComponents());
178 for(typename std::vector<typename MLFieldTraits<T>::F1TSWSDAType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++)
180 const typename Traits<T>::ArrayType *myArr((*it)->getUndergroundDataArrayTemplate());
181 if(myArr->getNumberOfComponents()!=nbCompo)
182 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : arrays must have same number of components !");
184 std::vector<std::pair< int, std::pair<mcIdType,mcIdType> > > extractInfo;
186 MCAuto<MEDFileFieldPerMesh> fpm(MEDFileFieldPerMesh::Aggregate(start,pms,dts,this,extractInfo));
187 _field_per_mesh.push_back(fpm);
189 double tv(f1tss[0]->getTime(iteration,order));
190 _iteration=iteration; _order=order; _dt=tv;
191 _arr=Traits<T>::ArrayType::New();
192 _arr->alloc(start,nbCompo); _arr->copyStringInfoFrom(*arr);
194 for(std::vector<std::pair< int, std::pair<mcIdType,mcIdType> > >::const_iterator it=extractInfo.begin();it!=extractInfo.end();it++)
196 const DataArray *zeArr(das[(*it).first]);
197 _arr->setContigPartOfSelectedValuesSlice(start,zeArr,(*it).second.first,(*it).second.second,1);
198 start+=(*it).second.second-(*it).second.first;
200 // see definition of _nb_of_tuples_to_be_allocated. array is built from scratch and allocated.
201 _nb_of_tuples_to_be_allocated=-3;
205 void MEDFileField1TSTemplateWithoutSDA<T>::copyTimeInfoFrom(const typename Traits<T>::FieldType *mcf)
208 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA<T>::copyTimeInfoFrom : input field is nullptr !");
210 double a(mcf->getTime(b,c));
214 ///////////////////////////////////////////////////////
217 MEDFileField1TSWithoutSDA *MEDFileField1TSNDTemplateWithoutSDA<T>::convertToDouble() const
219 MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
220 ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
221 ret->deepCpyLeavesFrom(*this);
222 if(this->_arr.isNotNull())
224 MCAuto<DataArrayDouble> arr2(this->_arr->convertToDblArr());
230 ///////////////////////////////////////////////////////
233 MEDFileTemplateField1TS<T>::MEDFileTemplateField1TS()
235 _content=new typename MLFieldTraits<T>::F1TSWSDAType;
239 * Returns a new empty instance of MEDFileField1TS.
240 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
241 * is to delete this field using decrRef() as it is no more needed.
244 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New()
246 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType);
247 ret->contentNotNull();
252 * Returns a new instance of MEDFileField1TS holding data of the first time step of
253 * the first field that has been read from a specified MED file.
254 * \param [in] fileName - the name of the MED file to read.
255 * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
256 * is to delete this field using decrRef() as it is no more needed.
257 * \throw If reading the file fails.
260 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, bool loadAll)
262 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
263 return New(fid,loadAll);
267 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, bool loadAll)
269 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,loadAll,0));
270 ret->contentNotNull();
275 * Returns a new instance of MEDFileField1TS holding data of the first time step of
276 * a given field that has been read from a specified MED file.
277 * \param [in] fileName - the name of the MED file to read.
278 * \param [in] fieldName - the name of the field to read.
279 * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
280 * is to delete this field using decrRef() as it is no more needed.
281 * \throw If reading the file fails.
282 * \throw If there is no field named \a fieldName in the file.
285 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
287 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
288 return New(fid,fieldName,loadAll);
292 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
294 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,loadAll,0));
295 ret->contentNotNull();
300 * Returns a new instance of MEDFileField1TS holding data of a given time step of
301 * a given field that has been read from a specified MED file.
302 * \param [in] fileName - the name of the MED file to read.
303 * \param [in] fieldName - the name of the field to read.
304 * \param [in] iteration - the iteration number of a required time step.
305 * \param [in] order - the iteration order number of required time step.
306 * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
307 * is to delete this field using decrRef() as it is no more needed.
308 * \throw If reading the file fails.
309 * \throw If there is no field named \a fieldName in the file.
310 * \throw If the required time step is missing from the file.
313 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
315 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
316 return New(fid,fieldName,iteration,order,loadAll);
320 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
322 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,iteration,order,loadAll,0));
323 ret->contentNotNull();
328 * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
329 * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
331 * Returns a new instance of MEDFileField1TS holding either a shallow copy
332 * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
333 * \warning this is a shallow copy constructor
334 * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
335 * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
336 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
337 * is to delete this field using decrRef() as it is no more needed.
340 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const typename MLFieldTraits<T>::F1TSWSDAType& other, bool shallowCopyOfContent)
342 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(other,shallowCopyOfContent));
343 ret->contentNotNull();
348 const typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull() const
350 const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
352 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the content pointer is null !");
353 const typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
356 std::ostringstream oss; oss << "MEDFileTemplateField1TS<T>::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
357 throw INTERP_KERNEL::Exception(oss.str());
363 typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull()
365 MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
367 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the non const content pointer is null !");
368 typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
371 std::ostringstream oss; oss << "MEDFileTemplateField1TS<T>::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
372 throw INTERP_KERNEL::Exception(oss.str());
378 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(MCAuto<DataArray>& arr)
381 throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : no array !");
382 typename Traits<T>::ArrayType *arrOutC(dynamic_cast<typename Traits<T>::ArrayType *>((DataArray*)arr));
384 throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
390 * Returns values and a profile of the field of a given type lying on a given support.
391 * For more info, see \ref AdvMEDLoaderAPIFieldRW
392 * \param [in] type - a spatial discretization of the field.
393 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
394 * \param [in] mesh - the supporting mesh.
395 * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
396 * field of interest lies on. If the field lies on all entities of the given
397 * dimension, all ids in \a pfl are zero. The caller is to delete this array
398 * using decrRef() as it is no more needed.
399 * \return DataArrayInt * - a new instance of DataArrayInt holding values of the
400 * field. The caller is to delete this array using decrRef() as it is no more needed.
401 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
402 * \throw If no field of \a this is lying on \a mesh.
403 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
406 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayIdType *&pfl) const
408 MCAuto<DataArray> arr(contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull()));
409 return ReturnSafelyTypedDataArray(arr);
413 void MEDFileTemplateField1TS<T>::setArray(DataArray *arr)
415 return contentNotNull()->setArray(arr);
419 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArray() const
421 return contentNotNull()->getUndergroundDataArrayTemplate();
425 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
427 return contentNotNull()->getUndergroundDataArrayTemplateExt(entries);
431 MCAuto<typename Traits<T>::FieldType> MEDFileTemplateField1TS<T>::SetDataArrayInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
434 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : input field is NULL !");
436 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : no array !");
438 double t0(f->getTime(t1,t2));
439 std::string tu(f->getTimeUnit());
440 MCAuto<typename Traits<T>::ArrayType> arr2(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(arr));
441 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
442 MCAuto<typename Traits<T>::FieldType> ret(Traits<T>::FieldType::New(*ft));
443 ret->setTime(t0,t1,t2); ret->setArray(arr2); ret->setTimeUnit(tu);
448 MCAuto<MEDCouplingFieldDouble> MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(const typename Traits<T>::FieldType *f)
451 double t0(f->getTime(t1,t2));
452 std::string tu(f->getTimeUnit());
453 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*f));
454 MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
455 ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
460 void MEDFileTemplateField1TS<T>::copyTimeInfoFrom(const typename Traits<T>::FieldType *mcf)
462 contentNotNull()->copyTimeInfoFrom(mcf);
466 * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
467 * method should be called (getFieldOnMeshAtLevel for example).
468 * But for normal usage of field in MED file world this method is the most efficient to fetch data.
470 * \param [in] mesh - the mesh the field is lying on
471 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
472 * caller is to delete this field using decrRef() as it is no more needed.
475 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::field(const MEDFileMesh *mesh) const
477 MCAuto<DataArray> arrOut;
478 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
479 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
484 * Returns a new typename Traits<T>::FieldType of a given type lying on
485 * mesh entities of a given dimension of the first mesh in MED file. If \a this field
486 * has not been constructed via file reading, an exception is thrown.
487 * For more info, see \ref AdvMEDLoaderAPIFieldRW
488 * \param [in] type - a spatial discretization of interest.
489 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
490 * \param [in] renumPol - specifies how to permute values of the result field according to
491 * the optional numbers of cells and nodes, if any. The valid values are
492 * - 0 - do not permute.
493 * - 1 - permute cells.
494 * - 2 - permute nodes.
495 * - 3 - permute cells and nodes.
497 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
498 * caller is to delete this field using decrRef() as it is no more needed.
499 * \throw If \a this field has not been constructed via file reading.
500 * \throw If the MED file is not readable.
501 * \throw If there is no mesh in the MED file.
502 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
503 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
504 * \sa getFieldOnMeshAtLevel()
507 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
509 if(getFileName().empty())
510 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
511 MCAuto<DataArray> arrOut;
512 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
513 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
518 * Returns a new typename Traits<T>::FieldType of a given type lying on
519 * the top level cells of the first mesh in MED file. If \a this field
520 * has not been constructed via file reading, an exception is thrown.
521 * For more info, see \ref AdvMEDLoaderAPIFieldRW
522 * \param [in] type - a spatial discretization of interest.
523 * \param [in] renumPol - specifies how to permute values of the result field according to
524 * the optional numbers of cells and nodes, if any. The valid values are
525 * - 0 - do not permute.
526 * - 1 - permute cells.
527 * - 2 - permute nodes.
528 * - 3 - permute cells and nodes.
530 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
531 * caller is to delete this field using decrRef() as it is no more needed.
532 * \throw If \a this field has not been constructed via file reading.
533 * \throw If the MED file is not readable.
534 * \throw If there is no mesh in the MED file.
535 * \throw If no field values of the given \a type.
536 * \throw If no field values lying on the top level support.
537 * \sa getFieldAtLevel()
540 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtTopLevel(TypeOfField type, int renumPol) const
542 if(getFileName().empty())
543 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
544 MCAuto<DataArray> arrOut;
545 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
546 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
551 * Returns a new typename Traits<T>::FieldType of given type lying on a given mesh.
552 * For more info, see \ref AdvMEDLoaderAPIFieldRW
553 * \param [in] type - a spatial discretization of the new field.
554 * \param [in] mesh - the supporting mesh.
555 * \param [in] renumPol - specifies how to permute values of the result field according to
556 * the optional numbers of cells and nodes, if any. The valid values are
557 * - 0 - do not permute.
558 * - 1 - permute cells.
559 * - 2 - permute nodes.
560 * - 3 - permute cells and nodes.
562 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
563 * caller is to delete this field using decrRef() as it is no more needed.
564 * \throw If no field of \a this is lying on \a mesh.
565 * \throw If the mesh is empty.
566 * \throw If no field values of the given \a type are available.
567 * \sa getFieldAtLevel()
568 * \sa getFieldOnMeshAtLevel()
571 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
573 MCAuto<DataArray> arrOut;
574 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
575 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
580 * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
581 * For more info, see \ref AdvMEDLoaderAPIFieldRW
582 * \param [in] type - a spatial discretization of interest.
583 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
584 * \param [in] mesh - the supporting mesh.
585 * \param [in] renumPol - specifies how to permute values of the result field according to
586 * the optional numbers of cells and nodes, if any. The valid values are
587 * - 0 - do not permute.
588 * - 1 - permute cells.
589 * - 2 - permute nodes.
590 * - 3 - permute cells and nodes.
592 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
593 * caller is to delete this field using decrRef() as it is no more needed.
594 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
595 * \throw If no field of \a this is lying on \a mesh.
596 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
597 * \sa getFieldAtLevel()
598 * \sa getFieldOnMeshAtLevel()
601 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
603 MCAuto<DataArray> arrOut;
604 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
605 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
610 * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
611 * This method is called "Old" because in MED3 norm a field has only one meshName
612 * attached, so this method is for readers of MED2 files. If \a this field
613 * has not been constructed via file reading, an exception is thrown.
614 * For more info, see \ref AdvMEDLoaderAPIFieldRW
615 * \param [in] type - a spatial discretization of interest.
616 * \param [in] mname - a name of the supporting mesh.
617 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
618 * \param [in] renumPol - specifies how to permute values of the result field according to
619 * the optional numbers of cells and nodes, if any. The valid values are
620 * - 0 - do not permute.
621 * - 1 - permute cells.
622 * - 2 - permute nodes.
623 * - 3 - permute cells and nodes.
625 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
626 * caller is to delete this field using decrRef() as it is no more needed.
627 * \throw If the MED file is not readable.
628 * \throw If there is no mesh named \a mName in the MED file.
629 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
630 * \throw If \a this field has not been constructed via file reading.
631 * \throw If no field of \a this is lying on the mesh named \a mName.
632 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
633 * \sa getFieldAtLevel()
636 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
638 if(getFileName().empty())
639 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
640 MCAuto<DataArray> arrOut;
641 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
642 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
647 * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
648 * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
649 * "Sort By Type"), if not, an exception is thrown.
650 * For more info, see \ref AdvMEDLoaderAPIFieldRW
651 * \param [in] field - the field to add to \a this.
652 * \throw If the name of \a field is empty.
653 * \throw If the data array of \a field is not set.
654 * \throw If the data array is already allocated but has different number of components
656 * \throw If the underlying mesh of \a field has no name.
657 * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
660 void MEDFileTemplateField1TS<T>::setFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
663 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
664 contentNotNull()->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,field->getArray(),*this,*contentNotNull());
668 * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
669 * can be an aggregation of several MEDCouplingFieldDouble instances.
670 * The mesh support of input parameter \a field is ignored here, it can be NULL.
671 * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
674 * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
675 * A new profile is added only if no equal profile is missing.
676 * For more info, see \ref AdvMEDLoaderAPIFieldRW
677 * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
678 * \param [in] mesh - the supporting mesh of \a field.
679 * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
680 * \param [in] profile - ids of mesh entities on which corresponding field values lie.
681 * \throw If either \a field or \a mesh or \a profile has an empty name.
682 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
683 * \throw If the data array of \a field is not set.
684 * \throw If the data array of \a this is already allocated but has different number of
685 * components than \a field.
686 * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
687 * \sa setFieldNoProfileSBT, setFieldProfileFlatly
690 void MEDFileTemplateField1TS<T>::setFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
692 setFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,true);
696 * Same as setFieldProfile except that here profile will be created unconditionally
697 * \sa setFieldProfile
700 void MEDFileTemplateField1TS<T>::setFieldProfileFlatly(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
702 setFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,false);
706 void MEDFileTemplateField1TS<T>::setFieldProfileGeneral(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, bool smartPflKiller)
709 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
710 contentNotNull()->setFieldProfile(field->timeDiscrSafe(),ft,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull(),smartPflKiller);
714 * Return an extraction of \a this using \a extractDef map to specify the extraction.
715 * The keys of \a extractDef is level relative to max ext of \a mm mesh.
717 * \return A new object that the caller is responsible to deallocate.
718 * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
721 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayIdType> >& extractDef, MEDFileMesh *mm) const
724 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
725 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New());
726 std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
727 for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
731 std::vector<int> levs;
732 getNonEmptyLevels(mm->getName(),levs);
733 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
735 std::map<int, MCAuto<DataArrayIdType> >::const_iterator it2(extractDef.find(*lev));
736 if(it2!=extractDef.end())
738 MCAuto<DataArrayIdType> t((*it2).second);
740 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
741 MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
742 MCAuto<typename Traits<T>::FieldType> fOut(f->buildSubPart(t));
743 ret->setFieldNoProfileSBT(fOut);
749 std::map<int, MCAuto<DataArrayIdType> >::const_iterator it2(extractDef.find(1));
750 if(it2==extractDef.end())
751 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
752 MCAuto<DataArrayIdType> t((*it2).second);
754 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
755 MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
756 MCAuto<typename Traits<T>::FieldType> fOut(f->deepCopy());
757 typename Traits<T>::ArrayType *arr(f->getArray());
758 MCAuto<typename Traits<T>::ArrayType> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
759 fOut->setArray(newArr);
760 ret->setFieldNoProfileSBT(fOut);
766 //////////////////////////
769 * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
770 * following the given input policy.
772 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
773 * By default (true) the globals are deeply copied.
774 * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
777 MEDFileField1TS *MEDFileNDTemplateField1TS<T>::convertToDouble(bool isDeepCpyGlobs) const
779 MCAuto<MEDFileField1TS> ret;
780 const MEDFileAnyTypeField1TSWithoutSDA *content(this->_content);
783 const typename MLFieldTraits<T>::F1TSWSDAType *contc(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(content));
786 std::ostringstream oss; oss << "MEDFileNDTemplateField1TS<T>::convertToDouble : the content inside this is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " ! This is incoherent !";
787 throw INTERP_KERNEL::Exception(oss.str());
789 MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
790 ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
793 ret=MEDFileField1TS::New();
795 ret->deepCpyGlobs(*this);
797 ret->shallowCpyGlobs(*this);
801 //////////////////////////
804 typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTSWithoutSDA<T>::New(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
806 return new typename MLFieldTraits<T>::FMTSWSDAType(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
810 void MEDFileTemplateFieldMultiTSWithoutSDA<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
813 throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
814 const typename MLFieldTraits<T>::F1TSWSDAType *f1tsC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(f1ts));
817 std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
818 throw INTERP_KERNEL::Exception(oss.str());
823 const char *MEDFileTemplateFieldMultiTSWithoutSDA<T>::getTypeStr() const
825 return MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
829 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew() const
831 return new typename MLFieldTraits<T>::FMTSWSDAType;
835 MEDFileAnyTypeField1TSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew1TSWithoutSDAEmptyInstance() const
837 return new typename MLFieldTraits<T>::F1TSWSDAType;
840 //////////////////////////
843 MEDFileFieldMultiTSWithoutSDA *MEDFileNDTemplateFieldMultiTSWithoutSDA<T>::convertToDouble() const
845 MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
846 ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
848 for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=this->_time_steps.begin();it!=this->_time_steps.end();it++,i++)
850 const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
853 const typename MLFieldTraits<T>::F1TSWSDAType *eltToConvC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(eltToConv));
855 throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
856 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt(eltToConvC->convertToDouble());
857 ret->setIteration(i,elt);
863 //////////////////////////
866 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS()
868 _content=new typename MLFieldTraits<T>::FMTSWSDAType;
872 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
877 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
882 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
887 * Return an extraction of \a this using \a extractDef map to specify the extraction.
888 * The keys of \a extractDef is level relative to max ext of \a mm mesh.
890 * \return A new object that the caller is responsible to deallocate.
893 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayIdType> >& extractDef, MEDFileMesh *mm) const
896 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::extractPart : mesh is null !");
897 MCAuto<typename MLFieldTraits<T>::FMTSType> fmtsOut(MLFieldTraits<T>::FMTSType::New());
898 int nbTS(getNumberOfTS());
899 for(int i=0;i<nbTS;i++)
901 MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
902 MCAuto<typename MLFieldTraits<T>::F1TSType> f1ts2(DynamicCastSafe<MEDFileAnyTypeField1TS,typename MLFieldTraits<T>::F1TSType>(f1ts));
903 MCAuto<typename MLFieldTraits<T>::F1TSType> f1tsOut(f1ts2->extractPartImpl(extractDef,mm));
904 fmtsOut->pushBackTimeStep(f1tsOut);
906 return fmtsOut.retn();
910 * Returns a new empty instance of MEDFileFieldMultiTS.
911 * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
912 * is to delete this field using decrRef() as it is no more needed.
915 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New()
917 return new typename MLFieldTraits<T>::FMTSType;
921 * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding data of the first field
922 * that has been read from a specified MED file.
923 * \param [in] fileName - the name of the MED file to read.
924 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
925 * is to delete this field using decrRef() as it is no more needed.
926 * \throw If reading the file fails.
929 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, bool loadAll)
931 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
932 return New(fid,loadAll);
936 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, bool loadAll)
938 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,loadAll,0));
939 ret->contentNotNull();//to check that content type matches with \a this type.
944 * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
945 * that has been read from a specified MED file.
946 * \param [in] fileName - the name of the MED file to read.
947 * \param [in] fieldName - the name of the field to read.
948 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
949 * is to delete this field using decrRef() as it is no more needed.
950 * \throw If reading the file fails.
951 * \throw If there is no field named \a fieldName in the file.
954 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
956 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
957 return New(fid,fieldName,loadAll);
961 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
963 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0));
964 ret->contentNotNull();//to check that content type matches with \a this type.
969 * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
970 * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
972 * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding either a shallow copy
973 * of a given MEDFileTemplateFieldMultiTS<T>WithoutSDA ( \a other ) or \a other itself.
974 * \warning this is a shallow copy constructor
975 * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
976 * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
977 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
978 * is to delete this field using decrRef() as it is no more needed.
981 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent)
983 return new typename MLFieldTraits<T>::FMTSType(other,shallowCopyOfContent);
987 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
989 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
990 INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
991 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0,ent));
992 ret->contentNotNull();//to check that content type matches with \a this type.
997 * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
998 * method should be called (getFieldOnMeshAtLevel for example).
999 * But for normal usage of field in MED file world this method is the most efficient to fetch data.
1001 * \param [in] iteration - the iteration number of a required time step.
1002 * \param [in] order - the iteration order number of required time step.
1003 * \param [in] mesh - the mesh the field is lying on
1004 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1005 * caller is to delete this field using decrRef() as it is no more needed.
1008 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::field(int iteration, int order, const MEDFileMesh *mesh) const
1010 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1011 MCAuto<DataArray> arrOut;
1012 MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
1013 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1018 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1019 * mesh entities of a given dimension of the first mesh in MED file.
1020 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1021 * \param [in] type - a spatial discretization of interest.
1022 * \param [in] iteration - the iteration number of a required time step.
1023 * \param [in] order - the iteration order number of required time step.
1024 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1025 * \param [in] renumPol - specifies how to permute values of the result field according to
1026 * the optional numbers of cells and nodes, if any. The valid values are
1027 * - 0 - do not permute.
1028 * - 1 - permute cells.
1029 * - 2 - permute nodes.
1030 * - 3 - permute cells and nodes.
1032 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1033 * caller is to delete this field using decrRef() as it is no more needed.
1034 * \throw If the MED file is not readable.
1035 * \throw If there is no mesh in the MED file.
1036 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1037 * \throw If no field values of the required parameters are available.
1040 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
1042 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1043 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1045 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
1046 MCAuto<DataArray> arrOut;
1047 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1048 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1053 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1054 * the top level cells of the first mesh in MED file.
1055 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1056 * \param [in] type - a spatial discretization of interest.
1057 * \param [in] iteration - the iteration number of a required time step.
1058 * \param [in] order - the iteration order number of required time step.
1059 * \param [in] renumPol - specifies how to permute values of the result field according to
1060 * the optional numbers of cells and nodes, if any. The valid values are
1061 * - 0 - do not permute.
1062 * - 1 - permute cells.
1063 * - 2 - permute nodes.
1064 * - 3 - permute cells and nodes.
1066 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1067 * caller is to delete this field using decrRef() as it is no more needed.
1068 * \throw If the MED file is not readable.
1069 * \throw If there is no mesh in the MED file.
1070 * \throw If no field values of the required parameters are available.
1073 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
1075 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1076 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1078 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel : mismatch of type of field !");
1079 MCAuto<DataArray> arrOut;
1080 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1081 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1086 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1088 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1089 * \param [in] type - a spatial discretization of interest.
1090 * \param [in] iteration - the iteration number of a required time step.
1091 * \param [in] order - the iteration order number of required time step.
1092 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1093 * \param [in] mesh - the supporting mesh.
1094 * \param [in] renumPol - specifies how to permute values of the result field according to
1095 * the optional numbers of cells and nodes, if any. The valid values are
1096 * - 0 - do not permute.
1097 * - 1 - permute cells.
1098 * - 2 - permute nodes.
1099 * - 3 - permute cells and nodes.
1101 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1102 * caller is to delete this field using decrRef() as it is no more needed.
1103 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1104 * \throw If no field of \a this is lying on \a mesh.
1105 * \throw If no field values of the required parameters are available.
1108 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
1110 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1111 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1113 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1114 MCAuto<DataArray> arrOut;
1115 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase()));
1116 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1121 * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
1123 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1124 * \param [in] type - a spatial discretization of the new field.
1125 * \param [in] iteration - the iteration number of a required time step.
1126 * \param [in] order - the iteration order number of required time step.
1127 * \param [in] mesh - the supporting mesh.
1128 * \param [in] renumPol - specifies how to permute values of the result field according to
1129 * the optional numbers of cells and nodes, if any. The valid values are
1130 * - 0 - do not permute.
1131 * - 1 - permute cells.
1132 * - 2 - permute nodes.
1133 * - 3 - permute cells and nodes.
1135 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1136 * caller is to delete this field using decrRef() as it is no more needed.
1137 * \throw If no field of \a this is lying on \a mesh.
1138 * \throw If no field values of the required parameters are available.
1141 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
1143 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1144 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1146 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1147 MCAuto<DataArray> arrOut;
1148 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase()));
1149 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1154 * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
1155 * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
1156 * This method is useful for MED2 file format when field on different mesh was autorized.
1159 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
1161 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1162 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1164 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld : mismatch of type of field !");
1165 MCAuto<DataArray> arrOut;
1166 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase()));
1167 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1172 * Returns values and a profile of the field of a given type, of a given time step,
1173 * lying on a given support.
1174 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1175 * \param [in] type - a spatial discretization of the field.
1176 * \param [in] iteration - the iteration number of a required time step.
1177 * \param [in] order - the iteration order number of required time step.
1178 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1179 * \param [in] mesh - the supporting mesh.
1180 * \param [out] pfl - a new instance of DataArrayIdType holding ids of mesh entities the
1181 * field of interest lies on. If the field lies on all entities of the given
1182 * dimension, all ids in \a pfl are zero. The caller is to delete this array
1183 * using decrRef() as it is no more needed.
1184 * \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
1185 * field. The caller is to delete this array using decrRef() as it is no more needed.
1186 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1187 * \throw If no field of \a this is lying on \a mesh.
1188 * \throw If no field values of the required parameters are available.
1191 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayIdType *&pfl) const
1193 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1194 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1196 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile : mismatch of type of field !");
1197 MCAuto<DataArray> ret(myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase()));
1198 return MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(ret);
1202 * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
1203 * the given field is checked if its elements are sorted suitable for writing to MED file
1204 * ("STB" stands for "Sort By Type"), if not, an exception is thrown.
1205 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1206 * \param [in] field - the field to add to \a this.
1207 * \throw If the name of \a field is empty.
1208 * \throw If the data array of \a field is not set.
1209 * \throw If existing time steps have different name or number of components than \a field.
1210 * \throw If the underlying mesh of \a field has no name.
1211 * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
1214 void MEDFileTemplateFieldMultiTS<T>::appendFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
1216 const typename Traits<T>::ArrayType *arr(NULL);
1218 arr=field->getArray();
1219 MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1220 contentNotNull()->appendFieldNoProfileSBT(field2,arr,*this);
1224 * Adds a MEDCouplingFieldDouble to \a this as another time step.
1225 * The mesh support of input parameter \a field is ignored here, it can be NULL.
1226 * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
1229 * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
1230 * A new profile is added only if no equal profile is missing.
1231 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1232 * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
1233 * \param [in] mesh - the supporting mesh of \a field.
1234 * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
1235 * \param [in] profile - ids of mesh entities on which corresponding field values lie.
1236 * \throw If either \a field or \a mesh or \a profile has an empty name.
1237 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1238 * \throw If the data array of \a field is not set.
1239 * \throw If the data array of \a this is already allocated but has different number of
1240 * components than \a field.
1241 * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
1242 * \sa setFieldNoProfileSBT, appendFieldProfileFlatly
1245 void MEDFileTemplateFieldMultiTS<T>::appendFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
1247 appendFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,true);
1251 * same as appendFieldProfile except that here profile is created unconditionaly
1254 void MEDFileTemplateFieldMultiTS<T>::appendFieldProfileFlatly(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
1256 appendFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,false);
1260 void MEDFileTemplateFieldMultiTS<T>::appendFieldProfileGeneral(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, bool smartPflKiller)
1262 const typename Traits<T>::ArrayType *arr(NULL);
1264 arr=field->getArray();
1265 MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1266 contentNotNull()->appendFieldProfile(field2,arr,mesh,meshDimRelToMax,profile,*this,smartPflKiller);
1270 const typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull() const
1272 const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1274 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is null !");
1275 const typename MLFieldTraits<T>::FMTSWSDAType *ret=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(pt);
1277 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
1282 typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull()
1284 MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1286 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is null !");
1287 typename MLFieldTraits<T>::FMTSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::FMTSWSDAType *>(pt));
1289 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
1294 * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
1295 * \param [in] pos - a time step id.
1296 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
1297 * delete this field using decrRef() as it is no more needed.
1298 * \throw If \a pos is not a valid time step id.
1301 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateFieldMultiTS<T>::getTimeStepAtPos(int pos) const
1303 const MEDFileAnyTypeField1TSWithoutSDA *item(contentNotNullBase()->getTimeStepAtPos2(pos));
1306 std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
1307 throw INTERP_KERNEL::Exception(oss.str());
1309 const typename MLFieldTraits<T>::F1TSWSDAType *itemC=dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(item);
1312 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New(*itemC,false));
1313 ret->shallowCpyGlobs(*this);
1316 std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " !";
1317 throw INTERP_KERNEL::Exception(oss.str());
1321 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray(int iteration, int order) const
1323 DataArray *ret(contentNotNull()->getUndergroundDataArray(iteration,order));
1326 typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1329 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray : invalid type of data detected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1330 throw INTERP_KERNEL::Exception(oss.str());
1336 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1338 DataArray *ret(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
1341 typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1344 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt : invalid type of data detected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1345 throw INTERP_KERNEL::Exception(oss.str());
1351 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::buildNewEmptyImpl() const
1353 return MLFieldTraits<T>::FMTSType::New();
1357 void MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
1360 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
1361 const typename MLFieldTraits<T>::F1TSType *f1tsC=dynamic_cast<const typename MLFieldTraits<T>::F1TSType *>(f1ts);
1364 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
1365 throw INTERP_KERNEL::Exception(oss.str());
1369 //////////////////////////
1372 * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
1373 * following the given input policy.
1375 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
1376 * By default (true) the globals are deeply copied.
1377 * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
1380 MEDFileFieldMultiTS *MEDFileNDTemplateFieldMultiTS<T>::convertToDouble(bool isDeepCpyGlobs) const
1382 MCAuto<MEDFileFieldMultiTS> ret;
1383 const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(this->_content);
1386 const typename MLFieldTraits<T>::FMTSWSDAType *contc=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(content);
1388 throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
1389 MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
1390 ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
1393 ret=MEDFileFieldMultiTS::New();
1395 ret->deepCpyGlobs(*this);
1397 ret->shallowCpyGlobs(*this);