1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #ifndef __MEDFILEFIELD_TXX__
22 #define __MEDFILEFIELD_TXX__
24 #include "MEDFileField.hxx"
25 #include "MEDCouplingTraits.hxx"
26 #include "MEDCouplingFieldInt.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<int,int> > >& 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,int> > >& 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 int 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<int,int> > > 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<int,int> > >::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;
202 ///////////////////////////////////////////////////////
205 MEDFileField1TSWithoutSDA *MEDFileField1TSNDTemplateWithoutSDA<T>::convertToDouble() const
207 MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
208 ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
209 ret->deepCpyLeavesFrom(*this);
210 if(this->_arr.isNotNull())
212 MCAuto<DataArrayDouble> arr2(this->_arr->convertToDblArr());
218 ///////////////////////////////////////////////////////
221 MEDFileTemplateField1TS<T>::MEDFileTemplateField1TS()
223 _content=new typename MLFieldTraits<T>::F1TSWSDAType;
227 * Returns a new empty instance of MEDFileField1TS.
228 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
229 * is to delete this field using decrRef() as it is no more needed.
232 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New()
234 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType);
235 ret->contentNotNull();
240 * Returns a new instance of MEDFileField1TS holding data of the first time step of
241 * the first field that has been read from a specified MED file.
242 * \param [in] fileName - the name of the MED file to read.
243 * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
244 * is to delete this field using decrRef() as it is no more needed.
245 * \throw If reading the file fails.
248 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, bool loadAll)
250 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
251 return New(fid,loadAll);
255 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, bool loadAll)
257 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,loadAll,0));
258 ret->contentNotNull();
263 * Returns a new instance of MEDFileField1TS holding data of the first time step of
264 * a given field that has been read from a specified MED file.
265 * \param [in] fileName - the name of the MED file to read.
266 * \param [in] fieldName - the name of the field to read.
267 * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
268 * is to delete this field using decrRef() as it is no more needed.
269 * \throw If reading the file fails.
270 * \throw If there is no field named \a fieldName in the file.
273 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
275 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
276 return New(fid,fieldName,loadAll);
280 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
282 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,loadAll,0));
283 ret->contentNotNull();
288 * Returns a new instance of MEDFileField1TS holding data of a given time step of
289 * a given field that has been read from a specified MED file.
290 * \param [in] fileName - the name of the MED file to read.
291 * \param [in] fieldName - the name of the field to read.
292 * \param [in] iteration - the iteration number of a required time step.
293 * \param [in] order - the iteration order number of required time step.
294 * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
295 * is to delete this field using decrRef() as it is no more needed.
296 * \throw If reading the file fails.
297 * \throw If there is no field named \a fieldName in the file.
298 * \throw If the required time step is missing from the file.
301 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
303 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
304 return New(fid,fieldName,iteration,order,loadAll);
308 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
310 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(fid,fieldName,iteration,order,loadAll,0));
311 ret->contentNotNull();
316 * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
317 * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
319 * Returns a new instance of MEDFileField1TS holding either a shallow copy
320 * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
321 * \warning this is a shallow copy constructor
322 * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
323 * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
324 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
325 * is to delete this field using decrRef() as it is no more needed.
328 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::New(const typename MLFieldTraits<T>::F1TSWSDAType& other, bool shallowCopyOfContent)
330 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(new typename MLFieldTraits<T>::F1TSType(other,shallowCopyOfContent));
331 ret->contentNotNull();
336 const typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull() const
338 const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
340 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the content pointer is null !");
341 const typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
344 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;
345 throw INTERP_KERNEL::Exception(oss.str());
351 typename MLFieldTraits<T>::F1TSWSDAType *MEDFileTemplateField1TS<T>::contentNotNull()
353 MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
355 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::contentNotNull : the non const content pointer is null !");
356 typename MLFieldTraits<T>::F1TSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(pt));
359 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;
360 throw INTERP_KERNEL::Exception(oss.str());
366 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(MCAuto<DataArray>& arr)
369 throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : no array !");
370 typename Traits<T>::ArrayType *arrOutC(dynamic_cast<typename Traits<T>::ArrayType *>((DataArray*)arr));
372 throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyTypedDataArray : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
378 * Returns values and a profile of the field of a given type lying on a given support.
379 * For more info, see \ref AdvMEDLoaderAPIFieldRW
380 * \param [in] type - a spatial discretization of the field.
381 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
382 * \param [in] mesh - the supporting mesh.
383 * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
384 * field of interest lies on. If the field lies on all entities of the given
385 * dimension, all ids in \a pfl are zero. The caller is to delete this array
386 * using decrRef() as it is no more needed.
387 * \return DataArrayInt * - a new instance of DataArrayInt holding values of the
388 * field. The caller is to delete this array using decrRef() as it is no more needed.
389 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
390 * \throw If no field of \a this is lying on \a mesh.
391 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
394 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
396 MCAuto<DataArray> arr(contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull()));
397 return ReturnSafelyTypedDataArray(arr);
401 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArray() const
403 return contentNotNull()->getUndergroundDataArrayTemplate();
407 typename Traits<T>::ArrayType *MEDFileTemplateField1TS<T>::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
409 return contentNotNull()->getUndergroundDataArrayTemplateExt(entries);
413 MCAuto<typename Traits<T>::FieldType> MEDFileTemplateField1TS<T>::SetDataArrayInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
416 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : input field is NULL !");
418 throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS<T>::SetDataArrayInField : no array !");
420 double t0(f->getTime(t1,t2));
421 std::string tu(f->getTimeUnit());
422 MCAuto<typename Traits<T>::ArrayType> arr2(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(arr));
423 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
424 MCAuto<typename Traits<T>::FieldType> ret(Traits<T>::FieldType::New(*ft));
425 ret->setTime(t0,t1,t2); ret->setArray(arr2); ret->setTimeUnit(tu);
430 MCAuto<MEDCouplingFieldDouble> MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(const typename Traits<T>::FieldType *f)
433 double t0(f->getTime(t1,t2));
434 std::string tu(f->getTimeUnit());
435 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*f));
436 MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
437 ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
442 * 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
443 * method should be called (getFieldOnMeshAtLevel for example).
444 * But for normal usage of field in MED file world this method is the most efficient to fetch data.
446 * \param [in] mesh - the mesh the field is lying on
447 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
448 * caller is to delete this field using decrRef() as it is no more needed.
451 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::field(const MEDFileMesh *mesh) const
453 MCAuto<DataArray> arrOut;
454 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
455 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
460 * Returns a new typename Traits<T>::FieldType of a given type lying on
461 * mesh entities of a given dimension of the first mesh in MED file. If \a this field
462 * has not been constructed via file reading, an exception is thrown.
463 * For more info, see \ref AdvMEDLoaderAPIFieldRW
464 * \param [in] type - a spatial discretization of interest.
465 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
466 * \param [in] renumPol - specifies how to permute values of the result field according to
467 * the optional numbers of cells and nodes, if any. The valid values are
468 * - 0 - do not permute.
469 * - 1 - permute cells.
470 * - 2 - permute nodes.
471 * - 3 - permute cells and nodes.
473 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
474 * caller is to delete this field using decrRef() as it is no more needed.
475 * \throw If \a this field has not been constructed via file reading.
476 * \throw If the MED file is not readable.
477 * \throw If there is no mesh in the MED file.
478 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
479 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
480 * \sa getFieldOnMeshAtLevel()
483 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
485 if(getFileName().empty())
486 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 !");
487 MCAuto<DataArray> arrOut;
488 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
489 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
494 * Returns a new typename Traits<T>::FieldType of a given type lying on
495 * the top level cells of the first mesh in MED file. If \a this field
496 * has not been constructed via file reading, an exception is thrown.
497 * For more info, see \ref AdvMEDLoaderAPIFieldRW
498 * \param [in] type - a spatial discretization of interest.
499 * \param [in] renumPol - specifies how to permute values of the result field according to
500 * the optional numbers of cells and nodes, if any. The valid values are
501 * - 0 - do not permute.
502 * - 1 - permute cells.
503 * - 2 - permute nodes.
504 * - 3 - permute cells and nodes.
506 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
507 * caller is to delete this field using decrRef() as it is no more needed.
508 * \throw If \a this field has not been constructed via file reading.
509 * \throw If the MED file is not readable.
510 * \throw If there is no mesh in the MED file.
511 * \throw If no field values of the given \a type.
512 * \throw If no field values lying on the top level support.
513 * \sa getFieldAtLevel()
516 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtTopLevel(TypeOfField type, int renumPol) const
518 if(getFileName().empty())
519 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 !");
520 MCAuto<DataArray> arrOut;
521 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
522 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
527 * Returns a new typename Traits<T>::FieldType of given type lying on a given mesh.
528 * For more info, see \ref AdvMEDLoaderAPIFieldRW
529 * \param [in] type - a spatial discretization of the new field.
530 * \param [in] mesh - the supporting mesh.
531 * \param [in] renumPol - specifies how to permute values of the result field according to
532 * the optional numbers of cells and nodes, if any. The valid values are
533 * - 0 - do not permute.
534 * - 1 - permute cells.
535 * - 2 - permute nodes.
536 * - 3 - permute cells and nodes.
538 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
539 * caller is to delete this field using decrRef() as it is no more needed.
540 * \throw If no field of \a this is lying on \a mesh.
541 * \throw If the mesh is empty.
542 * \throw If no field values of the given \a type are available.
543 * \sa getFieldAtLevel()
544 * \sa getFieldOnMeshAtLevel()
547 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
549 MCAuto<DataArray> arrOut;
550 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
551 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
556 * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
557 * For more info, see \ref AdvMEDLoaderAPIFieldRW
558 * \param [in] type - a spatial discretization of interest.
559 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
560 * \param [in] mesh - the supporting mesh.
561 * \param [in] renumPol - specifies how to permute values of the result field according to
562 * the optional numbers of cells and nodes, if any. The valid values are
563 * - 0 - do not permute.
564 * - 1 - permute cells.
565 * - 2 - permute nodes.
566 * - 3 - permute cells and nodes.
568 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
569 * caller is to delete this field using decrRef() as it is no more needed.
570 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
571 * \throw If no field of \a this is lying on \a mesh.
572 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
573 * \sa getFieldAtLevel()
574 * \sa getFieldOnMeshAtLevel()
577 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
579 MCAuto<DataArray> arrOut;
580 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
581 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
586 * Returns a new typename Traits<T>::FieldType of a given type lying on a given support.
587 * This method is called "Old" because in MED3 norm a field has only one meshName
588 * attached, so this method is for readers of MED2 files. If \a this field
589 * has not been constructed via file reading, an exception is thrown.
590 * For more info, see \ref AdvMEDLoaderAPIFieldRW
591 * \param [in] type - a spatial discretization of interest.
592 * \param [in] mName - a name of the supporting mesh.
593 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
594 * \param [in] renumPol - specifies how to permute values of the result field according to
595 * the optional numbers of cells and nodes, if any. The valid values are
596 * - 0 - do not permute.
597 * - 1 - permute cells.
598 * - 2 - permute nodes.
599 * - 3 - permute cells and nodes.
601 * \return typename Traits<T>::FieldType * - a new instance of typename Traits<T>::FieldType. The
602 * caller is to delete this field using decrRef() as it is no more needed.
603 * \throw If the MED file is not readable.
604 * \throw If there is no mesh named \a mName in the MED file.
605 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
606 * \throw If \a this field has not been constructed via file reading.
607 * \throw If no field of \a this is lying on the mesh named \a mName.
608 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
609 * \sa getFieldAtLevel()
612 typename Traits<T>::FieldType *MEDFileTemplateField1TS<T>::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
614 if(getFileName().empty())
615 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 !");
616 MCAuto<DataArray> arrOut;
617 MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
618 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
623 * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
624 * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
625 * "Sort By Type"), if not, an exception is thrown.
626 * For more info, see \ref AdvMEDLoaderAPIFieldRW
627 * \param [in] field - the field to add to \a this.
628 * \throw If the name of \a field is empty.
629 * \throw If the data array of \a field is not set.
630 * \throw If the data array is already allocated but has different number of components
632 * \throw If the underlying mesh of \a field has no name.
633 * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
636 void MEDFileTemplateField1TS<T>::setFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
639 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
640 contentNotNull()->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,field->getArray(),*this,*contentNotNull());
644 * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
645 * can be an aggregation of several MEDCouplingFieldDouble instances.
646 * The mesh support of input parameter \a field is ignored here, it can be NULL.
647 * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
650 * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
651 * A new profile is added only if no equal profile is missing.
652 * For more info, see \ref AdvMEDLoaderAPIFieldRW
653 * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
654 * \param [in] mesh - the supporting mesh of \a field.
655 * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
656 * \param [in] profile - ids of mesh entities on which corresponding field values lie.
657 * \throw If either \a field or \a mesh or \a profile has an empty name.
658 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
659 * \throw If the data array of \a field is not set.
660 * \throw If the data array of \a this is already allocated but has different number of
661 * components than \a field.
662 * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
663 * \sa setFieldNoProfileSBT()
666 void MEDFileTemplateField1TS<T>::setFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
669 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
670 contentNotNull()->setFieldProfile(field->timeDiscrSafe(),ft,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
674 * Return an extraction of \a this using \a extractDef map to specify the extraction.
675 * The keys of \a extractDef is level relative to max ext of \a mm mesh.
677 * \return A new object that the caller is responsible to deallocate.
678 * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
681 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
684 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
685 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New());
686 std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
687 for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
691 std::vector<int> levs;
692 getNonEmptyLevels(mm->getName(),levs);
693 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
695 std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
696 if(it2!=extractDef.end())
698 MCAuto<DataArrayInt> t((*it2).second);
700 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
701 MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
702 MCAuto<typename Traits<T>::FieldType> fOut(f->buildSubPart(t));
703 ret->setFieldNoProfileSBT(fOut);
709 std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
710 if(it2==extractDef.end())
711 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
712 MCAuto<DataArrayInt> t((*it2).second);
714 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
715 MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
716 MCAuto<typename Traits<T>::FieldType> fOut(f->deepCopy());
717 typename Traits<T>::ArrayType *arr(f->getArray());
718 MCAuto<typename Traits<T>::ArrayType> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
719 fOut->setArray(newArr);
720 ret->setFieldNoProfileSBT(fOut);
726 //////////////////////////
729 * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
730 * following the given input policy.
732 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
733 * By default (true) the globals are deeply copied.
734 * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
737 MEDFileField1TS *MEDFileNDTemplateField1TS<T>::convertToDouble(bool isDeepCpyGlobs) const
739 MCAuto<MEDFileField1TS> ret;
740 const MEDFileAnyTypeField1TSWithoutSDA *content(this->_content);
743 const typename MLFieldTraits<T>::F1TSWSDAType *contc(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(content));
746 std::ostringstream oss; oss << "MEDFileNDTemplateField1TS<T>::convertToDouble : the content inside this is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " ! This is incoherent !";
747 throw INTERP_KERNEL::Exception(oss.str());
749 MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
750 ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
753 ret=MEDFileField1TS::New();
755 ret->deepCpyGlobs(*this);
757 ret->shallowCpyGlobs(*this);
761 //////////////////////////
764 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)
766 return new typename MLFieldTraits<T>::FMTSWSDAType(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
770 void MEDFileTemplateFieldMultiTSWithoutSDA<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
773 throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
774 const typename MLFieldTraits<T>::F1TSWSDAType *f1tsC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(f1ts));
777 std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
778 throw INTERP_KERNEL::Exception(oss.str());
783 const char *MEDFileTemplateFieldMultiTSWithoutSDA<T>::getTypeStr() const
785 return MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
789 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew() const
791 return new typename MLFieldTraits<T>::FMTSWSDAType;
795 MEDFileAnyTypeField1TSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew1TSWithoutSDAEmptyInstance() const
797 return new typename MLFieldTraits<T>::F1TSWSDAType;
800 //////////////////////////
803 MEDFileFieldMultiTSWithoutSDA *MEDFileNDTemplateFieldMultiTSWithoutSDA<T>::convertToDouble() const
805 MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
806 ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
808 for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=this->_time_steps.begin();it!=this->_time_steps.end();it++,i++)
810 const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
813 const typename MLFieldTraits<T>::F1TSWSDAType *eltToConvC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(eltToConv));
815 throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
816 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt(eltToConvC->convertToDouble());
817 ret->setIteration(i,elt);
823 //////////////////////////
826 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS()
828 _content=new typename MLFieldTraits<T>::FMTSWSDAType;
832 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
837 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
842 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
847 * Return an extraction of \a this using \a extractDef map to specify the extraction.
848 * The keys of \a extractDef is level relative to max ext of \a mm mesh.
850 * \return A new object that the caller is responsible to deallocate.
853 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
856 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::extractPart : mesh is null !");
857 MCAuto<typename MLFieldTraits<T>::FMTSType> fmtsOut(MLFieldTraits<T>::FMTSType::New());
858 int nbTS(getNumberOfTS());
859 for(int i=0;i<nbTS;i++)
861 MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
862 MCAuto<typename MLFieldTraits<T>::F1TSType> f1ts2(DynamicCastSafe<MEDFileAnyTypeField1TS,typename MLFieldTraits<T>::F1TSType>(f1ts));
863 MCAuto<typename MLFieldTraits<T>::F1TSType> f1tsOut(f1ts2->extractPartImpl(extractDef,mm));
864 fmtsOut->pushBackTimeStep(f1tsOut);
866 return fmtsOut.retn();
870 * Returns a new empty instance of MEDFileFieldMultiTS.
871 * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
872 * is to delete this field using decrRef() as it is no more needed.
875 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New()
877 return new typename MLFieldTraits<T>::FMTSType;
881 * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding data of the first field
882 * that has been read from a specified MED file.
883 * \param [in] fileName - the name of the MED file to read.
884 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
885 * is to delete this field using decrRef() as it is no more needed.
886 * \throw If reading the file fails.
889 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, bool loadAll)
891 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
892 return New(fid,loadAll);
896 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, bool loadAll)
898 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,loadAll,0));
899 ret->contentNotNull();//to check that content type matches with \a this type.
904 * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
905 * that has been read from a specified MED file.
906 * \param [in] fileName - the name of the MED file to read.
907 * \param [in] fieldName - the name of the field to read.
908 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
909 * is to delete this field using decrRef() as it is no more needed.
910 * \throw If reading the file fails.
911 * \throw If there is no field named \a fieldName in the file.
914 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
916 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
917 return New(fid,fieldName,loadAll);
921 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
923 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0));
924 ret->contentNotNull();//to check that content type matches with \a this type.
929 * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
930 * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
932 * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding either a shallow copy
933 * of a given MEDFileTemplateFieldMultiTS<T>WithoutSDA ( \a other ) or \a other itself.
934 * \warning this is a shallow copy constructor
935 * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
936 * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
937 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
938 * is to delete this field using decrRef() as it is no more needed.
941 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent)
943 return new typename MLFieldTraits<T>::FMTSType(other,shallowCopyOfContent);
947 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)
949 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
950 INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
951 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0,ent));
952 ret->contentNotNull();//to check that content type matches with \a this type.
957 * 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
958 * method should be called (getFieldOnMeshAtLevel for example).
959 * But for normal usage of field in MED file world this method is the most efficient to fetch data.
961 * \param [in] iteration - the iteration number of a required time step.
962 * \param [in] order - the iteration order number of required time step.
963 * \param [in] mesh - the mesh the field is lying on
964 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
965 * caller is to delete this field using decrRef() as it is no more needed.
968 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::field(int iteration, int order, const MEDFileMesh *mesh) const
970 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
971 MCAuto<DataArray> arrOut;
972 MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
973 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
978 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
979 * mesh entities of a given dimension of the first mesh in MED file.
980 * For more info, see \ref AdvMEDLoaderAPIFieldRW
981 * \param [in] type - a spatial discretization of interest.
982 * \param [in] iteration - the iteration number of a required time step.
983 * \param [in] order - the iteration order number of required time step.
984 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
985 * \param [in] renumPol - specifies how to permute values of the result field according to
986 * the optional numbers of cells and nodes, if any. The valid values are
987 * - 0 - do not permute.
988 * - 1 - permute cells.
989 * - 2 - permute nodes.
990 * - 3 - permute cells and nodes.
992 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
993 * caller is to delete this field using decrRef() as it is no more needed.
994 * \throw If the MED file is not readable.
995 * \throw If there is no mesh in the MED file.
996 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
997 * \throw If no field values of the required parameters are available.
1000 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
1002 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1003 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1005 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
1006 MCAuto<DataArray> arrOut;
1007 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1008 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1013 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1014 * the top level cells of the first mesh in MED file.
1015 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1016 * \param [in] type - a spatial discretization of interest.
1017 * \param [in] iteration - the iteration number of a required time step.
1018 * \param [in] order - the iteration order number of required time step.
1019 * \param [in] renumPol - specifies how to permute values of the result field according to
1020 * the optional numbers of cells and nodes, if any. The valid values are
1021 * - 0 - do not permute.
1022 * - 1 - permute cells.
1023 * - 2 - permute nodes.
1024 * - 3 - permute cells and nodes.
1026 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1027 * caller is to delete this field using decrRef() as it is no more needed.
1028 * \throw If the MED file is not readable.
1029 * \throw If there is no mesh in the MED file.
1030 * \throw If no field values of the required parameters are available.
1033 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
1035 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1036 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1038 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel : mismatch of type of field !");
1039 MCAuto<DataArray> arrOut;
1040 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1041 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1046 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1048 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1049 * \param [in] type - a spatial discretization of interest.
1050 * \param [in] iteration - the iteration number of a required time step.
1051 * \param [in] order - the iteration order number of required time step.
1052 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1053 * \param [in] mesh - the supporting mesh.
1054 * \param [in] renumPol - specifies how to permute values of the result field according to
1055 * the optional numbers of cells and nodes, if any. The valid values are
1056 * - 0 - do not permute.
1057 * - 1 - permute cells.
1058 * - 2 - permute nodes.
1059 * - 3 - permute cells and nodes.
1061 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1062 * caller is to delete this field using decrRef() as it is no more needed.
1063 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1064 * \throw If no field of \a this is lying on \a mesh.
1065 * \throw If no field values of the required parameters are available.
1068 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
1070 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1071 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1073 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1074 MCAuto<DataArray> arrOut;
1075 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase()));
1076 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1081 * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
1083 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1084 * \param [in] type - a spatial discretization of the new field.
1085 * \param [in] iteration - the iteration number of a required time step.
1086 * \param [in] order - the iteration order number of required time step.
1087 * \param [in] mesh - the supporting mesh.
1088 * \param [in] renumPol - specifies how to permute values of the result field according to
1089 * the optional numbers of cells and nodes, if any. The valid values are
1090 * - 0 - do not permute.
1091 * - 1 - permute cells.
1092 * - 2 - permute nodes.
1093 * - 3 - permute cells and nodes.
1095 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1096 * caller is to delete this field using decrRef() as it is no more needed.
1097 * \throw If no field of \a this is lying on \a mesh.
1098 * \throw If no field values of the required parameters are available.
1101 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
1103 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1104 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1106 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1107 MCAuto<DataArray> arrOut;
1108 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase()));
1109 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1114 * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
1115 * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
1116 * This method is useful for MED2 file format when field on different mesh was autorized.
1119 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
1121 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1122 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1124 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld : mismatch of type of field !");
1125 MCAuto<DataArray> arrOut;
1126 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase()));
1127 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1132 * Returns values and a profile of the field of a given type, of a given time step,
1133 * lying on a given support.
1134 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1135 * \param [in] type - a spatial discretization of the field.
1136 * \param [in] iteration - the iteration number of a required time step.
1137 * \param [in] order - the iteration order number of required time step.
1138 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1139 * \param [in] mesh - the supporting mesh.
1140 * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
1141 * field of interest lies on. If the field lies on all entities of the given
1142 * dimension, all ids in \a pfl are zero. The caller is to delete this array
1143 * using decrRef() as it is no more needed.
1144 * \param [in] glob - the global data storing profiles and localization.
1145 * \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
1146 * field. The caller is to delete this array using decrRef() as it is no more needed.
1147 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1148 * \throw If no field of \a this is lying on \a mesh.
1149 * \throw If no field values of the required parameters are available.
1152 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
1154 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1155 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1157 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile : mismatch of type of field !");
1158 MCAuto<DataArray> ret(myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase()));
1159 return MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(ret);
1163 * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
1164 * the given field is checked if its elements are sorted suitable for writing to MED file
1165 * ("STB" stands for "Sort By Type"), if not, an exception is thrown.
1166 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1167 * \param [in] field - the field to add to \a this.
1168 * \throw If the name of \a field is empty.
1169 * \throw If the data array of \a field is not set.
1170 * \throw If existing time steps have different name or number of components than \a field.
1171 * \throw If the underlying mesh of \a field has no name.
1172 * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
1175 void MEDFileTemplateFieldMultiTS<T>::appendFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
1177 const typename Traits<T>::ArrayType *arr(NULL);
1179 arr=field->getArray();
1180 MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1181 contentNotNull()->appendFieldNoProfileSBT(field2,arr,*this);
1185 * Adds a MEDCouplingFieldDouble to \a this as another time step.
1186 * The mesh support of input parameter \a field is ignored here, it can be NULL.
1187 * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
1190 * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
1191 * A new profile is added only if no equal profile is missing.
1192 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1193 * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
1194 * \param [in] mesh - the supporting mesh of \a field.
1195 * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
1196 * \param [in] profile - ids of mesh entities on which corresponding field values lie.
1197 * \throw If either \a field or \a mesh or \a profile has an empty name.
1198 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1199 * \throw If the data array of \a field is not set.
1200 * \throw If the data array of \a this is already allocated but has different number of
1201 * components than \a field.
1202 * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
1203 * \sa setFieldNoProfileSBT()
1206 void MEDFileTemplateFieldMultiTS<T>::appendFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
1208 const typename Traits<T>::ArrayType *arr(NULL);
1210 arr=field->getArray();
1211 MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1212 contentNotNull()->appendFieldProfile(field2,arr,mesh,meshDimRelToMax,profile,*this);
1216 const typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull() const
1218 const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1220 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is null !");
1221 const typename MLFieldTraits<T>::FMTSWSDAType *ret=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(pt);
1223 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 !");
1228 typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull()
1230 MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1232 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is null !");
1233 typename MLFieldTraits<T>::FMTSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::FMTSWSDAType *>(pt));
1235 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 !");
1240 * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
1241 * \param [in] pos - a time step id.
1242 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
1243 * delete this field using decrRef() as it is no more needed.
1244 * \throw If \a pos is not a valid time step id.
1247 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateFieldMultiTS<T>::getTimeStepAtPos(int pos) const
1249 const MEDFileAnyTypeField1TSWithoutSDA *item(contentNotNullBase()->getTimeStepAtPos2(pos));
1252 std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
1253 throw INTERP_KERNEL::Exception(oss.str());
1255 const typename MLFieldTraits<T>::F1TSWSDAType *itemC=dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(item);
1258 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New(*itemC,false));
1259 ret->shallowCpyGlobs(*this);
1262 std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " !";
1263 throw INTERP_KERNEL::Exception(oss.str());
1267 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray(int iteration, int order) const
1269 DataArray *ret(contentNotNull()->getUndergroundDataArray(iteration,order));
1272 typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1275 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray : invalid type of data dectected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1276 throw INTERP_KERNEL::Exception(oss.str());
1282 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1284 DataArray *ret(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
1287 typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1290 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt : invalid type of data dectected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1291 throw INTERP_KERNEL::Exception(oss.str());
1297 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::buildNewEmptyImpl() const
1299 return MLFieldTraits<T>::FMTSType::New();
1303 void MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
1306 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
1307 const typename MLFieldTraits<T>::F1TSType *f1tsC=dynamic_cast<const typename MLFieldTraits<T>::F1TSType *>(f1ts);
1310 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
1311 throw INTERP_KERNEL::Exception(oss.str());
1315 //////////////////////////
1318 * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
1319 * following the given input policy.
1321 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
1322 * By default (true) the globals are deeply copied.
1323 * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
1326 MEDFileFieldMultiTS *MEDFileNDTemplateFieldMultiTS<T>::convertToDouble(bool isDeepCpyGlobs) const
1328 MCAuto<MEDFileFieldMultiTS> ret;
1329 const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(this->_content);
1332 const typename MLFieldTraits<T>::FMTSWSDAType *contc=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(content);
1334 throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
1335 MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
1336 ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
1339 ret=MEDFileFieldMultiTS::New();
1341 ret->deepCpyGlobs(*this);
1343 ret->shallowCpyGlobs(*this);