From 5ba9c0eb22796123cf4583e19adb9dbce832633c Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 23 Feb 2012 11:53:21 +0000 Subject: [PATCH] New organization of arrays. One array per MEDFileField1TSWithoutDAS rather than plenty one. --- src/MEDLoader/MEDFileField.cxx | 34 ++++++++++-- src/MEDLoader/MEDFileField.hxx | 6 +- src/MEDLoader/SauvWriter.cxx | 30 +++++----- src/MEDLoader/Swig/MEDLoader.i | 82 +++++++++++++++++++++++++--- src/MEDLoader/Swig/MEDLoaderTest3.py | 4 +- 5 files changed, 125 insertions(+), 31 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index f17d480cf..d48dc5a17 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -2114,7 +2114,22 @@ std::vector MEDFileField1TSWithoutDAS::getTypesOfFieldAvailable() c /*! * 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) +std::vector< std::vector< std::pair > > 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); +} + +/*! + * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially + * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller. + */ +std::vector< std::vector > MEDFileField1TSWithoutDAS::getFieldSplitedByType2(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) @@ -2124,7 +2139,7 @@ std::vector< std::vector > MEDFileField1TSWithoutDAS::g throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::getFieldSplitedByType : This is empty !"); std::vector< std::vector< std::pair > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs); int nbOfRet=ret0.size(); - std::vector< std::vector > ret(nbOfRet); + std::vector< std::vector > ret(nbOfRet); for(int i=0;i >& p=ret0[i]; @@ -2136,7 +2151,6 @@ std::vector< std::vector > MEDFileField1TSWithoutDAS::g ret[i][j]=tmp; } } - //anthony.geay@cea.fr return ret; } @@ -2862,11 +2876,23 @@ 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) +/*! + * entry point for users that want to iterate into MEDFile DataStructure without any overhead. + */ +std::vector< std::vector< std::pair > > 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); } +/*! + * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially + * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller. + */ +std::vector< std::vector > MEDFileFieldMultiTSWithoutDAS::getFieldSplitedByType2(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).getFieldSplitedByType2(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 a124ad9aa..4bbc0570b 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -351,7 +351,8 @@ 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); + 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); + std::vector< std::vector > getFieldSplitedByType2(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); @@ -413,7 +414,8 @@ 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); + std::vector< std::vector< std::pair > > 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); + std::vector< std::vector > getFieldSplitedByType2(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); virtual 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/SauvWriter.cxx b/src/MEDLoader/SauvWriter.cxx index 712ba6940..fb41ea3a6 100644 --- a/src/MEDLoader/SauvWriter.cxx +++ b/src/MEDLoader/SauvWriter.cxx @@ -1049,9 +1049,9 @@ void SauvWriter::writeNodalFields(map& fldNamePrefixMap) vector types; vector< vector > typesF; vector< vector > pfls, locs; - vector< vector > valsVec; - valsVec = _nodeFields[iF]->getFieldSplitedByType( it.first, it.second, _fileMesh->getName(), - types, typesF, pfls, locs); + vector< vector< std::pair > > valsVec; + valsVec=_nodeFields[iF]->getFieldSplitedByType( it.first, it.second, _fileMesh->getName(), + types, typesF, pfls, locs); // believe that there can be only one type in a nodal field, // so do not use a loop on types if ( pfls[0][0].empty() ) pfls[0][0] = noProfileName( types[0] ); @@ -1060,7 +1060,7 @@ void SauvWriter::writeNodalFields(map& fldNamePrefixMap) THROW_IK_EXCEPTION( "SauvWriter::writeNodalFields(): no sub-mesh for profile |" << pfls[0][0] << "|"); vals[0] = -pfl2Sub->second->_id; - vals[1] = valsVec[0][0]->getNumberOfTuples() / nbComp; + vals[1] = (valsVec[0][0].second-valsVec[0][0].first); vals[2] = compInfo.size(); for ( size_t i = 0; i < vals.size(); ++i, fcount++ ) *_sauvFile << setw(8) << vals[i]; @@ -1098,15 +1098,15 @@ void SauvWriter::writeNodalFields(map& fldNamePrefixMap) vector types; vector< vector > typesF; vector< vector > pfls, locs; - vector< vector > valsVec; + vector< vector< std::pair > > valsVec; valsVec = _nodeFields[iF]->getFieldSplitedByType( it.first, it.second, _fileMesh->getName(), types, typesF, pfls, locs); // believe that there can be only one type in a nodal field, // so do not perform a loop on types - const DataArrayDouble* valsArray = valsVec[0][0]; + const DataArrayDouble* valsArray = _nodeFields[iF]->getUndergroundDataArray(it.first, it.second); for ( size_t j = 0; j < compInfo.size(); ++j ) { - for ( size_t i = 0; i < (std::size_t)valsArray->getNumberOfTuples(); ++i, fcount++ ) + for ( size_t i = valsVec[0][0].first; i < (std::size_t)valsVec[0][0].second; ++i, fcount++ ) *_sauvFile << setw(22) << valsArray->getIJ( i, j ); fcount.stop(); } @@ -1159,7 +1159,7 @@ void SauvWriter::writeElemFields(map& fldNamePrefixMap) vector types; vector< vector > typesF; vector< vector > pfls, locs; - vector< vector > valsVec; + vector< vector< std::pair > > valsVec; valsVec = _cellFields[iF]->getFieldSplitedByType( it.first, it.second, _fileMesh->getName(), types, typesF, pfls, locs); for ( size_t i = 0; i < valsVec.size(); ++i ) @@ -1187,9 +1187,8 @@ void SauvWriter::writeElemFields(map& fldNamePrefixMap) vector types; vector< vector > typesF; vector< vector > pfls, locs; - vector< vector > valsVec; - valsVec = _cellFields[iF]->getFieldSplitedByType( it.first, it.second, _fileMesh->getName(), - types, typesF, pfls, locs); + _cellFields[iF]->getFieldSplitedByType( it.first, it.second, _fileMesh->getName(), + types, typesF, pfls, locs); for ( size_t iType = 0; iType < pfls.size(); ++iType ) for ( size_t iP = 0; iP < pfls[iType].size(); ++iP ) { @@ -1253,7 +1252,7 @@ void SauvWriter::writeElemTimeStamp(int iF, int iter, int order) vector types; vector< vector > typesF; vector< vector > pfls, locs; - vector< vector > valsVec; + vector< vector< std::pair > > valsVec; valsVec = _cellFields[iF]->getFieldSplitedByType( iter, order, _fileMesh->getName(), types, typesF, pfls, locs); for ( size_t iType = 0; iType < pfls.size(); ++iType ) @@ -1294,16 +1293,17 @@ void SauvWriter::writeElemTimeStamp(int iF, int iter, int order) } // (10) values - const DataArrayDouble* valArray = valsVec[iType][iP]; + const std::pair& bgEnd = valsVec[iType][iP]; + const DataArrayDouble* valArray = _cellFields[iF]->getUndergroundDataArray(iter, order); for ( iComp = 0; iComp < nbComp; ++iComp ) { *_sauvFile << setw(8) << nbPntPerCell - << setw(8) << valArray->getNbOfElems() / nbPntPerCell / nbComp + << setw(8) << (bgEnd.second-bgEnd.first) / nbPntPerCell << setw(8) << 0 << setw(8) << 0 << endl; fcount.init(3); - for ( size_t i = 0; i < (size_t) valArray->getNumberOfTuples(); ++i, fcount++ ) + for ( size_t i = bgEnd.first; i < (size_t) bgEnd.second; ++i, fcount++ ) *_sauvFile << setw(22) << valArray->getIJ( i, iComp ); fcount.stop(); } diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 8d00dc296..b83fbfeb9 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -707,12 +707,47 @@ namespace ParaMEDMEM 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); + std::vector< std::vector< std::pair > > 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< std::pair >& 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;j types; + std::vector< std::vector > typesF; + std::vector< std::vector > pfls; + std::vector< std::vector > locs; + std::vector< std::vector > ret=self->getFieldSplitedByType2(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]; @@ -723,8 +758,6 @@ namespace ParaMEDMEM 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())); @@ -864,12 +897,47 @@ namespace ParaMEDMEM 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); + std::vector< std::vector< std::pair > > 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;j types; + std::vector< std::vector > typesF; + std::vector< std::vector > pfls; + std::vector< std::vector > locs; + std::vector< std::vector > ret=self->getFieldSplitedByType2(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& dadsI=ret[i]; const std::vector& typesFI=typesF[i]; const std::vector& pflsI=pfls[i]; const std::vector& locsI=locs[i]; @@ -880,8 +948,6 @@ namespace ParaMEDMEM 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())); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 0d62132f3..79e6a639e 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -515,7 +515,7 @@ class MEDLoaderTest(unittest.TestCase): ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2]) f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0) self.assertTrue(f1.isEqual(f2,1e-12,1e-12)) - sbt=ff2.getFieldSplitedByType() + sbt=ff2.getFieldSplitedByType2() loc1=ff2.getLocalization("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5") self.assertEqual("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5",loc1.getName()) self.assertEqual((-1, 1,-1,-1,1,-1,-1,0,0,-1,0,0),loc1.getRefCoords()) @@ -596,7 +596,7 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(vals.isEqual(d,1e-14)) # ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1) - sbt=ff2.getFieldSplitedByType() + sbt=ff2.getFieldSplitedByType2() self.assertEqual(3,sbt[0][0])#TRI3 self.assertEqual(0,sbt[0][1][0][0])#CELL For TRI3 self.assertEqual("",sbt[0][1][0][2])#no profile For TRI3 -- 2.39.2