From: ageay Date: Mon, 11 Apr 2011 08:19:16 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~1028 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fc467f27e9ebb63b30d449bee2db23cef7f162ae;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index bfe6ea7a5..b751f687b 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -185,6 +185,20 @@ void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL: } } +void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception) +{ + if(getNumberOfTuples()!=other.getNumberOfTuples()) + { + std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " << other.getNumberOfTuples() << " having " << getNumberOfTuples() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(getNumberOfComponents()!=other.getNumberOfComponents()) + { + std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << other.getNumberOfComponents() << " having " << getNumberOfComponents() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception) { if(getNumberOfTuples()!=nbOfTuples) @@ -1755,12 +1769,9 @@ DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArray DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { - int nbOfComp=a1->getNumberOfComponents(); - if(nbOfComp!=a2->getNumberOfComponents()) - throw INTERP_KERNEL::Exception("Nb of components mismatch for array add !"); - int nbOfTuple=a1->getNumberOfTuples(); - if(nbOfTuple!=a2->getNumberOfTuples()) - throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array add !"); + int nbOfTuple=a2->getNumberOfTuples(); + int nbOfComp=a2->getNumberOfComponents(); + a1->checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array Add !"); DataArrayDouble *ret=DataArrayDouble::New(); ret->alloc(nbOfTuple,nbOfComp); std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::plus()); @@ -1770,24 +1781,18 @@ DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArray void DataArrayDouble::addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception) { - int nbOfComp=getNumberOfComponents(); - if(nbOfComp!=other->getNumberOfComponents()) - throw INTERP_KERNEL::Exception("Nb of components mismatch for array add !"); - int nbOfTuple=getNumberOfTuples(); - if(nbOfTuple!=other->getNumberOfTuples()) - throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array add !"); + int nbOfTuple=other->getNumberOfTuples(); + int nbOfComp=other->getNumberOfComponents(); + checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array add equal !"); std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::plus()); declareAsNew(); } DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { - int nbOfComp=a1->getNumberOfComponents(); - if(nbOfComp!=a2->getNumberOfComponents()) - throw INTERP_KERNEL::Exception("Nb of components mismatch for array Substract !"); - int nbOfTuple=a1->getNumberOfTuples(); - if(nbOfTuple!=a2->getNumberOfTuples()) - throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Substract !"); + int nbOfTuple=a2->getNumberOfTuples(); + int nbOfComp=a2->getNumberOfComponents(); + a1->checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array Substract !"); DataArrayDouble *ret=DataArrayDouble::New(); ret->alloc(nbOfTuple,nbOfComp); std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::minus()); @@ -1797,12 +1802,9 @@ DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const Dat void DataArrayDouble::substractEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception) { - int nbOfComp=getNumberOfComponents(); - if(nbOfComp!=other->getNumberOfComponents()) - throw INTERP_KERNEL::Exception("Nb of components mismatch for array substract !"); - int nbOfTuple=getNumberOfTuples(); - if(nbOfTuple!=other->getNumberOfTuples()) - throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array substract !"); + int nbOfTuple=other->getNumberOfTuples(); + int nbOfComp=other->getNumberOfComponents(); + checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array substract equal !"); std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::minus()); declareAsNew(); } @@ -1814,7 +1816,7 @@ DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const Data int nbOfComp=a1->getNumberOfComponents(); int nbOfComp2=a2->getNumberOfComponents(); if(nbOfTuple!=nbOfTuple2) - throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array multiply !"); + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !"); DataArrayDouble *ret=0; if(nbOfComp==nbOfComp2) { @@ -1849,7 +1851,7 @@ DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const Data ret->copyStringInfoFrom(*aMax); } else - throw INTERP_KERNEL::Exception("Nb of components mismatch for array multiply !"); + throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !"); } return ret; } @@ -1888,7 +1890,7 @@ DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataAr int nbOfComp=a1->getNumberOfComponents(); int nbOfComp2=a2->getNumberOfComponents(); if(nbOfTuple!=nbOfTuple2) - throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array divide !"); + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Divide !"); DataArrayDouble *ret=0; if(nbOfComp==nbOfComp2) { @@ -1911,7 +1913,7 @@ DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataAr ret->copyStringInfoFrom(*a1); } else - throw INTERP_KERNEL::Exception("Nb of components mismatch for array divide !"); + throw INTERP_KERNEL::Exception("Nb of components mismatch for array Divide !"); } return ret; } @@ -2501,6 +2503,58 @@ void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, Data arrI=retI; } +/*! + * This method expects that 'this' is allocated and with only one component. If not an exception will be thrown. + * This method returns a newly created array with 'this->getNumberOfTuples()' tuples and 1 component. + * This methods returns an 'old2New' corresponding array that allows to follow the following rules : + * - Lower a value in tuple in 'this' is, higher is its priority. + * - If two tuples i and j have same value if igetNumberOfTuples()-1' + * + * Example if 'this' contains the following array : [2,0,1,1,0,1,2,0,1,1,0,0] this method returns [10,0,5,6,1,7,11,2,8,9,3,4] + */ +DataArrayInt *DataArrayInt::buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildPermArrPerLevel : number of components must == 1 !"); + int nbOfTuples=getNumberOfTuples(); + const int *pt=getConstPointer(); + std::map m; + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + ret->alloc(nbOfTuples,1); + int *opt=ret->getPointer(); + for(int i=0;i::iterator it=m.find(val); + if(it!=m.end()) + { + *opt=(*it).second; + (*it).second++; + } + else + { + *opt=0; + m.insert(std::pair(val,1)); + } + } + int sum=0; + for(std::map::iterator it=m.begin();it!=m.end();it++) + { + int vt=(*it).second; + (*it).second=sum; + sum+=vt; + } + pt=getConstPointer(); + opt=ret->getPointer(); + for(int i=0;iincrRef(); + return ret; +} + /*! * This method checks that 'this' is with numberofcomponents == 1 and that it is equal to * stdext::iota() of size getNumberOfTuples. This method is particalary usefull for DataArrayInt instances @@ -2998,6 +3052,80 @@ void DataArrayInt::applyLin(int a, int b) throw(INTERP_KERNEL::Exception) declareAsNew(); } +/*! + * This method applies the operation 'numerator/x' for each element 'x' in 'this'. + * If there is a value in 'this' exactly equal to 0. an exception is thrown. + * Warning if presence of null this is modified for each values previous than place where exception was thrown ! + */ +void DataArrayInt::applyInv(int numerator) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int *ptr=getPointer(); + int nbOfElems=getNbOfElems(); + for(int i=0;i(),val)); + declareAsNew(); +} + +void DataArrayInt::applyModulus(int val) throw(INTERP_KERNEL::Exception) +{ + if(val<=0) + throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to operate modulus on value <= 0 !"); + checkAllocated(); + int *ptr=getPointer(); + int nbOfElems=getNbOfElems(); + std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::modulus(),val)); + declareAsNew(); +} + +/*! + * This method applies the operation 'numerator%x' for each element 'x' in 'this'. + * If there is a value in 'this' exactly equals or lower than 0. an exception is thrown. + * Warning if presence of null this is modified for each values previous than place where exception was thrown ! + */ +void DataArrayInt::applyRModulus(int val) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int *ptr=getPointer(); + int nbOfElems=getNbOfElems(); + for(int i=0;i0) + { + *ptr=val%(*ptr); + } + else + { + std::ostringstream oss; oss << "DataArrayInt::applyRModulus : presence of value <=0 in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents(); + oss << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + declareAsNew(); +} + DataArrayInt *DataArrayInt::Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception) { std::vector arr(2); @@ -3276,6 +3404,205 @@ std::set DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exce return ret; } +DataArrayInt *DataArrayInt::Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=a2->getNumberOfTuples(); + int nbOfComp=a2->getNumberOfComponents(); + a1->checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array Add !"); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::plus()); + ret->copyStringInfoFrom(*a1); + return ret; +} + +void DataArrayInt::addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=other->getNumberOfTuples(); + int nbOfComp=other->getNumberOfComponents(); + checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array add equal !"); + std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::plus()); + declareAsNew(); +} + +DataArrayInt *DataArrayInt::Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=a2->getNumberOfTuples(); + int nbOfComp=a2->getNumberOfComponents(); + a1->checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array Substract !"); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::minus()); + ret->copyStringInfoFrom(*a1); + return ret; +} + +void DataArrayInt::substractEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=other->getNumberOfTuples(); + int nbOfComp=other->getNumberOfComponents(); + checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array substract equal !"); + std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::minus()); + declareAsNew(); +} + +DataArrayInt *DataArrayInt::Multiply(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=a1->getNumberOfTuples(); + int nbOfTuple2=a2->getNumberOfTuples(); + int nbOfComp=a1->getNumberOfComponents(); + int nbOfComp2=a2->getNumberOfComponents(); + if(nbOfTuple!=nbOfTuple2) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !"); + DataArrayInt *ret=0; + if(nbOfComp==nbOfComp2) + { + ret=DataArrayInt::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::multiplies()); + ret->copyStringInfoFrom(*a1); + } + else + { + int nbOfCompMin,nbOfCompMax; + const DataArrayInt *aMin, *aMax; + if(nbOfComp>nbOfComp2) + { + nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp; + aMin=a2; aMax=a1; + } + else + { + nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2; + aMin=a1; aMax=a2; + } + if(nbOfCompMin==1) + { + ret=DataArrayInt::New(); + ret->alloc(nbOfTuple,nbOfCompMax); + const int *aMinPtr=aMin->getConstPointer(); + const int *aMaxPtr=aMax->getConstPointer(); + int *res=ret->getPointer(); + for(int i=0;i(),aMinPtr[i])); + ret->copyStringInfoFrom(*aMax); + } + else + throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !"); + } + return ret; +} + +void DataArrayInt::multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=getNumberOfTuples(); + int nbOfTuple2=other->getNumberOfTuples(); + int nbOfComp=getNumberOfComponents(); + int nbOfComp2=other->getNumberOfComponents(); + if(nbOfTuple!=nbOfTuple2) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array multiplyEqual !"); + if(nbOfComp==nbOfComp2) + { + std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::multiplies()); + } + else + { + if(nbOfComp2==1) + { + const int *ptr=other->getConstPointer(); + int *myPtr=getPointer(); + for(int i=0;i(),ptr[i])); + } + else + throw INTERP_KERNEL::Exception("Nb of components mismatch for array multiplyEqual !"); + } + declareAsNew(); +} + +DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=a1->getNumberOfTuples(); + int nbOfTuple2=a2->getNumberOfTuples(); + int nbOfComp=a1->getNumberOfComponents(); + int nbOfComp2=a2->getNumberOfComponents(); + if(nbOfTuple!=nbOfTuple2) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Divide !"); + DataArrayInt *ret=0; + if(nbOfComp==nbOfComp2) + { + ret=DataArrayInt::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::divides()); + ret->copyStringInfoFrom(*a1); + } + else + { + if(nbOfComp2==1) + { + ret=DataArrayInt::New(); + ret->alloc(nbOfTuple,nbOfComp); + const int *a2Ptr=a2->getConstPointer(); + const int *a1Ptr=a1->getConstPointer(); + int *res=ret->getPointer(); + for(int i=0;i(),a2Ptr[i])); + ret->copyStringInfoFrom(*a1); + } + else + throw INTERP_KERNEL::Exception("Nb of components mismatch for array Divide !"); + } + return ret; +} + +void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=getNumberOfTuples(); + int nbOfTuple2=other->getNumberOfTuples(); + int nbOfComp=getNumberOfComponents(); + int nbOfComp2=other->getNumberOfComponents(); + if(nbOfTuple!=nbOfTuple2) + throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array divideEqual !"); + if(nbOfComp==nbOfComp2) + { + std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::divides()); + } + else + { + if(nbOfComp2==1) + { + const int *ptr=other->getConstPointer(); + int *myPtr=getPointer(); + for(int i=0;i(),ptr[i])); + } + else + throw INTERP_KERNEL::Exception("Nb of components mismatch for array divideEqual !"); + } + declareAsNew(); +} + +DataArrayInt *DataArrayInt::Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=a2->getNumberOfTuples(); + int nbOfComp=a2->getNumberOfComponents(); + a1->checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array Modulus"); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(nbOfTuple,nbOfComp); + std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::modulus()); + ret->copyStringInfoFrom(*a1); + return ret; +} + +void DataArrayInt::modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception) +{ + int nbOfTuple=other->getNumberOfTuples(); + int nbOfComp=other->getNumberOfComponents(); + checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array modulus equal"); + std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::modulus()); + declareAsNew(); +} + int *DataArrayInt::CheckAndPreparePermutation(const int *start, const int *end) { int sz=std::distance(start,end); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 00f29a4b7..8d07d85c5 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -104,6 +104,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT int getNumberOfComponents() const { return _info_on_compo.size(); } MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _nb_of_tuples; } MEDCOUPLING_EXPORT int getNbOfElems() const { return _info_on_compo.size()*_nb_of_tuples; } + MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfElems(int nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception); protected: @@ -288,6 +289,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isIdentity() const; MEDCOUPLING_EXPORT bool isUniform(int val) const; MEDCOUPLING_EXPORT DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); @@ -317,6 +319,10 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT int getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void applyLin(int a, int b) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void applyInv(int numerator) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void applyDivideBy(int val) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void applyModulus(int val) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void applyRModulus(int val) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayInt *Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2); MEDCOUPLING_EXPORT static DataArrayInt *Aggregate(const std::vector& a) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayInt *Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); @@ -333,6 +339,16 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT std::set getDifferentValues() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } + MEDCOUPLING_EXPORT static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayInt *Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void substractEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayInt *Multiply(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayInt *Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayInt *Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); //! nothing to do here because this class does not aggregate any TimeLabel instance. MEDCOUPLING_EXPORT void updateTime() const { } public: diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 9e4cc9127..e32f8dbe3 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -3403,9 +3403,9 @@ DataArrayInt *MEDCouplingUMesh::checkTypeConsistencyAndContig(const std::vector< * This method is here too emulate the MEDMEM behaviour on BDC (buildDescendingConnectivity). Hoping this method becomes deprecated very soon. * This method make the assumption that 'this' and 'nM1LevMesh' mesh lyies on same coords (same pointer) as MED and MEDMEM does. * The following equality should be verified 'nM1LevMesh->getMeshDimension()==this->getMeshDimension()-1' - * This method returns 5+1 elements. 'desc', 'descIndx', 'revDesc', 'revDescIndx' and 'meshnM1' behaves exactly as ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity except the content as described after. The returned array specifies the numbering old2new that is to say the cell #k in 'nM1LevMesh' will have the number ret[k] in returned mesh 'nM1LevMesh'. + * This method returns 5+2 elements. 'desc', 'descIndx', 'revDesc', 'revDescIndx' and 'meshnM1' behaves exactly as ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity except the content as described after. The returned array specifies the n-1 mesh reordered by type as MEDMEM does. 'nM1LevMeshIds' contains the ids in returned 'meshnM1'. Finally 'meshnM1Old2New' contains numbering old2new that is to say the cell #k in coarse 'nM1LevMesh' will have the number ret[k] in returned mesh 'nM1LevMesh' MEDMEM reordered. */ -DataArrayInt *MEDCouplingUMesh::emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh, DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *&revDesc, DataArrayInt *&revDescIndx, MEDCouplingUMesh *& meshnM1) const throw(INTERP_KERNEL::Exception) +MEDCouplingUMesh *MEDCouplingUMesh::emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh, DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *&revDesc, DataArrayInt *&revDescIndx, DataArrayInt *& nM1LevMeshIds, DataArrayInt *&meshnM1Old2New) const throw(INTERP_KERNEL::Exception) { static const int N=18; static const INTERP_KERNEL::NormalizedCellType MEDMEM_ORDER[N] = { INTERP_KERNEL::NORM_POINT1, INTERP_KERNEL::NORM_SEG2, INTERP_KERNEL::NORM_SEG3, INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_QUAD8, INTERP_KERNEL::NORM_TETRA4, INTERP_KERNEL::NORM_PYRA5, INTERP_KERNEL::NORM_PENTA6, INTERP_KERNEL::NORM_HEXA8, INTERP_KERNEL::NORM_HEXGP12, INTERP_KERNEL::NORM_TETRA10, INTERP_KERNEL::NORM_PYRA13, INTERP_KERNEL::NORM_PENTA15, INTERP_KERNEL::NORM_HEXA20, INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_POLYHED }; @@ -3419,6 +3419,7 @@ DataArrayInt *MEDCouplingUMesh::emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevM MEDCouplingAutoRefCountObjectPtr tmp1=DataArrayInt::New(); MEDCouplingAutoRefCountObjectPtr ret1=buildDescendingConnectivity(desc,descIndx,tmp0,tmp1); MEDCouplingAutoRefCountObjectPtr ret0=ret1->getRenumArrForConsecutiveCellTypesSpec(MEDMEM_ORDER,MEDMEM_ORDER+N); + ret1->renumberCells(ret0->getConstPointer(),false); desc->transformWithIndArr(ret0->getConstPointer(),ret0->getConstPointer()+ret0->getNbOfElems()); MEDCouplingAutoRefCountObjectPtr tmp=MEDCouplingUMesh::New(); tmp->setConnectivity(tmp0,tmp1); @@ -3434,13 +3435,14 @@ DataArrayInt *MEDCouplingUMesh::emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevM std::ostringstream oss; oss << "MEDCouplingUMesh::emulateMEDMEMBDC : input N-1 mesh present a cell not in descending mesh ... Id of cell is " << tmp << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + nM1LevMeshIds=ret; // revDesc->incrRef(); revDescIndx->incrRef(); - meshnM1=ret1; ret1->incrRef(); ret0->incrRef(); - return ret0; + meshnM1Old2New=ret0; + return ret1; } /*! @@ -3489,46 +3491,58 @@ bool MEDCouplingUMesh::checkConsecutiveCellTypesAndOrder(const INTERP_KERNEL::No } /*! - * This method is similar to method MEDCouplingUMesh::rearrange2ConsecutiveCellTypes except that the type order is specfied by [orderBg,orderEnd) (as MEDCouplingUMesh::checkConsecutiveCellTypesAndOrder method) and that this method is \b const and performs \b NO permutation is 'this'. - * This method returns an array of size getNumberOfCells() that gives a renumber array old2New that can be used as input of MEDCouplingMesh::renumberCells. - * The mesh after this call will pass the test of MEDCouplingUMesh::checkConsecutiveCellTypesAndOrder with the same inputs. - * The returned array minimizes the permutations that is to say the order of cells inside same geometric type remains the same. + * This method returns 2 newly allocated DataArrayInt instances. The first is an array of size 'this->getNumberOfCells()' with one component, + * that tells for each cell the pos of its type in the array on type given in input parameter. The 2nd output parameter is an array with the same + * number of tuples than input type array and with one component. This 2nd output array gives type by type the number of occurence of type in 'this'. */ -DataArrayInt *MEDCouplingUMesh::getRenumArrForConsecutiveCellTypesSpec(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd) const +DataArrayInt *MEDCouplingUMesh::getLevArrPerCellTypes(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd, DataArrayInt *&nbPerType) const throw(INTERP_KERNEL::Exception) { checkFullyDefined(); int nbOfCells=getNumberOfCells(); const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); - int *tmp=new int[nbOfCells]; - int minPos=std::numeric_limits::max(); + MEDCouplingAutoRefCountObjectPtr tmpa=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr tmpb=DataArrayInt::New(); + tmpa->alloc(nbOfCells,1); + tmpb->alloc(std::distance(orderBg,orderEnd),1); + tmpb->fillWithZero(); + int *tmp=tmpa->getPointer(); + int *tmp2=tmpb->getPointer(); for(const int *i=connI;i!=connI+nbOfCells;i++) { - int pos=std::distance(orderBg,std::find(orderBg,orderEnd,(INTERP_KERNEL::NormalizedCellType)conn[*i])); - tmp[std::distance(connI,i)]=pos; - minPos=std::min(minPos,pos); - } - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc(nbOfCells,1); - int *optr=ret->getPointer(); - int k=0; - while(minPos!=std::numeric_limits::max()) - { - int nextMinPos=std::numeric_limits::max(); - for(int j=0;j::max(); - } - else - nextMinPos=std::min(nextMinPos,tmp[j]); + int pos=std::distance(orderBg,where); + tmp2[pos]++; + tmp[std::distance(connI,i)]=pos; + } + else + { + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel((INTERP_KERNEL::NormalizedCellType)conn[*i]); + std::ostringstream oss; oss << "MEDCouplingUMesh::getLevArrPerCellTypes : Cell #" << std::distance(connI,i); + oss << " has a type " << cm.getRepr() << " not in input array of type !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } - minPos=nextMinPos; } - delete [] tmp; - return ret; + nbPerType=tmpb; + tmpa->incrRef(); + tmpb->incrRef(); + return tmpa; +} + +/*! + * This method is similar to method MEDCouplingUMesh::rearrange2ConsecutiveCellTypes except that the type order is specfied by [orderBg,orderEnd) (as MEDCouplingUMesh::checkConsecutiveCellTypesAndOrder method) and that this method is \b const and performs \b NO permutation in 'this'. + * This method returns an array of size getNumberOfCells() that gives a renumber array old2New that can be used as input of MEDCouplingMesh::renumberCells. + * The mesh after this call to MEDCouplingMesh::renumberCells will pass the test of MEDCouplingUMesh::checkConsecutiveCellTypesAndOrder with the same inputs. + * The returned array minimizes the permutations that is to say the order of cells inside same geometric type remains the same. + */ +DataArrayInt *MEDCouplingUMesh::getRenumArrForConsecutiveCellTypesSpec(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd) const throw(INTERP_KERNEL::Exception) +{ + DataArrayInt *nbPerType=0; + MEDCouplingAutoRefCountObjectPtr tmpa=getLevArrPerCellTypes(orderBg,orderEnd,nbPerType); + nbPerType->decrRef(); + return tmpa->buildPermArrPerLevel(); } /*! diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 7a159d4fc..d9b4a2131 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -139,10 +139,11 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getSkewField() const throw(INTERP_KERNEL::Exception); //utilities for MED File RW MEDCOUPLING_EXPORT DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT DataArrayInt *emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh, DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *&revDesc, DataArrayInt *&revDescIndx, MEDCouplingUMesh *& meshnM1) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT MEDCouplingUMesh *emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh, DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *&revDesc, DataArrayInt *&revDescIndx, DataArrayInt *& nM1LevMeshIds, DataArrayInt *&meshnM1Old2New) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool checkConsecutiveCellTypes() const; MEDCOUPLING_EXPORT bool checkConsecutiveCellTypesAndOrder(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd) const; - MEDCOUPLING_EXPORT DataArrayInt *getRenumArrForConsecutiveCellTypesSpec(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd) const; + MEDCOUPLING_EXPORT DataArrayInt *getLevArrPerCellTypes(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd, DataArrayInt *&nbPerType) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *getRenumArrForConsecutiveCellTypesSpec(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *rearrange2ConsecutiveCellTypes(); MEDCOUPLING_EXPORT std::vector splitByType() const; MEDCOUPLING_EXPORT DataArrayInt *keepCellIdsByType(INTERP_KERNEL::NormalizedCellType type, const int *begin, const int *end) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 044e93984..edfbe7095 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -216,6 +216,9 @@ namespace ParaMEDMEM CPPUNIT_TEST( testUnPolyze2 ); CPPUNIT_TEST( testDACpyFrom1 ); CPPUNIT_TEST( testDAITransformWithIndArr1 ); + CPPUNIT_TEST( testDAIBuildPermArrPerLevel1 ); + CPPUNIT_TEST( testDAIOperations1 ); + CPPUNIT_TEST( testEmulateMEDMEMBDC1 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -458,6 +461,9 @@ namespace ParaMEDMEM void testUnPolyze2(); void testDACpyFrom1(); void testDAITransformWithIndArr1(); + void testDAIBuildPermArrPerLevel1(); + void testDAIOperations1(); + void testEmulateMEDMEMBDC1(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 82f5389d3..06bef434f 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1018,3 +1018,153 @@ void MEDCouplingBasicsTest::testDAITransformWithIndArr1() d->decrRef(); d1->decrRef(); } + +void MEDCouplingBasicsTest::testDAIBuildPermArrPerLevel1() +{ + const int arr[12]={2,0,1,1,0,1,2,0,1,1,0,0}; + const int expected1[12]={10,0,5,6,1,7,11,2,8,9,3,4}; + DataArrayInt *da=DataArrayInt::New(); + da->alloc(12,1); + std::copy(arr,arr+12,da->getPointer()); + DataArrayInt *da2=da->buildPermArrPerLevel(); + CPPUNIT_ASSERT_EQUAL(12,da2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0)); + da->decrRef(); + da2->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIOperations1() +{ + const int arr1[12]={-1,-2,4,7,3,2,6,6,4,3,0,1}; + DataArrayInt *da=DataArrayInt::New(); + da->alloc(4,3); + std::copy(arr1,arr1+12,da->getPointer()); + DataArrayInt *da1=DataArrayInt::New(); + da1->alloc(12,1); + da1->iota(2); + CPPUNIT_ASSERT_THROW(DataArrayInt::Add(da,da1),INTERP_KERNEL::Exception);//not same number of tuples/Components + da1->rearrange(3); + DataArrayInt *da2=DataArrayInt::Add(da,da1); + CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents()); + const int expected1[12]={1,1,8,12,9,9,14,15,14,14,12,14}; + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(0,i)); + da2->decrRef(); + da1->substractEqual(da); + const int expected2[12]={3,5,0,-2,3,5,2,3,6,8,12,12}; + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected2[i],da1->getIJ(0,i)); + da1->rearrange(1); da1->iota(2); da1->rearrange(3); + da1->addEqual(da); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],da1->getIJ(0,i)); + da1->rearrange(1); da1->iota(2); da1->rearrange(3); + da2=DataArrayInt::Multiply(da,da1); + CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents()); + const int expected3[12]={-2,-6,16,35,18,14,48,54,40,33,0,13}; + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected3[i],da2->getIJ(0,i)); + da2->decrRef(); + da->divideEqual(da1); + CPPUNIT_ASSERT_EQUAL(4,da->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,da->getNumberOfComponents()); + const int expected4[12]={0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}; + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected4[i],da->getIJ(0,i)); + std::copy(arr1,arr1+12,da->getPointer()); + da1->multiplyEqual(da); + CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected3[i],da1->getIJ(0,i)); + da1->rearrange(1); da1->iota(2); da1->rearrange(3); + da2=DataArrayInt::Divide(da,da1); + CPPUNIT_ASSERT_EQUAL(4,da2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,da2->getNumberOfComponents()); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected4[i],da2->getIJ(0,i)); + da2->decrRef(); + da1->applyInv(321); + CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents()); + const int expected5[12]={160,107,80,64,53,45,40,35,32,29,26,24}; + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected5[i],da1->getIJ(0,i)); + da1->applyDivideBy(2); + CPPUNIT_ASSERT_EQUAL(4,da1->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(3,da1->getNumberOfComponents()); + const int expected6[12]={80,53,40,32,26,22,20,17,16,14,13,12}; + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected6[i],da1->getIJ(0,i)); + const int expected7[12]={3,4,5,4,5,1,6,3,2,0,6,5}; + da1->applyModulus(7); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected7[i],da1->getIJ(0,i)); + da1->applyLin(1,1); + const int expected8[12]={3,3,3,3,3,1,3,3,0,0,3,3}; + da1->applyRModulus(3); + for(int i=0;i<12;i++) + CPPUNIT_ASSERT_EQUAL(expected8[i],da1->getIJ(0,i)); + // + da1->decrRef(); + da->decrRef(); +} + +void MEDCouplingBasicsTest::testEmulateMEDMEMBDC1() +{ + MEDCouplingUMesh *m1=0; + MEDCouplingUMesh *m=buildPointe_1(m1); + DataArrayInt *da1=DataArrayInt::New(); + DataArrayInt *da2=DataArrayInt::New(); + DataArrayInt *da3=0; + DataArrayInt *da4=0; + DataArrayInt *da5=0; + DataArrayInt *da0=0; + MEDCouplingUMesh *m2=m->emulateMEDMEMBDC(m1,da1,da2,da3,da4,da5,da0); + const int expected0[47]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,36,37,32,33,34,35,38,39,40,41,42,43,44,45,46}; + const int expected1[6]={1,32,29,23,41,36}; + CPPUNIT_ASSERT_EQUAL(47,da0->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,da0->getNumberOfComponents()); + for(int i=0;i<47;i++) + CPPUNIT_ASSERT_EQUAL(expected0[i],da0->getIJ(0,i)); + CPPUNIT_ASSERT_EQUAL(6,da5->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,da5->getNumberOfComponents()); + for(int i=0;i<6;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],da5->getIJ(0,i)); + const int expected2[70]={0,1,2,3,4,0,5,6,7,4,8,9,1,7,10,11,12,13,14,5,15,16,17,8,18,19,20,10,21,22,23,2,13,24,25,21,16,26,27,12,19,28,29,15,22,30,31,18,36,26,28,30,24,37,32,33,34,35,38,36,39,40,41,42,37,38,43,44,45,46}; + CPPUNIT_ASSERT_EQUAL(70,da1->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,da1->getNumberOfComponents()); + for(int i=0;i<70;i++) + CPPUNIT_ASSERT_EQUAL(expected2[i],da1->getIJ(0,i)); + const int expected3[17]={0,4,8,12,16,20,24,28,32,36,40,44,48,53,58,64,70}; + CPPUNIT_ASSERT_EQUAL(17,da2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents()); + for(int i=0;i<17;i++) + CPPUNIT_ASSERT_EQUAL(expected3[i],da2->getIJ(0,i)); + const int expected4[48]={0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,53,54,55,56,58,60,62,63,64,65,66,67,68,69,70}; + //const int expected4[48]={0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,54,56,57,58,59,60,62,63,64,65,66,67,68,69,70}; + CPPUNIT_ASSERT_EQUAL(48,da4->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,da4->getNumberOfComponents()); + for(int i=0;i<48;i++) + CPPUNIT_ASSERT_EQUAL(expected4[i],da4->getIJ(0,i)); + const int expected5[70]={0,1,0,3,0,7,0,1,2,1,4,1,2,3,2,5,2,3,6,3,4,9,4,8,4,5,10,5,9,5,6,11,6,10,6,7,8,7,11,7,8,12,8,9,12,9,10,12,10,11,12,11,13,13,13,13,12,14,13,15,14,15,14,14,14,14,15,15,15,15}; + CPPUNIT_ASSERT_EQUAL(70,da3->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,da3->getNumberOfComponents()); + for(int i=0;i<70;i++) + CPPUNIT_ASSERT_EQUAL(expected5[i],da3->getIJ(0,i)); + // + da0->decrRef(); + da1->decrRef(); + da2->decrRef(); + da3->decrRef(); + da4->decrRef(); + da5->decrRef(); + // + m2->decrRef(); + m1->decrRef(); + m->decrRef(); +} diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index bfdbadbd5..327afd51c 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -134,6 +134,10 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::getIdsNotEqualList; %newobject ParaMEDMEM::DataArrayInt::Aggregate; %newobject ParaMEDMEM::DataArrayInt::Meld; +%newobject ParaMEDMEM::DataArrayInt::Add; +%newobject ParaMEDMEM::DataArrayInt::Substract; +%newobject ParaMEDMEM::DataArrayInt::Multiply; +%newobject ParaMEDMEM::DataArrayInt::Divide; %newobject ParaMEDMEM::DataArrayInt::BuildUnion; %newobject ParaMEDMEM::DataArrayInt::BuildIntersection; %newobject ParaMEDMEM::DataArrayInt::fromNoInterlace; @@ -144,7 +148,18 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::buildIntersection; %newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex; %newobject ParaMEDMEM::DataArrayInt::buildPermutationArr; +%newobject ParaMEDMEM::DataArrayInt::buildPermArrPerLevel; %newobject ParaMEDMEM::DataArrayInt::__getitem__; +%newobject ParaMEDMEM::DataArrayInt::__add__; +%newobject ParaMEDMEM::DataArrayInt::__radd__; +%newobject ParaMEDMEM::DataArrayInt::__sub__; +%newobject ParaMEDMEM::DataArrayInt::__rsub__; +%newobject ParaMEDMEM::DataArrayInt::__mul__; +%newobject ParaMEDMEM::DataArrayInt::__rmul__; +%newobject ParaMEDMEM::DataArrayInt::__div__; +%newobject ParaMEDMEM::DataArrayInt::__rdiv__; +%newobject ParaMEDMEM::DataArrayInt::__mod__; +%newobject ParaMEDMEM::DataArrayInt::__rmod__; %newobject ParaMEDMEM::DataArrayDouble::New; %newobject ParaMEDMEM::DataArrayDouble::convertToIntArr; %newobject ParaMEDMEM::DataArrayDouble::deepCpy; @@ -940,6 +955,18 @@ namespace ParaMEDMEM return ret; } + PyObject *getLevArrPerCellTypes(PyObject *li, DataArrayInt *&nbPerType) const throw(INTERP_KERNEL::Exception) + { + int sz; + INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + DataArrayInt *tmp0,*tmp1=0; + tmp0=self->getLevArrPerCellTypes(order,(INTERP_KERNEL::NormalizedCellType *)order+sz,tmp1); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(tmp0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + static PyObject *MergeUMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) { std::vector meshes; @@ -1060,17 +1087,16 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - DataArrayInt *d2; - DataArrayInt *d3; - MEDCouplingUMesh *mOut; - DataArrayInt *d4=self->emulateMEDMEMBDC(nM1LevMesh,d0,d1,d2,d3,mOut); - PyObject *ret=PyTuple_New(6); + DataArrayInt *d2,*d3,*d4,*dd5; + MEDCouplingUMesh *mOut=self->emulateMEDMEMBDC(nM1LevMesh,d0,d1,d2,d3,d4,dd5); + PyObject *ret=PyTuple_New(7); PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(mOut),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d4),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,5,SWIG_NewPointerObj(SWIG_as_voidptr(d3),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr((DataArrayInt *)d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr((DataArrayInt *)d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,5,SWIG_NewPointerObj(SWIG_as_voidptr(d4),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,6,SWIG_NewPointerObj(SWIG_as_voidptr(dd5),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); d0->incrRef(); d1->incrRef(); return ret; @@ -3096,6 +3122,375 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception(msg); } } + + DataArrayInt *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __add__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1,val); + ret->incrRef(); + return ret; + } + case 3: + { + return DataArrayInt::Add(self,a); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__radd__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __radd__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1,val); + ret->incrRef(); + return ret; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *operator+=(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __iadd__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + self->applyLin(1,val); + return self; + } + case 3: + { + self->addEqual(a); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __sub__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1,-val); + ret->incrRef(); + return ret; + } + case 3: + { + return DataArrayInt::Substract(self,a); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rsub__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rsub__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(-1,val); + ret->incrRef(); + return ret; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *operator-=(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __isub__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + self->applyLin(1.,-val); + return self; + } + case 3: + { + self->substractEqual(a); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __mul__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(val,0); + ret->incrRef(); + return ret; + } + case 3: + { + return DataArrayInt::Multiply(self,a); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rmul__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(val,0); + ret->incrRef(); + return ret; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *operator*=(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __imul__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + self->applyLin(val,0); + return self; + } + case 3: + { + self->multiplyEqual(a); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __div__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyDivideBy(val); + ret->incrRef(); + return ret; + } + case 3: + { + return DataArrayInt::Divide(self,a); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rdiv__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyInv(val); + ret->incrRef(); + return ret; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *operator/=(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __imul__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + self->applyDivideBy(val); + return self; + } + case 3: + { + self->divideEqual(a); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__mod__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __mod__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyModulus(val); + ret->incrRef(); + return ret; + } + case 3: + { + return DataArrayInt::Modulus(self,a); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rmod__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rmod__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyRModulus(val); + ret->incrRef(); + return ret; + } + case 3: + { + return DataArrayInt::Modulus(self,a); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *operator%=(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __imod__ !"; + int val; + DataArrayInt *a; + std::vector aa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a); + switch(sw) + { + case 1: + { + self->applyModulus(val); + return self; + } + case 3: + { + self->modulusEqual(a); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } }; namespace ParaMEDMEM diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 1d49f3e5c..57affeb1c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -6182,6 +6182,70 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual([10.0, 12.5, 15.0, 14.0, 16.0, 18.0, 15.0, 16.5, 18.0, 13.0, 14.0, 15.0],da.getValues()) pass + def testSwigDAIOp(self): + da=DataArrayInt.New() + da.alloc(12,1) + da.iota(7) + da1=DataArrayInt.New() + da1.alloc(12,1) + da1.iota(8) + da2=da+da1 + self.assertEqual([15,17,19,21,23,25,27,29,31,33,35,37],da2.getValues()) + da2=da+3 + da3=3+da + self.assertTrue(da2.isEqual(da3)) + da2=da-1 + self.assertEqual([6,7,8,9,10,11,12,13,14,15,16,17],da2.getValues()) + da2=1-da + self.assertEqual([-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17],da2.getValues()) + da2=da*3 + self.assertEqual([21,24,27,30,33,36,39,42,45,48,51,54.0],da2.getValues()) + da2=3*da + self.assertEqual([21,24,27,30,33,36,39,42,45,48,51,54.0],da2.getValues()) + da2=da*da1 + self.assertEqual([56,72,90,110,132,156,182,210,240,272,306,342.0],da2.getValues()) + da2=da/4 + self.assertEqual([1,2,2,2,2,3,3,3,3,4,4,4],da2.getValues()) + da3=4/da + da4=da3*da2 + self.assertTrue(da4.isUniform(0)) + st1=da.getHiddenCppPointer() + da+=1 + st2=da.getHiddenCppPointer() + self.assertEqual(st1,st2) + self.assertTrue(da.isEqual(da1)) + da-=8 + st2=da.getHiddenCppPointer() + self.assertEqual(st1,st2) + self.assertEqual(range(12),da.getValues()) + da+=da1 + st2=da.getHiddenCppPointer() + self.assertEqual(st1,st2) + self.assertEqual([8,10,12,14,16,18,20,22,24,26,28,30],da.getValues()) + da/=2 + st2=da.getHiddenCppPointer() + self.assertEqual(st1,st2) + self.assertEqual([4,5,6,7,8,9,10,11,12,13,14,15],da.getValues()) + da*=da1 + st2=da.getHiddenCppPointer() + self.assertEqual(st1,st2) + self.assertEqual([32,45,60,77,96,117,140,165,192,221,252,285],da.getValues()) + da/=da1 + self.assertEqual(st1,st2) + self.assertEqual([4,5,6,7,8,9,10,11,12,13,14,15],da.getValues()) + da/=2 + st2=da.getHiddenCppPointer() + self.assertEqual(st1,st2) + self.assertEqual([2,2, 3,3, 4,4, 5,5, 6,6, 7,7],da.getValues()) + da.rearrange(3) + da5=DataArrayInt.New() + da5.setValues([5,4,3,2],4,1) + da*=da5 # it works with unmathing number of compo + st2=da.getHiddenCppPointer() + self.assertEqual(st1,st2) + self.assertEqual([10,10, 15,12,16,16,15,15, 18,12,14,14],da.getValues()) + pass + def testDAIAggregateMulti1(self): a=DataArrayInt.New() a.setValues(range(4),2,2) @@ -7082,6 +7146,143 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected[i],d1.getIJ(i,0)); pass pass + + def testDAIBuildPermArrPerLevel1(self): + arr=[2,0,1,1,0,1,2,0,1,1,0,0] + expected1=[10,0,5,6,1,7,11,2,8,9,3,4] + da=DataArrayInt.New(); + da.setValues(arr,12,1); + da2=da.buildPermArrPerLevel(); + self.assertEqual(12,da2.getNumberOfTuples()); + self.assertEqual(1,da2.getNumberOfComponents()); + for i in xrange(12): + self.assertEqual(expected1[i],da2.getIJ(i,0)); + pass + pass + + def testDAIOperations1(self): + arr1=[-1,-2,4,7,3,2,6,6,4,3,0,1] + da=DataArrayInt.New(); + da.setValues(arr1,4,3); + da1=DataArrayInt.New(); + da1.alloc(12,1); + da1.iota(2); + self.assertRaises(InterpKernelException,DataArrayInt.Add,da,da1);#not same number of tuples/Components + da1.rearrange(3); + da2=DataArrayInt.Add(da,da1); + self.assertEqual(4,da2.getNumberOfTuples()); + self.assertEqual(3,da2.getNumberOfComponents()); + expected1=[1,1,8,12,9,9,14,15,14,14,12,14] + for i in xrange(12): + self.assertEqual(expected1[i],da2.getIJ(0,i)); + pass + da1.substractEqual(da); + expected2=[3,5,0,-2,3,5,2,3,6,8,12,12] + for i in xrange(12): + self.assertEqual(expected2[i],da1.getIJ(0,i)); + pass + da1.rearrange(1); da1.iota(2); da1.rearrange(3); + da1.addEqual(da); + for i in xrange(12): + self.assertEqual(expected1[i],da1.getIJ(0,i)); + pass + da1.rearrange(1); da1.iota(2); da1.rearrange(3); + da2=DataArrayInt.Multiply(da,da1); + self.assertEqual(4,da2.getNumberOfTuples()); + self.assertEqual(3,da2.getNumberOfComponents()); + expected3=[-2,-6,16,35,18,14,48,54,40,33,0,13] + for i in xrange(12): + self.assertEqual(expected3[i],da2.getIJ(0,i)); + pass + da.divideEqual(da1); + self.assertEqual(4,da.getNumberOfTuples()); + self.assertEqual(3,da.getNumberOfComponents()); + expected4=[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0] + for i in xrange(12): + self.assertEqual(expected4[i],da.getIJ(0,i)); + pass + da.setValues(arr1,4,3); + da1.multiplyEqual(da); + self.assertEqual(4,da1.getNumberOfTuples()); + self.assertEqual(3,da1.getNumberOfComponents()); + for i in xrange(12): + self.assertEqual(expected3[i],da1.getIJ(0,i)); + pass + da1.rearrange(1); da1.iota(2); da1.rearrange(3); + da2=DataArrayInt.Divide(da,da1); + self.assertEqual(4,da2.getNumberOfTuples()); + self.assertEqual(3,da2.getNumberOfComponents()); + for i in xrange(12): + self.assertEqual(expected4[i],da2.getIJ(0,i)); + pass + da1.applyInv(321); + self.assertEqual(4,da1.getNumberOfTuples()); + self.assertEqual(3,da1.getNumberOfComponents()); + expected5=[160,107,80,64,53,45,40,35,32,29,26,24] + for i in xrange(12): + self.assertEqual(expected5[i],da1.getIJ(0,i)); + pass + da1.applyDivideBy(2); + self.assertEqual(4,da1.getNumberOfTuples()); + self.assertEqual(3,da1.getNumberOfComponents()); + expected6=[80,53,40,32,26,22,20,17,16,14,13,12] + for i in xrange(12): + self.assertEqual(expected6[i],da1.getIJ(0,i)); + pass + expected7=[3,4,5,4,5,1,6,3,2,0,6,5] + da1.applyModulus(7); + for i in xrange(12): + self.assertEqual(expected7[i],da1.getIJ(0,i)); + pass + da1.applyLin(1,1); + expected8=[3,3,3,3,3,1,3,3,0,0,3,3] + da1.applyRModulus(3); + for i in xrange(12): + self.assertEqual(expected8[i],da1.getIJ(0,i)); + pass + pass + + def testEmulateMEDMEMBDC1(self): + m,m1=MEDCouplingDataForTest.buildPointe_1(); + m2,da1,da2,da3,da4,da5,da0=m.emulateMEDMEMBDC(m1) + expected0=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,36,37,32,33,34,35,38,39,40,41,42,43,44,45,46] + expected1=[1,32,29,23,41,36] + self.assertEqual(47,da0.getNumberOfTuples()); + self.assertEqual(1,da0.getNumberOfComponents()); + for i in xrange(47): + self.assertEqual(expected0[i],da0.getIJ(0,i)); + pass + self.assertEqual(6,da5.getNumberOfTuples()); + self.assertEqual(1,da5.getNumberOfComponents()); + for i in xrange(6): + self.assertEqual(expected1[i],da5.getIJ(0,i)); + pass + expected2=[0,1,2,3,4,0,5,6,7,4,8,9,1,7,10,11,12,13,14,5,15,16,17,8,18,19,20,10,21,22,23,2,13,24,25,21,16,26,27,12,19,28,29,15,22,30,31,18,36,26,28,30,24,37,32,33,34,35,38,36,39,40,41,42,37,38,43,44,45,46] + self.assertEqual(70,da1.getNumberOfTuples()); + self.assertEqual(1,da1.getNumberOfComponents()); + for i in xrange(70): + self.assertEqual(expected2[i],da1.getIJ(0,i)); + pass + expected3=[0,4,8,12,16,20,24,28,32,36,40,44,48,53,58,64,70] + self.assertEqual(17,da2.getNumberOfTuples()); + self.assertEqual(1,da2.getNumberOfComponents()); + for i in xrange(17): + self.assertEqual(expected3[i],da2.getIJ(0,i)); + pass + expected4=[0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,53,54,55,56,58,60,62,63,64,65,66,67,68,69,70] + #expected4=[0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,54,56,57,58,59,60,62,63,64,65,66,67,68,69,70]; + self.assertEqual(48,da4.getNumberOfTuples()); + self.assertEqual(1,da4.getNumberOfComponents()); + for i in xrange(48): + self.assertEqual(expected4[i],da4.getIJ(0,i)); + pass + expected5=[0,1,0,3,0,7,0,1,2,1,4,1,2,3,2,5,2,3,6,3,4,9,4,8,4,5,10,5,9,5,6,11,6,10,6,7,8,7,11,7,8,12,8,9,12,9,10,12,10,11,12,11,13,13,13,13,12,14,13,15,14,15,14,14,14,14,15,15,15,15] + self.assertEqual(70,da3.getNumberOfTuples()); + self.assertEqual(1,da3.getNumberOfComponents()); + for i in xrange(70): + self.assertEqual(expected5[i],da3.getIJ(0,i)); + pass + pass def setUp(self): pass