From a75f4466e1769583cbf8b599933200aec4ea3b33 Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 24 Jul 2013 15:43:37 +0000 Subject: [PATCH] Target MEDReader --- src/MEDLoader/MEDFileFieldOverView.cxx | 123 ++++++++++++++++++++++++- src/MEDLoader/MEDFileFieldOverView.hxx | 4 + 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index ab12329ca..8f8fceccf 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -137,6 +137,22 @@ void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMesh checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs); } +int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const +{ + if(_loc.empty()) + { + if(getPflName().empty()) + return (_start_end.second-_start_end.first)/_nb_of_entity; + else + return (_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples(); + } + else + { + const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str())); + return loc.getNumberOfGaussPoints(); + } +} + std::string MEDFileField1TSStructItem2::getPflName() const { return _pfl->getName(); @@ -915,9 +931,8 @@ DataArray *MEDMeshMultiLev::buildDataArray(const MEDFileField1TSStructItem& fst, MEDCouplingAutoRefCountObjectPtr ret(const_cast(vals)); ret->incrRef(); if(isFastlyTheSameStruct(fst,globs)) return ret.retn(); - //else - // return constructDataArray(fst,globs,vals); - return 0; + else + return constructDataArray(fst,globs,vals); } std::string MEDMeshMultiLev::getPflNameOfId(int id) const @@ -931,6 +946,108 @@ std::string MEDMeshMultiLev::getPflNameOfId(int id) const return pfl->getName(); } +DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const throw(INTERP_KERNEL::Exception) +{ + if(fst.getType()==ON_NODES) + { + if(fst.getNumberOfItems()!=1) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !"); + const MEDFileField1TSStructItem2& p(fst[0]); + std::string pflName(p.getPflName()); + const DataArrayInt *nr(_node_reduction); + if(pflName.empty() && !nr) + return vals->deepCpy(); + if(pflName.empty() && nr) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !"); + if(!pflName.empty() && nr) + { + MEDCouplingAutoRefCountObjectPtr p1(globs->getProfile(pflName.c_str())->deepCpy()); + MEDCouplingAutoRefCountObjectPtr p2(nr->deepCpy()); + p1->sort(true); p2->sort(true); + if(!p1->isEqualWithoutConsideringStr(*p2)) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 3 !"); + p1=globs->getProfile(pflName.c_str())->checkAndPreparePermutation(); + p2=nr->checkAndPreparePermutation(); + p1=p1->invertArrayO2N2N2O(p1->getNumberOfTuples()); + p2=p1->selectByTupleIdSafe(p2->begin(),p2->end()); + MEDCouplingAutoRefCountObjectPtr ret(vals->deepCpy()); + ret->renumberInPlace(p2->begin()); + return ret.retn(); + } + if(!pflName.empty() && !nr) + { + MEDCouplingAutoRefCountObjectPtr p1(globs->getProfile(pflName.c_str())->deepCpy()); + p1->sort(true); + if(!p1->isIdentity() || p1->getNumberOfTuples()!=p.getNbEntity()) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !"); + MEDCouplingAutoRefCountObjectPtr ret(vals->deepCpy()); + ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin()); + return ret.retn(); + } + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !"); + } + else + { + std::size_t sz(fst.getNumberOfItems()); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrSafe(sz); + std::vector< const DataArray *> arr(sz); + for(std::size_t i=0;i& strtStop(p.getStartStop()); + std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it(std::find(_geo_types.begin(),_geo_types.end(),p.getGeo())); + if(it==_geo_types.end()) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !"); + if(std::find(it+1,_geo_types.end(),p.getGeo())!=_geo_types.end()) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !"); + std::size_t pos(std::distance(_geo_types.begin(),it)); + const DataArrayInt *thisP(_pfls[pos]),*otherP(p.getPfl(globs)); + MEDCouplingAutoRefCountObjectPtr ret(vals->selectByTupleId2(strtStop.first,strtStop.second,1)); + if(!thisP && !otherP) + { + arrSafe[i]=ret; arr[i]=ret; + continue; + } + int nbi(p.getNbOfIntegrationPts(globs)),nc(ret->getNumberOfComponents()); + if(!thisP && otherP) + { + MEDCouplingAutoRefCountObjectPtr p1(otherP->deepCpy()); + p1->sort(true); + if(!p1->isIdentity() || p1->getNumberOfTuples()!=p.getNbEntity()) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !"); + ret->rearrange(nbi*nc); ret->renumberInPlace(otherP->begin()); ret->rearrange(nc); + arrSafe[i]=ret; arr[i]=ret; + continue; + } + if(thisP && otherP) + { + MEDCouplingAutoRefCountObjectPtr p1(otherP->deepCpy()); + MEDCouplingAutoRefCountObjectPtr p2(thisP->deepCpy()); + p1->sort(true); p2->sort(true); + if(!p1->isEqualWithoutConsideringStr(*p2)) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !"); + p1=otherP->checkAndPreparePermutation(); + p2=thisP->checkAndPreparePermutation(); + p1=p1->invertArrayO2N2N2O(p1->getNumberOfTuples()); + p2=p1->selectByTupleIdSafe(p2->begin(),p2->end()); + ret->rearrange(nbi*nc); ret->renumberInPlace(otherP->begin()); ret->rearrange(nc); + continue; + } + if(thisP && !otherP) + { + MEDCouplingAutoRefCountObjectPtr p1(thisP->deepCpy()); + p1->sort(true); + if(!p1->isIdentity() || p1->getNumberOfTuples()!=p.getNbEntity()) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !"); + ret->rearrange(nbi*nc); ret->renumberInPlaceR(otherP->begin()); ret->rearrange(nc); + arrSafe[i]=ret; arr[i]=ret; + continue; + } + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 6 !"); + } + } +} + MEDMeshMultiLev::MEDMeshMultiLev() { } diff --git a/src/MEDLoader/MEDFileFieldOverView.hxx b/src/MEDLoader/MEDFileFieldOverView.hxx index 15b1d266d..3aaa55dc5 100644 --- a/src/MEDLoader/MEDFileFieldOverView.hxx +++ b/src/MEDLoader/MEDFileFieldOverView.hxx @@ -80,6 +80,7 @@ namespace ParaMEDMEM virtual MEDMeshMultiLev *prepare() const throw(INTERP_KERNEL::Exception) = 0; protected: std::string getPflNameOfId(int id) const; + DataArray *constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const throw(INTERP_KERNEL::Exception); protected: MEDMeshMultiLev(); MEDMeshMultiLev(const MEDMeshMultiLev& other); @@ -164,7 +165,10 @@ namespace ParaMEDMEM // const DataArrayInt *getPfl(const MEDFileFieldGlobsReal *globs) const; INTERP_KERNEL::NormalizedCellType getGeo() const { return _geo_type; } + int getNbEntity() const { return _nb_of_entity; } + const std::pair& getStartStop() const { return _start_end; } std::string getPflName() const; + int getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const; //! warning this method also set _nb_of_entity attribute ! void checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception); bool isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const char *pflName) const; -- 2.39.2