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;
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, DataArrayInt *&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<int,int> > >& 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()
688 void MEDFileTemplateField1TS<T>::setFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
691 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
692 contentNotNull()->setFieldProfile(field->timeDiscrSafe(),ft,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
696 * Return an extraction of \a this using \a extractDef map to specify the extraction.
697 * The keys of \a extractDef is level relative to max ext of \a mm mesh.
699 * \return A new object that the caller is responsible to deallocate.
700 * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
703 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateField1TS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
706 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
707 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New());
708 std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
709 for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
713 std::vector<int> levs;
714 getNonEmptyLevels(mm->getName(),levs);
715 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
717 std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
718 if(it2!=extractDef.end())
720 MCAuto<DataArrayInt> t((*it2).second);
722 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
723 MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
724 MCAuto<typename Traits<T>::FieldType> fOut(f->buildSubPart(t));
725 ret->setFieldNoProfileSBT(fOut);
731 std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
732 if(it2==extractDef.end())
733 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
734 MCAuto<DataArrayInt> t((*it2).second);
736 throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
737 MCAuto<typename Traits<T>::FieldType> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
738 MCAuto<typename Traits<T>::FieldType> fOut(f->deepCopy());
739 typename Traits<T>::ArrayType *arr(f->getArray());
740 MCAuto<typename Traits<T>::ArrayType> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
741 fOut->setArray(newArr);
742 ret->setFieldNoProfileSBT(fOut);
748 //////////////////////////
751 * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
752 * following the given input policy.
754 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
755 * By default (true) the globals are deeply copied.
756 * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
759 MEDFileField1TS *MEDFileNDTemplateField1TS<T>::convertToDouble(bool isDeepCpyGlobs) const
761 MCAuto<MEDFileField1TS> ret;
762 const MEDFileAnyTypeField1TSWithoutSDA *content(this->_content);
765 const typename MLFieldTraits<T>::F1TSWSDAType *contc(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(content));
768 std::ostringstream oss; oss << "MEDFileNDTemplateField1TS<T>::convertToDouble : the content inside this is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " ! This is incoherent !";
769 throw INTERP_KERNEL::Exception(oss.str());
771 MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
772 ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
775 ret=MEDFileField1TS::New();
777 ret->deepCpyGlobs(*this);
779 ret->shallowCpyGlobs(*this);
783 //////////////////////////
786 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)
788 return new typename MLFieldTraits<T>::FMTSWSDAType(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
792 void MEDFileTemplateFieldMultiTSWithoutSDA<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
795 throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
796 const typename MLFieldTraits<T>::F1TSWSDAType *f1tsC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(f1ts));
799 std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
800 throw INTERP_KERNEL::Exception(oss.str());
805 const char *MEDFileTemplateFieldMultiTSWithoutSDA<T>::getTypeStr() const
807 return MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
811 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew() const
813 return new typename MLFieldTraits<T>::FMTSWSDAType;
817 MEDFileAnyTypeField1TSWithoutSDA *MEDFileTemplateFieldMultiTSWithoutSDA<T>::createNew1TSWithoutSDAEmptyInstance() const
819 return new typename MLFieldTraits<T>::F1TSWSDAType;
822 //////////////////////////
825 MEDFileFieldMultiTSWithoutSDA *MEDFileNDTemplateFieldMultiTSWithoutSDA<T>::convertToDouble() const
827 MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
828 ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
830 for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=this->_time_steps.begin();it!=this->_time_steps.end();it++,i++)
832 const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
835 const typename MLFieldTraits<T>::F1TSWSDAType *eltToConvC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(eltToConv));
837 throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
838 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt(eltToConvC->convertToDouble());
839 ret->setIteration(i,elt);
845 //////////////////////////
848 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS()
850 _content=new typename MLFieldTraits<T>::FMTSWSDAType;
854 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
859 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
864 MEDFileTemplateFieldMultiTS<T>::MEDFileTemplateFieldMultiTS(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
869 * Return an extraction of \a this using \a extractDef map to specify the extraction.
870 * The keys of \a extractDef is level relative to max ext of \a mm mesh.
872 * \return A new object that the caller is responsible to deallocate.
875 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::extractPartImpl(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
878 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::extractPart : mesh is null !");
879 MCAuto<typename MLFieldTraits<T>::FMTSType> fmtsOut(MLFieldTraits<T>::FMTSType::New());
880 int nbTS(getNumberOfTS());
881 for(int i=0;i<nbTS;i++)
883 MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
884 MCAuto<typename MLFieldTraits<T>::F1TSType> f1ts2(DynamicCastSafe<MEDFileAnyTypeField1TS,typename MLFieldTraits<T>::F1TSType>(f1ts));
885 MCAuto<typename MLFieldTraits<T>::F1TSType> f1tsOut(f1ts2->extractPartImpl(extractDef,mm));
886 fmtsOut->pushBackTimeStep(f1tsOut);
888 return fmtsOut.retn();
892 * Returns a new empty instance of MEDFileFieldMultiTS.
893 * \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
894 * is to delete this field using decrRef() as it is no more needed.
897 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New()
899 return new typename MLFieldTraits<T>::FMTSType;
903 * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding data of the first field
904 * that has been read from a specified MED file.
905 * \param [in] fileName - the name of the MED file to read.
906 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
907 * is to delete this field using decrRef() as it is no more needed.
908 * \throw If reading the file fails.
911 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, bool loadAll)
913 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
914 return New(fid,loadAll);
918 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, bool loadAll)
920 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,loadAll,0));
921 ret->contentNotNull();//to check that content type matches with \a this type.
926 * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
927 * that has been read from a specified MED file.
928 * \param [in] fileName - the name of the MED file to read.
929 * \param [in] fieldName - the name of the field to read.
930 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
931 * is to delete this field using decrRef() as it is no more needed.
932 * \throw If reading the file fails.
933 * \throw If there is no field named \a fieldName in the file.
936 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
938 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
939 return New(fid,fieldName,loadAll);
943 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(med_idt fid, const std::string& fieldName, bool loadAll)
945 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0));
946 ret->contentNotNull();//to check that content type matches with \a this type.
951 * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
952 * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
954 * Returns a new instance of MEDFileTemplateFieldMultiTS<T> holding either a shallow copy
955 * of a given MEDFileTemplateFieldMultiTS<T>WithoutSDA ( \a other ) or \a other itself.
956 * \warning this is a shallow copy constructor
957 * \param [in] other - a MEDFileField1TSWithoutSDA to copy.
958 * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
959 * \return MEDFileTemplateFieldMultiTS<T> * - a new instance of MEDFileTemplateFieldMultiTS<T>. The caller
960 * is to delete this field using decrRef() as it is no more needed.
963 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::New(const typename MLFieldTraits<T>::FMTSWSDAType& other, bool shallowCopyOfContent)
965 return new typename MLFieldTraits<T>::FMTSType(other,shallowCopyOfContent);
969 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)
971 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
972 INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
973 MCAuto<typename MLFieldTraits<T>::FMTSType> ret(new typename MLFieldTraits<T>::FMTSType(fid,fieldName,loadAll,0,ent));
974 ret->contentNotNull();//to check that content type matches with \a this type.
979 * 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
980 * method should be called (getFieldOnMeshAtLevel for example).
981 * But for normal usage of field in MED file world this method is the most efficient to fetch data.
983 * \param [in] iteration - the iteration number of a required time step.
984 * \param [in] order - the iteration order number of required time step.
985 * \param [in] mesh - the mesh the field is lying on
986 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
987 * caller is to delete this field using decrRef() as it is no more needed.
990 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::field(int iteration, int order, const MEDFileMesh *mesh) const
992 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
993 MCAuto<DataArray> arrOut;
994 MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
995 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1000 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1001 * mesh entities of a given dimension of the first mesh in MED file.
1002 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1003 * \param [in] type - a spatial discretization of interest.
1004 * \param [in] iteration - the iteration number of a required time step.
1005 * \param [in] order - the iteration order number of required time step.
1006 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1007 * \param [in] renumPol - specifies how to permute values of the result field according to
1008 * the optional numbers of cells and nodes, if any. The valid values are
1009 * - 0 - do not permute.
1010 * - 1 - permute cells.
1011 * - 2 - permute nodes.
1012 * - 3 - permute cells and nodes.
1014 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1015 * caller is to delete this field using decrRef() as it is no more needed.
1016 * \throw If the MED file is not readable.
1017 * \throw If there is no mesh in the MED file.
1018 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1019 * \throw If no field values of the required parameters are available.
1022 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
1024 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1025 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1027 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
1028 MCAuto<DataArray> arrOut;
1029 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1030 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1035 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1036 * the top level cells of the first mesh in MED file.
1037 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1038 * \param [in] type - a spatial discretization of interest.
1039 * \param [in] iteration - the iteration number of a required time step.
1040 * \param [in] order - the iteration order number of required time step.
1041 * \param [in] renumPol - specifies how to permute values of the result field according to
1042 * the optional numbers of cells and nodes, if any. The valid values are
1043 * - 0 - do not permute.
1044 * - 1 - permute cells.
1045 * - 2 - permute nodes.
1046 * - 3 - permute cells and nodes.
1048 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1049 * caller is to delete this field using decrRef() as it is no more needed.
1050 * \throw If the MED file is not readable.
1051 * \throw If there is no mesh in the MED file.
1052 * \throw If no field values of the required parameters are available.
1055 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
1057 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1058 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1060 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtTopLevel : mismatch of type of field !");
1061 MCAuto<DataArray> arrOut;
1062 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase()));
1063 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1068 * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
1070 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1071 * \param [in] type - a spatial discretization of interest.
1072 * \param [in] iteration - the iteration number of a required time step.
1073 * \param [in] order - the iteration order number of required time step.
1074 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1075 * \param [in] mesh - the supporting mesh.
1076 * \param [in] renumPol - specifies how to permute values of the result field according to
1077 * the optional numbers of cells and nodes, if any. The valid values are
1078 * - 0 - do not permute.
1079 * - 1 - permute cells.
1080 * - 2 - permute nodes.
1081 * - 3 - permute cells and nodes.
1083 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1084 * caller is to delete this field using decrRef() as it is no more needed.
1085 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1086 * \throw If no field of \a this is lying on \a mesh.
1087 * \throw If no field values of the required parameters are available.
1090 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
1092 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1093 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1095 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1096 MCAuto<DataArray> arrOut;
1097 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase()));
1098 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1103 * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
1105 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1106 * \param [in] type - a spatial discretization of the new field.
1107 * \param [in] iteration - the iteration number of a required time step.
1108 * \param [in] order - the iteration order number of required time step.
1109 * \param [in] mesh - the supporting mesh.
1110 * \param [in] renumPol - specifies how to permute values of the result field according to
1111 * the optional numbers of cells and nodes, if any. The valid values are
1112 * - 0 - do not permute.
1113 * - 1 - permute cells.
1114 * - 2 - permute nodes.
1115 * - 3 - permute cells and nodes.
1117 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1118 * caller is to delete this field using decrRef() as it is no more needed.
1119 * \throw If no field of \a this is lying on \a mesh.
1120 * \throw If no field values of the required parameters are available.
1123 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
1125 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1126 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1128 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldOnMeshAtLevel : mismatch of type of field !");
1129 MCAuto<DataArray> arrOut;
1130 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase()));
1131 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1136 * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
1137 * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
1138 * This method is useful for MED2 file format when field on different mesh was autorized.
1141 typename Traits<T>::FieldType *MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
1143 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1144 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1146 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldAtLevelOld : mismatch of type of field !");
1147 MCAuto<DataArray> arrOut;
1148 MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase()));
1149 MCAuto<typename Traits<T>::FieldType> ret2(MEDFileTemplateField1TS<T>::SetDataArrayInField(ret,arrOut));
1154 * Returns values and a profile of the field of a given type, of a given time step,
1155 * lying on a given support.
1156 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1157 * \param [in] type - a spatial discretization of the field.
1158 * \param [in] iteration - the iteration number of a required time step.
1159 * \param [in] order - the iteration order number of required time step.
1160 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1161 * \param [in] mesh - the supporting mesh.
1162 * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
1163 * field of interest lies on. If the field lies on all entities of the given
1164 * dimension, all ids in \a pfl are zero. The caller is to delete this array
1165 * using decrRef() as it is no more needed.
1166 * \param [in] glob - the global data storing profiles and localization.
1167 * \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
1168 * field. The caller is to delete this array using decrRef() as it is no more needed.
1169 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1170 * \throw If no field of \a this is lying on \a mesh.
1171 * \throw If no field values of the required parameters are available.
1174 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
1176 const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
1177 const typename MLFieldTraits<T>::F1TSWSDAType *myF1TSC(dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(&myF1TS));
1179 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::getFieldWithProfile : mismatch of type of field !");
1180 MCAuto<DataArray> ret(myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase()));
1181 return MEDFileTemplateField1TS<T>::ReturnSafelyTypedDataArray(ret);
1185 * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
1186 * the given field is checked if its elements are sorted suitable for writing to MED file
1187 * ("STB" stands for "Sort By Type"), if not, an exception is thrown.
1188 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1189 * \param [in] field - the field to add to \a this.
1190 * \throw If the name of \a field is empty.
1191 * \throw If the data array of \a field is not set.
1192 * \throw If existing time steps have different name or number of components than \a field.
1193 * \throw If the underlying mesh of \a field has no name.
1194 * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
1197 void MEDFileTemplateFieldMultiTS<T>::appendFieldNoProfileSBT(const typename Traits<T>::FieldType *field)
1199 const typename Traits<T>::ArrayType *arr(NULL);
1201 arr=field->getArray();
1202 MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1203 contentNotNull()->appendFieldNoProfileSBT(field2,arr,*this);
1207 * Adds a MEDCouplingFieldDouble to \a this as another time step.
1208 * The mesh support of input parameter \a field is ignored here, it can be NULL.
1209 * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
1212 * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
1213 * A new profile is added only if no equal profile is missing.
1214 * For more info, see \ref AdvMEDLoaderAPIFieldRW
1215 * \param [in] field - the field to add to \a this. The mesh support of field is ignored.
1216 * \param [in] mesh - the supporting mesh of \a field.
1217 * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
1218 * \param [in] profile - ids of mesh entities on which corresponding field values lie.
1219 * \throw If either \a field or \a mesh or \a profile has an empty name.
1220 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1221 * \throw If the data array of \a field is not set.
1222 * \throw If the data array of \a this is already allocated but has different number of
1223 * components than \a field.
1224 * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
1225 * \sa setFieldNoProfileSBT()
1228 void MEDFileTemplateFieldMultiTS<T>::appendFieldProfile(const typename Traits<T>::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
1230 const typename Traits<T>::ArrayType *arr(NULL);
1232 arr=field->getArray();
1233 MCAuto<MEDCouplingFieldDouble> field2(MEDFileTemplateField1TS<T>::ToFieldTemplateWithTime(field));
1234 contentNotNull()->appendFieldProfile(field2,arr,mesh,meshDimRelToMax,profile,*this);
1238 const typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull() const
1240 const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1242 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the content pointer is null !");
1243 const typename MLFieldTraits<T>::FMTSWSDAType *ret=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(pt);
1245 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 !");
1250 typename MLFieldTraits<T>::FMTSWSDAType *MEDFileTemplateFieldMultiTS<T>::contentNotNull()
1252 MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
1254 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::contentNotNull : the non const content pointer is null !");
1255 typename MLFieldTraits<T>::FMTSWSDAType *ret(dynamic_cast<typename MLFieldTraits<T>::FMTSWSDAType *>(pt));
1257 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 !");
1262 * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
1263 * \param [in] pos - a time step id.
1264 * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
1265 * delete this field using decrRef() as it is no more needed.
1266 * \throw If \a pos is not a valid time step id.
1269 typename MLFieldTraits<T>::F1TSType *MEDFileTemplateFieldMultiTS<T>::getTimeStepAtPos(int pos) const
1271 const MEDFileAnyTypeField1TSWithoutSDA *item(contentNotNullBase()->getTimeStepAtPos2(pos));
1274 std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
1275 throw INTERP_KERNEL::Exception(oss.str());
1277 const typename MLFieldTraits<T>::F1TSWSDAType *itemC=dynamic_cast<const typename MLFieldTraits<T>::F1TSWSDAType *>(item);
1280 MCAuto<typename MLFieldTraits<T>::F1TSType> ret(MLFieldTraits<T>::F1TSType::New(*itemC,false));
1281 ret->shallowCpyGlobs(*this);
1284 std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " !";
1285 throw INTERP_KERNEL::Exception(oss.str());
1289 typename Traits<T>::ArrayType *MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray(int iteration, int order) const
1291 DataArray *ret(contentNotNull()->getUndergroundDataArray(iteration,order));
1294 typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1297 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArray : invalid type of data dectected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1298 throw INTERP_KERNEL::Exception(oss.str());
1304 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
1306 DataArray *ret(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
1309 typename Traits<T>::ArrayType *ret2(dynamic_cast<typename Traits<T>::ArrayType *>(ret));
1312 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::getUndergroundDataArrayExt : invalid type of data dectected ! Expecting " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR;
1313 throw INTERP_KERNEL::Exception(oss.str());
1319 typename MLFieldTraits<T>::FMTSType *MEDFileTemplateFieldMultiTS<T>::buildNewEmptyImpl() const
1321 return MLFieldTraits<T>::FMTSType::New();
1325 void MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
1328 throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
1329 const typename MLFieldTraits<T>::F1TSType *f1tsC=dynamic_cast<const typename MLFieldTraits<T>::F1TSType *>(f1ts);
1332 std::ostringstream oss; oss << "MEDFileTemplateFieldMultiTS<T>::checkCoherencyOfType : the input field1TS is not a " << MLFieldTraits<T>::F1TSWSDAType::TYPE_STR << " type !";
1333 throw INTERP_KERNEL::Exception(oss.str());
1337 //////////////////////////
1340 * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
1341 * following the given input policy.
1343 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
1344 * By default (true) the globals are deeply copied.
1345 * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
1348 MEDFileFieldMultiTS *MEDFileNDTemplateFieldMultiTS<T>::convertToDouble(bool isDeepCpyGlobs) const
1350 MCAuto<MEDFileFieldMultiTS> ret;
1351 const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(this->_content);
1354 const typename MLFieldTraits<T>::FMTSWSDAType *contc=dynamic_cast<const typename MLFieldTraits<T>::FMTSWSDAType *>(content);
1356 throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
1357 MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
1358 ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
1361 ret=MEDFileFieldMultiTS::New();
1363 ret->deepCpyGlobs(*this);
1365 ret->shallowCpyGlobs(*this);