From 1241316d649db061d088f9b80a5964492006d91e Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 27 Apr 2011 09:26:20 +0000 Subject: [PATCH] *** empty log message *** --- .../MEDCouplingFieldDiscretization.cxx | 56 ++++++++++++++++++- .../MEDCouplingFieldDiscretization.hxx | 7 +++ .../MEDCouplingGaussLocalization.cxx | 10 ++-- .../MEDCouplingGaussLocalization.hxx | 4 +- src/MEDCoupling_Swig/MEDCoupling.i | 1 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 16 ++++++ 6 files changed, 86 insertions(+), 8 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 73acfe1c2..ff914ddd5 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -349,6 +349,15 @@ int MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces(const MEDCouplingMes return mesh->getNumberOfCells(); } +DataArrayInt *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMesh *mesh) const +{ + int nbOfTuples=mesh->getNumberOfCells(); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(nbOfTuples+1,1); + ret->iota(0); + return ret; +} + void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { @@ -508,6 +517,15 @@ int MEDCouplingFieldDiscretizationP1::getNumberOfMeshPlaces(const MEDCouplingMes return mesh->getNumberOfNodes(); } +DataArrayInt *MEDCouplingFieldDiscretizationP1::getOffsetArr(const MEDCouplingMesh *mesh) const +{ + int nbOfTuples=mesh->getNumberOfNodes(); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(nbOfTuples+1,1); + ret->iota(0); + return ret; +} + DataArrayDouble *MEDCouplingFieldDiscretizationP1::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { return mesh->getCoordinatesAndOwner(); @@ -742,6 +760,11 @@ void MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells() const throw(INT throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkNoOrphanCells : presence of orphan cells !"); } +const DataArrayInt *MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds() const +{ + return _discr_per_cell; +} + MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss() { } @@ -812,6 +835,19 @@ int MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces(const MEDCoupling return mesh->getNumberOfCells(); } +DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const +{ + int nbOfTuples=mesh->getNumberOfCells(); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(nbOfTuples+1,1); + int *retPtr=ret->getPointer(); + const int *start=_discr_per_cell->getConstPointer(); + retPtr[0]=0; + for(int i=0;i& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { @@ -945,7 +981,7 @@ void MEDCouplingFieldDiscretizationGauss::resizeForUnserialization(const std::ve for(int i=0;i tmp(tinyInfo.begin()+3+i*delta,tinyInfo.begin()+3+(i+1)*delta); - MEDCouplingGaussLocalization elt=MEDCouplingGaussLocalization::buildNewInstanceFromTinyInfo(dim,tmp); + MEDCouplingGaussLocalization elt=MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(dim,tmp); _loc.push_back(elt); } } @@ -1336,6 +1372,24 @@ int MEDCouplingFieldDiscretizationGaussNE::getNumberOfMeshPlaces(const MEDCoupli return mesh->getNumberOfCells(); } +DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCouplingMesh *mesh) const +{ + int nbOfTuples=mesh->getNumberOfCells(); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(nbOfTuples+1,1); + int *retPtr=ret->getPointer(); + retPtr[0]=0; + for(int i=0;igetTypeOfCell(i); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); + if(cm.isDynamic()) + throw INTERP_KERNEL::Exception("Not implemented yet Gauss node on elements for polygons and polyedrons !"); + retPtr[i+1]=retPtr[i]+cm.getNumberOfNodes(); + } + return ret; +} + void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 0b74d713e..31997f276 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -51,6 +51,7 @@ namespace ParaMEDMEM virtual const char *getStringRepr() const = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const = 0; virtual int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const = 0; + virtual DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const = 0; virtual void normL1(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const throw(INTERP_KERNEL::Exception); virtual void normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, double *res) const throw(INTERP_KERNEL::Exception); virtual void integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs, double *res) const throw(INTERP_KERNEL::Exception); @@ -106,6 +107,7 @@ namespace ParaMEDMEM bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; + DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const; void renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; @@ -135,6 +137,7 @@ namespace ParaMEDMEM bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; + DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const; void renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; @@ -163,6 +166,8 @@ namespace ParaMEDMEM */ class MEDCOUPLING_EXPORT MEDCouplingFieldDiscretizationPerCell : public MEDCouplingFieldDiscretization { + public: + const DataArrayInt *getArrayOfDiscIds() const; protected: MEDCouplingFieldDiscretizationPerCell(); MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other); @@ -191,6 +196,7 @@ namespace ParaMEDMEM const char *getStringRepr() const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; + DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const; void renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; @@ -250,6 +256,7 @@ namespace ParaMEDMEM bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; int getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const; + DataArrayInt *getOffsetArr(const MEDCouplingMesh *mesh) const; void renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); DataArrayDouble *getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const; diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx index 18eb833bd..6e6a40e06 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx @@ -79,11 +79,11 @@ bool ParaMEDMEM::MEDCouplingGaussLocalization::isEqual(const MEDCouplingGaussLoc { if(_type!=other._type) return false; - if(!areAlmostEqual(_ref_coord,other._ref_coord,eps)) + if(!AreAlmostEqual(_ref_coord,other._ref_coord,eps)) return false; - if(!areAlmostEqual(_gauss_coord,other._gauss_coord,eps)) + if(!AreAlmostEqual(_gauss_coord,other._gauss_coord,eps)) return false; - if(!areAlmostEqual(_weight,other._weight,eps)) + if(!AreAlmostEqual(_weight,other._weight,eps)) return false; return true; } @@ -185,7 +185,7 @@ void ParaMEDMEM::MEDCouplingGaussLocalization::setWeight(int gaussPtIdInCell, do /*! * The format of 'tinyData' parameter is the same than pushed in method ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo. */ -ParaMEDMEM::MEDCouplingGaussLocalization ParaMEDMEM::MEDCouplingGaussLocalization::buildNewInstanceFromTinyInfo(int dim, const std::vector& tinyData) +ParaMEDMEM::MEDCouplingGaussLocalization ParaMEDMEM::MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(int dim, const std::vector& tinyData) { std::vector v1(dim*tinyData[1]),v2(dim*tinyData[2]),v3(tinyData[2]); return ParaMEDMEM::MEDCouplingGaussLocalization((INTERP_KERNEL::NormalizedCellType)tinyData[0],v1,v2,v3); @@ -203,7 +203,7 @@ int ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherencyOfRequest(int gaussP return dim; } -bool ParaMEDMEM::MEDCouplingGaussLocalization::areAlmostEqual(const std::vector& v1, const std::vector& v2, double eps) +bool ParaMEDMEM::MEDCouplingGaussLocalization::AreAlmostEqual(const std::vector& v1, const std::vector& v2, double eps) { int sz=v1.size(); if(sz!=(int)v2.size()) diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.hxx b/src/MEDCoupling/MEDCouplingGaussLocalization.hxx index 791e24355..18ed60812 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.hxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.hxx @@ -55,10 +55,10 @@ namespace ParaMEDMEM void setGaussCoord(int gaussPtIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception); void setWeight(int gaussPtIdInCell, double newVal) throw(INTERP_KERNEL::Exception); // - static MEDCouplingGaussLocalization buildNewInstanceFromTinyInfo(int dim, const std::vector& tinyData); + static MEDCouplingGaussLocalization BuildNewInstanceFromTinyInfo(int dim, const std::vector& tinyData); + static bool AreAlmostEqual(const std::vector& v1, const std::vector& v2, double eps); private: int checkCoherencyOfRequest(int gaussPtIdInCell, int comp) const throw(INTERP_KERNEL::Exception); - static bool areAlmostEqual(const std::vector& v1, const std::vector& v2, double eps); private: INTERP_KERNEL::NormalizedCellType _type; std::vector _ref_coord; diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index ea3fbdd41..d80090da7 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -71,6 +71,7 @@ using namespace INTERP_KERNEL; %feature("autodoc", "1"); %feature("docstring"); +%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getOffsetArr; %newobject ParaMEDMEM::MEDCouplingField::buildMeasureField; %newobject ParaMEDMEM::MEDCouplingField::getLocalizationOfDiscr; %newobject ParaMEDMEM::MEDCouplingFieldDouble::New; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 646ffd783..820f17b5b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -6263,6 +6263,22 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual([4,4,3,0,4,4,3,3,0,0,2,2],da.getValues()) pass + def testSwigDAIOp2(self): + da=DataArrayInt.New() + st=da.getHiddenCppPointer() + da.alloc(10,3) + da.rearrange(1) + da.iota(0) + da.rearrange(3) + da[:,1]+=4 + da[-2:,2]+=10 + da[-2:,2]+=10 + da[:,2]+=da[:,0] + da[da[0],:]=7 + self.assertEqual(st,da.getHiddenCppPointer()) + self.assertEqual(da.getValues(),[7,7,7,3,8,8,7,7,7,9,14,20,12,17,26,7,7,7,18,23,38,21,26,44,24,29,70,27,32,76]) + pass + def testDAIAggregateMulti1(self): a=DataArrayInt.New() a.setValues(range(4),2,2) -- 2.39.2