//
#include "MEDCouplingCMesh.hxx"
+#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingMemArray.hxx"
#include "MEDCouplingFieldDouble.hxx"
for(int l=0;l<spaceDim;l++)
{
int val=1;
- for(int p=l;p<spaceDim-1;p++)
+ for(int p=0;p<spaceDim-l-1;p++)
val*=getCoordsAt(p)->getNbOfElems()-1;
res[spaceDim-l-1]=val;
}
for(int l=0;l<spaceDim;l++)
{
int val=1;
- for(int p=l;p<spaceDim-1;p++)
+ for(int p=0;p<spaceDim-l-1;p++)
val*=getCoordsAt(p)->getNbOfElems();
res[spaceDim-l-1]=val;
}
void MEDCouplingCMesh::getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const
{
- //not implemented yet
+ int tmp[3];
+ int spaceDim=getSpaceDimension();
+ getSplitNodeValues(tmp);
+ const DataArrayDouble *tabs[3]={getCoordsAt(0),getCoordsAt(1),getCoordsAt(2)};
+ int tmp2[3];
+ getPosFromId(nodeId,spaceDim,tmp,tmp2);
+ for(int j=0;j<spaceDim;j++)
+ if(tabs[j])
+ coo.push_back(tabs[j]->getConstPointer()[tmp2[j]]);
}
std::string MEDCouplingCMesh::simpleRepr() const
declareAsNew();
}
+MEDCouplingUMesh *MEDCouplingCMesh::buildUnstructured() const
+{
+ int spaceDim=getSpaceDimension();
+ MEDCouplingUMesh *ret=MEDCouplingUMesh::New(getName(),spaceDim);
+ DataArrayDouble *coords=getCoordinatesAndOwner();
+ ret->setCoords(coords);
+ coords->decrRef();
+ switch(spaceDim)
+ {
+ case 1:
+ fill1DUnstructuredMesh(ret);
+ break;
+ case 2:
+ fill2DUnstructuredMesh(ret);
+ break;
+ case 3:
+ fill3DUnstructuredMesh(ret);
+ break;
+ default:
+ throw INTERP_KERNEL::Exception("MEDCouplingCMesh::buildUnstructured : big problem spacedim must be in 1,2 or 3 !");
+ };
+ return ret;
+}
+
MEDCouplingMesh *MEDCouplingCMesh::buildPart(const int *start, const int *end) const
{
- //not implemented yet !
- return 0;
+ MEDCouplingUMesh *um=buildUnstructured();
+ MEDCouplingMesh *ret=um->buildPart(start,end);
+ um->decrRef();
+ return ret;
}
MEDCouplingMesh *MEDCouplingCMesh::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const
{
- //not implemented yet !
- return 0;
+ MEDCouplingUMesh *um=buildUnstructured();
+ MEDCouplingMesh *ret=um->buildPartAndReduceNodes(start,end,arr);
+ um->decrRef();
+ return ret;
}
void MEDCouplingCMesh::getBoundingBox(double *bbox) const
{
- //not implemented yet !
+ int dim=getSpaceDimension();
+ int j=0;
+ for (int idim=0; idim<dim; idim++)
+ {
+ DataArrayDouble *c=getCoordsAt(idim);
+ if(c)
+ {
+ const double *coords=c->getConstPointer();
+ int nb=c->getNbOfElems();
+ bbox[2*j]=coords[0];
+ bbox[2*j+1]=coords[nb-1];
+ j++;
+ }
+ }
}
MEDCouplingFieldDouble *MEDCouplingCMesh::getMeasureField(bool isAbs) const
{
- //not implemented yet !
- return 0;
+ std::string name="MeasureOfMesh_";
+ name+=getName();
+ int nbelem=getNumberOfCells();
+ MEDCouplingFieldDouble *field=MEDCouplingFieldDouble::New(ON_CELLS);
+ field->setName(name.c_str());
+ DataArrayDouble* array=DataArrayDouble::New();
+ array->alloc(nbelem,1);
+ double *area_vol=array->getPointer();
+ field->setArray(array) ;
+ array->decrRef();
+ field->setMesh(const_cast<MEDCouplingCMesh *>(this));
+ int tmp[3];
+ getSplitCellValues(tmp);
+ int dim=getSpaceDimension();
+ const double **thisArr=new const double *[dim];
+ const DataArrayDouble *thisArr2[3]={_x_array,_y_array,_z_array};
+ for(int i=0;i<dim;i++)
+ thisArr[i]=thisArr2[i]->getConstPointer();
+ for(int icell=0;icell<nbelem;icell++)
+ {
+ int tmp2[3];
+ getPosFromId(icell,dim,tmp,tmp2);
+ area_vol[icell]=1.;
+ for(int i=0;i<dim;i++)
+ area_vol[icell]*=thisArr[i][tmp2[i]+1]-thisArr[i][tmp2[i]];
+ }
+ delete [] thisArr;
+ return field;
}
MEDCouplingFieldDouble *MEDCouplingCMesh::getMeasureFieldOnNode(bool isAbs) const
int MEDCouplingCMesh::getCellContainingPoint(const double *pos, double eps) const
{
- //not implemented yet !
- return -1;
+ int dim=getSpaceDimension();
+ int ret=0;
+ int coeff=1;
+ for(int i=0;i<dim;i++)
+ {
+ const double *d=getCoordsAt(i)->getConstPointer();
+ int nbOfNodes=getCoordsAt(i)->getNbOfElems();
+ double ref=pos[i];
+ const double *w=std::find_if(d,d+nbOfNodes,std::bind2nd(std::greater<double>(),ref));
+ int w2=std::distance(d,w);
+ if(w2<nbOfNodes && w2!=0)
+ {
+ ret+=coeff*(w2-1);
+ coeff*=nbOfNodes-1;
+ }
+ else
+ return -1;
+ }
+ return ret;
}
void MEDCouplingCMesh::rotate(const double *center, const double *vector, double angle)
void MEDCouplingCMesh::scale(const double *point, double factor)
{
- //not implemented yet !
- throw INTERP_KERNEL::Exception("Not implemented yet !");
+ for(int i=0;i<3;i++)
+ {
+ DataArrayDouble *c=getCoordsAt(i);
+ if(c)
+ {
+ double *coords=c->getPointer();
+ int lgth=c->getNbOfElems();
+ std::transform(coords,coords+lgth,coords,std::bind2nd(std::minus<double>(),point[i]));
+ std::transform(coords,coords+lgth,coords,std::bind2nd(std::multiplies<double>(),factor));
+ std::transform(coords,coords+lgth,coords,std::bind2nd(std::plus<double>(),point[i]));
+ c->declareAsNew();
+ }
+ }
+ updateTime();
}
MEDCouplingMesh *MEDCouplingCMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
throw INTERP_KERNEL::Exception("Functionnality of renumbering cell not available for CMesh !");
}
+void MEDCouplingCMesh::fill1DUnstructuredMesh(MEDCouplingUMesh *m) const
+{
+ const DataArrayDouble *c=getCoordsAt(0);
+ int nbOfCells=c->getNbOfElems()-1;
+ DataArrayInt *connI=DataArrayInt::New();
+ connI->alloc(nbOfCells+1,1);
+ int *ci=connI->getPointer();
+ DataArrayInt *conn=DataArrayInt::New();
+ conn->alloc(3*nbOfCells,1);
+ ci[0]=0;
+ int *cp=conn->getPointer();
+ for(int i=0;i<nbOfCells;i++)
+ {
+ cp[3*i]=(int)INTERP_KERNEL::NORM_SEG2;
+ cp[3*i+1]=i;
+ cp[3*i+2]=i+1;
+ ci[i+1]=3*(i+1);
+ }
+ m->setConnectivity(conn,connI,true);
+ conn->decrRef();
+ connI->decrRef();
+}
+
+void MEDCouplingCMesh::fill2DUnstructuredMesh(MEDCouplingUMesh *m) const
+{
+ const DataArrayDouble *c1=getCoordsAt(0);
+ const DataArrayDouble *c2=getCoordsAt(1);
+ int n1=c1->getNbOfElems()-1;
+ int n2=c2->getNbOfElems()-1;
+ DataArrayInt *connI=DataArrayInt::New();
+ connI->alloc(n1*n2+1,1);
+ int *ci=connI->getPointer();
+ DataArrayInt *conn=DataArrayInt::New();
+ conn->alloc(5*n1*n2,1);
+ ci[0]=0;
+ int *cp=conn->getPointer();
+ int pos=0;
+ for(int j=0;j<n2;j++)
+ for(int i=0;i<n1;i++,pos++)
+ {
+ cp[5*pos]=(int)INTERP_KERNEL::NORM_QUAD4;
+ cp[5*pos+1]=i+1+j*(n1+1);
+ cp[5*pos+2]=i+j*(n1+1);
+ cp[5*pos+3]=i+(j+1)*(n1+1);
+ cp[5*pos+4]=i+1+(j+1)*(n1+1);
+ ci[pos+1]=5*(pos+1);
+ }
+ m->setConnectivity(conn,connI,true);
+ conn->decrRef();
+ connI->decrRef();
+}
+
+void MEDCouplingCMesh::fill3DUnstructuredMesh(MEDCouplingUMesh *m) const
+{
+ const DataArrayDouble *c1=getCoordsAt(0);
+ const DataArrayDouble *c2=getCoordsAt(1);
+ const DataArrayDouble *c3=getCoordsAt(2);
+ int n1=c1->getNbOfElems()-1;
+ int n2=c2->getNbOfElems()-1;
+ int n3=c3->getNbOfElems()-1;
+ DataArrayInt *connI=DataArrayInt::New();
+ connI->alloc(n1*n2*n3+1,1);
+ int *ci=connI->getPointer();
+ DataArrayInt *conn=DataArrayInt::New();
+ conn->alloc(9*n1*n2*n3,1);
+ ci[0]=0;
+ int *cp=conn->getPointer();
+ int pos=0;
+ for(int k=0;k<n3;k++)
+ for(int j=0;j<n2;j++)
+ for(int i=0;i<n1;i++,pos++)
+ {
+ cp[9*pos]=(int)INTERP_KERNEL::NORM_HEXA8;
+ double tmp=(n1+1)*(n2+1);
+ cp[9*pos+1]=i+1+j*(n1+1)+k*tmp;
+ cp[9*pos+2]=i+j*(n1+1)+k*tmp;
+ cp[9*pos+3]=i+(j+1)*(n1+1)+k*tmp;
+ cp[9*pos+4]=i+1+(j+1)*(n1+1)+k*tmp;
+ cp[9*pos+5]=i+1+j*(n1+1)+(k+1)*tmp;
+ cp[9*pos+6]=i+j*(n1+1)+(k+1)*tmp;
+ cp[9*pos+7]=i+(j+1)*(n1+1)+(k+1)*tmp;
+ cp[9*pos+8]=i+1+(j+1)*(n1+1)+(k+1)*tmp;
+ ci[pos+1]=9*(pos+1);
+ }
+ m->setConnectivity(conn,connI,true);
+ conn->decrRef();
+ connI->decrRef();
+}
+
void MEDCouplingCMesh::getTinySerializationInformation(std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const
{
tinyInfo.clear();
namespace ParaMEDMEM
{
class DataArrayDouble;
+ class MEDCouplingUMesh;
class MEDCOUPLING_EXPORT MEDCouplingCMesh : public MEDCouplingMesh
{
DataArrayDouble *coordsY=0,
DataArrayDouble *coordsZ=0);
// tools
+ MEDCouplingUMesh *buildUnstructured() const;
MEDCouplingMesh *buildPart(const int *start, const int *end) const;
MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const;
void getBoundingBox(double *bbox) const;
DataArrayDouble *getCoordinatesAndOwner() const;
DataArrayDouble *getBarycenterAndOwner() const;
void renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception);
+ void fill1DUnstructuredMesh(MEDCouplingUMesh *m) const;
+ void fill2DUnstructuredMesh(MEDCouplingUMesh *m) const;
+ void fill3DUnstructuredMesh(MEDCouplingUMesh *m) const;
//some useful methods
void getSplitCellValues(int *res) const;
void getSplitNodeValues(int *res) const;
throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !");
}
+void MEDCouplingFieldDiscretization::renumberEntitiesFromO2NArr(const int *old2NewPtr, DataArrayDouble *arr, const char *msg)
+{
+ int oldNbOfElems=arr->getNumberOfTuples();
+ int nbOfComp=arr->getNumberOfComponents();
+ int newNbOfTuples=(*std::max_element(old2NewPtr,old2NewPtr+oldNbOfElems))+1;
+ DataArrayDouble *arrCpy=arr->deepCopy();
+ const double *ptSrc=arrCpy->getConstPointer();
+ arr->reAlloc(newNbOfTuples);
+ double *ptToFill=arr->getPointer();
+ std::fill(ptToFill,ptToFill+nbOfComp*newNbOfTuples,std::numeric_limits<double>::max());
+ for(int i=0;i<oldNbOfElems;i++)
+ {
+ int newNb=old2NewPtr[i];
+ if(newNb>=0)//if newNb<0 the node is considered as out.
+ {
+ if(std::find_if(ptToFill+newNb*nbOfComp,ptToFill+(newNb+1)*nbOfComp,std::bind2nd(std::not_equal_to<double>(),std::numeric_limits<double>::max()))
+ ==ptToFill+(newNb+1)*nbOfComp)
+ std::copy(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp);
+ else
+ {
+ if(!std::equal(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp))
+ {
+ arrCpy->decrRef();
+ std::ostringstream oss;
+ oss << msg << " " << i << " and " << std::find(old2NewPtr,old2NewPtr+i,newNb)-old2NewPtr
+ << " have been merged and " << msg << " field on them are different !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ }
+ }
+ arrCpy->decrRef();
+}
+
MEDCouplingFieldDiscretization::~MEDCouplingFieldDiscretization()
{
}
{
}
+void MEDCouplingFieldDiscretizationP0::renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const
+{
+ renumberEntitiesFromO2NArr(old2New,arr,"Cell");
+}
+
/*!
* This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end).
* @param di is an array returned that specifies entity ids (here cells ids) in mesh 'mesh' of entity in returned submesh.
void MEDCouplingFieldDiscretizationP1::renumberValuesOnNodes(const int *old2NewPtr, DataArrayDouble *arr) const
{
- int oldNbOfElems=arr->getNumberOfTuples();
- int nbOfComp=arr->getNumberOfComponents();
- int newNbOfTuples=(*std::max_element(old2NewPtr,old2NewPtr+oldNbOfElems))+1;
- DataArrayDouble *arrCpy=arr->deepCopy();
- const double *ptSrc=arrCpy->getConstPointer();
- arr->reAlloc(newNbOfTuples);
- double *ptToFill=arr->getPointer();
- std::fill(ptToFill,ptToFill+nbOfComp*newNbOfTuples,std::numeric_limits<double>::max());
- for(int i=0;i<oldNbOfElems;i++)
- {
- int newNb=old2NewPtr[i];
- if(std::find_if(ptToFill+newNb*nbOfComp,ptToFill+(newNb+1)*nbOfComp,std::bind2nd(std::not_equal_to<double>(),std::numeric_limits<double>::max()))
- ==ptToFill+(newNb+1)*nbOfComp)
- std::copy(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp);
- else
- {
- if(!std::equal(ptSrc+i*nbOfComp,ptSrc+(i+1)*nbOfComp,ptToFill+newNb*nbOfComp))
- {
- arrCpy->decrRef();
- std::ostringstream oss;
- oss << "Node " << i << " and " << std::find(old2NewPtr,old2NewPtr+i,newNb)-old2NewPtr
- << " have been merged and nodal field on them are different !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- }
- arrCpy->decrRef();
+ renumberEntitiesFromO2NArr(old2NewPtr,arr,"Node");
+}
+
+/*!
+ * Nothing to do it's not a bug.
+ */
+void MEDCouplingFieldDiscretizationP1::renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const
+{
}
/*!
MEDCouplingMesh *MEDCouplingFieldDiscretizationP1::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const
{
MEDCouplingMesh *ret=mesh->buildPartAndReduceNodes(start,end,di);
+ DataArrayInt *di2=di->invertArrayO2N2N2O(ret->getNumberOfNodes());
+ di->decrRef();
+ di=di2;
return ret;
}
{
}
+void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const
+{
+ throw INTERP_KERNEL::Exception("Not implemented yet !");
+}
+
void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception)
{
{
}
+void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const
+{
+ throw INTERP_KERNEL::Exception("Not implemented yet !");
+}
+
MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other):MEDCouplingFieldDiscretization(other)
{
}
virtual void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const = 0;
virtual MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const = 0;
virtual void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const = 0;
+ virtual void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const = 0;
virtual void getSerializationIntArray(DataArrayInt *& arr) const;
virtual void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
virtual void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
virtual ~MEDCouplingFieldDiscretization();
protected:
MEDCouplingFieldDiscretization();
+ static void renumberEntitiesFromO2NArr(const int *old2NewPtr, DataArrayDouble *arr, const char *msg);
protected:
double _precision;
static const double DFLT_PRECISION;
void getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const;
void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const;
void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const;
+ void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const;
MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const;
public:
static const char REPR[];
void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const;
MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const;
void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const;
+ void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const;
public:
static const char REPR[];
static const TypeOfField TYPE;
void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const;
MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const;
void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const;
+ void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const;
void setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception);
void setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector<double>& refCoo,
void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const;
MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const;
void renumberValuesOnNodes(const int *old2New, DataArrayDouble *arr) const;
+ void renumberValuesOnCells(const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const;
protected:
MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other);
public:
//
#include "MEDCouplingFieldDouble.hxx"
-#include "MEDCouplingPointSet.hxx"
+#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingTimeDiscretization.hxx"
#include "MEDCouplingFieldDiscretization.hxx"
#include "MEDCouplingAutoRefCountObjectPtr.hxx"
std::vector<DataArrayDouble *> arrays;
_time_discr->getArrays(arrays);
for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
- _type->renumberValuesOnNodes(old2NewBg,*iter);
+ if(*iter)
+ _type->renumberValuesOnNodes(old2NewBg,*iter);
}
/*!
return ret;
}
+/*!
+ * This method is an extension of ParaMEDMEM::MEDCouplingFieldDouble::getMaxValue method because the returned
+ * value is the same but this method also returns to you a tupleIds object which the caller have the responsibility
+ * to deal with. The main difference is that the returned tupleIds is those corresponding the first set array.
+ * If you have more than one array set (in LINEAR_TIME instance for example) only the first not null array will be used
+ * to compute tupleIds.
+ */
+double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ double ret=-std::numeric_limits<double>::max();
+ bool isExistingArr=false;
+ tupleIds=0;
+ for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
+ {
+ if(*iter)
+ {
+ isExistingArr=true;
+ DataArrayInt *tmp;
+ ret=std::max(ret,(*iter)->getMaxValue2(tmp));
+ if(!tupleIds)
+ tupleIds=tmp;
+ else
+ tmp->decrRef();
+ }
+ }
+ if(!isExistingArr)
+ throw INTERP_KERNEL::Exception("getMaxValue2 : No arrays defined !");
+ return ret;
+}
+
/*!
* This method returns the min value in 'this'. 'This' is expected to be a field with exactly \b one component. If not an exception will be thrown.
* To getMinValue on vector field applyFunc is needed before. This method looks only on all arrays stored in 'this->_time_discr'.
return ret;
}
+/*!
+ * This method is an extension of ParaMEDMEM::MEDCouplingFieldDouble::getMinValue method because the returned
+ * value is the same but this method also returns to you a tupleIds object which the caller have the responsibility
+ * to deal with. The main difference is that the returned tupleIds is those corresponding the first set array.
+ * If you have more than one array set (in LINEAR_TIME instance for example) only the first not null array will be used
+ * to compute tupleIds.
+ */
+double MEDCouplingFieldDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ double ret=-std::numeric_limits<double>::max();
+ bool isExistingArr=false;
+ tupleIds=0;
+ for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
+ {
+ if(*iter)
+ {
+ isExistingArr=true;
+ DataArrayInt *tmp;
+ ret=std::max(ret,(*iter)->getMinValue2(tmp));
+ if(!tupleIds)
+ tupleIds=tmp;
+ else
+ tmp->decrRef();
+ }
+ }
+ if(!isExistingArr)
+ throw INTERP_KERNEL::Exception("getMinValue2 : No arrays defined !");
+ return ret;
+}
+
/*!
* This method returns the average value in 'this'. 'This' is expected to be a field with exactly \b one component. If not an exception will be thrown.
* To getAverageValue on vector field applyFunc is needed before. This method looks only \b default array \b and \b only \b default.
_time_discr->applyLin(a,b,compoId);
}
+/*!
+ * This method sets 'this' to a uniform scalar field with one component.
+ * All tuples will have the same value 'value'.
+ * An exception is thrown if no underlying mesh is defined.
+ */
+MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) throw(INTERP_KERNEL::Exception)
+{
+ if(!_mesh)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !");
+ int nbOfTuple=_type->getNumberOfTuples(_mesh);
+ _time_discr->setUniformValue(nbOfTuple,value);
+ return *this;
+}
+
+/*!
+ * This method is very similar to this one MEDCouplingMesh::fillFromAnalytic.
+ * The main difference is that the field as been started to be constructed here.
+ * An exception is throw if no underlying mesh is set before the call of this method.
+ */
+void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate func) throw(INTERP_KERNEL::Exception)
+{
+ if(!_mesh)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
+ _time_discr->fillFromAnalytic(loc,nbOfComp,func);
+}
+
+/*!
+ * This method is very similar to this one MEDCouplingMesh::fillFromAnalytic.
+ * The main difference is that the field as been started to be constructed here.
+ * An exception is throw if no underlying mesh is set before the call of this method.
+ */
+void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception)
+{
+ if(!_mesh)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
+ _time_discr->fillFromAnalytic(loc,nbOfComp,func);
+}
+
/*!
* Applyies the function specified by pointer 'func' on each tuples on all arrays contained in _time_discr.
* If '*func' returns false during one evaluation an exception will be thrown.
/*!
* Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
* The field will contain exactly the same number of components after the call.
- * Use is not warranted and can cause SIGSEGV !
+ * Use is not warranted for the moment !
*/
void MEDCouplingFieldDouble::applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception)
{
_time_discr->applyFuncFast32(func);
}
+/*!
+ * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
+ * The field will contain exactly the same number of components after the call.
+ * Use is not warranted for the moment !
+ */
void MEDCouplingFieldDouble::applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception)
{
_time_discr->applyFuncFast64(func);
{
const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
if(!meshC)
- throw INTERP_KERNEL::Exception("Invalid mesh to apply mergeNodes on it !");
+ throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
bool ret;
int ret2;
std::vector<DataArrayDouble *> arrays;
_time_discr->getArrays(arrays);
for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
- _type->renumberValuesOnNodes(arr->getConstPointer(),*iter);
+ if(*iter)
+ _type->renumberValuesOnNodes(arr->getConstPointer(),*iter);
setMesh(meshC2);
return true;
}
+/*!
+ * This method applyies ParaMEDMEM::MEDCouplingPointSet::zipCoords method on 'this->_mesh' that should be set and of type ParaMEDMEM::MEDCouplingPointSet.
+ * If some nodes have disappeared true is returned.
+ */
+bool MEDCouplingFieldDouble::zipCoords() throw(INTERP_KERNEL::Exception)
+{
+ const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
+ if(!meshC)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
+ int oldNbOfNodes=meshC2->getNumberOfNodes();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->zipCoordsTraducer();
+ if(meshC2->getNumberOfNodes()!=oldNbOfNodes)
+ {
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
+ if(*iter)
+ _type->renumberValuesOnNodes(arr->getConstPointer(),*iter);
+ setMesh(meshC2);
+ return true;
+ }
+ return false;
+}
+
+/*!
+ * This method applyies ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer on 'this->_mesh' that should be set and of type ParaMEDMEM::MEDCouplingUMesh.
+ * The semantic of 'compType' is given in ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer method.
+ */
+bool MEDCouplingFieldDouble::zipConnectivity(int compType) throw(INTERP_KERNEL::Exception)
+{
+ const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(_mesh);
+ if(!meshC)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> meshC2((MEDCouplingUMesh *)meshC->deepCpy());
+ int oldNbOfCells=meshC2->getNumberOfCells();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->zipConnectivityTraducer(compType);
+ if(meshC2->getNumberOfCells()!=oldNbOfCells)
+ {
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
+ if(*iter)
+ _type->renumberValuesOnCells(meshC,arr->getConstPointer(),*iter);
+ setMesh(meshC2);
+ return true;
+ }
+ return false;
+}
+
MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
{
MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct();
double accumulate(int compId) const;
void accumulate(double *res) const;
double getMaxValue() const throw(INTERP_KERNEL::Exception);
+ double getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception);
double getMinValue() const throw(INTERP_KERNEL::Exception);
+ double getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception);
double getAverageValue() const throw(INTERP_KERNEL::Exception);
double getWeightedAverageValue() const throw(INTERP_KERNEL::Exception);
double normL1(int compId) const throw(INTERP_KERNEL::Exception);
void getValueOn(const double *spaceLoc, double time, double *res) const throw(INTERP_KERNEL::Exception);
//! \b temporary
void applyLin(double a, double b, int compoId);
+ MEDCouplingFieldDouble &operator=(double value) throw(INTERP_KERNEL::Exception);
+ 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, const char *func);
void applyFunc(const char *func);
void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception);
void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception);
bool mergeNodes(double eps) throw(INTERP_KERNEL::Exception);
+ bool zipCoords() throw(INTERP_KERNEL::Exception);
+ bool zipConnectivity(int compType) throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *determinant() const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *eigenValues() const throw(INTERP_KERNEL::Exception);
void DataArrayDouble::fillWithZero()
{
_mem.fillWithValue(0.);
+ declareAsNew();
+}
+
+void DataArrayDouble::fillWithValue(double val)
+{
+ _mem.fillWithValue(val);
+ declareAsNew();
}
std::string DataArrayDouble::repr() const
declareAsNew();
}
+/*!
+ * This method does \b not change the number of tuples after this call.
+ * Only a permutation is done.
+ */
+void DataArrayDouble::renumberInPlaceR(const int *new2Old)
+{
+ int nbTuples=getNumberOfTuples();
+ int nbOfCompo=getNumberOfComponents();
+ double *tmp=new double[nbTuples*nbOfCompo];
+ const double *iptr=getConstPointer();
+ for(int i=0;i<nbTuples;i++)
+ std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
+ std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
+ delete [] tmp;
+ declareAsNew();
+}
+
/*!
* This method does \b not change the number of tuples after this call.
* Only a permutation is done. If a permutation reduction is needed substr, or selectByTupleId should be used.
double *optr=ret->getPointer();
for(int i=0;i<nbTuples;i++)
std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
+ ret->copyStringInfoFrom(*this);
+ return ret;
+}
+
+/*!
+ * This method does \b not change the number of tuples after this call.
+ * Only a permutation is done.
+ */
+DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const
+{
+ int nbTuples=getNumberOfTuples();
+ int nbOfCompo=getNumberOfComponents();
+ DataArrayDouble *ret=DataArrayDouble::New();
+ ret->alloc(nbTuples,nbOfCompo);
+ ret->copyStringInfoFrom(*this);
+ const double *iptr=getConstPointer();
+ double *optr=ret->getPointer();
+ for(int i=0;i<nbTuples;i++)
+ std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+i*nbOfCompo);
+ ret->copyStringInfoFrom(*this);
+ return ret;
+}
+
+/*!
+ * Idem DataArrayDouble::renumber method except that the number of tuples is reduced.
+ * That is to say that it is expected that newNbOfTuple<this->getNumberOfTuples().
+ * ['old2New','old2New'+getNumberOfTuples()) defines a range containing old to new array. For every negative value in ['old2NewBg','old2New'+getNumberOfTuples()) the corresponding tuple is
+ * omitted.
+ */
+DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newNbOfTuple) const
+{
+ int nbTuples=getNumberOfTuples();
+ int nbOfCompo=getNumberOfComponents();
+ DataArrayDouble *ret=DataArrayDouble::New();
+ ret->alloc(newNbOfTuple,nbOfCompo);
+ const double *iptr=getConstPointer();
+ double *optr=ret->getPointer();
+ for(int i=0;i<nbTuples;i++)
+ {
+ int w=old2New[i];
+ if(w>=0)
+ std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
+ }
+ ret->copyStringInfoFrom(*this);
+ return ret;
+}
+
+/*!
+ * 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.
+ */
+DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
+{
+ DataArrayDouble *ret=DataArrayDouble::New();
+ int nbComp=getNumberOfComponents();
+ ret->alloc(std::distance(new2OldBg,new2OldEnd),nbComp);
+ ret->copyStringInfoFrom(*this);
+ double *pt=ret->getPointer();
+ const double *srcPt=getConstPointer();
+ int i=0;
+ for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
+ std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
+ ret->copyStringInfoFrom(*this);
return ret;
}
return ret;
}
-/*!
- * This method is a generalization of DataArrayDouble::substr method because a not contigous range can be specified here.
- */
-DataArrayDouble *DataArrayDouble::selectByTupleId(const int *start, const int *end) const
-{
- DataArrayDouble *ret=DataArrayDouble::New();
- int nbComp=getNumberOfComponents();
- ret->alloc(std::distance(start,end),nbComp);
- ret->copyStringInfoFrom(*this);
- double *pt=ret->getPointer();
- const double *srcPt=getConstPointer();
- int i=0;
- for(const int *w=start;w!=end;w++,i++)
- std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
- return ret;
-}
-
void DataArrayDouble::setArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
{
if(newArray!=arrayToSet)
return *loc;
}
+double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
+{
+ int tmp;
+ tupleIds=0;
+ double ret=getMaxValue(tmp);
+ tupleIds=getIdsInRange(ret,ret);
+ return ret;
+}
+
double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
{
if(getNumberOfComponents()!=1)
return *loc;
}
+double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
+{
+ int tmp;
+ tupleIds=0;
+ double ret=getMinValue(tmp);
+ tupleIds=getIdsInRange(ret,ret);
+ return ret;
+}
+
double DataArrayDouble::getAverageValue() const throw(INTERP_KERNEL::Exception)
{
if(getNumberOfComponents()!=1)
void DataArrayInt::fillWithZero()
{
_mem.fillWithValue(0);
+ declareAsNew();
+}
+
+void DataArrayInt::fillWithValue(int val)
+{
+ _mem.fillWithValue(val);
+ declareAsNew();
}
std::string DataArrayInt::repr() const
}
/*!
- * This method invert array 'di' that is a conversion map from Old to New node numbering to New to Old node numbering.
+ * This method invert array 'di' that is a conversion map from Old to New numbering to New to Old numbering.
*/
DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const
{
return ret;
}
+/*!
+ * This method invert array 'di' that is a conversion map from New to old numbering to Old to New numbering.
+ */
+DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
+{
+ DataArrayInt *ret=DataArrayInt::New();
+ ret->alloc(oldNbOfElem,1);
+ const int *new2Old=getConstPointer();
+ int *pt=ret->getPointer();
+ std::fill(pt,pt+oldNbOfElem,-1);
+ int nbOfNewElems=getNumberOfTuples();
+ for(int i=0;i<nbOfNewElems;i++)
+ pt[new2Old[i]]=i;
+ return ret;
+}
+
bool DataArrayInt::isEqual(const DataArrayInt& other) const
{
if(!areInfoEquals(other))
declareAsNew();
}
+void DataArrayInt::renumberInPlaceR(const int *new2Old)
+{
+ int nbTuples=getNumberOfTuples();
+ int nbOfCompo=getNumberOfComponents();
+ int *tmp=new int[nbTuples*nbOfCompo];
+ const int *iptr=getConstPointer();
+ for(int i=0;i<nbTuples;i++)
+ std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
+ std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
+ delete [] tmp;
+ declareAsNew();
+}
+
DataArrayInt *DataArrayInt::renumber(const int *old2New) const
{
int nbTuples=getNumberOfTuples();
int *optr=ret->getPointer();
for(int i=0;i<nbTuples;i++)
std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
+ ret->copyStringInfoFrom(*this);
+ return ret;
+}
+
+DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const
+{
+ int nbTuples=getNumberOfTuples();
+ int nbOfCompo=getNumberOfComponents();
+ DataArrayInt *ret=DataArrayInt::New();
+ ret->alloc(nbTuples,nbOfCompo);
+ ret->copyStringInfoFrom(*this);
+ const int *iptr=getConstPointer();
+ int *optr=ret->getPointer();
+ for(int i=0;i<nbTuples;i++)
+ std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+nbOfCompo*i);
+ ret->copyStringInfoFrom(*this);
+ return ret;
+}
+
+/*!
+ * Idem DataArrayDouble::renumber method except that the number of tuples is reduced.
+ * That is to say that it is expected that newNbOfTuple<this->getNumberOfTuples().
+ * ['old2New','old2New'+getNumberOfTuples()) defines a range containing old to new array. For every negative value in ['old2NewBg','old2New'getNumberOfTuples()) the corresponding tuple is
+ * omitted.
+ */
+DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const
+{
+ int nbTuples=getNumberOfTuples();
+ int nbOfCompo=getNumberOfComponents();
+ DataArrayInt *ret=DataArrayInt::New();
+ ret->alloc(newNbOfTuple,nbOfCompo);
+ const int *iptr=getConstPointer();
+ int *optr=ret->getPointer();
+ for(int i=0;i<nbTuples;i++)
+ {
+ int w=old2New[i];
+ if(w>=0)
+ std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
+ }
+ ret->copyStringInfoFrom(*this);
+ return ret;
+}
+
+/*!
+ * This method is a generalization of DataArrayDouble::substr method because a not contigous range can be specified here.
+ * This method is equavalent to DataArrayInt::renumberAndReduce except that convention in input is new2old and \b not old2new.
+ */
+DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
+{
+ DataArrayInt *ret=DataArrayInt::New();
+ int nbComp=getNumberOfComponents();
+ ret->alloc(std::distance(new2OldBg,new2OldEnd),nbComp);
+ ret->copyStringInfoFrom(*this);
+ int *pt=ret->getPointer();
+ const int *srcPt=getConstPointer();
+ int i=0;
+ for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
+ std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
+ ret->copyStringInfoFrom(*this);
return ret;
}
return ret;
}
-
-/*!
- * This method is a generalization of DataArrayDouble::substr method because a not contigous range can be specified here.
- */
-DataArrayInt *DataArrayInt::selectByTupleId(const int *start, const int *end) const
-{
- DataArrayInt *ret=DataArrayInt::New();
- int nbComp=getNumberOfComponents();
- ret->alloc(std::distance(start,end),nbComp);
- ret->copyStringInfoFrom(*this);
- int *pt=ret->getPointer();
- const int *srcPt=getConstPointer();
- int i=0;
- for(const int *w=start;w!=end;w++,i++)
- std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
- return ret;
-}
-
void DataArrayInt::reAlloc(int nbOfTuples)
{
_mem.reAlloc(_info_on_compo.size()*nbOfTuples);
MEDCOUPLING_EXPORT DataArrayDouble *performCpy(bool deepCpy) const;
MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo);
MEDCOUPLING_EXPORT void fillWithZero();
+ MEDCOUPLING_EXPORT void fillWithValue(double val);
MEDCOUPLING_EXPORT std::string repr() const;
MEDCOUPLING_EXPORT std::string reprZip() const;
MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reAlloc(int nbOfTuples);
MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const;
MEDCOUPLING_EXPORT void renumberInPlace(const int *old2New);
+ MEDCOUPLING_EXPORT void renumberInPlaceR(const int *new2Old);
MEDCOUPLING_EXPORT DataArrayDouble *renumber(const int *old2New) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *renumberR(const int *new2Old) const;
+ MEDCOUPLING_EXPORT DataArrayDouble *renumberAndReduce(const int *old2New, int newNbOfTuple) const;
+ 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 *selectByTupleId(const int *start, const int *end) const;
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 void checkNoNullValues() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT double getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT double getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT double getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT double getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT double getAverageValue() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void accumulate(double *res) const;
MEDCOUPLING_EXPORT double accumulate(int compId) const;
MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt& other) const;
MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayInt& other) const;
MEDCOUPLING_EXPORT void fillWithZero();
+ MEDCOUPLING_EXPORT void fillWithValue(int val);
MEDCOUPLING_EXPORT std::string repr() const;
MEDCOUPLING_EXPORT std::string reprZip() const;
MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArr);
MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const;
+ MEDCOUPLING_EXPORT DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const;
//!alloc or useArray should have been called before.
MEDCOUPLING_EXPORT void reAlloc(int nbOfTuples);
MEDCOUPLING_EXPORT DataArrayDouble *convertToDblArr() const;
MEDCOUPLING_EXPORT void renumberInPlace(const int *old2New);
+ MEDCOUPLING_EXPORT void renumberInPlaceR(const int *new2Old);
MEDCOUPLING_EXPORT DataArrayInt *renumber(const int *old2New) const;
+ MEDCOUPLING_EXPORT DataArrayInt *renumberR(const int *new2Old) const;
+ MEDCOUPLING_EXPORT DataArrayInt *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const;
+ MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const;
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 *selectByTupleId(const int *start, const int *end) const;
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; }
#include "MEDCouplingMemArray.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include "MEDCouplingFieldDiscretization.hxx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
-#include "InterpKernelExprParser.hxx"
-
+#include <set>
#include <sstream>
#include <iterator>
*/
MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, FunctionToEvaluate func) const
{
- MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(t);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(t,NO_TIME);
ret->setMesh(this);
- DataArrayDouble *loc=ret->getDiscretization()->getLocalizationOfDiscValues(this);
- DataArrayDouble *array=DataArrayDouble::New();
- int nbOfTuple=loc->getNumberOfTuples();
- int nbCompIn=loc->getNumberOfComponents();
- const double *locPtr=loc->getConstPointer();
- array->alloc(nbOfTuple,nbOfComp);
- double *ptToFill=array->getPointer();
- for(int i=0;i<nbOfTuple;i++)
- {
- if(!func(locPtr+nbCompIn*i,ptToFill))
- {
- std::ostringstream oss; oss << "For tuple # " << i << " localized on (";
- std::copy(locPtr+nbCompIn*i,locPtr+nbCompIn*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed !";
- loc->decrRef();
- array->decrRef();
- ret->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- ptToFill+=nbOfComp;
- }
- loc->decrRef();
- ret->setArray(array);
- array->decrRef();
+ ret->fillFromAnalytic(nbOfComp,func);
+ ret->incrRef();
return ret;
}
*/
MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, const char *func) const
{
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- std::set<std::string> vars;
- expr.getTrueSetOfVars(vars);
- if((int)vars.size()>getSpaceDimension())
- {
- std::ostringstream oss; oss << "The mesh has a spaceDim==" << getSpaceDimension() << " and there are ";
- oss << vars.size() << " variables : ";
- std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- std::vector<std::string> varsV(vars.begin(),vars.end());
- expr.prepareExprEvaluation(varsV);
- //
- MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(t);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(t,NO_TIME);
ret->setMesh(this);
- DataArrayDouble *loc=ret->getDiscretization()->getLocalizationOfDiscValues(this);
- DataArrayDouble *array=DataArrayDouble::New();
- int nbOfTuple=loc->getNumberOfTuples();
- int nbCompIn=loc->getNumberOfComponents();
- const double *locPtr=loc->getConstPointer();
- array->alloc(nbOfTuple,nbOfComp);
- double *ptToFill=array->getPointer();
- for(int i=0;i<nbOfTuple;i++)
- {
- try
- {
- expr.evaluateExpr(nbOfComp,locPtr+nbCompIn*i,ptToFill);
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " localized on (";
- std::copy(locPtr+nbCompIn*i,locPtr+nbCompIn*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed ! " << e.what();
- loc->decrRef();
- array->decrRef();
- ret->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- ptToFill+=nbOfComp;
- }
- loc->decrRef();
- ret->setArray(array);
- array->decrRef();
+ ret->fillFromAnalytic(nbOfComp,func);
+ ret->incrRef();
return ret;
}
}
}
+void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, double value)
+{
+ 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])
+ {
+ arrays[j]->incrRef();
+ arrays[j]->fillWithValue(value);
+ arrays2[j]=arrays[j];
+ }
+ else
+ {
+ DataArrayDouble *tmp=DataArrayDouble::New();
+ tmp->alloc(nbOfTuple,1);
+ tmp->fillWithValue(value);
+ arrays2[j]=tmp;
+ }
+ }
+ std::vector<DataArrayDouble *> arrays3(arrays.size());
+ for(int j=0;j<(int)arrays.size();j++)
+ arrays3[j]=arrays2[j];
+ setArrays(arrays3,0);
+}
+
void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId)
{
std::vector<DataArrayDouble *> arrays;
}
}
+void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, FunctionToEvaluate func) 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++)
+ arrays2[j]=loc->applyFunc(nbOfComp,func);
+ std::vector<DataArrayDouble *> arrays3(arrays.size());
+ for(int j=0;j<(int)arrays.size();j++)
+ arrays3[j]=arrays2[j];
+ setArrays(arrays3,0);
+}
+
+void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, const char *func) 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++)
+ arrays2[j]=loc->applyFunc(nbOfComp,func);
+ std::vector<DataArrayDouble *> arrays3(arrays.size());
+ for(int j=0;j<(int)arrays.size();j++)
+ arrays3[j]=arrays2[j];
+ setArrays(arrays3,0);
+}
+
MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel()
{
}
virtual MEDCouplingTimeDiscretization *maxPerTuple() const 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 applyLin(double a, double b, int compoId);
virtual void applyFunc(int nbOfComp, FunctionToEvaluate func);
virtual void applyFunc(int nbOfComp, const char *func);
virtual void applyFunc(const char *func);
virtual void applyFuncFast32(const char *func);
virtual void applyFuncFast64(const char *func);
-
+ virtual void fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, FunctionToEvaluate func) throw(INTERP_KERNEL::Exception);
+ virtual void fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception);
//
virtual ~MEDCouplingTimeDiscretization();
protected:
DataArrayInt *MEDCouplingUMesh::zipCoordsTraducer()
{
int nbOfNodes=getNumberOfNodes();
- int *traducer=new int[nbOfNodes];
+ DataArrayInt *ret=DataArrayInt::New();
+ ret->alloc(nbOfNodes,1);
+ int *traducer=ret->getPointer();
std::fill(traducer,traducer+nbOfNodes,-1);
int nbOfCells=getNumberOfCells();
const int *connIndex=_nodal_connec_index->getConstPointer();
for(int j=connIndex[i]+1;j<connIndex[i+1];j++)
if(conn[j]>=0)
conn[j]=traducer[conn[j]];
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc(newNbOfNodes,1);
- int *retPtr=ret->getPointer();
- for(int i=0;i<nbOfNodes;i++)
- if(traducer[i]!=-1)
- retPtr[traducer[i]]=i;
- delete [] traducer;
- DataArrayDouble *newCoords=_coords->selectByTupleId(retPtr,retPtr+newNbOfNodes);
+ DataArrayDouble *newCoords=_coords->renumberAndReduce(traducer,newNbOfNodes);
setCoords(newCoords);
newCoords->decrRef();
return ret;
CPPUNIT_TEST( testIsEqualWithoutConsideringStr1 );
CPPUNIT_TEST( testGetNodeIdsOfCell1 );
CPPUNIT_TEST( testGetEdgeRatioField1 );
+ CPPUNIT_TEST( testFillFromAnalytic3 );
+ CPPUNIT_TEST( testFieldDoubleOpEqual1 );
+ CPPUNIT_TEST( testAreaBary3D2 );
+ CPPUNIT_TEST( testGetMeasureFieldCMesh1 );
+ CPPUNIT_TEST( testFieldDoubleZipCoords1 );
+ CPPUNIT_TEST( testFieldDoubleZipConnectivity1 );
+ CPPUNIT_TEST( testDaDoubleRenumber1 );
+ CPPUNIT_TEST( testDaDoubleRenumberAndReduce1 );
+ CPPUNIT_TEST( testDaDoubleRenumberInPlace1 );
+ CPPUNIT_TEST( testDaDoubleSelectByTupleId1 );
+ CPPUNIT_TEST( testDaDoubleRenumberR1 );
+ CPPUNIT_TEST( testDaDoubleRenumberInPlaceR1 );
+ CPPUNIT_TEST( testDaDoubleGetMinMaxValues1 );
+ CPPUNIT_TEST( testFieldDoubleGetMinMaxValues2 );
+ CPPUNIT_TEST( testBuildUnstructuredCMesh1 );
+ CPPUNIT_TEST( testDataArrayIntInvertO2NNO21 );
//MEDCouplingBasicsTestInterp.cxx
CPPUNIT_TEST( test2DInterpP0P0_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_1 );
void testIsEqualWithoutConsideringStr1();
void testGetNodeIdsOfCell1();
void testGetEdgeRatioField1();
+ void testFillFromAnalytic3();
+ void testFieldDoubleOpEqual1();
+ void testAreaBary3D2();
+ void testGetMeasureFieldCMesh1();
+ void testFieldDoubleZipCoords1();
+ void testFieldDoubleZipConnectivity1();
+ void testDaDoubleRenumber1();
+ void testDaDoubleRenumberAndReduce1();
+ void testDaDoubleRenumberInPlace1();
+ void testDaDoubleSelectByTupleId1();
+ void testDaDoubleRenumberR1();
+ void testDaDoubleRenumberInPlaceR1();
+ void testDaDoubleGetMinMaxValues1();
+ void testFieldDoubleGetMinMaxValues2();
+ void testBuildUnstructuredCMesh1();
+ void testDataArrayIntInvertO2NNO21();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
MEDCouplingUMesh *subMesh=dynamic_cast<MEDCouplingUMesh *>(subMeshPtSet);
CPPUNIT_ASSERT(subMesh);
DataArrayInt *traducer=subMesh->zipCoordsTraducer();
- const int expectedTraducer[7]={0,1,3,4,5,7,8};
- CPPUNIT_ASSERT(std::equal(expectedTraducer,expectedTraducer+7,traducer->getPointer()));
+ const int expectedTraducer[9]={0,1,-1,2,3,4,-1,5,6};
+ CPPUNIT_ASSERT(std::equal(expectedTraducer,expectedTraducer+9,traducer->getPointer()));
traducer->decrRef();
CPPUNIT_ASSERT_EQUAL(INTERP_KERNEL::NORM_QUAD4,*subMesh->getAllTypes().begin());
CPPUNIT_ASSERT_EQUAL(2,subMesh->getNumberOfCells());
f1->decrRef();
m1->decrRef();
}
+
+void MEDCouplingBasicsTest::testFillFromAnalytic3()
+{
+ MEDCouplingUMesh *m=build2DTargetMesh_1();
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"y+x"),INTERP_KERNEL::Exception);
+ f1->setMesh(m);
+ f1->setName("myField");
+ f1->fillFromAnalytic(1,"y+x");
+ f1->checkCoherency();
+ CPPUNIT_ASSERT(std::string(f1->getName())=="myField");
+ CPPUNIT_ASSERT(f1->getTypeOfField()==ON_CELLS);
+ CPPUNIT_ASSERT(f1->getTimeDiscretization()==ONE_TIME);
+ CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
+ double values1[5]={-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9};
+ const double *tmp=f1->getArray()->getConstPointer();
+ std::transform(tmp,tmp+5,values1,values1,std::minus<double>());
+ std::transform(values1,values1+5,values1,std::ptr_fun<double,double>(fabs));
+ double max=*std::max_element(values1,values1+5);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
+ f1->decrRef();
+ //
+ f1=MEDCouplingFieldDouble::New(ON_NODES,CONST_ON_TIME_INTERVAL);
+ f1->setMesh(m);
+ f1->setEndTime(1.2,3,4);
+ f1->fillFromAnalytic(1,"y+2*x");
+ f1->checkCoherency();
+ CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
+ CPPUNIT_ASSERT(f1->getTimeDiscretization()==CONST_ON_TIME_INTERVAL);
+ CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
+ double values2[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
+ tmp=f1->getArray()->getConstPointer();
+ std::transform(tmp,tmp+9,values2,values2,std::minus<double>());
+ std::transform(values2,values2+9,values2,std::ptr_fun<double,double>(fabs));
+ max=*std::max_element(values2,values2+9);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
+ f1->decrRef();
+ f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
+ f1->setMesh(m);
+ f1->setEndTime(1.2,3,4);
+ f1->fillFromAnalytic(1,"2.*x+y");
+ f1->checkCoherency();
+ CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
+ CPPUNIT_ASSERT(f1->getTimeDiscretization()==LINEAR_TIME);
+ CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
+ tmp=f1->getArray()->getConstPointer();
+ double values2Bis[9]={-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1};
+ double values2BisBis[9];
+ std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
+ std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
+ max=*std::max_element(values2BisBis,values2BisBis+9);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
+ tmp=f1->getEndArray()->getConstPointer();
+ std::transform(tmp,tmp+9,values2Bis,values2BisBis,std::minus<double>());
+ std::transform(values2,values2+9,values2BisBis,std::ptr_fun<double,double>(fabs));
+ max=*std::max_element(values2BisBis,values2BisBis+9);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
+ f1->decrRef();
+ //
+ f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
+ f1->setMesh(m);
+ f1->fillFromAnalytic(2,"(x+y)*IVec+2*(x+y)*JVec");
+ f1->checkCoherency();
+ CPPUNIT_ASSERT(f1->getTypeOfField()==ON_NODES);
+ CPPUNIT_ASSERT(f1->getTimeDiscretization()==NO_TIME);
+ CPPUNIT_ASSERT_EQUAL(2,f1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
+ double values3[18]={-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8};
+ tmp=f1->getArray()->getConstPointer();
+ std::transform(tmp,tmp+18,values3,values3,std::minus<double>());
+ std::transform(values3,values3+18,values3,std::ptr_fun<double,double>(fabs));
+ max=*std::max_element(values3,values3+18);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.,max,1.e-12);
+ double values4[2];
+ f1->accumulate(values4);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(3.6,values4[0],1.e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(7.2,values4[1],1.e-12);
+ f1->integral(true,values4);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5,values4[0],1.e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,values4[1],1.e-12);
+ f1->decrRef();
+ //
+ f1=MEDCouplingFieldDouble::New(ON_NODES,NO_TIME);
+ f1->setMesh(m);
+ CPPUNIT_ASSERT_THROW(f1->fillFromAnalytic(1,"1./(x-0.2)"),INTERP_KERNEL::Exception);
+ //
+ m->decrRef();
+ f1->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldDoubleOpEqual1()
+{
+ MEDCouplingUMesh *m=build2DTargetMesh_1();
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ CPPUNIT_ASSERT_THROW((*f1)=0.07,INTERP_KERNEL::Exception);
+ f1->setMesh(m);
+ (*f1)=0.07;
+ f1->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
+ for(int i=0;i<5;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.07,f1->getIJ(i,0),1e-16);
+ (*f1)=0.09;
+ f1->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,f1->getNumberOfTuples());
+ for(int i=0;i<5;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.09,f1->getIJ(i,0),1e-16);
+ f1->decrRef();
+ //
+ f1=MEDCouplingFieldDouble::New(ON_NODES,LINEAR_TIME);
+ f1->setEndTime(4.5,2,3);
+ f1->setMesh(m);
+ (*f1)=0.08;
+ f1->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(1,f1->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(9,f1->getNumberOfTuples());
+ for(int i=0;i<9;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getIJ(i,0),1e-16);
+ CPPUNIT_ASSERT_EQUAL(1,f1->getEndArray()->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(9,f1->getEndArray()->getNumberOfTuples());
+ for(int i=0;i<9;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.08,f1->getEndArray()->getIJ(i,0),1e-16);
+ f1->decrRef();
+ //
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testAreaBary3D2()
+{
+ const double coordsForHexa8[24]={
+ -75.45749305371, 180.95495078401, 39.515472018008,
+ -9.755591679144, 23.394927935279, 5.108794294848,
+ 14.337630157832, 61.705351002702, 160.42422501908,
+ -27.273893776752, 167.567731083961, 192.830034145464,
+ //
+ 99.857193154796,264.499264735586,-8.287335493412,
+ 144.939882761126,156.38626563134,-31.896173894226,
+ 161.34096835726,182.4654895809,73.832387065572,
+ 132.680430393685,255.37973247196,96.15235602819
+ };
+ const double volHexa8=3258520.29637466;
+ const double baryHexa8[3]={43.925705821778, 155.31893955289, 65.874418109644};
+
+ const double coordsForPenta6[18]={
+ -68.199829618726,178.938498373416,62.608505919588,
+ 8.461744647847,76.653979804423,165.00018874933,
+ -27.273893776752,167.567731083961,192.830034145464,
+ //
+ 106.586501038965,262.629609408327,13.124533008813,
+ 155.465082847275,197.414118382622,78.408350795821,
+ 132.680430393685,255.37973247196,96.15235602819
+ };
+ const double volPenta6=944849.868507338;
+ const double baryPenta6[3]={39.631002313543,182.692711783428,106.98540473964};
+
+ const double coordsForPyra5[15]={
+ 132.680430393685,255.37973247196,96.15235602819,
+ -27.273893776752,167.567731083961,192.830034145464,
+ 8.461744647847,76.653979804423,165.00018874933,
+ 155.465082847275,197.414118382622,78.408350795821,
+ //
+ -68.199829618726,178.938498373416,62.608505919588
+ };
+ const double volPyra5=756943.92980254;
+ const double baryPyra5[3]={29.204294116618,172.540129749156,118.01035951483};
+ MEDCouplingUMesh *mesh=MEDCouplingUMesh::New("Bary3D2",3);
+ DataArrayDouble *coo=DataArrayDouble::New();
+ coo->alloc(19,3);
+ double *tmp=std::copy(coordsForHexa8,coordsForHexa8+24,coo->getPointer());
+ tmp=std::copy(coordsForPenta6,coordsForPenta6+18,tmp);
+ std::copy(coordsForPyra5,coordsForPyra5+15,tmp);
+ mesh->setCoords(coo);
+ coo->decrRef();
+ //
+ int tmpConn[8]={0,1,2,3,4,5,6,7};
+ mesh->allocateCells(3);
+ mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,tmpConn);
+ std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),8));
+ mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,tmpConn);
+ std::transform(tmpConn,tmpConn+8,tmpConn,std::bind2nd(std::plus<int>(),6));
+ mesh->insertNextCell(INTERP_KERNEL::NORM_PYRA5,5,tmpConn);
+ mesh->finishInsertingCells();
+ mesh->checkCoherency();
+ bool isMerged;
+ int newNebOfNodes;
+ DataArrayInt *da=mesh->mergeNodes(1e-7,isMerged,newNebOfNodes);
+ da->decrRef();
+ CPPUNIT_ASSERT_EQUAL(12,newNebOfNodes);
+ MEDCouplingFieldDouble *vols=mesh->getMeasureField(true);
+ CPPUNIT_ASSERT_EQUAL(3,vols->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,vols->getNumberOfComponents());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(volHexa8,vols->getIJ(0,0),1e-6);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(volPenta6,vols->getIJ(1,0),1e-7);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(volPyra5,vols->getIJ(2,0),1e-7);
+ vols->decrRef();
+ DataArrayDouble *bary=mesh->getBarycenterAndOwner();
+ CPPUNIT_ASSERT_EQUAL(3,bary->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,bary->getNumberOfComponents());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[0],bary->getIJ(0,0),1e-11);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[1],bary->getIJ(0,1),1e-11);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(baryHexa8[2],bary->getIJ(0,2),1e-11);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[0],bary->getIJ(1,0),1e-11);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[1],bary->getIJ(1,1),1e-11);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPenta6[2],bary->getIJ(1,2),1e-11);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[0],bary->getIJ(2,0),1e-11);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[1],bary->getIJ(2,1),1e-11);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(baryPyra5[2],bary->getIJ(2,2),1e-11);
+ bary->decrRef();
+ //
+ mesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::testGetMeasureFieldCMesh1()
+{
+ MEDCouplingCMesh *m=MEDCouplingCMesh::New();
+ DataArrayDouble *da=DataArrayDouble::New();
+ const double discX[4]={2.3,3.4,5.8,10.2};
+ const double discY[3]={12.3,23.4,45.8};
+ const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
+ da->alloc(4,1);
+ std::copy(discX,discX+4,da->getPointer());
+ m->setCoordsAt(0,da);
+ da->decrRef();
+ m->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(4,m->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(3,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(1,m->getSpaceDimension());
+ MEDCouplingFieldDouble *f=m->getMeasureField(true);
+ CPPUNIT_ASSERT_EQUAL(3,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
+ const double expected1[3]={1.1,2.4,4.4};
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(i,0),1e-12);
+ f->decrRef();
+ DataArrayDouble *coords=m->getCoordinatesAndOwner();
+ CPPUNIT_ASSERT_EQUAL(4,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
+ for(int i=0;i<4;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(discX[i],coords->getIJ(i,0),1e-12);
+ coords->decrRef();
+ coords=m->getBarycenterAndOwner();
+ CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,coords->getNumberOfComponents());
+ const double expected1_3[3]={2.85,4.6,8.};
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1_3[i],coords->getIJ(i,0),1e-12);
+ coords->decrRef();
+ //
+ da=DataArrayDouble::New();
+ da->alloc(3,1);
+ std::copy(discY,discY+3,da->getPointer());
+ m->setCoordsAt(1,da);
+ da->decrRef();
+ m->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(12,m->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(6,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(2,m->getSpaceDimension());
+ f=m->getMeasureField(true);
+ CPPUNIT_ASSERT_EQUAL(6,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
+ const double expected2[6]={12.21,26.64,48.84,24.64,53.76,98.56};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(i,0),1e-12);
+ f->decrRef();
+ coords=m->getCoordinatesAndOwner();
+ CPPUNIT_ASSERT_EQUAL(12,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
+ const double expected2_2[24]={2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8};
+ for(int i=0;i<24;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_2[i],coords->getIJ(0,i),1e-12);
+ coords->decrRef();
+ coords=m->getBarycenterAndOwner();
+ CPPUNIT_ASSERT_EQUAL(6,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,coords->getNumberOfComponents());
+ const double expected2_3[12]={2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6};
+ for(int i=0;i<12;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2_3[i],coords->getIJ(0,i),1e-12);
+ coords->decrRef();
+ //
+ da=DataArrayDouble::New();
+ da->alloc(5,1);
+ std::copy(discZ,discZ+5,da->getPointer());
+ m->setCoordsAt(2,da);
+ da->decrRef();
+ m->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(60,m->getNumberOfNodes());
+ CPPUNIT_ASSERT_EQUAL(24,m->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(3,m->getSpaceDimension());
+ f=m->getMeasureField(true);
+ CPPUNIT_ASSERT_EQUAL(24,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents());
+ const double expected3[24]={23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224};
+ for(int i=0;i<24;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f->getIJ(i,0),1e-12);
+ f->decrRef();
+ coords=m->getCoordinatesAndOwner();
+ CPPUNIT_ASSERT_EQUAL(60,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
+ const double expected3_2[180]={
+ 2.3,12.3,-0.7, 3.4,12.3,-0.7, 5.8,12.3,-0.7, 10.2,12.3,-0.7, 2.3,23.4,-0.7, 3.4,23.4,-0.7, 5.8,23.4,-0.7, 10.2,23.4,-0.7, 2.3,45.8,-0.7, 3.4,45.8,-0.7, 5.8,45.8,-0.7, 10.2,45.8,-0.7,
+ 2.3,12.3,1.2, 3.4,12.3,1.2, 5.8,12.3,1.2, 10.2,12.3,1.2, 2.3,23.4,1.2, 3.4,23.4,1.2, 5.8,23.4,1.2, 10.2,23.4,1.2, 2.3,45.8,1.2, 3.4,45.8,1.2, 5.8,45.8,1.2, 10.2,45.8,1.2,
+ 2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
+ 2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
+ 2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67
+ };
+ for(int i=0;i<180;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_2[i],coords->getIJ(0,i),1e-12);
+ coords->decrRef();
+ coords=m->getBarycenterAndOwner();
+ CPPUNIT_ASSERT_EQUAL(24,coords->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(3,coords->getNumberOfComponents());
+ const double expected3_3[72]={
+ 2.85,17.85,0.25,4.6,17.85,0.25,8.,17.85,0.25, 2.85,34.6,0.25,4.6,34.6,0.25,8.,34.6,0.25,
+ 2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
+ 2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
+ 2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4
+ };
+ for(int i=0;i<72;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3_3[i],coords->getIJ(0,i),1e-12);
+ coords->decrRef();
+ //
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldDoubleZipCoords1()
+{
+ MEDCouplingUMesh *m=build2DTargetMeshMergeNode_1();
+ MEDCouplingFieldDouble *f=m->fillFromAnalytic(ON_NODES,2,"x*2.");
+ f->getArray()->setInfoOnComponent(0,"titi");
+ f->getArray()->setInfoOnComponent(1,"tutu");
+ f->checkCoherency();
+ CPPUNIT_ASSERT_EQUAL(18,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
+ const double expected1[36]={-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
+ for(int i=0;i<36;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(f->zipCoords());
+ f->checkCoherency();
+ const double expected2[30]={-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4};
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(!f->zipCoords());
+ f->checkCoherency();
+ for(int i=0;i<30;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
+ CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
+ f->decrRef();
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldDoubleZipConnectivity1()
+{
+ MEDCouplingUMesh *m1=build2DTargetMesh_1();
+ MEDCouplingUMesh *m2=build2DTargetMesh_1();
+ const int cells1[3]={2,3,4};
+ MEDCouplingPointSet *m3_1=m2->buildPartOfMySelf(cells1,cells1+3,true);
+ MEDCouplingUMesh *m3=dynamic_cast<MEDCouplingUMesh *>(m3_1);
+ CPPUNIT_ASSERT(m3);
+ m2->decrRef();
+ MEDCouplingUMesh *m4=build2DSourceMesh_1();
+ MEDCouplingUMesh *m5=MEDCouplingUMesh::mergeUMeshes(m1,m3);
+ m1->decrRef();
+ m3->decrRef();
+ MEDCouplingUMesh *m6=MEDCouplingUMesh::mergeUMeshes(m5,m4);
+ m4->decrRef();
+ m5->decrRef();
+ //
+ CPPUNIT_ASSERT_EQUAL(10,m6->getNumberOfCells());
+ CPPUNIT_ASSERT_EQUAL(22,m6->getNumberOfNodes());
+ bool areNodesMerged;
+ int newNbOfNodes;
+ DataArrayInt *arr=m6->mergeNodes(1e-13,areNodesMerged,newNbOfNodes);
+ CPPUNIT_ASSERT_EQUAL(9,m6->getNumberOfNodes());
+ arr->decrRef();
+ MEDCouplingFieldDouble *f=m6->fillFromAnalytic(ON_CELLS,2,"x");
+ MEDCouplingFieldDouble *f2=m6->fillFromAnalytic(ON_NODES,2,"x");
+ CPPUNIT_ASSERT_EQUAL(10,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
+ const double expected1[20]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
+ -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
+ 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
+ for(int i=0;i<20;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f->getIJ(0,i),1e-12);
+ f->getArray()->setInfoOnComponent(0,"titi");
+ f->getArray()->setInfoOnComponent(1,"tutu");
+ f->checkCoherency();
+ CPPUNIT_ASSERT(f->zipConnectivity(0));
+ const double expected2[14]={-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
+ -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326};
+ CPPUNIT_ASSERT_EQUAL(7,f->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f->getNumberOfComponents());
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],f->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(0))=="titi");
+ CPPUNIT_ASSERT(std::string(f->getArray()->getInfoOnComponent(1))=="tutu");
+ CPPUNIT_ASSERT(!f->zipConnectivity(0));
+ f->decrRef();
+ //
+ const double expected3[18]={-0.3, -0.3, 0.2, 0.2, 0.7, 0.7, -0.3, -0.3, 0.2, 0.2, 0.7, 0.7,
+ -0.3, -0.3, 0.2, 0.2, 0.7, 0.7};
+ CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
+ for(int i=0;i<18;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
+ CPPUNIT_ASSERT(f2->zipConnectivity(0));
+ CPPUNIT_ASSERT_EQUAL(9,f2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,f2->getNumberOfComponents());
+ for(int i=0;i<18;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],f2->getIJ(0,i),1e-12);
+ f2->decrRef();
+ //
+ m6->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumber1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ a->setInfoOnComponent(0,"toto");
+ a->setInfoOnComponent(1,"tata");
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={3,1,0,6,5,4,2};
+ DataArrayDouble *b=a->renumber(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
+ const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ c->setInfoOnComponent(0,"toto");
+ c->setInfoOnComponent(1,"tata");
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ DataArrayInt *d=c->renumber(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
+ const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
+ c->decrRef();
+ d->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumberAndReduce1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ a->setInfoOnComponent(0,"toto");
+ a->setInfoOnComponent(1,"tata");
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={2,-1,1,-1,0,4,3};
+ DataArrayDouble *b=a->renumberAndReduce(arr2,5);
+ CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
+ const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ c->setInfoOnComponent(0,"toto");
+ c->setInfoOnComponent(1,"tata");
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ DataArrayInt *d=c->renumberAndReduce(arr2,5);
+ CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
+ const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
+ c->decrRef();
+ d->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumberInPlace1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={3,1,0,6,5,4,2};
+ a->renumberInPlace(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
+ const double expected1[14]={3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ c->renumberInPlace(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
+ const int expected2[14]={3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
+ c->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumberR1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ a->setInfoOnComponent(0,"toto");
+ a->setInfoOnComponent(1,"tata");
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={3,1,0,6,5,4,2};
+ DataArrayDouble *b=a->renumberR(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
+ const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ c->setInfoOnComponent(0,"toto");
+ c->setInfoOnComponent(1,"tata");
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ DataArrayInt *d=c->renumberR(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
+ const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
+ c->decrRef();
+ d->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleRenumberInPlaceR1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={3,1,0,6,5,4,2};
+ a->renumberInPlaceR(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,a->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,a->getNumberOfComponents());
+ const double expected1[14]={4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a->getIJ(0,i),1e-14);
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ c->renumberInPlaceR(arr2);
+ CPPUNIT_ASSERT_EQUAL(7,c->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,c->getNumberOfComponents());
+ const int expected2[14]={4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13};
+ for(int i=0;i<14;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],c->getIJ(0,i));
+ c->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleSelectByTupleId1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(7,2);
+ a->setInfoOnComponent(0,"toto");
+ a->setInfoOnComponent(1,"tata");
+ const double arr1[14]={1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1};
+ std::copy(arr1,arr1+14,a->getPointer());
+ //
+ const int arr2[7]={4,2,0,6,5};
+ DataArrayDouble *b=a->selectByTupleId(arr2,arr2+5);
+ CPPUNIT_ASSERT_EQUAL(5,b->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,b->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(b->getInfoOnComponent(1))=="tata");
+ const double expected1[10]={5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],b->getIJ(0,i),1e-14);
+ b->decrRef();
+ a->decrRef();
+ //
+ DataArrayInt *c=DataArrayInt::New();
+ c->alloc(7,2);
+ c->setInfoOnComponent(0,"toto");
+ c->setInfoOnComponent(1,"tata");
+ const int arr3[14]={1,11,2,12,3,13,4,14,5,15,6,16,7,17};
+ std::copy(arr3,arr3+14,c->getPointer());
+ DataArrayInt *d=c->selectByTupleId(arr2,arr2+5);
+ CPPUNIT_ASSERT_EQUAL(5,d->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(2,d->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(0))=="toto");
+ CPPUNIT_ASSERT(std::string(d->getInfoOnComponent(1))=="tata");
+ const int expected2[10]={5,15,3,13,1,11,7,17,6,16};
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],d->getIJ(0,i));
+ c->decrRef();
+ d->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDaDoubleGetMinMaxValues1()
+{
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(9,1);
+ const double arr1[9]={2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56};
+ std::copy(arr1,arr1+9,a->getPointer());
+ int where;
+ double m=a->getMaxValue(where);
+ CPPUNIT_ASSERT_EQUAL(1,where);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
+ DataArrayInt *ws;
+ m=a->getMaxValue2(ws);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4.56,m,1e-12);
+ CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
+ const int expected1[3]={1,4,8};
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
+ ws->decrRef();
+ a->decrRef();
+ a=DataArrayDouble::New();
+ const double arr2[9]={-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56};
+ a->alloc(9,1);
+ std::copy(arr2,arr2+9,a->getPointer());
+ where=-2;
+ m=a->getMinValue(where);
+ CPPUNIT_ASSERT_EQUAL(1,where);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
+ m=a->getMinValue2(ws);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.56,m,1e-12);
+ CPPUNIT_ASSERT_EQUAL(3,ws->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
+ ws->decrRef();
+ a->decrRef();
+}
+
+void MEDCouplingBasicsTest::testFieldDoubleGetMinMaxValues2()
+{
+ MEDCouplingUMesh *m1=0;
+ MEDCouplingUMesh *m2=build3DExtrudedUMesh_1(m1);
+ m1->decrRef();
+ CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
+ const double arr1[18]={8.71,4.53,-12.41,8.71,-8.71,8.7099,4.55,8.71,5.55,6.77,-1e-200,4.55,8.7099,0.,1.23,0.,2.22,8.71};
+ MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
+ DataArrayDouble *a=DataArrayDouble::New();
+ a->alloc(18,1);
+ std::copy(arr1,arr1+18,a->getPointer());
+ f->setArray(a);
+ a->decrRef();
+ f->setMesh(m2);
+ //
+ f->checkCoherency();
+ double m=f->getMaxValue();
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
+ DataArrayInt *ws;
+ m=f->getMaxValue2(ws);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8.71,m,1e-12);
+ CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
+ const int expected1[4]={0,3,7,17};
+ for(int i=0;i<4;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
+ ws->decrRef();
+ //
+ const double arr2[18]={-8.71,-4.53,12.41,-8.71,8.71,-8.7099,-4.55,-8.71,-5.55,-6.77,1e-200,-4.55,-8.7099,0.,-1.23,0.,-2.22,-8.71};
+ std::copy(arr2,arr2+18,a->getPointer());
+ f->checkCoherency();
+ m=f->getMinValue();
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
+ m=f->getMinValue2(ws);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.71,m,1e-12);
+ CPPUNIT_ASSERT_EQUAL(4,ws->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ws->getNumberOfComponents());
+ for(int i=0;i<4;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],ws->getIJ(i,0));
+ ws->decrRef();
+ //
+ f->decrRef();
+ m2->decrRef();
+}
+
+void MEDCouplingBasicsTest::testBuildUnstructuredCMesh1()
+{
+ MEDCouplingCMesh *m=MEDCouplingCMesh::New();
+ DataArrayDouble *da=DataArrayDouble::New();
+ const double discX[4]={2.3,3.4,5.8,10.2};
+ const double discY[3]={12.3,23.4,45.8};
+ const double discZ[5]={-0.7,1.2,1.25,2.13,2.67};
+ da->alloc(4,1);
+ std::copy(discX,discX+4,da->getPointer());
+ m->setCoordsAt(0,da);
+ da->decrRef();
+ m->checkCoherency();
+ double pos=2.4;
+ CPPUNIT_ASSERT_EQUAL(0,m->getCellContainingPoint(&pos,1e-12));
+ pos=3.7;
+ CPPUNIT_ASSERT_EQUAL(1,m->getCellContainingPoint(&pos,1e-12));
+ pos=5.9;
+ CPPUNIT_ASSERT_EQUAL(2,m->getCellContainingPoint(&pos,1e-12));
+ pos=10.3;
+ CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
+ pos=1.3;
+ CPPUNIT_ASSERT_EQUAL(-1,m->getCellContainingPoint(&pos,1e-12));
+ //
+ MEDCouplingUMesh *m2=m->buildUnstructured();
+ m2->checkCoherency();
+ MEDCouplingFieldDouble *f1=m->getMeasureField(false);
+ MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
+ CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),3);
+ CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),3);
+ CPPUNIT_ASSERT_EQUAL(1,m2->getMeshDimension());
+ CPPUNIT_ASSERT_EQUAL(1,m2->getSpaceDimension());
+ for(int i=0;i<3;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
+ da=DataArrayDouble::New();
+ da->alloc(3,1);
+ std::copy(discY,discY+3,da->getPointer());
+ m->setCoordsAt(1,da);
+ da->decrRef();
+ m2->decrRef();
+ f1->decrRef();
+ f2->decrRef();
+ //
+ m2=m->buildUnstructured();
+ m2->checkCoherency();
+ f1=m->getMeasureField(false);
+ f2=m2->getMeasureField(false);
+ CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),6);
+ CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),6);
+ CPPUNIT_ASSERT_EQUAL(2,m2->getMeshDimension());
+ CPPUNIT_ASSERT_EQUAL(2,m2->getSpaceDimension());
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
+ f1->decrRef();
+ f2->decrRef();
+ m2->decrRef();
+ //
+ da=DataArrayDouble::New();
+ da->alloc(5,1);
+ std::copy(discZ,discZ+5,da->getPointer());
+ m->setCoordsAt(2,da);
+ da->decrRef();
+ m2=m->buildUnstructured();
+ m2->checkCoherency();
+ f1=m->getMeasureField(false);
+ f2=m2->getMeasureField(false);
+ CPPUNIT_ASSERT_EQUAL(f1->getNumberOfTuples(),24);
+ CPPUNIT_ASSERT_EQUAL(f2->getNumberOfTuples(),24);
+ CPPUNIT_ASSERT_EQUAL(3,m2->getMeshDimension());
+ CPPUNIT_ASSERT_EQUAL(3,m2->getSpaceDimension());
+ for(int i=0;i<24;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getIJ(i,0),f2->getIJ(i,0),1e-10);
+ f1->decrRef();
+ f2->decrRef();
+ //
+ double pos1[3]={5.,30.,2.};
+ CPPUNIT_ASSERT_EQUAL(16,m->getCellContainingPoint(pos1,1e-12));
+ //
+ const double pt[3]={2.4,12.7,-3.4};
+ m->scale(pt,3.7);
+ MEDCouplingUMesh *m3=m->buildUnstructured();
+ m2->scale(pt,3.7);
+ CPPUNIT_ASSERT(m3->isEqual(m2,1e-12));
+ m2->decrRef();
+ m3->decrRef();
+ //
+ m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testDataArrayIntInvertO2NNO21()
+{
+ const int arr1[6]={2,0,4,1,5,3};
+ DataArrayInt *da=DataArrayInt::New();
+ da->alloc(6,1);
+ std::copy(arr1,arr1+6,da->getPointer());
+ DataArrayInt *da2=da->invertArrayO2N2N2O(6);
+ CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
+ const int expected1[6]={1,3,0,5,2,4};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_EQUAL(expected1[i],da2->getIJ(i,0));
+ DataArrayInt *da3=da2->invertArrayN2O2O2N(6);
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_EQUAL(arr1[i],da3->getIJ(i,0));
+ da3->decrRef();
+ da2->decrRef();
+ da->decrRef();
+ //
+ const int arr2[10]={3,-1,5,4,-1,0,-1,1,2,-1};
+ da=DataArrayInt::New();
+ da->alloc(10,1);
+ std::copy(arr2,arr2+10,da->getPointer());
+ da2=da->invertArrayO2N2N2O(6);
+ CPPUNIT_ASSERT_EQUAL(6,da2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da2->getNumberOfComponents());
+ const int expected2[10]={5,7,8,0,3,2};
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_EQUAL(expected2[i],da2->getIJ(i,0));
+ da3=da2->invertArrayN2O2O2N(10);
+ for(int i=0;i<10;i++)
+ CPPUNIT_ASSERT_EQUAL(arr2[i],da3->getIJ(i,0));
+ da3->decrRef();
+ da2->decrRef();
+ da->decrRef();
+}
subMesh=mesh.buildPartOfMySelf(tab1,True);
self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
traducer=subMesh.zipCoordsTraducer();
- expectedTraducer=[0,1,3,4,5,7,8]
+ expectedTraducer=[0, 1, -1, 2, 3, 4, -1, 5, 6]
self.assertEqual(expectedTraducer,list(traducer.getValues()));
self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]);
self.assertEqual(2,subMesh.getNumberOfCells());
self.assertTrue(abs(tmp[i]-values3[i])<1.e-12)
pass
values4=f1.accumulate();
+ self.assertEqual(2,len(values4))
self.assertTrue(abs(3.6-values4[0])<1.e-12);
self.assertTrue(abs(7.2-values4[1])<1.e-12);
values4=f1.integral(True);
+ self.assertEqual(2,len(values4))
self.assertTrue(abs(0.5-values4[0])<1.e-12);
self.assertTrue(abs(1.-values4[1])<1.e-12);
#
self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
pass
#integral
+ self.assertTrue(4,f1.getNumberOfTuples())
res=f1.integral(False);
+ self.assertTrue(3,len(res))
expected3=[0.9866,-0.3615,0.4217]
for i in xrange(3):
self.assertTrue(abs(expected3[i]-res[i])<1e-12);
pass
#normL1
res=f1.normL1();
+ self.assertTrue(3,len(res))
expected5=[11.3068,27.3621,43.7881]
for i in xrange(3):
self.assertTrue(abs(expected5[i]-res[i])<1e-12);
self.assertTrue(abs(expected5[2]-f1.normL1(2))<1e-12);
#normL2
res=f1.normL2();
+ self.assertTrue(3,len(res))
expected7=[9.0252562290496776, 21.545259176904789, 34.433193070059595]
for i in xrange(3):
self.assertTrue(abs(expected7[i]-res[i])<1e-9);
self.assertAlmostEqual(expected2[i],f1.getIJ(i,0),14);
pass
pass
+
+ def testFillFromAnalytic3(self):
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
+ self.assertRaises(Exception,f1.fillFromAnalytic,1,"y+x");
+ f1.setMesh(m)
+ f1.setName("myField");
+ f1.fillFromAnalytic(1,"y+x");
+ f1.checkCoherency();
+ self.assertEqual(f1.getName(),"myField");
+ self.assertEqual(f1.getTypeOfField(),ON_CELLS);
+ self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
+ self.assertEqual(1,f1.getNumberOfComponents());
+ self.assertEqual(5,f1.getNumberOfTuples());
+ values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
+ tmp=f1.getArray().getValues();
+ self.assertEqual(len(values1),len(tmp))
+ for i in xrange(len(values1)):
+ self.assertTrue(abs(values1[i]-tmp[i])<1.e-12);
+ pass
+ #
+ f1=MEDCouplingFieldDouble.New(ON_NODES,CONST_ON_TIME_INTERVAL)
+ f1.setMesh(m)
+ f1.fillFromAnalytic(1,"y+2*x");
+ f1.setEndTime(1.2,3,4);
+ f1.checkCoherency();
+ self.assertEqual(f1.getTypeOfField(),ON_NODES);
+ self.assertEqual(f1.getTimeDiscretization(),CONST_ON_TIME_INTERVAL);
+ self.assertEqual(1,f1.getNumberOfComponents());
+ self.assertEqual(9,f1.getNumberOfTuples());
+ values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
+ tmp=f1.getArray().getValues();
+ self.assertEqual(len(values2),len(tmp))
+ for i in xrange(len(values2)):
+ self.assertTrue(abs(values2[i]-tmp[i])<1.e-12);
+ pass
+ f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
+ f1.setMesh(m)
+ f1.fillFromAnalytic(1,"2.*x+y");
+ f1.setEndTime(1.2,3,4);
+ f1.checkCoherency();
+ self.assertEqual(f1.getTypeOfField(),ON_NODES);
+ self.assertEqual(f1.getTimeDiscretization(),LINEAR_TIME);
+ self.assertEqual(1,f1.getNumberOfComponents());
+ self.assertEqual(9,f1.getNumberOfTuples());
+ tmp=f1.getArray().getValues();
+ values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
+ self.assertEqual(len(values2Bis),len(tmp))
+ for i in xrange(len(values2Bis)):
+ self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
+ pass
+ tmp=f1.getEndArray().getValues();
+ self.assertEqual(len(values2Bis),len(tmp))
+ for i in xrange(len(values2Bis)):
+ self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
+ pass
+ #
+ f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
+ f1.setMesh(m)
+ f1.fillFromAnalytic(2,"(x+y)*IVec+2*(x+y)*JVec");
+ f1.checkCoherency();
+ self.assertEqual(f1.getTypeOfField(),ON_NODES);
+ self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
+ self.assertEqual(2,f1.getNumberOfComponents());
+ self.assertEqual(9,f1.getNumberOfTuples());
+ values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
+ tmp=f1.getArray().getValues();
+ self.assertEqual(len(values3),len(tmp))
+ for i in xrange(len(values3)):
+ self.assertTrue(abs(values3[i]-tmp[i])<1.e-12);
+ pass
+ values4=f1.accumulate();
+ self.assertTrue(abs(3.6-values4[0])<1.e-12);
+ self.assertTrue(abs(7.2-values4[1])<1.e-12);
+ values4=f1.integral(True);
+ self.assertTrue(abs(0.5-values4[0])<1.e-12);
+ self.assertTrue(abs(1.-values4[1])<1.e-12);
+ #
+ f1=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
+ f1.setMesh(m);
+ self.assertRaises(Exception,f1.fillFromAnalytic,1,"1./(x-0.2)");
+ pass
+
+ def testFieldDoubleOpEqual1(self):
+ m=MEDCouplingDataForTest.build2DTargetMesh_1();
+ f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+ self.assertRaises(Exception,f1.assign,0.07);
+ f1.setMesh(m);
+ f1.assign(0.07);
+ f1.checkCoherency();
+ self.assertEqual(1,f1.getNumberOfComponents());
+ self.assertEqual(5,f1.getNumberOfTuples());
+ for i in xrange(5):
+ self.assertAlmostEqual(0.07,f1.getIJ(i,0),16);
+ pass
+ f1.assign(0.09);
+ f1.checkCoherency();
+ self.assertEqual(1,f1.getNumberOfComponents());
+ self.assertEqual(5,f1.getNumberOfTuples());
+ for i in xrange(5):
+ self.assertAlmostEqual(0.09,f1.getIJ(i,0),16);
+ pass
+ #
+ f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
+ f1.setEndTime(4.5,2,3);
+ f1.setMesh(m);
+ f1.assign(0.08);
+ f1.checkCoherency();
+ self.assertEqual(1,f1.getNumberOfComponents());
+ self.assertEqual(9,f1.getNumberOfTuples());
+ for i in xrange(9):
+ self.assertAlmostEqual(0.08,f1.getIJ(i,0),16);
+ pass
+ self.assertEqual(1,f1.getEndArray().getNumberOfComponents());
+ self.assertEqual(9,f1.getEndArray().getNumberOfTuples());
+ for i in xrange(9):
+ self.assertAlmostEqual(0.08,f1.getEndArray().getIJ(i,0),16);
+ pass
+ pass
+
+ def testAreaBary3D2(self):
+ coordsForHexa8=[-75.45749305371, 180.95495078401, 39.515472018008,
+ -9.755591679144, 23.394927935279, 5.108794294848,
+ 14.337630157832, 61.705351002702, 160.42422501908,
+ -27.273893776752, 167.567731083961, 192.830034145464,
+ 99.857193154796,264.499264735586,-8.287335493412,
+ 144.939882761126,156.38626563134,-31.896173894226,
+ 161.34096835726,182.4654895809,73.832387065572,
+ 132.680430393685,255.37973247196,96.15235602819];
+ volHexa8=3258520.29637466;
+ baryHexa8=[43.925705821778, 155.31893955289, 65.874418109644]
+
+ coordsForPenta6=[-68.199829618726,178.938498373416,62.608505919588,
+ 8.461744647847,76.653979804423,165.00018874933,
+ -27.273893776752,167.567731083961,192.830034145464,
+ 106.586501038965,262.629609408327,13.124533008813,
+ 155.465082847275,197.414118382622,78.408350795821,
+ 132.680430393685,255.37973247196,96.15235602819];
+ volPenta6=944849.868507338;
+ baryPenta6=[39.631002313543,182.692711783428,106.98540473964]
+
+ coordsForPyra5=[132.680430393685,255.37973247196,96.15235602819,
+ -27.273893776752,167.567731083961,192.830034145464,
+ 8.461744647847,76.653979804423,165.00018874933,
+ 155.465082847275,197.414118382622,78.408350795821,
+ -68.199829618726,178.938498373416,62.608505919588];
+ volPyra5=756943.92980254;
+ baryPyra5=[29.204294116618,172.540129749156,118.01035951483]
+ mesh=MEDCouplingUMesh.New("Bary3D2",3);
+ coo=DataArrayDouble.New();
+ tmp=coordsForHexa8+coordsForPenta6+coordsForPyra5
+ coo.setValues(tmp,19,3);
+ mesh.setCoords(coo);
+ #
+ tmpConn=[0,1,2,3,4,5,6,7]
+ mesh.allocateCells(3);
+ mesh.insertNextCell(NORM_HEXA8,8,tmpConn[0:8])
+ mesh.insertNextCell(NORM_PENTA6,6,[i+8 for i in tmpConn])
+ mesh.insertNextCell(NORM_PYRA5,5,[i+14 for i in tmpConn])
+ mesh.finishInsertingCells();
+ mesh.checkCoherency();
+ mesh.mergeNodes(1e-7)
+ self.assertEqual(12,mesh.getNumberOfNodes());
+ vols=mesh.getMeasureField(True);
+ self.assertEqual(3,vols.getNumberOfTuples());
+ self.assertEqual(1,vols.getNumberOfComponents());
+ self.assertAlmostEqual(volHexa8,vols.getIJ(0,0),6);
+ self.assertAlmostEqual(volPenta6,vols.getIJ(1,0),7);
+ self.assertAlmostEqual(volPyra5,vols.getIJ(2,0),7);
+ bary=mesh.getBarycenterAndOwner();
+ self.assertEqual(3,bary.getNumberOfTuples());
+ self.assertEqual(3,bary.getNumberOfComponents());
+ self.assertAlmostEqual(baryHexa8[0],bary.getIJ(0,0),11);
+ self.assertAlmostEqual(baryHexa8[1],bary.getIJ(0,1),11);
+ self.assertAlmostEqual(baryHexa8[2],bary.getIJ(0,2),11);
+ self.assertAlmostEqual(baryPenta6[0],bary.getIJ(1,0),11);
+ self.assertAlmostEqual(baryPenta6[1],bary.getIJ(1,1),11);
+ self.assertAlmostEqual(baryPenta6[2],bary.getIJ(1,2),11);
+ self.assertAlmostEqual(baryPyra5[0],bary.getIJ(2,0),11);
+ self.assertAlmostEqual(baryPyra5[1],bary.getIJ(2,1),11);
+ self.assertAlmostEqual(baryPyra5[2],bary.getIJ(2,2),11);
+ pass
+
+ def testGetMeasureFieldCMesh1(self):
+ m=MEDCouplingCMesh.New();
+ da=DataArrayDouble.New();
+ discX=[2.3,3.4,5.8,10.2]
+ discY=[12.3,23.4,45.8]
+ discZ=[-0.7,1.2,1.25,2.13,2.67]
+ da.setValues(discX,4,1);
+ m.setCoordsAt(0,da);
+ m.checkCoherency();
+ self.assertEqual(4,m.getNumberOfNodes());
+ self.assertEqual(3,m.getNumberOfCells());
+ self.assertEqual(1,m.getSpaceDimension());
+ f=m.getMeasureField(True);
+ self.assertEqual(3,f.getNumberOfTuples());
+ self.assertEqual(1,f.getNumberOfComponents());
+ expected1=[1.1,2.4,4.4]
+ for i in xrange(3):
+ self.assertAlmostEqual(expected1[i],f.getIJ(i,0),12);
+ pass
+ coords=m.getCoordinatesAndOwner();
+ self.assertEqual(4,coords.getNumberOfTuples());
+ self.assertEqual(1,coords.getNumberOfComponents());
+ for i in xrange(4):
+ self.assertAlmostEqual(discX[i],coords.getIJ(i,0),12);
+ pass
+ coords=m.getBarycenterAndOwner();
+ self.assertEqual(3,coords.getNumberOfTuples());
+ self.assertEqual(1,coords.getNumberOfComponents());
+ expected1_3=[2.85,4.6,8.]
+ for i in xrange(3):
+ self.assertAlmostEqual(expected1_3[i],coords.getIJ(i,0),12);
+ pass
+ #
+ da=DataArrayDouble.New();
+ da.setValues(discY,3,1);
+ m.setCoordsAt(1,da);
+ m.checkCoherency();
+ self.assertEqual(12,m.getNumberOfNodes());
+ self.assertEqual(6,m.getNumberOfCells());
+ self.assertEqual(2,m.getSpaceDimension());
+ f=m.getMeasureField(True);
+ self.assertEqual(6,f.getNumberOfTuples());
+ self.assertEqual(1,f.getNumberOfComponents());
+ expected2=[12.21,26.64,48.84,24.64,53.76,98.56]
+ for i in xrange(6):
+ self.assertAlmostEqual(expected2[i],f.getIJ(i,0),12);
+ pass
+ coords=m.getCoordinatesAndOwner();
+ self.assertEqual(12,coords.getNumberOfTuples());
+ self.assertEqual(2,coords.getNumberOfComponents());
+ expected2_2=[2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8]
+ for i in xrange(24):
+ self.assertAlmostEqual(expected2_2[i],coords.getIJ(0,i),12);
+ pass
+ coords=m.getBarycenterAndOwner();
+ self.assertEqual(6,coords.getNumberOfTuples());
+ self.assertEqual(2,coords.getNumberOfComponents());
+ expected2_3=[2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6]
+ for i in xrange(12):
+ self.assertAlmostEqual(expected2_3[i],coords.getIJ(0,i),12);
+ pass
+ #
+ da=DataArrayDouble.New();
+ da.setValues(discZ,5,1);
+ m.setCoordsAt(2,da);
+ m.checkCoherency();
+ self.assertEqual(60,m.getNumberOfNodes());
+ self.assertEqual(24,m.getNumberOfCells());
+ self.assertEqual(3,m.getSpaceDimension());
+ f=m.getMeasureField(True);
+ self.assertEqual(24,f.getNumberOfTuples());
+ self.assertEqual(1,f.getNumberOfComponents());
+ expected3=[23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224]
+ for i in xrange(24):
+ self.assertAlmostEqual(expected3[i],f.getIJ(i,0),12);
+ pass
+ coords=m.getCoordinatesAndOwner();
+ self.assertEqual(60,coords.getNumberOfTuples());
+ self.assertEqual(3,coords.getNumberOfComponents());
+ expected3_2=[
+ 2.3,12.3,-0.7, 3.4,12.3,-0.7, 5.8,12.3,-0.7, 10.2,12.3,-0.7, 2.3,23.4,-0.7, 3.4,23.4,-0.7, 5.8,23.4,-0.7, 10.2,23.4,-0.7, 2.3,45.8,-0.7, 3.4,45.8,-0.7, 5.8,45.8,-0.7, 10.2,45.8,-0.7,
+ 2.3,12.3,1.2, 3.4,12.3,1.2, 5.8,12.3,1.2, 10.2,12.3,1.2, 2.3,23.4,1.2, 3.4,23.4,1.2, 5.8,23.4,1.2, 10.2,23.4,1.2, 2.3,45.8,1.2, 3.4,45.8,1.2, 5.8,45.8,1.2, 10.2,45.8,1.2,
+ 2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
+ 2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
+ 2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67];
+ for i in xrange(180):
+ self.assertAlmostEqual(expected3_2[i],coords.getIJ(0,i),12);
+ pass
+ coords=m.getBarycenterAndOwner();
+ self.assertEqual(24,coords.getNumberOfTuples());
+ self.assertEqual(3,coords.getNumberOfComponents());
+ expected3_3=[
+ 2.85,17.85,0.25,4.6,17.85,0.25,8.,17.85,0.25, 2.85,34.6,0.25,4.6,34.6,0.25,8.,34.6,0.25,
+ 2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
+ 2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
+ 2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4];
+ for i in xrange(72):
+ self.assertAlmostEqual(expected3_3[i],coords.getIJ(0,i),12);
+ pass
+ pass
+
+ def testFieldDoubleZipCoords1(self):
+ m=MEDCouplingDataForTest.build2DTargetMeshMergeNode_1();
+ f=m.fillFromAnalytic(ON_NODES,2,"x*2.");
+ f.getArray().setInfoOnComponent(0,"titi");
+ f.getArray().setInfoOnComponent(1,"tutu");
+ f.checkCoherency();
+ self.assertEqual(18,f.getNumberOfTuples());
+ self.assertEqual(2,f.getNumberOfComponents());
+ expected1=[-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4]
+ for i in xrange(36):
+ self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
+ pass
+ self.assertTrue(f.zipCoords());
+ f.checkCoherency();
+ expected2=[-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4]
+ for i in xrange(30):
+ self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
+ pass
+ self.assertTrue(not f.zipCoords());
+ f.checkCoherency();
+ for i in xrange(30):
+ self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
+ pass
+ self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
+ self.assertTrue(f.getArray().getInfoOnComponent(1)=="tutu");
+ pass
+
+ def testFieldDoubleZipConnectivity1(self):
+ m1=MEDCouplingDataForTest.build2DTargetMesh_1();
+ m2=MEDCouplingDataForTest.build2DTargetMesh_1();
+ cells1=[2,3,4]
+ m3_1=m2.buildPartOfMySelf(cells1,True);
+ m3=m3_1;
+ m4=MEDCouplingDataForTest.build2DSourceMesh_1();
+ m5=MEDCouplingUMesh.mergeUMeshes(m1,m3);
+ m6=MEDCouplingUMesh.mergeUMeshes(m5,m4);
+ #
+ self.assertEqual(10,m6.getNumberOfCells());
+ self.assertEqual(22,m6.getNumberOfNodes());
+ arr,areNodesMerged,newNbOfNodes=m6.mergeNodes(1e-13);
+ self.assertEqual(9,m6.getNumberOfNodes());
+ f=m6.fillFromAnalytic(ON_CELLS,2,"x");
+ f2=m6.fillFromAnalytic(ON_NODES,2,"x");
+ self.assertEqual(10,f.getNumberOfTuples());
+ self.assertEqual(2,f.getNumberOfComponents());
+ expected1=[-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
+ -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
+ 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
+ for i in xrange(20):
+ self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
+ pass
+ f.getArray().setInfoOnComponent(0,"titi");
+ f.getArray().setInfoOnComponent(1,"tutu");
+ f.checkCoherency();
+ self.assertTrue(f.zipConnectivity(0));
+ expected2=[-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
+ -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
+ self.assertEqual(7,f.getNumberOfTuples());
+ self.assertEqual(2,f.getNumberOfComponents());
+ for i in xrange(14):
+ self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
+ pass
+ self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
+ self.assertTrue(f.getArray().getInfoOnComponent(1)=="tutu");
+ self.assertTrue(not f.zipConnectivity(0));
+ #
+ expected3=[-0.3, -0.3, 0.2, 0.2, 0.7, 0.7, -0.3, -0.3, 0.2, 0.2, 0.7, 0.7,
+ -0.3, -0.3, 0.2, 0.2, 0.7, 0.7];
+ self.assertEqual(9,f2.getNumberOfTuples());
+ self.assertEqual(2,f2.getNumberOfComponents());
+ for i in xrange(18):
+ self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
+ pass
+ self.assertTrue(f2.zipConnectivity(0));
+ self.assertEqual(9,f2.getNumberOfTuples());
+ self.assertEqual(2,f2.getNumberOfComponents());
+ for i in xrange(18):
+ self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
+ pass
+ pass
+
+ def testDaDoubleRenumber1(self):
+ a=DataArrayDouble.New();
+ arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
+ a.setValues(arr1,7,2);
+ a.setInfoOnComponent(0,"toto");
+ a.setInfoOnComponent(1,"tata");
+ #
+ arr2=[3,1,0,6,5,4,2]
+ b=a.renumber(arr2);
+ self.assertEqual(7,b.getNumberOfTuples());
+ self.assertEqual(2,b.getNumberOfComponents());
+ self.assertTrue(b.getInfoOnComponent(0)=="toto");
+ self.assertTrue(b.getInfoOnComponent(1)=="tata");
+ expected1=[3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1]
+ for i in xrange(14):
+ self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
+ pass
+ #
+ c=DataArrayInt.New();
+ arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
+ c.setValues(arr3,7,2);
+ c.setInfoOnComponent(0,"toto");
+ c.setInfoOnComponent(1,"tata");
+ d=c.renumber(arr2);
+ self.assertEqual(7,d.getNumberOfTuples());
+ self.assertEqual(2,d.getNumberOfComponents());
+ self.assertTrue(d.getInfoOnComponent(0)=="toto");
+ self.assertTrue(d.getInfoOnComponent(1)=="tata");
+ expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
+ for i in xrange(14):
+ self.assertEqual(expected2[i],d.getIJ(0,i));
+ pass
+ pass
+
+ def testDaDoubleRenumberAndReduce1(self):
+ a=DataArrayDouble.New();
+ arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
+ a.setValues(arr1,7,2);
+ a.setInfoOnComponent(0,"toto");
+ a.setInfoOnComponent(1,"tata");
+ #
+ arr2=[2,-1,1,-1,0,4,3]
+ b=a.renumberAndReduce(arr2,5);
+ self.assertEqual(5,b.getNumberOfTuples());
+ self.assertEqual(2,b.getNumberOfComponents());
+ self.assertTrue(b.getInfoOnComponent(0)=="toto");
+ self.assertTrue(b.getInfoOnComponent(1)=="tata");
+ expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
+ for i in xrange(10):
+ self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
+ pass
+ #
+ c=DataArrayInt.New();
+ arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
+ c.setValues(arr3,7,2);
+ c.setInfoOnComponent(0,"toto");
+ c.setInfoOnComponent(1,"tata");
+ d=c.renumberAndReduce(arr2,5);
+ self.assertEqual(5,d.getNumberOfTuples());
+ self.assertEqual(2,d.getNumberOfComponents());
+ self.assertTrue(d.getInfoOnComponent(0)=="toto");
+ self.assertTrue(d.getInfoOnComponent(1)=="tata");
+ expected2=[5,15,3,13,1,11,7,17,6,16]
+ for i in xrange(10):
+ self.assertEqual(expected2[i],d.getIJ(0,i));
+ pass
+ pass
+
+ def testDaDoubleRenumberInPlace1(self):
+ a=DataArrayDouble.New();
+ arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
+ a.setValues(arr1,7,2);
+ #
+ arr2=[3,1,0,6,5,4,2]
+ a.renumberInPlace(arr2);
+ self.assertEqual(7,a.getNumberOfTuples());
+ self.assertEqual(2,a.getNumberOfComponents());
+ expected1=[3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1]
+ for i in xrange(14):
+ self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
+ pass
+ #
+ c=DataArrayInt.New();
+ arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
+ c.setValues(arr3,7,2);
+ c.renumberInPlace(arr2);
+ self.assertEqual(7,c.getNumberOfTuples());
+ self.assertEqual(2,c.getNumberOfComponents());
+ expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
+ for i in xrange(14):
+ self.assertEqual(expected2[i],c.getIJ(0,i));
+ pass
+ pass
+
+ def testDaDoubleRenumberR1(self):
+ a=DataArrayDouble.New();
+ arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
+ a.setValues(arr1,7,2);
+ a.setInfoOnComponent(0,"toto");
+ a.setInfoOnComponent(1,"tata");
+ #
+ arr2=[3,1,0,6,5,4,2]
+ b=a.renumberR(arr2);
+ self.assertEqual(7,b.getNumberOfTuples());
+ self.assertEqual(2,b.getNumberOfComponents());
+ self.assertTrue(b.getInfoOnComponent(0)=="toto");
+ self.assertTrue(b.getInfoOnComponent(1)=="tata");
+ expected1=[4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1]
+ for i in xrange(14):
+ self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
+ pass
+ #
+ c=DataArrayInt.New();
+ arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
+ c.setValues(arr3,7,2);
+ c.setInfoOnComponent(0,"toto");
+ c.setInfoOnComponent(1,"tata");
+ d=c.renumberR(arr2);
+ self.assertEqual(7,d.getNumberOfTuples());
+ self.assertEqual(2,d.getNumberOfComponents());
+ self.assertTrue(d.getInfoOnComponent(0)=="toto");
+ self.assertTrue(d.getInfoOnComponent(1)=="tata");
+ expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
+ for i in xrange(14):
+ self.assertEqual(expected2[i],d.getIJ(0,i));
+ pass
+ pass
+
+ def testDaDoubleRenumberInPlaceR1(self):
+ a=DataArrayDouble.New();
+ arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
+ a.setValues(arr1,7,2);
+ #
+ arr2=[3,1,0,6,5,4,2]
+ a.renumberInPlaceR(arr2);
+ self.assertEqual(7,a.getNumberOfTuples());
+ self.assertEqual(2,a.getNumberOfComponents());
+ expected1=[4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1]
+ for i in xrange(14):
+ self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
+ pass
+ #
+ c=DataArrayInt.New();
+ arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
+ c.setValues(arr3,7,2);
+ c.renumberInPlaceR(arr2);
+ self.assertEqual(7,c.getNumberOfTuples());
+ self.assertEqual(2,c.getNumberOfComponents());
+ expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
+ for i in xrange(14):
+ self.assertEqual(expected2[i],c.getIJ(0,i));
+ pass
+ pass
+
+ def testDaDoubleSelectByTupleId1(self):
+ a=DataArrayDouble.New();
+ arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
+ a.setValues(arr1,7,2);
+ a.setInfoOnComponent(0,"toto");
+ a.setInfoOnComponent(1,"tata");
+ #
+ arr2=[4,2,0,6,5]
+ b=a.selectByTupleId(arr2);
+ self.assertEqual(5,b.getNumberOfTuples());
+ self.assertEqual(2,b.getNumberOfComponents());
+ self.assertTrue(b.getInfoOnComponent(0)=="toto");
+ self.assertTrue(b.getInfoOnComponent(1)=="tata");
+ expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
+ for i in xrange(10):
+ self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
+ pass
+ #
+ c=DataArrayInt.New();
+ arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
+ c.setValues(arr3,7,2);
+ c.setInfoOnComponent(0,"toto");
+ c.setInfoOnComponent(1,"tata");
+ d=c.selectByTupleId(arr2);
+ self.assertEqual(5,d.getNumberOfTuples());
+ self.assertEqual(2,d.getNumberOfComponents());
+ self.assertTrue(d.getInfoOnComponent(0)=="toto");
+ self.assertTrue(d.getInfoOnComponent(1)=="tata");
+ expected2=[5,15,3,13,1,11,7,17,6,16]
+ for i in xrange(10):
+ self.assertEqual(expected2[i],d.getIJ(0,i));
+ pass
+ pass
+
+ def testDaDoubleGetMinMaxValues1(self):
+ a=DataArrayDouble.New();
+ arr1=[2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56]
+ a.setValues(arr1,9,1);
+ m,where=a.getMaxValue();
+ self.assertEqual(1,where);
+ self.assertAlmostEqual(4.56,m,12);
+ m,ws=a.getMaxValue2();
+ self.assertAlmostEqual(4.56,m,12);
+ self.assertEqual(3,ws.getNumberOfTuples());
+ self.assertEqual(1,ws.getNumberOfComponents());
+ expected1=[1,4,8]
+ for i in xrange(3):
+ self.assertEqual(expected1[i],ws.getIJ(i,0));
+ pass
+ a=DataArrayDouble.New();
+ arr2=[-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56]
+ a.setValues(arr2,9,1);
+ m,where=a.getMinValue();
+ self.assertEqual(1,where);
+ self.assertAlmostEqual(-4.56,m,12);
+ m,ws=a.getMinValue2();
+ self.assertAlmostEqual(-4.56,m,12);
+ self.assertEqual(3,ws.getNumberOfTuples());
+ self.assertEqual(1,ws.getNumberOfComponents());
+ for i in xrange(3):
+ self.assertEqual(expected1[i],ws.getIJ(i,0));
+ pass
+ pass
+
+ def testFieldDoubleGetMinMaxValues2(self):
+ m2,m1=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
+ self.assertEqual(18,m2.getNumberOfCells());
+ arr1=[8.71,4.53,-12.41,8.71,-8.71,8.7099,4.55,8.71,5.55,6.77,-1e-200,4.55,8.7099,0.,1.23,0.,2.22,8.71]
+ f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
+ a=DataArrayDouble.New();
+ a.setValues(arr1,18,1);
+ f.setArray(a);
+ f.setMesh(m2);
+ #
+ f.checkCoherency();
+ m=f.getMaxValue();
+ self.assertAlmostEqual(8.71,m,12);
+ m,ws=f.getMaxValue2();
+ self.assertAlmostEqual(8.71,m,12);
+ self.assertEqual(4,ws.getNumberOfTuples());
+ self.assertEqual(1,ws.getNumberOfComponents());
+ expected1=[0,3,7,17]
+ for i in xrange(4):
+ self.assertEqual(expected1[i],ws.getIJ(i,0));
+ pass
+ #
+ arr2=[-8.71,-4.53,12.41,-8.71,8.71,-8.7099,-4.55,-8.71,-5.55,-6.77,1e-200,-4.55,-8.7099,0.,-1.23,0.,-2.22,-8.71]
+ a.setValues(arr2,18,1);
+ f.checkCoherency();
+ m=f.getMinValue();
+ self.assertAlmostEqual(-8.71,m,12);
+ m,ws=f.getMinValue2();
+ self.assertAlmostEqual(-8.71,m,12);
+ self.assertEqual(4,ws.getNumberOfTuples());
+ self.assertEqual(1,ws.getNumberOfComponents());
+ for i in xrange(4):
+ self.assertEqual(expected1[i],ws.getIJ(i,0));
+ pass
+ pass
+
+ def testBuildUnstructuredCMesh1(self):
+ m=MEDCouplingCMesh.New();
+ da=DataArrayDouble.New();
+ discX=[2.3,3.4,5.8,10.2]
+ discY=[12.3,23.4,45.8]
+ discZ=[-0.7,1.2,1.25,2.13,2.67]
+ da.setValues(discX,4,1);
+ m.setCoordsAt(0,da);
+ m.checkCoherency();
+ self.assertEqual(0,m.getCellContainingPoint([2.4],12));
+ self.assertEqual(1,m.getCellContainingPoint([3.7],12));
+ self.assertEqual(2,m.getCellContainingPoint([5.9],12));
+ self.assertEqual(-1,m.getCellContainingPoint([10.3],12));
+ self.assertEqual(-1,m.getCellContainingPoint([1.3],12));
+ #
+ m2=m.buildUnstructured();
+ m2.checkCoherency();
+ f1=m.getMeasureField(False);
+ f2=m2.getMeasureField(False);
+ self.assertEqual(f1.getNumberOfTuples(),3);
+ self.assertEqual(f2.getNumberOfTuples(),3);
+ self.assertEqual(1,m2.getMeshDimension());
+ self.assertEqual(1,m2.getSpaceDimension());
+ for i in xrange(3):
+ self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
+ pass
+ da=DataArrayDouble.New();
+ da.setValues(discY,3,1);
+ m.setCoordsAt(1,da);
+ #
+ m2=m.buildUnstructured();
+ m2.checkCoherency();
+ f1=m.getMeasureField(False);
+ f2=m2.getMeasureField(False);
+ self.assertEqual(f1.getNumberOfTuples(),6);
+ self.assertEqual(f2.getNumberOfTuples(),6);
+ self.assertEqual(2,m2.getMeshDimension());
+ self.assertEqual(2,m2.getSpaceDimension());
+ for i in xrange(6):
+ self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
+ pass
+ #
+ da=DataArrayDouble.New();
+ da.setValues(discZ,5,1);
+ m.setCoordsAt(2,da);
+ m2=m.buildUnstructured();
+ m2.checkCoherency();
+ f1=m.getMeasureField(False);
+ f2=m2.getMeasureField(False);
+ self.assertEqual(f1.getNumberOfTuples(),24);
+ self.assertEqual(f2.getNumberOfTuples(),24);
+ self.assertEqual(3,m2.getMeshDimension());
+ self.assertEqual(3,m2.getSpaceDimension());
+ for i in xrange(24):
+ self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
+ pass
+ #
+ pos1=[5.,30.,2.]
+ self.assertEqual(16,m.getCellContainingPoint(pos1,1e-12));
+ #
+ pt=[2.4,12.7,-3.4]
+ m.scale(pt,3.7);
+ m3=m.buildUnstructured();
+ m2.scale(pt,3.7);
+ self.assertTrue(m3.isEqual(m2,1e-12));
+ pass
+
+ def testDataArrayIntInvertO2NNO21(self):
+ arr1=[2,0,4,1,5,3]
+ da=DataArrayInt.New();
+ da.setValues(arr1,6,1);
+ da2=da.invertArrayO2N2N2O(6);
+ self.assertEqual(6,da2.getNumberOfTuples());
+ self.assertEqual(1,da2.getNumberOfComponents());
+ expected1=[1,3,0,5,2,4]
+ for i in xrange(6):
+ self.assertEqual(expected1[i],da2.getIJ(i,0));
+ pass
+ da3=da2.invertArrayN2O2O2N(6);
+ for i in xrange(6):
+ self.assertEqual(arr1[i],da3.getIJ(i,0));
+ pass
+ #
+ arr2=[3,-1,5,4,-1,0,-1,1,2,-1]
+ da=DataArrayInt.New();
+ da.setValues(arr2,10,1);
+ da2=da.invertArrayO2N2N2O(6);
+ self.assertEqual(6,da2.getNumberOfTuples());
+ self.assertEqual(1,da2.getNumberOfComponents());
+ expected2=[5,7,8,0,3,2]
+ for i in xrange(6):
+ self.assertEqual(expected2[i],da2.getIJ(i,0));
+ pass
+ da3=da2.invertArrayN2O2O2N(10);
+ for i in xrange(10):
+ self.assertEqual(arr2[i],da3.getIJ(i,0));
+ pass
+ pass
def setUp(self):
pass
%newobject ParaMEDMEM::DataArrayInt::substr;
%newobject ParaMEDMEM::DataArrayInt::changeNbOfComponents;
%newobject ParaMEDMEM::DataArrayInt::selectByTupleId;
+%newobject ParaMEDMEM::DataArrayInt::renumber;
+%newobject ParaMEDMEM::DataArrayInt::renumberR;
+%newobject ParaMEDMEM::DataArrayInt::renumberAndReduce;
+%newobject ParaMEDMEM::DataArrayInt::invertArrayO2N2N2O;
+%newobject ParaMEDMEM::DataArrayInt::invertArrayN2O2O2N;
%newobject ParaMEDMEM::DataArrayDouble::aggregate;
%newobject ParaMEDMEM::DataArrayDouble::dot;
%newobject ParaMEDMEM::DataArrayDouble::crossProduct;
%newobject ParaMEDMEM::DataArrayDouble::deviator;
%newobject ParaMEDMEM::DataArrayDouble::magnitude;
%newobject ParaMEDMEM::DataArrayDouble::maxPerTuple;
+%newobject ParaMEDMEM::DataArrayDouble::renumber;
+%newobject ParaMEDMEM::DataArrayDouble::renumberR;
+%newobject ParaMEDMEM::DataArrayDouble::renumberAndReduce;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::clone;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::cloneWithMesh;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::buildNewTimeReprFromThis;
%newobject ParaMEDMEM::MEDCouplingExtrudedMesh::New;
%newobject ParaMEDMEM::MEDCouplingExtrudedMesh::build3DUnstructuredMesh;
%newobject ParaMEDMEM::MEDCouplingCMesh::New;
+%newobject ParaMEDMEM::MEDCouplingCMesh::buildUnstructured;
%feature("unref") DataArrayDouble "$this->decrRef();"
%feature("unref") MEDCouplingPointSet "$this->decrRef();"
%feature("unref") MEDCouplingMesh "$this->decrRef();"
%feature("unref") MEDCouplingField "$this->decrRef();"
%feature("unref") MEDCouplingFieldDouble "$this->decrRef();"
-%ignore ParaMEDMEM::TimeLabel::operator=;
+%rename(assign) *::operator=;
%ignore ParaMEDMEM::MemArray::operator=;
%ignore ParaMEDMEM::MemArray::operator[];
%ignore ParaMEDMEM::MEDCouplingPointSet::getCoords();
%ignore ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationDblInfo;
%ignore ParaMEDMEM::MEDCouplingGaussLocalization::fillWithValues;
%ignore ParaMEDMEM::MEDCouplingGaussLocalization::buildNewInstanceFromTinyInfo;
+
%rename (Exception) InterpKernelException;
%nodefaultctor;
virtual void getBoundingBox(double *bbox) const = 0;
virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const = 0;
virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const = 0;
- virtual int getCellContainingPoint(const double *pos, double eps) const = 0;
virtual MEDCouplingFieldDouble *fillFromAnalytic(TypeOfField t, int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception);
virtual MEDCouplingFieldDouble *buildOrthogonalField() const = 0;
virtual void rotate(const double *center, const double *vector, double angle) = 0;
return self->simpleRepr();
}
+ int getCellContainingPoint(PyObject *p, double eps) const
+ {
+ int sz;
+ double *pos=convertPyToNewDblArr2(p,&sz);
+ int ret=self->getCellContainingPoint(pos,eps);
+ delete [] pos;
+ return ret;
+ }
+
void renumberCells(PyObject *li, bool check) throw(INTERP_KERNEL::Exception)
{
int size;
{
return self->simpleRepr();
}
-
- int getCellContainingPoint(PyObject *p, double eps) const
- {
- int sz;
- double *pos=convertPyToNewDblArr2(p,&sz);
- int ret=self->getCellContainingPoint(pos,eps);
- delete [] pos;
- return ret;
- }
void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li)
{
int sz;
DataArrayDouble *coordsY=0,
DataArrayDouble *coordsZ=0);
void setCoordsAt(int i, DataArrayDouble *arr) throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *buildUnstructured() const;
%extend {
std::string __str__() const
{
int nbOfTuples=self->getNumberOfTuples();
return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples);
}
+
+ DataArrayDouble *renumber(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ DataArrayDouble *ret=self->renumber(tmp);
+ delete [] tmp;
+ return ret;
+ }
+
+ DataArrayDouble *renumberR(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ DataArrayDouble *ret=self->renumberR(tmp);
+ delete [] tmp;
+ return ret;
+ }
+
+ DataArrayDouble *renumberAndReduce(PyObject *li, int newNbOfTuple) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ DataArrayDouble *ret=self->renumberAndReduce(tmp,newNbOfTuple);
+ delete [] tmp;
+ return ret;
+ }
+
+ void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ self->renumberInPlace(tmp);
+ delete [] tmp;
+ }
+
+ void renumberInPlaceR(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ self->renumberInPlaceR(tmp);
+ delete [] tmp;
+ }
+
+ DataArrayDouble *selectByTupleId(PyObject *li) const
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ DataArrayDouble *ret=self->selectByTupleId(tmp,tmp+size);
+ delete [] tmp;
+ return ret;
+ }
+
+ PyObject *getMaxValue() const throw(INTERP_KERNEL::Exception)
+ {
+ int tmp;
+ double r1=self->getMaxValue(tmp);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1));
+ PyTuple_SetItem(ret,1,PyInt_FromLong(tmp));
+ return ret;
+ }
+
+ PyObject *getMaxValue2() const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *tmp;
+ double r1=self->getMaxValue2(tmp);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
+
+ PyObject *getMinValue() const throw(INTERP_KERNEL::Exception)
+ {
+ int tmp;
+ double r1=self->getMinValue(tmp);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1));
+ PyTuple_SetItem(ret,1,PyInt_FromLong(tmp));
+ return ret;
+ }
+
+ PyObject *getMinValue2() const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *tmp;
+ double r1=self->getMinValue2(tmp);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
};
%extend ParaMEDMEM::DataArrayInt
PyList_SetItem(ret,1,ret1);
return ret;
}
+
+ void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ self->renumberInPlace(tmp);
+ delete [] tmp;
+ }
+
+ void renumberInPlaceR(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ self->renumberInPlaceR(tmp);
+ delete [] tmp;
+ }
+
+ DataArrayInt *renumberAndReduce(PyObject *li, int newNbOfTuple) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ DataArrayInt *ret=self->renumberAndReduce(tmp,newNbOfTuple);
+ delete [] tmp;
+ return ret;
+ }
+
+ DataArrayInt *renumber(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ DataArrayInt *ret=self->renumber(tmp);
+ delete [] tmp;
+ return ret;
+ }
+
+ DataArrayInt *renumberR(PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ if(size!=self->getNumberOfTuples())
+ {
+ throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !");
+ delete [] tmp;
+ }
+ DataArrayInt *ret=self->renumberR(tmp);
+ delete [] tmp;
+ return ret;
+ }
+
+ DataArrayInt *selectByTupleId(PyObject *li) const
+ {
+ int size;
+ int *tmp=convertPyToNewIntArr2(li,&size);
+ DataArrayInt *ret=self->selectByTupleId(tmp,tmp+size);
+ delete [] tmp;
+ return ret;
+ }
};
namespace ParaMEDMEM
void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception);
void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception);
bool mergeNodes(double eps) throw(INTERP_KERNEL::Exception);
+ bool zipCoords() throw(INTERP_KERNEL::Exception);
+ bool zipConnectivity(int compType) throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *determinant() const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *eigenValues() const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *maxPerTuple() const throw(INTERP_KERNEL::Exception);
void changeNbOfComponents(int newNbOfComp, double dftValue=0.) throw(INTERP_KERNEL::Exception);
void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception);
+ 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(const char *func) throw(INTERP_KERNEL::Exception);
void applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception);
}
PyObject *accumulate() const
{
- int sz=self->getNumberOfTuples();
+ int sz=self->getNumberOfComponents();
double *tmp=new double[sz];
self->accumulate(tmp);
PyObject *ret=convertDblArrToPyList(tmp,sz);
}
PyObject *integral(bool isWAbs) const
{
- int sz=self->getNumberOfTuples();
+ int sz=self->getNumberOfComponents();
double *tmp=new double[sz];
self->integral(isWAbs,tmp);
PyObject *ret=convertDblArrToPyList(tmp,sz);
}
PyObject *normL1() const throw(INTERP_KERNEL::Exception)
{
- int sz=self->getNumberOfTuples();
+ int sz=self->getNumberOfComponents();
double *tmp=new double[sz];
self->normL1(tmp);
PyObject *ret=convertDblArrToPyList(tmp,sz);
}
PyObject *normL2() const throw(INTERP_KERNEL::Exception)
{
- int sz=self->getNumberOfTuples();
+ int sz=self->getNumberOfComponents();
double *tmp=new double[sz];
self->normL2(tmp);
PyObject *ret=convertDblArrToPyList(tmp,sz);
delete [] tmp;
return ret;
}
+
+ PyObject *getMaxValue2() const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *tmp;
+ double r1=self->getMaxValue2(tmp);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
+
+ PyObject *getMinValue2() const throw(INTERP_KERNEL::Exception)
+ {
+ DataArrayInt *tmp;
+ double r1=self->getMinValue2(tmp);
+ PyObject *ret=PyTuple_New(2);
+ PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+ }
}
};
}
self.assertTrue(f2.isEqual(f1,1e-12,1e-12));
pass
+ def testFieldNodeProfilRW1(self):
+ fileName="Pyfile19.med";
+ fileName2="Pyfile20.med";
+ m=MEDLoaderDataForTest.build2DMesh_1();
+ nbOfNodes=m.getNumberOfNodes();
+ MEDLoader.WriteUMesh(fileName,m,True);
+ f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
+ f1.setName("VFieldOnNodes");
+ f1.setMesh(m);
+ array=DataArrayDouble.New();
+ arr1=[1.,101.,2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.]
+ array.setValues(arr1,nbOfNodes,2);
+ f1.setArray(array);
+ array.setInfoOnComponent(0,"tyty (mm)");
+ array.setInfoOnComponent(1,"uiop (MW)");
+ f1.setTime(3.14,2,7);
+ f1.checkCoherency();
+ arr2=[2,4,5,3,6,7]
+ f2=f1.buildSubPart(arr2);
+ f2.getMesh().setName(f1.getMesh().getName());
+ MEDLoader.WriteField(fileName,f2,False);#<- False important for the test
+ #
+ f3=MEDLoader.ReadFieldNode(fileName,f2.getMesh().getName(),0,f2.getName(),2,7);
+ f3.checkCoherency();
+ self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
+ #
+ arr3=[1,3,0,5,2,4]
+ f2.renumberNodes(arr3);
+ MEDLoader.WriteUMesh(fileName2,m,True);
+ MEDLoader.WriteField(fileName2,f2,False);#<- False important for the test
+ f3=MEDLoader.ReadFieldNode(fileName2,f2.getMesh().getName(),0,f2.getName(),2,7);
+ f3.checkCoherency();
+ self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
+ #
+ pass
+
+ def testFieldNodeProfilRW2(self):
+ fileName="Pyfile23.med";
+ mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
+ MEDLoader.WriteUMesh(fileName,mesh,True);
+ #
+ f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
+ f1.setName("FieldMix");
+ f1.setMesh(mesh);
+ arr2=[1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
+ 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.];
+ array=DataArrayDouble.New();
+ array.setValues(arr2,12,2);
+ f1.setArray(array);
+ array.setInfoOnComponent(0,"plkj (mm)");
+ array.setInfoOnComponent(1,"pqqqss (mm)");
+ tmp=array.getPointer();
+ f1.setTime(3.17,2,7);
+ #
+ renumArr=[3,7,2,1,5,11,10,0,9,6,8,4]
+ f1.renumberNodes(renumArr);
+ f1.checkCoherency();
+ MEDLoader.WriteField(fileName,f1,False);#<- False important for the test
+ f2=MEDLoader.ReadFieldNode(fileName,f1.getMesh().getName(),0,f1.getName(),2,7);
+ self.assertTrue(f2.isEqual(f1,1e-12,1e-12));
+ #
+ pass
+
def testMixCellAndNodesFieldRW1(self):
fileName="Pyfile21.med";
mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
self.assertTrue(f3.isEqual(f1,1e-12,1e-12));
#
pass
+
+ def testGetAllFieldNamesRW1(self):
+ fileName="Pyfile22.med";
+ mesh=MEDLoaderDataForTest.build2DMesh_2();
+ f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
+ f1.setName("Field1");
+ f1.setTime(3.44,5,6);
+ f1.setMesh(mesh);
+ f1.fillFromAnalytic(2,"x+y");
+ MEDLoader.WriteField(fileName,f1,True);
+ f1.setTime(1002.3,7,8);
+ f1.fillFromAnalytic(2,"x+77.*y");
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1.setName("Field2");
+ MEDLoader.WriteField(fileName,f1,False);
+ f1.setName("Field3");
+ mesh.setName("2DMesh_2Bis");
+ MEDLoader.WriteField(fileName,f1,False);
+ f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+ f1.setName("Field8");
+ f1.setTime(8.99,7,9);
+ f1.setMesh(mesh);
+ f1.fillFromAnalytic(3,"3*x+y");
+ MEDLoader.WriteField(fileName,f1,False);
+ fs=MEDLoader.GetAllFieldNames(fileName);
+ self.assertEqual(4,len(fs));
+ self.assertTrue(fs[0]=="Field1");
+ self.assertTrue(fs[1]=="Field2");
+ self.assertTrue(fs[2]=="Field3");
+ self.assertTrue(fs[3]=="Field8");
+ pass
pass
unittest.main()
static std::vector<std::string> GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
static std::vector<std::string> GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
+ static std::vector<std::string> GetAllFieldNames(const char *fileName) 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);
f2->renumberNodes(arr3);
MEDLoader::WriteUMesh(fileName2,m,true);
MEDLoader::WriteField(fileName2,f2,false);//<- false important for the test
- f3=MEDLoader::ReadFieldNode(fileName,f2->getMesh()->getName(),0,f2->getName(),2,7);
+ f3=MEDLoader::ReadFieldNode(fileName2,f2->getMesh()->getName(),0,f2->getName(),2,7);
f3->checkCoherency();
- //CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));//<- bug
+ CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));
f3->decrRef();
f2->decrRef();
//
m->decrRef();
}
+void MEDLoaderTest::testFieldNodeProfilRW2()
+{
+ const char fileName[]="file23.med";
+ MEDCouplingUMesh *mesh=build3DSurfMesh_1();
+ MEDLoader::WriteUMesh(fileName,mesh,true);
+ //
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
+ f1->setName("FieldMix");
+ f1->setMesh(mesh);
+ const double arr2[24]={
+ 1071.,1171.,1010.,1110.,1020.,1120.,1030.,1130.,1040.,1140.,1050.,1150.,
+ 1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
+ };
+ DataArrayDouble *array=DataArrayDouble::New();
+ array->alloc(12,2);
+ f1->setArray(array);
+ array->setInfoOnComponent(0,"plkj (mm)");
+ array->setInfoOnComponent(1,"pqqqss (mm)");
+ array->decrRef();
+ double *tmp=array->getPointer();
+ std::copy(arr2,arr2+24,tmp);
+ f1->setTime(3.17,2,7);
+ //
+ const int renumArr[12]={3,7,2,1,5,11,10,0,9,6,8,4};
+ f1->renumberNodes(renumArr);
+ f1->checkCoherency();
+ MEDLoader::WriteField(fileName,f1,false);//<- false important for the test
+ MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldNode(fileName,f1->getMesh()->getName(),0,f1->getName(),2,7);
+ CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12));
+ //
+ f2->decrRef();
+ mesh->decrRef();
+ f1->decrRef();
+}
+
void MEDLoaderTest::testFieldGaussRW1()
{
const char fileName[]="file13.med";
mesh->decrRef();
}
+void MEDLoaderTest::testGetAllFieldNamesRW1()
+{
+ const char fileName[]="file22.med";
+ MEDCouplingUMesh *mesh=build2DMesh_2();
+ MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME);
+ f1->setName("Field1");
+ f1->setTime(3.44,5,6);
+ f1->setMesh(mesh);
+ f1->fillFromAnalytic(2,"x+y");
+ MEDLoader::WriteField(fileName,f1,true);
+ f1->setTime(1002.3,7,8);
+ f1->fillFromAnalytic(2,"x+77.*y");
+ MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1->setName("Field2");
+ MEDLoader::WriteField(fileName,f1,false);
+ f1->setName("Field3");
+ mesh->setName("2DMesh_2Bis");
+ MEDLoader::WriteField(fileName,f1,false);
+ f1->decrRef();
+ f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f1->setName("Field8");
+ f1->setTime(8.99,7,9);
+ f1->setMesh(mesh);
+ f1->fillFromAnalytic(3,"3*x+y");
+ MEDLoader::WriteField(fileName,f1,false);
+ f1->decrRef();
+ std::vector<std::string> fs=MEDLoader::GetAllFieldNames(fileName);
+ CPPUNIT_ASSERT_EQUAL(4,(int)fs.size());
+ CPPUNIT_ASSERT(fs[0]=="Field1");
+ CPPUNIT_ASSERT(fs[1]=="Field2");
+ CPPUNIT_ASSERT(fs[2]=="Field3");
+ CPPUNIT_ASSERT(fs[3]=="Field8");
+ mesh->decrRef();
+}
+
MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1()
{
double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 };
CPPUNIT_TEST( testMultiMeshRW1 );
CPPUNIT_TEST( testFieldProfilRW1 );
CPPUNIT_TEST( testFieldNodeProfilRW1 );
+ CPPUNIT_TEST( testFieldNodeProfilRW2 );
CPPUNIT_TEST( testFieldGaussRW1 );
CPPUNIT_TEST( testFieldGaussNERW1 );
CPPUNIT_TEST( testLittleStrings1 );
CPPUNIT_TEST( testMultiFieldShuffleRW1 );
CPPUNIT_TEST( testWriteUMeshesRW1 );
CPPUNIT_TEST( testMixCellAndNodesFieldRW1 );
+ CPPUNIT_TEST( testGetAllFieldNamesRW1 );
CPPUNIT_TEST_SUITE_END();
public:
void testMesh1DRW();
void testMultiMeshRW1();
void testFieldProfilRW1();
void testFieldNodeProfilRW1();
+ void testFieldNodeProfilRW2();
void testFieldGaussRW1();
void testFieldGaussNERW1();
void testLittleStrings1();
void testMultiFieldShuffleRW1();
void testWriteUMeshesRW1();
void testMixCellAndNodesFieldRW1();
+ void testGetAllFieldNamesRW1();
private:
MEDCouplingUMesh *build1DMesh_1();
MEDCouplingUMesh *build2DCurveMesh_1();