From: ageay Date: Thu, 25 Aug 2011 08:18:29 +0000 (+0000) Subject: Low level method to have access of arrays by type. X-Git-Tag: V6_main_FINAL~976 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bb5ca776e898bcdbefa38cfb012acd50ba770e0b;p=tools%2Fmedcoupling.git Low level method to have access of arrays by type. --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 03b1d21fe..64ac48e87 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -378,6 +378,14 @@ void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid) const throw(INTERP_ reinterpret_cast(_arr->getConstPointer())); } +void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, const DataArrayDouble *& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception) +{ + type=_type; + pfl=_profile; + loc=_localization; + dad=_arr; +} + int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception) { switch(type) @@ -611,6 +619,16 @@ void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set } } +void MEDFileFieldPerMeshPerType::fillFieldSplitedByType(std::vector& dads, std::vector& types, std::vector& pfls, std::vector& locs) const throw(INTERP_KERNEL::Exception) +{ + int sz=_field_pm_pt_pd.size(); + dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz); + for(int i=0;igetCoarseData(types[i],dads[i],pfls[i],locs[i]); + } +} + int MEDFileFieldPerMeshPerType::getIteration() const { return _father->getIteration(); @@ -872,6 +890,19 @@ void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set& types (*it)->fillTypesOfFieldAvailable(types); } +std::vector< std::vector > MEDFileFieldPerMesh::getFieldSplitedByType(std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector > & locs) const throw(INTERP_KERNEL::Exception) +{ + int sz=_field_pm_pt.size(); + std::vector< std::vector > ret(sz); + types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz); + for(int i=0;igetGeoType(); + _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]); + } + return ret; +} + double MEDFileFieldPerMesh::getTime() const { return _father->getTime(); @@ -1737,6 +1768,20 @@ std::vector MEDFileField1TSWithoutDAS::getTypesOfFieldAvailable() c return ret; } +/*! + * entry point for users that want to iterate into MEDFile DataStructure without any overhead. + */ +std::vector< std::vector > MEDFileField1TSWithoutDAS::getFieldSplitedByType(const char *mname, std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const throw(INTERP_KERNEL::Exception) +{ + int meshId=0; + if(mname) + meshId=getMeshIdFromMeshName(mname); + else + if(_field_per_mesh.empty()) + throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::getFieldSplitedByType : This is empty !"); + return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs); +} + void MEDFileField1TSWithoutDAS::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception) { med_int numdt,numit; @@ -2377,6 +2422,11 @@ std::vector< std::vector > MEDFileFieldMultiTSWithoutDAS::getTypesO return ret; } +std::vector< std::vector > MEDFileFieldMultiTSWithoutDAS::getFieldSplitedByType(int iteration, int order, const char *mname, std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const throw(INTERP_KERNEL::Exception) +{ + return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs); +} + const MEDFileField1TSWithoutDAS& MEDFileFieldMultiTSWithoutDAS::getTimeStepEntry(int iteration, int order) const throw(INTERP_KERNEL::Exception) { for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 2c9a2cba3..8909fc53c 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -85,6 +85,7 @@ namespace ParaMEDMEM void assignFieldProfile(const char *pflName, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldProfile(const char *pflName, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void getCoarseData(TypeOfField& type, const DataArrayDouble *& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); const MEDFileFieldPerMeshPerType *getFather() const; int getIteration() const; @@ -134,6 +135,7 @@ namespace ParaMEDMEM void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); void getDimension(int& dim) const; void fillTypesOfFieldAvailable(std::set& types) const throw(INTERP_KERNEL::Exception); + void fillFieldSplitedByType(std::vector& dads, std::vector& types, std::vector& pfls, std::vector& locs) const throw(INTERP_KERNEL::Exception); int getIteration() const; int getOrder() const; double getTime() const; @@ -172,6 +174,7 @@ namespace ParaMEDMEM void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); void fillTypesOfFieldAvailable(std::set& types) const throw(INTERP_KERNEL::Exception); + std::vector< std::vector > getFieldSplitedByType(std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const throw(INTERP_KERNEL::Exception); void getDimension(int& dim) const; double getTime() const; int getIteration() const; @@ -310,6 +313,7 @@ namespace ParaMEDMEM void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); public: std::vector getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception); + std::vector< std::vector > getFieldSplitedByType(const char *mname, std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFieldFieldGlobsReal *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception); @@ -364,6 +368,7 @@ namespace ParaMEDMEM int getNumberOfTS() const; std::vector< std::pair > getIterations() const; std::vector< std::vector > getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception); + std::vector< std::vector > getFieldSplitedByType(int iteration, int order, const char *mname, std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); std::string getName() const; std::vector< std::pair > getTimeSteps(std::vector& ret1) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index e7733e217..98bfc961f 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -572,10 +572,46 @@ namespace ParaMEDMEM { std::vector ret=self->getTypesOfFieldAvailable(); PyObject *ret2=PyList_New(ret.size()); - for(int i=0;i types; + std::vector< std::vector > typesF; + std::vector< std::vector > pfls; + std::vector< std::vector > locs; + std::vector< std::vector > ret=self->getFieldSplitedByType(mname,types,typesF,pfls,locs); + int sz=ret.size(); + PyObject *ret2=PyList_New(sz); + for(int i=0;i& dadsI=ret[i]; + const std::vector& typesFI=typesF[i]; + const std::vector& pflsI=pfls[i]; + const std::vector& locsI=locs[i]; + PyObject *elt=PyTuple_New(2); + PyTuple_SetItem(elt,0,SWIG_From_int(types[i])); + int sz2=ret[i].size(); + PyObject *elt2=PyList_New(sz2); + for(int j=0;jincrRef(); + PyTuple_SetItem(elt3,0,SWIG_From_int(typesFI[j])); + PyTuple_SetItem(elt3,1,SWIG_NewPointerObj(SWIG_as_voidptr(dadsI[j]),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(elt3,2,PyString_FromString(pflsI[j].c_str())); + PyTuple_SetItem(elt3,3,PyString_FromString(locsI[j].c_str())); + PyList_SetItem(elt2,j,elt3); + } + PyTuple_SetItem(elt,1,elt2); + PyList_SetItem(ret2,i,elt); + } + return ret2; + } } }; @@ -651,16 +687,52 @@ namespace ParaMEDMEM { std::vector< std::vector > ret=self->getTypesOfFieldAvailable(); PyObject *ret2=PyList_New(ret.size()); - for(int i=0;i& rett=ret[i]; PyObject *ret3=PyList_New(rett.size()); - for(int j=0;j types; + std::vector< std::vector > typesF; + std::vector< std::vector > pfls; + std::vector< std::vector > locs; + std::vector< std::vector > ret=self->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs); + int sz=ret.size(); + PyObject *ret2=PyList_New(sz); + for(int i=0;i& dadsI=ret[i]; + const std::vector& typesFI=typesF[i]; + const std::vector& pflsI=pfls[i]; + const std::vector& locsI=locs[i]; + PyObject *elt=PyTuple_New(2); + PyTuple_SetItem(elt,0,SWIG_From_int(types[i])); + int sz2=ret[i].size(); + PyObject *elt2=PyList_New(sz2); + for(int j=0;jincrRef(); + PyTuple_SetItem(elt3,0,SWIG_From_int(typesFI[j])); + PyTuple_SetItem(elt3,1,SWIG_NewPointerObj(SWIG_as_voidptr(dadsI[j]),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(elt3,2,PyString_FromString(pflsI[j].c_str())); + PyTuple_SetItem(elt3,3,PyString_FromString(locsI[j].c_str())); + PyList_SetItem(elt2,j,elt3); + } + PyTuple_SetItem(elt,1,elt2); + PyList_SetItem(ret2,i,elt); + } + return ret2; + } } };