From: Anthony Geay Date: Wed, 1 Oct 2014 11:58:22 +0000 (+0200) Subject: On the road of ParaMEDReader for fields. X-Git-Tag: V7_5_0a1~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=81a526de5d2d181f68bf6ed56c1bf84c86c1680e;p=modules%2Fmed.git On the road of ParaMEDReader for fields. --- diff --git a/src/MEDCoupling/MEDCouplingPartDefinition.cxx b/src/MEDCoupling/MEDCouplingPartDefinition.cxx index 08c1d2282..4ff6ad4a0 100644 --- a/src/MEDCoupling/MEDCouplingPartDefinition.cxx +++ b/src/MEDCoupling/MEDCouplingPartDefinition.cxx @@ -178,6 +178,13 @@ int SlicePartDefinition::getEffectiveStop() const return _start+nbElems*_step; } +void SlicePartDefinition::getSlice(int& start, int& stop, int& step) const +{ + start=_start; + stop=_stop; + step=_step; +} + SlicePartDefinition::SlicePartDefinition(int start, int stop, int step):_start(start),_stop(stop),_step(step) { } diff --git a/src/MEDCoupling/MEDCouplingPartDefinition.hxx b/src/MEDCoupling/MEDCouplingPartDefinition.hxx index a64ca77c1..d30868f0b 100644 --- a/src/MEDCoupling/MEDCouplingPartDefinition.hxx +++ b/src/MEDCoupling/MEDCouplingPartDefinition.hxx @@ -74,6 +74,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT std::string getRepr() const; //specific method MEDCOUPLING_EXPORT int getEffectiveStop() const; + MEDCOUPLING_EXPORT void getSlice(int& start, int& stop, int& step) const; private: SlicePartDefinition(int start, int stop, int step); MEDCOUPLING_EXPORT void updateTime() const; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 6d3fa8e9f..e0334fbea 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -15930,6 +15930,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(pd.toDAI().isEqual(DataArrayInt([5,8,11,14,17,20]))) self.assertEqual(pd.getNumberOfElems(),6) self.assertEqual(pd.getEffectiveStop(),23) + self.assertEqual(pd.getSlice(),slice(5,23,3)) pd=PartDefinition.New(5,22,1) self.assertTrue(isinstance(pd,SlicePartDefinition)) self.assertTrue(pd.toDAI().isEqual(DataArrayInt([5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]))) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index c5820aef9..86dbd41ac 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -5466,6 +5466,13 @@ namespace ParaMEDMEM { return SlicePartDefinition::New(start,stop,step); } + + PyObject *getSlice() const throw(INTERP_KERNEL::Exception) + { + int a,b,c; + self->getSlice(a,b,c); + return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(c)); + } std::string __str__() const throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index aad1dfd60..f07c99ce4 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2032,6 +2032,7 @@ std::vector MEDFileUMesh::getDirectChildrenWithNull() c ret.push_back((const DataArrayInt *)_num_coords); ret.push_back((const DataArrayInt *)_rev_num_coords); ret.push_back((const DataArrayAsciiChar *)_name_coords); + ret.push_back((const PartDefinition *)_part_coords); for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++) ret.push_back((const MEDFileUMeshSplitL1*) *it); return ret; @@ -2297,6 +2298,7 @@ void MEDFileUMesh::dispatchLoadedPart(med_idt fid, const MEDFileUMeshL2& loaderl _num_coords=loaderl2.getCoordsNum(); if(!mrs || mrs->isNodeNameFieldReading()) _name_coords=loaderl2.getCoordsName(); + _part_coords=loaderl2.getPartDefOfCoo(); computeRevNum(); } @@ -2755,6 +2757,21 @@ const DataArrayAsciiChar *MEDFileUMesh::getNameFieldAtLevel(int meshDimRelToMaxE return l1->getNameField(); } +/*! + * This method returns for a specified relative level \a meshDimRelToMaxExt the part effectively read (if the instance is the result of the read of a file). + * + * \param [in] meshDimRelToMaxExt - the extended relative level for which the part definition is requested. + * \param [in] gt - The input geometric type for which the part definition is requested. + * \return the part definition owned by \a this. So no need to deallocate the returned instance. + */ +const PartDefinition *MEDFileUMesh::getPartDefAtLevel(int meshDimRelToMaxExt, INTERP_KERNEL::NormalizedCellType gt) const +{ + if(meshDimRelToMaxExt==1) + return _part_coords; + const MEDFileUMeshSplitL1 *l1(getMeshAtLevSafe(meshDimRelToMaxExt)); + return l1->getPartDef(gt); +} + int MEDFileUMesh::getNumberOfNodes() const { const DataArrayDouble *coo=_coords; @@ -3164,6 +3181,18 @@ DataArrayInt *MEDFileUMesh::extractNumberFieldOnGeoType(INTERP_KERNEL::Normalize return sp->extractNumberFieldOnGeoType(gt); } +/*! + * This method returns for specified geometric type \a gt the relative level to \a this. + * If the relative level is empty an exception will be thrown. + */ +int MEDFileUMesh::getRelativeLevOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(gt); + int ret((int)cm.getDimension()-getMeshDimension()); + getMeshAtLevSafe(ret);//To test that returned value corresponds to a valid level. + return ret; +} + const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const { if(meshDimRelToMaxExt==1) diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index a25401aea..7a76c0fe6 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -24,6 +24,7 @@ #include "MEDLoaderDefines.hxx" #include "MEDFileMeshLL.hxx" #include "MEDFileUtilities.hxx" +#include "MEDCouplingPartDefinition.hxx" #include "MEDFileMeshReadSelector.hxx" #include @@ -224,6 +225,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const; MEDLOADER_EXPORT const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const; MEDLOADER_EXPORT const DataArrayAsciiChar *getNameFieldAtLevel(int meshDimRelToMaxExt) const; + MEDLOADER_EXPORT const PartDefinition *getPartDefAtLevel(int meshDimRelToMaxExt, INTERP_KERNEL::NormalizedCellType gt=INTERP_KERNEL::NORM_ERROR) const; MEDLOADER_EXPORT int getNumberOfNodes() const; MEDLOADER_EXPORT bool hasImplicitPart() const; MEDLOADER_EXPORT int buildImplicitPartIfAny(INTERP_KERNEL::NormalizedCellType gt) const; @@ -262,6 +264,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const; MEDLOADER_EXPORT DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const; MEDLOADER_EXPORT DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const; + MEDLOADER_EXPORT int getRelativeLevOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const; // MEDLOADER_EXPORT void setFamilyNameAttachedOnId(int id, const std::string& newFamName); MEDLOADER_EXPORT void setCoords(DataArrayDouble *coords); @@ -306,6 +309,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _num_coords; MEDCouplingAutoRefCountObjectPtr _name_coords; mutable MEDCouplingAutoRefCountObjectPtr _rev_num_coords; + MEDCouplingAutoRefCountObjectPtr _part_coords; }; class MEDFileStructuredMesh : public MEDFileMesh diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index ce16d0da1..d09fa1d4e 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -124,6 +124,7 @@ void MEDFileUMeshPerType::loadPart(med_idt fid, const char *mName, int dt, int i med_bool changement,transformation; int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(type)); + _pd=PartDefinition::New(strt,end,step); if(!cm.isDynamic()) { loadPartStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity,strt,end,step,mrs); diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx index ed795f159..0a9098871 100644 --- a/src/MEDLoader/MEDFileMeshElt.hxx +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -23,6 +23,7 @@ #include "MEDCouplingMemArray.hxx" #include "MEDCoupling1GTUMesh.hxx" +#include "MEDCouplingPartDefinition.hxx" #include "MEDCouplingAutoRefCountObjectPtr.hxx" #include "NormalizedUnstructuredMesh.hxx" @@ -47,6 +48,7 @@ namespace ParaMEDMEM const DataArrayInt *getFam() const { return _fam; } const DataArrayInt *getNum() const { return _num; } const DataArrayAsciiChar *getNames() const { return _names; } + const PartDefinition *getPartDef() const { return _pd; } static void Write(med_idt fid, const std::string& mname, int mdim, const MEDCoupling1GTUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names); private: MEDFileUMeshPerType(); @@ -69,6 +71,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _num; MEDCouplingAutoRefCountObjectPtr _fam; MEDCouplingAutoRefCountObjectPtr _names; + MEDCouplingAutoRefCountObjectPtr _pd; med_entity_type _entity; }; } diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index a140e971b..0591a6bd9 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -378,6 +378,7 @@ void MEDFileUMeshL2::loadPartCoords(med_idt fid, int mId, const std::vectorgetPointer()); + _part_coords=PartDefinition::New(nMin,nMax,1); MEDfilterClose(&filter); MEDfilterBlockOfEntityCr(fid,nCoords,1,1,MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE, MED_NO_PROFILE,nMin+1,1,1,nbNodesToLoad,0,&filter2); @@ -634,15 +635,18 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::st int sz=v.size(); std::vector ms(sz); std::vector fams(sz),nums(sz); - std::vector names(sz); + std::vector names(sz); + std::vector pds(sz); for(int i=0;igetMesh()); MEDCouplingAutoRefCountObjectPtr tmp2=l2.getCoords(); elt->setCoords(tmp2); ms[i]=elt; + pds[i]=v[i]->getPartDef(); } _m_by_types.assignParts(ms); + _m_by_types.assignDefParts(pds); if(l2.isFamDefinedOnLev(id)) { for(int i=0;ifillWithZero(); @@ -1161,10 +1170,27 @@ void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupl ret[i]=const_cast(elt); elt->incrRef(); } _m_parts=ret; + _part_def.clear(); _part_def.resize(sz); _mp_time=std::max(_mp_time,_m_time)+1; _m=0; } +void MEDFileUMeshAggregateCompute::assignDefParts(const std::vector& partDefs) +{ + if(_mp_time<_m_time) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : the parts require a computation !"); + std::size_t sz(partDefs.size()); + if(_part_def.size()!=partDefs.size() || _part_def.size()!=_m_parts.size()) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : sizes of vectors of part definition mismatch !"); + for(std::size_t i=0;iincrRef(); + _part_def[i]=const_cast(elt); + } +} + void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m) { _m=m; @@ -1198,7 +1224,7 @@ std::vector MEDFileUMeshAggregateCompute::get return _m->getAllGeoTypesSorted(); } -std::vector MEDFileUMeshAggregateCompute::getPartsWithoutComputation() const +std::vector MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const { if(_mp_time<_m_time) throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !"); @@ -1217,12 +1243,12 @@ std::vector MEDFileUMeshAggregateCompute::getParts() cons { if(_mp_time<_m_time) forceComputationOfPartsFromUMesh(); - return getPartsWithoutComputation(); + return retrievePartsWithoutComputation(); } -MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const +MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const { - std::vector v(getPartsWithoutComputation()); + std::vector v(retrievePartsWithoutComputation()); std::size_t sz(v.size()); for(std::size_t i=0;i v(getPartsWithoutComputation()); + std::vector v(retrievePartsWithoutComputation()); std::size_t sz(v.size()); for(std::size_t i=0;igetCellModelEnum()==gt) + return _part_def[i]; + } + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !"); +} + std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const { if(_mp_time>_m_time) diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 8cdcc988f..4be19e047 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -27,6 +27,7 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingCMesh.hxx" #include "MEDCoupling1GTUMesh.hxx" +#include "MEDCouplingPartDefinition.hxx" #include "MEDCouplingCurveLinearMesh.hxx" #include "MEDCouplingAutoRefCountObjectPtr.hxx" @@ -51,6 +52,7 @@ namespace ParaMEDMEM int getIteration() const { return _iteration; } int getOrder() const { return _order; } double getTime() const { return _time; } + MEDCouplingAutoRefCountObjectPtr getPartDefOfCoo() const { return _part_coords; } std::vector getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim); static int GetMeshIdFromName(med_idt fid, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1); static double CheckMeshTimeStep(med_idt fid, const std::string& mname, int nstep, int dt, int it); @@ -64,6 +66,7 @@ namespace ParaMEDMEM int _iteration; int _order; double _time; + MEDCouplingAutoRefCountObjectPtr _part_coords; }; class MEDFileUMeshL2 : public MEDFileMeshL2 @@ -149,12 +152,13 @@ namespace ParaMEDMEM MEDFileUMeshAggregateCompute(); void setName(const std::string& name); void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts); + void assignDefParts(const std::vector& partDefs); void assignUMesh(MEDCouplingUMesh *m); MEDCouplingUMesh *getUmesh() const; std::vector getParts() const; std::vector getGeoTypes() const; - std::vector getPartsWithoutComputation() const; - MEDCoupling1GTUMesh *getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const; + std::vector retrievePartsWithoutComputation() const; + MEDCoupling1GTUMesh *retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const; void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const; std::size_t getTimeOfThis() const; std::size_t getHeapMemorySizeWithoutChildren() const; @@ -169,6 +173,7 @@ namespace ParaMEDMEM int getSize() const; void setCoords(DataArrayDouble *coords); void forceComputationOfPartsFromUMesh() const; + const PartDefinition *getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const; private: std::size_t getTimeOfParts() const; std::size_t getTimeOfUMesh() const; @@ -177,6 +182,7 @@ namespace ParaMEDMEM mutable std::size_t _mp_time; mutable std::size_t _m_time; mutable MEDCouplingAutoRefCountObjectPtr _m; + mutable std::vector< MEDCouplingAutoRefCountObjectPtr > _part_def; }; class MEDFileUMeshSplitL1 : public RefCountObject @@ -208,8 +214,8 @@ namespace ParaMEDMEM DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const; MEDCouplingUMesh *getWholeMesh(bool renum) const; std::vector getGeoTypes() const; - std::vector getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.getPartsWithoutComputation(); } - MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.getPartWithoutComputation(gt); } + std::vector getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.retrievePartsWithoutComputation(); } + MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.retrievePartWithoutComputation(gt); } DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const; DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const; std::vector getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); } @@ -218,6 +224,7 @@ namespace ParaMEDMEM const DataArrayInt *getNumberField() const; const DataArrayAsciiChar *getNameField() const; const DataArrayInt *getRevNumberField() const; + const PartDefinition *getPartDef(INTERP_KERNEL::NormalizedCellType gt) const; void eraseFamilyField(); void setGroupsFromScratch(const std::vector& ms, std::map& familyIds, std::map >& groups); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 3efbfad25..0da87e7b3 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -97,6 +97,7 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileUMesh::New; %newobject ParaMEDMEM::MEDFileUMesh::LoadPartOf; %newobject ParaMEDMEM::MEDFileUMesh::getCoords; +%newobject ParaMEDMEM::MEDFileUMesh::getPartDefAtLevel; %newobject ParaMEDMEM::MEDFileUMesh::getGroup; %newobject ParaMEDMEM::MEDFileUMesh::getGroups; %newobject ParaMEDMEM::MEDFileUMesh::getFamily; @@ -727,6 +728,7 @@ namespace ParaMEDMEM static MEDFileUMesh *New(); ~MEDFileUMesh(); int getSpaceDimension() const throw(INTERP_KERNEL::Exception); + int getRelativeLevOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception); // std::vector getGrpNonEmptyLevels(const std::string& grp) const throw(INTERP_KERNEL::Exception); std::vector getGrpNonEmptyLevelsExt(const std::string& grp) const throw(INTERP_KERNEL::Exception); @@ -840,6 +842,14 @@ namespace ParaMEDMEM return ret; } + PartDefinition *getPartDefAtLevel(int meshDimRelToMaxExt, INTERP_KERNEL::NormalizedCellType gt=INTERP_KERNEL::NORM_ERROR) const throw(INTERP_KERNEL::Exception) + { + const PartDefinition *ret(self->getPartDefAtLevel(meshDimRelToMaxExt,gt)); + if(ret) + ret->incrRef(); + return const_cast(ret); + } + PyObject *duplicateNodesOnM1Group(const std::string& grpNameM1) throw(INTERP_KERNEL::Exception) { DataArrayInt *ret0=0,*ret1=0,*ret2=0;