From: ageay Date: Tue, 24 Jan 2012 14:27:53 +0000 (+0000) Subject: Addition of underground pointer access in MEDFileField. X-Git-Tag: V6_main_FINAL~905 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ddb96a842eaf183a4c908f0ddcb5dc20cdf6ea81;p=tools%2Fmedcoupling.git Addition of underground pointer access in MEDFileField. --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 3fcf5878f..072d94350 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -445,6 +445,12 @@ void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const } } +DataArrayDouble *MEDFileFieldPerMeshPerTypePerDisc::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception) +{ + const DataArrayDouble *ret=_arr; + return const_cast(ret); +} + void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) { TypeOfField type=getType(); @@ -784,6 +790,15 @@ void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes); } +DataArrayDouble *MEDFileFieldPerMeshPerType::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception) +{ + if(_field_pm_pt_pd.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::getUndergroundDataArray : splitted MEDFileField*, this method has no sense !"); + if(_field_pm_pt_pd[0]==0) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::getUndergroundDataArray : no field specified !"); + return _field_pm_pt_pd[0]->getUndergroundDataArray(); +} + MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_geo_type(geoType) { } @@ -1230,6 +1245,15 @@ DataArrayDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField t return 0; } +DataArrayDouble *MEDFileFieldPerMesh::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception) +{ + if(_field_pm_pt.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getUndergroundDataArray : splitted MEDFileField*, this method has no sense !"); + if(_field_pm_pt[0]==0) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getUndergroundDataArray : no field specified !"); + return _field_pm_pt[0]->getUndergroundDataArray(); +} + int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type) { int i=0; @@ -2148,6 +2172,20 @@ DataArrayDouble *MEDFileField1TSWithoutDAS::getFieldWithProfile(TypeOfField type return _field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob); } +/*! + * This method retrieves direct access to the underground ParaMEDMEM::DataArrayDouble instance. + * This method allows to the user a direct access to the values. + * This method throws an exception if 'this' is composed with multiple arrays due to cell type splitting (field on cells and field on gauss points). + */ +DataArrayDouble *MEDFileField1TSWithoutDAS::getUndergroundDataArray() const throw(INTERP_KERNEL::Exception) +{ + if(_field_per_mesh.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::getUndergroundDataArray : splitted MEDFileField*, this method has no sense !"); + if(_field_per_mesh[0]==0) + throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::getUndergroundDataArray : no field specified !"); + return _field_per_mesh[0]->getUndergroundDataArray(); +} + MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, int csit, int iteration, int order, const std::vector& infos):_name(fieldName),_infos(infos),_csit(csit),_iteration(iteration),_order(order) { diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 19e429f9c..e46d3ed8e 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -114,6 +114,7 @@ namespace ParaMEDMEM int getLocId() const { return _loc_id; } void getFieldAtLevel(TypeOfField type, const MEDFieldFieldGlobsReal *glob, std::vector& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const; + DataArrayDouble *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception); static int ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception); private: MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid, TypeOfField type, int profileIt) throw(INTERP_KERNEL::Exception); @@ -156,6 +157,7 @@ namespace ParaMEDMEM std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; void getFieldAtLevel(int meshDim, TypeOfField type, const MEDFieldFieldGlobsReal *glob, std::vector& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const; + DataArrayDouble *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception); static med_entity_type ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType); private: std::vector addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception); @@ -199,6 +201,7 @@ namespace ParaMEDMEM std::vector getLocsReallyUsed() const; MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDFieldFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception); DataArrayDouble *getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception); private: int addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type); MEDCouplingFieldDouble *finishField(TypeOfField type, const MEDFieldFieldGlobsReal *glob, @@ -316,6 +319,7 @@ namespace ParaMEDMEM void fillIteration(std::pair& p) const; void fillTypesOfFieldAvailable(std::vector& types) const throw(INTERP_KERNEL::Exception); const std::vector& getInfo() const { return _infos; } + std::vector& getInfo() { return _infos; } // static MEDFileField1TSWithoutDAS *New(const char *fieldName, int csit, int iteration, int order, const std::vector& infos); void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); @@ -335,6 +339,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, const char *mName, int renumPol, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFieldFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum) const throw(INTERP_KERNEL::Exception); DataArrayDouble *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception); protected: int addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); int getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index bc8b4323f..daf58ddcd 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -89,6 +89,7 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldAtTopLevel; %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldOnMeshAtLevel; %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldAtLevelOld; +%newobject ParaMEDMEM::MEDFileField1TSWithoutDAS::getUndergroundDataArray; %newobject ParaMEDMEM::MEDFileField1TS::New; %newobject ParaMEDMEM::MEDFileField1TS::getFieldAtLevel; %newobject ParaMEDMEM::MEDFileField1TS::getFieldAtTopLevel; @@ -672,6 +673,14 @@ namespace ParaMEDMEM } return ret2; } + + DataArrayDouble *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception) + { + DataArrayDouble *ret=self->getUndergroundDataArray(); + if(ret) + ret->incrRef(); + return ret; + } } }; diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 935ebe005..f8d3c4024 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -461,8 +461,12 @@ class MEDLoaderTest(unittest.TestCase): mm1.write(fname,2) ff1=MEDFileField1TS.New() ff1.setFieldNoProfileSBT(f1) + nv=1456. + da=ff1.getUndergroundDataArray().setIJ(0,0,nv) ff1.write(fname,0) f2=MEDLoader.ReadFieldNode(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2]) + self.assertTrue(not f1.isEqual(f2,1e-12,1e-12)) + f1.getArray().setIJ(0,0,nv) self.assertTrue(f1.isEqual(f2,1e-12,1e-12)) # fname="Pyfile27.med"