X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileField.cxx;h=61b2b0660288e22c9d5e1014879e8a3b25b38481;hb=b3e28553eab4c76446ec4214ad4a8d71528905ab;hp=296c87f17de8f47080ae7c0582518379bdc938a6;hpb=05c7d7249901246b526bb3579f2c022d4de2a748;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 296c87f17..61b2b0660 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -432,7 +432,7 @@ std::vector MEDFileFieldPerMeshPerTypePerDisc::getDirec MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const { - MCAuto ret=new MEDFileFieldPerMeshPerTypePerDisc(*this); + MCAuto ret(new MEDFileFieldPerMeshPerTypePerDisc(*this)); ret->_father=father; return ret.retn(); } @@ -537,12 +537,11 @@ void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_i INTERP_KERNEL::AutoPtr locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); INTERP_KERNEL::AutoPtr pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); std::string fieldName(nasc.getName()),meshName(getMeshName()); - int iteration(getIteration()),order(getOrder()); + int iteration(getIteration()),order(getOrder()),profilesize,nbi; TypeOfField type(getType()); - INTERP_KERNEL::NormalizedCellType geoType(getGeoType()); - int profilesize,nbi; med_geometry_type mgeoti; - med_entity_type menti(MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(type,geoType,mgeoti)); + med_entity_type menti; + _father->entriesForMEDfile(type,mgeoti,menti); int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi)); _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE); _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE); @@ -577,9 +576,9 @@ void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileF std::string fieldName(nasc.getName()),meshName(getMeshName()); int iteration(getIteration()),order(getOrder()); TypeOfField type(getType()); - INTERP_KERNEL::NormalizedCellType geoType(getGeoType()); med_geometry_type mgeoti; - med_entity_type menti(MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(type,geoType,mgeoti)); + med_entity_type menti; + _father->entriesForMEDfile(type,mgeoti,menti); if(_start>_end) throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !"); if(_start==_end) @@ -648,10 +647,9 @@ void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& o const char startLine[]=" ## "; std::string startLine2(bkOffset,' '); startLine2+=startLine; - MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type); + INTERP_KERNEL::AutoCppPtr tmp(MEDCouplingFieldDiscretization::New(_type)); oss << startLine2 << "Localization #" << id << "." << std::endl; oss << startLine2 << " Type=" << tmp->getRepr() << "." << std::endl; - delete tmp; oss << startLine2 << " This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl; oss << startLine2 << " This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl; oss << startLine2 << " This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl; @@ -776,10 +774,11 @@ void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const { TypeOfField type=getType(); - INTERP_KERNEL::NormalizedCellType geoType=getGeoType(); + INTERP_KERNEL::NormalizedCellType geoType(getGeoType()); med_geometry_type mgeoti; - med_entity_type menti=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(type,geoType,mgeoti); - const DataArray *arr=getOrCreateAndGetArray(); + med_entity_type menti; + _father->entriesForMEDfile(getType(),mgeoti,menti); + const DataArray *arr(getOrCreateAndGetArray()); if(!arr) throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !"); if(!arr->isAllocated()) @@ -1604,6 +1603,11 @@ INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const return _geo_type; } +void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const +{ + ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt); +} + void MEDFileFieldPerMeshPerType::getDimension(int& dim) const { const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type)); @@ -1668,6 +1672,108 @@ MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileField } } +MCAuto MEDFileFieldPerMeshPerType::Aggregate(int &start, const std::vector >& pms, const std::vector< std::vector< std::pair > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector > >& extractInfo) +{ + MCAuto ret(MEDFileFieldPerMeshPerType::New(father,gt)); + std::map > > m; + for(std::vector >::const_iterator it=pms.begin();it!=pms.end();it++) + { + for(std::vector< MCAuto >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++) + m[(*it2)->getType()].push_back(std::pair((*it).first,*it2)); + } + for(std::map > >::const_iterator it=m.begin();it!=m.end();it++) + { + MCAuto agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo)); + ret->_field_pm_pt_pd.push_back(agg); + } + return ret; +} + +////////////////////////////////////////////////// + +MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc) +{ + if(!entities) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !"); + const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast(entities)); + if(!entities2) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !"); + const MEDFileStructureElement *se(entities2->getWithGT(idGT)); + return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc); +} + +MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath) +{ + _se.takeRef(se); + INTERP_KERNEL::AutoPtr pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName)); + _field_pm_pt_pd.resize(nbProfiles); + for(int i=0;igetEntity(),i,NULL); + } +} + +int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const +{ + return _se->getDynGT(); +} + +void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const +{ + throw INTERP_KERNEL::Exception("not implemented yet !"); +} + +void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const +{ + gt=getDynGT(); + ent=MED_STRUCT_ELEMENT; +} + +INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const +{ + throw INTERP_KERNEL::Exception("not implemented yet !"); +} + +void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const +{ + const char startLine[]=" ## "; + std::string startLine2(bkOffset,' '); + std::string startLine3(startLine2); + startLine3+=startLine; + oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl; + oss << startLine3 << "Entry is defined on " << _field_pm_pt_pd.size() << " localizations." << std::endl; + int i=0; + for(std::vector< MCAuto >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++) + { + if((*it).isNotNull()) + (*it)->simpleRepr(bkOffset,oss,i); + else + { + oss << startLine2 << " ## " << "Localization #" << i << " is empty !" << std::endl; + } + } +} + +std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const +{ + throw INTERP_KERNEL::Exception("not implemented yet !"); +} + +MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const +{ + MCAuto ret(new MEDFileFieldPerMeshPerTypeDyn(*this)); + ret->setFather(father); + ret->deepCopyElements(); + return ret.retn(); +} + +void MEDFileFieldPerMeshPerTypeDyn::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair >& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const +{ + throw INTERP_KERNEL::Exception("not implemented yet !"); +} + ////////////////////////////////////////////////// MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities) @@ -1688,8 +1794,8 @@ std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const std::vector MEDFileFieldPerMesh::getDirectChildrenWithNull() const { std::vector ret; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) - ret.push_back((const MEDFileFieldPerMeshPerType *)*it); + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + ret.push_back(*it); return ret; } @@ -1698,9 +1804,9 @@ MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithout MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this); ret->_father=father; std::size_t i=0; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++) { - if((const MEDFileFieldPerMeshPerType *)*it) + if((*it).isNotNull()) ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret)); } return ret.retn(); @@ -1712,11 +1818,10 @@ void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) co oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl; oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl; int i=0; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++) { - const MEDFileFieldPerMeshPerType *cur=*it; - if(cur) - cur->simpleRepr(bkOffset,oss,i); + if((*it).isNotNull()) + (*it)->simpleRepr(bkOffset,oss,i); else { oss << startLine << " ## Entry geometry type #" << i << " is empty !" << std::endl; @@ -1788,13 +1893,13 @@ void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc) { - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc); } void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc) { - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) (*it)->loadBigArraysRecursively(fid,nasc); } @@ -1810,13 +1915,13 @@ void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc void MEDFileFieldPerMesh::getDimension(int& dim) const { - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) (*it)->getDimension(dim); } bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const { - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) if(!(*it)->isUniqueLevel(dim)) return false; return true; @@ -1824,7 +1929,7 @@ bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set& types) const { - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) (*it)->fillTypesOfFieldAvailable(types); } @@ -1864,17 +1969,70 @@ int MEDFileFieldPerMesh::getNumberOfComponents() const bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const { - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { - const MEDFileFieldPerMeshPerType *fpmt(*it); - if(!fpmt) + if((*it).isNull()) continue; - if(fpmt->presenceOfMultiDiscPerGeoType()) + if((*it)->presenceOfMultiDiscPerGeoType()) return true; } return false; } +bool MEDFileFieldPerMesh::presenceOfStructureElements() const +{ + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + if((*it).isNotNull()) + { + const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast((const MEDFileFieldPerMeshPerTypeCommon *)*it)); + if(pt) + return true; + } + return false; +} + +bool MEDFileFieldPerMesh::onlyStructureElements() const +{ + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + if((*it).isNotNull()) + { + const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast((const MEDFileFieldPerMeshPerTypeCommon *)*it)); + if(!pt) + return false; + } + return true; +} + +void MEDFileFieldPerMesh::killStructureElements() +{ + std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res; + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + { + if((*it).isNotNull()) + { + const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast((const MEDFileFieldPerMeshPerTypeCommon *)*it)); + if(!pt) + res.push_back(*it); + } + } + _field_pm_pt=res; +} + +void MEDFileFieldPerMesh::keepOnlyStructureElements() +{ + std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res; + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + { + if((*it).isNotNull()) + { + const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast((const MEDFileFieldPerMeshPerTypeCommon *)*it)); + if(pt) + res.push_back(*it); + } + } + _field_pm_pt=res; +} + DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() { if(!_father) @@ -1979,7 +2137,7 @@ std::vector MEDFileFieldPerMesh::getPflsReallyUsed() const { std::vector ret; std::set ret2; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { std::vector tmp=(*it)->getPflsReallyUsed(); for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) @@ -1995,7 +2153,7 @@ std::vector MEDFileFieldPerMesh::getPflsReallyUsed() const std::vector MEDFileFieldPerMesh::getPflsReallyUsedMulti() const { std::vector ret; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { std::vector tmp=(*it)->getPflsReallyUsedMulti(); ret.insert(ret.end(),tmp.begin(),tmp.end()); @@ -2007,7 +2165,7 @@ std::vector MEDFileFieldPerMesh::getLocsReallyUsed() const { std::vector ret; std::set ret2; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { std::vector tmp=(*it)->getLocsReallyUsed(); for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) @@ -2023,7 +2181,7 @@ std::vector MEDFileFieldPerMesh::getLocsReallyUsed() const std::vector MEDFileFieldPerMesh::getLocsReallyUsedMulti() const { std::vector ret; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { std::vector tmp=(*it)->getLocsReallyUsedMulti(); ret.insert(ret.end(),tmp.begin(),tmp.end()); @@ -2149,8 +2307,8 @@ bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshNam */ void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair >& its) { - std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret; + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { std::vector< std::pair > its2; if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2)) @@ -2168,8 +2326,8 @@ void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &gl */ void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair >& its) { - std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret; + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { std::vector< std::pair > its2; if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2)) @@ -2187,27 +2345,28 @@ void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFiel for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++) types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it); // - std::vector< MCAuto< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size()); + std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size()); std::map > >::const_iterator it1=types.begin(); - std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin(); + std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin(); for(;it1!=types.end();it1++,it2++) { MCAuto elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId())); elt->setLeaves((*it1).second); - *it2=elt; + MCAuto elt2(DynamicCast(elt)); + *it2=elt2; } _field_pm_pt=fieldPmPt; } void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair, std::string > >& mapOfModif) { - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) (*it)->changePflsRefsNamesGen(mapOfModif); } void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair, std::string > >& mapOfModif) { - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) (*it)->changeLocsRefsNamesGen(mapOfModif); } @@ -2224,7 +2383,7 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField t std::vector notNullPflsPerGeoType; std::vector locs,code; std::vector geoTypes; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes); // Sort by types SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType); @@ -2277,7 +2436,7 @@ DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, c std::vector notNullPflsPerGeoType; std::vector locs,code; std::vector geoTypes; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes); // Sort by types SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType); @@ -2317,13 +2476,13 @@ void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { (*it)->getSizes(globalSz,nbOfEntries); } entries.resize(nbOfEntries); nbOfEntries=0; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { (*it)->fillValues(nbOfEntries,entries); } @@ -2331,7 +2490,7 @@ void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { if((*it)->getGeoType()==typ) return (*it)->getLeafGivenLocId(locId); @@ -2339,7 +2498,7 @@ MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ); std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl; oss << "Possiblities are : "; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType()); oss << "\"" << cm2.getRepr() << "\", "; @@ -2349,7 +2508,7 @@ MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const { - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { if((*it)->getGeoType()==typ) return (*it)->getLeafGivenLocId(locId); @@ -2357,7 +2516,7 @@ const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAn const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ); std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl; oss << "Possiblities are : "; - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) { const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType()); oss << "\"" << cm2.getRepr() << "\", "; @@ -2410,23 +2569,6 @@ MCAuto MEDFileFieldPerMeshPerTypePerDisc::Agg return ret; } -MCAuto MEDFileFieldPerMeshPerTypeCommon::Aggregate(int &start, const std::vector >& pms, const std::vector< std::vector< std::pair > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector > >& extractInfo) -{ - MCAuto ret(MEDFileFieldPerMeshPerType::New(father,gt)); - std::map > > m; - for(std::vector >::const_iterator it=pms.begin();it!=pms.end();it++) - { - for(std::vector< MCAuto >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++) - m[(*it2)->getType()].push_back(std::pair((*it).first,*it2)); - } - for(std::map > >::const_iterator it=m.begin();it!=m.end();it++) - { - MCAuto agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo)); - ret->_field_pm_pt_pd.push_back(agg); - } - return ret; -} - MCAuto MEDFileFieldPerMesh::Aggregate(int &start, const std::vector& pms, const std::vector< std::vector< std::pair > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector > >& extractInfo) { MCAuto ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder())); @@ -2434,17 +2576,21 @@ MCAuto MEDFileFieldPerMesh::Aggregate(int &start, const std std::size_t i(0); for(std::vector::const_iterator it=pms.begin();it!=pms.end();it++,i++) { - const std::vector< MCAuto< MEDFileFieldPerMeshPerType > >& v((*it)->_field_pm_pt); - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it2=v.begin();it2!=v.end();it2++) + const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt); + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++) { INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType()); - m[gt].push_back(std::pair(i,*it2)); + const MEDFileFieldPerMeshPerType *elt(dynamic_cast((const MEDFileFieldPerMeshPerTypeCommon *)(*it2))); + if(!elt) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !"); + m[gt].push_back(std::pair(i,elt)); } } for(std::map > >::const_iterator it=m.begin();it!=m.end();it++) { - MCAuto agg(MEDFileFieldPerMeshPerTypeCommon::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo)); - ret->_field_pm_pt.push_back(agg); + MCAuto agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo)); + MCAuto agg2(DynamicCast(agg)); + ret->_field_pm_pt.push_back(agg2); } return ret; } @@ -2453,8 +2599,8 @@ int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellTyp { int i=0; int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type)); - std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin(); - for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++) + std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin(); + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++) { INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType(); if(type==curType) @@ -2671,8 +2817,7 @@ MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities) } return new MFFPMIter2(tmp); } - else - throw INTERP_KERNEL::Exception("MFFPMIter::NewCell : not recognized type !"); + return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in } } @@ -2691,8 +2836,7 @@ bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities) return true; return false; } - else - throw INTERP_KERNEL::Exception("MFFPMIter::IsPresenceOfNode : not recognized type !"); + return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in } } @@ -2750,6 +2894,18 @@ MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWith _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1); } } + if(!entities) + return ; + std::vector dynGT(entities->getDynGTAvail()); + for(std::vector::const_iterator it=dynGT.begin();it!=dynGT.end();it++) + { + int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName)); + if(nbPfl>0) + { + _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc)); + _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1); + } + } } MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath) @@ -4878,6 +5034,38 @@ bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const return false; } +bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + if(!(*it)->onlyStructureElements()) + return false; + return true; +} + +void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements() +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + (*it)->killStructureElements(); +} + +void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements() +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + (*it)->keepOnlyStructureElements(); +} + MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto& arrOut, const MEDFileFieldNameScope& nasc) const { static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to be extracted with \"field\" method ! Call getFieldOnMeshAtLevel method instead to deal with complexity !"; @@ -5307,17 +5495,17 @@ MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWi { } -MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const +MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const { MCAuto ret(new MEDFileField1TSWithoutSDA(*this)); ret->deepCpyLeavesFrom(*this); return ret.retn(); } -MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const +MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const { - MCAuto ret=static_cast(shallowCpy()); - if((const DataArrayDouble *)_arr) + MCAuto ret(shallowCpy()); + if(_arr.isNotNull()) ret->_arr=_arr->deepCopy(); return ret.retn(); } @@ -5406,17 +5594,17 @@ DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::v return getUndergroundDataArrayTemplate(); } -MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const +MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const { MCAuto ret(new MEDFileIntField1TSWithoutSDA(*this)); ret->deepCpyLeavesFrom(*this); return ret.retn(); } -MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const +MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const { - MCAuto ret=static_cast(shallowCpy()); - if((const DataArrayInt *)_arr) + MCAuto ret(shallowCpy()); + if(_arr.isNotNull()) ret->_arr=_arr->deepCopy(); return ret.retn(); } @@ -6724,7 +6912,7 @@ void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull()); } -MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const +MEDFileField1TS *MEDFileField1TS::shallowCpy() const { return new MEDFileField1TS(*this); } @@ -6836,7 +7024,7 @@ MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other { } -MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const +MEDFileIntField1TS *MEDFileIntField1TS::shallowCpy() const { return new MEDFileIntField1TS(*this); } @@ -7313,6 +7501,62 @@ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::part return buildFromTimeStepIds(ids->begin(),ids->end()); } +bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + if(!(*it)->onlyStructureElements()) + return false; + return true; +} + +void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements() +{ + std::vector< MCAuto > ret; + for(std::vector< MCAuto >::iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + { + if((*it)->presenceOfStructureElements()) + { + if(!(*it)->onlyStructureElements()) + { + (*it)->killStructureElements(); + ret.push_back(*it); + } + } + else + { + ret.push_back(*it); + } + } + _time_steps=ret; +} + +void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements() +{ + std::vector< MCAuto > ret; + for(std::vector< MCAuto >::iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + { + if((*it)->presenceOfStructureElements()) + { + if(!(*it)->onlyStructureElements()) + (*it)->keepOnlyStructureElements(); + ret.push_back(*it); + } + } + _time_steps=ret; +} + bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const { for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) @@ -10136,6 +10380,11 @@ MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll) MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll) { MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return NewWithDynGT(fid,se,loadAll); +} + +MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll) +{ if(!se) throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !"); INTERP_KERNEL::AutoCppPtr entities(MEDFileEntities::BuildFrom(*se)); @@ -10800,6 +11049,60 @@ MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std:: return ret.retn(); } +bool MEDFileFields::presenceOfStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_fields.begin();it!=_fields.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +void MEDFileFields::killStructureElements() +{ + std::vector< MCAuto > ret; + for(std::vector< MCAuto >::iterator it=_fields.begin();it!=_fields.end();it++) + if((*it).isNotNull()) + { + if((*it)->presenceOfStructureElements()) + { + if(!(*it)->onlyStructureElements()) + { + (*it)->killStructureElements(); + ret.push_back(*it); + } + } + else + { + ret.push_back(*it); + } + } + _fields=ret; +} + +void MEDFileFields::keepOnlyStructureElements() +{ + std::vector< MCAuto > ret; + for(std::vector< MCAuto >::iterator it=_fields.begin();it!=_fields.end();it++) + if((*it).isNotNull()) + { + if((*it)->presenceOfStructureElements()) + { + if(!(*it)->onlyStructureElements()) + (*it)->keepOnlyStructureElements(); + ret.push_back(*it); + } + } + _fields=ret; +} + +MCAuto MEDFileFields::partOfThisOnStructureElements() const +{ + MCAuto ret(deepCopy()); + ret->keepOnlyStructureElements(); + return ret; +} + MEDFileFieldsIterator *MEDFileFields::iterator() { return new MEDFileFieldsIterator(this);