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;
}
_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.
_time_discr->changeNbOfComponents(newNbOfComp,dftValue);
}
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std::vector<int>& 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<int>& 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);
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);
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<int>& compoIds) const throw(INTERP_KERNEL::Exception);
+ void setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector<int>& 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);
//
#include "MEDCouplingMemArray.txx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
#include "GenMathFormulae.hxx"
#include "InterpKernelExprParser.hxx"
_info_on_compo=other._info_on_compo;
}
+void DataArray::copyPartOfStringInfoFrom(const DataArray& other, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
+{
+ int nbOfCompoOth=other.getNumberOfComponents();
+ int newNbOfCompo=compoIds.size();
+ for(int i=0;i<newNbOfCompo;i++)
+ if(compoIds[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<newNbOfCompo;i++)
+ setInfoOnComponent(i,other.getInfoOnComponent(compoIds[i]).c_str());
+}
+
+void DataArray::copyPartOfStringInfoFrom2(const std::vector<int>& 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<partOfCompoToSet;i++)
+ if(compoIds[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<partOfCompoToSet;i++)
+ setInfoOnComponent(compoIds[i],other.getInfoOnComponent(i).c_str());
+}
+
bool DataArray::areInfoEquals(const DataArray& other) const
{
if(_nb_of_tuples!=other._nb_of_tuples)
return ret;
}
+DataArrayDouble *DataArrayDouble::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> 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;i<nbOfTuples;i++)
+ for(int j=0;j<newNbOfCompo;j++,nc++)
+ *nc=oldc[i*oldNbOfCompo+compoIds[j]];
+ ret->incrRef();
+ return ret;
+}
+
+void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& 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<nbOfTuples;i++)
+ for(int j=0;j<partOfCompoSz;j++,ac++)
+ nc[nbOfCompo*i+compoIds[j]]=*ac;
+}
+
void DataArrayDouble::setArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
{
if(newArray!=arrayToSet)
declareAsNew();
}
+DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> 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;i<nbOfTuples;i++)
+ for(int j=0;j<newNbOfCompo;j++,nc++)
+ *nc=oldc[i*oldNbOfCompo+compoIds[j]];
+ ret->incrRef();
+ return ret;
+}
+
+void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector<int>& 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<nbOfTuples;i++)
+ for(int j=0;j<partOfCompoSz;j++,ac++)
+ nc[nbOfCompo*i+compoIds[j]]=*ac;
+}
+
void DataArrayInt::setArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
{
if(newArray!=arrayToSet)
public:
MEDCOUPLING_EXPORT void setName(const char *name);
MEDCOUPLING_EXPORT void copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void copyPartOfStringInfoFrom(const DataArray& other, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void copyPartOfStringInfoFrom2(const std::vector<int>& 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; }
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<int>& compoIds) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& 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(); }
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<int>& compoIds) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayInt *a, const std::vector<int>& 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; }
MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() const throw(INTERP_KERNEL::Exception)
{
- MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
std::vector<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
std::vector<DataArrayDouble *> 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<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
std::vector<DataArrayDouble *> 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<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
std::vector<DataArrayDouble *> 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<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
std::vector<DataArrayDouble *> 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<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
std::vector<DataArrayDouble *> 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<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
std::vector<DataArrayDouble *> 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<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
std::vector<DataArrayDouble *> 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<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
std::vector<DataArrayDouble *> 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<int>& compoIds) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<DataArrayDouble *> arrays;
+ getArrays(arrays);
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > 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<DataArrayDouble *> 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<int>& compoIds) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<DataArrayDouble *> 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;i<arrays1.size();i++)
+ {
+ if(arrays1[i]!=0 && arrays2[i]!=0)
+ arrays1[i]->setSelectedComponents(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<DataArrayDouble *> arrays;
}
}
-void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, double value)
+void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo, double value)
{
std::vector<DataArrayDouble *> arrays;
getArrays(arrays);
else
{
DataArrayDouble *tmp=DataArrayDouble::New();
- tmp->alloc(nbOfTuple,1);
+ tmp->alloc(nbOfTuple,nbOfCompo);
tmp->fillWithValue(value);
arrays2[j]=tmp;
}
void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const char *func)
{
- std::vector<DataArrayDouble *> arrays;
+ std::vector<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector<DataArrayDouble *> arrays2(arrays.size());
for(int j=0;j<(int)arrays.size();j++)
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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;
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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;
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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;
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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;
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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;
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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;
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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;
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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;
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(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;
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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;
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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;
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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;
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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;
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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;
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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;
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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;
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(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;
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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;
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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;
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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;
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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;
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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;
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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;
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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;
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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;
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(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;
const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(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;
const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(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;
const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(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;
const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(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;
const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(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;
const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(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;
const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(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;
const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(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;
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<int>& compoIds) const throw(INTERP_KERNEL::Exception);
+ virtual void setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector<int>& 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);
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 );
void testFieldDoubleGetMinMaxValues2();
void testBuildUnstructuredCMesh1();
void testDataArrayIntInvertO2NNO21();
+ void testKeepSetSelectedComponent1();
+ void testKeepSetSelectedComponent2();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
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<int> 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<int> 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<int> 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<int> arr5V(arr5,arr5+3);
+ std::vector<int> arr6V(arr6,arr6+3);
+ std::vector<int> 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<int> 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<int> 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<int> 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();
+}
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):
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());
#
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
static PyObject* convertMesh(ParaMEDMEM::MEDCouplingMesh* mesh, int owner)
{
- PyObject *ret;
+ PyObject *ret=0;
if(dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(mesh))
ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner);
if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
+ if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(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;
}
%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;
%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;
%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;
};
}
+%extend ParaMEDMEM::DataArray
+{
+ void copyPartOfStringInfoFrom(const DataArray& other, PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<int> tmp;
+ convertPyToNewIntArr3(li,tmp);
+ self->copyPartOfStringInfoFrom(other,tmp);
+ }
+
+ void copyPartOfStringInfoFrom2(PyObject *li, const DataArray& other) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<int> tmp;
+ convertPyToNewIntArr3(li,tmp);
+ self->copyPartOfStringInfoFrom2(tmp,other);
+ }
+}
+
%extend ParaMEDMEM::DataArrayDouble
{
std::string __str__() const
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<int> tmp;
+ convertPyToNewIntArr3(li,tmp);
+ return self->keepSelectedComponents(tmp);
+ }
+
+ void setSelectedComponents(const DataArrayDouble *a, PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<int> tmp;
+ convertPyToNewIntArr3(li,tmp);
+ self->setSelectedComponents(a,tmp);
+ }
};
%extend ParaMEDMEM::DataArrayInt
delete [] tmp;
return ret;
}
+
+ DataArrayInt *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<int> tmp;
+ convertPyToNewIntArr3(li,tmp);
+ return self->keepSelectedComponents(tmp);
+ }
+
+ void setSelectedComponents(const DataArrayInt *a, PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<int> tmp;
+ convertPyToNewIntArr3(li,tmp);
+ self->setSelectedComponents(a,tmp);
+ }
};
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);
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<int> tmp;
+ convertPyToNewIntArr3(li,tmp);
+ return self->keepSelectedComponents(tmp);
+ }
+
+ void setSelectedComponents(const MEDCouplingFieldDouble *f, PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<int> tmp;
+ convertPyToNewIntArr3(li,tmp);
+ self->setSelectedComponents(f,tmp);
+ }
}
};
}
ret.push_back(curMeshName);
}
}
+ med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
+ for(int k=0;k<nbPdt;k++)
+ {
+ MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
+ if(std::find(ret.begin(),ret.end(),curMeshName)==ret.end())
+ ret.push_back(curMeshName);
+ }
}
}
delete [] maa_ass;
return ret;
}
+std::vector< std::pair< std::pair<int,int>, 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<int,int>, 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<nbFields;i++)
+ {
+ med_int ncomp=MEDnChamp(fid,i+1);
+ char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
+ char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
+ MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
+ delete [] comp;
+ delete [] unit;
+ if(curFieldName==fieldName)
+ {
+ bool found=false;
+ for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found;j++)
+ {
+ med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
+ for(int k=0;k<nbPdt;k++)
+ {
+ MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ std::string maa_ass_cpp(maa_ass);
+ if(meshNameCpp==maa_ass_cpp)
+ {
+ found=true;
+ ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
+ }
+ }
+ }
+ med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
+ for(int k=0;k<nbPdt;k++)
+ {
+ MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ std::string maa_ass_cpp(maa_ass);
+ if(meshNameCpp==maa_ass_cpp)
+ ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
+ }
+ }
+ }
+ delete [] maa_ass;
+ delete [] dt_unit;
+ delete [] nomcha;
+ MEDfermer(fid);
+ return ret;
+}
+
+double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
+{
+ CheckFileForRead(fileName);
+ 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);
+ //
+ bool found=false;
+ bool found2=false;
+ double ret;
+ for(int i=0;i<nbFields && !found;i++)
+ {
+ med_int ncomp=MEDnChamp(fid,i+1);
+ char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
+ char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
+ MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
+ delete [] comp;
+ delete [] unit;
+ if(curFieldName==fieldName)
+ {
+ found=true;
+ for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found2;j++)
+ {
+ med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
+ for(int k=0;k<nbPdt;k++)
+ {
+ MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ if(numdt==iteration && numo==order)
+ {
+ found2=true;
+ ret=dt;
+ }
+ }
+ }
+ if(!found2)
+ {
+ med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
+ for(int k=0;k<nbPdt && !found2;k++)
+ {
+ MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ if(numdt==iteration && numo==order)
+ {
+ found2=true;
+ ret=dt;
+ }
+ }
+ }
+ }
+ }
+ delete [] maa_ass;
+ delete [] dt_unit;
+ delete [] nomcha;
+ MEDfermer(fid);
+ if(!found || !found2)
+ {
+ std::ostringstream oss;
+ oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return ret;
+}
+
std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
{
+ if(its.empty())
+ return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
CheckFileForRead(fileName);
std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
if(its.empty())
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);
}
static std::vector< std::pair<int,int> > GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception);
static std::vector< std::pair<int,int> > GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception);
static std::vector< std::pair<int,int> > GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception);
+ static std::vector< std::pair< std::pair<int,int>, 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<std::string>& fams) throw(INTERP_KERNEL::Exception);
static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception);
static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> 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)
return ret;
}
+ static PyObject *GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector< std::pair< std::pair<int,int>, double> > res=MEDLoader::GetAllFieldIterations(fileName,meshName,fieldName);
+ PyObject *ret=PyList_New(res.size());
+ int rk=0;
+ for(std::vector< std::pair< std::pair<int,int>, 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<int,int> > res=MEDLoader::GetCellFieldIterations(fileName,meshName,fieldName);