From: ageay Date: Thu, 25 Aug 2011 11:03:05 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~973 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e886ac1712c65c87fb612626a1c365f9ae751c48;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 64ac48e87..769e1fd3d 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -102,6 +102,47 @@ void MEDFileFieldLoc::writeLL(med_idt fid) const MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT); } +std::string MEDFileFieldLoc::repr() const +{ + std::ostringstream oss; oss.precision(15); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); + oss << "Localization \"" << _name << "\" :\n" << " - Geometric Type : " << cm.getRepr(); + oss << "\n - Dimension : " << _dim << "\n - Number of gauss points : "; + oss << _nb_gauss_pt << "\n - Number of nodes in cell : " << _nb_node_per_cell; + oss << "\n - Ref coords are : "; + int sz=_ref_coo.size(); + if(sz%_dim==0) + { + int nbOfTuples=sz/_dim; + for(int i=0;i(oss," ")); + oss << "\n - Gauss coords in reference element : "; + sz=_gs_coo.size(); + if(sz%_dim==0) + { + int nbOfTuples=sz/_dim; + for(int i=0;i(oss," ")); + oss << "\n - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator(oss," ")); + return oss.str(); +} + void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { _type=field->getTypeOfField(); @@ -1442,6 +1483,11 @@ int MEDFieldFieldGlobs::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERN return _locs[locId]->getNbOfGaussPtPerCell(); } +const MEDFileFieldLoc& MEDFieldFieldGlobs::getLocalization(const char *pflName) const throw(INTERP_KERNEL::Exception) +{ + return getLocalizationFromId(getLocalizationId(pflName)); +} + const MEDFileFieldLoc& MEDFieldFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception) { if(locId<0 || locId>=(int)_locs.size()) @@ -1623,6 +1669,11 @@ std::string MEDFieldFieldGlobsReal::getFileName2() const return _globals->getFileName2(); } +const MEDFileFieldLoc& MEDFieldFieldGlobsReal::getLocalization(const char *pflName) const throw(INTERP_KERNEL::Exception) +{ + return _globals->getLocalization(pflName); +} + const MEDFileFieldLoc& MEDFieldFieldGlobsReal::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception) { return _globals->getLocalizationFromId(locId); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 470b19477..737acee13 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -52,7 +52,11 @@ namespace ParaMEDMEM static MEDFileFieldLoc *New(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& w); int getNbOfGaussPtPerCell() const { return _nb_gauss_pt; } void writeLL(med_idt fid) const; + std::string repr() const; bool isName(const char *name) const { return _name==name; } + int getDimension() const { return _dim; } + int getNumberOfGaussPoints() const { return _nb_gauss_pt; } + int getNumberOfPointsInCells() const { return _nb_node_per_cell; } const std::vector& getRefCoords() const { return _ref_coo; } const std::vector& getGaussCoords() const { return _gs_coo; } const std::vector& getGaussWeights() const { return _w; } @@ -237,6 +241,7 @@ namespace ParaMEDMEM const char *getFileName() const { return _file_name.c_str(); } std::string getFileName2() const { return _file_name; } const MEDFileFieldLoc& getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception); + const MEDFileFieldLoc& getLocalization(const char *pflName) const throw(INTERP_KERNEL::Exception); const DataArrayInt *getProfile(const std::string& pflName) const throw(INTERP_KERNEL::Exception); // void appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception); @@ -273,6 +278,7 @@ namespace ParaMEDMEM const char *getFileName() const; std::string getFileName2() const; const MEDFileFieldLoc& getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception); + const MEDFileFieldLoc& getLocalization(const char *pflName) const throw(INTERP_KERNEL::Exception); const DataArrayInt *getProfile(const std::string& pflName) const throw(INTERP_KERNEL::Exception); // void appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 98bfc961f..f70d6a5f6 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -102,6 +102,7 @@ using namespace ParaMEDMEM; %feature("unref") MEDFileCMesh "$this->decrRef();" %feature("unref") MEDFileMeshMultiTS "$this->decrRef();" %feature("unref") MEDFileMeshes "$this->decrRef();" +%feature("unref") MEDFileFieldLoc "$this->decrRef();" %feature("unref") MEDFileField1TS "$this->decrRef();" %feature("unref") MEDFileFieldMultiTS "$this->decrRef();" %feature("unref") MEDFileFields "$this->decrRef();" @@ -534,6 +535,26 @@ namespace ParaMEDMEM } }; + class MEDFileFieldLoc : public RefCountObject + { + public: + const std::string& getName() const; + int getDimension() const; + int getNumberOfGaussPoints() const; + int getNumberOfPointsInCells() const; + const std::vector& getRefCoords() const; + const std::vector& getGaussCoords() const; + const std::vector& getGaussWeights() const; + bool isEqual(const MEDFileFieldLoc& other, double eps) const; + %extend + { + std::string __str__() const + { + return self->repr(); + } + } + }; + class MEDFieldFieldGlobsReal { public: @@ -542,6 +563,30 @@ namespace ParaMEDMEM std::vector getLocs() const; virtual std::vector getPflsReallyUsed() const = 0; virtual std::vector getLocsReallyUsed() const = 0; + %extend + { + PyObject *getProfile(const std::string& pflName) const throw(INTERP_KERNEL::Exception) + { + const DataArrayInt *ret=self->getProfile(pflName); + if(ret) + ret->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + + PyObject *getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception) + { + const MEDFileFieldLoc *loc=&self->getLocalizationFromId(locId); + loc->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(loc),SWIGTYPE_p_ParaMEDMEM__MEDFileFieldLoc, SWIG_POINTER_OWN | 0 ); + } + + PyObject *getLocalization(const char *pflName) const throw(INTERP_KERNEL::Exception) + { + const MEDFileFieldLoc *loc=&self->getLocalization(pflName); + loc->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(loc),SWIGTYPE_p_ParaMEDMEM__MEDFileFieldLoc, SWIG_POINTER_OWN | 0 ); + } + } }; class MEDFileField1TSWithoutDAS : public RefCountObject diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index d0d1d8a58..9680b6338 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -493,6 +493,13 @@ 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() + 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()) + self.assertEqual(6,loc1.getNumberOfPointsInCells()) + self.assertEqual(3,loc1.getNumberOfGaussPoints()) + self.assertEqual(2,loc1.getDimension()) # pass @@ -561,6 +568,15 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(vals.isEqual(d,1e-14)) # ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1) + sbt=ff2.getFieldSplitedByType() + 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 + self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],sbt[0][1][0][1].getValues())# values for TRI3 + self.assertEqual(4,sbt[1][0])#QUAD4 + self.assertEqual(0,sbt[1][1][0][0])#CELL For QUAD4 + self.assertEqual("sup1_NORM_QUAD4",sbt[1][1][0][2])# profile For QUAD4 + self.assertEqual([19, 20, 21, 22, 23, 24],sbt[1][1][0][1].getValues())# values for QUAD4 self.assertEqual([0],ff2.getTypesOfFieldAvailable()) vals,pfl=ff2.getFieldWithProfile(ON_CELLS,0,mm1) self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) @@ -848,5 +864,5 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12)) pass pass - + unittest.main()