1 // Copyright (C) 2017-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #include "MEDFileFieldInternal.hxx"
22 #include "MEDFileField.hxx"
23 #include "MEDFileFieldVisitor.hxx"
24 #include "MEDFileStructureElement.hxx"
25 #include "MEDLoaderBase.hxx"
26 #include "MEDFileSafeCaller.txx"
27 #include "MEDFileEntities.hxx"
29 #include "MEDCouplingGaussLocalization.hxx"
30 #include "MEDCouplingFieldTemplate.hxx"
31 #include "MEDCouplingFieldDouble.hxx"
33 #include "CellModel.hxx"
35 // From MEDLOader.cxx TU
36 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
37 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
38 extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
40 using namespace MEDCoupling;
42 MEDFileGTKeeper::~MEDFileGTKeeper()
46 MEDFileGTKeeper *MEDFileGTKeeperSta::deepCopy() const
48 return new MEDFileGTKeeperSta(_geo_type);
51 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperSta::getGeoType() const
56 std::string MEDFileGTKeeperSta::getRepr() const
58 return INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr();
61 bool MEDFileGTKeeperSta::isEqual(const MEDFileGTKeeper *other) const
63 const MEDFileGTKeeperSta *otherC(dynamic_cast<const MEDFileGTKeeperSta *>(other));
66 return _geo_type==otherC->_geo_type;
69 MEDFileGTKeeperDyn::MEDFileGTKeeperDyn(const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileStructureElement *se):_mesh(mesh),_section(section),_se(se)
77 if(_mesh.isNull() || _section.isNull() || _se.isNull())
78 throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn constructor : null pointer not allowed !");
81 MEDFileGTKeeper *MEDFileGTKeeperDyn::deepCopy() const
83 return new MEDFileGTKeeperDyn(_mesh,_section,_se);
86 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperDyn::getGeoType() const
88 throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn::getGeoType : not valid !");
91 std::string MEDFileGTKeeperDyn::getRepr() const
93 std::ostringstream oss;
94 oss << _se->getDynGT();
98 bool MEDFileGTKeeperDyn::isEqual(const MEDFileGTKeeper *other) const
100 const MEDFileGTKeeperDyn *otherC(dynamic_cast<const MEDFileGTKeeperDyn *>(other));
106 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
108 return new MEDFileFieldLoc(fid,locName);
111 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id, const MEDFileEntities *entities)
113 return new MEDFileFieldLoc(fid,id,entities);
116 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
118 return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
121 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
123 med_geometry_type geotype;
124 med_geometry_type sectiongeotype;
125 med_int nsectionmeshcell, dim, nb_gauss_pt;
126 INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
127 INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
128 MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&dim,&nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,§iongeotype);
129 _dim=FromMedInt<int>(dim);
130 _nb_gauss_pt=FromMedInt<int>(nb_gauss_pt);
131 _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+INTERP_KERNEL::NORM_MAXTYPE,geotype))));
132 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
133 _nb_node_per_cell=cm.getNumberOfNodes();
134 _ref_coo.resize(_dim*_nb_node_per_cell);
135 _gs_coo.resize(_dim*_nb_gauss_pt);
136 _w.resize(_nb_gauss_pt);
137 MEDFILESAFECALLERRD0(MEDlocalizationRd,(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]));
140 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id, const MEDFileEntities *entities)
142 med_geometry_type geotype;
143 med_geometry_type sectiongeotype;
144 med_int nsectionmeshcell,dim,nb_gauss_pt;
145 INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
146 INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
147 INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
148 MEDFILESAFECALLERRD0(MEDlocalizationInfo,(fid,id+1,locName,&geotype,&dim,&nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,§iongeotype));
149 _dim=FromMedInt<int>(dim);
150 _nb_gauss_pt=FromMedInt<int>(nb_gauss_pt);
152 std::string sectionName(MEDLoaderBase::buildStringFromFortran(sectionmeshname,MED_NAME_SIZE));
153 if(sectionName.empty())
155 _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+INTERP_KERNEL::NORM_MAXTYPE,geotype))));
156 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
157 _nb_node_per_cell=cm.getNumberOfNodes();
161 const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
164 std::ostringstream oss; oss << "MEDFileFieldLoc cstr : for loc \"" << _name << "\" presence of non static type ! Expect entities !";
165 throw INTERP_KERNEL::Exception(oss.str());
167 const MEDFileStructureElement *se(entities2->getWithGT(geotype));
168 const MEDFileUMesh *um(entities2->getSupMeshWithName(se->getMeshName()));
169 const MEDFileUMesh *section(entities2->getSupMeshWithName(sectionName));
170 _gt=new MEDFileGTKeeperDyn(um,section,se);
172 med_int dummy, nb_node_per_cell;
173 MEDFILESAFECALLERRD0(MEDmeshGeotypeParameter,(fid,geotype,&dummy,&nb_node_per_cell));
174 _nb_node_per_cell=FromMedInt<int>(nb_node_per_cell);
177 _ref_coo.resize(_dim*_nb_node_per_cell);
178 _gs_coo.resize(_dim*_nb_gauss_pt);
179 _w.resize(_nb_gauss_pt);
180 MEDFILESAFECALLERRD0(MEDlocalizationRd,(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]));
183 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
184 const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_gt(new MEDFileGTKeeperSta(geoType)),_name(locName),_ref_coo(refCoo),_gs_coo(gsCoo),_w(w)
186 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
187 _dim=cm.getDimension();
188 _nb_node_per_cell=cm.getNumberOfNodes();
189 _nb_gauss_pt=(int)_w.size();
193 MEDFileFieldLoc::MEDFileFieldLoc(const MEDFileFieldLoc& other):_dim(other._dim),_nb_gauss_pt(other._nb_gauss_pt),_gt(other._gt->deepCopy()),_nb_node_per_cell(other._nb_node_per_cell),_name(other._name),_ref_coo(other._ref_coo),_gs_coo(other._gs_coo),_w(other._w)
197 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
199 return new MEDFileFieldLoc(*this);
202 bool MEDFileFieldLoc::isOnStructureElement() const
204 const MEDFileGTKeeper *gt(_gt);
206 throw INTERP_KERNEL::Exception("MEDFileFieldLoc::isOnStructureElement : null pointer !");
207 const MEDFileGTKeeperDyn *gt2(dynamic_cast<const MEDFileGTKeeperDyn *>(gt));
211 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
213 return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
216 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
218 return std::vector<const BigMemoryObject *>();
221 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
223 static const char OFF7[]="\n ";
224 oss << "\"" << _name << "\"" << OFF7;
225 oss << "GeoType=" << _gt->getRepr() << OFF7;
226 oss << "Dimension=" << _dim << OFF7;
227 oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
228 oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
229 oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
230 oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
231 oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
234 void MEDFileFieldLoc::setName(const std::string& name)
239 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
241 if(_name!=other._name)
245 if(_nb_gauss_pt!=other._nb_gauss_pt)
247 if(_nb_node_per_cell!=other._nb_node_per_cell)
249 if(!_gt->isEqual(other._gt))
251 if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
253 if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
255 if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
261 void MEDFileFieldLoc::writeLL(med_idt fid) const
263 MEDFILESAFECALLERWR0(MEDlocalizationWr,(fid,_name.c_str(),typmai3[(int)getGeoType()],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT));
266 std::string MEDFileFieldLoc::repr() const
268 std::ostringstream oss; oss.precision(15);
269 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
270 oss << "Localization \"" << _name << "\" :\n" << " - Geometric Type : " << cm.getRepr();
271 oss << "\n - Dimension : " << _dim << "\n - Number of gauss points : ";
272 oss << _nb_gauss_pt << "\n - Number of nodes in cell : " << _nb_node_per_cell;
273 oss << "\n - Ref coords are : ";
274 std::size_t sz=_ref_coo.size();
277 std::size_t nbOfTuples=sz/_dim;
278 for(std::size_t i=0;i<nbOfTuples;i++)
281 for(int j=0;j<_dim;j++)
282 { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
287 std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
288 oss << "\n - Gauss coords in reference element : ";
292 std::size_t nbOfTuples=sz/_dim;
293 for(std::size_t i=0;i<nbOfTuples;i++)
296 for(int j=0;j<_dim;j++)
297 { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
302 std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
303 oss << "\n - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
307 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(mcIdType& start, mcIdType offset, mcIdType nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
309 _type=field->getTypeOfField();
315 getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
316 _end=_start+nbOfCells;
322 MCAuto<DataArrayIdType> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
323 const mcIdType *arrPtr=arr->getConstPointer();
324 getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
325 _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
331 const MEDCouplingFieldDiscretization *disc(field->getDiscretization());
332 const MEDCouplingGaussLocalization& gsLoc(field->getGaussLocalization(FromIdType<int>(_loc_id)));
333 const MEDCouplingFieldDiscretizationGauss *disc2(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc));
335 throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
336 const DataArrayIdType *dai(disc2->getArrayOfDiscIds());
337 MCAuto<DataArrayIdType> dai2(disc2->getOffsetArr(field->getMesh()));
338 const mcIdType *dai2Ptr(dai2->getConstPointer());
339 mcIdType nbi(ToIdType(gsLoc.getWeights().size()));
340 MCAuto<DataArrayIdType> da2(dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1));
341 MCAuto<DataArrayIdType> da3(da2->findIdsEqual(_loc_id));
342 const mcIdType *da3Ptr(da3->getConstPointer());
343 if(da3->getNumberOfTuples()!=nbOfCells)
344 {//profile : for gauss even in NoProfile !!!
345 std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
347 da3->setName(_profile.c_str());
348 glob.appendProfile(da3);
350 MCAuto<DataArrayIdType> da4(DataArrayIdType::New());
351 _nval=da3->getNbOfElems();
352 da4->alloc(_nval*nbi,1);
353 mcIdType *da4Ptr(da4->getPointer());
354 for(mcIdType i=0;i<_nval;i++)
356 mcIdType ref=dai2Ptr[offset+da3Ptr[i]];
357 for(mcIdType j=0;j<nbi;j++)
360 std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
361 _localization=oss2.str();
362 getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
363 _end=_start+_nval*nbi;
364 glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
368 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
374 * Leaf method of field with profile assignment. This method is the most general one. No optimization is done here.
375 * \param [in] isPflAlone whether there are several profiles or not
376 * \param [in] start starting ID
377 * \param [in] multiTypePfl is the end user profile specified in high level API
378 * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
379 * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
380 * \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
381 * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondence with the MEDFileField. The mesh inside the \a field is simply ignored.
383 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, mcIdType& start, const DataArrayIdType *multiTypePfl, const DataArrayIdType *idsInPfl, DataArrayIdType *locIds, mcIdType nbOfEltsInWholeMesh, const MEDCouplingFieldTemplate *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
386 _type=field->getTypeOfField();
387 std::string pflName(multiTypePfl->getName());
388 std::ostringstream oss; oss << pflName;
392 { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" << cm.getRepr(); }
399 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
400 if(_type!=ON_GAUSS_PT)
402 locIds->setName(oss.str());
403 glob.appendProfile(locIds);
412 _nval=idsInPfl->getNumberOfTuples();
413 getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
419 _nval=idsInPfl->getNumberOfTuples();
420 getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
426 MCAuto<DataArrayIdType> arr=field->getDiscretization()->getOffsetArr(mesh);
427 MCAuto<DataArrayIdType> arr2=arr->deltaShiftIndex();
428 MCAuto<DataArrayIdType> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
429 arr3->computeOffsetsFull();
430 MCAuto<DataArrayIdType> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
431 mcIdType trueNval=tmp->getNumberOfTuples();
432 _nval=idsInPfl->getNumberOfTuples();
433 getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
434 _end=_start+trueNval;
439 const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
441 throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
442 const DataArrayIdType *da1=disc2->getArrayOfDiscIds();
443 const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(FromIdType<int>(_loc_id));
444 MCAuto<DataArrayIdType> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
445 MCAuto<DataArrayIdType> da3=da2->findIdsEqual(_loc_id);
446 MCAuto<DataArrayIdType> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
448 MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
449 MCAuto<DataArrayIdType> arr=disc2->getOffsetArr(mesh2);
451 MCAuto<DataArrayIdType> tmp=DataArrayIdType::New();
453 for(const mcIdType *pt=da4->begin();pt!=da4->end();pt++)
454 trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
455 tmp->alloc(trueNval,1);
456 mcIdType *tmpPtr=tmp->getPointer();
457 for(const mcIdType *pt=da4->begin();pt!=da4->end();pt++)
458 for(mcIdType j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
461 _nval=da4->getNumberOfTuples();
462 getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
463 _end=_start+trueNval;
464 oss << "_loc_" << _loc_id;
467 MCAuto<DataArrayIdType> da5=locIds->selectByTupleId(da3->begin(),da3->end());
468 da5->setName(oss.str());
469 glob.appendProfile(da5);
474 if(!da3->isIota(nbOfEltsInWholeMesh))
476 da3->setName(oss.str());
477 glob.appendProfile(da3);
481 std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
482 _localization=oss2.str();
483 glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
487 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
492 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(mcIdType& start, const MEDCouplingFieldTemplate *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
495 _nval=arrr->getNumberOfTuples();
496 getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
501 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
503 return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
506 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, mcIdType locId)
508 return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
511 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
513 return new MEDFileFieldPerMeshPerTypePerDisc(other);
516 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
518 return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
521 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
523 std::vector<const BigMemoryObject *> ret(1);
524 ret[0]=(const PartDefinition*)_pd;
528 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const
530 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(*this));
535 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField atype, mcIdType profileIt, const PartDefinition *pd)
536 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
541 catch(INTERP_KERNEL::Exception& e)
546 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, mcIdType locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
550 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_profile_it(other._profile_it),_pd(other._pd),_tmp_work1(other._tmp_work1)
554 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<mcIdType>::max()),_end(-std::numeric_limits<mcIdType>::max()),
555 _nval(-std::numeric_limits<mcIdType>::max()),_loc_id(-std::numeric_limits<int>::max())
559 void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const std::string& fieldName, int nbOfCompo, int iteration, int order, med_entity_type menti, med_geometry_type mgeoti, unsigned char *startFeedingPtr)
561 const PartDefinition *pd(_pd);
564 med_entity_type mentiCpy(menti);
565 INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
567 med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
568 if(nbValsInFile==0 && menti==MED_CELL)
570 nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_FACE,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
573 nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_EDGE,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
575 { mentiCpy=MED_DESCENDING_EDGE; }
578 { mentiCpy=MED_DESCENDING_FACE; }
580 if(_end-_start!=nbValsInFile*nbi)
582 std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi << " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
583 throw INTERP_KERNEL::Exception(oss.str());
585 MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,mentiCpy,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
589 if(!_profile.empty())
590 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
591 INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
592 med_int profilesize,nbi;
593 med_int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,FromIdType<int>(_profile_it+1),MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
594 const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
597 mcIdType start,stop,step;
598 spd->getSlice(start,stop,step);
599 mcIdType nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
600 med_filter filter=MED_FILTER_INIT;
601 MEDFILESAFECALLERRD0(MEDfilterBlockOfEntityCr,(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
602 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
603 /*start*/ToMedInt(start+1),/*stride*/ToMedInt(step),/*count*/1,/*blocksize*/ToMedInt(nbOfEltsToLoad),
604 /*lastblocksize=useless because count=1*/0,&filter));
605 MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
606 MEDfilterClose(&filter);
609 const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
612 dpd->checkConsistencyLight();
613 MCAuto<DataArrayIdType> myIds(dpd->toDAI());
614 mcIdType a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
615 myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
616 myIds->applyLin(1,-a);
617 mcIdType nbOfEltsToLoad(b-a+1);
618 med_filter filter=MED_FILTER_INIT;
619 {//TODO : manage int32 !
620 MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
621 tmp->alloc(nbOfEltsToLoad,nbOfCompo);
622 MEDFILESAFECALLERRD0(MEDfilterBlockOfEntityCr,(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
623 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
624 /*start*/ToMedInt(a+1),/*stride*/1,/*count*/1,/*blocksize*/ToMedInt(nbOfEltsToLoad),
625 /*lastblocksize=useless because count=1*/0,&filter));
626 MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
627 MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
628 feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
629 feeder->setContigPartOfSelectedValues(0,tmp,myIds);
631 MEDfilterClose(&filter);
634 throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
638 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
643 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, mcIdType& start, const MEDFileFieldNameScope& nasc)
645 INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
646 INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
647 std::string fieldName(nasc.getName()),meshName(getMeshName());
648 med_int iteration(getIteration()),order(getOrder()),profilesize,nbi;
649 TypeOfField type(getType());
650 med_geometry_type mgeoti;
651 med_entity_type menti;
652 _father->entriesForMEDfile(type,mgeoti,menti);
653 med_int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,FromIdType<int>(_profile_it+1),MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
654 if(zeNVal==0 && type==ON_CELLS)
655 {//eheh maybe there's a surprise :)
656 med_int zeNVal1(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_FACE,mgeoti,FromIdType<int>(_profile_it+1),MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
659 med_int zeNVal2(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_EDGE,mgeoti,FromIdType<int>(_profile_it+1),MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
668 _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
669 _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
670 const PartDefinition *pd(_pd);
677 if(!_profile.empty())
678 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
679 _nval=pd->getNumberOfElems();
682 _end=start+_nval*nbi;
684 if(type==ON_CELLS && !_localization.empty())
686 if(_localization!="MED_GAUSS_ELNO")//For compatibility with MED2.3
687 setType(ON_GAUSS_PT);
690 setType(ON_GAUSS_NE);
691 _localization.clear();
696 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
698 std::string fieldName(nasc.getName()),meshName(getMeshName());
699 int iteration(getIteration()),order(getOrder());
700 TypeOfField type(getType());
701 med_geometry_type mgeoti;
702 med_entity_type menti;
703 _father->entriesForMEDfile(type,mgeoti,menti);
705 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
708 DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
709 if(_start<0 || _start>=arr->getNumberOfTuples())
711 std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
712 throw INTERP_KERNEL::Exception(oss.str());
714 if(_end<0 || _end>arr->getNumberOfTuples())
716 std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
717 throw INTERP_KERNEL::Exception(oss.str());
719 int nbOfCompo((int)arr->getNumberOfComponents());
720 DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
723 double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
724 goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
727 DataArrayInt32 *arrI(dynamic_cast<DataArrayInt32 *>(arr));
730 Int32 *startFeeding(arrI->getPointer()+_start*nbOfCompo);
731 goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
734 DataArrayInt64 *arrI64(dynamic_cast<DataArrayInt64 *>(arr));
737 Int64 *startFeeding(arrI64->getPointer()+_start*nbOfCompo);
738 goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
741 DataArrayFloat *arrF(dynamic_cast<DataArrayFloat *>(arr));
744 float *startFeeding(arrF->getPointer()+_start*nbOfCompo);
745 goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
748 throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 FLOAT32 INT32 or INT64 !");
752 * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
754 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(mcIdType newValueOfStart)
756 mcIdType delta=_end-_start;
757 _start=newValueOfStart;
761 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
763 return _father->getIteration();
766 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
768 return _father->getOrder();
771 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
773 return _father->getTime();
776 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
778 return _father->getMeshName();
781 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
783 const char startLine[]=" ## ";
784 std::string startLine2(bkOffset,' ');
785 startLine2+=startLine;
786 INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
787 oss << startLine2 << "Localization #" << id << "." << std::endl;
788 oss << startLine2 << " Type=" << tmp->getRepr() << "." << std::endl;
789 oss << startLine2 << " This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
790 oss << startLine2 << " This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
791 oss << startLine2 << " This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
794 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
799 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
801 return _father->getGeoType();
804 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoTypeStatic() const
806 return _father->getGeoTypeStatic();
809 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
814 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
819 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
821 return _father->getNumberOfComponents();
824 mcIdType MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
829 void MEDFileFieldPerMeshPerTypePerDisc::incrementNbOfVals(mcIdType deltaNbVal)
831 mcIdType nbi((_end-_start)/_nval);
833 _end+=nbi*deltaNbVal;
836 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
838 return _father->getOrCreateAndGetArray();
841 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
843 const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
844 return fath->getOrCreateAndGetArray();
847 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
849 return _father->getInfo();
852 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
857 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
862 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
864 return _localization;
867 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
869 _localization=newLocName;
872 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
874 for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
876 if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
878 _profile=(*it2).second;
884 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
886 for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
888 if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
890 _localization=(*it2).second;
896 void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<mcIdType,mcIdType> >& dads, std::vector<const DataArrayIdType *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
900 dads.push_back(std::pair<mcIdType,mcIdType>(_start,_end));
901 geoTypes.push_back(getGeoType());
906 pfls.push_back(glob->getProfile(_profile.c_str()));
908 if(_localization.empty())
912 locs.push_back(glob->getLocalizationId(_localization.c_str()));
916 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, mcIdType& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
918 entries[startEntryId]=std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,mcIdType> ,std::pair<mcIdType,mcIdType> >(std::pair<INTERP_KERNEL::NormalizedCellType,mcIdType>(getGeoType(),discId),std::pair<mcIdType,mcIdType>(_start,_end));
922 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
924 med_geometry_type mgeoti;
925 med_entity_type menti;
926 _father->entriesForMEDfile(getType(),mgeoti,menti);
927 const DataArray *arr(getOrCreateAndGetArray());
929 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
930 if(!arr->isAllocated())
931 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
932 const DataArrayDouble *arrD(dynamic_cast<const DataArrayDouble *>(arr));
933 const DataArrayInt32 *arrI(dynamic_cast<const DataArrayInt32 *>(arr));
934 const DataArrayInt64 *arrI64(dynamic_cast<const DataArrayInt64 *>(arr));
935 const DataArrayFloat *arrF(dynamic_cast<const DataArrayFloat *>(arr));
936 const unsigned char *locToWrite=0;
938 locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
940 locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
942 locToWrite=reinterpret_cast<const unsigned char *>(arrI64->getConstPointer()+_start*arr->getNumberOfComponents());
944 locToWrite=reinterpret_cast<const unsigned char *>(arrF->getConstPointer()+_start*arr->getNumberOfComponents());
946 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 FLOAT32 INT32 and INT64 !");
947 MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
948 MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,ToMedInt(_nval),
952 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<mcIdType,mcIdType>& dad, std::string& pfl, std::string& loc) const
957 dad.first=_start; dad.second=_end;
961 * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
962 * This code corresponds to the distribution of types in the corresponding mesh.
963 * \param [out] ptToFill memory zone where the output will be stored.
964 * \return the size of data pushed into output param \a ptToFill
966 mcIdType MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(mcIdType offset, const std::vector<mcIdType>& codeOfMesh, const MEDFileFieldGlobsReal& glob, mcIdType *ptToFill) const
968 _loc_id=FromIdType<int>(offset);
969 std::ostringstream oss;
970 std::size_t nbOfType=codeOfMesh.size()/3;
972 for(std::size_t i=0;i<nbOfType && found==-1;i++)
973 if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
977 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
978 oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
979 throw INTERP_KERNEL::Exception(oss.str());
981 mcIdType *work=ptToFill;
984 if(_nval!=codeOfMesh[3*found+1])
986 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
987 oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
988 oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
989 throw INTERP_KERNEL::Exception(oss.str());
991 for(mcIdType ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
996 const DataArrayIdType *pfl=glob.getProfile(_profile.c_str());
997 if(pfl->getNumberOfTuples()!=_nval)
999 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
1000 oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
1002 oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
1003 throw INTERP_KERNEL::Exception(oss.str());
1005 mcIdType offset2=codeOfMesh[3*found+2];
1006 for(const mcIdType *pflId=pfl->begin();pflId!=pfl->end();pflId++)
1008 if(*pflId<codeOfMesh[3*found+1])
1009 *work++=offset2+*pflId;
1015 mcIdType MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(mcIdType *ptToFill) const
1017 for(mcIdType i=_start;i<_end;i++)
1022 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, mcIdType locId)
1031 return FromIdType<int>(locId);
1033 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
1037 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
1040 std::map<std::pair<std::string,TypeOfField>,int> m;
1041 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
1042 for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
1043 if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
1044 m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
1046 for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
1047 ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
1052 * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
1054 * \param [in] offset the offset id used to take into account that \a result is not compulsory empty in input
1055 * \param [in] entriesOnSameDisc some entries **on same localization** if not the result can be invalid. The _start and _end on them are relative to \a arr parameter.
1056 * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
1057 * \param [in] newCode one of the input parameter to explicit the new geo type dispatch (in classical format same than those asked by MEDFileFields::renumberEntitiesLyingOnMesh)
1058 * \param [in,out] glob if necessary by the method, new profiles can be added to it
1059 * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
1060 * \param [out] result All new entries will be appended on it.
1061 * \return false if the configuration of renumbering leads to an unnecessary resplit of input \a entriesOnSameDisc. If not true is returned (the most general case !)
1063 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(mcIdType offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1064 const DataArrayIdType *explicitIdsInMesh,
1065 const std::vector<mcIdType>& newCode,
1066 MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
1067 std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
1069 if(entriesOnSameDisc.empty())
1071 TypeOfField type=entriesOnSameDisc[0]->getType();
1072 mcIdType szEntities=0,szTuples=0;
1073 for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
1074 { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
1075 mcIdType nbi=szTuples/szEntities;
1076 if(szTuples%szEntities!=0)
1077 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
1078 MCAuto<DataArrayIdType> renumTuples=DataArrayIdType::New(); renumTuples->alloc(szTuples,1);
1079 MCAuto<DataArrayIdType> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
1080 std::vector< MCAuto<DataArrayIdType> > newGeoTypesPerChunk(entriesOnSameDisc.size());
1081 std::vector< const DataArrayIdType * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
1082 std::vector< MCAuto<DataArrayIdType> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
1083 std::vector< const DataArrayIdType * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
1084 MCAuto<DataArrayIdType> newGeoTypesPerChunk4=DataArrayIdType::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
1086 for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
1088 mcIdType startOfEltIdOfChunk=(*it)->_start;
1089 MCAuto<DataArrayIdType> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
1090 MCAuto<DataArrayIdType> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
1091 MCAuto<DataArrayIdType> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
1093 MCAuto<DataArrayIdType> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
1094 newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
1096 newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
1097 newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
1099 MCAuto<DataArrayIdType> newGeoTypesEltIdsAllGather=DataArrayIdType::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
1100 MCAuto<DataArrayIdType> newGeoTypesEltIdsAllGather2=DataArrayIdType::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
1101 MCAuto<DataArrayIdType> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
1102 MCAuto<DataArrayIdType> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
1104 MCAuto<DataArrayIdType> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
1106 MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
1107 arrPart->renumberInPlace(renumTupleIds->begin());
1108 arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,ToIdType(arrPart->getNumberOfComponents()),1);
1110 const mcIdType *idIt=diffVals->begin();
1111 std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
1113 for(mcIdType i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
1115 MCAuto<DataArrayIdType> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
1116 MCAuto<DataArrayIdType> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
1117 mcIdType nbEntityElts=subIds->getNumberOfTuples();
1119 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
1120 NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
1124 result.push_back(eltToAdd);
1125 offset2+=nbEntityElts*nbi;
1127 ret=ret || li.empty();
1132 * \param [in] typeF type of field of new chunk
1133 * \param [in] geoType the geometric type of the chunk
1134 * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
1135 * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
1136 * \param [in] nbi number of integration points
1137 * \param [in] offset The offset in the **global array of data**.
1138 * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
1139 * to the new chunk to create.
1140 * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
1141 * \param [out] notInExisting If false the return newly allocated entry is not coming from \a entriesOnSameDisc. If true the output comes from copy of \a entriesOnSameDisc
1142 * and corresponding entry erased from \a entriesOnSameDisc.
1143 * \return a newly allocated chunk
1145 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayIdType *idsOfMeshElt,
1146 bool isPfl, mcIdType nbi, mcIdType offset,
1147 std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1148 MEDFileFieldGlobsReal& glob,
1149 bool ¬InExisting)
1151 mcIdType nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1152 std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1153 for(;it!=entriesOnSameDisc.end();it++)
1155 if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1159 if((*it)->_profile.empty())
1162 if(!(*it)->_profile.empty())
1164 const DataArrayIdType *pfl=glob.getProfile((*it)->_profile.c_str());
1165 if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1171 if(it==entriesOnSameDisc.end())
1174 MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1176 ret->_loc_id=(int)geoType;
1177 ret->_nval=nbMeshEntities;
1179 ret->_end=ret->_start+ret->_nval*nbi;
1182 idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1183 glob.appendProfile(idsOfMeshElt);
1184 ret->_profile=idsOfMeshElt->getName();
1186 //tony treatment of localization
1191 notInExisting=false;
1192 MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1193 ret->_loc_id=(int)geoType;
1194 ret->setNewStart(offset);
1195 entriesOnSameDisc.erase(it);
1201 ////////////////////////////////////
1203 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1207 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1212 void MEDFileFieldPerMeshPerTypeCommon::accept(MEDFileFieldVisitor& visitor) const
1214 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1215 if((*it).isNotNull())
1217 visitor.newPerMeshPerTypePerDisc(*it);
1221 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1224 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1226 if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1227 _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1231 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1233 return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1236 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1238 std::vector<const BigMemoryObject *> ret;
1239 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1240 ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1244 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(mcIdType& start, mcIdType offset, mcIdType nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1246 std::vector<mcIdType> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1247 for(std::vector<mcIdType>::const_iterator it=pos.begin();it!=pos.end();it++)
1248 _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1252 * This method is the most general one. No optimization is done here.
1253 * \param [in] multiTypePfl is the end user profile specified in high level API
1254 * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1255 * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
1256 * \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1257 * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1258 * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondence with the MEDFileField. The mesh inside the \a field is simply ignored.
1260 void MEDFileFieldPerMeshPerTypeCommon::assignFieldProfile(bool isPflAlone, mcIdType& start, const DataArrayIdType *multiTypePfl, const DataArrayIdType *idsInPfl, DataArrayIdType *locIds, mcIdType nbOfEltsInWholeMesh, const MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1262 std::vector<mcIdType> pos=addNewEntryIfNecessary(field,idsInPfl);
1263 for(std::vector<mcIdType>::const_iterator it=pos.begin();it!=pos.end();it++)
1264 _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1267 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(mcIdType& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1269 _field_pm_pt_pd.resize(1);
1270 _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1271 _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1274 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(mcIdType& start, const DataArrayIdType *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1276 MCAuto<DataArrayIdType> pfl2=pfl->deepCopy();
1277 if(!arr || !arr->isAllocated())
1278 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1279 _field_pm_pt_pd.resize(1);
1280 _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1281 _field_pm_pt_pd[0]->assignFieldProfile(true,start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1284 std::vector<mcIdType> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, mcIdType offset, mcIdType nbOfCells)
1286 TypeOfField type=field->getTypeOfField();
1287 if(type!=ON_GAUSS_PT)
1289 int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1290 std::size_t sz=_field_pm_pt_pd.size();
1292 for(std::size_t j=0;j<sz && !found;j++)
1294 if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1296 _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1302 _field_pm_pt_pd.resize(sz+1);
1303 _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1305 std::vector<mcIdType> ret(1,(mcIdType)sz);
1310 std::vector<mcIdType> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1311 std::size_t sz2=ret2.size();
1312 std::vector<mcIdType> ret3(sz2);
1314 for(std::size_t i=0;i<sz2;i++)
1316 mcIdType sz=ToIdType(_field_pm_pt_pd.size());
1317 mcIdType locIdToFind=ret2[i];
1319 for(mcIdType j=0;j<sz && !found;j++)
1321 if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1323 _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,FromIdType<int>(locIdToFind));
1330 _field_pm_pt_pd.resize(sz+1);
1331 _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,FromIdType<int>(locIdToFind));
1339 std::vector<mcIdType> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, mcIdType offset, mcIdType nbOfCells)
1341 const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1342 const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1344 throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1345 const DataArrayIdType *da=disc2->getArrayOfDiscIds();
1347 throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1348 MCAuto<DataArrayIdType> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1349 MCAuto<DataArrayIdType> retTmp=da2->getDifferentValues();
1350 if(retTmp->presenceOfValue(-1))
1351 throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1352 std::vector<mcIdType> ret(retTmp->begin(),retTmp->end());
1356 std::vector<mcIdType> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, const DataArrayIdType *subCells)
1358 TypeOfField type=field->getTypeOfField();
1359 if(type!=ON_GAUSS_PT)
1361 int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1362 std::size_t sz=_field_pm_pt_pd.size();
1364 for(std::size_t j=0;j<sz && !found;j++)
1366 if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1368 _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1374 _field_pm_pt_pd.resize(sz+1);
1375 _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1377 std::vector<mcIdType> ret(1,0);
1382 std::vector<mcIdType> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1383 std::size_t sz2=ret2.size();
1384 std::vector<mcIdType> ret3(sz2);
1386 for(std::size_t i=0;i<sz2;i++)
1388 mcIdType sz=ToIdType(_field_pm_pt_pd.size());
1389 mcIdType locIdToFind=ret2[i];
1391 for(mcIdType j=0;j<sz && !found;j++)
1393 if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1395 _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1402 _field_pm_pt_pd.resize(sz+1);
1403 _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1411 std::vector<mcIdType> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, const DataArrayIdType *subCells)
1413 const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1414 const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1416 throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1417 const DataArrayIdType *da=disc2->getArrayOfDiscIds();
1419 throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1420 MCAuto<DataArrayIdType> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1421 MCAuto<DataArrayIdType> retTmp=da2->getDifferentValues();
1422 if(retTmp->presenceOfValue(-1))
1423 throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1424 std::vector<mcIdType> ret(retTmp->begin(),retTmp->end());
1428 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1433 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1435 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1436 int curDim((int)cm.getDimension());
1437 if(dim!=std::numeric_limits<int>::max())
1447 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1449 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1451 (*it)->fillTypesOfFieldAvailable(types);
1455 void MEDFileFieldPerMeshPerTypeCommon::fillFieldSplitedByType(std::vector< std::pair<mcIdType,mcIdType> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1457 std::size_t sz=_field_pm_pt_pd.size();
1458 dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1459 for(std::size_t i=0;i<sz;i++)
1461 _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1465 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1467 return _father->getIteration();
1470 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1472 return _father->getOrder();
1475 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1477 return _father->getTime();
1480 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1482 return _father->getMeshName();
1485 void MEDFileFieldPerMeshPerTypeCommon::getSizes(mcIdType& globalSz, mcIdType& nbOfEntries) const
1487 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1489 globalSz+=(*it)->getNumberOfTuples();
1491 nbOfEntries+=(mcIdType)_field_pm_pt_pd.size();
1494 std::size_t MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1496 return _father->getNumberOfComponents();
1499 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1502 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1504 const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1511 void MEDFileFieldPerMeshPerTypeCommon::pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc)
1513 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt;
1515 _field_pm_pt_pd.push_back(elt);
1518 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1520 return _father->getOrCreateAndGetArray();
1523 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1525 const MEDFileFieldPerMesh *fath=_father;
1526 return fath->getOrCreateAndGetArray();
1529 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1531 return _father->getInfo();
1534 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1536 std::vector<std::string> ret;
1537 std::set<std::string> ret2;
1538 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1540 std::string tmp=(*it1)->getProfile();
1542 if(ret2.find(tmp)==ret2.end())
1551 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1553 std::vector<std::string> ret;
1554 std::set<std::string> ret2;
1555 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1557 std::string tmp=(*it1)->getLocalization();
1558 if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1559 if(ret2.find(tmp)==ret2.end())
1568 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1570 std::vector<std::string> ret;
1571 std::set<std::string> ret2;
1572 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1574 std::string tmp=(*it1)->getProfile();
1581 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1583 std::vector<std::string> ret;
1584 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1586 std::string tmp=(*it1)->getLocalization();
1587 if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1593 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1595 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1596 (*it1)->changePflsRefsNamesGen(mapOfModif);
1599 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1601 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1602 (*it1)->changeLocsRefsNamesGen(mapOfModif);
1605 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(mcIdType locId)
1607 if(_field_pm_pt_pd.empty())
1609 std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1610 throw INTERP_KERNEL::Exception(oss.str());
1612 if(locId>=0 && locId<ToIdType(_field_pm_pt_pd.size()))
1613 return _field_pm_pt_pd[locId];
1614 std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1615 oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1616 throw INTERP_KERNEL::Exception(oss2.str().c_str());
1617 return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1620 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(mcIdType locId) const
1622 if(_field_pm_pt_pd.empty())
1624 std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1625 throw INTERP_KERNEL::Exception(oss.str());
1627 if(locId>=0 && locId<ToIdType(_field_pm_pt_pd.size()))
1628 return _field_pm_pt_pd[locId];
1629 std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1630 oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1631 throw INTERP_KERNEL::Exception(oss2.str().c_str());
1632 return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1635 int MEDFileFieldPerMeshPerTypeCommon::locIdOfLeaf(const MEDFileFieldPerMeshPerTypePerDisc *leaf) const
1638 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,ret++)
1640 const MEDFileFieldPerMeshPerTypePerDisc *cand(*it);
1644 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::locIdOfLeaf : not found such a leaf in this !");
1647 void MEDFileFieldPerMeshPerTypeCommon::fillValues(mcIdType& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
1650 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1652 (*it)->fillValues(i,startEntryId,entries);
1656 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1658 _field_pm_pt_pd=leaves;
1659 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1660 (*it)->setFather(this);
1664 * \param [in,out] globalNum a global numbering counter for the renumbering.
1665 * \param [out] its - list of pair (start,stop) kept
1666 * \return bool - false if the type of field \a tof is not contained in \a this.
1668 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, mcIdType &globalNum, std::vector< std::pair<mcIdType,mcIdType> >& its)
1671 std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1672 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1673 if((*it)->getType()==tof)
1675 newPmPtPd.push_back(*it);
1676 std::pair<mcIdType,mcIdType> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1677 (*it)->setNewStart(globalNum);
1678 globalNum=(*it)->getEnd();
1679 its.push_back(bgEnd);
1683 _field_pm_pt_pd=newPmPtPd;
1688 * \param [in,out] globalNum a global numbering counter for the renumbering.
1689 * \param [out] its - list of pair (start,stop) kept
1690 * \return bool - false if the type of field \a tof is not contained in \a this.
1692 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, mcIdType &globalNum, std::vector< std::pair<mcIdType,mcIdType> >& its)
1694 if(_field_pm_pt_pd.size()<=idOfDisc)
1696 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1697 std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1698 std::pair<mcIdType,mcIdType> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1699 elt->setNewStart(globalNum);
1700 globalNum=elt->getEnd();
1701 its.push_back(bgEnd);
1702 _field_pm_pt_pd=newPmPtPd;
1706 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, mcIdType &start, const MEDFileFieldNameScope& nasc)
1708 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1709 (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1712 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1714 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1715 (*it)->loadBigArray(fid,nasc);
1718 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1720 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1722 (*it)->copyOptionsFrom(*this);
1723 (*it)->writeLL(fid,nasc);
1727 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1732 medfGeoType=typmai3[(int)ikGeoType];
1735 medfGeoType=MED_NONE;
1738 medfGeoType=typmai3[(int)ikGeoType];
1739 return MED_NODE_ELEMENT;
1741 medfGeoType=typmai3[(int)ikGeoType];
1744 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1746 return MED_UNDEF_ENTITY_TYPE;
1749 //////////////////////////////////////////////////
1751 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1753 return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1756 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1758 return new MEDFileFieldPerMeshPerType(fath,geoType);
1761 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1763 MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1764 ret->setFather(father);
1765 ret->deepCopyElements();
1769 void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<mcIdType,mcIdType> >& dads, std::vector<const DataArrayIdType *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1771 if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1773 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1774 if(meshDim!=(int)cm.getDimension())
1777 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1778 (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1781 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1786 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoTypeStatic() const
1791 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1793 ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1796 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1798 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1799 int curDim((int)cm.getDimension());
1800 dim=std::max(dim,curDim);
1803 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1805 const char startLine[]=" ## ";
1806 std::string startLine2(bkOffset,' ');
1807 std::string startLine3(startLine2);
1808 startLine3+=startLine;
1809 if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1811 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1812 oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1815 oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1816 oss << startLine3 << "Entry is defined on " << _field_pm_pt_pd.size() << " localizations." << std::endl;
1818 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1820 const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1822 cur->simpleRepr(bkOffset,oss,i);
1825 oss << startLine2 << " ## " << "Localization #" << i << " is empty !" << std::endl;
1830 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1832 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1833 return std::string(cm.getRepr());
1836 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1840 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1842 INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1843 INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1844 med_geometry_type mgeoti;
1845 med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1846 med_int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1847 _field_pm_pt_pd.resize(nbProfiles);
1848 for(int i=0;i<nbProfiles;i++)
1850 _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1854 med_int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1855 for(int i=0;i<nbProfiles2;i++)
1856 _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1858 if(!_field_pm_pt_pd.empty() || type!=ON_CELLS)
1860 // dark side of the force.
1862 med_int nbProfiles1(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_FACE,mgeoti,pflName,locName));
1863 med_int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_EDGE,mgeoti,pflName,locName));
1864 if(nbProfiles1==0 && nbProfiles2==0)
1865 return ;// OK definitely nothing in field
1866 menti=nbProfiles1>=nbProfiles2?MED_DESCENDING_FACE:MED_DESCENDING_EDGE;//not enough words to describe the beauty
1867 nbProfiles=std::max(nbProfiles1,nbProfiles2);
1868 _field_pm_pt_pd.resize(nbProfiles);
1869 for(int i=0;i<nbProfiles;i++)
1870 _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_CELLS,i,pd);
1874 MCAuto<MEDFileFieldPerMeshPerType> MEDFileFieldPerMeshPerType::Aggregate(mcIdType &start, const std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >& pms, const std::vector< std::vector< std::pair<int,mcIdType> > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector<std::pair< int, std::pair<mcIdType,mcIdType> > >& extractInfo)
1876 MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1877 std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1878 for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1880 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1881 m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1883 for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1885 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1886 ret->_field_pm_pt_pd.push_back(agg);
1891 //////////////////////////////////////////////////
1893 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1896 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1897 const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1899 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1900 const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1901 return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1904 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1907 INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1908 INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1909 med_int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1910 _field_pm_pt_pd.resize(nbProfiles);
1911 for(int i=0;i<nbProfiles;i++)
1913 _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1917 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1919 return _se->getDynGT();
1922 std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const
1924 return _se->getName();
1927 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1929 throw INTERP_KERNEL::Exception("not implemented yet !");
1932 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1935 ent=MED_STRUCT_ELEMENT;
1938 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1940 throw INTERP_KERNEL::Exception("not implemented yet !");
1943 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoTypeStatic() const
1945 return _se->getGeoType();
1948 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1950 const char startLine[]=" ## ";
1951 std::string startLine2(bkOffset,' ');
1952 std::string startLine3(startLine2);
1953 startLine3+=startLine;
1954 oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1955 oss << startLine3 << "Entry is defined on " << _field_pm_pt_pd.size() << " localizations." << std::endl;
1957 for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1959 if((*it).isNotNull())
1960 (*it)->simpleRepr(bkOffset,oss,i);
1963 oss << startLine2 << " ## " << "Localization #" << i << " is empty !" << std::endl;
1968 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1970 throw INTERP_KERNEL::Exception("not implemented yet !");
1973 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1975 MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1976 ret->setFather(father);
1977 ret->deepCopyElements();
1981 void MEDFileFieldPerMeshPerTypeDyn::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<mcIdType,mcIdType> >& dads, std::vector<const DataArrayIdType *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1983 throw INTERP_KERNEL::Exception("not implemented yet !");
1986 //////////////////////////////////////////////////
1988 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1990 return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1993 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1995 return new MEDFileFieldPerMesh(fath,mesh);
1998 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
2000 return _field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
2003 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
2005 std::vector<const BigMemoryObject *> ret;
2006 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2011 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
2013 MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
2014 ret->_father=father;
2016 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2018 if((*it).isNotNull())
2019 ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
2024 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
2026 std::string startLine(bkOffset,' ');
2027 oss << startLine << "## Field part (" << id << ") lying on mesh \"" << getMeshName() << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
2028 oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
2030 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2032 if((*it).isNotNull())
2033 (*it)->simpleRepr(bkOffset,oss,i);
2036 oss << startLine << " ## Entry geometry type #" << i << " is empty !" << std::endl;
2041 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
2043 mesh->getTime(_mesh_iteration,_mesh_order);
2046 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(mcIdType& start, const std::vector<mcIdType>& code, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2048 std::size_t nbOfTypes=code.size()/3;
2050 for(std::size_t i=0;i<nbOfTypes;i++)
2052 INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
2053 mcIdType nbOfCells=code[3*i+1];
2054 mcIdType pos=addNewEntryIfNecessary(type);
2055 _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
2061 * This method is the most general one. No optimization is done here.
2062 * \param [in] multiTypePfl is the end user profile specified in high level API
2063 * \param [in] code is the code of \a mesh[multiTypePfl] mesh. It is of size of number of different geometric types into \a mesh[multiTypePfl].
2064 * \param [in] code2 is the code of the \b WHOLE mesh on the same level. So all types in \a code are in \a code2.
2065 * \param [in] idsInPflPerType is the selection into the \a multiTypePfl whole profile that corresponds to the given geometric type. This vector is always 3 times smaller than \a code.
2066 * \param [in] idsPerType is a vector containing the profiles needed to be created for MED file format. \b WARNING these processed MED file profiles can be subdivided again in case of Gauss points.
2067 * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondence with the MEDFileField. The mesh inside the \a field is simply ignored.
2069 void MEDFileFieldPerMesh::assignFieldProfile(mcIdType& start, const DataArrayIdType *multiTypePfl, const std::vector<mcIdType>& code, const std::vector<mcIdType>& code2, const std::vector<DataArrayIdType *>& idsInPflPerType, const std::vector<DataArrayIdType *>& idsPerType, const MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2071 std::size_t nbOfTypes(code.size()/3);
2072 for(std::size_t i=0;i<nbOfTypes;i++)
2074 INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
2075 mcIdType pos=addNewEntryIfNecessary(type);
2076 DataArrayIdType *pfl=0;
2078 pfl=idsPerType[code[3*i+2]];
2079 std::size_t nbOfTupes2=code2.size()/3;
2080 std::size_t found=0;
2081 for(;found<nbOfTupes2;found++)
2082 if(code[3*i]==code2[3*found])
2084 if(found==nbOfTupes2)
2085 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
2086 _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
2090 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(mcIdType& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
2092 mcIdType pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2093 _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
2096 void MEDFileFieldPerMesh::assignNodeFieldProfile(mcIdType& start, const DataArrayIdType *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2098 mcIdType pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2099 _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
2102 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, mcIdType& start, const MEDFileFieldNameScope& nasc)
2104 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2105 (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
2108 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
2110 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2111 (*it)->loadBigArraysRecursively(fid,nasc);
2114 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
2116 std::size_t nbOfTypes=_field_pm_pt.size();
2117 for(std::size_t i=0;i<nbOfTypes;i++)
2119 _field_pm_pt[i]->copyOptionsFrom(*this);
2120 _field_pm_pt[i]->writeLL(fid,nasc);
2124 void MEDFileFieldPerMesh::getDimension(int& dim) const
2126 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2127 (*it)->getDimension(dim);
2130 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
2132 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2133 if(!(*it)->isUniqueLevel(dim))
2138 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
2140 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2141 (*it)->fillTypesOfFieldAvailable(types);
2144 std::vector< std::vector< std::pair<mcIdType,mcIdType> > > MEDFileFieldPerMesh::getFieldSplitedByType(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
2146 std::size_t sz=_field_pm_pt.size();
2147 std::vector< std::vector<std::pair<mcIdType,mcIdType> > > ret(sz);
2148 types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
2149 for(std::size_t i=0;i<sz;i++)
2151 types[i]=_field_pm_pt[i]->getGeoType();
2152 _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
2157 double MEDFileFieldPerMesh::getTime() const
2160 return _father->getTime(tmp1,tmp2);
2163 int MEDFileFieldPerMesh::getIteration() const
2165 return _father->getIteration();
2168 int MEDFileFieldPerMesh::getOrder() const
2170 return _father->getOrder();
2173 std::size_t MEDFileFieldPerMesh::getNumberOfComponents() const
2175 return _father->getNumberOfComponents();
2178 std::string MEDFileFieldPerMesh::getMeshName() const
2180 return _father->getMeshName();
2183 void MEDFileFieldPerMesh::setMeshName(const std::string& meshName)
2185 _father->setMeshName(meshName);
2188 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
2190 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2194 if((*it)->presenceOfMultiDiscPerGeoType())
2200 bool MEDFileFieldPerMesh::presenceOfStructureElements() const
2202 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2203 if((*it).isNotNull())
2205 const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2212 bool MEDFileFieldPerMesh::onlyStructureElements() const
2214 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2215 if((*it).isNotNull())
2217 const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2224 void MEDFileFieldPerMesh::killStructureElements()
2226 std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2227 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2229 if((*it).isNotNull())
2231 const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2239 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2241 std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2242 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2244 if((*it).isNotNull())
2246 const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2254 void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName)
2256 std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2257 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2259 if((*it).isNotNull())
2261 const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2263 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !");
2264 if(pt->getModelName()==seName)
2271 void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
2273 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2275 if((*it).isNotNull())
2277 const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2280 ps.push_back(std::pair<std::string,std::string>(getMeshName(),pt->getModelName()));
2283 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !");
2288 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2291 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2292 return _father->getOrCreateAndGetArray();
2295 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2298 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2299 return _father->getOrCreateAndGetArray();
2302 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2304 return _father->getInfo();
2308 * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2309 * Before the call of this method 'geoTypes','dads','pfls','locs' must be reorganized so that types in geoTypes are contiguous and ordered following typmai2 array.
2310 * It returns 2 output vectors :
2311 * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2312 * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2313 * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2315 void MEDFileFieldPerMesh::SortArraysPerType(const MEDFileFieldGlobsReal *glob, TypeOfField type, const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes, const std::vector< std::pair<mcIdType,mcIdType> >& dads, const std::vector<const DataArrayIdType *>& pfls, const std::vector<int>& locs, std::vector<mcIdType>& code, std::vector<DataArrayIdType *>& notNullPfls)
2317 int notNullPflsSz=0;
2318 std::size_t nbOfArrs=geoTypes.size();
2319 for(std::size_t i=0;i<nbOfArrs;i++)
2322 std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2323 std::size_t nbOfDiffGeoTypes=geoTypes3.size();
2324 code.resize(3*nbOfDiffGeoTypes);
2325 notNullPfls.resize(notNullPflsSz);
2328 for(std::size_t i=0;i<nbOfDiffGeoTypes;i++)
2330 std::size_t startZone=j;
2331 INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2332 std::vector<const DataArrayIdType *> notNullTmp;
2334 notNullTmp.push_back(pfls[j]);
2336 for(;j<nbOfArrs;j++)
2337 if(geoTypes[j]==refType)
2340 notNullTmp.push_back(pfls[j]);
2344 std::vector< std::pair<mcIdType,mcIdType> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2345 std::vector<const DataArrayIdType *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2346 std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2347 code[3*i]=(mcIdType)refType;
2348 std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2349 code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2350 if(notNullTmp.empty())
2354 notNullPfls[notNullPflsSz]=DataArrayIdType::Aggregate(notNullTmp);
2355 code[3*i+2]=notNullPflsSz++;
2361 * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2363 mcIdType MEDFileFieldPerMesh::ComputeNbOfElems(const MEDFileFieldGlobsReal *glob, TypeOfField type, const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes, const std::vector< std::pair<mcIdType,mcIdType> >& dads, const std::vector<int>& locs)
2365 std::size_t sz=dads.size();
2367 for(std::size_t i=0;i<sz;i++)
2371 if(type!=ON_GAUSS_NE)
2372 ret+=dads[i].second-dads[i].first;
2375 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2376 ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2381 int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2382 ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2388 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2390 std::vector<std::string> ret;
2391 std::set<std::string> ret2;
2392 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2394 std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2395 for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2396 if(ret2.find(*it2)==ret2.end())
2398 ret.push_back(*it2);
2405 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2407 std::vector<std::string> ret;
2408 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2410 std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2411 ret.insert(ret.end(),tmp.begin(),tmp.end());
2416 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2418 std::vector<std::string> ret;
2419 std::set<std::string> ret2;
2420 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2422 std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2423 for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2424 if(ret2.find(*it2)==ret2.end())
2426 ret.push_back(*it2);
2433 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2435 std::vector<std::string> ret;
2436 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2438 std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2439 ret.insert(ret.end(),tmp.begin(),tmp.end());
2444 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2446 for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2448 if((*it).first==getMeshName())
2450 setMeshName((*it).second);
2457 void MEDFileFieldPerMesh::convertMedBallIntoClassic()
2459 if(_field_pm_pt.size()!=1)
2460 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : Only managed for single mesh !");
2461 if(_field_pm_pt[0].isNull())
2462 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : null pointer !");
2463 MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<MEDFileFieldPerMeshPerTypeDyn *>((MEDFileFieldPerMeshPerTypeCommon *)_field_pm_pt[0]));
2465 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : this is expected to be marked as structure element !");
2466 if(pt->getNumberOfLoc()!=1)
2467 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : only one loc managed !");
2468 const MEDFileFieldPerMeshPerTypePerDisc *disc(pt->getLeafGivenLocId(0));
2470 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : internal error !");
2471 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> disc2(MEDFileFieldPerMeshPerTypePerDisc::New(*disc));
2472 disc2->setType(ON_NODES);
2473 MCAuto<MEDFileFieldPerMeshPerType> pt2(MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR));
2474 disc2->setFather(pt2);
2475 pt2->setFather(this);
2476 pt2->pushDiscretization(disc2);
2477 _field_pm_pt[0]=DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(pt2);
2480 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<mcIdType>& oldCode, const std::vector<mcIdType>& newCode, const DataArrayIdType *renumO2N,
2481 MEDFileFieldGlobsReal& glob)
2483 if(getMeshName()!=meshName)
2485 std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2486 for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2487 std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > > entries;
2488 std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2489 std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2490 getUndergroundDataArrayExt(entries);
2491 DataArray *arr0(getOrCreateAndGetArray());//tony
2493 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2494 DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2496 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2499 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2500 for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2502 if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2504 entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2505 sz+=(*it).second.second-(*it).second.first;
2508 otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2510 MCAuto<DataArrayIdType> renumDefrag=DataArrayIdType::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2511 ////////////////////
2512 MCAuto<DataArrayIdType> explicitIdsOldInMesh=DataArrayIdType::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2513 mcIdType *workI2=explicitIdsOldInMesh->getPointer();
2514 mcIdType sz1=0,sz2=0,sid=1;
2515 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2516 // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2517 for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2519 // tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2520 MCAuto<DataArrayIdType> explicitIdsOldInArr=DataArrayIdType::New(); explicitIdsOldInArr->alloc(sz,1);
2521 mcIdType *workI=explicitIdsOldInArr->getPointer();
2522 for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2524 mcIdType delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2525 (*itL2)->setLocId(sz2);
2526 (*itL2)->_tmp_work1=(*itL2)->getStart();
2527 mcIdType delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2529 renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2531 explicitIdsOldInMesh->reAlloc(sz2);
2532 mcIdType tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2533 ////////////////////
2534 MCAuto<DataArrayIdType> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2535 // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2536 std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2537 for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2539 otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2540 otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2541 otherEntriesNew.back()->setLocId((*it)->getGeoType());
2543 std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2544 std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2545 for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2547 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2548 mcIdType newStart=elt->getLocId();
2549 elt->setLocId((*it)->getGeoType());
2550 elt->setNewStart(newStart);
2551 elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2552 entriesKeptNew.push_back(elt);
2553 entriesKeptNew2.push_back(elt);
2555 MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2556 // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2557 MCAuto<DataArrayIdType> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2558 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2560 for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2563 /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2565 MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2566 curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2568 ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2569 glob,arr2,otherEntriesNew) || ret;
2573 // Assign new dispatching
2574 assignNewLeaves(otherEntriesNew);
2575 arr->deepCopyFrom(*arr2);
2580 * \param [in,out] globalNum a global numbering counter for the renumbering.
2581 * \param [out] its - list of pair (start,stop) kept
2583 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, mcIdType &globalNum, std::vector< std::pair<mcIdType,mcIdType> >& its)
2585 std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2586 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2588 std::vector< std::pair<mcIdType,mcIdType> > its2;
2589 if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2592 its.insert(its.end(),its2.begin(),its2.end());
2599 * \param [in,out] globalNum a global numbering counter for the renumbering.
2600 * \param [out] its - list of pair (start,stop) kept
2602 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, mcIdType &globalNum, std::vector< std::pair<mcIdType,mcIdType> >& its)
2604 std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2605 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2607 std::vector< std::pair<mcIdType,mcIdType> > its2;
2608 if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2611 its.insert(its.end(),its2.begin(),its2.end());
2617 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2619 std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2620 for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2621 types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2623 std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2624 std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2625 std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2626 for(;it1!=types.end();it1++,it2++)
2628 MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2629 elt->setLeaves((*it1).second);
2630 MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2633 _field_pm_pt=fieldPmPt;
2636 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2638 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2639 (*it)->changePflsRefsNamesGen(mapOfModif);
2642 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2644 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2645 (*it)->changeLocsRefsNamesGen(mapOfModif);
2649 * \param [in] mesh is the whole mesh
2651 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2653 if(_field_pm_pt.empty())
2654 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2656 std::vector< std::pair<mcIdType,mcIdType> > dads;
2657 std::vector<const DataArrayIdType *> pfls;
2658 std::vector<DataArrayIdType *> notNullPflsPerGeoType;
2659 std::vector<int> locs;
2660 std::vector<mcIdType>code;
2661 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2662 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2663 (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2665 SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2668 std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2669 throw INTERP_KERNEL::Exception(oss.str());
2672 std::vector< MCAuto<DataArrayIdType> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2673 std::vector< const DataArrayIdType *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2676 DataArrayIdType *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2678 return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2681 MCAuto<DataArrayIdType> arr2(arr);
2682 return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2688 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2689 mcIdType nb=code[1];
2692 if(nb!=mesh->getNumberOfNodes())
2694 std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2695 oss << " nodes in mesh !";
2696 throw INTERP_KERNEL::Exception(oss.str());
2698 return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2701 return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2705 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayIdType *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2707 if(_field_pm_pt.empty())
2708 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2710 std::vector<std::pair<mcIdType,mcIdType> > dads;
2711 std::vector<const DataArrayIdType *> pfls;
2712 std::vector<DataArrayIdType *> notNullPflsPerGeoType;
2713 std::vector<int> locs;
2714 std::vector<mcIdType> code;
2715 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2716 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2717 (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2719 SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2722 std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2723 throw INTERP_KERNEL::Exception(oss.str());
2725 std::vector< MCAuto<DataArrayIdType> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2726 std::vector< const DataArrayIdType *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2729 MCAuto<DataArrayIdType> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2730 return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2735 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2736 mcIdType nb=code[1];
2739 if(nb!=mesh->getNumberOfNodes())
2741 std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2742 oss << " nodes in mesh !";
2743 throw INTERP_KERNEL::Exception(oss.str());
2746 return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2752 void MEDFileFieldPerMesh::accept(MEDFileFieldVisitor& visitor) const
2754 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2755 if((*it).isNotNull())
2757 visitor.newPerMeshPerTypeEntry(*it);
2758 (*it)->accept(visitor);
2759 visitor.endPerMeshPerTypeEntry(*it);
2763 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<mcIdType,mcIdType> > >& entries) const
2765 mcIdType globalSz=0;
2766 mcIdType nbOfEntries=0;
2767 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2769 (*it)->getSizes(globalSz,nbOfEntries);
2771 entries.resize(nbOfEntries);
2773 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2775 (*it)->fillValues(nbOfEntries,entries);
2779 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, mcIdType locId)
2781 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2783 if((*it)->getGeoType()==typ)
2784 return (*it)->getLeafGivenLocId(locId);
2786 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2787 std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2788 oss << "Possibilities are : ";
2789 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2791 const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2792 oss << "\"" << cm2.getRepr() << "\", ";
2794 throw INTERP_KERNEL::Exception(oss.str());
2797 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, mcIdType locId) const
2799 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2801 if((*it)->getGeoType()==typ)
2802 return (*it)->getLeafGivenLocId(locId);
2804 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2805 std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2806 oss << "Possibilities are : ";
2807 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2809 const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2810 oss << "\"" << cm2.getRepr() << "\", ";
2812 throw INTERP_KERNEL::Exception(oss.str());
2816 * \param [in,out] start - Integer that gives the current position in the final aggregated array
2817 * \param [in] pms - list of elements to aggregate. integer gives the mesh id
2818 * \param [in] dts - (Distribution of types) = level 1 : meshes to aggregate. Level 2 : all geo type. Level 3 pair specifying geo type and number of elem in geotype.
2819 * \param [out] extractInfo - Gives information about the where the data comes from. It is a vector of triplet. First element in the triplet the mesh pos. The 2nd one the start pos. The 3rd the end pos.
2821 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> MEDFileFieldPerMeshPerTypePerDisc::Aggregate(mcIdType &start, const std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >& pms, const std::vector< std::vector< std::pair<int,mcIdType> > >& dts, TypeOfField tof, MEDFileFieldPerMeshPerType *father, std::vector<std::pair< int, std::pair<mcIdType,mcIdType> > >& extractInfo)
2823 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2825 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2826 for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2829 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2830 if(!(*it).second->getProfile().empty())
2831 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2832 if(!(*it).second->getLocalization().empty())
2833 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2835 INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2837 std::vector< std::pair<int,int> > filteredDTS;
2838 for(std::vector< std::vector< std::pair<int,mcIdType> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2839 for(std::vector< std::pair<int,mcIdType> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2840 if((*it2).first==gt)
2841 filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2842 if(pms.size()!=filteredDTS.size())
2843 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2844 std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2845 std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2846 mcIdType zeStart(start),nval(0);
2847 for(;it1!=pms.end();it1++,it2++)
2849 if((*it1).first!=(*it2).first)
2850 throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2851 mcIdType s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2852 extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2854 nval+=((*it1).second)->getNumberOfVals();
2856 ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2860 MCAuto<MEDFileFieldPerMesh> MEDFileFieldPerMesh::Aggregate(mcIdType &start, const std::vector<const MEDFileFieldPerMesh *>& pms, const std::vector< std::vector< std::pair<int,mcIdType> > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector<std::pair< int, std::pair<mcIdType,mcIdType> > >& extractInfo)
2862 MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2863 std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2865 for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2867 const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2868 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2870 INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2871 const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2873 throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2874 m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2877 for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2879 MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2880 MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2881 ret->_field_pm_pt.push_back(agg2);
2886 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2889 std::size_t pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2890 std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2891 for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2893 INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2898 std::size_t pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2903 std::size_t ret=std::distance(_field_pm_pt.begin(),it2);
2904 _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2909 * 'dads' and 'locs' input parameters have the same number of elements
2910 * \param [in] mesh is \b NOT the global mesh, but the possibly reduced mesh. \a mesh parameter will be directly aggregated in the returned field
2912 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2913 const std::vector< std::pair<mcIdType,mcIdType> >& dads, const std::vector<int>& locs,
2914 const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2917 MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2918 ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2919 MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2920 const std::vector<std::string>& infos=getInfo();
2921 da->setInfoOnComponents(infos);
2923 if(type==ON_GAUSS_PT)
2926 std::size_t nbOfArrs=dads.size();
2927 for(std::size_t i=0;i<nbOfArrs;i++)
2929 std::vector<std::pair<mcIdType,mcIdType> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2930 const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2931 mcIdType nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2932 MCAuto<DataArrayIdType> di=DataArrayIdType::New();
2933 di->alloc(nbOfElems,1);
2935 const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2936 ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2945 * This method is an extension of MEDFileFieldPerMesh::finishField method. It deals with profiles. This method should be called when type is different from ON_NODES.
2946 * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2947 * No check of this is performed. 'da' array contains an array in old2New style to be applied to mesh to obtain the right support.
2948 * The order of cells in the returned field is those imposed by the profile.
2949 * \param [in] mesh is the global mesh.
2951 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2952 const std::vector<std::pair<mcIdType,mcIdType> >& dads, const std::vector<int>& locs,
2953 const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2954 const MEDCouplingMesh *mesh, const DataArrayIdType *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2956 if(da->isIota(mesh->getNumberOfCells()))
2957 return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2958 MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2959 m2->setName(mesh->getName().c_str());
2960 MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2966 * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2968 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2969 const std::vector<std::pair<mcIdType,mcIdType> >& dads, const std::vector<int>& locs,
2970 const MEDCouplingMesh *mesh, const DataArrayIdType *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2972 if(da->isIota(mesh->getNumberOfNodes()))
2973 return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2974 // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2975 const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2978 if(meshu->getNodalConnectivity()==0)
2980 MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2981 mcIdType nb=da->getNbOfElems();
2982 const mcIdType *ptr=da->getConstPointer();
2983 MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2984 meshuc->allocateCells(nb);
2985 for(mcIdType i=0;i<nb;i++)
2986 meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2987 meshuc->finishInsertingCells();
2988 ret->setMesh(meshuc);
2989 const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2990 if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2991 disc->checkCoherencyBetween(meshuc,arrOut);
2996 MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2998 DataArrayIdType *arr2=0;
2999 MCAuto<DataArrayIdType> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
3000 MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
3001 MCAuto<DataArrayIdType> arr3(arr2);
3002 mcIdType nnodes=mesh2->getNumberOfNodes();
3003 if(nnodes==(mcIdType)da->getNbOfElems())
3005 MCAuto<DataArrayIdType> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
3006 arrOut->renumberInPlace(da3->getConstPointer());
3007 mesh2->setName(mesh->getName().c_str());
3008 ret->setMesh(mesh2);
3013 std::ostringstream oss; oss << "MEDFileFieldPerMesh::finishFieldNode2 : The field on nodes lies on a node profile so that it is impossible to find a submesh having exactly the same nodes of that profile !!!";
3014 oss << "So it is impossible to return a well defined MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
3015 oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
3016 oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
3017 oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
3018 oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
3019 throw INTERP_KERNEL::Exception(oss.str());
3025 * This method is the most light method of field retrieving.
3027 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<mcIdType,mcIdType> >& dads, const DataArrayIdType *pflIn, mcIdType nbOfElems, DataArrayIdType *&pflOut) const
3031 pflOut=DataArrayIdType::New();
3032 pflOut->alloc(nbOfElems,1);
3037 pflOut=const_cast<DataArrayIdType*>(pflIn);
3040 MCAuto<DataArrayIdType> safePfl(pflOut);
3041 MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
3042 const std::vector<std::string>& infos=getInfo();
3043 std::size_t nbOfComp=infos.size();
3044 for(std::size_t i=0;i<nbOfComp;i++)
3045 da->setInfoOnComponent(i,infos[i].c_str());
3056 static MFFPMIter *NewCell(const MEDFileEntities *entities);
3057 static bool IsPresenceOfNode(const MEDFileEntities *entities);
3058 virtual ~MFFPMIter() { }
3059 virtual void begin() = 0;
3060 virtual bool finished() const = 0;
3061 virtual void next() = 0;
3062 virtual int current() const = 0;
3065 class MFFPMIterSimple : public MFFPMIter
3068 MFFPMIterSimple():_pos(0) { }
3069 void begin() { _pos=0; }
3070 bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
3071 void next() { _pos++; }
3072 int current() const { return _pos; }
3077 class MFFPMIter2 : public MFFPMIter
3080 MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
3081 void begin() { _it=_ids.begin(); }
3082 bool finished() const { return _it==_ids.end(); }
3083 void next() { _it++; }
3084 int current() const { return *_it; }
3086 std::vector<int> _ids;
3087 std::vector<int>::const_iterator _it;
3090 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
3093 return new MFFPMIterSimple;
3096 const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3099 std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
3100 const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3101 for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3103 if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
3104 tmp.push_back((*it).second);
3106 return new MFFPMIter2(tmp);
3108 return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
3112 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
3118 const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3121 const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3122 for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3123 if((*it).first==ON_NODES)
3127 return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
3131 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
3133 std::size_t sz(cts.size());
3135 for(std::size_t i=0;i<sz;i++)
3137 INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
3138 if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
3139 _ids[i]=(int)std::distance(typmai2,loc);
3141 throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
3147 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
3150 INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3151 INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3152 INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3153 const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
3154 INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
3155 for(iter0->begin();!iter0->finished();iter0->next())
3157 med_int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3158 std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3159 med_int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3160 std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3161 if(nbProfile>0 || nbProfile2>0)
3163 const PartDefinition *pd(0);
3165 pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
3166 _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
3173 if(MFFPMIter::IsPresenceOfNode(entities))
3175 med_int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
3178 const PartDefinition *pd(0);
3180 pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
3181 _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
3182 setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3187 std::vector<int> dynGT(entities->getDynGTAvail());
3188 for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
3190 med_int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
3193 _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
3194 setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3197 if(!_field_pm_pt.empty())
3199 //for vicious users using MED_ARETE MED_FACE in fields. the last try. For Others not overhead to pay.
3200 iter0=MFFPMIter::NewCell(entities);
3201 for(iter0->begin();!iter0->finished();iter0->next())
3203 med_int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_FACE,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3204 std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3205 med_int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_EDGE,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3206 std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3207 if(nbProfile>0 || nbProfile2>0)
3209 _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,NULL));
3218 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
3220 copyTinyInfoFrom(mesh);