From: vsr Date: Tue, 23 Nov 2010 16:48:36 +0000 (+0000) Subject: Merge from V5_1_5_BR 23/11/2010 X-Git-Tag: MED_OP_AG_0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=accbe3b9de21dc315f8aeeb7e3772746ac493543;p=tools%2Fmedcoupling.git Merge from V5_1_5_BR 23/11/2010 --- diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index eecbba978..2c62b3f44 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -715,7 +715,7 @@ MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) throw(IN if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !"); int nbOfTuple=_type->getNumberOfTuples(_mesh); - _time_discr->setUniformValue(nbOfTuple,value); + _time_discr->setUniformValue(nbOfTuple,1,value); return *this; } @@ -754,6 +754,18 @@ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) _time_discr->applyFunc(nbOfComp,func); } +/*! + * This method is a specialization of other overloaded methods. When 'nbOfComp' equals 1 this method is equivalent to + * ParaMEDMEM::MEDCouplingFieldDouble::operator=. + */ +void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val) +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::applyFunc : no mesh defined !"); + int nbOfTuple=_type->getNumberOfTuples(_mesh); + _time_discr->setUniformValue(nbOfTuple,nbOfComp,val); +} + /*! * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr. * If '*func' fails in evaluation during one evaluation an exception will be thrown. @@ -1157,6 +1169,21 @@ void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftVal _time_discr->changeNbOfComponents(newNbOfComp,dftValue); } +MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName(getName()); + ret->setMesh(getMesh()); + return ret; +} + +void MEDCouplingFieldDouble::setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector& compoIds) throw(INTERP_KERNEL::Exception) +{ + _time_discr->setSelectedComponents(f->_time_discr,compoIds); +} + void MEDCouplingFieldDouble::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception) { _time_discr->sortPerTuple(asc); diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index bcdb5861d..48c0bace0 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -89,6 +89,7 @@ namespace ParaMEDMEM void fillFromAnalytic(int nbOfComp, FunctionToEvaluate func) throw(INTERP_KERNEL::Exception); void fillFromAnalytic(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception); void applyFunc(int nbOfComp, FunctionToEvaluate func); + void applyFunc(int nbOfComp, double val); void applyFunc(int nbOfComp, const char *func); void applyFunc(const char *func); void applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception); @@ -120,6 +121,8 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *magnitude() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *maxPerTuple() const throw(INTERP_KERNEL::Exception); void changeNbOfComponents(int newNbOfComp, double dftValue=0.) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); + void setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); static MEDCouplingFieldDouble *dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index c40c4dd92..5365cb97c 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -18,6 +18,7 @@ // #include "MEDCouplingMemArray.txx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" #include "GenMathFormulae.hxx" #include "InterpKernelExprParser.hxx" @@ -44,6 +45,36 @@ void DataArray::copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL:: _info_on_compo=other._info_on_compo; } +void DataArray::copyPartOfStringInfoFrom(const DataArray& other, const std::vector& compoIds) throw(INTERP_KERNEL::Exception) +{ + int nbOfCompoOth=other.getNumberOfComponents(); + int newNbOfCompo=compoIds.size(); + for(int i=0;i=nbOfCompoOth) + { + std::ostringstream oss; oss << "Specified component ids is to high (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompoOth << ")"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + for(int i=0;i& compoIds, const DataArray& other) throw(INTERP_KERNEL::Exception) +{ + int nbOfCompo=getNumberOfComponents(); + int partOfCompoToSet=compoIds.size(); + if(partOfCompoToSet!=other.getNumberOfComponents()) + throw INTERP_KERNEL::Exception("Given compoIds has not the same size as number of components of given array !"); + for(int i=0;i=nbOfCompo) + { + std::ostringstream oss; oss << "Specified component ids is to high (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + for(int i=0;i& compoIds) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); + int newNbOfCompo=compoIds.size(); + int oldNbOfCompo=getNumberOfComponents(); + int nbOfTuples=getNumberOfTuples(); + ret->alloc(nbOfTuples,newNbOfCompo); + ret->copyPartOfStringInfoFrom(*this,compoIds); + const double *oldc=getConstPointer(); + double *nc=ret->getPointer(); + for(int i=0;iincrRef(); + return ret; +} + +void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std::vector& compoIds) throw(INTERP_KERNEL::Exception) +{ + copyPartOfStringInfoFrom2(compoIds,*a); + int partOfCompoSz=compoIds.size(); + int nbOfCompo=getNumberOfComponents(); + int nbOfTuples=getNumberOfTuples(); + const double *ac=a->getConstPointer(); + double *nc=getPointer(); + for(int i=0;i& compoIds) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); + int newNbOfCompo=compoIds.size(); + int oldNbOfCompo=getNumberOfComponents(); + int nbOfTuples=getNumberOfTuples(); + ret->alloc(nbOfTuples,newNbOfCompo); + ret->copyPartOfStringInfoFrom(*this,compoIds); + const int *oldc=getConstPointer(); + int *nc=ret->getPointer(); + for(int i=0;iincrRef(); + return ret; +} + +void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector& compoIds) throw(INTERP_KERNEL::Exception) +{ + copyPartOfStringInfoFrom2(compoIds,*a); + int partOfCompoSz=compoIds.size(); + int nbOfCompo=getNumberOfComponents(); + int nbOfTuples=getNumberOfTuples(); + const int *ac=a->getConstPointer(); + int *nc=getPointer(); + for(int i=0;i& compoIds) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void copyPartOfStringInfoFrom2(const std::vector& compoIds, const DataArray& other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool areInfoEquals(const DataArray& other) const; MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT std::string getName() const { return _name; } @@ -135,6 +137,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const; MEDCOUPLING_EXPORT DataArrayDouble *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayDouble *a, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } MEDCOUPLING_EXPORT double getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, double newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; declareAsNew(); } @@ -221,6 +225,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool isIdentity() const; MEDCOUPLING_EXPORT DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayInt *a, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); } MEDCOUPLING_EXPORT int getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; } MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, int newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index a98a75f58..a150a9cd4 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -306,7 +306,6 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedPr MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() const throw(INTERP_KERNEL::Exception) { - MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); @@ -320,13 +319,13 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() cons std::vector arrays3(arrays.size()); for(int j=0;j<(int)arrays.size();j++) arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); ret->setArrays(arrays3,0); return ret; } MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() const throw(INTERP_KERNEL::Exception) { - MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); @@ -340,13 +339,13 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() cons std::vector arrays3(arrays.size()); for(int j=0;j<(int)arrays.size();j++) arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); ret->setArrays(arrays3,0); return ret; } MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() const throw(INTERP_KERNEL::Exception) { - MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); @@ -360,13 +359,13 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() con std::vector arrays3(arrays.size()); for(int j=0;j<(int)arrays.size();j++) arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); ret->setArrays(arrays3,0); return ret; } MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const throw(INTERP_KERNEL::Exception) { - MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); @@ -380,13 +379,13 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const th std::vector arrays3(arrays.size()); for(int j=0;j<(int)arrays.size();j++) arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); ret->setArrays(arrays3,0); return ret; } MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const throw(INTERP_KERNEL::Exception) { - MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); @@ -400,13 +399,13 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const thro std::vector arrays3(arrays.size()); for(int j=0;j<(int)arrays.size();j++) arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); ret->setArrays(arrays3,0); return ret; } MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const throw(INTERP_KERNEL::Exception) { - MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); @@ -420,13 +419,13 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const t std::vector arrays3(arrays.size()); for(int j=0;j<(int)arrays.size();j++) arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); ret->setArrays(arrays3,0); return ret; } MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const throw(INTERP_KERNEL::Exception) { - MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); @@ -440,13 +439,13 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const std::vector arrays3(arrays.size()); for(int j=0;j<(int)arrays.size();j++) arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); ret->setArrays(arrays3,0); return ret; } MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() const throw(INTERP_KERNEL::Exception) { - MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); @@ -460,10 +459,47 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() cons std::vector arrays3(arrays.size()); for(int j=0;j<(int)arrays.size();j++) arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception) +{ + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->keepSelectedComponents(compoIds); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); ret->setArrays(arrays3,0); return ret; } +void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector& compoIds) throw(INTERP_KERNEL::Exception) +{ + std::vector arrays1,arrays2; + getArrays(arrays1); + other->getArrays(arrays2); + if(arrays1.size()!=arrays2.size()) + throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : number of arrays mismatch !"); + for(unsigned int i=0;isetSelectedComponents(arrays2[i],compoIds); + else if(arrays1[i]!=0 || arrays2[i]!=0) + throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : some time array in correspondance are not defined symetrically !"); + } +} + void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception) { std::vector arrays; @@ -493,7 +529,7 @@ void MEDCouplingTimeDiscretization::sortPerTuple(bool asc) throw(INTERP_KERNEL:: } } -void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, double value) +void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo, double value) { std::vector arrays; getArrays(arrays); @@ -509,7 +545,7 @@ void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, double value) else { DataArrayDouble *tmp=DataArrayDouble::New(); - tmp->alloc(nbOfTuple,1); + tmp->alloc(nbOfTuple,nbOfCompo); tmp->fillWithValue(value); arrays2[j]=tmp; } @@ -551,7 +587,7 @@ void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate f void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const char *func) { - std::vector arrays; + std::vector arrays; getArrays(arrays); std::vector arrays2(arrays.size()); for(int j=0;j<(int)arrays.size();j++) @@ -693,9 +729,9 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCoupli const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !"); + DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setTimeTolerance(getTimeTolerance()); - DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); ret->setArray(arr,0); arr->decrRef(); return ret; @@ -706,8 +742,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTime const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::dot on mismatched time discretization !"); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; DataArrayDouble *arr=DataArrayDouble::dot(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -718,8 +754,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::crossProduct(const MEDCou const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::crossProduct on mismatched time discretization !"); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; DataArrayDouble *arr=DataArrayDouble::crossProduct(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -730,8 +766,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::max(const MEDCouplingTime const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !"); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; DataArrayDouble *arr=DataArrayDouble::max(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -742,8 +778,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::min(const MEDCouplingTime const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !"); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; DataArrayDouble *arr=DataArrayDouble::min(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -754,8 +790,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTime const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::add on mismatched time discretization !"); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; DataArrayDouble *arr=DataArrayDouble::add(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -774,8 +810,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::substract(const MEDCoupli const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::substract on mismatched time discretization !"); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; DataArrayDouble *arr=DataArrayDouble::substract(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -794,8 +830,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::multiply(const MEDCouplin const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::multiply on mismatched time discretization !"); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; DataArrayDouble *arr=DataArrayDouble::multiply(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -814,8 +850,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingT const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("divide on mismatched time discretization !"); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; DataArrayDouble *arr=DataArrayDouble::divide(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -992,9 +1028,9 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCoupl const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !"); + DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; ret->setTimeTolerance(getTimeTolerance()); - DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1020,8 +1056,8 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::crossProduct(const MEDCo const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("WithTimeStep::crossProduct on mismatched time discretization !"); - MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; DataArrayDouble *arr=DataArrayDouble::crossProduct(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -1032,8 +1068,8 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::max(const MEDCouplingTim const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("WithTimeStep::max on mismatched time discretization !"); - MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; DataArrayDouble *arr=DataArrayDouble::max(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -1044,8 +1080,8 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::min(const MEDCouplingTim const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("WithTimeStep::min on mismatched time discretization !"); - MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; DataArrayDouble *arr=DataArrayDouble::min(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -1056,8 +1092,8 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTim const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("WithTimeStep::add on mismatched time discretization !"); - MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; DataArrayDouble *arr=DataArrayDouble::add(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1079,8 +1115,8 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::substract(const MEDCoupl const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("WithTimeStep::substract on mismatched time discretization !"); - MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; DataArrayDouble *arr=DataArrayDouble::substract(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1102,8 +1138,8 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::multiply(const MEDCoupli const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("WithTimeStep::multiply on mismatched time discretization !"); - MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; DataArrayDouble *arr=DataArrayDouble::multiply(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1125,8 +1161,8 @@ MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::divide(const MEDCoupling const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("WithTimeStep::divide on mismatched time discretization !"); - MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; DataArrayDouble *arr=DataArrayDouble::divide(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1388,9 +1424,9 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const M const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !"); + DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setTimeTolerance(getTimeTolerance()); - DataArrayDouble *arr=DataArrayDouble::aggregate(getArray(),other->getArray()); ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1406,8 +1442,8 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCoup const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("ConstOnTimeInterval::dot on mismatched time discretization !"); - MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; DataArrayDouble *arr=DataArrayDouble::dot(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -1418,8 +1454,8 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::crossProduct(cons const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("ConstOnTimeInterval::crossProduct on mismatched time discretization !"); - MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; DataArrayDouble *arr=DataArrayDouble::crossProduct(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -1430,8 +1466,8 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::max(const MEDCoup const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("ConstOnTimeInterval::max on mismatched time discretization !"); - MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; DataArrayDouble *arr=DataArrayDouble::max(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -1442,8 +1478,8 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::min(const MEDCoup const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("ConstOnTimeInterval::min on mismatched time discretization !"); - MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; DataArrayDouble *arr=DataArrayDouble::min(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setArray(arr,0); arr->decrRef(); return ret; @@ -1454,8 +1490,8 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCoup const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("ConstOnTimeInterval::add on mismatched time discretization !"); - MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; DataArrayDouble *arr=DataArrayDouble::add(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1479,8 +1515,8 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::substract(const M const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substract on mismatched time discretization !"); - MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; DataArrayDouble *arr=DataArrayDouble::substract(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1504,8 +1540,8 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const ME const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !"); - MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; DataArrayDouble *arr=DataArrayDouble::multiply(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1529,8 +1565,8 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDC const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("divide on mismatched time discretization !"); - MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; DataArrayDouble *arr=DataArrayDouble::divide(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; ret->setArray(arr,0); arr->decrRef(); int tmp1,tmp2; @@ -1899,12 +1935,12 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplin const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::aggregation on mismatched time discretization !"); + DataArrayDouble *arr1=DataArrayDouble::aggregate(getArray(),other->getArray()); + DataArrayDouble *arr2=DataArrayDouble::aggregate(getEndArray(),other->getEndArray()); MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; ret->setTimeTolerance(getTimeTolerance()); - DataArrayDouble *arr1=DataArrayDouble::aggregate(getArray(),other->getArray()); ret->setArray(arr1,0); arr1->decrRef(); - DataArrayDouble *arr2=DataArrayDouble::aggregate(getEndArray(),other->getEndArray()); ret->setEndArray(arr2,0); arr2->decrRef(); return ret; @@ -1915,11 +1951,11 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeD const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !"); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; DataArrayDouble *arr1=DataArrayDouble::dot(getArray(),other->getArray()); + DataArrayDouble *arr2=DataArrayDouble::dot(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; ret->setArray(arr1,0); arr1->decrRef(); - DataArrayDouble *arr2=DataArrayDouble::dot(getEndArray(),other->getEndArray()); ret->setEndArray(arr2,0); arr2->decrRef(); return ret; @@ -1930,11 +1966,11 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCoup const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !"); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; DataArrayDouble *arr1=DataArrayDouble::crossProduct(getArray(),other->getArray()); + DataArrayDouble *arr2=DataArrayDouble::crossProduct(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; ret->setArray(arr1,0); arr1->decrRef(); - DataArrayDouble *arr2=DataArrayDouble::crossProduct(getEndArray(),other->getEndArray()); ret->setEndArray(arr2,0); arr2->decrRef(); return ret; @@ -1960,11 +1996,11 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeD const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !"); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; DataArrayDouble *arr1=DataArrayDouble::min(getArray(),other->getArray()); + DataArrayDouble *arr2=DataArrayDouble::min(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; ret->setArray(arr1,0); arr1->decrRef(); - DataArrayDouble *arr2=DataArrayDouble::min(getEndArray(),other->getEndArray()); ret->setEndArray(arr2,0); arr2->decrRef(); return ret; @@ -1975,11 +2011,11 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeD const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !"); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; DataArrayDouble *arr1=DataArrayDouble::add(getArray(),other->getArray()); + DataArrayDouble *arr2=DataArrayDouble::add(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; ret->setArray(arr1,0); arr1->decrRef(); - DataArrayDouble *arr2=DataArrayDouble::add(getEndArray(),other->getEndArray()); ret->setEndArray(arr2,0); arr2->decrRef(); return ret; @@ -1999,11 +2035,11 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::substract(const MEDCouplin const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::substract on mismatched time discretization !"); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; DataArrayDouble *arr1=DataArrayDouble::substract(getArray(),other->getArray()); + DataArrayDouble *arr2=DataArrayDouble::substract(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; ret->setArray(arr1,0); arr1->decrRef(); - DataArrayDouble *arr2=DataArrayDouble::substract(getEndArray(),other->getEndArray()); ret->setEndArray(arr2,0); arr2->decrRef(); return ret; @@ -2023,11 +2059,11 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::multiply(const MEDCoupling const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::multiply on mismatched time discretization !"); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; DataArrayDouble *arr1=DataArrayDouble::multiply(getArray(),other->getArray()); + DataArrayDouble *arr2=DataArrayDouble::multiply(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; ret->setArray(arr1,0); arr1->decrRef(); - DataArrayDouble *arr2=DataArrayDouble::multiply(getEndArray(),other->getEndArray()); ret->setEndArray(arr2,0); arr2->decrRef(); return ret; @@ -2047,11 +2083,11 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::divide(const MEDCouplingTi const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::divide on mismatched time discretization !"); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; DataArrayDouble *arr1=DataArrayDouble::divide(getArray(),other->getArray()); + DataArrayDouble *arr2=DataArrayDouble::divide(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; ret->setArray(arr1,0); arr1->decrRef(); - DataArrayDouble *arr2=DataArrayDouble::divide(getEndArray(),other->getEndArray()); ret->setEndArray(arr2,0); arr2->decrRef(); return ret; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index f3e80dd9b..e826e12ce 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -103,9 +103,11 @@ namespace ParaMEDMEM virtual MEDCouplingTimeDiscretization *deviator() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *magnitude() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *maxPerTuple() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); + virtual void setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); virtual void changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception); virtual void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); - virtual void setUniformValue(int nbOfTuple, double value); + virtual void setUniformValue(int nbOfTuple, int nbOfCompo, double value); virtual void applyLin(double a, double b, int compoId); virtual void applyFunc(int nbOfComp, FunctionToEvaluate func); virtual void applyFunc(int nbOfComp, const char *func); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 0e8cf3e7f..569560584 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -141,6 +141,8 @@ namespace ParaMEDMEM CPPUNIT_TEST( testFieldDoubleGetMinMaxValues2 ); CPPUNIT_TEST( testBuildUnstructuredCMesh1 ); CPPUNIT_TEST( testDataArrayIntInvertO2NNO21 ); + CPPUNIT_TEST( testKeepSetSelectedComponent1 ); + CPPUNIT_TEST( testKeepSetSelectedComponent2 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -310,6 +312,8 @@ namespace ParaMEDMEM void testFieldDoubleGetMinMaxValues2(); void testBuildUnstructuredCMesh1(); void testDataArrayIntInvertO2NNO21(); + void testKeepSetSelectedComponent1(); + void testKeepSetSelectedComponent2(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index 9636efbaa..0c36bdbad 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -2843,3 +2843,165 @@ void MEDCouplingBasicsTest::testDataArrayIntInvertO2NNO21() da->decrRef(); } +void MEDCouplingBasicsTest::testKeepSetSelectedComponent1() +{ + const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.}; + DataArrayDouble *a1=DataArrayDouble::New(); + a1->alloc(5,4); + std::copy(arr1,arr1+20,a1->getPointer()); + a1->setInfoOnComponent(0,"aaaa"); + a1->setInfoOnComponent(1,"bbbb"); + a1->setInfoOnComponent(2,"cccc"); + a1->setInfoOnComponent(3,"dddd"); + const int arr2[6]={1,2,1,2,0,0}; + std::vector arr2V(arr2,arr2+6); + DataArrayDouble *a2=a1->keepSelectedComponents(arr2V); + CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples()); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="cccc"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="bbbb"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa"); + const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.}; + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14); + DataArrayInt *a3=a1->convertToIntArr(); + DataArrayInt *a4=a3->keepSelectedComponents(arr2V); + CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples()); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="cccc"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="bbbb"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa"); + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_EQUAL(int(expected1[i]),a4->getIJ(0,i)); + // setSelectedComponents + const int arr3[2]={3,2}; + std::vector arr3V(arr3,arr3+2); + DataArrayDouble *a5=a1->keepSelectedComponents(arr3V); + a5->setInfoOnComponent(0,"eeee"); + a5->setInfoOnComponent(1,"ffff"); + const int arr4[2]={1,2}; + std::vector arr4V(arr4,arr4+2); + a2->setSelectedComponents(a5,arr4V); + CPPUNIT_ASSERT_EQUAL(6,a2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,a2->getNumberOfTuples()); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(0))=="bbbb"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(1))=="eeee"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(2))=="ffff"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(3))=="cccc"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(4))=="aaaa"); + CPPUNIT_ASSERT(std::string(a2->getInfoOnComponent(5))=="aaaa"); + const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.}; + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14); + DataArrayInt *a6=a5->convertToIntArr(); + a6->setInfoOnComponent(0,"eeee"); + a6->setInfoOnComponent(1,"ffff"); + a4->setSelectedComponents(a6,arr4V); + CPPUNIT_ASSERT_EQUAL(6,a4->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,a4->getNumberOfTuples()); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(0))=="bbbb"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(1))=="eeee"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(2))=="ffff"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(3))=="cccc"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(4))=="aaaa"); + CPPUNIT_ASSERT(std::string(a4->getInfoOnComponent(5))=="aaaa"); + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_EQUAL(int(expected2[i]),a4->getIJ(0,i)); + // test of throw + const int arr5[3]={2,3,6}; + const int arr6[3]={2,7,5}; + const int arr7[4]={2,1,4,6}; + std::vector arr5V(arr5,arr5+3); + std::vector arr6V(arr6,arr6+3); + std::vector arr7V(arr7,arr7+4); + CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr5V),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(a2->keepSelectedComponents(arr6V),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception); + arr7V.resize(3); + CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception); + // + a6->decrRef(); + a5->decrRef(); + a4->decrRef(); + a3->decrRef(); + a2->decrRef(); + a1->decrRef(); +} + +void MEDCouplingBasicsTest::testKeepSetSelectedComponent2() +{ + MEDCouplingUMesh *m1=build2DTargetMesh_1(); + const double arr1[20]={1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.}; + DataArrayDouble *a1=DataArrayDouble::New(); + a1->alloc(5,4); + std::copy(arr1,arr1+20,a1->getPointer()); + a1->setInfoOnComponent(0,"aaaa"); + a1->setInfoOnComponent(1,"bbbb"); + a1->setInfoOnComponent(2,"cccc"); + a1->setInfoOnComponent(3,"dddd"); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setTime(2.3,4,5); + f1->setMesh(m1); + f1->setName("f1"); + f1->setArray(a1); + f1->checkCoherency(); + // + const int arr2[6]={1,2,1,2,0,0}; + std::vector arr2V(arr2,arr2+6); + MEDCouplingFieldDouble *f2=f1->keepSelectedComponents(arr2V); + CPPUNIT_ASSERT(f2->getMesh()==f1->getMesh()); + CPPUNIT_ASSERT(f2->getTimeDiscretization()==ONE_TIME); + int dt,it; + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13); + CPPUNIT_ASSERT_EQUAL(4,dt); + CPPUNIT_ASSERT_EQUAL(5,it); + f2->checkCoherency(); + CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="cccc"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="bbbb"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa"); + const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.}; + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f2->getIJ(0,i),1e-14); + //setSelectedComponents + const int arr3[2]={3,2}; + std::vector arr3V(arr3,arr3+2); + MEDCouplingFieldDouble *f5=f1->keepSelectedComponents(arr3V); + f5->setTime(6.7,8,9); + f5->getArray()->setInfoOnComponent(0,"eeee"); + f5->getArray()->setInfoOnComponent(1,"ffff"); + f5->checkCoherency(); + const int arr4[2]={1,2}; + std::vector arr4V(arr4,arr4+2); + f2->setSelectedComponents(f5,arr4V); + CPPUNIT_ASSERT_EQUAL(6,f2->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(5,f2->getNumberOfTuples()); + f2->checkCoherency(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.3,f2->getTime(dt,it),1e-13); + CPPUNIT_ASSERT_EQUAL(4,dt); + CPPUNIT_ASSERT_EQUAL(5,it); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(0))=="bbbb"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(1))=="eeee"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(2))=="ffff"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(3))=="cccc"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(4))=="aaaa"); + CPPUNIT_ASSERT(std::string(f2->getArray()->getInfoOnComponent(5))=="aaaa"); + const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.}; + for(int i=0;i<30;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f2->getIJ(0,i),1e-14); + f5->decrRef(); + f1->decrRef(); + f2->decrRef(); + a1->decrRef(); + m1->decrRef(); +} diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index d53183363..a8e328c08 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -759,6 +759,8 @@ class MEDCouplingBasicsTest(unittest.TestCase): m5=m4.build3DUnstructuredMesh(); self.assertTrue(m5.isEqual(m3,1e-12)); f=m5.getMeasureField(True); + f.setMesh(m4) + self.assertTrue(isinstance(f.getMesh(),MEDCouplingExtrudedMesh)) arr=f.getArray(); arrPtr=arr.getValues(); for i in xrange(15): @@ -4043,6 +4045,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): m2.checkCoherency(); f1=m.getMeasureField(False); f2=m2.getMeasureField(False); + self.assertTrue(isinstance(f1.getMesh(),MEDCouplingCMesh)) self.assertEqual(f1.getNumberOfTuples(),3); self.assertEqual(f2.getNumberOfTuples(),3); self.assertEqual(1,m2.getMeshDimension()); @@ -4530,6 +4533,152 @@ class MEDCouplingBasicsTest(unittest.TestCase): # pass + def testKeepSetSelectedComponent1(self): + arr1=[1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.] + a1=DataArrayDouble.New(); + a1.setValues(arr1,5,4); + a1.setInfoOnComponent(0,"aaaa"); + a1.setInfoOnComponent(1,"bbbb"); + a1.setInfoOnComponent(2,"cccc"); + a1.setInfoOnComponent(3,"dddd"); + arr2V=[1,2,1,2,0,0] + a2=a1.keepSelectedComponents(arr2V); + self.assertEqual(6,a2.getNumberOfComponents()); + self.assertEqual(5,a2.getNumberOfTuples()); + self.assertTrue(a2.getInfoOnComponent(0)=="bbbb"); + self.assertTrue(a2.getInfoOnComponent(1)=="cccc"); + self.assertTrue(a2.getInfoOnComponent(2)=="bbbb"); + self.assertTrue(a2.getInfoOnComponent(3)=="cccc"); + self.assertTrue(a2.getInfoOnComponent(4)=="aaaa"); + self.assertTrue(a2.getInfoOnComponent(5)=="aaaa"); + expected1=[2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.] + for i in xrange(30): + self.assertAlmostEqual(expected1[i],a2.getIJ(0,i),14); + pass + a3=a1.convertToIntArr(); + a4=a3.keepSelectedComponents(arr2V); + self.assertEqual(6,a4.getNumberOfComponents()); + self.assertEqual(5,a4.getNumberOfTuples()); + self.assertTrue(a4.getInfoOnComponent(0)=="bbbb"); + self.assertTrue(a4.getInfoOnComponent(1)=="cccc"); + self.assertTrue(a4.getInfoOnComponent(2)=="bbbb"); + self.assertTrue(a4.getInfoOnComponent(3)=="cccc"); + self.assertTrue(a4.getInfoOnComponent(4)=="aaaa"); + self.assertTrue(a4.getInfoOnComponent(5)=="aaaa"); + for i in xrange(30): + self.assertEqual(int(expected1[i]),a4.getIJ(0,i)); + pass + # setSelectedComponents + arr3V=[3,2] + a5=a1.keepSelectedComponents(arr3V); + a5.setInfoOnComponent(0,"eeee"); + a5.setInfoOnComponent(1,"ffff"); + arr4V=[1,2] + a2.setSelectedComponents(a5,arr4V); + self.assertEqual(6,a2.getNumberOfComponents()); + self.assertEqual(5,a2.getNumberOfTuples()); + self.assertTrue(a2.getInfoOnComponent(0)=="bbbb"); + self.assertTrue(a2.getInfoOnComponent(1)=="eeee"); + self.assertTrue(a2.getInfoOnComponent(2)=="ffff"); + self.assertTrue(a2.getInfoOnComponent(3)=="cccc"); + self.assertTrue(a2.getInfoOnComponent(4)=="aaaa"); + self.assertTrue(a2.getInfoOnComponent(5)=="aaaa"); + expected2=[2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.] + for i in xrange(30): + self.assertAlmostEqual(expected2[i],a2.getIJ(0,i),14); + pass + a6=a5.convertToIntArr(); + a6.setInfoOnComponent(0,"eeee"); + a6.setInfoOnComponent(1,"ffff"); + a4.setSelectedComponents(a6,arr4V); + self.assertEqual(6,a4.getNumberOfComponents()); + self.assertEqual(5,a4.getNumberOfTuples()); + self.assertTrue(a4.getInfoOnComponent(0)=="bbbb"); + self.assertTrue(a4.getInfoOnComponent(1)=="eeee"); + self.assertTrue(a4.getInfoOnComponent(2)=="ffff"); + self.assertTrue(a4.getInfoOnComponent(3)=="cccc"); + self.assertTrue(a4.getInfoOnComponent(4)=="aaaa"); + self.assertTrue(a4.getInfoOnComponent(5)=="aaaa"); + for i in xrange(30): + self.assertEqual(int(expected2[i]),a4.getIJ(0,i)); + pass + # test of throw + arr5V=[2,3,6] + arr6V=[2,7,5] + arr7V=[2,1,4,6] + self.assertRaises(Exception,a2.keepSelectedComponents,arr5V); + self.assertRaises(Exception,a2.keepSelectedComponents,arr6V); + self.assertRaises(Exception,a2.setSelectedComponents,a1,arr7V); + arr7V=arr7V[0:3] + self.assertRaises(Exception,a2.setSelectedComponents,a1,arr7V); + # + pass + + def testKeepSetSelectedComponent2(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + arr1=[1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.] + a1=DataArrayDouble.New(); + a1.setValues(arr1,5,4); + a1.setInfoOnComponent(0,"aaaa"); + a1.setInfoOnComponent(1,"bbbb"); + a1.setInfoOnComponent(2,"cccc"); + a1.setInfoOnComponent(3,"dddd"); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setTime(2.3,4,5); + f1.setMesh(m1); + f1.setName("f1"); + f1.setArray(a1); + f1.checkCoherency(); + # + arr2V=[1,2,1,2,0,0] + f2=f1.keepSelectedComponents(arr2V); + self.assertTrue(f2.getTimeDiscretization()==ONE_TIME); + t,dt,it=f2.getTime() + self.assertAlmostEqual(2.3,t,13); + self.assertEqual(4,dt); + self.assertEqual(5,it); + f2.checkCoherency(); + self.assertEqual(6,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + self.assertTrue(f2.getArray().getInfoOnComponent(0)=="bbbb"); + self.assertTrue(f2.getArray().getInfoOnComponent(1)=="cccc"); + self.assertTrue(f2.getArray().getInfoOnComponent(2)=="bbbb"); + self.assertTrue(f2.getArray().getInfoOnComponent(3)=="cccc"); + self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa"); + self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa"); + expected1=[2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.] + for i in xrange(30): + self.assertAlmostEqual(expected1[i],f2.getIJ(0,i),14); + pass + #setSelectedComponents + arr3V=[3,2] + f5=f1.keepSelectedComponents(arr3V); + f5.setTime(6.7,8,9); + f5.getArray().setInfoOnComponent(0,"eeee"); + f5.getArray().setInfoOnComponent(1,"ffff"); + f5.checkCoherency(); + arr4V=[1,2] + f2.setSelectedComponents(f5,arr4V); + self.assertEqual(6,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + f2.checkCoherency(); + t,dt,it=f2.getTime() + self.assertAlmostEqual(2.3,t,13); + self.assertEqual(4,dt); + self.assertEqual(5,it); + self.assertTrue(f2.getArray().getInfoOnComponent(0)=="bbbb"); + self.assertTrue(f2.getArray().getInfoOnComponent(1)=="eeee"); + self.assertTrue(f2.getArray().getInfoOnComponent(2)=="ffff"); + self.assertTrue(f2.getArray().getInfoOnComponent(3)=="cccc"); + self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa"); + self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa"); + expected2=[2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.] + for i in xrange(30): + self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),14); + pass + # + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index b5d9b2a29..d1af65ba8 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -23,11 +23,18 @@ static PyObject* convertMesh(ParaMEDMEM::MEDCouplingMesh* mesh, int owner) { - PyObject *ret; + PyObject *ret=0; if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner); + if(!ret) + { + PyErr_SetString(PyExc_TypeError,"Not recognized type of mesh on downcast !"); + PyErr_Print(); + } return ret; } diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i index f6d3f696e..d6b35f447 100644 --- a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i +++ b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i @@ -76,6 +76,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingFieldDouble::deviator; %newobject ParaMEDMEM::MEDCouplingFieldDouble::magnitude; %newobject ParaMEDMEM::MEDCouplingFieldDouble::maxPerTuple; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::keepSelectedComponents; %newobject ParaMEDMEM::MEDCouplingFieldDouble::dotFields; %newobject ParaMEDMEM::MEDCouplingFieldDouble::dot; %newobject ParaMEDMEM::MEDCouplingFieldDouble::crossProductFields; @@ -97,6 +98,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::performCpy; %newobject ParaMEDMEM::DataArrayInt::substr; %newobject ParaMEDMEM::DataArrayInt::changeNbOfComponents; +%newobject ParaMEDMEM::DataArrayInt::keepSelectedComponents; %newobject ParaMEDMEM::DataArrayInt::selectByTupleId; %newobject ParaMEDMEM::DataArrayInt::renumber; %newobject ParaMEDMEM::DataArrayInt::renumberR; @@ -112,6 +114,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayDouble::divide; %newobject ParaMEDMEM::DataArrayDouble::substr; %newobject ParaMEDMEM::DataArrayDouble::changeNbOfComponents; +%newobject ParaMEDMEM::DataArrayDouble::keepSelectedComponents; %newobject ParaMEDMEM::DataArrayDouble::getIdsInRange; %newobject ParaMEDMEM::DataArrayDouble::selectByTupleId; %newobject ParaMEDMEM::DataArrayDouble::applyFunc; @@ -751,6 +754,23 @@ namespace ParaMEDMEM }; } +%extend ParaMEDMEM::DataArray +{ + void copyPartOfStringInfoFrom(const DataArray& other, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->copyPartOfStringInfoFrom(other,tmp); + } + + void copyPartOfStringInfoFrom2(PyObject *li, const DataArray& other) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->copyPartOfStringInfoFrom2(tmp,other); + } +} + %extend ParaMEDMEM::DataArrayDouble { std::string __str__() const @@ -895,6 +915,20 @@ namespace ParaMEDMEM PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } + + DataArrayDouble *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + return self->keepSelectedComponents(tmp); + } + + void setSelectedComponents(const DataArrayDouble *a, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->setSelectedComponents(a,tmp); + } }; %extend ParaMEDMEM::DataArrayInt @@ -1017,6 +1051,20 @@ namespace ParaMEDMEM delete [] tmp; return ret; } + + DataArrayInt *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + return self->keepSelectedComponents(tmp); + } + + void setSelectedComponents(const DataArrayInt *a, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->setSelectedComponents(a,tmp); + } }; namespace ParaMEDMEM @@ -1135,6 +1183,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble &operator=(double value) throw(INTERP_KERNEL::Exception); void fillFromAnalytic(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception); void applyFunc(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception); + void applyFunc(int nbOfComp, double val) throw(INTERP_KERNEL::Exception); void applyFunc(const char *func) throw(INTERP_KERNEL::Exception); void applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception); void applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception); @@ -1362,6 +1411,20 @@ namespace ParaMEDMEM PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } + + MEDCouplingFieldDouble *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + return self->keepSelectedComponents(tmp); + } + + void setSelectedComponents(const MEDCouplingFieldDouble *f, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->setSelectedComponents(f,tmp); + } } }; } diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 1c08abd94..cde077cee 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -390,6 +390,14 @@ std::vector MEDLoader::GetMeshNamesOnField(const char *fileName, co ret.push_back(curMeshName); } } + med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE); + for(int k=0;k MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName return ret; } +std::vector< std::pair< std::pair, double> > MEDLoader::GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) +{ + CheckFileForRead(fileName); + std::string meshNameCpp(meshName); + std::vector< std::pair< std::pair, double> > ret; + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nbFields=MEDnChamp(fid,0); + // + med_type_champ typcha; + med_int ngauss=0; + med_int numdt=0,numo=0,nbrefmaa; + med_float dt=0.0; + med_booleen local; + char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM); + char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + // + for(int i=0;i > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); @@ -1856,6 +1995,8 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadField(ParaMEDMEM::TypeOfField std::vector MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, const std::vector >& its) throw(INTERP_KERNEL::Exception) { + if(its.empty()) + return std::vector(); CheckFileForRead(fileName); std::vector ret(its.size()); if(its.empty()) @@ -2686,5 +2827,8 @@ void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const Pa std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + std::string fieldName(f->getName()); + if(fieldName.empty()) + throw INTERP_KERNEL::Exception("Trying to write a field with no name ! MED file format needs a not empty field name !"); MEDLoaderNS::appendFieldDirectly(fileName,f); } diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index d262c04a3..b90cad0f7 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -99,6 +99,8 @@ class MEDLOADER_EXPORT MEDLoader static std::vector< std::pair > GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); static std::vector< std::pair > GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); static std::vector< std::pair > GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); + static std::vector< std::pair< std::pair, double> > GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); + static double GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/libMEDLoader_Swig.i b/src/MEDLoader/Swig/libMEDLoader_Swig.i index ddf0c24c0..5feded4d5 100644 --- a/src/MEDLoader/Swig/libMEDLoader_Swig.i +++ b/src/MEDLoader/Swig/libMEDLoader_Swig.i @@ -58,6 +58,7 @@ public: static std::vector GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); static std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static double GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); %extend { static PyObject *GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) @@ -75,6 +76,22 @@ public: return ret; } + static PyObject *GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) + { + std::vector< std::pair< std::pair, double> > res=MEDLoader::GetAllFieldIterations(fileName,meshName,fieldName); + PyObject *ret=PyList_New(res.size()); + int rk=0; + for(std::vector< std::pair< std::pair, double> >::const_iterator iter=res.begin();iter!=res.end();iter++,rk++) + { + PyObject *elt=PyTuple_New(3); + PyTuple_SetItem(elt,0,SWIG_From_int((*iter).first.first)); + PyTuple_SetItem(elt,1,SWIG_From_int((*iter).first.second)); + PyTuple_SetItem(elt,2,SWIG_From_double((*iter).second)); + PyList_SetItem(ret,rk,elt); + } + return ret; + } + static PyObject *GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { std::vector< std::pair > res=MEDLoader::GetCellFieldIterations(fileName,meshName,fieldName);