int nbOfCompoOth=other.getNumberOfComponents();
std::size_t newNbOfCompo=compoIds.size();
for(std::size_t i=0;i<newNbOfCompo;i++)
- if(compoIds[i]>=nbOfCompoOth)
+ if(compoIds[i]>=nbOfCompoOth || compoIds[i]<0)
{
- std::ostringstream oss; oss << "Specified component ids is to high (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompoOth << ")";
+ std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompoOth << ")";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
for(std::size_t i=0;i<newNbOfCompo;i++)
if((int)partOfCompoToSet!=other.getNumberOfComponents())
throw INTERP_KERNEL::Exception("Given compoIds has not the same size as number of components of given array !");
for(std::size_t i=0;i<partOfCompoToSet;i++)
- if(compoIds[i]>=nbOfCompo)
+ if(compoIds[i]>=nbOfCompo || compoIds[i]<0)
{
- std::ostringstream oss; oss << "Specified component ids is to high (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")";
+ std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
for(std::size_t i=0;i<partOfCompoToSet;i++)
std::string DataArray::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
{
- if(i<(int)_info_on_compo.size())
+ if(i<(int)_info_on_compo.size() && i>=0)
return _info_on_compo[i];
else
{
- std::ostringstream oss; oss << "getInfoOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size();
+ std::ostringstream oss; oss << "DataArray::getInfoOnComponent : Specified component id is out of range (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
*/
std::string DataArray::getVarOnComponent(int i) const throw(INTERP_KERNEL::Exception)
{
- if(i<(int)_info_on_compo.size())
+ if(i<(int)_info_on_compo.size() && i>=0)
{
return GetVarNameFromInfo(_info_on_compo[i]);
}
else
{
- std::ostringstream oss; oss << "getVarOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size();
+ std::ostringstream oss; oss << "DataArray::getVarOnComponent : Specified component id is out of range (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
*/
std::string DataArray::getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception)
{
- if(i<(int)_info_on_compo.size())
+ if(i<(int)_info_on_compo.size() && i>=0)
{
return GetUnitFromInfo(_info_on_compo[i]);
}
else
{
- std::ostringstream oss; oss << "getUnitOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size();
+ std::ostringstream oss; oss << "DataArray::getUnitOnComponent : Specified component id is out of range (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
{
- if(i<(int)_info_on_compo.size())
+ if(i<(int)_info_on_compo.size() && i>=0)
_info_on_compo[i]=info;
else
{
- std::ostringstream oss; oss << "setInfoOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size();
+ std::ostringstream oss; oss << "DataArray::setInfoOnComponent : Specified component id is out of range (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
{
if(value<0 || value>=ref)
{
- std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg << " ! Expected in range [0," << ref << ") having " << value << " !";
+ std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg << " ! Expected in range [0," << ref << "[ having " << value << " !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
{
if(value<0 || value>ref)
{
- std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected a range in [0," << ref << ") having closing open parenthesis " << value << " !";
+ std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected a range in [0," << ref << "] having closing open parenthesis " << value << " !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
void DataArrayDouble::fillWithZero() throw(INTERP_KERNEL::Exception)
{
- fillWithValue(0.);
+ checkAllocated();
+ _mem.fillWithValue(0.);
+ declareAsNew();
}
void DataArrayDouble::fillWithValue(double val) throw(INTERP_KERNEL::Exception)
{
- if(!getPointer())
- throw INTERP_KERNEL::Exception("DataArrayDouble::fillWithValue : allocate first !");
- _mem.fillWithValue(val);
+ checkAllocated();
+ _mem.fillWithValue(val);
declareAsNew();
}
void DataArrayDouble::iota(double init) throw(INTERP_KERNEL::Exception)
{
- double *ptr=getPointer();
- if(!ptr)
- throw INTERP_KERNEL::Exception("DataArrayDouble::iota : allocate first !");
+ checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
+ double *ptr=getPointer();
int ntuples=getNumberOfTuples();
for(int i=0;i<ntuples;i++)
ptr[i]=init+double(i);
bool DataArrayDouble::isUniform(double val, double eps) const
{
+ checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
int nbOfTuples=getNumberOfTuples();
_mem.reverse();
}
-void DataArrayDouble::checkMonotonic(double eps) const throw(INTERP_KERNEL::Exception)
+/*!
+ * This method check that (Maths) array consistently INCREASING or DECREASING in value,
+ * with at least absolute difference value of |eps| at each step.
+ * if not an exception will be thrown.
+ */
+ void DataArrayDouble::checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
{
- if(!isMonotonic(eps))
- throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not monotonic !");
+ if(!isMonotonic(increasing, eps))
+ if (increasing)
+ {
+ throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not INCREASING monotonic !");
+ }
+ else
+ {
+ throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not DECREASING monotonic !");
+ }
}
-bool DataArrayDouble::isMonotonic(double eps) const throw(INTERP_KERNEL::Exception)
+/*!
+ * This method check that (Maths) array consistently INCREASING or DECREASING in value,
+ * with at least absolute difference value of |eps| at each step.
+ */
+bool DataArrayDouble::isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
{
checkAllocated();
if(getNumberOfComponents()!=1)
if(nbOfElements==0)
return true;
double ref=ptr[0];
- for(int i=1;i<nbOfElements;i++)
+ double absEps=fabs(eps);
+ if (increasing)
{
- if(ptr[i]<ref+eps)
- return false;
- ref=ptr[i];
+ for(int i=1;i<nbOfElements;i++)
+ {
+ if(ptr[i]<(ref+absEps)) return false;
+ ref=ptr[i];
+ }
+ return true;
+ }
+ else
+ {
+ for(int i=1;i<nbOfElements;i++)
+ {
+ if(ptr[i]>(ref-absEps)) return false;
+ ref=ptr[i];
+ }
+ return true;
}
- return true;
}
std::string DataArrayDouble::repr() const
/*!
* This method is a generalization of DataArrayDouble::substr method because a not contigous range can be specified here.
- * This method is equavalent to DataArrayDouble::renumberAndReduce except that convention in input is new2old and \b not old2new.
+ * This method is equivalent to DataArrayDouble::renumberAndReduce except that convention in input is new2old and \b not old2new.
*/
DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
{
*/
void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception)
{
+ checkAllocated();
+ int nbOfCompo=getNumberOfComponents();
+ if ((nbOfCompo<1) || (nbOfCompo>3)) //test before work
+ throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : Unexpected spacedim of coords. Must be 1, 2 or 3.");
+
+ int nbOfTuples=getNumberOfTuples();
comm=DataArrayInt::New();
commIndex=DataArrayInt::New();
//
- checkAllocated();
- int nbOfTuples=getNumberOfTuples();
- int nbOfCompo=getNumberOfComponents();
std::vector<double> bbox(2*nbOfTuples*nbOfCompo);
const double *coordsPtr=getConstPointer();
for(int i=0;i<nbOfTuples;i++)
case 1:
findCommonTuplesAlg<1>(bbox,nbOfTuples,limitTupleId,prec,c,cI);
break;
- default:
- throw INTERP_KERNEL::Exception("Unexpected spacedim of coords. Must be 1, 2 or 3.");
+ //default: test yet
}
commIndex->alloc((int)cI.size(),1);
std::copy(cI.begin(),cI.end(),commIndex->getPointer());
void DataArrayInt::fillWithZero()
{
+ checkAllocated();
_mem.fillWithValue(0);
declareAsNew();
}
void DataArrayInt::fillWithValue(int val)
{
+ checkAllocated();
_mem.fillWithValue(val);
declareAsNew();
}
void DataArrayInt::iota(int init) throw(INTERP_KERNEL::Exception)
{
- int *ptr=getPointer();
- if(!ptr)
- throw INTERP_KERNEL::Exception("DataArrayInt::iota : allocate first !");
+ checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
+ int *ptr=getPointer();
int ntuples=getNumberOfTuples();
for(int i=0;i<ntuples;i++)
ptr[i]=init+i;
*/
bool DataArrayInt::isIdentity() const
{
+ checkAllocated();
if(getNumberOfComponents()!=1)
return false;
int nbOfTuples=getNumberOfTuples();
bool DataArrayInt::isUniform(int val) const
{
+ checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
int nbOfTuples=getNumberOfTuples();
DataArrayDouble *DataArrayInt::convertToDblArr() const
{
+ checkAllocated();
DataArrayDouble *ret=DataArrayDouble::New();
ret->alloc(getNumberOfTuples(),getNumberOfComponents());
int nbOfVals=getNbOfElems();