1 // Copyright (C) 2007-2020 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;
203 void MEDFileField1TSTemplateWithoutSDA<T>::copyTimeInfoFrom(const typename Traits<T>::FieldType *mcf)
206 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA<T>::copyTimeInfoFrom : input field is nullptr !");
208 double a(mcf->getTime(b,c));
212 ///////////////////////////////////////////////////////
215 MEDFileField1TSWithoutSDA *MEDFileField1TSNDTemplateWithoutSDA<T>::convertToDouble() const
217 MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
218 ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
219 ret->deepCpyLeavesFrom(*this);
220 if(this->_arr.isNotNull())
222 MCAuto<DataArrayDouble> arr2(this->_arr->convertToDblArr());
228 ///////////////////////////////////////////////////////
231 MEDFileTemplateField1TS<T>::MEDFileTemplateField1TS()
233 _content=new typename MLFieldTraits<T>::F1TSWSDAType;
237 * Returns a new empty instance of MEDFileField1TS.
238 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
239 * is to delete this field using decrRef() as it is no more needed.
242 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New()
244 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType);
245 ret->contentNotNull();
250 * Returns a new instance of MEDFileField1TS holding data of the first time step of
251 * the first field that has been read from a specified MED file.
252 * \param [in] fileName - the name of the MED file to read.
253 * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
254 * is to delete this field using decrRef() as it is no more needed.
255 * \throw If reading the file fails.
258 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, bool loadAll)
260 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
261 return New(fid,loadAll);
265 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, bool loadAll)
267 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,loadAll,0));
268 ret->contentNotNull();
273 * Returns a new instance of MEDFileField1TS holding data of the first time step of
274 * a given field that has been read from a specified MED file.
275 * \param [in] fileName - the name of the MED file to read.
276 * \param [in] fieldName - the name of the field to read.
277 * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
278 * is to delete this field using decrRef() as it is no more needed.
279 * \throw If reading the file fails.
280 * \throw If there is no field named \a fieldName in the file.
283 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
285 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
286 return New(fid,fieldName,loadAll);
290 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
292 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,loadAll,0));
293 ret->contentNotNull();
298 * Returns a new instance of MEDFileField1TS holding data of a given time step of
299 * a given field that has been read from a specified MED file.
300 * \param [in] fileName - the name of the MED file to read.
301 * \param [in] fieldName - the name of the field to read.
302 * \param [in] iteration - the iteration number of a required time step.
303 * \param [in] order - the iteration order number of required time step.
304 * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
305 * is to delete this field using decrRef() as it is no more needed.
306 * \throw If reading the file fails.
307 * \throw If there is no field named \a fieldName in the file.
308 * \throw If the required time step is missing from the file.
311 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
313 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
314 return New(fid,fieldName,iteration,order,loadAll);
318 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
320 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,iteration,order,loadAll,0));
321 ret->contentNotNull();
326 * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
327 * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
329 * Returns a new instance of MEDFileField1TS holding either a shallow copy
330 * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
331 * \warning this is a shallow copy constructor
332 * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
333 * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
334 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
335 * is to delete this field using decrRef() as it is no more needed.
338 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const typename MLFieldTraits<T>::F1TSWSDAType& other, bool shallowCopyOfContent)
340 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(other,shallowCopyOfContent));
341 ret->contentNotNull();
346 const typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull() const
348 const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
350 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the content pointer is null !");
351 const typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
354 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;
355 throw INTERP_KERNEL::Exception(oss.str());
361 typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull()
363 MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
365 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the non const content pointer is null !");
366 typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
369 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;
370 throw INTERP_KERNEL::Exception(oss.str());
376 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(MCAuto<DataArray>& arr)
379 throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : no array !");
380 typename Traits<T>::ArrayType *arrOutC(dynamic_cast<typename Traits<T>::ArrayType *>((DataArray*)arr));
382 throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
388 * Returns values and a profile of the field of a given type lying on a given support.
389 * For more info, see \ref AdvMEDLoaderAPIFieldRW
390 * \param [in] type - a spatial discretization of the field.
391 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
392 * \param [in] mesh - the supporting mesh.
393 * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
394 * field of interest lies on. If the field lies on all entities of the given
395 * dimension, all ids in \a pfl are zero. The caller is to delete this array
396 * using decrRef() as it is no more needed.
397 * \return DataArrayInt * - a new instance of DataArrayInt holding values of the
398 * field. The caller is to delete this array using decrRef() as it is no more needed.
399 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
400 * \throw If no field of \a this is lying on \a mesh.
401 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
404 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayIdType *&pfl) const
406 MCAuto<DataArray> arr(contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull()));
407 return ReturnSafelyTypedDataArray(arr);
411 void MEDFileTemplateField1TS<T>::setArray(DataArray *arr)
413 return contentNotNull()->setArray(arr);
417 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArray() const
419 return contentNotNull()->getUndergroundDataArrayTemplate();
423 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
425 return contentNotNull()->getUndergroundDataArrayTemplateExt(entries);
429 MCAuto<typename Traits<T>::FieldType> MEDFileTemplateField1TS<T>::SetDataArrayInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
432 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : input field is NULL !");
434 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : no array !");
436 double t0(f->getTime(t1,t2));
437 std::string tu(f->getTimeUnit());
438 MCAuto<typename Traits<T>::ArrayType> arr2(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(arr));
439 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
440 MCAuto<typename Traits<T>::FieldType> ret(Traits<T>::FieldType::New(*ft));
441 ret->setTime(t0,t1,t2); ret->setArray(arr2); ret->setTimeUnit(tu);
446 MCAuto<MEDCouplingFieldDouble> MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(const typename Traits<T>::FieldType *f)
449 double t0(f->getTime(t1,t2));
450 std::string tu(f->getTimeUnit());
451 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*f));
452 MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
453 ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
458 void MEDFileTemplateField1TS<T>::copyTimeInfoFrom(const typename Traits<T>::FieldType *mcf)
460 contentNotNull()->copyTimeInfoFrom(mcf);
464 * 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
465 * method should be called (getFieldOnMeshAtLevel for example).
466 * But for normal usage of field in MED file world this method is the most efficient to fetch data.
468 * \param [in] mesh - the mesh the field is lying on
469 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
470 * caller is to delete this field using decrRef() as it is no more needed.
473 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::field(const MEDFileMesh *mesh) const
475 MCAuto<DataArray> arrOut;
476 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
477 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
482 * Returns a new typename Traits<T>::FieldType of a given type lying on
483 * mesh entities of a given dimension of the first mesh in MED file. If \a this field
484 * has not been constructed via file reading, an exception is thrown.
485 * For more info, see \ref AdvMEDLoaderAPIFieldRW
486 * \param [in] type - a spatial discretization of interest.
487 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
488 * \param [in] renumPol - specifies how to permute values of the result field according to
489 * the optional numbers of cells and nodes, if any. The valid values are
490 * - 0 - do not permute.
491 * - 1 - permute cells.
492 * - 2 - permute nodes.
493 * - 3 - permute cells and nodes.
495 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
496 * caller is to delete this field using decrRef() as it is no more needed.
497 * \throw If \a this field has not been constructed via file reading.
498 * \throw If the MED file is not readable.
499 * \throw If there is no mesh in the MED file.
500 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
501 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
502 * \sa getFieldOnMeshAtLevel()
505 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
507 if(getFileName().empty())
508 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 !");
509 MCAuto<DataArray> arrOut;
510 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
511 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
516 * Returns a new typename Traits<T>::FieldType of a given type lying on
517 * the top level cells of the first mesh in MED file. If \a this field
518 * has not been constructed via file reading, an exception is thrown.
519 * For more info, see \ref AdvMEDLoaderAPIFieldRW
520 * \param [in] type - a spatial discretization of interest.
521 * \param [in] renumPol - specifies how to permute values of the result field according to
522 * the optional numbers of cells and nodes, if any. The valid values are
523 * - 0 - do not permute.
524 * - 1 - permute cells.
525 * - 2 - permute nodes.
526 * - 3 - permute cells and nodes.
528 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
529 * caller is to delete this field using decrRef() as it is no more needed.
530 * \throw If \a this field has not been constructed via file reading.
531 * \throw If the MED file is not readable.
532 * \throw If there is no mesh in the MED file.
533 * \throw If no field values of the given \a type.
534 * \throw If no field values lying on the top level support.
535 * \sa getFieldAtLevel()
538 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtTopLevel(TypeOfField type, int renumPol) const
540 if(getFileName().empty())
541 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 !");
542 MCAuto<DataArray> arrOut;
543 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
544 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
549 * Returns a new typename Traits<T>::FieldType of given type lying on a given mesh.
550 * For more info, see \ref AdvMEDLoaderAPIFieldRW
551 * \param [in] type - a spatial discretization of the new field.
552 * \param [in] mesh - the supporting mesh.
553 * \param [in] renumPol - specifies how to permute values of the result field according to
554 * the optional numbers of cells and nodes, if any. The valid values are
555 * - 0 - do not permute.
556 * - 1 - permute cells.
557 * - 2 - permute nodes.
558 * - 3 - permute cells and nodes.
560 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
561 * caller is to delete this field using decrRef() as it is no more needed.
562 * \throw If no field of \a this is lying on \a mesh.
563 * \throw If the mesh is empty.
564 * \throw If no field values of the given \a type are available.
565 * \sa getFieldAtLevel()
566 * \sa getFieldOnMeshAtLevel()
569 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
571 MCAuto<DataArray> arrOut;
572 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
573 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
578 * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
579 * For more info, see \ref AdvMEDLoaderAPIFieldRW
580 * \param [in] type - a spatial discretization of interest.
581 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
582 * \param [in] mesh - the supporting mesh.
583 * \param [in] renumPol - specifies how to permute values of the result field according to
584 * the optional numbers of cells and nodes, if any. The valid values are
585 * - 0 - do not permute.
586 * - 1 - permute cells.
587 * - 2 - permute nodes.
588 * - 3 - permute cells and nodes.
590 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
591 * caller is to delete this field using decrRef() as it is no more needed.
592 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
593 * \throw If no field of \a this is lying on \a mesh.
594 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
595 * \sa getFieldAtLevel()
596 * \sa getFieldOnMeshAtLevel()
599 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
601 MCAuto<DataArray> arrOut;
602 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
603 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
608 * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
609 * This method is called "Old" because in MED3 norm a field has only one meshName
610 * attached, so this method is for readers of MED2 files. If \a this field
611 * has not been constructed via file reading, an exception is thrown.
612 * For more info, see \ref AdvMEDLoaderAPIFieldRW
613 * \param [in] type - a spatial discretization of interest.
614 * \param [in] mname - a name of the supporting mesh.
615 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
616 * \param [in] renumPol - specifies how to permute values of the result field according to
617 * the optional numbers of cells and nodes, if any. The valid values are
618 * - 0 - do not permute.
619 * - 1 - permute cells.
620 * - 2 - permute nodes.
621 * - 3 - permute cells and nodes.
623 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
624 * caller is to delete this field using decrRef() as it is no more needed.
625 * \throw If the MED file is not readable.
626 * \throw If there is no mesh named \a mName in the MED file.
627 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
628 * \throw If \a this field has not been constructed via file reading.
629 * \throw If no field of \a this is lying on the mesh named \a mName.
630 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
631 * \sa getFieldAtLevel()
634 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
636 if(getFileName().empty())
637 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 !");
638 MCAuto<DataArray> arrOut;
639 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
640 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
645 * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
646 * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
647 * "Sort By Type"), if not, an exception is thrown.
648 * For more info, see \ref AdvMEDLoaderAPIFieldRW
649 * \param [in] field - the field to add to \a this.
650 * \throw If the name of \a field is empty.
651 * \throw If the data array of \a field is not set.
652 * \throw If the data array is already allocated but has different number of components
654 * \throw If the underlying mesh of \a field has no name.
655 * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
658 void MEDFileTemplateField1TS<T>::setFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
661 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
662 contentNotNull()->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,field->getArray(),*this,*contentNotNull());
666 * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
667 * can be an aggregation of several MEDCouplingFieldDouble instances.
668 * The mesh support of input parameter \a field is ignored here, it can be NULL.
669 * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
672 * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
673 * A new profile is added only if no equal profile is missing.
674 * For more info, see \ref AdvMEDLoaderAPIFieldRW
675 * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
676 * \param [in] mesh - the supporting mesh of \a field.
677 * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
678 * \param [in] profile - ids of mesh entities on which corresponding field values lie.
679 * \throw If either \a field or \a mesh or \a profile has an empty name.
680 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
681 * \throw If the data array of \a field is not set.
682 * \throw If the data array of \a this is already allocated but has different number of
683 * components than \a field.
684 * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
685 * \sa setFieldNoProfileSBT, setFieldProfileFlatly
688 void MEDFileTemplateField1TS<T>::setFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
690 setFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,true);
694 * Same as setFieldProfile except that here profile will be created unconditionally
695 * \sa setFieldProfile
698 void MEDFileTemplateField1TS<T>::setFieldProfileFlatly(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
700 setFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,false);
704 void MEDFileTemplateField1TS<T>::setFieldProfileGeneral(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, bool smartPflKiller)
707 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
708 contentNotNull()->setFieldProfile(field->timeDiscrSafe(),ft,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull(),smartPflKiller);
712 * Return an extraction of \a this using \a extractDef map to specify the extraction.
713 * The keys of \a extractDef is level relative to max ext of \a mm mesh.
715 * \return A new object that the caller is responsible to deallocate.
716 * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
719 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayIdType> >& extractDef, MEDFileMesh *mm) const
722 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
723 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New());
724 std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
725 for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
729 std::vector<int> levs;
730 getNonEmptyLevels(mm->getName(),levs);
731 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
733 std::map<int, MCAuto<DataArrayIdType> >::const_iterator it2(extractDef.find(*lev));
734 if(it2!=extractDef.end())
736 MCAuto<DataArrayIdType> t((*it2).second);
738 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
739 MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
740 MCAuto<typename Traits<T>::FieldType> fOut(f->buildSubPart(t));
741 ret->setFieldNoProfileSBT(fOut);
747 std::map<int, MCAuto<DataArrayIdType> >::const_iterator it2(extractDef.find(1));
748 if(it2==extractDef.end())
749 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
750 MCAuto<DataArrayIdType> t((*it2).second);
752 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
753 MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
754 MCAuto<typename Traits<T>::FieldType> fOut(f->deepCopy());
755 typename Traits<T>::ArrayType *arr(f->getArray());
756 MCAuto<typename Traits<T>::ArrayType> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
757 fOut->setArray(newArr);
758 ret->setFieldNoProfileSBT(fOut);
764 //////////////////////////
767 * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
768 * following the given input policy.
770 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
771 * By default (true) the globals are deeply copied.
772 * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
775 MEDFileField1TS *MEDFileNDTemplateField1TS<T>::convertToDouble(bool isDeepCpyGlobs) const
777 MCAuto<MEDFileField1TS> ret;
778 const MEDFileAnyTypeField1TSWithoutSDA *content(this->_content);
781 const typename MLFieldTraits<T>::F1TSWSDAType *contc(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(content));
784 std::ostringstream oss; oss << "MEDFileNDTemplateField1TS<T>::convertToDouble : the content inside this is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " ! This is incoherent !";
785 throw INTERP_KERNEL::Exception(oss.str());
787 MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
788 ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
791 ret=MEDFileField1TS::New();
793 ret->deepCpyGlobs(*this);
795 ret->shallowCpyGlobs(*this);
799 //////////////////////////
802 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)
804 return new typename MLFieldTraits<T>::FMTSWSDAType(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
808 void MEDFileTemplateFieldMultiTSWithoutSDA<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
811 throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
812 const typename MLFieldTraits<T>::F1TSWSDAType *f1tsC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(f1ts));
815 std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
816 throw INTERP_KERNEL::Exception(oss.str());
821 const char *MEDFileTemplateFieldMultiTSWithoutSDA<T>::getTypeStr() const
823 return MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
827 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew() const
829 return new typename MLFieldTraits<T>::FMTSWSDAType;
833 MEDFileAnyTypeField1TSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew1TSWithoutSDAEmptyInstance() const
835 return new typename MLFieldTraits<T>::F1TSWSDAType;
838 //////////////////////////
841 MEDFileFieldMultiTSWithoutSDA *MEDFileNDTemplateFieldMultiTSWithoutSDA<T>::convertToDouble() const
843 MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
844 ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
846 for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=this->_time_steps.begin();it!=this->_time_steps.end();it++,i++)
848 const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
851 const typename MLFieldTraits<T>::F1TSWSDAType *eltToConvC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(eltToConv));
853 throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
854 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt(eltToConvC->convertToDouble());
855 ret->setIteration(i,elt);
861 //////////////////////////
864 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS()
866 _content=new typename MLFieldTraits<T>::FMTSWSDAType;
870 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
875 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
880 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
885 * Return an extraction of \a this using \a extractDef map to specify the extraction.
886 * The keys of \a extractDef is level relative to max ext of \a mm mesh.
888 * \return A new object that the caller is responsible to deallocate.
891 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayIdType> >& extractDef, MEDFileMesh *mm) const
894 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::extractPart : mesh is null !");
895 MCAuto<typename MLFieldTraits<T>::FMTSType> fmtsOut(MLFieldTraits<T>::FMTSType::New());
896 int nbTS(getNumberOfTS());
897 for(int i=0;i<nbTS;i++)
899 MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
900 MCAuto<typename MLFieldTraits<T>::F1TSType> f1ts2(DynamicCastSafe<MEDFileAnyTypeField1TS,typename MLFieldTraits<T>::F1TSType>(f1ts));
901 MCAuto<typename MLFieldTraits<T>::F1TSType> f1tsOut(f1ts2->extractPartImpl(extractDef,mm));
902 fmtsOut->pushBackTimeStep(f1tsOut);
904 return fmtsOut.retn();
908 * Returns a new empty instance of MEDFileFieldMultiTS.
909 * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
910 * is to delete this field using decrRef() as it is no more needed.
913 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New()
915 return new typename MLFieldTraits<T>::FMTSType;
919 * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding data of the first field
920 * that has been read from a specified MED file.
921 * \param [in] fileName - the name of the MED file to read.
922 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
923 * is to delete this field using decrRef() as it is no more needed.
924 * \throw If reading the file fails.
927 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, bool loadAll)
929 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
930 return New(fid,loadAll);
934 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, bool loadAll)
936 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,loadAll,0));
937 ret->contentNotNull();//to check that content type matches with \a this type.
942 * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
943 * that has been read from a specified MED file.
944 * \param [in] fileName - the name of the MED file to read.
945 * \param [in] fieldName - the name of the field to read.
946 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
947 * is to delete this field using decrRef() as it is no more needed.
948 * \throw If reading the file fails.
949 * \throw If there is no field named \a fieldName in the file.
952 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
954 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
955 return New(fid,fieldName,loadAll);
959 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
961 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0));
962 ret->contentNotNull();//to check that content type matches with \a this type.
967 * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
968 * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
970 * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding either a shallow copy
971 * of a given MEDFileTemplateFieldMultiTS<T>WithoutSDA ( \a other ) or \a other itself.
972 * \warning this is a shallow copy constructor
973 * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
974 * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
975 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
976 * is to delete this field using decrRef() as it is no more needed.
979 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent)
981 return new typename MLFieldTraits<T>::FMTSType(other,shallowCopyOfContent);
985 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)
987 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
988 INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
989 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0,ent));
990 ret->contentNotNull();//to check that content type matches with \a this type.
995 * 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
996 * method should be called (getFieldOnMeshAtLevel for example).
997 * But for normal usage of field in MED file world this method is the most efficient to fetch data.
999 * \param [in] iteration - the iteration number of a required time step.
1000 * \param [in] order - the iteration order number of required time step.
1001 * \param [in] mesh - the mesh the field is lying on
1002 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1003 * caller is to delete this field using decrRef() as it is no more needed.
1006 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::field(int iteration, int order, const MEDFileMesh *mesh) const
1008 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1009 MCAuto<DataArray> arrOut;
1010 MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
1011 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1016 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1017 * mesh entities of a given dimension of the first mesh in MED file.
1018 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1019 * \param [in] type - a spatial discretization of interest.
1020 * \param [in] iteration - the iteration number of a required time step.
1021 * \param [in] order - the iteration order number of required time step.
1022 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1023 * \param [in] renumPol - specifies how to permute values of the result field according to
1024 * the optional numbers of cells and nodes, if any. The valid values are
1025 * - 0 - do not permute.
1026 * - 1 - permute cells.
1027 * - 2 - permute nodes.
1028 * - 3 - permute cells and nodes.
1030 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1031 * caller is to delete this field using decrRef() as it is no more needed.
1032 * \throw If the MED file is not readable.
1033 * \throw If there is no mesh in the MED file.
1034 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1035 * \throw If no field values of the required parameters are available.
1038 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
1040 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1041 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1043 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
1044 MCAuto<DataArray> arrOut;
1045 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1046 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1051 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1052 * the top level cells of the first mesh in MED file.
1053 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1054 * \param [in] type - a spatial discretization of interest.
1055 * \param [in] iteration - the iteration number of a required time step.
1056 * \param [in] order - the iteration order number of required time step.
1057 * \param [in] renumPol - specifies how to permute values of the result field according to
1058 * the optional numbers of cells and nodes, if any. The valid values are
1059 * - 0 - do not permute.
1060 * - 1 - permute cells.
1061 * - 2 - permute nodes.
1062 * - 3 - permute cells and nodes.
1064 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1065 * caller is to delete this field using decrRef() as it is no more needed.
1066 * \throw If the MED file is not readable.
1067 * \throw If there is no mesh in the MED file.
1068 * \throw If no field values of the required parameters are available.
1071 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
1073 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1074 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1076 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel : mismatch of type of field !");
1077 MCAuto<DataArray> arrOut;
1078 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1079 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1084 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1086 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1087 * \param [in] type - a spatial discretization of interest.
1088 * \param [in] iteration - the iteration number of a required time step.
1089 * \param [in] order - the iteration order number of required time step.
1090 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1091 * \param [in] mesh - the supporting mesh.
1092 * \param [in] renumPol - specifies how to permute values of the result field according to
1093 * the optional numbers of cells and nodes, if any. The valid values are
1094 * - 0 - do not permute.
1095 * - 1 - permute cells.
1096 * - 2 - permute nodes.
1097 * - 3 - permute cells and nodes.
1099 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1100 * caller is to delete this field using decrRef() as it is no more needed.
1101 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1102 * \throw If no field of \a this is lying on \a mesh.
1103 * \throw If no field values of the required parameters are available.
1106 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
1108 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1109 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1111 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1112 MCAuto<DataArray> arrOut;
1113 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase()));
1114 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1119 * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
1121 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1122 * \param [in] type - a spatial discretization of the new field.
1123 * \param [in] iteration - the iteration number of a required time step.
1124 * \param [in] order - the iteration order number of required time step.
1125 * \param [in] mesh - the supporting mesh.
1126 * \param [in] renumPol - specifies how to permute values of the result field according to
1127 * the optional numbers of cells and nodes, if any. The valid values are
1128 * - 0 - do not permute.
1129 * - 1 - permute cells.
1130 * - 2 - permute nodes.
1131 * - 3 - permute cells and nodes.
1133 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1134 * caller is to delete this field using decrRef() as it is no more needed.
1135 * \throw If no field of \a this is lying on \a mesh.
1136 * \throw If no field values of the required parameters are available.
1139 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
1141 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1142 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1144 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1145 MCAuto<DataArray> arrOut;
1146 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase()));
1147 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1152 * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
1153 * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
1154 * This method is useful for MED2 file format when field on different mesh was autorized.
1157 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
1159 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1160 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1162 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld : mismatch of type of field !");
1163 MCAuto<DataArray> arrOut;
1164 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase()));
1165 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1170 * Returns values and a profile of the field of a given type, of a given time step,
1171 * lying on a given support.
1172 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1173 * \param [in] type - a spatial discretization of the field.
1174 * \param [in] iteration - the iteration number of a required time step.
1175 * \param [in] order - the iteration order number of required time step.
1176 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1177 * \param [in] mesh - the supporting mesh.
1178 * \param [out] pfl - a new instance of DataArrayIdType holding ids of mesh entities the
1179 * field of interest lies on. If the field lies on all entities of the given
1180 * dimension, all ids in \a pfl are zero. The caller is to delete this array
1181 * using decrRef() as it is no more needed.
1182 * \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
1183 * field. The caller is to delete this array using decrRef() as it is no more needed.
1184 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1185 * \throw If no field of \a this is lying on \a mesh.
1186 * \throw If no field values of the required parameters are available.
1189 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayIdType *&pfl) const
1191 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1192 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1194 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile : mismatch of type of field !");
1195 MCAuto<DataArray> ret(myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase()));
1196 return MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(ret);
1200 * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
1201 * the given field is checked if its elements are sorted suitable for writing to MED file
1202 * ("STB" stands for "Sort By Type"), if not, an exception is thrown.
1203 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1204 * \param [in] field - the field to add to \a this.
1205 * \throw If the name of \a field is empty.
1206 * \throw If the data array of \a field is not set.
1207 * \throw If existing time steps have different name or number of components than \a field.
1208 * \throw If the underlying mesh of \a field has no name.
1209 * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
1212 void MEDFileTemplateFieldMultiTS<T>::appendFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
1214 const typename Traits<T>::ArrayType *arr(NULL);
1216 arr=field->getArray();
1217 MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1218 contentNotNull()->appendFieldNoProfileSBT(field2,arr,*this);
1222 * Adds a MEDCouplingFieldDouble to \a this as another time step.
1223 * The mesh support of input parameter \a field is ignored here, it can be NULL.
1224 * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
1227 * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
1228 * A new profile is added only if no equal profile is missing.
1229 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1230 * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
1231 * \param [in] mesh - the supporting mesh of \a field.
1232 * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
1233 * \param [in] profile - ids of mesh entities on which corresponding field values lie.
1234 * \throw If either \a field or \a mesh or \a profile has an empty name.
1235 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1236 * \throw If the data array of \a field is not set.
1237 * \throw If the data array of \a this is already allocated but has different number of
1238 * components than \a field.
1239 * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
1240 * \sa setFieldNoProfileSBT, appendFieldProfileFlatly
1243 void MEDFileTemplateFieldMultiTS<T>::appendFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
1245 appendFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,true);
1249 * same as appendFieldProfile except that here profile is created unconditionaly
1252 void MEDFileTemplateFieldMultiTS<T>::appendFieldProfileFlatly(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile)
1254 appendFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,false);
1258 void MEDFileTemplateFieldMultiTS<T>::appendFieldProfileGeneral(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, bool smartPflKiller)
1260 const typename Traits<T>::ArrayType *arr(NULL);
1262 arr=field->getArray();
1263 MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1264 contentNotNull()->appendFieldProfile(field2,arr,mesh,meshDimRelToMax,profile,*this,smartPflKiller);
1268 const typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull() const
1270 const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1272 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is null !");
1273 const typename MLFieldTraits<T>::FMTSWSDAType *ret=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(pt);
1275 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 !");
1280 typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull()
1282 MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1284 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is null !");
1285 typename MLFieldTraits<T>::FMTSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::FMTSWSDAType *>(pt));
1287 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 !");
1292 * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
1293 * \param [in] pos - a time step id.
1294 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
1295 * delete this field using decrRef() as it is no more needed.
1296 * \throw If \a pos is not a valid time step id.
1299 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateFieldMultiTS<T>::getTimeStepAtPos(int pos) const
1301 const MEDFileAnyTypeField1TSWithoutSDA *item(contentNotNullBase()->getTimeStepAtPos2(pos));
1304 std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
1305 throw INTERP_KERNEL::Exception(oss.str());
1307 const typename MLFieldTraits<T>::F1TSWSDAType *itemC=dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(item);
1310 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New(*itemC,false));
1311 ret->shallowCpyGlobs(*this);
1314 std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " !";
1315 throw INTERP_KERNEL::Exception(oss.str());
1319 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray(int iteration, int order) const
1321 DataArray *ret(contentNotNull()->getUndergroundDataArray(iteration,order));
1324 typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1327 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray : invalid type of data detected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1328 throw INTERP_KERNEL::Exception(oss.str());
1334 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
1336 DataArray *ret(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
1339 typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1342 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt : invalid type of data detected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1343 throw INTERP_KERNEL::Exception(oss.str());
1349 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::buildNewEmptyImpl() const
1351 return MLFieldTraits<T>::FMTSType::New();
1355 void MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
1358 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
1359 const typename MLFieldTraits<T>::F1TSType *f1tsC=dynamic_cast<const typename MLFieldTraits<T>::F1TSType *>(f1ts);
1362 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
1363 throw INTERP_KERNEL::Exception(oss.str());
1367 //////////////////////////
1370 * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
1371 * following the given input policy.
1373 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
1374 * By default (true) the globals are deeply copied.
1375 * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
1378 MEDFileFieldMultiTS *MEDFileNDTemplateFieldMultiTS<T>::convertToDouble(bool isDeepCpyGlobs) const
1380 MCAuto<MEDFileFieldMultiTS> ret;
1381 const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(this->_content);
1384 const typename MLFieldTraits<T>::FMTSWSDAType *contc=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(content);
1386 throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
1387 MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
1388 ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
1391 ret=MEDFileFieldMultiTS::New();
1393 ret->deepCpyGlobs(*this);
1395 ret->shallowCpyGlobs(*this);