1 // Copyright (C) 2017-2023 CEA, EDF
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 #include "MEDFileField1TS.hxx"
22 #include "MEDFileFieldVisitor.hxx"
23 #include "MEDFileSafeCaller.txx"
24 #include "MEDLoaderBase.hxx"
25 #include "MEDFileField.txx"
27 #include "MEDCouplingFieldTemplate.hxx"
28 #include "MEDCouplingFieldDouble.hxx"
30 using namespace MEDCoupling;
32 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
34 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<Int32>;
35 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<Int64>;
36 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<float>;
37 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<double>;
38 template class MEDCoupling::MEDFileField1TSNDTemplateWithoutSDA<Int32>;
39 template class MEDCoupling::MEDFileField1TSNDTemplateWithoutSDA<Int64>;
40 template class MEDCoupling::MEDFileField1TSNDTemplateWithoutSDA<float>;
41 template class MEDCoupling::MEDFileTemplateField1TS<Int32>;
42 template class MEDCoupling::MEDFileTemplateField1TS<Int64>;
43 template class MEDCoupling::MEDFileTemplateField1TS<float>;
44 template class MEDCoupling::MEDFileTemplateField1TS<double>;
45 template class MEDCoupling::MEDFileNDTemplateField1TS<Int32>;
46 template class MEDCoupling::MEDFileNDTemplateField1TS<Int64>;
47 template class MEDCoupling::MEDFileNDTemplateField1TS<float>;
49 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
50 const char MEDFileInt32Field1TSWithoutSDA::TYPE_STR[]="INT32";
51 const char MEDFileInt64Field1TSWithoutSDA::TYPE_STR[]="INT64";
52 const char MEDFileFloatField1TSWithoutSDA::TYPE_STR[]="FLOAT32";
54 //= MEDFileAnyTypeField1TSWithoutSDA
56 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
58 _field_per_mesh.resize(other._field_per_mesh.size());
60 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
62 if((const MEDFileFieldPerMesh *)*it)
63 _field_per_mesh[i]=(*it)->deepCopy(this);
67 void MEDFileAnyTypeField1TSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
69 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
72 visitor.newMeshEntry(*it);
73 (*it)->accept(visitor);
74 visitor.endMeshEntry(*it);
79 * Prints a string describing \a this field into a stream. This string is outputted
80 * by \c print Python command.
81 * \param [in] bkOffset - number of white spaces printed at the beginning of each line.
82 * \param [in,out] oss - the out stream.
83 * \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
84 * info id printed, else, not.
86 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
88 std::string startOfLine(bkOffset,' ');
89 oss << startOfLine << "Field ";
91 oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
92 oss << "on one time Step ";
94 oss << "(" << f1tsId << ") ";
95 oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
96 oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
97 const DataArray *arr=getUndergroundDataArray();
100 const std::vector<std::string> &comps=arr->getInfoOnComponents();
103 oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
104 for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
105 oss << startOfLine << " - \"" << (*it) << "\"" << std::endl;
107 if(arr->isAllocated())
109 oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
112 oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
116 oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
118 oss << startOfLine << "----------------------" << std::endl;
119 if(!_field_per_mesh.empty())
122 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
124 const MEDFileFieldPerMesh *cur=(*it2);
126 cur->simpleRepr(bkOffset,oss,i);
128 oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
133 oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
135 oss << startOfLine << "----------------------" << std::endl;
138 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
140 const DataArray *arr(getUndergroundDataArray());
142 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
143 std::size_t nbOfCompo=arr->getNumberOfComponents();
144 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
145 for(std::size_t i=0;i<nbOfCompo;i++)
148 std::vector<std::size_t> v(1,i);
149 MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
150 ret[i]->setArray(arr2);
155 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName,meshName),_iteration(iteration),_order(order),_csit(csit),_nb_of_tuples_to_be_allocated(-2)
159 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
164 * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
165 * empty. Returns -1 if this in on nodes.
166 * \return int - the dimension of \a this.
168 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
171 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
172 (*it)->getDimension(ret);
176 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
179 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
181 MEDFileFieldPerMesh *cur(*it);
183 ret=cur->changeMeshNames(modifTab) || ret;
189 * Returns the number of iteration of the state of underlying mesh.
190 * \return int - the iteration number.
191 * \throw If \c _field_per_mesh.empty()
193 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
195 if(_field_per_mesh.empty())
196 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
197 return _field_per_mesh[0]->getMeshIteration();
201 * Returns the order number of iteration of the state of underlying mesh.
202 * \return int - the order number.
203 * \throw If \c _field_per_mesh.empty()
205 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
207 if(_field_per_mesh.empty())
208 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
209 return _field_per_mesh[0]->getMeshOrder();
213 * Checks if \a this field is tagged by a given iteration number and a given
214 * iteration order number.
215 * \param [in] iteration - the iteration number of interest.
216 * \param [in] order - the iteration order number of interest.
217 * \return bool - \c true if \a this->getIteration() == \a iteration &&
218 * \a this->getOrder() == \a order.
220 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
222 return iteration==_iteration && order==_order;
226 * Returns number of iteration and order number of iteration when
227 * \a this field has been calculated.
228 * \return std::pair<int,int> - a pair of the iteration number and the iteration
231 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
233 std::pair<int,int> p;
239 * Returns number of iteration and order number of iteration when
240 * \a this field has been calculated.
241 * \param [in,out] p - a pair returning the iteration number and the iteration
244 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
251 * Returns all types of spatial discretization of \a this field.
252 * \param [in,out] types - a sequence of types of \a this field.
254 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
256 std::set<TypeOfField> types2;
257 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
259 (*it)->fillTypesOfFieldAvailable(types2);
261 std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
262 std::copy(types2.begin(),types2.end(),bi);
266 * Returns all types of spatial discretization of \a this field.
267 * \return std::vector<TypeOfField> - a sequence of types of spatial discretization
270 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
272 std::vector<TypeOfField> ret;
273 fillTypesOfFieldAvailable(ret);
277 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
279 std::vector<std::string> ret;
280 std::set<std::string> ret2;
281 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
283 std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
284 for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
285 if(ret2.find(*it2)==ret2.end())
294 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
296 std::vector<std::string> ret;
297 std::set<std::string> ret2;
298 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
300 std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
301 for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
302 if(ret2.find(*it2)==ret2.end())
311 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
313 std::vector<std::string> ret;
314 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
316 std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
317 ret.insert(ret.end(),tmp.begin(),tmp.end());
322 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
324 std::vector<std::string> ret;
325 std::set<std::string> ret2;
326 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
328 std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
329 ret.insert(ret.end(),tmp.begin(),tmp.end());
334 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
336 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
337 (*it)->changePflsRefsNamesGen(mapOfModif);
340 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
342 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
343 (*it)->changeLocsRefsNamesGen(mapOfModif);
347 * Returns all attributes of parts of \a this field lying on a given mesh.
348 * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
349 * item of every of returned sequences refers to the _i_-th part of \a this field.
350 * Thus all sequences returned by this method are of the same length equal to number
351 * of different types of supporting entities.<br>
352 * A field part can include sub-parts with several different spatial discretizations,
353 * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
354 * for example. Hence, some of the returned sequences contains nested sequences, and an item
355 * of a nested sequence corresponds to a type of spatial discretization.<br>
356 * This method allows for iteration over MEDFile DataStructure without any overhead.
357 * \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
358 * for the case with only one underlying mesh. (Actually, the number of meshes is
359 * not checked if \a mname == \c NULL).
360 * \param [in,out] types - a sequence of types of underlying mesh entities. A type per
361 * a field part is returned.
362 * \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
363 * This sequence is of the same length as \a types.
364 * \param [in,out] pfls - a sequence returning a profile name per each type of spatial
365 * discretization. A profile name can be empty.
366 * Length of this and of nested sequences is the same as that of \a typesF.
367 * \param [in,out] locs - a sequence returning a localization name per each type of spatial
368 * discretization. A localization name can be empty.
369 * Length of this and of nested sequences is the same as that of \a typesF.
370 * \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
371 * of ids of tuples within the data array, per each type of spatial
372 * discretization within one mesh entity type.
373 * Length of this and of nested sequences is the same as that of \a typesF.
374 * \throw If no field is lying on \a mname.
376 std::vector< std::vector< std::pair<mcIdType,mcIdType> > > MEDFileAnyTypeField1TSWithoutSDA::getFieldSplitedByType(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
378 if(_field_per_mesh.empty())
379 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
380 return _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
384 * Returns dimensions of mesh elements \a this field lies on. The returned value is a
385 * maximal absolute dimension and values returned via the out parameter \a levs are
386 * dimensions relative to the maximal absolute dimension. <br>
387 * This method is designed for MEDFileField1TS instances that have a discretization
388 * \ref MEDCoupling::ON_CELLS "ON_CELLS",
389 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
390 * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
391 * Only these 3 discretizations will be taken into account here. If \a this is
392 * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
393 * This method is useful to make the link between the dimension of the underlying mesh
394 * and the levels of \a this, because it is possible that the highest dimension of \a this
395 * field is not equal to the dimension of the underlying mesh.
397 * Let's consider the following case:
398 * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
399 * TETRA4, HEXA8, TRI3 and SEG2.
400 * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
401 * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
403 * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
404 * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
405 * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
406 * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
407 * parameter of getFieldAtLevel() is computed basing on the returned values as this:
408 * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
410 * to retrieve the highest level of
411 * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br>
412 * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
413 * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
414 * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
415 * \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
416 * for the case with only one underlying mesh. (Actually, the number of meshes is
417 * not checked if \a mname == \c NULL).
418 * \param [in,out] levs - a sequence returning the dimensions relative to the maximal
419 * absolute one. They are in decreasing order. This sequence is cleared before
421 * \return int - the maximal absolute dimension of elements \a this fields lies on.
422 * \throw If no field is lying on \a mname.
424 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
427 std::vector<INTERP_KERNEL::NormalizedCellType> types;
428 std::vector< std::vector<TypeOfField> > typesF;
429 std::vector< std::vector<std::string> > pfls, locs;
430 if(_field_per_mesh.empty())
431 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels : This is empty !");
432 _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
434 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
435 std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
436 if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
438 st.erase(INTERP_KERNEL::NORM_ERROR);
440 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
442 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
443 ret1.insert((int)cm.getDimension());
445 int ret=*std::max_element(ret1.begin(),ret1.end());
446 std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
447 std::transform(levs.begin(),levs.end(),levs.begin(),std::bind(std::plus<int>(),std::placeholders::_1,-ret));
451 void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic()
453 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it<_field_per_mesh.end();it++)
454 if((*it).isNotNull())
455 (*it)->convertMedBallIntoClassic();
458 void MEDFileAnyTypeField1TSWithoutSDA::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayIdType *pfl)
461 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : null pfl !");
462 std::string name(pfl->getName());
463 pfl->checkAllocated();
464 if(pfl->getNumberOfComponents()!=1)
465 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : non mono compo array !");
467 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : empty pfl name !");
468 if(_field_per_mesh.size()!=1)
469 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single mesh supported !");
470 MCAuto<MEDFileFieldPerMesh> fpm(_field_per_mesh[0]);
472 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single not null mesh supported !");
473 MEDFileFieldPerMeshPerTypePerDisc *disc(fpm->getLeafGivenTypeAndLocId(ct,0));
474 if(disc->getType()!=tof)
475 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : error !");
476 mcIdType s(disc->getStart()),e(disc->getEnd()),nt(pfl->getNumberOfTuples());
477 DataArray *arr(getUndergroundDataArray());
478 mcIdType nt2(arr->getNumberOfTuples()),delta((e-s)-nt);
480 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : internal error !");
481 MCAuto<DataArray> arr0(arr->selectByTupleIdSafeSlice(0,s,1)),arr1(arr->selectByTupleIdSafeSlice(s,e,1)),arr2(arr->selectByTupleIdSafeSlice(e,nt2,1));
482 MCAuto<DataArray> arr11(arr1->selectByTupleIdSafe(pfl->begin(),pfl->end()));
483 MCAuto<DataArray> arrOut(arr->buildNewEmptyInstance());
484 arrOut->alloc(nt2-delta,arr->getNumberOfComponents());
485 arrOut->copyStringInfoFrom(*arr);
486 arrOut->setContigPartOfSelectedValuesSlice(0,arr0,0,s,1);
487 arrOut->setContigPartOfSelectedValuesSlice(s,arr11,0,nt,1);
488 arrOut->setContigPartOfSelectedValuesSlice(e-delta,arr2,0,nt2-e,1);
490 disc->setEnd(e-delta);
491 disc->setProfile(name);
495 * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
496 * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
497 * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of
498 * \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
500 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
502 if(_field_per_mesh.empty())
503 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
504 return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
508 * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
509 * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
510 * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of
511 * \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
513 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
515 if(_field_per_mesh.empty())
516 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
517 return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
521 * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
523 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
525 if(_field_per_mesh.empty())
526 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
529 std::string mName2(mName);
531 std::vector<std::string> msg;
532 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
533 if(mName2==(*it)->getMeshName())
536 msg.push_back((*it)->getMeshName());
537 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
538 oss << "Possible meshes are : ";
539 for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
540 oss << "\"" << (*it2) << "\" ";
541 throw INTERP_KERNEL::Exception(oss.str());
544 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
547 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
548 std::string tmp(mesh->getName());
550 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
552 std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
554 for(;it!=_field_per_mesh.end();it++,i++)
556 if((*it)->getMeshName()==tmp)
559 std::size_t sz=_field_per_mesh.size();
560 _field_per_mesh.resize(sz+1);
561 _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
565 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<mcIdType>& oldCode, const std::vector<mcIdType>& newCode, const DataArrayIdType *renumO2N,
566 MEDFileFieldGlobsReal& glob)
569 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
571 MEDFileFieldPerMesh *fpm(*it);
573 ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
579 * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
580 * splitting that leads to single spatial discretization of this.
582 * \sa splitMultiDiscrPerGeoTypes
584 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
586 std::vector<INTERP_KERNEL::NormalizedCellType> types;
587 std::vector< std::vector<TypeOfField> > typesF;
588 std::vector< std::vector<std::string> > pfls,locs;
589 std::vector< std::vector<std::pair<mcIdType,mcIdType> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
590 std::set<TypeOfField> allEnt;
591 for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
592 for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
594 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
595 std::set<TypeOfField>::const_iterator it3(allEnt.begin());
596 for(std::size_t i=0;i<allEnt.size();i++,it3++)
598 std::vector< std::pair<mcIdType,mcIdType> > its;
600 mcIdType newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
601 ret[i]->updateData(newLgth,its);
607 * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest splitting level that can be done.
608 * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
610 * \sa splitDiscretizations
612 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
614 std::vector<INTERP_KERNEL::NormalizedCellType> types;
615 std::vector< std::vector<TypeOfField> > typesF;
616 std::vector< std::vector<std::string> > pfls,locs;
617 std::vector< std::vector<std::pair<mcIdType,mcIdType> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
618 std::set<TypeOfField> allEnt;
619 std::size_t nbOfMDPGT(0),ii(0);
620 for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
622 nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
623 for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
627 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
629 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
632 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
633 ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
636 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
637 for(std::size_t i=0;i<nbOfMDPGT;i++)
639 std::vector< std::pair<mcIdType,mcIdType> > its;
641 mcIdType newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
642 ret[i]->updateData(newLgth,its);
647 mcIdType MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<mcIdType,mcIdType> >& its)
649 mcIdType globalCounter(0);
650 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
651 (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
652 return globalCounter;
655 mcIdType MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<mcIdType,mcIdType> >& its)
657 mcIdType globalCounter(0);
658 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
659 (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
660 return globalCounter;
663 void MEDFileAnyTypeField1TSWithoutSDA::updateData(mcIdType newLgth, const std::vector< std::pair<mcIdType,mcIdType> >& oldStartStops)
665 if(_nb_of_tuples_to_be_allocated>=0)
667 _nb_of_tuples_to_be_allocated=newLgth;
668 const DataArray *oldArr(getUndergroundDataArray());
671 MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
672 newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
674 _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
678 if(_nb_of_tuples_to_be_allocated==-1)
680 if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
682 const DataArray *oldArr(getUndergroundDataArray());
683 if(!oldArr || !oldArr->isAllocated())
684 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
685 MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
686 newArr->alloc(newLgth,getNumberOfComponents());
688 newArr->copyStringInfoFrom(*oldArr);
690 for(std::vector< std::pair<mcIdType,mcIdType> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
692 if((*it).second<(*it).first)
693 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
694 newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
695 pos+=(*it).second-(*it).first;
700 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
703 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
705 if(_field_per_mesh.empty())
706 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
707 if(_field_per_mesh.size()>1)
708 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writing mode only ONE underlying mesh supported !");
709 _field_per_mesh[0]->copyOptionsFrom(opts);
710 _field_per_mesh[0]->writeLL(fid,nasc);
714 * MED file does not support ' ' at the end of the field name. This method corrects the possibly invalid input \a nonCorrectFieldName to a correct one by right stripping input.
716 std::string MEDFileAnyTypeField1TSWithoutSDA::FieldNameToMEDFileConvention(const std::string& nonCorrectFieldName)
718 std::string::size_type pos0(nonCorrectFieldName.find_last_not_of(' '));
719 if(pos0==std::string::npos)
720 return nonCorrectFieldName;
721 if(pos0+1==nonCorrectFieldName.length())
722 return nonCorrectFieldName;
723 return nonCorrectFieldName.substr(0,pos0+1);
727 * This methods returns true is the allocation has been needed leading to a modification of state in \a this->_nb_of_tuples_to_be_allocated.
728 * If false is returned the memory allocation is not required.
730 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
732 if(_nb_of_tuples_to_be_allocated>=0)
734 getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
735 _nb_of_tuples_to_be_allocated=-2;
738 if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
740 if(_nb_of_tuples_to_be_allocated==-1)
741 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
742 if(_nb_of_tuples_to_be_allocated<-3)
743 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
744 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
747 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities, const MEDFileCapability *capability)
751 med_int meshnumdt(-1),meshnumit(-1);
752 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
753 if(!capability || !capability->isFastReader())
757 INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
758 MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit)); // to check with Adrien for legacy MED files
760 if(_iteration!=numdt || _order!=numit)
761 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
762 _field_per_mesh.resize(1);
767 mm=ms->getMeshWithName(getMeshName());
770 _field_per_mesh[0]=MEDFileFieldPerMesh::NewOnRead(fid,this,0,FromMedInt<int>(meshnumdt),FromMedInt<int>(meshnumit),nasc,mm,entities);
771 _nb_of_tuples_to_be_allocated=0;
772 _field_per_mesh[0]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
775 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const PartDefinition *pd, const MEDFileEntities *entities, const MEDFileCapability *capability)
779 med_int meshnumdt(-1),meshnumit(-1);
780 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
781 if(!capability || !capability->isFastReader())
785 INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
786 MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit)); // to check with Adrien for legacy MED files
788 if(_iteration!=numdt || _order!=numit)
789 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
790 _field_per_mesh.resize(1);
791 _field_per_mesh[0]=MEDFileFieldPerMesh::NewOnRead(fid,this,0,FromMedInt<int>(meshnumdt),FromMedInt<int>(meshnumit),nasc,pd,entities);
792 _nb_of_tuples_to_be_allocated=0;
793 _field_per_mesh[0]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
796 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
798 allocIfNecessaryTheArrayToReceiveDataFromFile();
799 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
800 (*it)->loadBigArraysRecursively(fid,nasc);
803 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
805 if(allocIfNecessaryTheArrayToReceiveDataFromFile())
806 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
807 (*it)->loadBigArraysRecursively(fid,nasc);
810 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
812 MEDFileCapability cap(fid);
813 loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities,&cap);
814 loadBigArraysRecursively(fid,nasc);
817 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const PartDefinition *pd, const MEDFileEntities *entities)
819 MEDFileCapability cap(fid);
820 loadOnlyStructureOfDataRecursively(fid,nasc,pd,entities,&cap);
821 loadBigArraysRecursively(fid,nasc);
824 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
826 DataArray *thisArr(getUndergroundDataArray());
827 if(thisArr && thisArr->isAllocated())
829 _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
830 thisArr->desallocate();
834 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
836 return _mesh_name.capacity()+_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
839 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
841 std::vector<const BigMemoryObject *> ret;
842 if(getUndergroundDataArray())
843 ret.push_back(getUndergroundDataArray());
844 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
845 ret.push_back((const MEDFileFieldPerMesh *)*it);
850 * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
851 * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
852 * "Sort By Type"), if not, an exception is thrown.
853 * \param [in] field - the field to add to \a this. The array of field \a field is ignored
854 * \param [in] arr - the array of values.
855 * \param [in,out] glob - the global data where profiles and localization present in
856 * \a field, if any, are added.
857 * \throw If the name of \a field is empty.
858 * \throw If the data array of \a field is not set.
859 * \throw If \a this->_arr is already allocated but has different number of components
861 * \throw If the underlying mesh of \a field has no name.
862 * \throw If elements in the mesh are not in the order suitable for writing to the MED file.
864 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
866 const MEDCouplingMesh *mesh(field->getMesh());
868 TypeOfField type(field->getTypeOfField());
869 std::vector<DataArrayIdType *> dummy;
871 setMeshName(mesh->getName());
872 mcIdType start(copyTinyInfoFrom(th,field,arr));
873 int pos(addNewEntryIfNecessary(mesh));
876 std::vector<mcIdType> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
877 _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
880 _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
884 * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
885 * of a given mesh are used as the support of the given field (a real support is not used).
886 * Elements of the given mesh must be sorted suitable for writing to MED file.
887 * Order of underlying mesh entities of the given field specified by \a profile parameter
888 * is not prescribed; this method permutes field values to have them sorted by element
889 * type as required for writing to MED file. A new profile is added only if no equal
890 * profile is missing.
891 * \param [in] field - the field to add to \a this. The field double values are ignored.
892 * \param [in] arrOfVals - the values of the field \a field used.
893 * \param [in] mesh - the supporting mesh of \a field.
894 * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
895 * \param [in] profile - ids of mesh entities on which corresponding field values lie.
896 * \param [in,out] glob - the global data where profiles and localization present in
897 * \a field, if any, are added.
898 * \param [in] nasc - the name scope used to assign names. Depends on the caller on the top call stack
899 * \param [in] smartPflKiller - specifies if this method tries at most to avoid profiles
900 * \throw If either \a field or \a mesh or \a profile has an empty name.
901 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
902 * \throw If the data array of \a field is not set.
903 * \throw If \a this->_arr is already allocated but has different number of components
905 * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
906 * \sa setFieldNoProfileSBT()
908 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc, bool smartPflKiller)
911 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
912 if(!arrOfVals || !arrOfVals->isAllocated())
913 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
914 TypeOfField type=field->getTypeOfField();
915 std::vector<DataArrayIdType *> idsInPflPerType;
916 std::vector<DataArrayIdType *> idsPerType;
917 std::vector<mcIdType> code,code2;
918 MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
921 m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType,smartPflKiller);
922 std::vector< MCAuto<DataArrayIdType> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
923 std::vector< MCAuto<DataArrayIdType> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin());
924 std::vector<const DataArrayIdType *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
926 MCAuto<MEDCouplingFieldTemplate> field2=field->clone(false);
927 mcIdType nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
928 if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
930 std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
931 throw INTERP_KERNEL::Exception(oss.str());
934 mcIdType start(copyTinyInfoFrom(th,field,arrOfVals));
935 code2=m->getDistributionOfTypes();
937 mcIdType pos=addNewEntryIfNecessary(m);
938 _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
942 if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
943 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
944 std::vector<mcIdType> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
945 std::vector<const DataArrayIdType *> idsPerType3(1); idsPerType3[0]=profile;
946 mcIdType nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
947 if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
949 std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
950 throw INTERP_KERNEL::Exception(oss.str());
952 mcIdType start(copyTinyInfoFrom(th,field,arrOfVals));
953 mcIdType pos(addNewEntryIfNecessary(m));
954 _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
959 * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
961 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(mcIdType newNbOfTuples)
963 if(_nb_of_tuples_to_be_allocated>=0)
964 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile : the object is expected to be appended to a data coming from a file but not loaded ! Load before appending data !");
965 DataArray *arr(getOrCreateAndGetArray());
966 arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
967 _nb_of_tuples_to_be_allocated=-3;
971 * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
972 * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
973 * larger by the size of \a field. Returns an id of the first not filled
974 * tuple of \a this->_arr.
975 * \param [in] field - the field to copy the info on components and the name from.
976 * \return int - the id of first not initialized tuple of \a this->_arr.
977 * \throw If the name of \a field is empty.
978 * \throw If the data array of \a field is not set.
979 * \throw If \a this->_arr is already allocated but has different number of components
982 mcIdType MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
985 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
986 std::string name(field->getName());
987 setName(name.c_str());
989 setMeshName(field->getMesh()->getName());
990 setDtUnit(th->getTimeUnit());
992 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
994 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
995 if(!arr->isAllocated())
996 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
997 _dt=th->getTime(_iteration,_order);
998 getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
999 if(!getOrCreateAndGetArray()->isAllocated())
1001 allocNotFromFile(arr->getNumberOfTuples());
1006 mcIdType oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
1007 mcIdType newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
1008 getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
1009 _nb_of_tuples_to_be_allocated=-3;
1010 return oldNbOfTuples;
1015 * Returns number of components in \a this field
1016 * \return int - the number of components.
1018 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
1020 return getOrCreateAndGetArray()->getNumberOfComponents();
1024 * Change info on components in \a this.
1025 * \throw If size of \a infos is not equal to the number of components already in \a this.
1027 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
1029 DataArray *arr=getOrCreateAndGetArray();
1030 arr->setInfoOnComponents(infos);//will throw an exception if number of components mismatches
1034 * Returns info on components of \a this field.
1035 * \return const std::vector<std::string>& - a sequence of strings each being an
1036 * information on _i_-th component.
1038 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
1040 const DataArray *arr=getOrCreateAndGetArray();
1041 return arr->getInfoOnComponents();
1045 * Returns a mutable info on components of \a this field.
1046 * \return std::vector<std::string>& - a sequence of strings each being an
1047 * information on _i_-th component.
1049 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
1051 DataArray *arr=getOrCreateAndGetArray();
1052 return arr->getInfoOnComponents();
1055 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
1057 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
1059 const MEDFileFieldPerMesh *fpm(*it);
1062 if(fpm->presenceOfMultiDiscPerGeoType())
1068 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
1070 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
1071 if((*it).isNotNull())
1072 if((*it)->presenceOfStructureElements())
1077 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
1079 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
1080 if((*it).isNotNull())
1081 if(!(*it)->onlyStructureElements())
1086 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
1088 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
1089 if((*it).isNotNull())
1090 (*it)->killStructureElements();
1093 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
1095 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
1096 if((*it).isNotNull())
1097 (*it)->keepOnlyStructureElements();
1100 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName)
1102 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
1103 if((*it).isNotNull())
1104 (*it)->keepOnlyOnSE(seName);
1107 void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
1109 for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
1110 if((*it).isNotNull())
1111 (*it)->getMeshSENames(ps);
1114 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
1116 static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to be extracted with \"field\" method ! Call getFieldOnMeshAtLevel method instead to deal with complexity !";
1117 if(_field_per_mesh.empty())
1118 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
1119 if(_field_per_mesh.size()>1)
1120 throw INTERP_KERNEL::Exception(MSG0);
1121 if(_field_per_mesh[0].isNull())
1122 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
1123 const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
1124 std::set<TypeOfField> types;
1125 pm->fillTypesOfFieldAvailable(types);
1127 throw INTERP_KERNEL::Exception(MSG0);
1128 TypeOfField type(*types.begin());
1129 int meshDimRelToMax(0);
1134 int myDim(std::numeric_limits<int>::max());
1135 bool isUnique(pm->isUniqueLevel(myDim));
1137 throw INTERP_KERNEL::Exception(MSG0);
1138 meshDimRelToMax=myDim-mesh->getMeshDimension();
1139 if(meshDimRelToMax>0)
1140 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
1142 return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
1146 * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
1147 * \param [in] type - a spatial discretization of the new field.
1148 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1149 * \param [in] mName - a name of the supporting mesh.
1150 * \param [in] renumPol - specifies how to permute values of the result field according to
1151 * the optional numbers of cells and nodes, if any. The valid values are
1152 * - 0 - do not permute.
1153 * - 1 - permute cells.
1154 * - 2 - permute nodes.
1155 * - 3 - permute cells and nodes.
1157 * \param [in] glob - the global data storing profiles and localization.
1158 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1159 * caller is to delete this field using decrRef() as it is no more needed.
1160 * \throw If the MED file is not readable.
1161 * \throw If there is no mesh named \a mName in the MED file.
1162 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1163 * \throw If no field of \a this is lying on the mesh \a mName.
1164 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
1166 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
1168 MCAuto<MEDFileMesh> mm;
1170 mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
1172 mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
1173 return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
1177 * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
1178 * \param [in] type - a spatial discretization of the new field.
1179 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1180 * \param [in] renumPol - specifies how to permute values of the result field according to
1181 * the optional numbers of cells and nodes, if any. The valid values are
1182 * - 0 - do not permute.
1183 * - 1 - permute cells.
1184 * - 2 - permute nodes.
1185 * - 3 - permute cells and nodes.
1187 * \param [in] glob - the global data storing profiles and localization.
1188 * \param [in] mesh - the supporting mesh.
1189 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1190 * caller is to delete this field using decrRef() as it is no more needed.
1191 * \throw If the MED file is not readable.
1192 * \throw If no field of \a this is lying on \a mesh.
1193 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1194 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
1196 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
1198 MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
1199 const DataArrayIdType *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
1200 if(meshDimRelToMax==1)
1201 (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
1202 return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
1206 * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
1208 * \param [in] type - a spatial discretization of the new field.
1209 * \param [in] mName - a name of the supporting mesh.
1210 * \param [in] renumPol - specifies how to permute values of the result field according to
1211 * the optional numbers of cells and nodes, if any. The valid values are
1212 * - 0 - do not permute.
1213 * - 1 - permute cells.
1214 * - 2 - permute nodes.
1215 * - 3 - permute cells and nodes.
1217 * \param [in] glob - the global data storing profiles and localization.
1218 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1219 * caller is to delete this field using decrRef() as it is no more needed.
1220 * \throw If the MED file is not readable.
1221 * \throw If there is no mesh named \a mName in the MED file.
1222 * \throw If there are no mesh entities in the mesh.
1223 * \throw If no field values of the given \a type are available.
1225 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
1227 MCAuto<MEDFileMesh> mm;
1229 mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
1231 mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
1232 int absDim=getDimension();
1233 int meshDimRelToMax=absDim-mm->getMeshDimension();
1234 return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
1238 * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
1239 * \param [in] type - a spatial discretization of the new field.
1240 * \param [in] renumPol - specifies how to permute values of the result field according to
1241 * the optional numbers of cells and nodes, if any. The valid values are
1242 * - 0 - do not permute.
1243 * - 1 - permute cells.
1244 * - 2 - permute nodes.
1245 * - 3 - permute cells and nodes.
1247 * \param [in] glob - the global data storing profiles and localization.
1248 * \param [in] mesh - the supporting mesh.
1249 * \param [in] cellRenum - the cell numbers array used for permutation of the result
1250 * field according to \a renumPol.
1251 * \param [in] nodeRenum - the node numbers array used for permutation of the result
1252 * field according to \a renumPol.
1253 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
1254 * caller is to delete this field using decrRef() as it is no more needed.
1255 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
1256 * \throw If no field of \a this is lying on \a mesh.
1257 * \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
1259 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayIdType *cellRenum, const DataArrayIdType *nodeRenum, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
1261 static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
1263 MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[0]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
1268 //no need to test _field_per_mesh.empty() because geMeshName has already done it
1275 throw INTERP_KERNEL::Exception(msg1);
1276 //no need to test _field_per_mesh.empty() because geMeshName has already done it
1279 if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
1281 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
1282 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
1283 throw INTERP_KERNEL::Exception(oss.str());
1285 MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
1286 if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
1287 std::vector<DataArray *> arrOut2(1,arrOut);
1288 // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
1289 disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
1290 (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
1295 [[clang::fallthrough]]; // yes no break here - silence clang warning.
1298 //no need to test _field_per_mesh.empty() because geMeshName has already done it
1300 throw INTERP_KERNEL::Exception(msg1);
1303 if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
1305 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
1306 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
1307 throw INTERP_KERNEL::Exception(oss.str());
1309 MCAuto<DataArrayIdType> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
1310 if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
1311 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
1312 ret->renumberNodes(nodeRenumSafe->getConstPointer());
1318 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
1324 * Returns values and a profile of the field of a given type lying on a given support.
1325 * \param [in] type - a spatial discretization of the field.
1326 * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
1327 * \param [in] mesh - the supporting mesh.
1328 * \param [out] pfl - a new instance of DataArrayIdType holding ids of mesh entities the
1329 * field of interest lies on. If the field lies on all entities of the given
1330 * dimension, all ids in \a pfl are zero. The caller is to delete this array
1331 * using decrRef() as it is no more needed.
1332 * \param [in] glob - the global data storing profiles and localization.
1333 * \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
1334 * field. The caller is to delete this array using decrRef() as it is no more needed.
1335 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
1336 * \throw If no field of \a this is lying on \a mesh.
1337 * \throw If no field values of the given \a type are available.
1339 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayIdType *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
1341 MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
1342 MCAuto<DataArray> ret=_field_per_mesh[0]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
1343 ret->setName(nasc.getName().c_str());
1347 //= MEDFileField1TSWithoutSDA
1350 * Throws if a given value is not a valid (non-extended) relative dimension.
1351 * \param [in] meshDimRelToMax - the relative dimension value.
1352 * \throw If \a meshDimRelToMax > 0.
1354 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
1356 if(meshDimRelToMax>0)
1357 throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
1361 * Checks if elements of a given mesh are in the order suitable for writing
1362 * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
1363 * vector describing types of elements and their number.
1364 * \param [in] mesh - the mesh to check.
1365 * \return std::vector<int> - a vector holding for each element type (1) item of
1366 * INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1.
1367 * These values are in full-interlace mode.
1368 * \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
1370 std::vector<mcIdType> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
1373 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
1374 std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
1375 std::size_t nbOfTypes=geoTypes.size();
1376 std::vector<mcIdType> code(3*nbOfTypes);
1377 MCAuto<DataArrayIdType> arr1=DataArrayIdType::New();
1378 arr1->alloc(nbOfTypes,1);
1379 mcIdType *arrPtr=arr1->getPointer();
1380 std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
1381 for(std::size_t i=0;i<nbOfTypes;i++,it++)
1382 arrPtr[i]=ToIdType(std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it)));
1383 MCAuto<DataArrayIdType> arr2=arr1->checkAndPreparePermutation();
1384 const mcIdType *arrPtr2=arr2->getConstPointer();
1386 for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
1388 mcIdType pos=arrPtr2[i];
1389 mcIdType nbCells=mesh->getNumberOfCellsWithType(*it);
1390 code[3*pos]=(mcIdType)(*it);
1391 code[3*pos+1]=nbCells;
1392 code[3*pos+2]=-1;//no profiles
1394 std::vector<const DataArrayIdType *> idsPerType;//no profiles
1395 DataArrayIdType *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
1399 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
1404 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
1406 return new MEDFileField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
1410 * Returns all attributes and values of parts of \a this field lying on a given mesh.
1411 * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
1412 * item of every of returned sequences refers to the _i_-th part of \a this field.
1413 * Thus all sequences returned by this method are of the same length equal to number
1414 * of different types of supporting entities.<br>
1415 * A field part can include sub-parts with several different spatial discretizations,
1416 * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
1417 * for example. Hence, some of the returned sequences contains nested sequences, and an item
1418 * of a nested sequence corresponds to a type of spatial discretization.<br>
1419 * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
1420 * The overhead is due to selecting values into new instances of DataArrayDouble.
1421 * \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
1422 * for the case with only one underlying mesh. (Actually, the number of meshes is
1423 * not checked if \a mname == \c NULL).
1424 * \param [in,out] types - a sequence of types of underlying mesh entities. A type per
1425 * a field part is returned.
1426 * \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
1427 * A field part can include sub-parts with several different spatial discretizations,
1428 * \ref MEDCoupling::ON_CELLS "ON_CELLS" and
1429 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
1430 * This sequence is of the same length as \a types.
1431 * \param [in,out] pfls - a sequence returning a profile name per each type of spatial
1432 * discretization. A profile name can be empty.
1433 * Length of this and of nested sequences is the same as that of \a typesF.
1434 * \param [in,out] locs - a sequence returning a localization name per each type of spatial
1435 * discretization. A localization name can be empty.
1436 * Length of this and of nested sequences is the same as that of \a typesF.
1437 * \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
1438 * per each type of spatial discretization within one mesh entity type.
1439 * The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
1440 * Length of this and of nested sequences is the same as that of \a typesF.
1441 * \throw If no field is lying on \a mname.
1443 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TSWithoutSDA::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
1446 if(_field_per_mesh.empty())
1447 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
1448 std::vector< std::vector< std::pair<mcIdType,mcIdType> > > ret0=_field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
1449 std::size_t nbOfRet=ret0.size();
1450 std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
1451 for(std::size_t i=0;i<nbOfRet;i++)
1453 const std::vector< std::pair<mcIdType,mcIdType> >& p=ret0[i];
1454 std::size_t nbOfRet1=p.size();
1455 ret[i].resize(nbOfRet1);
1456 for(std::size_t j=0;j<nbOfRet1;j++)
1458 DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
1465 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
1470 MEDFileInt32Field1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
1472 MCAuto<MEDFileInt32Field1TSWithoutSDA> ret(new MEDFileInt32Field1TSWithoutSDA);
1473 ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
1474 ret->deepCpyLeavesFrom(*this);
1475 const DataArrayDouble *arr(_arr);
1478 MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
1479 ret->setArray(arr2);
1484 MEDFileInt64Field1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt64() const
1486 MCAuto<MEDFileInt64Field1TSWithoutSDA> ret(new MEDFileInt64Field1TSWithoutSDA);
1487 ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
1488 ret->deepCpyLeavesFrom(*this);
1489 const DataArrayDouble *arr(_arr);
1492 MCAuto<DataArrayInt64> arr2(arr->convertToInt64Arr());
1493 ret->setArray(arr2);
1499 * Returns a pointer to the underground DataArrayDouble instance and a
1500 * sequence describing parameters of a support of each part of \a this field. The
1501 * caller should not decrRef() the returned DataArrayDouble. This method allows for a
1502 * direct access to the field values. This method is intended for the field lying on one
1504 * \param [in,out] entries - the sequence describing parameters of a support of each
1505 * part of \a this field. Each item of this sequence consists of two parts. The
1506 * first part describes a type of mesh entity and an id of discretization of a
1507 * current field part. The second part describes a range of values [begin,end)
1508 * within the returned array relating to the current field part.
1509 * \return DataArrayDouble * - the pointer to the field values array.
1510 * \throw If the number of underlying meshes is not equal to 1.
1511 * \throw If no field values are available.
1512 * \sa getUndergroundDataArray()
1514 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1516 return getUndergroundDataArrayTemplateExt(entries);
1519 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,meshName,csit,iteration,order)
1521 DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
1522 arr->setInfoAndChangeNbOfCompo(infos);
1525 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
1529 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
1531 MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
1532 ret->deepCpyLeavesFrom(*this);
1536 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
1538 MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
1539 if(_arr.isNotNull())
1540 ret->_arr=_arr->deepCopy();
1544 //= MEDFileInt32Field1TSWithoutSDA
1546 MEDFileInt32Field1TSWithoutSDA *MEDFileInt32Field1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
1548 return new MEDFileInt32Field1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
1551 MEDFileInt32Field1TSWithoutSDA::MEDFileInt32Field1TSWithoutSDA()
1555 MEDFileInt32Field1TSWithoutSDA::MEDFileInt32Field1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
1556 const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<int>(fieldName,meshName,csit,iteration,order,infos)
1558 DataArrayInt32 *arr(getOrCreateAndGetArrayTemplate());
1559 arr->setInfoAndChangeNbOfCompo(infos);
1562 const char *MEDFileInt32Field1TSWithoutSDA::getTypeStr() const
1568 * Returns a pointer to the underground DataArrayIdType instance and a
1569 * sequence describing parameters of a support of each part of \a this field. The
1570 * caller should not decrRef() the returned DataArrayIdType. This method allows for a
1571 * direct access to the field values. This method is intended for the field lying on one
1573 * \param [in,out] entries - the sequence describing parameters of a support of each
1574 * part of \a this field. Each item of this sequence consists of two parts. The
1575 * first part describes a type of mesh entity and an id of discretization of a
1576 * current field part. The second part describes a range of values [begin,end)
1577 * within the returned array relating to the current field part.
1578 * \return DataArrayIdType * - the pointer to the field values array.
1579 * \throw If the number of underlying meshes is not equal to 1.
1580 * \throw If no field values are available.
1581 * \sa getUndergroundDataArray()
1583 DataArray *MEDFileInt32Field1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1585 return getUndergroundDataArrayIntExt(entries);
1589 * Returns a pointer to the underground DataArrayInt instance and a
1590 * sequence describing parameters of a support of each part of \a this field. The
1591 * caller should not decrRef() the returned DataArrayIdType. This method allows for a
1592 * direct access to the field values. This method is intended for the field lying on one
1594 * \param [in,out] entries - the sequence describing parameters of a support of each
1595 * part of \a this field. Each item of this sequence consists of two parts. The
1596 * first part describes a type of mesh entity and an id of discretization of a
1597 * current field part. The second part describes a range of values [begin,end)
1598 * within the returned array relating to the current field part.
1599 * \return DataArrayInt * - the pointer to the field values array.
1600 * \throw If the number of underlying meshes is not equal to 1.
1601 * \throw If no field values are available.
1602 * \sa getUndergroundDataArray()
1604 DataArrayInt32 *MEDFileInt32Field1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1606 if(_field_per_mesh.size()!=1)
1607 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
1608 if(_field_per_mesh[0]==0)
1609 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
1610 _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
1611 return getUndergroundDataArrayTemplate();
1614 MEDFileInt32Field1TSWithoutSDA *MEDFileInt32Field1TSWithoutSDA::shallowCpy() const
1616 MCAuto<MEDFileInt32Field1TSWithoutSDA> ret(new MEDFileInt32Field1TSWithoutSDA(*this));
1617 ret->deepCpyLeavesFrom(*this);
1621 MEDFileInt32Field1TSWithoutSDA *MEDFileInt32Field1TSWithoutSDA::deepCopy() const
1623 MCAuto<MEDFileInt32Field1TSWithoutSDA> ret(shallowCpy());
1624 if(_arr.isNotNull())
1625 ret->_arr=_arr->deepCopy();
1629 //= MEDFileInt64Field1TSWithoutSDA
1631 MEDFileInt64Field1TSWithoutSDA *MEDFileInt64Field1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
1633 return new MEDFileInt64Field1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
1636 MEDFileInt64Field1TSWithoutSDA::MEDFileInt64Field1TSWithoutSDA()
1640 MEDFileInt64Field1TSWithoutSDA::MEDFileInt64Field1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
1641 const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<Int64>(fieldName,meshName,csit,iteration,order,infos)
1643 DataArrayInt64 *arr(getOrCreateAndGetArrayTemplate());
1644 arr->setInfoAndChangeNbOfCompo(infos);
1647 const char *MEDFileInt64Field1TSWithoutSDA::getTypeStr() const
1653 * Returns a pointer to the underground DataArrayIdType instance and a
1654 * sequence describing parameters of a support of each part of \a this field. The
1655 * caller should not decrRef() the returned DataArrayIdType. This method allows for a
1656 * direct access to the field values. This method is intended for the field lying on one
1658 * \param [in,out] entries - the sequence describing parameters of a support of each
1659 * part of \a this field. Each item of this sequence consists of two parts. The
1660 * first part describes a type of mesh entity and an id of discretization of a
1661 * current field part. The second part describes a range of values [begin,end)
1662 * within the returned array relating to the current field part.
1663 * \return DataArrayIdType * - the pointer to the field values array.
1664 * \throw If the number of underlying meshes is not equal to 1.
1665 * \throw If no field values are available.
1666 * \sa getUndergroundDataArray()
1668 DataArray *MEDFileInt64Field1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1670 return getUndergroundDataArrayIntExt(entries);
1674 * Returns a pointer to the underground DataArrayInt instance and a
1675 * sequence describing parameters of a support of each part of \a this field. The
1676 * caller should not decrRef() the returned DataArrayIdType. This method allows for a
1677 * direct access to the field values. This method is intended for the field lying on one
1679 * \param [in,out] entries - the sequence describing parameters of a support of each
1680 * part of \a this field. Each item of this sequence consists of two parts. The
1681 * first part describes a type of mesh entity and an id of discretization of a
1682 * current field part. The second part describes a range of values [begin,end)
1683 * within the returned array relating to the current field part.
1684 * \return DataArrayInt * - the pointer to the field values array.
1685 * \throw If the number of underlying meshes is not equal to 1.
1686 * \throw If no field values are available.
1687 * \sa getUndergroundDataArray()
1689 DataArrayInt64 *MEDFileInt64Field1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1691 if(_field_per_mesh.size()!=1)
1692 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
1693 if(_field_per_mesh[0]==0)
1694 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
1695 _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
1696 return getUndergroundDataArrayTemplate();
1699 MEDFileInt64Field1TSWithoutSDA *MEDFileInt64Field1TSWithoutSDA::shallowCpy() const
1701 MCAuto<MEDFileInt64Field1TSWithoutSDA> ret(new MEDFileInt64Field1TSWithoutSDA(*this));
1702 ret->deepCpyLeavesFrom(*this);
1706 MEDFileInt64Field1TSWithoutSDA *MEDFileInt64Field1TSWithoutSDA::deepCopy() const
1708 MCAuto<MEDFileInt64Field1TSWithoutSDA> ret(shallowCpy());
1709 if(_arr.isNotNull())
1710 ret->_arr=_arr->deepCopy();
1714 //= MEDFileFloatField1TSWithoutSDA
1716 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
1718 return new MEDFileFloatField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
1721 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA()
1725 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
1726 const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<float>(fieldName,meshName,csit,iteration,order,infos)
1728 DataArrayFloat *arr(getOrCreateAndGetArrayTemplate());
1729 arr->setInfoAndChangeNbOfCompo(infos);
1732 const char *MEDFileFloatField1TSWithoutSDA::getTypeStr() const
1738 * Returns a pointer to the underground DataArrayFloat instance and a
1739 * sequence describing parameters of a support of each part of \a this field. The
1740 * caller should not decrRef() the returned DataArrayFloat. This method allows for a
1741 * direct access to the field values. This method is intended for the field lying on one
1743 * \param [in,out] entries - the sequence describing parameters of a support of each
1744 * part of \a this field. Each item of this sequence consists of two parts. The
1745 * first part describes a type of mesh entity and an id of discretization of a
1746 * current field part. The second part describes a range of values [begin,end)
1747 * within the returned array relating to the current field part.
1748 * \return DataArrayFloat * - the pointer to the field values array.
1749 * \throw If the number of underlying meshes is not equal to 1.
1750 * \throw If no field values are available.
1751 * \sa getUndergroundDataArray()
1753 DataArray *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1755 return getUndergroundDataArrayFloatExt(entries);
1759 * Returns a pointer to the underground DataArrayFloat instance and a
1760 * sequence describing parameters of a support of each part of \a this field. The
1761 * caller should not decrRef() the returned DataArrayFloat. This method allows for a
1762 * direct access to the field values. This method is intended for the field lying on one
1764 * \param [in,out] entries - the sequence describing parameters of a support of each
1765 * part of \a this field. Each item of this sequence consists of two parts. The
1766 * first part describes a type of mesh entity and an id of discretization of a
1767 * current field part. The second part describes a range of values [begin,end)
1768 * within the returned array relating to the current field part.
1769 * \return DataArrayFloat * - the pointer to the field values array.
1770 * \throw If the number of underlying meshes is not equal to 1.
1771 * \throw If no field values are available.
1772 * \sa getUndergroundDataArray()
1774 DataArrayFloat *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayFloatExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1776 if(_field_per_mesh.size()!=1)
1777 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
1778 if(_field_per_mesh[0]==0)
1779 throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
1780 _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
1781 return getUndergroundDataArrayTemplate();
1784 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::shallowCpy() const
1786 MCAuto<MEDFileFloatField1TSWithoutSDA> ret(new MEDFileFloatField1TSWithoutSDA(*this));
1787 ret->deepCpyLeavesFrom(*this);
1791 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::deepCopy() const
1793 MCAuto<MEDFileFloatField1TSWithoutSDA> ret(shallowCpy());
1794 if(_arr.isNotNull())
1795 ret->_arr=_arr->deepCopy();
1799 //= MEDFileAnyTypeField1TS
1801 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
1805 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::AllocateContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order)
1807 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
1808 med_field_type typcha;
1809 std::vector<std::string> infos;
1810 std::string dtunit,meshName;
1813 std::string fName(fieldName);
1815 LocateField2(fid,0,true,fName,typcha,infos,dtunit,meshName);
1816 nbOfStep2=LocateField(fid,fName,iii,typcha,infos,dtunit,meshName);
1819 std::ostringstream oss; oss << "MEDFileField1TS(fid,fName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fName << "\' but there is no time steps on it !";
1820 throw INTERP_KERNEL::Exception(oss.str());
1827 ret=MEDFileField1TSWithoutSDA::New(fName,meshName,-1,iteration,order,std::vector<std::string>());
1832 ret=MEDFileInt32Field1TSWithoutSDA::New(fName,meshName,-1,iteration,order,std::vector<std::string>());
1837 ret=MEDFileInt64Field1TSWithoutSDA::New(fName,meshName,-1,iteration,order,std::vector<std::string>());
1842 ret=MEDFileFloatField1TSWithoutSDA::New(fName,meshName,-1,iteration,order,std::vector<std::string>());
1847 if(sizeof(med_int)==sizeof(int))
1849 ret=MEDFileInt32Field1TSWithoutSDA::New(fName,meshName,-1,iteration,order,std::vector<std::string>());
1855 std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::AllocateContentFrom(fid,fName,iteration,order) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32, MED_FLOAT32, MED_INT64] !";
1856 throw INTERP_KERNEL::Exception(oss.str());
1859 ret->setDtUnit(dtunit.c_str());
1860 ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
1862 // searching for timestep given in parameter
1864 std::vector< std::pair<int,int> > dtits(nbOfStep2);
1865 for(int i=0;i<nbOfStep2 && !found;i++)
1867 med_int numdt,numit;
1869 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fName.c_str(),i+1,&numdt,&numit,&dt));
1870 if (iteration==-1 && order==-1) // either no timestep were given, so we just stop at the first one
1874 ret->setTime(FromMedInt<int>(numdt),FromMedInt<int>(numit),dt);
1876 else if(numdt==iteration && numit==order) // or we found the correct timestep
1882 dtits[i]=std::pair<int,int>(numdt,numit);
1886 std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
1887 for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
1888 oss << "(" << (*iter).first << "," << (*iter).second << "), ";
1889 throw INTERP_KERNEL::Exception(oss.str());
1896 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
1898 std::string useless;
1899 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret(AllocateContentFrom(fid,useless));
1901 ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
1903 ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
1907 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
1909 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret(AllocateContentFrom(fid,fieldName));
1911 ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
1913 ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
1917 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
1919 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret(AllocateContentFrom(fid,fieldName,iteration,order));
1921 ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
1923 ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
1927 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, const PartDefinition *pd, const MEDFileEntities *entities)
1929 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret(AllocateContentFrom(fid,fieldName,iteration,order));
1930 ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),pd,entities);
1935 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
1936 try:MEDFileFieldGlobsReal(fid)
1938 _content=BuildContentFrom(fid,loadAll,ms,entities);
1941 catch(INTERP_KERNEL::Exception& e)
1946 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
1947 try:MEDFileFieldGlobsReal(fid)
1949 _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
1952 catch(INTERP_KERNEL::Exception& e)
1957 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
1958 try:MEDFileFieldGlobsReal(fid)
1960 _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms,entities);
1963 catch(INTERP_KERNEL::Exception& e)
1968 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
1971 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
1972 if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
1974 MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
1975 ret->_content=c; c->incrRef();
1978 if(dynamic_cast<const MEDFileInt32Field1TSWithoutSDA *>(c))
1980 MCAuto<MEDFileInt32Field1TS> ret(MEDFileInt32Field1TS::New());
1981 ret->_content=c; c->incrRef();
1984 if(dynamic_cast<const MEDFileInt64Field1TSWithoutSDA *>(c))
1986 MCAuto<MEDFileInt64Field1TS> ret(MEDFileInt64Field1TS::New());
1987 ret->_content=c; c->incrRef();
1990 if(dynamic_cast<const MEDFileFloatField1TSWithoutSDA *>(c))
1992 MCAuto<MEDFileFloatField1TS> ret(MEDFileFloatField1TS::New());
1993 ret->_content=c; c->incrRef();
1996 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
1999 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
2001 MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
2002 ret->setFileName(FileNameFromFID(fid));
2006 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
2008 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
2009 return New(fid,loadAll);
2012 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
2014 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0,0));
2015 MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
2016 ret->loadGlobals(fid);
2021 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
2023 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
2024 return New(fid,fieldName,loadAll);
2027 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
2029 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
2030 MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
2031 ret->loadGlobals(fid);
2035 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
2037 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
2038 return New(fid,fieldName,iteration,order,loadAll);
2041 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
2043 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,(const MEDFileMeshes *)0,0));
2044 MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
2045 ret->loadGlobals(fid);
2049 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
2051 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
2052 return NewAdv(fid,fieldName,iteration,order,loadAll,entities);
2055 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
2057 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,(const MEDFileMeshes *)0,entities));
2058 MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
2059 ret->loadGlobals(fid);
2064 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(med_idt fid, const std::string& fieldName, int iteration, int order, const MEDFileEntities *entities, const std::vector<mcIdType>& distrib)
2066 MCAuto<DataArrayIdType> listOfIds=DataArrayIdType::New();
2067 listOfIds->useArray(distrib.data(),false,DeallocType::C_DEALLOC,distrib.size(),1);
2068 MCAuto<PartDefinition> pd=PartDefinition::New(listOfIds);
2069 MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,pd,entities));
2070 MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
2071 ret->loadGlobals(fid);
2077 * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
2078 * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
2080 * \warning this is a shallow copy constructor
2082 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
2084 if(!shallowCopyOfContent)
2086 const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
2087 otherPtr->incrRef();
2088 _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
2092 _content=other.shallowCpy();
2096 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut, std::string& meshName)
2100 med_int nbFields=MEDnField(fid);
2101 if(fieldIdCFormat>=nbFields)
2103 std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
2104 throw INTERP_KERNEL::Exception(oss.str());
2107 med_int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
2108 INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
2109 INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
2110 INTERP_KERNEL::AutoPtr<char> dtunit(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
2111 INTERP_KERNEL::AutoPtr<char> nomcha(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2112 INTERP_KERNEL::AutoPtr<char> nomMaa(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2115 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
2116 fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
2117 dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
2118 meshName=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
2119 infos.clear(); infos.resize(ncomp);
2120 for(int j=0;j<ncomp;j++)
2121 infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
2122 return FromMedInt<int>(nbOfStep);
2126 * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
2128 * \return in case of success the number of time steps available for the field with name \a fieldName.
2130 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut, std::string& meshName)
2132 med_int nbFields=MEDnField(fid);
2134 std::vector<std::string> fns(nbFields);
2136 for(int i=0;i<nbFields && !found;i++)
2138 std::string tmp,tmp2;
2139 nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut,tmp2);
2141 found=(tmp==fieldName);
2150 std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
2151 for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
2152 oss << "\"" << *it << "\" ";
2153 throw INTERP_KERNEL::Exception(oss.str());
2159 * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
2160 * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
2161 * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
2162 * It is the responsibility of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
2163 * to keep a valid instance.
2164 * If \b this do not have any leaf that correspond to the request of the input parameter (\b mName, \b typ, \b locId) an INTERP_KERNEL::Exception will be thrown.
2165 * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
2166 * If \b newPflName already exists and that \b forceRenameOnGlob is false (the default) an INTERP_KERNEL::Exception will be thrown to avoid big confusion. In this case the called should rename before the profile name with name \b newPflName.
2168 * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
2169 * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
2170 * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of
2171 * \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
2172 * \param [in] newLocName is the new localization name.
2173 * \param [in] forceRenameOnGlob specifies the behaviour in case of profile \b newPflName already exists. If true, the renaming is done without check. It can lead to major bug.
2174 * If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
2176 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
2178 MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
2179 std::string oldPflName=disc->getProfile();
2180 std::vector<std::string> vv=getPflsReallyUsedMulti();
2181 std::size_t nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
2182 if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
2184 disc->setProfile(newPflName);
2185 DataArrayIdType *pfl=getProfile(oldPflName.c_str());
2186 pfl->setName(newPflName);
2190 std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
2191 throw INTERP_KERNEL::Exception(oss.str());
2196 * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
2197 * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
2198 * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
2199 * It is the responsibility of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
2200 * to keep a valid instance.
2201 * If \b this do not have any leaf that correspond to the request of the input parameter (\b mName, \b typ, \b locId) an INTERP_KERNEL::Exception will be thrown.
2202 * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
2203 * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
2204 * If \b newLocName already exists an INTERP_KERNEL::Exception will be thrown to avoid big confusion. In this case the called should rename before the profile name with name \b newLocName.
2206 * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
2207 * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
2208 * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of
2209 * \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
2210 * \param [in] newLocName is the new localization name.
2211 * \param [in] forceRenameOnGlob specifies the behaviour in case of profile \b newLocName already exists. If true, the renaming is done without check. It can lead to major bug.
2212 * If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
2214 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
2216 MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
2217 std::string oldLocName=disc->getLocalization();
2218 std::vector<std::string> vv=getLocsReallyUsedMulti();
2219 std::size_t nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
2220 if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
2222 disc->setLocalization(newLocName);
2223 MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
2224 loc.setName(newLocName);
2228 std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
2229 throw INTERP_KERNEL::Exception(oss.str());
2233 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
2235 MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
2237 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
2241 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
2243 const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
2245 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
2250 * This method alloc the arrays and load potentially huge arrays contained in this field.
2251 * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
2252 * This method can be also called to refresh or reinit values from a file.
2254 * \throw If the fileName is not set or points to a non readable MED file.
2255 * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
2257 void MEDFileAnyTypeField1TS::loadArrays()
2259 if(getFileName().empty())
2260 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
2261 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
2262 contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
2266 * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
2267 * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
2268 * this method does not throw if \a this does not come from file read.
2270 * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
2272 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
2274 if(!getFileName().empty())
2276 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
2277 contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
2282 * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
2283 * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
2284 * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
2286 * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
2288 void MEDFileAnyTypeField1TS::unloadArrays()
2290 contentNotNullBase()->unloadArrays();
2294 * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
2295 * This method is the symmetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
2296 * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
2298 * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
2300 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
2302 if(!getFileName().empty())
2303 contentNotNullBase()->unloadArrays();
2306 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
2308 std::size_t nbComp(getNumberOfComponents());
2309 INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
2310 INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
2311 for(std::size_t i=0;i<nbComp;i++)
2313 std::string info=getInfo()[i];
2315 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
2316 MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
2317 MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
2319 if(getName().empty())
2320 throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
2321 MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),ToMedInt(nbComp),comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
2322 writeGlobals(fid,*this);
2323 contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
2326 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
2328 return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
2331 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
2333 std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
2334 ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
2339 * Returns a string describing \a this field. This string is outputted
2340 * by \c print Python command.
2342 std::string MEDFileAnyTypeField1TS::simpleRepr() const
2344 std::ostringstream oss;
2345 contentNotNullBase()->simpleRepr(0,oss,-1);
2346 simpleReprGlobs(oss);
2351 * This method returns all profiles whose name is non empty used.
2352 * \b WARNING If profile is used several times it will be reported \b only \b once.
2353 * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
2355 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
2357 return contentNotNullBase()->getPflsReallyUsed2();
2361 * This method returns all localizations whose name is non empty used.
2362 * \b WARNING If localization is used several times it will be reported \b only \b once.
2364 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
2366 return contentNotNullBase()->getLocsReallyUsed2();
2370 * This method returns all profiles whose name is non empty used.
2371 * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
2373 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
2375 return contentNotNullBase()->getPflsReallyUsedMulti2();
2379 * This method returns all localizations whose name is non empty used.
2380 * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
2382 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
2384 return contentNotNullBase()->getLocsReallyUsedMulti2();
2387 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2389 contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
2392 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2394 contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
2397 int MEDFileAnyTypeField1TS::getDimension() const
2399 return contentNotNullBase()->getDimension();
2402 int MEDFileAnyTypeField1TS::getIteration() const
2404 return contentNotNullBase()->getIteration();
2407 int MEDFileAnyTypeField1TS::getOrder() const
2409 return contentNotNullBase()->getOrder();
2412 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
2414 return contentNotNullBase()->getTime(iteration,order);
2417 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
2419 contentNotNullBase()->setTime(iteration,order,val);
2422 std::string MEDFileAnyTypeField1TS::getName() const
2424 return contentNotNullBase()->getName();
2427 void MEDFileAnyTypeField1TS::setName(const std::string& name)
2429 contentNotNullBase()->setName(name);
2432 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
2434 contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
2437 std::string MEDFileAnyTypeField1TS::getDtUnit() const
2439 return contentNotNullBase()->getDtUnit();
2442 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
2444 contentNotNullBase()->setDtUnit(dtUnit);
2447 std::string MEDFileAnyTypeField1TS::getMeshName() const
2449 return contentNotNullBase()->getMeshName();
2452 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
2454 contentNotNullBase()->setMeshName(newMeshName);
2457 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2459 return contentNotNullBase()->changeMeshNames(modifTab);
2462 int MEDFileAnyTypeField1TS::getMeshIteration() const
2464 return contentNotNullBase()->getMeshIteration();
2467 int MEDFileAnyTypeField1TS::getMeshOrder() const
2469 return contentNotNullBase()->getMeshOrder();
2472 std::size_t MEDFileAnyTypeField1TS::getNumberOfComponents() const
2474 return contentNotNullBase()->getNumberOfComponents();
2477 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
2479 return contentNotNullBase()->isDealingTS(iteration,order);
2482 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
2484 return contentNotNullBase()->getDtIt();
2487 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
2489 contentNotNullBase()->fillIteration(p);
2492 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
2494 contentNotNullBase()->fillTypesOfFieldAvailable(types);
2497 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
2499 contentNotNullBase()->setInfo(infos);
2502 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
2504 return contentNotNullBase()->getInfo();
2506 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
2508 return contentNotNullBase()->getInfo();
2511 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
2513 return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
2516 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
2518 return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
2521 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
2523 return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
2526 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
2528 return contentNotNullBase()->getNonEmptyLevels(mname,levs);
2531 void MEDFileAnyTypeField1TS::convertMedBallIntoClassic()
2533 return contentNotNullBase()->convertMedBallIntoClassic();
2536 void MEDFileAnyTypeField1TS::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayIdType *pfl)
2538 return contentNotNullBase()->makeReduction(ct,tof,pfl);
2541 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
2543 return contentNotNullBase()->getTypesOfFieldAvailable();
2546 std::vector< std::vector<std::pair<mcIdType,mcIdType> > > MEDFileAnyTypeField1TS::getFieldSplitedByType(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
2547 std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
2549 return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
2553 * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
2554 * The returned instances are deep copy of \a this except that for globals that are shared with those contained in \a this.
2555 * ** WARNING ** do no forget to rename the output instances to avoid to write n-times in the same MED file field !
2557 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
2559 const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
2561 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
2562 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
2563 std::size_t sz(contentsSplit.size());
2564 std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
2565 for(std::size_t i=0;i<sz;i++)
2567 ret[i]=shallowCpy();
2568 ret[i]->_content=contentsSplit[i];
2574 * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
2575 * The returned instances are shallowed copied of \a this except that for globals that are shared with those contained in \a this.
2577 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
2579 const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
2581 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
2582 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
2583 std::size_t sz(contentsSplit.size());
2584 std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
2585 for(std::size_t i=0;i<sz;i++)
2587 ret[i]=shallowCpy();
2588 ret[i]->_content=contentsSplit[i];
2594 * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
2595 * The returned instances are shallowed copied of \a this except that for globals that are shared with those contained in \a this.
2597 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
2599 const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
2601 throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
2602 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
2603 std::size_t sz(contentsSplit.size());
2604 std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
2605 for(std::size_t i=0;i<sz;i++)
2607 ret[i]=shallowCpy();
2608 ret[i]->_content=contentsSplit[i];
2613 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
2615 MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
2616 if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
2617 ret->_content=_content->deepCopy();
2618 ret->deepCpyGlobs(*this);
2622 mcIdType MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
2624 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
2625 return copyTinyInfoFrom(field->timeDiscrSafe(),ft,arr);
2628 mcIdType MEDFileAnyTypeField1TS::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
2630 return contentNotNullBase()->copyTinyInfoFrom(th,field,arr);
2636 * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
2637 * following the given input policy.
2639 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
2640 * By default (true) the globals are deeply copied.
2641 * \return MEDFileInt32Field1TS * - a new object that is the result of the conversion of \a this to int32 field.
2643 MEDFileInt32Field1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
2645 MCAuto<MEDFileInt32Field1TS> ret;
2646 const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
2649 const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
2651 throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
2652 MCAuto<MEDFileInt32Field1TSWithoutSDA> newc(contc->convertToInt());
2653 ret=static_cast<MEDFileInt32Field1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileInt32Field1TSWithoutSDA *)newc));
2656 ret=MEDFileInt32Field1TS::New();
2658 ret->deepCpyGlobs(*this);
2660 ret->shallowCpyGlobs(*this);
2665 * This method performs a copy with datatype modification ( float64->int64 ) of \a this. The globals information are copied
2666 * following the given input policy.
2668 * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
2669 * By default (true) the globals are deeply copied.
2670 * \return MEDFileInt32Field1TS * - a new object that is the result of the conversion of \a this to int64 field.
2672 MEDFileInt64Field1TS *MEDFileField1TS::convertToInt64(bool isDeepCpyGlobs) const
2674 MCAuto<MEDFileInt64Field1TS> ret;
2675 const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
2678 const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
2680 throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
2681 MCAuto<MEDFileInt64Field1TSWithoutSDA> newc(contc->convertToInt64());
2682 ret=static_cast<MEDFileInt64Field1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileInt64Field1TSWithoutSDA *)newc));
2685 ret=MEDFileInt64Field1TS::New();
2687 ret->deepCpyGlobs(*this);
2689 ret->shallowCpyGlobs(*this);
2693 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
2694 try:MEDFileTemplateField1TS<double>(fid,loadAll,ms)
2697 catch(INTERP_KERNEL::Exception& e)
2700 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
2701 try:MEDFileTemplateField1TS<double>(fid,fieldName,loadAll,ms)
2704 catch(INTERP_KERNEL::Exception& e)
2707 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
2708 try:MEDFileTemplateField1TS<double>(fid,fieldName,iteration,order,loadAll,ms)
2711 catch(INTERP_KERNEL::Exception& e)
2715 * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
2716 * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
2718 * \warning this is a shallow copy constructor
2720 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
2721 try:MEDFileTemplateField1TS<double>(other,shallowCopyOfContent)
2724 catch(INTERP_KERNEL::Exception& e)
2727 MCAuto<MEDFileAnyTypeField1TS> MEDFileField1TS::buildNewEmpty() const
2729 return MCAuto<MEDFileAnyTypeField1TS>(MEDFileField1TS::New());
2732 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
2734 return new MEDFileField1TS(*this);
2737 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
2738 std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
2740 return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
2743 //= MEDFileInt32Field1TS
2745 MCAuto<MEDFileAnyTypeField1TS> MEDFileInt32Field1TS::buildNewEmpty() const
2747 return MCAuto<MEDFileAnyTypeField1TS>(MEDFileInt32Field1TS::New());
2750 MCAuto<MEDCouplingFieldDouble> MEDFileInt32Field1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt32 *f)
2753 throw INTERP_KERNEL::Exception("MEDFileInt32Field1TS::ConvertFieldIntToFieldDouble : null input field !");
2755 double t0(f->getTime(t1,t2));
2756 std::string tu(f->getTimeUnit());
2757 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
2758 MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
2759 ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
2763 //= MEDFileInt64Field1TS
2765 MCAuto<MEDFileAnyTypeField1TS> MEDFileInt64Field1TS::buildNewEmpty() const
2767 return MCAuto<MEDFileAnyTypeField1TS>(MEDFileInt64Field1TS::New());
2770 MCAuto<MEDCouplingFieldDouble> MEDFileInt64Field1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt64 *f)
2773 throw INTERP_KERNEL::Exception("MEDFileInt64Field1TS::ConvertFieldIntToFieldDouble : null input field !");
2775 double t0(f->getTime(t1,t2));
2776 std::string tu(f->getTimeUnit());
2777 MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
2778 MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
2779 ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
2783 //= MEDFileFloatField1TS
2785 MCAuto<MEDFileAnyTypeField1TS> MEDFileFloatField1TS::buildNewEmpty() const
2787 return MCAuto<MEDFileAnyTypeField1TS>(MEDFileFloatField1TS::New());