* is to delete this array using decrRef() as it is no more needed. The array
* does not contain any textual info on components.
* \throw If \a this->getNumberOfComponents() != 2.
+ * \sa fromCartToPolar
*/
DataArrayDouble *DataArrayDouble::fromPolarToCart() const
{
* on the third component is copied from \a this array. The caller
* is to delete this array using decrRef() as it is no more needed.
* \throw If \a this->getNumberOfComponents() != 3.
+ * \sa fromCartToCyl
*/
DataArrayDouble *DataArrayDouble::fromCylToCart() const
{
* on the third component is copied from \a this array. The caller
* is to delete this array using decrRef() as it is no more needed.
* \throw If \a this->getNumberOfComponents() != 3.
+ * \sa fromCartToSpher
*/
DataArrayDouble *DataArrayDouble::fromSpherToCart() const
{
return ret.retn();
}
+/*!
+ * This method returns a newly created array to be deallocated that contains the result of conversion from cartesian to polar.
+ * This method expects that \a this has exactly 2 components.
+ * \sa fromPolarToCart
+ */
+DataArrayDouble *DataArrayDouble::fromCartToPolar() const
+{
+ MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
+ checkAllocated();
+ int nbOfComp(getNumberOfComponents()),nbTuples(getNumberOfTuples());
+ if(nbOfComp!=2)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToPolar : must be an array with exactly 2 components !");
+ ret->alloc(nbTuples,2);
+ double *retPtr(ret->getPointer());
+ const double *ptr(begin());
+ for(int i=0;i<nbTuples;i++,ptr+=2,retPtr+=2)
+ {
+ retPtr[0]=sqrt(ptr[0]*ptr[0]+ptr[1]*ptr[1]);
+ retPtr[1]=atan2(ptr[1],ptr[0]);
+ }
+ return ret.retn();
+}
+
+/*!
+ * This method returns a newly created array to be deallocated that contains the result of conversion from cartesian to cylindrical.
+ * This method expects that \a this has exactly 3 components.
+ * \sa fromCylToCart
+ */
+DataArrayDouble *DataArrayDouble::fromCartToCyl() const
+{
+ MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
+ checkAllocated();
+ int nbOfComp(getNumberOfComponents()),nbTuples(getNumberOfTuples());
+ if(nbOfComp!=3)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToCyl : must be an array with exactly 3 components !");
+ ret->alloc(nbTuples,3);
+ double *retPtr(ret->getPointer());
+ const double *ptr(begin());
+ for(int i=0;i<nbTuples;i++,ptr+=3,retPtr+=3)
+ {
+ retPtr[0]=sqrt(ptr[0]*ptr[0]+ptr[1]*ptr[1]);
+ retPtr[1]=atan2(ptr[1],ptr[0]);
+ retPtr[2]=ptr[2];
+ }
+ return ret.retn();
+}
+
+/*!
+ * This method returns a newly created array to be deallocated that contains the result of conversion from cartesian to spherical coordinates.
+ * \sa fromSpherToCart
+ */
+DataArrayDouble *DataArrayDouble::fromCartToSpher() const
+{
+ MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
+ checkAllocated();
+ int nbOfComp(getNumberOfComponents()),nbTuples(getNumberOfTuples());
+ if(nbOfComp!=3)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToSpher : must be an array with exactly 3 components !");
+ ret->alloc(nbTuples,3);
+ double *retPtr(ret->getPointer());
+ const double *ptr(begin());
+ for(int i=0;i<nbTuples;i++,ptr+=3,retPtr+=3)
+ {
+ retPtr[0]=sqrt(ptr[0]*ptr[0]+ptr[1]*ptr[1]+ptr[2]*ptr[2]);
+ retPtr[1]=acos(ptr[2]/retPtr[0]);
+ retPtr[2]=atan2(ptr[1],ptr[0]);
+ }
+ return ret.retn();
+}
+
+/*!
+ * This method returns a newly created array to be deallocated that contains the result of conversion from cartesian to cylindrical relative to the given \a center and a \a vector.
+ * This method expects that \a this has exactly 3 components.
+ * \sa MEDCouplingFieldDouble::computeVectorFieldCyl
+ */
+DataArrayDouble *DataArrayDouble::fromCartToCylGiven(const DataArrayDouble *coords, const double center[3], const double vect[3]) const
+{
+ if(!coords)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToCylGiven : input coords are NULL !");
+ MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
+ checkAllocated(); coords->checkAllocated();
+ int nbOfComp(getNumberOfComponents()),nbTuples(getNumberOfTuples());
+ if(nbOfComp!=3)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToCylGiven : must be an array with exactly 3 components !");
+ if(coords->getNumberOfComponents()!=3)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToCylGiven : coords array must have exactly 3 components !");
+ if(coords->getNumberOfTuples()!=nbTuples)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToCylGiven : coords array must have the same number of tuples !");
+ ret->alloc(nbTuples,nbOfComp);
+ double magOfVect(sqrt(vect[0]*vect[0]+vect[1]*vect[1]+vect[2]*vect[2]));
+ if(magOfVect<1e-12)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToCylGiven : magnitude of vect is too low !");
+ double Ur[3],Uteta[3],Uz[3],*retPtr(ret->getPointer());
+ const double *coo(coords->begin()),*vectField(begin());
+ std::transform(vect,vect+3,Uz,std::bind2nd(std::multiplies<double>(),1./magOfVect));
+ for(int i=0;i<nbTuples;i++,vectField+=3,retPtr+=3,coo+=3)
+ {
+ std::transform(coo,coo+3,center,Ur,std::minus<double>());
+ Uteta[0]=Uz[1]*Ur[2]-Uz[2]*Ur[1]; Uteta[1]=Uz[2]*Ur[0]-Uz[0]*Ur[2]; Uteta[2]=Uz[0]*Ur[1]-Uz[1]*Ur[0];
+ double magOfTeta(sqrt(Uteta[0]*Uteta[0]+Uteta[1]*Uteta[1]+Uteta[2]*Uteta[2]));
+ std::transform(Uteta,Uteta+3,Uteta,std::bind2nd(std::multiplies<double>(),1./magOfTeta));
+ Ur[0]=Uteta[1]*Uz[2]-Uteta[2]*Uz[1]; Ur[1]=Uteta[2]*Uz[0]-Uteta[0]*Uz[2]; Ur[2]=Uteta[0]*Uz[1]-Uteta[1]*Uz[0];
+ retPtr[0]=Ur[0]*vectField[0]+Ur[1]*vectField[1]+Ur[2]*vectField[2];
+ retPtr[1]=Uteta[0]*vectField[0]+Uteta[1]*vectField[1]+Uteta[2]*vectField[2];
+ retPtr[2]=Uz[0]*vectField[0]+Uz[1]*vectField[1]+Uz[2]*vectField[2];
+ }
+ ret->copyStringInfoFrom(*this);
+ return ret.retn();
+}
+
/*!
* Computes the doubly contracted product of every tensor defined by the tuple of \a this
* array contating 6 components.
return ret.retn();
}
+/*!
+ * Elements of \a partOfThis are expected to be included in \a this.
+ * The returned array \a ret is so that this[ret]==partOfThis
+ *
+ * For example, if \a this array contents are [9,10,0,6,4,11,3,8] and if \a partOfThis contains [6,0,11,8]
+ * the return array will contain [3,2,5,7].
+ *
+ * \a this is expected to be a 1 compo allocated array.
+ * \param [in] partOfThis - A 1 compo allocated array
+ * \return - A newly allocated array to be dealed by caller having the same number of tuples than \a partOfThis.
+ * \throw if two same element is present twice in \a this
+ * \throw if an element in \a partOfThis is \b NOT in \a this.
+ */
+DataArrayInt *DataArrayInt::indicesOfSubPart(const DataArrayInt& partOfThis) const
+{
+ if(getNumberOfComponents()!=1 || partOfThis.getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : this and input array must be one component array !");
+ checkAllocated(); partOfThis.checkAllocated();
+ int thisNbTuples(getNumberOfTuples()),nbTuples(partOfThis.getNumberOfTuples());
+ const int *thisPt(begin()),*pt(partOfThis.begin());
+ MCAuto<DataArrayInt> ret(DataArrayInt::New());
+ ret->alloc(nbTuples,1);
+ int *retPt(ret->getPointer());
+ std::map<int,int> m;
+ for(int i=0;i<thisNbTuples;i++,thisPt++)
+ m[*thisPt]=i;
+ if(m.size()!=thisNbTuples)
+ throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : some elements appears more than once !");
+ for(int i=0;i<nbTuples;i++,retPt++,pt++)
+ {
+ std::map<int,int>::const_iterator it(m.find(*pt));
+ if(it!=m.end())
+ *retPt=(*it).second;
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::indicesOfSubPart : At pos #" << i << " of input array value is " << *pt << " not in this !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ return ret.retn();
+}
+
void DataArrayInt::aggregate(const DataArrayInt *other)
{
if(!other)